Skip to content

Commit 6e52c64

Browse files
committed
Auto merge of #13985 - Veykril:content-modified, r=Veykril
Don't respond with a ContentModified while loading the workspace Initially this was done to prevent frequent inlay hint flickering, but this causes a lot of problems for a bunch of clients. We can (and already kind of have) move this into the semantic token request handlers instead. Fixes #10910
2 parents 56fb0ca + 7385467 commit 6e52c64

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

crates/rust-analyzer/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,10 @@ impl Config {
14381438
try_or_def!(self.caps.workspace.as_ref()?.code_lens.as_ref()?.refresh_support?)
14391439
}
14401440

1441+
pub fn inlay_hints_refresh(&self) -> bool {
1442+
try_or_def!(self.caps.workspace.as_ref()?.inlay_hint.as_ref()?.refresh_support?)
1443+
}
1444+
14411445
pub fn insert_replace_support(&self) -> bool {
14421446
try_or_def!(
14431447
self.caps

crates/rust-analyzer/src/handlers.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,8 @@ pub(crate) fn handle_semantic_tokens_full(
14701470

14711471
let mut highlight_config = snap.config.highlighting_config();
14721472
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
1473-
highlight_config.syntactic_name_ref_highlighting = !snap.proc_macros_loaded;
1473+
highlight_config.syntactic_name_ref_highlighting =
1474+
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
14741475

14751476
let highlights = snap.analysis.highlight(highlight_config, file_id)?;
14761477
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
@@ -1493,7 +1494,8 @@ pub(crate) fn handle_semantic_tokens_full_delta(
14931494

14941495
let mut highlight_config = snap.config.highlighting_config();
14951496
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
1496-
highlight_config.syntactic_name_ref_highlighting = !snap.proc_macros_loaded;
1497+
highlight_config.syntactic_name_ref_highlighting =
1498+
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
14971499

14981500
let highlights = snap.analysis.highlight(highlight_config, file_id)?;
14991501
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
@@ -1524,7 +1526,12 @@ pub(crate) fn handle_semantic_tokens_range(
15241526
let text = snap.analysis.file_text(frange.file_id)?;
15251527
let line_index = snap.file_line_index(frange.file_id)?;
15261528

1527-
let highlights = snap.analysis.highlight_range(snap.config.highlighting_config(), frange)?;
1529+
let mut highlight_config = snap.config.highlighting_config();
1530+
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
1531+
highlight_config.syntactic_name_ref_highlighting =
1532+
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
1533+
1534+
let highlights = snap.analysis.highlight_range(highlight_config, frange)?;
15281535
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
15291536
Ok(Some(semantic_tokens.into()))
15301537
}

crates/rust-analyzer/src/main_loop.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ impl GlobalState {
307307
if self.config.code_lens_refresh() {
308308
self.send_request::<lsp_types::request::CodeLensRefresh>((), |_, _| ());
309309
}
310+
311+
// Refresh inlay hints if the client supports it.
312+
if self.config.inlay_hints_refresh() {
313+
self.send_request::<lsp_types::request::InlayHintRefreshRequest>((), |_, _| ());
314+
}
310315
}
311316

312317
if (!was_quiescent || state_changed || memdocs_added_or_removed)
@@ -606,25 +611,16 @@ impl GlobalState {
606611
Ok(())
607612
});
608613

609-
if let RequestDispatcher { req: Some(req), global_state: this } = &mut dispatcher {
610-
if this.shutdown_requested {
614+
match &mut dispatcher {
615+
RequestDispatcher { req: Some(req), global_state: this } if this.shutdown_requested => {
611616
this.respond(lsp_server::Response::new_err(
612617
req.id.clone(),
613618
lsp_server::ErrorCode::InvalidRequest as i32,
614619
"Shutdown already requested.".to_owned(),
615620
));
616621
return;
617622
}
618-
619-
// Avoid flashing a bunch of unresolved references during initial load.
620-
if this.workspaces.is_empty() && !this.is_quiescent() {
621-
this.respond(lsp_server::Response::new_err(
622-
req.id.clone(),
623-
lsp_server::ErrorCode::ContentModified as i32,
624-
"waiting for cargo metadata or cargo check".to_owned(),
625-
));
626-
return;
627-
}
623+
_ => (),
628624
}
629625

630626
dispatcher

0 commit comments

Comments
 (0)