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

clear LSP clients #2

Open
willthbill opened this issue Feb 11, 2022 · 3 comments
Open

clear LSP clients #2

willthbill opened this issue Feb 11, 2022 · 3 comments

Comments

@willthbill
Copy link
Owner

willthbill commented Feb 11, 2022

I might be interested in clearing LSP clients, so that old LSP clients does not keep on running in the background after opening a new directory.
I have implemented the simplest fix on branch clear-lsp-clients, but it seems to give session-related problems (see b58b760)
More specifically regarding auto-session if I stop all LSP clients and then restores a session that was saved while an LSP client was active I get an error.

Error detected while processing CursorMoved Autocommands for "<buffer=7>":
method textDocument/documentHighlight is not supported by any of the servers registered for the current buffer

I have the following setup of opener.nvim, which means that LSP clients are stopped and they immediatly after RestoreSession is called.

require("opener").setup {
     pre_open = function()
        vim.cmd "SaveSession"
    end,
    post_open = function(dir)
        local Lib = require "auto-session-library"
        Lib.conf.last_loaded_session = nil
        vim.cmd "RestoreSession"
    end,
}

This is of course due to no LSP client being active at the time of restoring, but is that really necessary to restore a session?

willthbill added a commit that referenced this issue Feb 11, 2022
If an auto-session session is restored in the post-open hook, then
an error may be throw related to that no LSP client is available.
This is because the LSP clients takes a while to start.

Related to #2
@willthbill
Copy link
Owner Author

@rmagatti Do you have any thoughts on this. Could it be a potential bug in auto-session? Or am I missing a simple fix. I don't understand all the technical details of how sessions work.

@rmagatti
Copy link

This is more because the autocmd for CursorMoved is still registered and it gets triggered, but you've stopped the clients. It's kind of unrelated to session saving altogether, it's just that by killing the lsp clients yourself but not unregistering whatever autocmds use the clients you end up running into this.

Also I thought lsp clients wouldn't keep running in the background if there is no buffer for them to attach to, but idk if that's accurate.

@willthbill
Copy link
Owner Author

That makes sense.
Unfortunately it seems that automatically shutting down clients/servers (idk what to call them, clients that communicate with a server) is on the 0.9 todos neovim/neovim#14430

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

No branches or pull requests

2 participants