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
This commit is contained in:
bors 2023-01-19 21:00:26 +00:00
commit 6e52c64031
3 changed files with 22 additions and 15 deletions

View File

@ -1438,6 +1438,10 @@ pub fn code_lens_refresh(&self) -> bool {
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

View File

@ -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()))
}

View File

@ -307,6 +307,11 @@ fn handle_event(&mut self, event: Event) -> Result<()> {
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 @@ fn on_request(&mut self, req: Request) {
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 @@ fn on_request(&mut self, req: Request) {
));
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