Unnamed repository; edit this file 'description' to name the repository.
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 https://github.com/rust-lang/rust-analyzer/issues/10910
bors 2023-01-20
parent 56fb0ca · parent 7385467 · commit 6e52c64
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--crates/rust-analyzer/src/handlers.rs13
-rw-r--r--crates/rust-analyzer/src/main_loop.rs20
3 files changed, 22 insertions, 15 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 9ea042b423..fd2f934f9f 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -1438,6 +1438,10 @@ impl Config {
try_or_def!(self.caps.workspace.as_ref()?.code_lens.as_ref()?.refresh_support?)
}
+ pub fn inlay_hints_refresh(&self) -> bool {
+ try_or_def!(self.caps.workspace.as_ref()?.inlay_hint.as_ref()?.refresh_support?)
+ }
+
pub fn insert_replace_support(&self) -> bool {
try_or_def!(
self.caps
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 033ef75cca..33ca781066 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1470,7 +1470,8 @@ pub(crate) fn handle_semantic_tokens_full(
let mut highlight_config = snap.config.highlighting_config();
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
- highlight_config.syntactic_name_ref_highlighting = !snap.proc_macros_loaded;
+ highlight_config.syntactic_name_ref_highlighting =
+ snap.workspaces.is_empty() || !snap.proc_macros_loaded;
let highlights = snap.analysis.highlight(highlight_config, file_id)?;
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
@@ -1493,7 +1494,8 @@ pub(crate) fn handle_semantic_tokens_full_delta(
let mut highlight_config = snap.config.highlighting_config();
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
- highlight_config.syntactic_name_ref_highlighting = !snap.proc_macros_loaded;
+ highlight_config.syntactic_name_ref_highlighting =
+ snap.workspaces.is_empty() || !snap.proc_macros_loaded;
let highlights = snap.analysis.highlight(highlight_config, file_id)?;
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
@@ -1524,7 +1526,12 @@ pub(crate) fn handle_semantic_tokens_range(
let text = snap.analysis.file_text(frange.file_id)?;
let line_index = snap.file_line_index(frange.file_id)?;
- let highlights = snap.analysis.highlight_range(snap.config.highlighting_config(), frange)?;
+ let mut highlight_config = snap.config.highlighting_config();
+ // Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
+ highlight_config.syntactic_name_ref_highlighting =
+ snap.workspaces.is_empty() || !snap.proc_macros_loaded;
+
+ let highlights = snap.analysis.highlight_range(highlight_config, frange)?;
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
Ok(Some(semantic_tokens.into()))
}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index b00107c69a..4290b77606 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -307,6 +307,11 @@ impl GlobalState {
if self.config.code_lens_refresh() {
self.send_request::<lsp_types::request::CodeLensRefresh>((), |_, _| ());
}
+
+ // Refresh inlay hints if the client supports it.
+ if self.config.inlay_hints_refresh() {
+ self.send_request::<lsp_types::request::InlayHintRefreshRequest>((), |_, _| ());
+ }
}
if (!was_quiescent || state_changed || memdocs_added_or_removed)
@@ -606,8 +611,8 @@ impl GlobalState {
Ok(())
});
- if let RequestDispatcher { req: Some(req), global_state: this } = &mut dispatcher {
- if this.shutdown_requested {
+ match &mut dispatcher {
+ RequestDispatcher { req: Some(req), global_state: this } if this.shutdown_requested => {
this.respond(lsp_server::Response::new_err(
req.id.clone(),
lsp_server::ErrorCode::InvalidRequest as i32,
@@ -615,16 +620,7 @@ impl GlobalState {
));
return;
}
-
- // Avoid flashing a bunch of unresolved references during initial load.
- if this.workspaces.is_empty() && !this.is_quiescent() {
- this.respond(lsp_server::Response::new_err(
- req.id.clone(),
- lsp_server::ErrorCode::ContentModified as i32,
- "waiting for cargo metadata or cargo check".to_owned(),
- ));
- return;
- }
+ _ => (),
}
dispatcher