From 22b743893400edbf5446b0cdd4478cf87f28edd2 Mon Sep 17 00:00:00 2001 From: mathijs-bakker Date: Tue, 2 Sep 2025 14:50:02 +0200 Subject: [PATCH] Add start editor server --- lua/godotdev/start_editor_server.lua | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lua/godotdev/start_editor_server.lua diff --git a/lua/godotdev/start_editor_server.lua b/lua/godotdev/start_editor_server.lua new file mode 100644 index 0000000..d48db99 --- /dev/null +++ b/lua/godotdev/start_editor_server.lua @@ -0,0 +1,34 @@ +local M = {} + +local default_pipe = (vim.loop.os_uname().version:match("Windows")) and [[\\.\pipe\godot.nvim]] or "/tmp/godot.nvim" + +local function start_editor_server(pipe) + pipe = pipe or default_pipe + if vim.v.servername == pipe then + vim.notify("Godot editor server already running on " .. pipe, vim.log.levels.INFO) + return + end + vim.fn.serverstart(pipe) + vim.notify("Godot editor server started on " .. pipe, vim.log.levels.INFO) +end + +-- User command +vim.api.nvim_create_user_command("GodotEditorServer", function(opts) + start_editor_server(opts.args ~= "" and opts.args or nil) +end, { + nargs = "?", + complete = "file", +}) + +-- Autostart when opening a Godot script (.gd or .cs if enabled) +vim.api.nvim_create_autocmd("BufReadPost", { + pattern = { "*.gd", "*.cs" }, + callback = function() + local config = require("godotdev") + if config.autostart_editor_server then + start_editor_server() + end + end, +}) + +return M