Skip to content
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

Merged
merged 1 commit into from
Jan 29, 2024
Merged

Conversation

brookhong
Copy link
Contributor

Remove autocmd BufReadPost on LspStop so that lsp won't be auto started on buf read after explicit stop with LspStop.

@@ -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)
Copy link
Member

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.

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

Copy link
Contributor Author

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.

lua/lspconfig/configs.lua Outdated Show resolved Hide resolved
@@ -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)
Copy link
Member

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
Copy link
Member

@justinmk justinmk Jan 29, 2024

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 justinmk changed the title Remove autocmd BufReadPost on LspStop so that lsp won't be auto start… fix: disable autostart after :LspStop Jan 29, 2024
@justinmk justinmk merged commit d1d8b8a into neovim:master Jan 29, 2024
9 checks passed
@artkpv
Copy link

artkpv commented Dec 10, 2024

@justinmk , @glepnir Thank you for this tool.

I wish to stop Lsp in my personal wiki. I start it with

 nvim -c 'cd ~/mydir/notes' -c WikiEnable  -c 'lua vim.g.init_my_wiki_config()' "$@"

Where this funciton there is

--- Inside my Lazy config for my wiki pluging (https://github.com/lervag/wiki.vim)
    'lervag/wiki.vim',
    lazy = false, -- we don't want to lazy load VimTeX
    config = function()
      vim.g.init_my_wiki_config = function()
        --- ...
        vim.cmd 'LspStop'
       end
    end

It works for my first buffer I open. But when I move to another buffer (.md) the lsp starts. And I need to enter :LspStop. Then the lsp doesn't start for other buffers.

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 :LspStop each time I open another buffer. Is there some flag like 'disable_lsp' or something to do that?

@glepnir
Copy link
Member

glepnir commented Dec 11, 2024

which server you used for wiki.vim find it and set auto_start =false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants