Skip to content

Commit

Permalink
feat(health): don't warn if nvim-dap is not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jan 27, 2025
1 parent 5d993d3 commit 630c8b0
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions lua/rustaceanvim/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@ local health = {}
local h = vim.health

---@class rustaceanvim.LuaDependency
---@field module string The name of a module
---@field optional fun():boolean Function that returns whether the dependency is optional
---@field name string The name of the dependency
---@field module string The name of a module to check for
---@field is_optional fun():boolean Function that returns whether the dependency is optional
---@field is_configured fun():boolean Function that returns whether the dependency is configured
---@field url string URL (markdown)
---@field info string Additional information

---@type rustaceanvim.LuaDependency[]
local lua_dependencies = {
{
name = 'nvim-dap',
module = 'dap',
optional = function()
is_optional = function()
return true
end,
is_configured = function()
local rustaceanvim_opts = type(vim.g.rustaceanvim) == 'function' and vim.g.rustaceanvim()
or vim.g.rustaceanvim
or {}
local dap_opts = vim.tbl_get(rustaceanvim_opts, 'dap')
return type(dap_opts) == 'table'
end,
url = '[mfussenegger/nvim-dap](https://github.com/mfussenegger/nvim-dap)',
info = 'Needed for debugging features',
},
Expand All @@ -27,7 +37,7 @@ local lua_dependencies = {
---@field required_version_spec? string Version range spec. See `vim.version.range()`
---@field get_binaries fun():string[] Function that returns the binaries to check for
---@field is_installed? fun(bin: string):boolean Default: `vim.fn.executable(bin) == 1`
---@field optional fun():boolean Function that returns whether the dependency is optional
---@field is_optional fun():boolean Function that returns whether the dependency is optional
---@field url string URL (markdown)
---@field info string Additional information
---@field extra_checks_if_installed? fun(bin: string) Optional extra checks to perform if the dependency is installed
Expand All @@ -39,10 +49,14 @@ local function check_lua_dependency(dep)
h.ok(dep.url .. ' installed.')
return
end
if dep.optional() then
h.warn(('%s not installed. %s %s'):format(dep.module, dep.info, dep.url))
if dep.is_optional() then
if dep.is_configured() then
h.warn(('optional dependency %s is configured, but not installed. %s %s'):format(dep.name, dep.info, dep.url))
else
h.ok(('optional dependency %s not installed. %s %s'):format(dep.name, dep.info, dep.url))
end
else
error(('Lua dependency %s not found: %s'):format(dep.module, dep.url))
error(('Lua dependency %s not found: %s'):format(dep.name, dep.url))
end
end

Expand Down Expand Up @@ -94,7 +108,7 @@ local function check_external_dependency(dep)
end
return
end
if not dep.optional() then
if not dep.is_optional() then
h.error(([[
%s: not found: %s
rustaceanvim requires %s.
Expand Down Expand Up @@ -209,7 +223,7 @@ function health.check()
end)
return success
end,
optional = function()
is_optional = function()
return false
end,
url = '[rust-analyzer](https://rust-analyzer.github.io/)',
Expand All @@ -232,7 +246,7 @@ function health.check()
end)
return success
end,
optional = function()
is_optional = function()
return true
end,
url = '[ra-multiplex](https://github.com/pr2502/ra-multiplex)',
Expand All @@ -243,7 +257,7 @@ function health.check()
get_binaries = function()
return { 'cargo' }
end,
optional = function()
is_optional = function()
return true
end,
url = '[Cargo](https://doc.rust-lang.org/cargo/)',
Expand All @@ -258,7 +272,7 @@ function health.check()
get_binaries = function()
return { 'rustc' }
end,
optional = function()
is_optional = function()
return true
end,
url = '[rustc](https://doc.rust-lang.org/rustc/what-is-rustc.html)',
Expand All @@ -275,7 +289,7 @@ function health.check()
get_binaries = function()
return { config.tools.cargo_override }
end,
optional = function()
is_optional = function()
return true
end,
url = '',
Expand Down

0 comments on commit 630c8b0

Please sign in to comment.