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

[FEATURE] LSPs do not stop when switching session to another project #208

Closed
rmagatti opened this issue Mar 2, 2023 · 7 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@rmagatti
Copy link
Owner

rmagatti commented Mar 2, 2023

Is your feature request related to a problem? Please describe.
When switching from a lua project to a typescript project for example, then running LspInfo we can see both tsserver and lua_ls active. This isn't really a session concern theoretically, maybe I can implement this feature with the hooks feature, but since LSPs are built-into Neovim, it may make sense to have some support within auto-session.

Screenshot 2023-03-01 at 10 23 37 PM

I worry how much this crosses into "project management" or "specific plugin" territory, but still worth considering.

Describe the solution you'd like
That LSPs for the previously loaded session gets shut down just like buffers from a previously loaded sessions do when switching sessions.

Describe alternatives you've considered
Using pre and or post hooks to explicitly call to shutdown lsp servers before a next load of a session happens.

Additional context
N/A

@rmagatti rmagatti added the enhancement New feature or request label Mar 2, 2023
@rmagatti rmagatti self-assigned this Mar 2, 2023
@adaviloper
Copy link

After enabling this plugin, I've noticed that LSPs also do not start after a session is loaded. I've tried using the post_restore_cmds to run LspStart, but the command doesn't seem to exist yet (I'm using Lazy).
If I switch to a different file, the LSPs start up, but if I switch back to the first file that was opened, the LSP is still inactive.

@rmagatti
Copy link
Owner Author

@adaviloper that would be something with your configuration specifically. In my config the lsp starts normally after the session is loaded.

@mixtli
Copy link

mixtli commented Jun 28, 2024

I get the same behavior FYI. Not sure how to track it down really.

@mixtli
Copy link

mixtli commented Jun 28, 2024

Hmm. Setting this seems to fix it:

		cwd_change_handling = {
			restore_upcoming_session = false, -- <-- THE DOCS LIE!! This is necessary!!
		},

@cameronr
Copy link
Collaborator

@rmagatti we could do something like the following in RestoreSessionFile:

        local clients = vim.lsp.get_clients()
        if #clients > 0 then vim.lsp.stop_client(clients) end

the only downside is that vim.lsp.get_clients() seems to take a small amount of time and that is noticeable when launching nvim (prolly not noticeable otherwise). we could plumb through that an autorestore is happening on startup and not do it in that case.

do you think it's worth the trouble?

@rmagatti
Copy link
Owner Author

@rmagatti we could do something like the following in RestoreSessionFile:

        local clients = vim.lsp.get_clients()
        if #clients > 0 then vim.lsp.stop_client(clients) end

the only downside is that vim.lsp.get_clients() seems to take a small amount of time and that is noticeable when launching nvim (prolly not noticeable otherwise). we could plumb through that an autorestore is happening on startup and not do it in that case.

do you think it's worth the trouble?

It might be worthwhile having something like this behind a default false config to start.
And yes, we'd need to exempt startup auto-restore from kicking off lsp calls.

Something that comes to mind is that not everyone uses vim builtin lsp, which means this config would benefit from being a boolean|function type that executes the function the user provides instead of the builtin function (which should be vim.lsp only) to interact with the LSP.

cameronr added a commit that referenced this issue Nov 27, 2024
Fix: #208 stop LSs when restoring session
@cameronr
Copy link
Collaborator

If you want to stop previous language servers when restoring another session add lsp_stop_on_restore = false, to your auto-session config.

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

No branches or pull requests

4 participants