Also dump the macro sub-namespace of macros
This commit is contained in:
parent
8ef7bc266b
commit
14d5ec349e
6 changed files with 45 additions and 37 deletions
|
|
@ -326,7 +326,7 @@ fn main() {
|
|||
- FooWorks : type value
|
||||
|
||||
crate
|
||||
- foo : macro
|
||||
- foo : macro!
|
||||
- main : value
|
||||
"#]],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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)"),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -889,7 +889,7 @@ use self::m::S::{self};
|
|||
- m : type
|
||||
|
||||
crate::m
|
||||
- S : type value macro
|
||||
- S : type value macro!
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
"#]],
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue