mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
Merge pull request #19016 from Veykril/push-moqnsytyrupu
fix: Fix `ItemScope` not recording glob imports
This commit is contained in:
commit
93de80d833
11 changed files with 239 additions and 213 deletions
|
|
@ -475,7 +475,7 @@ fn outer() {
|
||||||
|
|
||||||
block scope::tests
|
block scope::tests
|
||||||
name: _
|
name: _
|
||||||
outer: v
|
outer: vg
|
||||||
|
|
||||||
crate
|
crate
|
||||||
outer: v
|
outer: v
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,7 @@ impl ImportMap {
|
||||||
match import {
|
match import {
|
||||||
ImportOrExternCrate::ExternCrate(id) => Some(id.into()),
|
ImportOrExternCrate::ExternCrate(id) => Some(id.into()),
|
||||||
ImportOrExternCrate::Import(id) => Some(id.import.into()),
|
ImportOrExternCrate::Import(id) => Some(id.import.into()),
|
||||||
|
ImportOrExternCrate::Glob(id) => Some(id.into()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match item {
|
match item {
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,54 @@ pub struct PerNsGlobImports {
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum ImportOrExternCrate {
|
pub enum ImportOrExternCrate {
|
||||||
|
Glob(UseId),
|
||||||
Import(ImportId),
|
Import(ImportId),
|
||||||
ExternCrate(ExternCrateId),
|
ExternCrate(ExternCrateId),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ImportOrGlob> for ImportOrExternCrate {
|
||||||
|
fn from(value: ImportOrGlob) -> Self {
|
||||||
|
match value {
|
||||||
|
ImportOrGlob::Glob(it) => ImportOrExternCrate::Glob(it),
|
||||||
|
ImportOrGlob::Import(it) => ImportOrExternCrate::Import(it),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ImportType> for ImportOrExternCrate {
|
||||||
|
fn from(value: ImportType) -> Self {
|
||||||
|
match value {
|
||||||
|
ImportType::Glob(it) => ImportOrExternCrate::Glob(it),
|
||||||
|
ImportType::Import(it) => ImportOrExternCrate::Import(it),
|
||||||
|
ImportType::ExternCrate(it) => ImportOrExternCrate::ExternCrate(it),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImportOrExternCrate {
|
||||||
|
pub fn into_import(self) -> Option<ImportOrGlob> {
|
||||||
|
match self {
|
||||||
|
ImportOrExternCrate::Import(it) => Some(ImportOrGlob::Import(it)),
|
||||||
|
ImportOrExternCrate::Glob(it) => Some(ImportOrGlob::Glob(it)),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub enum ImportOrGlob {
|
||||||
|
Glob(UseId),
|
||||||
|
Import(ImportId),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImportOrGlob {
|
||||||
|
pub fn into_import(self) -> Option<ImportId> {
|
||||||
|
match self {
|
||||||
|
ImportOrGlob::Import(it) => Some(it),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub(crate) enum ImportType {
|
pub(crate) enum ImportType {
|
||||||
Import(ImportId),
|
Import(ImportId),
|
||||||
|
|
@ -42,21 +86,33 @@ pub(crate) enum ImportType {
|
||||||
ExternCrate(ExternCrateId),
|
ExternCrate(ExternCrateId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImportOrExternCrate {
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub fn into_import(self) -> Option<ImportId> {
|
pub enum ImportOrDef {
|
||||||
match self {
|
Import(ImportId),
|
||||||
ImportOrExternCrate::Import(it) => Some(it),
|
Glob(UseId),
|
||||||
_ => None,
|
ExternCrate(ExternCrateId),
|
||||||
|
Def(ModuleDefId),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ImportOrExternCrate> for ImportOrDef {
|
||||||
|
fn from(value: ImportOrExternCrate) -> Self {
|
||||||
|
match value {
|
||||||
|
ImportOrExternCrate::Import(it) => ImportOrDef::Import(it),
|
||||||
|
ImportOrExternCrate::Glob(it) => ImportOrDef::Glob(it),
|
||||||
|
ImportOrExternCrate::ExternCrate(it) => ImportOrDef::ExternCrate(it),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
impl From<ImportOrGlob> for ImportOrDef {
|
||||||
pub enum ImportOrDef {
|
fn from(value: ImportOrGlob) -> Self {
|
||||||
Import(ImportId),
|
match value {
|
||||||
ExternCrate(ExternCrateId),
|
ImportOrGlob::Import(it) => ImportOrDef::Import(it),
|
||||||
Def(ModuleDefId),
|
ImportOrGlob::Glob(it) => ImportOrDef::Glob(it),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||||
pub struct ImportId {
|
pub struct ImportId {
|
||||||
pub import: UseId,
|
pub import: UseId,
|
||||||
|
|
@ -96,8 +152,8 @@ pub struct ItemScope {
|
||||||
|
|
||||||
// the resolutions of the imports of this scope
|
// the resolutions of the imports of this scope
|
||||||
use_imports_types: FxHashMap<ImportOrExternCrate, ImportOrDef>,
|
use_imports_types: FxHashMap<ImportOrExternCrate, ImportOrDef>,
|
||||||
use_imports_values: FxHashMap<ImportId, ImportOrDef>,
|
use_imports_values: FxHashMap<ImportOrGlob, ImportOrDef>,
|
||||||
use_imports_macros: FxHashMap<ImportId, ImportOrDef>,
|
use_imports_macros: FxHashMap<ImportOrGlob, ImportOrDef>,
|
||||||
|
|
||||||
use_decls: Vec<UseId>,
|
use_decls: Vec<UseId>,
|
||||||
extern_crate_decls: Vec<ExternCrateId>,
|
extern_crate_decls: Vec<ExternCrateId>,
|
||||||
|
|
@ -162,7 +218,7 @@ impl ItemScope {
|
||||||
.map(move |name| (name, self.get(name)))
|
.map(move |name| (name, self.get(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn values(&self) -> impl Iterator<Item = (&Name, Item<ModuleDefId, ImportId>)> + '_ {
|
pub fn values(&self) -> impl Iterator<Item = (&Name, Item<ModuleDefId, ImportOrGlob>)> + '_ {
|
||||||
self.values.iter().map(|(n, &i)| (n, i))
|
self.values.iter().map(|(n, &i)| (n, i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,7 +228,7 @@ impl ItemScope {
|
||||||
self.types.iter().map(|(n, &i)| (n, i))
|
self.types.iter().map(|(n, &i)| (n, i))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn macros(&self) -> impl Iterator<Item = (&Name, Item<MacroId, ImportId>)> + '_ {
|
pub fn macros(&self) -> impl Iterator<Item = (&Name, Item<MacroId, ImportOrGlob>)> + '_ {
|
||||||
self.macros.iter().map(|(n, &i)| (n, i))
|
self.macros.iter().map(|(n, &i)| (n, i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,6 +239,7 @@ impl ItemScope {
|
||||||
.filter_map(ImportOrExternCrate::into_import)
|
.filter_map(ImportOrExternCrate::into_import)
|
||||||
.chain(self.use_imports_values.keys().copied())
|
.chain(self.use_imports_values.keys().copied())
|
||||||
.chain(self.use_imports_macros.keys().copied())
|
.chain(self.use_imports_macros.keys().copied())
|
||||||
|
.filter_map(ImportOrGlob::into_import)
|
||||||
.sorted()
|
.sorted()
|
||||||
.dedup()
|
.dedup()
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +249,7 @@ impl ItemScope {
|
||||||
|
|
||||||
let mut def_map;
|
let mut def_map;
|
||||||
let mut scope = self;
|
let mut scope = self;
|
||||||
while let Some(&m) = scope.use_imports_macros.get(&import) {
|
while let Some(&m) = scope.use_imports_macros.get(&ImportOrGlob::Import(import)) {
|
||||||
match m {
|
match m {
|
||||||
ImportOrDef::Import(i) => {
|
ImportOrDef::Import(i) => {
|
||||||
let module_id = i.import.lookup(db).container;
|
let module_id = i.import.lookup(db).container;
|
||||||
|
|
@ -224,7 +281,7 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut scope = self;
|
let mut scope = self;
|
||||||
while let Some(&m) = scope.use_imports_values.get(&import) {
|
while let Some(&m) = scope.use_imports_values.get(&ImportOrGlob::Import(import)) {
|
||||||
match m {
|
match m {
|
||||||
ImportOrDef::Import(i) => {
|
ImportOrDef::Import(i) => {
|
||||||
let module_id = i.import.lookup(db).container;
|
let module_id = i.import.lookup(db).container;
|
||||||
|
|
@ -514,29 +571,11 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
_ => _ = glob_imports.types.remove(&lookup),
|
_ => _ = glob_imports.types.remove(&lookup),
|
||||||
}
|
}
|
||||||
let import = match import {
|
let import = import.map(Into::into);
|
||||||
Some(ImportType::ExternCrate(extern_crate)) => {
|
|
||||||
Some(ImportOrExternCrate::ExternCrate(extern_crate))
|
|
||||||
}
|
|
||||||
Some(ImportType::Import(import)) => {
|
|
||||||
Some(ImportOrExternCrate::Import(import))
|
|
||||||
}
|
|
||||||
None | Some(ImportType::Glob(_)) => None,
|
|
||||||
};
|
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_types.insert(
|
self.use_imports_types
|
||||||
import,
|
.insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into));
|
||||||
match prev {
|
|
||||||
Some(ImportOrExternCrate::Import(import)) => {
|
|
||||||
ImportOrDef::Import(import)
|
|
||||||
}
|
|
||||||
Some(ImportOrExternCrate::ExternCrate(import)) => {
|
|
||||||
ImportOrDef::ExternCrate(import)
|
|
||||||
}
|
|
||||||
None => ImportOrDef::Def(fld.def),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
@ -552,28 +591,12 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if glob_imports.types.remove(&lookup) {
|
if glob_imports.types.remove(&lookup) {
|
||||||
let import = match import {
|
let import = import.map(Into::into);
|
||||||
Some(ImportType::ExternCrate(extern_crate)) => {
|
|
||||||
Some(ImportOrExternCrate::ExternCrate(extern_crate))
|
|
||||||
}
|
|
||||||
Some(ImportType::Import(import)) => {
|
|
||||||
Some(ImportOrExternCrate::Import(import))
|
|
||||||
}
|
|
||||||
None | Some(ImportType::Glob(_)) => None,
|
|
||||||
};
|
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_types.insert(
|
self.use_imports_types.insert(
|
||||||
import,
|
import,
|
||||||
match prev {
|
prev.map_or(ImportOrDef::Def(fld.def), Into::into),
|
||||||
Some(ImportOrExternCrate::Import(import)) => {
|
|
||||||
ImportOrDef::Import(import)
|
|
||||||
}
|
|
||||||
Some(ImportOrExternCrate::ExternCrate(import)) => {
|
|
||||||
ImportOrDef::ExternCrate(import)
|
|
||||||
}
|
|
||||||
None => ImportOrDef::Def(fld.def),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
cov_mark::hit!(import_shadowed);
|
cov_mark::hit!(import_shadowed);
|
||||||
|
|
@ -597,18 +620,14 @@ impl ItemScope {
|
||||||
_ => _ = glob_imports.values.remove(&lookup),
|
_ => _ = glob_imports.values.remove(&lookup),
|
||||||
}
|
}
|
||||||
let import = match import {
|
let import = match import {
|
||||||
Some(ImportType::Import(import)) => Some(import),
|
Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)),
|
||||||
|
Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_values.insert(
|
self.use_imports_values
|
||||||
import,
|
.insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into));
|
||||||
match prev {
|
|
||||||
Some(import) => ImportOrDef::Import(import),
|
|
||||||
None => ImportOrDef::Def(fld.def),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
@ -616,19 +635,16 @@ impl ItemScope {
|
||||||
Entry::Occupied(mut entry) if !matches!(import, Some(ImportType::Glob(..))) => {
|
Entry::Occupied(mut entry) if !matches!(import, Some(ImportType::Glob(..))) => {
|
||||||
if glob_imports.values.remove(&lookup) {
|
if glob_imports.values.remove(&lookup) {
|
||||||
cov_mark::hit!(import_shadowed);
|
cov_mark::hit!(import_shadowed);
|
||||||
|
|
||||||
let import = match import {
|
let import = match import {
|
||||||
Some(ImportType::Import(import)) => Some(import),
|
Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)),
|
||||||
|
Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_values.insert(
|
self.use_imports_values
|
||||||
import,
|
.insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into));
|
||||||
match prev {
|
|
||||||
Some(import) => ImportOrDef::Import(import),
|
|
||||||
None => ImportOrDef::Def(fld.def),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
@ -649,17 +665,15 @@ impl ItemScope {
|
||||||
_ => _ = glob_imports.macros.remove(&lookup),
|
_ => _ = glob_imports.macros.remove(&lookup),
|
||||||
}
|
}
|
||||||
let import = match import {
|
let import = match import {
|
||||||
Some(ImportType::Import(import)) => Some(import),
|
Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)),
|
||||||
|
Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_macros.insert(
|
self.use_imports_macros.insert(
|
||||||
import,
|
import,
|
||||||
match prev {
|
prev.map_or_else(|| ImportOrDef::Def(fld.def.into()), Into::into),
|
||||||
Some(import) => ImportOrDef::Import(import),
|
|
||||||
None => ImportOrDef::Def(fld.def.into()),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
|
|
@ -669,17 +683,15 @@ impl ItemScope {
|
||||||
if glob_imports.macros.remove(&lookup) {
|
if glob_imports.macros.remove(&lookup) {
|
||||||
cov_mark::hit!(import_shadowed);
|
cov_mark::hit!(import_shadowed);
|
||||||
let import = match import {
|
let import = match import {
|
||||||
Some(ImportType::Import(import)) => Some(import),
|
Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)),
|
||||||
|
Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_macros.insert(
|
self.use_imports_macros.insert(
|
||||||
import,
|
import,
|
||||||
match prev {
|
prev.map_or_else(|| ImportOrDef::Def(fld.def.into()), Into::into),
|
||||||
Some(import) => ImportOrDef::Import(import),
|
|
||||||
None => ImportOrDef::Def(fld.def.into()),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
|
|
@ -704,16 +716,27 @@ impl ItemScope {
|
||||||
.map(|def| &mut def.vis)
|
.map(|def| &mut def.vis)
|
||||||
.chain(self.values.values_mut().map(|def| &mut def.vis))
|
.chain(self.values.values_mut().map(|def| &mut def.vis))
|
||||||
.chain(self.unnamed_trait_imports.values_mut().map(|def| &mut def.vis))
|
.chain(self.unnamed_trait_imports.values_mut().map(|def| &mut def.vis))
|
||||||
.for_each(|vis| {
|
.for_each(|vis| match vis {
|
||||||
*vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit)
|
&mut Visibility::Module(_, visibility_explicitness) => {
|
||||||
|
*vis = Visibility::Module(this_module, visibility_explicitness)
|
||||||
|
}
|
||||||
|
Visibility::Public => {
|
||||||
|
*vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for mac in self.macros.values_mut() {
|
for mac in self.macros.values_mut() {
|
||||||
if matches!(mac.def, MacroId::ProcMacroId(_) if mac.import.is_none()) {
|
if matches!(mac.def, MacroId::ProcMacroId(_) if mac.import.is_none()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
match mac.vis {
|
||||||
mac.vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit);
|
Visibility::Module(_, visibility_explicitness) => {
|
||||||
|
mac.vis = Visibility::Module(this_module, visibility_explicitness)
|
||||||
|
}
|
||||||
|
Visibility::Public => {
|
||||||
|
mac.vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -732,20 +755,25 @@ impl ItemScope {
|
||||||
buf.push_str(" t");
|
buf.push_str(" t");
|
||||||
match import {
|
match import {
|
||||||
Some(ImportOrExternCrate::Import(_)) => buf.push('i'),
|
Some(ImportOrExternCrate::Import(_)) => buf.push('i'),
|
||||||
|
Some(ImportOrExternCrate::Glob(_)) => buf.push('g'),
|
||||||
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push('e'),
|
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push('e'),
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(Item { import, .. }) = def.values {
|
if let Some(Item { import, .. }) = def.values {
|
||||||
buf.push_str(" v");
|
buf.push_str(" v");
|
||||||
if import.is_some() {
|
match import {
|
||||||
buf.push('i');
|
Some(ImportOrGlob::Import(_)) => buf.push('i'),
|
||||||
|
Some(ImportOrGlob::Glob(_)) => buf.push('g'),
|
||||||
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(Item { import, .. }) = def.macros {
|
if let Some(Item { import, .. }) = def.macros {
|
||||||
buf.push_str(" m");
|
buf.push_str(" m");
|
||||||
if import.is_some() {
|
match import {
|
||||||
buf.push('i');
|
Some(ImportOrGlob::Import(_)) => buf.push('i'),
|
||||||
|
Some(ImportOrGlob::Glob(_)) => buf.push('g'),
|
||||||
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if def.is_none() {
|
if def.is_none() {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ use triomphe::Arc;
|
||||||
use crate::{
|
use crate::{
|
||||||
attr::Attrs,
|
attr::Attrs,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::{ImportId, ImportOrExternCrate, ImportType, PerNsGlobImports},
|
item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob, ImportType, PerNsGlobImports},
|
||||||
item_tree::{
|
item_tree::{
|
||||||
self, AttrOwner, FieldsShape, FileItemTreeId, ImportKind, ItemTree, ItemTreeId,
|
self, AttrOwner, FieldsShape, FileItemTreeId, ImportKind, ItemTree, ItemTreeId,
|
||||||
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
||||||
|
|
@ -527,7 +527,10 @@ impl DefCollector<'_> {
|
||||||
// FIXME: This should specifically look for a glob import somehow and record that here
|
// FIXME: This should specifically look for a glob import somehow and record that here
|
||||||
self.def_map.prelude = Some((
|
self.def_map.prelude = Some((
|
||||||
m,
|
m,
|
||||||
import.and_then(ImportOrExternCrate::into_import).map(|it| it.import),
|
import
|
||||||
|
.and_then(ImportOrExternCrate::into_import)
|
||||||
|
.and_then(ImportOrGlob::into_import)
|
||||||
|
.map(|it| it.import),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
types => {
|
types => {
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,8 @@ mod a {
|
||||||
c: t
|
c: t
|
||||||
|
|
||||||
crate::a::b::c
|
crate::a::b::c
|
||||||
A: v
|
A: vg
|
||||||
b: t
|
b: tg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -256,8 +256,8 @@ pub enum Foo { Bar, Baz }
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Bar: t v
|
Bar: tg vg
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -421,10 +421,10 @@ pub struct NotExported;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Exported: t v
|
Exported: tg vg
|
||||||
PublicItem: t v
|
PublicItem: tg vg
|
||||||
allowed_reexport: t
|
allowed_reexport: tg
|
||||||
exported: t
|
exported: tg
|
||||||
not_allowed_reexport1: _
|
not_allowed_reexport1: _
|
||||||
not_allowed_reexport2: _
|
not_allowed_reexport2: _
|
||||||
"#]],
|
"#]],
|
||||||
|
|
@ -692,7 +692,7 @@ mod b {
|
||||||
b: t
|
b: t
|
||||||
|
|
||||||
crate::a
|
crate::a
|
||||||
T: t v
|
T: t vg
|
||||||
|
|
||||||
crate::b
|
crate::b
|
||||||
T: v
|
T: v
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ pub struct Baz;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
Foo: t v
|
Foo: tg vg
|
||||||
bar: t
|
bar: tg
|
||||||
foo: t
|
foo: t
|
||||||
|
|
||||||
crate::foo
|
crate::foo
|
||||||
|
|
@ -53,20 +53,20 @@ pub use super::*;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
Foo: t v
|
Foo: tg vg
|
||||||
bar: t
|
bar: tg
|
||||||
foo: t
|
foo: t
|
||||||
|
|
||||||
crate::foo
|
crate::foo
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
Foo: t v
|
Foo: t v
|
||||||
bar: t
|
bar: t
|
||||||
|
|
||||||
crate::foo::bar
|
crate::foo::bar
|
||||||
Baz: t v
|
Baz: t v
|
||||||
Foo: t v
|
Foo: tg vg
|
||||||
bar: t
|
bar: tg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -91,20 +91,20 @@ pub use super::*;
|
||||||
",
|
",
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
bar: t
|
bar: tg
|
||||||
foo: t
|
foo: t
|
||||||
|
|
||||||
crate::foo
|
crate::foo
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
PrivateStructFoo: t v
|
PrivateStructFoo: t v
|
||||||
bar: t
|
bar: t
|
||||||
|
|
||||||
crate::foo::bar
|
crate::foo::bar
|
||||||
Baz: t v
|
Baz: t v
|
||||||
PrivateStructBar: t v
|
PrivateStructBar: t v
|
||||||
PrivateStructFoo: t v
|
PrivateStructFoo: tg vg
|
||||||
bar: t
|
bar: tg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -130,9 +130,9 @@ pub(crate) struct PubCrateStruct;
|
||||||
",
|
",
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Foo: t
|
Foo: tg
|
||||||
PubCrateStruct: t v
|
PubCrateStruct: tg vg
|
||||||
bar: t
|
bar: tg
|
||||||
foo: t
|
foo: t
|
||||||
|
|
||||||
crate::foo
|
crate::foo
|
||||||
|
|
@ -160,7 +160,7 @@ pub struct Baz;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -178,7 +178,7 @@ struct Foo;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -193,8 +193,8 @@ use self::Foo::*;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Bar: t v
|
Bar: tg vg
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
Foo: t
|
Foo: t
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
@ -210,8 +210,8 @@ use self::Foo::{*};
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Bar: t v
|
Bar: tg vg
|
||||||
Baz: t v
|
Baz: tg vg
|
||||||
Foo: t
|
Foo: t
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
@ -359,7 +359,7 @@ use event::Event;
|
||||||
event: t
|
event: t
|
||||||
|
|
||||||
crate::event
|
crate::event
|
||||||
Event: t v
|
Event: t vg
|
||||||
serenity: t
|
serenity: t
|
||||||
|
|
||||||
crate::event::serenity
|
crate::event::serenity
|
||||||
|
|
@ -388,10 +388,10 @@ use reexport::*;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Trait: t
|
Trait: tg
|
||||||
defs: t
|
defs: t
|
||||||
function: v
|
function: vg
|
||||||
makro: m
|
makro: mg
|
||||||
reexport: t
|
reexport: t
|
||||||
|
|
||||||
crate::defs
|
crate::defs
|
||||||
|
|
@ -400,10 +400,10 @@ use reexport::*;
|
||||||
makro: m
|
makro: m
|
||||||
|
|
||||||
crate::reexport
|
crate::reexport
|
||||||
Trait: t
|
Trait: tg
|
||||||
function: v
|
function: vg
|
||||||
inner: t
|
inner: t
|
||||||
makro: m
|
makro: mg
|
||||||
|
|
||||||
crate::reexport::inner
|
crate::reexport::inner
|
||||||
Trait: ti
|
Trait: ti
|
||||||
|
|
@ -442,12 +442,12 @@ mod glob_target {
|
||||||
ShouldBePrivate: t v
|
ShouldBePrivate: t v
|
||||||
|
|
||||||
crate::outer
|
crate::outer
|
||||||
ShouldBePrivate: t v
|
ShouldBePrivate: tg vg
|
||||||
inner_superglob: t
|
inner_superglob: t
|
||||||
|
|
||||||
crate::outer::inner_superglob
|
crate::outer::inner_superglob
|
||||||
ShouldBePrivate: t v
|
ShouldBePrivate: tg vg
|
||||||
inner_superglob: t
|
inner_superglob: tg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -473,20 +473,20 @@ use reexport_2::*;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Placeholder: t v
|
Placeholder: tg vg
|
||||||
libs: t
|
libs: t
|
||||||
reexport_1: t
|
reexport_1: tg
|
||||||
reexport_2: t
|
reexport_2: t
|
||||||
|
|
||||||
crate::libs
|
crate::libs
|
||||||
Placeholder: t v
|
Placeholder: t v
|
||||||
|
|
||||||
crate::reexport_2
|
crate::reexport_2
|
||||||
Placeholder: t v
|
Placeholder: tg vg
|
||||||
reexport_1: t
|
reexport_1: t
|
||||||
|
|
||||||
crate::reexport_2::reexport_1
|
crate::reexport_2::reexport_1
|
||||||
Placeholder: t v
|
Placeholder: tg vg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,9 +97,9 @@ macro_rules! structs {
|
||||||
bar: t
|
bar: t
|
||||||
|
|
||||||
crate::bar
|
crate::bar
|
||||||
Bar: t
|
Bar: tg
|
||||||
Foo: t
|
Foo: tg
|
||||||
bar: t
|
bar: tg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -130,9 +130,9 @@ macro_rules! structs {
|
||||||
bar: t
|
bar: t
|
||||||
|
|
||||||
crate::bar
|
crate::bar
|
||||||
Bar: t
|
Bar: tg
|
||||||
Foo: t
|
Foo: tg
|
||||||
bar: t
|
bar: tg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -169,9 +169,9 @@ macro_rules! inner {
|
||||||
bar: t
|
bar: t
|
||||||
|
|
||||||
crate::bar
|
crate::bar
|
||||||
Bar: t
|
Bar: tg
|
||||||
Foo: t
|
Foo: tg
|
||||||
bar: t
|
bar: tg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -794,7 +794,7 @@ pub trait Clone {}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
Clone: t m
|
Clone: tg mg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1075,9 +1075,9 @@ macro_rules! mbe {
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
DummyTrait: m
|
DummyTrait: mg
|
||||||
attribute_macro: m
|
attribute_macro: mg
|
||||||
function_like_macro: m
|
function_like_macro: mg
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
item_scope::{ImportId, ImportOrExternCrate, ItemInNs},
|
item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob, ItemInNs},
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
MacroId, ModuleDefId,
|
MacroId, ModuleDefId,
|
||||||
};
|
};
|
||||||
|
|
@ -36,8 +36,8 @@ pub struct Item<Def, Import = ImportId> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type TypesItem = Item<ModuleDefId, ImportOrExternCrate>;
|
pub type TypesItem = Item<ModuleDefId, ImportOrExternCrate>;
|
||||||
pub type ValuesItem = Item<ModuleDefId>;
|
pub type ValuesItem = Item<ModuleDefId, ImportOrGlob>;
|
||||||
pub type MacrosItem = Item<MacroId>;
|
pub type MacrosItem = Item<MacroId, ImportOrGlob>;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
|
||||||
pub struct PerNs {
|
pub struct PerNs {
|
||||||
|
|
@ -59,7 +59,7 @@ impl PerNs {
|
||||||
PerNs { types: None, values: None, macros: None }
|
PerNs { types: None, values: None, macros: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn values(def: ModuleDefId, vis: Visibility, import: Option<ImportId>) -> PerNs {
|
pub fn values(def: ModuleDefId, vis: Visibility, import: Option<ImportOrGlob>) -> PerNs {
|
||||||
PerNs { types: None, values: Some(Item { def, vis, import }), macros: None }
|
PerNs { types: None, values: Some(Item { def, vis, import }), macros: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,7 +84,7 @@ impl PerNs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn macros(def: MacroId, vis: Visibility, import: Option<ImportId>) -> PerNs {
|
pub fn macros(def: MacroId, vis: Visibility, import: Option<ImportOrGlob>) -> PerNs {
|
||||||
PerNs { types: None, values: None, macros: Some(Item { def, vis, import }) }
|
PerNs { types: None, values: None, macros: Some(Item { def, vis, import }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ impl PerNs {
|
||||||
self.values.map(|it| it.def)
|
self.values.map(|it| it.def)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_values_import(self) -> Option<(ModuleDefId, Option<ImportId>)> {
|
pub fn take_values_import(self) -> Option<(ModuleDefId, Option<ImportOrGlob>)> {
|
||||||
self.values.map(|it| (it.def, it.import))
|
self.values.map(|it| (it.def, it.import))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ impl PerNs {
|
||||||
self.macros.map(|it| it.def)
|
self.macros.map(|it| it.def)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_macros_import(self) -> Option<(MacroId, Option<ImportId>)> {
|
pub fn take_macros_import(self) -> Option<(MacroId, Option<ImportOrGlob>)> {
|
||||||
self.macros.map(|it| (it.def, it.import))
|
self.macros.map(|it| (it.def, it.import))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,14 +159,12 @@ impl PerNs {
|
||||||
.map(|it| (ItemInNs::Types(it.def), it.import))
|
.map(|it| (ItemInNs::Types(it.def), it.import))
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(
|
.chain(
|
||||||
self.values.map(|it| {
|
self.values
|
||||||
(ItemInNs::Values(it.def), it.import.map(ImportOrExternCrate::Import))
|
.map(|it| (ItemInNs::Values(it.def), it.import.map(ImportOrExternCrate::from))),
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.chain(
|
.chain(
|
||||||
self.macros.map(|it| {
|
self.macros
|
||||||
(ItemInNs::Macros(it.def), it.import.map(ImportOrExternCrate::Import))
|
.map(|it| (ItemInNs::Macros(it.def), it.import.map(ImportOrExternCrate::from))),
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
generics::{GenericParams, TypeOrConstParamData},
|
generics::{GenericParams, TypeOrConstParamData},
|
||||||
hir::{BindingId, ExprId, LabelId},
|
hir::{BindingId, ExprId, LabelId},
|
||||||
item_scope::{BuiltinShadowMode, ImportId, ImportOrExternCrate, BUILTIN_SCOPE},
|
item_scope::{BuiltinShadowMode, ImportOrExternCrate, ImportOrGlob, BUILTIN_SCOPE},
|
||||||
lang_item::LangItemTarget,
|
lang_item::LangItemTarget,
|
||||||
nameres::{DefMap, MacroSubNs, ResolvePathResultPrefixInfo},
|
nameres::{DefMap, MacroSubNs, ResolvePathResultPrefixInfo},
|
||||||
path::{ModPath, Path, PathKind},
|
path::{ModPath, Path, PathKind},
|
||||||
|
|
@ -107,7 +107,7 @@ pub enum TypeNs {
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum ResolveValueResult {
|
pub enum ResolveValueResult {
|
||||||
ValueNs(ValueNs, Option<ImportId>),
|
ValueNs(ValueNs, Option<ImportOrGlob>),
|
||||||
Partial(TypeNs, usize, Option<ImportOrExternCrate>),
|
Partial(TypeNs, usize, Option<ImportOrExternCrate>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -485,7 +485,7 @@ impl Resolver {
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
path: &ModPath,
|
path: &ModPath,
|
||||||
expected_macro_kind: Option<MacroSubNs>,
|
expected_macro_kind: Option<MacroSubNs>,
|
||||||
) -> Option<(MacroId, Option<ImportId>)> {
|
) -> Option<(MacroId, Option<ImportOrGlob>)> {
|
||||||
let (item_map, module) = self.item_scope();
|
let (item_map, module) = self.item_scope();
|
||||||
item_map
|
item_map
|
||||||
.resolve_path(db, module, path, BuiltinShadowMode::Other, expected_macro_kind)
|
.resolve_path(db, module, path, BuiltinShadowMode::Other, expected_macro_kind)
|
||||||
|
|
@ -1014,7 +1014,7 @@ impl ModuleItemMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_value_ns(per_ns: PerNs) -> Option<(ValueNs, Option<ImportId>)> {
|
fn to_value_ns(per_ns: PerNs) -> Option<(ValueNs, Option<ImportOrGlob>)> {
|
||||||
let (def, import) = per_ns.take_values_import()?;
|
let (def, import) = per_ns.take_values_import()?;
|
||||||
let res = match def {
|
let res = match def {
|
||||||
ModuleDefId::FunctionId(it) => ValueNs::FunctionId(it),
|
ModuleDefId::FunctionId(it) => ValueNs::FunctionId(it),
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::{ImportId, ImportOrExternCrate},
|
item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob},
|
||||||
per_ns::Item,
|
per_ns::Item,
|
||||||
src::{HasChildSource, HasSource},
|
src::{HasChildSource, HasSource},
|
||||||
visibility::{Visibility, VisibilityExplicitness},
|
visibility::{Visibility, VisibilityExplicitness},
|
||||||
|
|
@ -55,9 +55,10 @@ impl DeclarationLocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents an outstanding module that the symbol collector must collect symbols from.
|
/// Represents an outstanding module that the symbol collector must collect symbols from.
|
||||||
|
#[derive(Debug)]
|
||||||
struct SymbolCollectorWork {
|
struct SymbolCollectorWork {
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
parent: Option<DefWithBodyId>,
|
parent: Option<Name>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SymbolCollector<'a> {
|
pub struct SymbolCollector<'a> {
|
||||||
|
|
@ -81,7 +82,15 @@ impl<'a> SymbolCollector<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_module(db: &dyn HirDatabase, module: Module) -> Box<[FileSymbol]> {
|
||||||
|
let mut symbol_collector = SymbolCollector::new(db);
|
||||||
|
symbol_collector.collect(module);
|
||||||
|
symbol_collector.finish()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn collect(&mut self, module: Module) {
|
pub fn collect(&mut self, module: Module) {
|
||||||
|
let _p = tracing::info_span!("SymbolCollector::collect", ?module).entered();
|
||||||
|
tracing::info!(?module, "SymbolCollector::collect",);
|
||||||
self.edition = module.krate().edition(self.db);
|
self.edition = module.krate().edition(self.db);
|
||||||
|
|
||||||
// The initial work is the root module we're collecting, additional work will
|
// The initial work is the root module we're collecting, additional work will
|
||||||
|
|
@ -97,16 +106,12 @@ impl<'a> SymbolCollector<'a> {
|
||||||
self.symbols.into_iter().collect()
|
self.symbols.into_iter().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_module(db: &dyn HirDatabase, module: Module) -> Box<[FileSymbol]> {
|
|
||||||
let mut symbol_collector = SymbolCollector::new(db);
|
|
||||||
symbol_collector.collect(module);
|
|
||||||
symbol_collector.finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn do_work(&mut self, work: SymbolCollectorWork) {
|
fn do_work(&mut self, work: SymbolCollectorWork) {
|
||||||
|
let _p = tracing::info_span!("SymbolCollector::do_work", ?work).entered();
|
||||||
|
tracing::info!(?work, "SymbolCollector::do_work");
|
||||||
self.db.unwind_if_cancelled();
|
self.db.unwind_if_cancelled();
|
||||||
|
|
||||||
let parent_name = work.parent.and_then(|id| self.def_with_body_id_name(id));
|
let parent_name = work.parent.map(|name| name.as_str().to_smolstr());
|
||||||
self.with_container_name(parent_name, |s| s.collect_from_module(work.module_id));
|
self.with_container_name(parent_name, |s| s.collect_from_module(work.module_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,18 +121,18 @@ impl<'a> SymbolCollector<'a> {
|
||||||
ModuleDefId::ModuleId(id) => this.push_module(id, name),
|
ModuleDefId::ModuleId(id) => this.push_module(id, name),
|
||||||
ModuleDefId::FunctionId(id) => {
|
ModuleDefId::FunctionId(id) => {
|
||||||
this.push_decl(id, name, false);
|
this.push_decl(id, name, false);
|
||||||
this.collect_from_body(id);
|
this.collect_from_body(id, Some(name.clone()));
|
||||||
}
|
}
|
||||||
ModuleDefId::AdtId(AdtId::StructId(id)) => this.push_decl(id, name, false),
|
ModuleDefId::AdtId(AdtId::StructId(id)) => this.push_decl(id, name, false),
|
||||||
ModuleDefId::AdtId(AdtId::EnumId(id)) => this.push_decl(id, name, false),
|
ModuleDefId::AdtId(AdtId::EnumId(id)) => this.push_decl(id, name, false),
|
||||||
ModuleDefId::AdtId(AdtId::UnionId(id)) => this.push_decl(id, name, false),
|
ModuleDefId::AdtId(AdtId::UnionId(id)) => this.push_decl(id, name, false),
|
||||||
ModuleDefId::ConstId(id) => {
|
ModuleDefId::ConstId(id) => {
|
||||||
this.push_decl(id, name, false);
|
this.push_decl(id, name, false);
|
||||||
this.collect_from_body(id);
|
this.collect_from_body(id, Some(name.clone()));
|
||||||
}
|
}
|
||||||
ModuleDefId::StaticId(id) => {
|
ModuleDefId::StaticId(id) => {
|
||||||
this.push_decl(id, name, false);
|
this.push_decl(id, name, false);
|
||||||
this.collect_from_body(id);
|
this.collect_from_body(id, Some(name.clone()));
|
||||||
}
|
}
|
||||||
ModuleDefId::TraitId(id) => {
|
ModuleDefId::TraitId(id) => {
|
||||||
this.push_decl(id, name, false);
|
this.push_decl(id, name, false);
|
||||||
|
|
@ -235,6 +240,7 @@ impl<'a> SymbolCollector<'a> {
|
||||||
if is_explicit_import(vis) {
|
if is_explicit_import(vis) {
|
||||||
match i {
|
match i {
|
||||||
ImportOrExternCrate::Import(i) => push_import(self, i, name, def),
|
ImportOrExternCrate::Import(i) => push_import(self, i, name, def),
|
||||||
|
ImportOrExternCrate::Glob(_) => (),
|
||||||
ImportOrExternCrate::ExternCrate(i) => {
|
ImportOrExternCrate::ExternCrate(i) => {
|
||||||
push_extern_crate(self, i, name, def)
|
push_extern_crate(self, i, name, def)
|
||||||
}
|
}
|
||||||
|
|
@ -249,7 +255,10 @@ impl<'a> SymbolCollector<'a> {
|
||||||
for (name, Item { def, vis, import }) in scope.macros() {
|
for (name, Item { def, vis, import }) in scope.macros() {
|
||||||
if let Some(i) = import {
|
if let Some(i) = import {
|
||||||
if is_explicit_import(vis) {
|
if is_explicit_import(vis) {
|
||||||
push_import(self, i, name, def.into());
|
match i {
|
||||||
|
ImportOrGlob::Import(i) => push_import(self, i, name, def.into()),
|
||||||
|
ImportOrGlob::Glob(_) => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -260,7 +269,10 @@ impl<'a> SymbolCollector<'a> {
|
||||||
for (name, Item { def, vis, import }) in scope.values() {
|
for (name, Item { def, vis, import }) in scope.values() {
|
||||||
if let Some(i) = import {
|
if let Some(i) = import {
|
||||||
if is_explicit_import(vis) {
|
if is_explicit_import(vis) {
|
||||||
push_import(self, i, name, def);
|
match i {
|
||||||
|
ImportOrGlob::Import(i) => push_import(self, i, name, def),
|
||||||
|
ImportOrGlob::Glob(_) => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +281,7 @@ impl<'a> SymbolCollector<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for const_id in scope.unnamed_consts() {
|
for const_id in scope.unnamed_consts() {
|
||||||
self.collect_from_body(const_id);
|
self.collect_from_body(const_id, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name, id) in scope.legacy_macros() {
|
for (name, id) in scope.legacy_macros() {
|
||||||
|
|
@ -285,7 +297,7 @@ impl<'a> SymbolCollector<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_from_body(&mut self, body_id: impl Into<DefWithBodyId>) {
|
fn collect_from_body(&mut self, body_id: impl Into<DefWithBodyId>, name: Option<Name>) {
|
||||||
let body_id = body_id.into();
|
let body_id = body_id.into();
|
||||||
let body = self.db.body(body_id);
|
let body = self.db.body(body_id);
|
||||||
|
|
||||||
|
|
@ -294,7 +306,7 @@ impl<'a> SymbolCollector<'a> {
|
||||||
for (id, _) in def_map.modules() {
|
for (id, _) in def_map.modules() {
|
||||||
self.work.push(SymbolCollectorWork {
|
self.work.push(SymbolCollectorWork {
|
||||||
module_id: def_map.module_id(id),
|
module_id: def_map.module_id(id),
|
||||||
parent: Some(body_id),
|
parent: name.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -333,24 +345,6 @@ impl<'a> SymbolCollector<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn def_with_body_id_name(&self, body_id: DefWithBodyId) -> Option<SmolStr> {
|
|
||||||
match body_id {
|
|
||||||
DefWithBodyId::FunctionId(id) => {
|
|
||||||
Some(self.db.function_data(id).name.display_no_db(self.edition).to_smolstr())
|
|
||||||
}
|
|
||||||
DefWithBodyId::StaticId(id) => {
|
|
||||||
Some(self.db.static_data(id).name.display_no_db(self.edition).to_smolstr())
|
|
||||||
}
|
|
||||||
DefWithBodyId::ConstId(id) => {
|
|
||||||
Some(self.db.const_data(id).name.as_ref()?.display_no_db(self.edition).to_smolstr())
|
|
||||||
}
|
|
||||||
DefWithBodyId::VariantId(id) => {
|
|
||||||
Some(self.db.enum_variant_data(id).name.display_no_db(self.edition).to_smolstr())
|
|
||||||
}
|
|
||||||
DefWithBodyId::InTypeConstId(_) => Some("in type const".into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn push_assoc_item(&mut self, assoc_item_id: AssocItemId, name: &Name) {
|
fn push_assoc_item(&mut self, assoc_item_id: AssocItemId, name: &Name) {
|
||||||
match assoc_item_id {
|
match assoc_item_id {
|
||||||
AssocItemId::FunctionId(id) => self.push_decl(id, name, true),
|
AssocItemId::FunctionId(id) => self.push_decl(id, name, true),
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Ar
|
||||||
fn module_symbols(db: &dyn SymbolsDatabase, module: Module) -> Arc<SymbolIndex> {
|
fn module_symbols(db: &dyn SymbolsDatabase, module: Module) -> Arc<SymbolIndex> {
|
||||||
let _p = tracing::info_span!("module_symbols").entered();
|
let _p = tracing::info_span!("module_symbols").entered();
|
||||||
|
|
||||||
Arc::new(SymbolIndex::new(SymbolCollector::collect_module(db.upcast(), module)))
|
Arc::new(SymbolIndex::new(SymbolCollector::new_module(db.upcast(), module)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn crate_symbols(db: &dyn SymbolsDatabase, krate: Crate) -> Box<[Arc<SymbolIndex>]> {
|
pub fn crate_symbols(db: &dyn SymbolsDatabase, krate: Crate) -> Box<[Arc<SymbolIndex>]> {
|
||||||
|
|
@ -284,13 +284,15 @@ impl SymbolIndex {
|
||||||
builder.insert(key, value).unwrap();
|
builder.insert(key, value).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: fst::Map should ideally have a way to shrink the backing buffer without the unwrap dance
|
let map = builder
|
||||||
let map = fst::Map::new({
|
.into_inner()
|
||||||
let mut buf = builder.into_inner().unwrap();
|
.and_then(|mut buf| {
|
||||||
buf.shrink_to_fit();
|
fst::Map::new({
|
||||||
buf
|
buf.shrink_to_fit();
|
||||||
})
|
buf
|
||||||
.unwrap();
|
})
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
SymbolIndex { symbols, map }
|
SymbolIndex { symbols, map }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -491,7 +493,7 @@ pub(self) use crate::Trait as IsThisJustATrait;
|
||||||
.modules(&db)
|
.modules(&db)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|module_id| {
|
.map(|module_id| {
|
||||||
let mut symbols = SymbolCollector::collect_module(&db, module_id);
|
let mut symbols = SymbolCollector::new_module(&db, module_id);
|
||||||
symbols.sort_by_key(|it| it.name.as_str().to_owned());
|
symbols.sort_by_key(|it| it.name.as_str().to_owned());
|
||||||
(module_id, symbols)
|
(module_id, symbols)
|
||||||
})
|
})
|
||||||
|
|
@ -518,7 +520,7 @@ struct Duplicate;
|
||||||
.modules(&db)
|
.modules(&db)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|module_id| {
|
.map(|module_id| {
|
||||||
let mut symbols = SymbolCollector::collect_module(&db, module_id);
|
let mut symbols = SymbolCollector::new_module(&db, module_id);
|
||||||
symbols.sort_by_key(|it| it.name.as_str().to_owned());
|
symbols.sort_by_key(|it| it.name.as_str().to_owned());
|
||||||
(module_id, symbols)
|
(module_id, symbols)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue