Skip to content

Commit ddb5a53

Browse files
bors[bot]Veykril
andauthored
Merge #11562
11562: fix: Don't emit unresolvedReference highlight tags in unlinked files r=Veykril a=Veykril Emitting these overwrites any syntax based highlighting that is being done in the file, causing a lot of noise if the user gave them a specific color. bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents a2cc1d6 + 03d3355 commit ddb5a53

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

crates/ide/src/syntax_highlighting.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ pub(crate) fn highlight(
183183
traverse(
184184
&mut hl,
185185
&sema,
186-
InFile::new(file_id.into(), &root),
186+
file_id,
187+
&root,
187188
sema.scope(&root).krate(),
188189
range_to_highlight,
189190
syntactic_name_ref_highlighting,
@@ -194,11 +195,13 @@ pub(crate) fn highlight(
194195
fn traverse(
195196
hl: &mut Highlights,
196197
sema: &Semantics<RootDatabase>,
197-
root: InFile<&SyntaxNode>,
198+
file_id: FileId,
199+
root: &SyntaxNode,
198200
krate: Option<hir::Crate>,
199201
range_to_highlight: TextRange,
200202
syntactic_name_ref_highlighting: bool,
201203
) {
204+
let is_unlinked = sema.to_module_def(file_id).is_none();
202205
let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default();
203206

204207
let mut current_macro_call: Option<ast::MacroCall> = None;
@@ -209,7 +212,7 @@ fn traverse(
209212

210213
// Walk all nodes, keeping track of whether we are inside a macro or not.
211214
// If in macro, expand it first and highlight the expanded code.
212-
for event in root.value.preorder_with_tokens() {
215+
for event in root.preorder_with_tokens() {
213216
let range = match &event {
214217
WalkEvent::Enter(it) | WalkEvent::Leave(it) => it.text_range(),
215218
};
@@ -283,7 +286,7 @@ fn traverse(
283286
WalkEvent::Enter(it) => it,
284287
WalkEvent::Leave(NodeOrToken::Token(_)) => continue,
285288
WalkEvent::Leave(NodeOrToken::Node(node)) => {
286-
inject::doc_comment(hl, sema, root.with_value(&node));
289+
inject::doc_comment(hl, sema, InFile::new(file_id.into(), &node));
287290
continue;
288291
}
289292
};
@@ -378,6 +381,11 @@ fn traverse(
378381
NodeOrToken::Token(token) => highlight::token(sema, token).zip(Some(None)),
379382
};
380383
if let Some((mut highlight, binding_hash)) = element {
384+
if is_unlinked && highlight.tag == HlTag::UnresolvedReference {
385+
// do not emit unresolved references if the file is unlinked
386+
// let the editor do its highlighting for these tokens instead
387+
continue;
388+
}
381389
if inside_attribute {
382390
highlight |= HlMod::Attribute
383391
}

0 commit comments

Comments
 (0)