Skip to content

Commit 1a36541

Browse files
committed
feat(godot): Add .uid file handling and godot-server
1 parent a34848c commit 1a36541

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

lua/astrocommunity/pack/godot/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ This plugin pack does the following:
77
- Adds `gdscript` treesitter parsers
88
- Adds `godot_resource` treesitter parsers
99
- Adds `glsl` treesitter parsers
10-
- Adds [quickgd.nvim](https://github.com/QuickGD/quickgd.nvim)
10+
- Adds [godot-server.nvim](https://github.com/Cretezy/godot-server.nvim) to open files from Godot in Neovim. Requires configuration in the Godot editor (see [project page](https://github.com/Cretezy/godot-server.nvim))
11+
- Adds [quickgd.nvim](https://github.com/QuickGD/quickgd.nvim) to provide `:GodotStart` (starts project), `:GodotRun` (shows picker to run scenes), and `:GodotRunLast` (runs the last ran scene)
12+
13+
## Options
14+
15+
- `vim.g.godot_move_uid`: Control if `.uid` files are moved when renaming/moving files in Godot projects. Defaults to `true`
16+
- `vim.g.godot_hide_uid`: Control if `.uid` files are hidden from neo-tree and snacks file picker in Godot projects. Can be `false` (don't hide), `always` (not visible when hidden files are enabled in neo-tree), `hide` (only visible when hidden files are enabled in neo-tree). Defaults to `always`

lua/astrocommunity/pack/godot/init.lua

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
local function is_godot_project(path)
2+
-- Start with the current directory
3+
local current_path = path
4+
5+
-- Keep traversing up until we reach the root directory
6+
while current_path and current_path ~= "" do
7+
-- Check if project.godot exists in the current directory
8+
if vim.uv.fs_stat(current_path .. "/project.godot") then return true end
9+
10+
-- Move up one directory level
11+
local parent_path = vim.fn.fnamemodify(current_path, ":h")
12+
13+
-- If we've reached the root or haven't changed directories, stop
14+
if parent_path == current_path then break end
15+
16+
current_path = parent_path
17+
end
18+
19+
return false
20+
end
21+
22+
local function move_uid_handler(source, destination)
23+
-- Check if file is inside a Godot project
24+
if vim.g.godot_move_uid ~= false and is_godot_project(source) then
25+
-- Check if corresponding .uid file exists
26+
local uid_file = source .. ".uid"
27+
local uid_stat = vim.uv.fs_stat(uid_file)
28+
29+
if uid_stat then
30+
-- Rename the uid file
31+
local new_uid_file = destination .. ".uid"
32+
local success, err = vim.uv.fs_rename(uid_file, new_uid_file)
33+
if not success then vim.notify("Failed to rename Godot UID file: " .. (err or "unknown error")) end
34+
end
35+
end
36+
end
37+
138
return {
239
{
340
"AstroNvim/astrocore",
@@ -20,4 +57,39 @@ return {
2057
end
2158
end,
2259
},
60+
{
61+
"nvim-neo-tree/neo-tree.nvim",
62+
opts = function(_, opts)
63+
-- Add renaming Godot UID files with file renames
64+
opts.event_handlers = opts.event_handlers or {}
65+
table.insert(opts.event_handlers, {
66+
event = "file_renamed",
67+
handler = function(args) move_uid_handler(args.source, args.destination) end,
68+
})
69+
table.insert(opts.event_handlers, {
70+
event = "file_moved",
71+
handler = function(args) move_uid_handler(args.source, args.destination) end,
72+
})
73+
74+
-- Add Godot UID files to the filter list
75+
if vim.g.godot_hide_uid ~= false then
76+
local never_show = vim.g.godot_hide_uid == "never"
77+
78+
opts.filesystem = opts.filesystem or {}
79+
opts.filesystem.filtered_items = opts.filesystem.filtered_items or {}
80+
81+
if never_show then
82+
opts.filesystem.filtered_items.never_show_by_pattern = opts.filesystem.filtered_items.never_show_by_pattern
83+
or {}
84+
table.insert(opts.filesystem.filtered_items.never_show_by_pattern, "*.uid")
85+
else
86+
opts.filesystem.filtered_items.hide_by_pattern = opts.filesystem.filtered_items.hide_by_pattern or {}
87+
table.insert(opts.filesystem.filtered_items.hide_by_pattern, "*.uid")
88+
end
89+
end
90+
end,
91+
},
92+
{
93+
"Cretezy/godot-server.nvim",
94+
},
2395
}

0 commit comments

Comments
 (0)