Files

187 lines
5.2 KiB
Lua
Raw Permalink Normal View History

2025-08-20 17:43:50 +02:00
local health = vim.health
2025-08-22 11:49:38 +02:00
local godotdev = require("godotdev")
local M = {}
2025-08-20 17:43:50 +02:00
2025-08-21 17:53:15 +02:00
M.opts = {
editor_port = 6005,
debug_port = 6006,
}
2025-08-20 17:43:50 +02:00
function M.setup(opts)
M.opts = vim.tbl_extend("force", M.opts, opts or {})
end
2025-08-20 17:47:18 +02:00
local is_windows = vim.loop.os_uname().sysname == "Windows_NT"
2025-08-20 17:43:50 +02:00
local function port_open(host, port)
2025-08-21 17:53:15 +02:00
local cmd
2025-08-20 17:47:18 +02:00
if is_windows then
if vim.fn.executable("ncat") ~= 1 then
return false
end
2025-08-21 17:53:15 +02:00
cmd = string.format("ncat -z -w 1 %s %d 2>NUL", host, port)
2025-08-20 17:43:50 +02:00
else
2025-08-21 17:53:15 +02:00
if vim.fn.executable("nc") ~= 1 then
return true -- assume port ok if nc is missing
2025-08-20 17:47:18 +02:00
end
2025-08-21 17:53:15 +02:00
cmd = string.format("nc -z -w 1 %s %d >/dev/null 2>&1", host, port)
2025-08-20 17:43:50 +02:00
end
2025-08-21 17:53:15 +02:00
vim.fn.system(cmd)
return vim.v.shell_error == 0
end
local function plugin_installed(name)
if name == "nvim-lspconfig" then
return vim.fn.exists(":LspInfo") == 2
elseif name == "nvim-dap" then
return vim.fn.exists(":DapContinue") == 2
elseif name == "nvim-treesitter" then
return pcall(require, "nvim-treesitter.configs")
end
return false
2025-08-20 17:43:50 +02:00
end
2025-08-22 11:49:38 +02:00
local function has_exe(name)
return vim.fn.executable(name) == 1
end
local function check_indent()
health.start("Indentation")
local handle = io.popen("grep -P '\t' -R --include='*.gd' --include='*.cs' . 2>/dev/null | head -n 1")
if handle then
local result = handle:read("*a")
handle:close()
if result ~= "" then
health.warn(
"Mixed indentation detected (tabs found in .gd or .cs files). Godot expects spaces, 4 per indent. See :help godotdev-indent"
)
else
health.ok("Indentation style looks consistent (no tabs in .gd or .cs files).")
end
end
end
2025-08-20 17:43:50 +02:00
function M.check()
health.start("Godotdev.nvim")
2025-08-22 11:49:38 +02:00
-- 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")
2025-08-21 17:53:15 +02:00
for _, plugin in ipairs({ "nvim-lspconfig", "nvim-treesitter", "nvim-dap" }) do
if plugin_installed(plugin) then
2025-08-22 11:49:38 +02:00
health.ok("✅ OK Dependency '" .. plugin .. "' is installed")
2025-08-20 17:43:50 +02:00
else
2025-08-22 11:49:38 +02:00
health.warn("⚠️ WARNING Dependency '" .. plugin .. "' not found. Some features may not work.")
2025-08-20 17:43:50 +02:00
end
end
2025-08-22 11:49:38 +02:00
-- Godot detection
health.start("Godot detection")
2025-08-21 17:53:15 +02:00
local editor_port = M.opts.editor_port
if port_open("127.0.0.1", editor_port) then
2025-08-22 11:49:38 +02:00
health.ok("✅ OK Godot editor LSP detected on port " .. editor_port)
2025-08-20 17:43:50 +02:00
else
2025-08-21 17:53:15 +02:00
health.warn(string.format(
2025-08-22 11:49:38 +02:00
[[ WARNING Godot editor LSP not detected on port %d.
2025-08-21 17:53:15 +02:00
Make sure the Godot editor is running with LSP server enabled.
2025-08-22 11:49:38 +02:00
- Enable TCP LSP server in Editor Settings Network
- Confirm port matches %d]],
2025-08-21 17:53:15 +02:00
editor_port,
editor_port
))
end
local debug_port = M.opts.debug_port
if plugin_installed("nvim-dap") then
if port_open("127.0.0.1", debug_port) then
2025-08-22 11:49:38 +02:00
health.ok("✅ OK Godot editor debug server detected on port " .. debug_port)
2025-08-21 17:53:15 +02:00
else
2025-08-22 11:49:38 +02:00
health.warn("⚠️ WARNING Godot editor debug server not detected on port " .. debug_port)
2025-08-21 17:53:15 +02:00
end
end
if is_windows then
2025-08-22 11:49:38 +02:00
if has_exe("ncat") then
health.ok("✅ OK 'ncat' is installed")
2025-08-21 17:53:15 +02:00
else
health.error([[
2025-08-22 11:49:38 +02:00
ERROR Windows: 'ncat' not found. Install via Scoop or Chocolatey:
2025-08-21 17:53:15 +02:00
scoop install nmap
2025-08-22 11:49:38 +02:00
choco install nmap]])
2025-08-21 17:53:15 +02:00
end
2025-08-20 17:43:50 +02:00
end
2025-08-22 11:49:38 +02:00
-- 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
-- Code Formatting:
health.start("GDScript Formatter")
2025-09-08 10:50:21 +02:00
local formatter = godotdev.opts.formatter or "gdformat"
local exe = godotdev.opts.formatter_cmd or formatter
if has_exe(exe) then
health.ok("✅ OK '" .. exe .. "' found")
2025-09-08 10:50:21 +02:00
else
if formatter == "gdformat" then
health.warn([[
2025-09-08 10:50:21 +02:00
ERROR 'gdformat' not found.
Install with Python pip or Homebrew:
2025-09-08 10:50:21 +02:00
Linux / macOS:
pip install gdtoolkit
macOS (Homebrew):
brew install gdtoolkit
Windows:
pip install gdtoolkit]])
elseif formatter == "gdscript-format" then
health.warn([[
ERROR 'gdscript-format' not found.
Install from the repo: https://github.com/Scony/godot-gdscript-formatter-tree-sitter
Follow instructions in README.md]])
end
2025-09-08 10:50:21 +02:00
end
check_indent()
end
2025-09-08 10:50:21 +02:00
return M