Skip to content

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

Merged
merged 1 commit into from
May 3, 2025
Merged

Conversation

jfly
Copy link
Contributor

@jfly jfly commented Apr 29, 2025

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 like lsp._enabled_configs.

@github-actions github-actions bot added the lsp label Apr 29, 2025
@github-actions github-actions bot requested a review from MariaSolOs April 29, 2025 02:05
Copy link
Member

@justinmk justinmk left a 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

@jfly jfly force-pushed the add-is-enabled branch 2 times, most recently from 4f2122e to ac0d2d9 Compare April 30, 2025 00:19
--- @param name string Config name
--- @return boolean
function lsp.is_enabled(name)
return lsp._enabled_configs[name] ~= nil
Copy link
Member

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('*', ...).

Copy link
Member

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.

@lewis6991
Copy link
Member

lewis6991 commented Apr 30, 2025

I'm like warm about this, but don't strongly object.

Functions like this will become irrelevant if we ever decide to create a 'lsp' buffer option, which would probably change the dynamics of how people think about this subject.

@justinmk
Copy link
Member

Functions like this will become irrelevant if we ever decide to create a 'lsp' buffer option, which would probably change the dynamics of how people think about this subject.

good point. though they might still be relevant if they have advanced filters like vim.diagnostic.is_enabled() .

unfortunately, it may be awhile before we have "dict options", which are likely needed for this and treesitter.

@@ -594,6 +594,14 @@ function lsp.enable(name, enable)
})
end

--- Checks if the given LSP config is enabled or not.
Copy link
Member

@justinmk justinmk Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--- 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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@lewis6991
Copy link
Member

My thought was that an lsp option could just be a comma separated string of server names and can be appended to in FileType autocmds.

@jfly jfly force-pushed the add-is-enabled branch 2 times, most recently from c983711 to 0af3693 Compare May 1, 2025 18:54
@justinmk
Copy link
Member

justinmk commented May 2, 2025

needs a news.txt item

@jfly jfly force-pushed the add-is-enabled branch from 0af3693 to 518dddc Compare May 2, 2025 18:37
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`.
@jfly jfly force-pushed the add-is-enabled branch from 518dddc to b477703 Compare May 2, 2025 18:38
@jfly
Copy link
Contributor Author

jfly commented May 2, 2025

needs a news.txt item

done!

@justinmk justinmk merged commit 03d378f into neovim:master May 3, 2025
31 checks passed
@justinmk
Copy link
Member

justinmk commented May 3, 2025

This is somewhat redundant with vim.lsp.config['foo'], but that forces loading/resolving the config, so I guess is_enabled is needed.

@justinmk justinmk changed the title feat(lsp): add a vim.lsp.is_enabled feat(lsp): vim.lsp.is_enabled() May 3, 2025
@neovim-backports
Copy link

Successfully created backport PR for release-0.11:

github-actions bot pushed a commit that referenced this pull request May 3, 2025
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)
github-actions bot pushed a commit that referenced this pull request May 3, 2025
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants