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

Keep server running without a related source file open? #2387

Open
LPGhatguy opened this issue Oct 6, 2023 · 6 comments
Open

Keep server running without a related source file open? #2387

LPGhatguy opened this issue Oct 6, 2023 · 6 comments

Comments

@LPGhatguy
Copy link

Hello! Thank you for maintaining this project, it's been super helpful.

This has been a difficult issue to figure out and it's made me feel like I'm going insane recently. I apologize if this report is unclear and I'm willing to help track this down!

Bug Description

Once the server is running, everything runs smoothly in my editor, even when editing files in multiple crates within a workspace.

However, if I close all of my currently open Rust files and open a Rust file in a different crate within the same workspace, it seems like the rust-analyzer server gets restarted. In my workspace, this takes a long time and makes the LSP appear to be broken.

If I close the file and then open a file within the same crate, the server does not get restarted.

As a workaround, I can keep a Rust file from any of the project's crates open forever, which keeps the server from ever getting restarted.

Video of Bug Happening

Here is a video of the issue, which might help demonstrate what I'm running into:

sublime_text_fK0BQDzy3W.mp4

I start off with a file open in the root crate in my workspace. The server is up and running and completion is working.

I close that file and open a file in a different crate within the same workspace, located in crates/gui. My CPU fan spins up and my status bar indicates that rust-analyzer is re-checking and indexing my workspace again! Completion doesn't work in the new file for up to 30 seconds!

If I keep the first file open instead of closing it and open the second file, the server does not re-index and completion works instantly. Here is a video of that:

sublime_text_MKvAfyeexw.mp4
@rchl
Copy link
Member

rchl commented Oct 6, 2023

This is a standard behavior of https://github.com/sublimelsp/LSP that the server is closed after few seconds once the last file using it is closed. This is to not keep unused servers in memory taking space unnecessarily.

In my personal workflow I tend to always keep some files open and don't clean up the whole workspace before opening a new file. And I imagine this to be the most common flow since there seems to be little benefit in closing all files IMO.

Not sure what would be a satisfying solution for you? Maybe just extending the time before the server shutsdown to 30s or so?

@LPGhatguy
Copy link
Author

VS Code does not have this issue, at least with rust-analyzer. Once a Rust file is opened in a workspace, the server is started and it isn't closed until the workspace is closed. I think this is a significantly better behavior.

This is a standard behavior of https://github.com/sublimelsp/LSP that the server is closed after few seconds once the last file using it is closed. This is to not keep unused servers in memory taking space unnecessarily.

Is that behavior implemented in the LSP extension, or here, in LSP-rust-analyzer?

In my personal workflow I tend to always keep some files open and don't clean up the whole workspace before opening a new file. And I imagine this to be the most common flow since there seems to be little benefit in closing all files IMO.

I don't think it's that uncommon. Once I've completed working on one task, especially within one part of the codebase, it's nice to be able to clear my plate and close some files. Waiting for the server to start back up again is not fun.

Not sure what would be a satisfying solution for you? Maybe just extending the time before the server shutsdown to 30s or so?

I don't think the server should shut down at all in this case. If I have a Rust project open, I am likely to work in that Rust project and use the LSP features. If I am done working on the project, I'll close it. Especially in a large project, the cost of restarting the server is extremely high.

If there was a setting to keep the server running as long as I have a Rust project open, that would be ideal to me.

@rchl
Copy link
Member

rchl commented Oct 7, 2023

If there was a setting to keep the server running as long as I have a Rust project open, that would be ideal to me.

There could be a global setting that changes the current behavior. It would affect all servers though.

Alternatively there could be a per-server setting to decide that.

Some servers like LSP-json start very fast and are not really project-aware so in those cases it shouldn't be noticeable if those are closed so maybe a per-server setting makes more sense.

@LPGhatguy
Copy link
Author

I've opened an issue in the LSP repo about the possibility of having that setting.

@rwols
Copy link
Member

rwols commented Oct 10, 2023

Related, and the root cause: rust-lang/rust-analyzer#4712

@LPGhatguy
Copy link
Author

I tried configuring ra-multiplex, the workaround folks have mentioned in rust-lang/rust-analyzer#4712.

I wasn't able to get it running in Sublime Text on my system. I'm not sure if it's a Windows compatibility issue, something with the LSP mechanism, or something I didn't do correctly.

@rchl rchl transferred this issue from sublimelsp/LSP-rust-analyzer Jan 3, 2024
@rchl rchl changed the title Keep server running without a Rust source file open? Keep server running without a related source file open? Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants