diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-26 12:54:57 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-26 12:54:57 +0000 |
| commit | ddb5a53fd7100c973d78d8cb2da2ee77b34fd82f (patch) | |
| tree | 06c646174acfcad3fbae88c3482749d93c201a4a | |
| parent | a2cc1d6b7b499d6b03436db7fc8053aea72f75ac (diff) | |
| parent | 03d33556c9f248ea6a1d8473b98cfa4c1e96343b (diff) | |
| download | rust-ddb5a53fd7100c973d78d8cb2da2ee77b34fd82f.tar.gz rust-ddb5a53fd7100c973d78d8cb2da2ee77b34fd82f.zip | |
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 <lukastw97@gmail.com>
| -rw-r--r-- | crates/ide/src/syntax_highlighting.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 7d92c5051b1..1b2fc9c635d 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -183,7 +183,8 @@ pub(crate) fn highlight( traverse( &mut hl, &sema, - InFile::new(file_id.into(), &root), + file_id, + &root, sema.scope(&root).krate(), range_to_highlight, syntactic_name_ref_highlighting, @@ -194,11 +195,13 @@ pub(crate) fn highlight( fn traverse( hl: &mut Highlights, sema: &Semantics<RootDatabase>, - root: InFile<&SyntaxNode>, + file_id: FileId, + root: &SyntaxNode, krate: Option<hir::Crate>, range_to_highlight: TextRange, syntactic_name_ref_highlighting: bool, ) { + let is_unlinked = sema.to_module_def(file_id).is_none(); let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default(); let mut current_macro_call: Option<ast::MacroCall> = None; @@ -209,7 +212,7 @@ fn traverse( // Walk all nodes, keeping track of whether we are inside a macro or not. // If in macro, expand it first and highlight the expanded code. - for event in root.value.preorder_with_tokens() { + for event in root.preorder_with_tokens() { let range = match &event { WalkEvent::Enter(it) | WalkEvent::Leave(it) => it.text_range(), }; @@ -283,7 +286,7 @@ fn traverse( WalkEvent::Enter(it) => it, WalkEvent::Leave(NodeOrToken::Token(_)) => continue, WalkEvent::Leave(NodeOrToken::Node(node)) => { - inject::doc_comment(hl, sema, root.with_value(&node)); + inject::doc_comment(hl, sema, InFile::new(file_id.into(), &node)); continue; } }; @@ -378,6 +381,11 @@ fn traverse( NodeOrToken::Token(token) => highlight::token(sema, token).zip(Some(None)), }; if let Some((mut highlight, binding_hash)) = element { + if is_unlinked && highlight.tag == HlTag::UnresolvedReference { + // do not emit unresolved references if the file is unlinked + // let the editor do its highlighting for these tokens instead + continue; + } if inside_attribute { highlight |= HlMod::Attribute } |
