Skip to content

Commit df6ce96

Browse files
committed
Auto merge of rust-lang#17886 - Wilfred:prime_caches_quiescent, r=Veykril
internal: ServerStatusParams should consider 'prime caches' in quiescent status Priming caches is a performance win, but it takes a lock on the salsa database and prevents rust-analyzer from responding to e.g. go-to-def requests. This causes confusion for users, who see the spinner next to rust-analyzer in the VS Code footer stop, so they start attempting to navigate their code. Instead, set the `quiescent` status in LSP to false during cache priming, so the VS Code spinner persists until we can respond to any LSP request.
2 parents f9c0c8a + f25cb80 commit df6ce96

File tree

1 file changed

+19
-4
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src

1 file changed

+19
-4
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ pub(crate) enum ProcMacroProgress {
6161
}
6262

6363
impl GlobalState {
64+
/// Is the server quiescent?
65+
///
66+
/// This indicates that we've fully loaded the projects and
67+
/// are ready to do semantic work.
6468
pub(crate) fn is_quiescent(&self) -> bool {
6569
self.vfs_done
6670
&& self.last_reported_status.is_some()
@@ -71,6 +75,15 @@ impl GlobalState {
7175
&& self.vfs_progress_config_version >= self.vfs_config_version
7276
}
7377

78+
/// Is the server ready to respond to analysis dependent LSP requests?
79+
///
80+
/// Unlike `is_quiescent`, this returns false when we're indexing
81+
/// the project, because we're holding the salsa lock and cannot
82+
/// respond to LSP requests that depend on salsa data.
83+
fn is_fully_ready(&self) -> bool {
84+
self.is_quiescent() && !self.prime_caches_queue.op_in_progress()
85+
}
86+
7487
pub(crate) fn update_configuration(&mut self, config: Config) {
7588
let _p = tracing::info_span!("GlobalState::update_configuration").entered();
7689
let old_config = mem::replace(&mut self.config, Arc::new(config));
@@ -102,13 +115,15 @@ impl GlobalState {
102115
}
103116

104117
pub(crate) fn current_status(&self) -> lsp_ext::ServerStatusParams {
105-
let quiescent = self.is_quiescent();
106-
let mut status =
107-
lsp_ext::ServerStatusParams { health: lsp_ext::Health::Ok, quiescent, message: None };
118+
let mut status = lsp_ext::ServerStatusParams {
119+
health: lsp_ext::Health::Ok,
120+
quiescent: self.is_fully_ready(),
121+
message: None,
122+
};
108123
let mut message = String::new();
109124

110125
if !self.config.cargo_autoreload(None)
111-
&& quiescent
126+
&& self.is_quiescent()
112127
&& self.fetch_workspaces_queue.op_requested()
113128
&& self.config.discover_workspace_config().is_none()
114129
{

0 commit comments

Comments
 (0)