-
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
fix: disable autostart after :LspStop #2987
Conversation
@@ -136,7 +137,7 @@ function configs.__newindex(t, config_name, config_def) | |||
end | |||
|
|||
if root_dir then | |||
api.nvim_create_autocmd('BufReadPost', { | |||
buf_read_post_autocmd_id = api.nvim_create_autocmd('BufReadPost', { | |||
pattern = fn.fnameescape(root_dir) .. '/*', | |||
callback = function(arg) | |||
M.manager:try_add_wrapper(arg.buf, root_dir) |
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.
Can the callback check if the client was force stopped? Then it can return true
, which will automatically remove the autocmd.
M.manager:try_add_wrapper(arg.buf, root_dir) | |
if client.is_stopped -- psuedocode | |
return true | |
end | |
M.manager:try_add_wrapper(arg.buf, root_dir) |
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.
Nice, with this addressed, other two comments should be also good.
Thanks, updated.
plugin/lspconfig.lua
Outdated
@@ -144,6 +144,10 @@ api.nvim_create_user_command('LspStop', function(info) | |||
client.stop(force) | |||
end | |||
end | |||
local matching_configs = require('lspconfig.util').get_config_by_ft(vim.bo.filetype) |
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.
This seems fragile. OTOH, I guess LspStop
itself is kind of a hack so...
so that lsp won't be auto started on buf read after explicit stop with LspStop.
@@ -139,6 +139,9 @@ function configs.__newindex(t, config_name, config_def) | |||
api.nvim_create_autocmd('BufReadPost', { | |||
pattern = fn.fnameescape(root_dir) .. '/*', | |||
callback = function(arg) | |||
if #M.manager:clients() == 0 then | |||
return true | |||
end |
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.
I was hoping there is a way to checking that the clients were force-stopped. Could there be an edge case where the client dies because of an error, which would then (unintentionally) remove this autocmd?
I guess we can try this. LspStart
will recreate this autocmd again.
@justinmk , @glepnir Thank you for this tool. I wish to stop Lsp in my personal wiki. I start it with
Where this funciton there is
It works for my first buffer I open. But when I move to another buffer (.md) the lsp starts. And I need to enter How to stop the lsp? Expected behavior: my function there in my config in init.lua stops the lsp and I don't need to type |
which server you used for wiki.vim find it and set auto_start =false. |
Remove autocmd BufReadPost on LspStop so that lsp won't be auto started on buf read after explicit stop with LspStop.