Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir/src/source_analyzer.rs24
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html12
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs10
-rw-r--r--crates/rust-analyzer/src/reload.rs2
4 files changed, 29 insertions, 19 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index f8f8152219..a7f5c3f1cf 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -1186,21 +1186,15 @@ impl<'db> SourceAnalyzer<'db> {
}
if let Some(attr) = meta_path.parent_attr() {
- let adt = if let Some(field) =
- attr.syntax().parent().and_then(ast::RecordField::cast)
- {
- field.syntax().ancestors().take(4).find_map(ast::Adt::cast)
- } else if let Some(field) =
- attr.syntax().parent().and_then(ast::TupleField::cast)
- {
- field.syntax().ancestors().take(4).find_map(ast::Adt::cast)
- } else if let Some(variant) =
- attr.syntax().parent().and_then(ast::Variant::cast)
- {
- variant.syntax().ancestors().nth(2).and_then(ast::Adt::cast)
- } else {
- None
- };
+ let adt =
+ attr.syntax().ancestors().find_map(ast::Item::cast).and_then(
+ |it| match it {
+ ast::Item::Struct(it) => Some(ast::Adt::Struct(it)),
+ ast::Item::Enum(it) => Some(ast::Adt::Enum(it)),
+ ast::Item::Union(it) => Some(ast::Adt::Union(it)),
+ _ => None,
+ },
+ );
if let Some(adt) = adt {
let ast_id = db.ast_id_map(self.file_id).ast_id(&adt);
if let Some(helpers) = self
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 fa7f7b1cba..6b63edf563 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html
@@ -54,7 +54,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="comment">// This is another normal comment</span>
<span class="attribute_bracket attribute macro proc_macro">#</span><span class="attribute_bracket attribute macro proc_macro">[</span><span class="attribute attribute default_library library macro proc_macro">derive</span><span class="parenthesis attribute macro proc_macro">(</span><span class="derive attribute default_library library macro">Copy</span><span class="comma attribute macro proc_macro">,</span> <span class="unresolved_reference attribute macro">Unresolved</span><span class="parenthesis attribute macro proc_macro">)</span><span class="attribute_bracket attribute macro proc_macro">]</span>
<span class="comment">// The reason for these being here is to test AttrIds</span>
+<span class="attribute_bracket attribute macro proc_macro">#</span><span class="attribute_bracket attribute macro proc_macro">[</span><span class="derive_helper attribute default_library library macro proc_macro">default</span><span class="attribute_bracket attribute macro proc_macro">]</span>
<span class="keyword macro proc_macro">enum</span> <span class="enum declaration macro proc_macro">Foo</span> <span class="brace macro proc_macro">{</span>
<span class="attribute_bracket attribute macro proc_macro">#</span><span class="attribute_bracket attribute macro proc_macro">[</span><span class="derive_helper attribute default_library library macro proc_macro">default</span><span class="attribute_bracket attribute macro proc_macro">]</span>
- <span class="enum_variant declaration macro proc_macro">Bar</span>
-<span class="brace macro proc_macro">}</span></code></pre> \ No newline at end of file
+ <span class="enum_variant declaration macro proc_macro">Bar</span> <span class="brace macro proc_macro">{</span>
+ <span class="attribute_bracket attribute macro proc_macro">#</span><span class="attribute_bracket attribute macro proc_macro">[</span><span class="derive_helper attribute default_library library macro proc_macro">default</span><span class="attribute_bracket attribute macro proc_macro">]</span>
+ <span class="field declaration macro proc_macro">field</span><span class="colon macro proc_macro">:</span> <span class="builtin_type macro proc_macro">i32</span>
+ <span class="brace macro proc_macro">}</span>
+<span class="brace macro proc_macro">}</span>
+
+<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="derive attribute default_library library macro">Default</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
+<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="derive_helper attribute default_library library">default</span><span class="attribute_bracket attribute">]</span>
+<span class="keyword">struct</span> <span class="struct declaration">Bar</span><span class="parenthesis">(</span><span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="derive_helper attribute default_library library">default</span><span class="attribute_bracket attribute">]</span> <span class="builtin_type">i32</span><span class="parenthesis">)</span><span class="semicolon">;</span></code></pre> \ 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 b1094872ff..ab69578ed9 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -39,10 +39,18 @@ fn attributes() {
// This is another normal comment
#[derive(Copy, Unresolved)]
// The reason for these being here is to test AttrIds
+#[default]
enum Foo {
#[default]
- Bar
+ Bar {
+ #[default]
+ field: i32
+ }
}
+
+#[derive(Default)]
+#[default]
+struct Bar(#[default] i32);
"#,
expect_file!["./test_data/highlight_attributes.html"],
false,
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 1832275eb3..74fd0e6533 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -440,7 +440,7 @@ impl GlobalState {
let expansion_res = match client {
Some(Ok(client)) => match res {
Ok((crate_name, path)) => {
- progress(format!("loading proc-macros: {path}"));
+ progress(path.to_string());
let ignored_proc_macros = ignored_proc_macros
.iter()
.find_map(|(name, macros)| {