From 468c7f29a56fa9ebb70bdbe395edbc11b14289c2 Mon Sep 17 00:00:00 2001 From: mathijs-bakker Date: Fri, 22 Aug 2025 11:49:38 +0200 Subject: [PATCH] Add C# installation support --- README.md | 28 +++++++++----- lua/godotdev/health.lua | 82 ++++++++++++++++++++++++++++++----------- lua/godotdev/setup.lua | 19 ++++++++++ 3 files changed, 97 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index f694d63..4b67287 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # godotdev.nvim -Batteries-included Neovim plugin for **Godot game development**, using Neovim as an external editor. Provides LSP support for GDScript and Godot shaders, DAP debugging, and Treesitter syntax highlighting. +BBatteries-included Neovim plugin for Godot game development, using Neovim as an external editor. Provides LSP support for GDScript and Godot shaders, DAP debugging, Treesitter syntax highlighting, and optional C# installation support. ## Features @@ -11,7 +11,9 @@ Batteries-included Neovim plugin for **Godot game development**, using Neovim as - `.gdshader` syntax highlighting via Treesitter - Debug GDScript with `nvim-dap` (`127.0.0.1:6006` by default) - Keymaps for common LSP actions +- Optional C# support: LSP, debugging, and tooling - Batteries included: everything you need for Godot development in Neovim +- Built-in health checks via `:checkhealth godotdev` ## Requirements @@ -21,27 +23,29 @@ Batteries-included Neovim plugin for **Godot game development**, using Neovim as - `nvim-dap` and `nvim-dap-ui` for debugging - `nvim-treesitter` - Windows users must have [`ncat`](https://nmap.org/ncat/) in PATH +- Optional C# support requires: + - .NET SDK (dotnet) + - C# LSP server (csharp-ls recommended or omnisharp) + - netcoredbg debugger ## Installation (Lazy.nvim) ```lua { 'Mathijs-Bakker/godotdev.nvim', - lazy = false, dependencies = { 'nvim-lspconfig', 'nvim-dap', 'nvim-dap-ui', 'nvim-treesitter' }, - config = function() - require("godotdev").setup() - end, } ``` ## Quickstart 1. Open your Godot project in Neovim 1. Start Godot editor with TCP LSP enabled (Editor Settings → Network → Enable TCP LSP server) -1. Open a .gd or .gdshader file +1. Open a `.gd` or `.gdshader` file 1. LSP will automatically attach -1. Use rn to rename, gd to go to definition, gr for references, etc. +1. Use `rn` to rename, `gd` to go to definition, `gr` for references, etc. 1. Start debugging with DAP (Launch scene configuration) +1. Optional: Enable C# support by setting `csharp = true` in the plugin setup +1. Run `:checkhealth godotdev` at any time to verify plugin, LSP, debug server, and C# dependencies ## Configuration @@ -51,6 +55,7 @@ require("godotdev").setup({ editor_host = "127.0.0.1", -- Godot editor host editor_port = 6005, -- LSP port debug_port = 6006, -- DAP port + csharp = true, -- enable C# support }) ``` @@ -152,7 +157,10 @@ gdvim - `du` -> , Toggle UI - `dr` -> , Open REPL +## C# installation Support -## License - -MIT +- Enable by setting `csharp = true` in `require("godotdev").setup()` +- Health checks via `:checkhealth godotdev` will verify: + - .NET SDK (`dotnet`) + - C# LSP server (`csharp-ls` or `omnisharp`) + - Debugger (`netcoredbg`) diff --git a/lua/godotdev/health.lua b/lua/godotdev/health.lua index 73d650b..10080ea 100644 --- a/lua/godotdev/health.lua +++ b/lua/godotdev/health.lua @@ -1,4 +1,6 @@ local health = vim.health +local godotdev = require("godotdev") + local M = {} M.opts = { @@ -29,7 +31,6 @@ local function port_open(host, port) return vim.v.shell_error == 0 end --- Check if a plugin is installed, works with Lazy.nvim local function plugin_installed(name) if name == "nvim-lspconfig" then return vim.fn.exists(":LspInfo") == 2 @@ -41,59 +42,96 @@ local function plugin_installed(name) return false end +local function has_exe(name) + return vim.fn.executable(name) == 1 +end + function M.check() health.start("Godotdev.nvim") - -- plugin dependencies + -- Godot version + health.start("Godot version") + local ok, godot_version = pcall(vim.fn.system, "godot --version") + if ok and godot_version and godot_version ~= "" then + local ver = vim.trim(godot_version) + health.ok("Godot detected: " .. ver) + local major, minor = ver:match("(%d+)%.(%d+)") + if major and minor and (tonumber(major) < 4 or (tonumber(major) == 4 and tonumber(minor) < 3)) then + health.warn("Godot version is below 4.3. Some features may not work correctly.") + end + else + health.info("Godot executable not found. Make sure 'godot' is in your PATH.") + end + + -- Dependencies + health.start("Dependencies") for _, plugin in ipairs({ "nvim-lspconfig", "nvim-treesitter", "nvim-dap" }) do if plugin_installed(plugin) then - health.ok("Dependency '" .. plugin .. "' is installed") + health.ok("✅ OK Dependency '" .. plugin .. "' is installed") else - health.warn("Dependency '" .. plugin .. "' not found. Some features may not work.") + health.warn("⚠️ WARNING Dependency '" .. plugin .. "' not found. Some features may not work.") end end - -- Godot editor LSP + -- Godot detection + health.start("Godot detection") local editor_port = M.opts.editor_port if port_open("127.0.0.1", editor_port) then - health.ok("Godot editor LSP detected on port " .. editor_port) + health.ok("✅ OK Godot editor LSP detected on port " .. editor_port) else health.warn(string.format( - [[ -Godot editor LSP not detected on port %d. + [[⚠️ WARNING Godot editor LSP not detected on port %d. Make sure the Godot editor is running with LSP server enabled. - -- Open your project in Godot. -- Enable the LSP server (Editor Settings → Network → Enable TCP LSP server). -- Confirm the port matches %d (change `editor_port` in your config if needed). -]], +- Enable TCP LSP server in Editor Settings → Network +- Confirm port matches %d]], editor_port, editor_port )) end - -- Godot editor debug server local debug_port = M.opts.debug_port if plugin_installed("nvim-dap") then if port_open("127.0.0.1", debug_port) then - health.ok("Godot editor debug server detected on port " .. debug_port) + health.ok("✅ OK Godot editor debug server detected on port " .. debug_port) else - health.warn("Godot editor debug server not detected on port " .. debug_port) + health.warn("⚠️ WARNING Godot editor debug server not detected on port " .. debug_port) end end - -- Windows: ncat check if is_windows then - if vim.fn.executable("ncat") == 1 then - health.ok("'ncat' is installed") + if has_exe("ncat") then + health.ok("✅ OK 'ncat' is installed") else health.error([[ -Windows: 'ncat' not found. Install via Scoop or Chocolatey: +❌ ERROR Windows: 'ncat' not found. Install via Scoop or Chocolatey: scoop install nmap - choco install nmap -]]) + choco install nmap]]) end end + + -- Optional C# support + if godotdev.opts.csharp then + health.start("C# support") + if has_exe("dotnet") then + health.ok("✅ OK 'dotnet' found") + else + health.error("❌ ERROR 'dotnet' not found. Install the .NET SDK: https://dotnet.microsoft.com/download") + end + + if has_exe("csharp-ls") or has_exe("omnisharp") then + health.ok("✅ OK C# LSP server found (csharp-ls or omnisharp)") + else + health.error("❌ ERROR No C# LSP server found. Install 'csharp-ls' (recommended) or 'omnisharp'.") + end + + if has_exe("netcoredbg") then + health.ok("✅ OK 'netcoredbg' found") + else + health.error("❌ ERROR 'netcoredbg' not found. Install from: https://github.com/Samsung/netcoredbg") + end + else + health.info("ℹ️ C# checks skipped (csharp=false)") + end end return M diff --git a/lua/godotdev/setup.lua b/lua/godotdev/setup.lua index 91b1715..fb42f56 100644 --- a/lua/godotdev/setup.lua +++ b/lua/godotdev/setup.lua @@ -25,6 +25,25 @@ function M.setup(opts) }) require("godotdev.tree-sitter") + + if opts.csharp then + local dap = require("dap") + dap.adapters.coreclr = { + type = "executable", + command = opts.netcoredbg_path or "netcoredbg", + args = { "--interpreter=vscode" }, + } + dap.configurations.cs = { + { + type = "coreclr", + name = "launch - netcoredbg", + request = "launch", + program = function() + return vim.fn.input("Path to dll: ", vim.fn.getcwd() .. "/bin/Debug/net6.0/", "file") + end, + }, + } + end end return M