Skip to content

Commit 241fd2f

Browse files
committed
Properly record meaningful imports as re-exports in symbol index
1 parent 618b913 commit 241fd2f

File tree

12 files changed

+213
-143
lines changed

12 files changed

+213
-143
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ dependencies = [
523523
"hir-def",
524524
"hir-expand",
525525
"hir-ty",
526+
"indexmap",
526527
"intern",
527528
"itertools",
528529
"rustc-hash 2.0.0",

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ impl ItemScope {
162162
.map(move |name| (name, self.get(name)))
163163
}
164164

165+
pub fn values(&self) -> impl Iterator<Item = (&Name, Item<ModuleDefId, ImportId>)> + '_ {
166+
self.values.iter().map(|(n, &i)| (n, i))
167+
}
168+
169+
pub fn types(
170+
&self,
171+
) -> impl Iterator<Item = (&Name, Item<ModuleDefId, ImportOrExternCrate>)> + '_ {
172+
self.types.iter().map(|(n, &i)| (n, i))
173+
}
174+
175+
pub fn macros(&self) -> impl Iterator<Item = (&Name, Item<MacroId, ImportId>)> + '_ {
176+
self.macros.iter().map(|(n, &i)| (n, i))
177+
}
178+
165179
pub fn imports(&self) -> impl Iterator<Item = ImportId> + '_ {
166180
self.use_imports_types
167181
.keys()
@@ -263,11 +277,6 @@ impl ItemScope {
263277
self.unnamed_consts.iter().copied()
264278
}
265279

266-
/// Iterate over all module scoped macros
267-
pub(crate) fn macros(&self) -> impl Iterator<Item = (&Name, MacroId)> + '_ {
268-
self.entries().filter_map(|(name, def)| def.take_macros().map(|macro_| (name, macro_)))
269-
}
270-
271280
/// Iterate over all legacy textual scoped macros visible at the end of the module
272281
pub fn legacy_macros(&self) -> impl Iterator<Item = (&Name, &[MacroId])> + '_ {
273282
self.legacy_macros.iter().map(|(name, def)| (name, &**def))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl ModuleId {
502502
}
503503

504504
/// Whether this module represents the crate root module
505-
fn is_crate_root(&self) -> bool {
505+
pub fn is_crate_root(&self) -> bool {
506506
self.local_id == DefMap::ROOT && self.block.is_none()
507507
}
508508
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ impl DefCollector<'_> {
717717
}
718718
}
719719
None => {
720-
for (name, def) in root_scope.macros() {
721-
self.def_map.macro_use_prelude.insert(name.clone(), (def, extern_crate));
720+
for (name, it) in root_scope.macros() {
721+
self.def_map.macro_use_prelude.insert(name.clone(), (it.def, extern_crate));
722722
}
723723
}
724724
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ impl Visibility {
240240

241241
if a_ancestors.any(|m| m == mod_b.local_id) {
242242
// B is above A
243-
return Some(Visibility::Module(mod_a, expl_b));
243+
return Some(Visibility::Module(mod_a, expl_a));
244244
}
245245

246246
if b_ancestors.any(|m| m == mod_a.local_id) {
247247
// A is above B
248-
return Some(Visibility::Module(mod_b, expl_a));
248+
return Some(Visibility::Module(mod_b, expl_b));
249249
}
250250

251251
None

src/tools/rust-analyzer/crates/hir/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ itertools.workspace = true
2020
smallvec.workspace = true
2121
tracing.workspace = true
2222
triomphe.workspace = true
23+
indexmap.workspace = true
2324

2425
# local deps
2526
base-db.workspace = true

0 commit comments

Comments
 (0)