Unnamed repository; edit this file 'description' to name the repository.
Also dump the macro sub-namespace of macros
Zalathar 5 months ago
parent bf8342a · commit 217e3ca
-rw-r--r--crates/hir-def/src/expr_store/tests/body/block.rs2
-rw-r--r--crates/hir-def/src/item_scope.rs14
-rw-r--r--crates/hir-def/src/nameres.rs2
-rw-r--r--crates/hir-def/src/nameres/tests.rs2
-rw-r--r--crates/hir-def/src/nameres/tests/globs.rs8
-rw-r--r--crates/hir-def/src/nameres/tests/macros.rs54
6 files changed, 45 insertions, 37 deletions
diff --git a/crates/hir-def/src/expr_store/tests/body/block.rs b/crates/hir-def/src/expr_store/tests/body/block.rs
index e36f6550d5..f13f857ccc 100644
--- a/crates/hir-def/src/expr_store/tests/body/block.rs
+++ b/crates/hir-def/src/expr_store/tests/body/block.rs
@@ -326,7 +326,7 @@ fn main() {
- FooWorks : type value
crate
- - foo : macro
+ - foo : macro!
- main : value
"#]],
);
diff --git a/crates/hir-def/src/item_scope.rs b/crates/hir-def/src/item_scope.rs
index 01adef5bcc..204031ebee 100644
--- a/crates/hir-def/src/item_scope.rs
+++ b/crates/hir-def/src/item_scope.rs
@@ -4,7 +4,7 @@
use std::{fmt, sync::LazyLock};
use base_db::Crate;
-use hir_expand::{AstId, MacroCallId, attrs::AttrId, db::ExpandDatabase, name::Name};
+use hir_expand::{AstId, MacroCallId, attrs::AttrId, name::Name};
use indexmap::map::Entry;
use itertools::Itertools;
use la_arena::Idx;
@@ -19,6 +19,7 @@ use crate::{
AdtId, BuiltinType, ConstId, ExternBlockId, ExternCrateId, FxIndexMap, HasModule, ImplId,
LocalModuleId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId,
db::DefDatabase,
+ nameres::MacroSubNs,
per_ns::{Item, MacrosItem, PerNs, TypesItem, ValuesItem},
visibility::Visibility,
};
@@ -735,10 +736,16 @@ impl ItemScope {
}
}
- pub(crate) fn dump(&self, db: &dyn ExpandDatabase, buf: &mut String) {
+ pub(crate) fn dump(&self, db: &dyn DefDatabase, buf: &mut String) {
let mut entries: Vec<_> = self.resolutions().collect();
entries.sort_by_key(|(name, _)| name.clone());
+ let print_macro_sub_ns =
+ |buf: &mut String, macro_id: MacroId| match MacroSubNs::from_id(db, macro_id) {
+ MacroSubNs::Bang => buf.push('!'),
+ MacroSubNs::Attr => buf.push('#'),
+ };
+
for (name, def) in entries {
let display_name: &dyn fmt::Display = match &name {
Some(name) => &name.display(db, Edition::LATEST),
@@ -763,8 +770,9 @@ impl ItemScope {
None => (),
}
}
- if let Some(Item { import, .. }) = def.macros {
+ if let Some(Item { def: macro_id, import, .. }) = def.macros {
buf.push_str(" macro");
+ print_macro_sub_ns(buf, macro_id);
match import {
Some(ImportOrExternCrate::Import(_)) => buf.push_str(" (import)"),
Some(ImportOrExternCrate::Glob(_)) => buf.push_str(" (glob)"),
diff --git a/crates/hir-def/src/nameres.rs b/crates/hir-def/src/nameres.rs
index 50958efa45..f44187ec59 100644
--- a/crates/hir-def/src/nameres.rs
+++ b/crates/hir-def/src/nameres.rs
@@ -814,7 +814,7 @@ pub enum MacroSubNs {
}
impl MacroSubNs {
- fn from_id(db: &dyn DefDatabase, macro_id: MacroId) -> Self {
+ pub(crate) fn from_id(db: &dyn DefDatabase, macro_id: MacroId) -> Self {
let expander = match macro_id {
MacroId::Macro2Id(it) => it.lookup(db).expander,
MacroId::MacroRulesId(it) => it.lookup(db).expander,
diff --git a/crates/hir-def/src/nameres/tests.rs b/crates/hir-def/src/nameres/tests.rs
index 68f47f50bf..23d60d58f0 100644
--- a/crates/hir-def/src/nameres/tests.rs
+++ b/crates/hir-def/src/nameres/tests.rs
@@ -889,7 +889,7 @@ use self::m::S::{self};
- m : type
crate::m
- - S : type value macro
+ - S : type value macro!
"#]],
);
}
diff --git a/crates/hir-def/src/nameres/tests/globs.rs b/crates/hir-def/src/nameres/tests/globs.rs
index 779f7769bb..62887e2941 100644
--- a/crates/hir-def/src/nameres/tests/globs.rs
+++ b/crates/hir-def/src/nameres/tests/globs.rs
@@ -391,24 +391,24 @@ use reexport::*;
- Trait : type (glob)
- defs : type
- function : value (glob)
- - makro : macro (glob)
+ - makro : macro! (glob)
- reexport : type
crate::defs
- Trait : type
- function : value
- - makro : macro
+ - makro : macro!
crate::reexport
- Trait : type (glob)
- function : value (glob)
- inner : type
- - makro : macro (glob)
+ - makro : macro! (glob)
crate::reexport::inner
- Trait : type (import)
- function : value (import)
- - makro : macro (import)
+ - makro : macro! (import)
"#]],
);
}
diff --git a/crates/hir-def/src/nameres/tests/macros.rs b/crates/hir-def/src/nameres/tests/macros.rs
index 5b60031ae3..9c2ca1b57f 100644
--- a/crates/hir-def/src/nameres/tests/macros.rs
+++ b/crates/hir-def/src/nameres/tests/macros.rs
@@ -207,8 +207,8 @@ macro_rules! bar {
expect![[r#"
crate
- Foo : type
- - bar : macro (import)
- - foo : macro (import)
+ - bar : macro! (import)
+ - foo : macro! (import)
"#]],
);
}
@@ -555,9 +555,9 @@ fn baz() {}
"#,
expect![[r#"
crate
- - bar : type (import) macro (import)
- - baz : type (import) value macro (import)
- - foo : type macro
+ - bar : type (import) macro! (import)
+ - baz : type (import) value macro! (import)
+ - foo : type macro!
"#]],
);
}
@@ -628,13 +628,13 @@ mod m {
- OkAliasSuper : type value
- OkCrate : type value
- OkPlain : type value
- - bar : macro
+ - bar : macro!
- m : type
crate::m
- - alias1 : macro (import)
- - alias2 : macro (import)
- - alias3 : macro (import)
+ - alias1 : macro! (import)
+ - alias2 : macro! (import)
+ - alias3 : macro! (import)
- not_found : _
"#]],
);
@@ -794,7 +794,7 @@ pub trait Clone {}
"#,
expect![[r#"
crate
- - Clone : type (glob) macro (glob)
+ - Clone : type (glob) macro# (glob)
"#]],
);
}
@@ -910,7 +910,7 @@ fn derive() {}
expect![[r#"
crate
- S : type value
- - derive : macro
+ - derive : macro#
"#]],
);
}
@@ -1029,13 +1029,13 @@ pub fn derive_macro_2(_item: TokenStream) -> TokenStream {
"#,
expect![[r#"
crate
- - AnotherTrait : macro
- - DummyTrait : macro
+ - AnotherTrait : macro#
+ - DummyTrait : macro#
- TokenStream : type value
- - attribute_macro : value macro
+ - attribute_macro : value macro#
- derive_macro : value
- derive_macro_2 : value
- - function_like_macro : value macro
+ - function_like_macro : value macro!
"#]],
);
}
@@ -1075,9 +1075,9 @@ macro_rules! mbe {
"#,
expect![[r#"
crate
- - DummyTrait : macro (glob)
- - attribute_macro : macro (glob)
- - function_like_macro : macro (glob)
+ - DummyTrait : macro# (glob)
+ - attribute_macro : macro# (glob)
+ - function_like_macro : macro! (glob)
"#]],
);
}
@@ -1120,7 +1120,7 @@ structs!(Foo);
expect![[r#"
crate
- Foo : type
- - structs : macro
+ - structs : macro!
"#]],
);
}
@@ -1196,8 +1196,8 @@ struct B;
crate
- A : type value
- B : type value
- - inner_a : macro
- - inner_b : macro
+ - inner_a : macro!
+ - inner_b : macro!
"#]],
);
}
@@ -1228,7 +1228,7 @@ struct A;
expect![[r#"
crate
- A : type value
- - inner : macro
+ - inner : macro!
"#]],
);
// eager -> MBE -> $crate::mbe
@@ -1257,7 +1257,7 @@ struct A;
expect![[r#"
crate
- A : type value
- - inner : macro
+ - inner : macro!
"#]],
);
}
@@ -1501,9 +1501,9 @@ pub mod prelude {
expect![[r#"
crate
- Ok : type value
- - bar : macro
+ - bar : macro!
- dep : type (extern)
- - foo : macro
+ - foo : macro!
- ok : value
"#]],
);
@@ -1589,8 +1589,8 @@ pub mod prelude {
expect![[r#"
crate
- Ok : type value
- - bar : macro (import)
- - foo : macro (import)
+ - bar : macro# (import)
+ - foo : macro# (import)
- ok : value
"#]],
);