Skip to content

Commit 62d1897

Browse files
Only send inlay hint refresh requests on initial load
Editor itself is able to invalidate hints after edits, and /refresh was sent after editor reports changes to the language server. This forces the editor to either query & invalidate the hints twice after every edit, or wait for /refresh to come before querying the hints. Both options are rather useless, so instead, send a request on server startup only: client editors do not know when the server actually starts up, this will help to query the initial hints after editor was open and the server was still starting up.
1 parent b06503b commit 62d1897

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/rust-analyzer/src/global_state.rs

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub(crate) struct GlobalState {
6666

6767
// status
6868
pub(crate) shutdown_requested: bool,
69+
pub(crate) send_hint_refresh_query: bool,
6970
pub(crate) last_reported_status: Option<lsp_ext::ServerStatusParams>,
7071

7172
// proc macros
@@ -177,6 +178,7 @@ impl GlobalState {
177178
mem_docs: MemDocs::default(),
178179
semantic_tokens_cache: Arc::new(Default::default()),
179180
shutdown_requested: false,
181+
send_hint_refresh_query: false,
180182
last_reported_status: None,
181183
source_root_config: SourceRootConfig::default(),
182184
config_errors: Default::default(),

crates/rust-analyzer/src/main_loop.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ impl GlobalState {
317317
}
318318

319319
// Refresh inlay hints if the client supports it.
320-
if self.config.inlay_hints_refresh() {
320+
if (self.send_hint_refresh_query || self.proc_macro_changed)
321+
&& self.config.inlay_hints_refresh()
322+
{
321323
self.send_request::<lsp_types::request::InlayHintRefreshRequest>((), |_, _| ());
324+
self.send_hint_refresh_query = false;
322325
}
323326
}
324327

@@ -509,6 +512,7 @@ impl GlobalState {
509512
}
510513

511514
self.switch_workspaces("fetched build data".to_string());
515+
self.send_hint_refresh_query = true;
512516

513517
(Some(Progress::End), None)
514518
}
@@ -525,7 +529,7 @@ impl GlobalState {
525529
ProcMacroProgress::End(proc_macro_load_result) => {
526530
self.fetch_proc_macros_queue.op_completed(true);
527531
self.set_proc_macros(proc_macro_load_result);
528-
532+
self.send_hint_refresh_query = true;
529533
(Some(Progress::End), None)
530534
}
531535
};

0 commit comments

Comments
 (0)