Skip to content

Commit 630c8b0

Browse files
committed
feat(health): don't warn if nvim-dap is not configured
1 parent 5d993d3 commit 630c8b0

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

lua/rustaceanvim/health.lua

+27-13
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ local health = {}
55
local h = vim.health
66

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

1315
---@type rustaceanvim.LuaDependency[]
1416
local lua_dependencies = {
1517
{
18+
name = 'nvim-dap',
1619
module = 'dap',
17-
optional = function()
20+
is_optional = function()
1821
return true
1922
end,
23+
is_configured = function()
24+
local rustaceanvim_opts = type(vim.g.rustaceanvim) == 'function' and vim.g.rustaceanvim()
25+
or vim.g.rustaceanvim
26+
or {}
27+
local dap_opts = vim.tbl_get(rustaceanvim_opts, 'dap')
28+
return type(dap_opts) == 'table'
29+
end,
2030
url = '[mfussenegger/nvim-dap](https://github.com/mfussenegger/nvim-dap)',
2131
info = 'Needed for debugging features',
2232
},
@@ -27,7 +37,7 @@ local lua_dependencies = {
2737
---@field required_version_spec? string Version range spec. See `vim.version.range()`
2838
---@field get_binaries fun():string[] Function that returns the binaries to check for
2939
---@field is_installed? fun(bin: string):boolean Default: `vim.fn.executable(bin) == 1`
30-
---@field optional fun():boolean Function that returns whether the dependency is optional
40+
---@field is_optional fun():boolean Function that returns whether the dependency is optional
3141
---@field url string URL (markdown)
3242
---@field info string Additional information
3343
---@field extra_checks_if_installed? fun(bin: string) Optional extra checks to perform if the dependency is installed
@@ -39,10 +49,14 @@ local function check_lua_dependency(dep)
3949
h.ok(dep.url .. ' installed.')
4050
return
4151
end
42-
if dep.optional() then
43-
h.warn(('%s not installed. %s %s'):format(dep.module, dep.info, dep.url))
52+
if dep.is_optional() then
53+
if dep.is_configured() then
54+
h.warn(('optional dependency %s is configured, but not installed. %s %s'):format(dep.name, dep.info, dep.url))
55+
else
56+
h.ok(('optional dependency %s not installed. %s %s'):format(dep.name, dep.info, dep.url))
57+
end
4458
else
45-
error(('Lua dependency %s not found: %s'):format(dep.module, dep.url))
59+
error(('Lua dependency %s not found: %s'):format(dep.name, dep.url))
4660
end
4761
end
4862

@@ -94,7 +108,7 @@ local function check_external_dependency(dep)
94108
end
95109
return
96110
end
97-
if not dep.optional() then
111+
if not dep.is_optional() then
98112
h.error(([[
99113
%s: not found: %s
100114
rustaceanvim requires %s.
@@ -209,7 +223,7 @@ function health.check()
209223
end)
210224
return success
211225
end,
212-
optional = function()
226+
is_optional = function()
213227
return false
214228
end,
215229
url = '[rust-analyzer](https://rust-analyzer.github.io/)',
@@ -232,7 +246,7 @@ function health.check()
232246
end)
233247
return success
234248
end,
235-
optional = function()
249+
is_optional = function()
236250
return true
237251
end,
238252
url = '[ra-multiplex](https://github.com/pr2502/ra-multiplex)',
@@ -243,7 +257,7 @@ function health.check()
243257
get_binaries = function()
244258
return { 'cargo' }
245259
end,
246-
optional = function()
260+
is_optional = function()
247261
return true
248262
end,
249263
url = '[Cargo](https://doc.rust-lang.org/cargo/)',
@@ -258,7 +272,7 @@ function health.check()
258272
get_binaries = function()
259273
return { 'rustc' }
260274
end,
261-
optional = function()
275+
is_optional = function()
262276
return true
263277
end,
264278
url = '[rustc](https://doc.rust-lang.org/rustc/what-is-rustc.html)',
@@ -275,7 +289,7 @@ function health.check()
275289
get_binaries = function()
276290
return { config.tools.cargo_override }
277291
end,
278-
optional = function()
292+
is_optional = function()
279293
return true
280294
end,
281295
url = '',

0 commit comments

Comments
 (0)