Skip to content

Commit 14d5ec3

Browse files
committed
Also dump the macro sub-namespace of macros
1 parent 8ef7bc2 commit 14d5ec3

File tree

6 files changed

+45
-37
lines changed

6 files changed

+45
-37
lines changed

src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests/body/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn main() {
326326
- FooWorks : type value
327327
328328
crate
329-
- foo : macro
329+
- foo : macro!
330330
- main : value
331331
"#]],
332332
);

src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::{fmt, sync::LazyLock};
55

66
use base_db::Crate;
7-
use hir_expand::{AstId, MacroCallId, attrs::AttrId, db::ExpandDatabase, name::Name};
7+
use hir_expand::{AstId, MacroCallId, attrs::AttrId, name::Name};
88
use indexmap::map::Entry;
99
use itertools::Itertools;
1010
use la_arena::Idx;
@@ -19,6 +19,7 @@ use crate::{
1919
AdtId, BuiltinType, ConstId, ExternBlockId, ExternCrateId, FxIndexMap, HasModule, ImplId,
2020
LocalModuleId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId,
2121
db::DefDatabase,
22+
nameres::MacroSubNs,
2223
per_ns::{Item, MacrosItem, PerNs, TypesItem, ValuesItem},
2324
visibility::Visibility,
2425
};
@@ -735,10 +736,16 @@ impl ItemScope {
735736
}
736737
}
737738

738-
pub(crate) fn dump(&self, db: &dyn ExpandDatabase, buf: &mut String) {
739+
pub(crate) fn dump(&self, db: &dyn DefDatabase, buf: &mut String) {
739740
let mut entries: Vec<_> = self.resolutions().collect();
740741
entries.sort_by_key(|(name, _)| name.clone());
741742

743+
let print_macro_sub_ns =
744+
|buf: &mut String, macro_id: MacroId| match MacroSubNs::from_id(db, macro_id) {
745+
MacroSubNs::Bang => buf.push('!'),
746+
MacroSubNs::Attr => buf.push('#'),
747+
};
748+
742749
for (name, def) in entries {
743750
let display_name: &dyn fmt::Display = match &name {
744751
Some(name) => &name.display(db, Edition::LATEST),
@@ -763,8 +770,9 @@ impl ItemScope {
763770
None => (),
764771
}
765772
}
766-
if let Some(Item { import, .. }) = def.macros {
773+
if let Some(Item { def: macro_id, import, .. }) = def.macros {
767774
buf.push_str(" macro");
775+
print_macro_sub_ns(buf, macro_id);
768776
match import {
769777
Some(ImportOrExternCrate::Import(_)) => buf.push_str(" (import)"),
770778
Some(ImportOrExternCrate::Glob(_)) => buf.push_str(" (glob)"),

src/tools/rust-analyzer/crates/hir-def/src/nameres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ pub enum MacroSubNs {
814814
}
815815

816816
impl MacroSubNs {
817-
fn from_id(db: &dyn DefDatabase, macro_id: MacroId) -> Self {
817+
pub(crate) fn from_id(db: &dyn DefDatabase, macro_id: MacroId) -> Self {
818818
let expander = match macro_id {
819819
MacroId::Macro2Id(it) => it.lookup(db).expander,
820820
MacroId::MacroRulesId(it) => it.lookup(db).expander,

src/tools/rust-analyzer/crates/hir-def/src/nameres/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ use self::m::S::{self};
889889
- m : type
890890
891891
crate::m
892-
- S : type value macro
892+
- S : type value macro!
893893
"#]],
894894
);
895895
}

src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,24 +391,24 @@ use reexport::*;
391391
- Trait : type (glob)
392392
- defs : type
393393
- function : value (glob)
394-
- makro : macro (glob)
394+
- makro : macro! (glob)
395395
- reexport : type
396396
397397
crate::defs
398398
- Trait : type
399399
- function : value
400-
- makro : macro
400+
- makro : macro!
401401
402402
crate::reexport
403403
- Trait : type (glob)
404404
- function : value (glob)
405405
- inner : type
406-
- makro : macro (glob)
406+
- makro : macro! (glob)
407407
408408
crate::reexport::inner
409409
- Trait : type (import)
410410
- function : value (import)
411-
- makro : macro (import)
411+
- makro : macro! (import)
412412
"#]],
413413
);
414414
}

src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ macro_rules! bar {
207207
expect![[r#"
208208
crate
209209
- Foo : type
210-
- bar : macro (import)
211-
- foo : macro (import)
210+
- bar : macro! (import)
211+
- foo : macro! (import)
212212
"#]],
213213
);
214214
}
@@ -555,9 +555,9 @@ fn baz() {}
555555
"#,
556556
expect![[r#"
557557
crate
558-
- bar : type (import) macro (import)
559-
- baz : type (import) value macro (import)
560-
- foo : type macro
558+
- bar : type (import) macro! (import)
559+
- baz : type (import) value macro! (import)
560+
- foo : type macro!
561561
"#]],
562562
);
563563
}
@@ -628,13 +628,13 @@ mod m {
628628
- OkAliasSuper : type value
629629
- OkCrate : type value
630630
- OkPlain : type value
631-
- bar : macro
631+
- bar : macro!
632632
- m : type
633633
634634
crate::m
635-
- alias1 : macro (import)
636-
- alias2 : macro (import)
637-
- alias3 : macro (import)
635+
- alias1 : macro! (import)
636+
- alias2 : macro! (import)
637+
- alias3 : macro! (import)
638638
- not_found : _
639639
"#]],
640640
);
@@ -794,7 +794,7 @@ pub trait Clone {}
794794
"#,
795795
expect![[r#"
796796
crate
797-
- Clone : type (glob) macro (glob)
797+
- Clone : type (glob) macro# (glob)
798798
"#]],
799799
);
800800
}
@@ -910,7 +910,7 @@ fn derive() {}
910910
expect![[r#"
911911
crate
912912
- S : type value
913-
- derive : macro
913+
- derive : macro#
914914
"#]],
915915
);
916916
}
@@ -1029,13 +1029,13 @@ pub fn derive_macro_2(_item: TokenStream) -> TokenStream {
10291029
"#,
10301030
expect![[r#"
10311031
crate
1032-
- AnotherTrait : macro
1033-
- DummyTrait : macro
1032+
- AnotherTrait : macro#
1033+
- DummyTrait : macro#
10341034
- TokenStream : type value
1035-
- attribute_macro : value macro
1035+
- attribute_macro : value macro#
10361036
- derive_macro : value
10371037
- derive_macro_2 : value
1038-
- function_like_macro : value macro
1038+
- function_like_macro : value macro!
10391039
"#]],
10401040
);
10411041
}
@@ -1075,9 +1075,9 @@ macro_rules! mbe {
10751075
"#,
10761076
expect![[r#"
10771077
crate
1078-
- DummyTrait : macro (glob)
1079-
- attribute_macro : macro (glob)
1080-
- function_like_macro : macro (glob)
1078+
- DummyTrait : macro# (glob)
1079+
- attribute_macro : macro# (glob)
1080+
- function_like_macro : macro! (glob)
10811081
"#]],
10821082
);
10831083
}
@@ -1120,7 +1120,7 @@ structs!(Foo);
11201120
expect![[r#"
11211121
crate
11221122
- Foo : type
1123-
- structs : macro
1123+
- structs : macro!
11241124
"#]],
11251125
);
11261126
}
@@ -1196,8 +1196,8 @@ struct B;
11961196
crate
11971197
- A : type value
11981198
- B : type value
1199-
- inner_a : macro
1200-
- inner_b : macro
1199+
- inner_a : macro!
1200+
- inner_b : macro!
12011201
"#]],
12021202
);
12031203
}
@@ -1228,7 +1228,7 @@ struct A;
12281228
expect![[r#"
12291229
crate
12301230
- A : type value
1231-
- inner : macro
1231+
- inner : macro!
12321232
"#]],
12331233
);
12341234
// eager -> MBE -> $crate::mbe
@@ -1257,7 +1257,7 @@ struct A;
12571257
expect![[r#"
12581258
crate
12591259
- A : type value
1260-
- inner : macro
1260+
- inner : macro!
12611261
"#]],
12621262
);
12631263
}
@@ -1501,9 +1501,9 @@ pub mod prelude {
15011501
expect![[r#"
15021502
crate
15031503
- Ok : type value
1504-
- bar : macro
1504+
- bar : macro!
15051505
- dep : type (extern)
1506-
- foo : macro
1506+
- foo : macro!
15071507
- ok : value
15081508
"#]],
15091509
);
@@ -1589,8 +1589,8 @@ pub mod prelude {
15891589
expect![[r#"
15901590
crate
15911591
- Ok : type value
1592-
- bar : macro (import)
1593-
- foo : macro (import)
1592+
- bar : macro# (import)
1593+
- foo : macro# (import)
15941594
- ok : value
15951595
"#]],
15961596
);

0 commit comments

Comments
 (0)