-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: allow conditional attachment of LSP servers #3302
Conversation
emm i think there has a way to do . vim.api.nvim_create_autocmd('LspAttach' ,
callback = function(args)
local bufnr = args.buf
local bufname = vim.api.nvim_buf_get_name(bufnr)
if should_not_attach then
vim.lsp.buf_detach_client(bufnr, args.data.client_id)
end
end
|
same answer as before #2477 (comment) nvim-lspconfig is a bunch of configs. It's not a platform. It is not going to continue gaining random features. Use |
Like I said in my PR, there isn't currently a good way of doing this. Starting the LSP and then stopping it again is not an ideal solution.
lspconfig already has a bunch of code that handles launching of servers so the user doesn't need to worry about the technicalities of it. Using vim.lsp.start() directly would probably involve a bunch more custom code the user needs to write (and have the time and knowledge to know how to write). This PR only adds a few lines of code (really just 3) and solves this problem for these users. I don't really see how that can be a bad thing 🙂 |
this is not stop any client it just remove buffer of client on_attach |
Actually I tried that code but it doesn't seem to work. I just get an error (even after putting the callback in braces). |
wrap in |
Thanks, that worked. So just to clarify, this will stop the server from ever starting, correct? If this is the case then it seems to achieve the same goal as my code change. Given that this the solution you provided is robust, would it be a good idea to document it somewhere (perhaps in a FAQ if we have one)? |
The docs seem to say that LspAttach is triggered after an LSP client attaches to a buffer. That would make me think that the server was already started, unless the autocommands are run before doing that. |
This will not prevent the server process from starting. It will just remove the buffer from the server's attatched_buffers. If you want to stop the client after remove buffer from server add check continue like If you want more detailed control over the start and stop of the server, please read lsp is asynchronous in the editor. There is an event loop queue scheduling. |
This PR adds the ability for users to conditionally attach an LSP server to a buffer based on a user provided function that will be evaluated. This functionality is useful for disabling an LSP server for a particular project, or for files in a particular subdirectory. Currently there is no good way of doing this.
With this addition, disabling an LSP for a given project is easy:
Then in the project's
.exrc
file the following can be added:Related issues: