Skip to content

Commit 7e0ee0a

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 7e0ee0a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,12 @@ impl GlobalState {
223223

224224
for progress in prime_caches_progress {
225225
let (state, message, fraction);
226-
match progress {
226+
let should_refresh = match progress {
227227
PrimeCachesProgress::Begin => {
228228
state = Progress::Begin;
229229
message = None;
230230
fraction = 0.0;
231+
false
231232
}
232233
PrimeCachesProgress::Report(report) => {
233234
state = Progress::Report;
@@ -248,6 +249,7 @@ impl GlobalState {
248249
};
249250

250251
fraction = Progress::fraction(report.crates_done, report.crates_total);
252+
false
251253
}
252254
PrimeCachesProgress::End { cancelled } => {
253255
state = Progress::End;
@@ -259,10 +261,21 @@ impl GlobalState {
259261
self.prime_caches_queue
260262
.request_op("restart after cancellation".to_string(), ());
261263
}
264+
!cancelled
262265
}
263266
};
264267

265268
self.report_progress("Indexing", state, message, Some(fraction), None);
269+
if should_refresh && self.config.inlay_hints_refresh() {
270+
// Refresh inlay hints if the client supports it.
271+
// Hint /refresh invalidates all hints globally, so do not send the queries after regular changes:
272+
// client editors are capable of invalidating the hints locally after the change.
273+
// But do send the /refresh request when the server [re]started — the client has no good way of knowing that.
274+
self.send_request::<lsp_types::request::InlayHintRefreshRequest>(
275+
(),
276+
|_, _| (),
277+
);
278+
}
266279
}
267280
}
268281
Event::Vfs(message) => {
@@ -315,11 +328,6 @@ impl GlobalState {
315328
if self.config.code_lens_refresh() {
316329
self.send_request::<lsp_types::request::CodeLensRefresh>((), |_, _| ());
317330
}
318-
319-
// Refresh inlay hints if the client supports it.
320-
if self.config.inlay_hints_refresh() {
321-
self.send_request::<lsp_types::request::InlayHintRefreshRequest>((), |_, _| ());
322-
}
323331
}
324332

325333
let update_diagnostics = (!was_quiescent || state_changed || memdocs_added_or_removed)

0 commit comments

Comments
 (0)