mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
feat(lsp): vim.lsp.is_enabled() #33703
Problem:
No way to check if a LSP config is enabled without causing it to
resolve. E.g. `vim.lsp.config['…'] ~= nil` will resolve the config,
which could be an unwanted and somewhat expensive side-effect.
Solution:
Introduce `vim.lsp.is_enabled()`.
(cherry picked from commit 03d378fda6
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
3a4d3934c4
commit
4e43264cd3
@@ -1042,6 +1042,15 @@ get_log_path() *vim.lsp.get_log_path()*
|
|||||||
Return: ~
|
Return: ~
|
||||||
(`string`) path to log file
|
(`string`) path to log file
|
||||||
|
|
||||||
|
is_enabled({name}) *vim.lsp.is_enabled()*
|
||||||
|
Checks if the given LSP config is enabled (globally, not per-buffer).
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {name} (`string`) Config name
|
||||||
|
|
||||||
|
Return: ~
|
||||||
|
(`boolean`)
|
||||||
|
|
||||||
omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
|
omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
|
||||||
Implements 'omnifunc' compatible LSP completion.
|
Implements 'omnifunc' compatible LSP completion.
|
||||||
|
|
||||||
|
@@ -174,6 +174,8 @@ API
|
|||||||
• |vim.secure.read()| now returns `true` for trusted directories. Previously
|
• |vim.secure.read()| now returns `true` for trusted directories. Previously
|
||||||
it would return `nil`, which made it impossible to tell if the directory was
|
it would return `nil`, which made it impossible to tell if the directory was
|
||||||
actually trusted.
|
actually trusted.
|
||||||
|
• Added |vim.lsp.is_enabled()| to check if a given LSP config has been enabled
|
||||||
|
by |vim.lsp.enable()|.
|
||||||
|
|
||||||
DEFAULTS
|
DEFAULTS
|
||||||
|
|
||||||
|
@@ -615,6 +615,14 @@ function lsp.enable(name, enable)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Checks if the given LSP config is enabled (globally, not per-buffer).
|
||||||
|
---
|
||||||
|
--- @param name string Config name
|
||||||
|
--- @return boolean
|
||||||
|
function lsp.is_enabled(name)
|
||||||
|
return lsp._enabled_configs[name] ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
--- @class vim.lsp.start.Opts
|
--- @class vim.lsp.start.Opts
|
||||||
--- @inlinedoc
|
--- @inlinedoc
|
||||||
---
|
---
|
||||||
|
@@ -6708,4 +6708,26 @@ describe('LSP', function()
|
|||||||
markers_resolve_to({ 'foo', { 'bar', 'baz' }, 'marker_d' }, dir_b)
|
markers_resolve_to({ 'foo', { 'bar', 'baz' }, 'marker_d' }, dir_b)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('vim.lsp.is_enabled()', function()
|
||||||
|
it('works', function()
|
||||||
|
exec_lua(function()
|
||||||
|
vim.lsp.config('foo', {
|
||||||
|
cmd = { 'foo' },
|
||||||
|
root_markers = { '.foorc' },
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- LSP config defaults to disabled.
|
||||||
|
eq(false, exec_lua([[return vim.lsp.is_enabled('foo')]]))
|
||||||
|
|
||||||
|
-- Confirm we can enable it.
|
||||||
|
exec_lua([[vim.lsp.enable('foo')]])
|
||||||
|
eq(true, exec_lua([[return vim.lsp.is_enabled('foo')]]))
|
||||||
|
|
||||||
|
-- And finally, disable it again.
|
||||||
|
exec_lua([[vim.lsp.enable('foo', false)]])
|
||||||
|
eq(false, exec_lua([[return vim.lsp.is_enabled('foo')]]))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user