From b6e7cf320172d4cb86c8adaa431ab23ee8862bb1 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 8 Mar 2023 13:51:14 +0100 Subject: [PATCH] Highlight unresolved derives as being unresolved --- crates/hir/src/semantics.rs | 2 +- crates/ide/src/syntax_highlighting/highlight.rs | 4 +++- .../syntax_highlighting/test_data/highlight_attributes.html | 2 +- crates/ide/src/syntax_highlighting/tests.rs | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 2a0077cf50..8bd905d011 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -538,8 +538,8 @@ impl<'db> SemanticsImpl<'db> { } fn expand_derive_as_pseudo_attr_macro(&self, attr: &ast::Attr) -> Option { - let src = self.wrap_node_infile(attr.clone()); let adt = attr.syntax().parent().and_then(ast::Adt::cast)?; + let src = self.wrap_node_infile(attr.clone()); let call_id = self.with_ctx(|ctx| { ctx.attr_to_derive_macro_call(src.with_value(&adt), src).map(|(_, it, _)| it) })?; diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 390b7efdeb..2111baad74 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -217,7 +217,9 @@ fn highlight_name_ref( // to anything when used. // We can fix this for derive attributes since derive helpers are recorded, but not for // general attributes. - None if name_ref.syntax().ancestors().any(|it| it.kind() == ATTR) => { + None if name_ref.syntax().ancestors().any(|it| it.kind() == ATTR) + && !sema.hir_file_for(name_ref.syntax()).is_derive_attr_pseudo_expansion(sema.db) => + { return HlTag::Symbol(SymbolKind::Attribute).into(); } None => return HlTag::UnresolvedReference.into(), diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html b/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html index 1a43988147..567ab8ccc1 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html @@ -53,6 +53,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd // This is another normal comment /// This is another doc comment // This is another normal comment -#[derive(Copy)] +#[derive(Copy, Unresolved)] // The reason for these being here is to test AttrIds struct Foo; \ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index fc9b5d3ba4..ac9bd8e39d 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -34,7 +34,7 @@ fn attributes() { // This is another normal comment /// This is another doc comment // This is another normal comment -#[derive(Copy)] +#[derive(Copy, Unresolved)] // The reason for these being here is to test AttrIds struct Foo; "#,