-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
feat(lsp): vim.lsp.is_enabled() #33703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objection, wait to hear from @mfussenegger and others
4f2122e
to
ac0d2d9
Compare
--- @param name string Config name | ||
--- @return boolean | ||
function lsp.is_enabled(name) | ||
return lsp._enabled_configs[name] ~= nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lewis6991 will know better but I think that we should also check lsp.config._configs['*']
here (in case the LSP server was configured with vim.lsp.config('*', ...)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*
is a weird case. I don't think we need to check for it here.
I'm like warm about this, but don't strongly object. Functions like this will become irrelevant if we ever decide to create a |
good point. though they might still be relevant if they have advanced filters like unfortunately, it may be awhile before we have "dict options", which are likely needed for this and treesitter. |
runtime/lua/vim/lsp.lua
Outdated
@@ -594,6 +594,14 @@ function lsp.enable(name, enable) | |||
}) | |||
end | |||
|
|||
--- Checks if the given LSP config is enabled or not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--- Checks if the given LSP config is enabled or not. | |
--- Checks if the given LSP config is enabled (globally, not per-buffer). | |
--- | |
--- Note: "configs" are _used by_ "clients", which attach to buffers. | |
--- Use |vim.lsp.get_clients()| to check active LSP clients for a given buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Just wondering: this phrasing sort of implies that you can enable/disable a LSP config per buffer. Is that possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the phrasing is intended to avoid confusion by being explicit. Clients are enabled per-buffer, and it's likely that users will get that confused with configs, which are (roughly) global.
My thought was that an |
c983711
to
0af3693
Compare
needs a news.txt item |
Justification: I want to be able to toggle some LSPs on/off, and I'd like to be able to do that without having to reach into `lsp.lua` internals like `lsp._enabled_configs`.
done! |
This is somewhat redundant with |
vim.lsp.is_enabled
Successfully created backport PR for |
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 03d378f)
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 03d378f)
Justification: I want to be able to toggle some LSPs on/off (see #33702), and I'd like to be able to do that without having to reach into
lsp.lua
internals likelsp._enabled_configs
.