Skip to content

Commit 3fc2a3f

Browse files
Cretezymehalter
andauthored
feat(godot): Add .uid/.import file handling and godot-server.nvim (#1450)
* feat(godot): Add .uid file handling and godot-server * fix(godot): use neo-tree nested files and clean up event handlers * chore(godot): improve notification formatting * refactor(godot): `neo-tree` events can share an id for easier unsubscribe --------- Co-authored-by: Micah Halter <[email protected]>
1 parent 9444af4 commit 3fc2a3f

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Godot Language Pack
22

3-
**Requirements:** `Godot` needs to be running to use LSP and DAP for gdscript
3+
**Requirements:** Godot needs to be running to use LSP and DAP for GDScript
44

55
This plugin pack does the following:
66

@@ -9,4 +9,5 @@ This plugin pack does the following:
99
- Adds `gdscript` treesitter parsers
1010
- Adds `godot_resource` treesitter parsers
1111
- Adds `glsl` treesitter parsers
12-
- Adds [quickgd.nvim](https://github.com/QuickGD/quickgd.nvim)
12+
- Adds [quickgd.nvim](https://github.com/QuickGD/quickgd.nvim) to provide commands for starting Godot
13+
- 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))

lua/astrocommunity/pack/godot/init.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
local function gd_move_handler(source, destination)
2+
if not vim.fs.root(source, "project.godot") then return end -- only run in godot projects
3+
local suffix = source:match "%.gd$" and "uid" or "import"
4+
local tmp_file = ("%s.%s"):format(source, suffix)
5+
local tmp_stat = vim.uv.fs_stat(tmp_file)
6+
7+
if tmp_stat then
8+
-- Rename the temporary file
9+
local new_tmp_file = ("%s.%s"):format(destination, suffix)
10+
local success, err = vim.uv.fs_rename(tmp_file, new_tmp_file)
11+
if not success then
12+
vim.notify(("Failed to rename Godot file: `%s`\n```\n%s\n```"):format(tmp_file, err or "unknown error"))
13+
end
14+
end
15+
end
16+
117
return {
218
{
319
"AstroNvim/astrocore",
@@ -73,4 +89,39 @@ return {
7389
end
7490
end,
7591
},
92+
{
93+
"nvim-neo-tree/neo-tree.nvim",
94+
optional = true,
95+
opts = {
96+
event_handlers = {
97+
{
98+
event = "file_renamed",
99+
handler = function(args) gd_move_handler(args.source, args.destination) end,
100+
id = "godot_handler",
101+
},
102+
{
103+
event = "file_moved",
104+
handler = function(args) gd_move_handler(args.source, args.destination) end,
105+
id = "godot_handler",
106+
},
107+
},
108+
nesting_rules = {
109+
godot_import = {
110+
pattern = "^(.*)$",
111+
files = { -- pretty loose, but is probably a specific enough pattern to be alright
112+
"%1.import",
113+
},
114+
},
115+
godot_uid = {
116+
pattern = "^(.*%.gd)$",
117+
files = {
118+
"%1.uid",
119+
},
120+
},
121+
},
122+
},
123+
},
124+
{
125+
"Cretezy/godot-server.nvim",
126+
},
76127
}

0 commit comments

Comments
 (0)