Add dependencies check

This commit is contained in:
mathijs-bakker
2025-08-21 17:53:15 +02:00
parent d99e28a6fc
commit ffe83a5124

View File

@@ -1,7 +1,10 @@
local health = vim.health local health = vim.health
local M = {} local M = {}
M.opts = { editor_port = 6005 } M.opts = {
editor_port = 6005,
debug_port = 6006,
}
function M.setup(opts) function M.setup(opts)
M.opts = vim.tbl_extend("force", M.opts, opts or {}) M.opts = vim.tbl_extend("force", M.opts, opts or {})
@@ -10,53 +13,86 @@ end
local is_windows = vim.loop.os_uname().sysname == "Windows_NT" local is_windows = vim.loop.os_uname().sysname == "Windows_NT"
local function port_open(host, port) local function port_open(host, port)
local cmd
if is_windows then if is_windows then
if vim.fn.executable("ncat") ~= 1 then if vim.fn.executable("ncat") ~= 1 then
return false return false
end end
local cmd = string.format("ncat -z -w 1 %s %d 2>/dev/null", host, port) cmd = string.format("ncat -z -w 1 %s %d 2>NUL", host, port)
vim.fn.system(cmd)
return vim.v.shell_error == 0
else else
if vim.fn.executable("nc") == 1 then if vim.fn.executable("nc") ~= 1 then
local cmd = string.format("nc -z -w 1 %s %d 2>/dev/null", host, port) return true -- assume port ok if nc is missing
end
cmd = string.format("nc -z -w 1 %s %d >/dev/null 2>&1", host, port)
end
vim.fn.system(cmd) vim.fn.system(cmd)
return vim.v.shell_error == 0 return vim.v.shell_error == 0
end end
return true
-- 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
elseif name == "nvim-dap" then
return vim.fn.exists(":DapContinue") == 2
elseif name == "nvim-treesitter" then
return pcall(require, "nvim-treesitter.configs")
end end
return false
end end
function M.check() function M.check()
health.start("Godotdev.nvim") health.start("Godotdev.nvim")
if is_windows then -- plugin dependencies
if vim.fn.executable("ncat") == 1 then for _, plugin in ipairs({ "nvim-lspconfig", "nvim-treesitter", "nvim-dap" }) do
health.ok("'ncat' is installed") if plugin_installed(plugin) then
health.ok("Dependency '" .. plugin .. "' is installed")
else else
health.error([[Windows: 'ncat' not found. Install via Scoop or Chocolatey: health.warn("Dependency '" .. plugin .. "' not found. Some features may not work.")
scoop install nmap
choco install nmap]])
end end
end end
local port = M.opts.editor_port -- Godot editor LSP
if port_open("127.0.0.1", port) then local editor_port = M.opts.editor_port
health.ok("Godot editor LSP detected on port " .. port) if port_open("127.0.0.1", editor_port) then
health.ok("Godot editor LSP detected on port " .. editor_port)
else else
local msg = string.format( health.warn(string.format(
[[ [[
Godot editor LSP not detected on port %d. Godot editor LSP not detected on port %d.
Make sure the Godot editor is running with the LSP server enabled on this port. Make sure the Godot editor is running with LSP server enabled.
- Open your project in Godot. - Open your project in Godot.
- Enable the LSP server (Editor Settings → Network → Enable TCP LSP server). - Enable the LSP server (Editor Settings → Network → Enable TCP LSP server).
- Confirm the port matches %d (change `editor_port` in your config if needed). - Confirm the port matches %d (change `editor_port` in your config if needed).
]], ]],
port, editor_port,
port editor_port
) ))
health.warn(msg) 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)
else
health.warn("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")
else
health.error([[
Windows: 'ncat' not found. Install via Scoop or Chocolatey:
scoop install nmap
choco install nmap
]])
end
end end
end end