Skip to content

Commit 643c3a5

Browse files
committed
Auto merge of #13134 - Veykril:proc-highlight, r=Veykril
Highlight namerefs by syntax until proc-macros have been loaded Usually when loading up a project, once loading is done we start answering highlight requests while proc-macros haven't always been loaded yet, so we start out with showing a lot of unresolved name-refs. After this PR, we'll use syntax based highlighting for those unresolved namerefs until the proc-macros have been loaded.
2 parents ab068f1 + 66ec636 commit 643c3a5

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

crates/rust-analyzer/src/global_state.rs

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub(crate) struct GlobalStateSnapshot {
116116
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
117117
vfs: Arc<RwLock<(vfs::Vfs, NoHashHashMap<FileId, LineEndings>)>>,
118118
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
119+
pub(crate) proc_macros_loaded: bool,
119120
}
120121

121122
impl std::panic::UnwindSafe for GlobalStateSnapshot {}
@@ -256,6 +257,7 @@ impl GlobalState {
256257
check_fixes: Arc::clone(&self.diagnostics.check_fixes),
257258
mem_docs: self.mem_docs.clone(),
258259
semantic_tokens_cache: Arc::clone(&self.semantic_tokens_cache),
260+
proc_macros_loaded: !self.fetch_build_data_queue.last_op_result().0.is_empty(),
259261
}
260262
}
261263

crates/rust-analyzer/src/handlers.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,11 @@ pub(crate) fn handle_semantic_tokens_full(
15041504
let text = snap.analysis.file_text(file_id)?;
15051505
let line_index = snap.file_line_index(file_id)?;
15061506

1507-
let highlights = snap.analysis.highlight(snap.config.highlighting_config(), file_id)?;
1507+
let mut highlight_config = snap.config.highlighting_config();
1508+
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
1509+
highlight_config.syntactic_name_ref_highlighting = !snap.proc_macros_loaded;
1510+
1511+
let highlights = snap.analysis.highlight(highlight_config, file_id)?;
15081512
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
15091513

15101514
// Unconditionally cache the tokens
@@ -1523,7 +1527,11 @@ pub(crate) fn handle_semantic_tokens_full_delta(
15231527
let text = snap.analysis.file_text(file_id)?;
15241528
let line_index = snap.file_line_index(file_id)?;
15251529

1526-
let highlights = snap.analysis.highlight(snap.config.highlighting_config(), file_id)?;
1530+
let mut highlight_config = snap.config.highlighting_config();
1531+
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
1532+
highlight_config.syntactic_name_ref_highlighting = !snap.proc_macros_loaded;
1533+
1534+
let highlights = snap.analysis.highlight(highlight_config, file_id)?;
15271535
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
15281536

15291537
let mut cache = snap.semantic_tokens_cache.lock();

crates/rust-analyzer/src/reload.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ impl GlobalState {
347347
error
348348
})
349349
})
350-
.collect();
351-
}
350+
.collect()
351+
};
352352
}
353353

354354
let watch = match files_config.watcher {

0 commit comments

Comments
 (0)