mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
rename def_id -> def
This commit is contained in:
parent
e884ab05c2
commit
bc77f91cf6
3 changed files with 17 additions and 31 deletions
|
@ -59,7 +59,7 @@ impl ModuleScope {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Resolution {
|
pub struct Resolution {
|
||||||
/// None for unresolved
|
/// None for unresolved
|
||||||
pub def_id: PerNs<ModuleDef>,
|
pub def: PerNs<ModuleDef>,
|
||||||
/// ident by which this is imported into local scope.
|
/// ident by which this is imported into local scope.
|
||||||
pub import: Option<ImportId>,
|
pub import: Option<ImportId>,
|
||||||
}
|
}
|
||||||
|
@ -211,11 +211,11 @@ where
|
||||||
let krate = Crate::new(crate_id);
|
let krate = Crate::new(crate_id);
|
||||||
for dep in krate.dependencies(self.db) {
|
for dep in krate.dependencies(self.db) {
|
||||||
if let Some(module) = dep.krate.root_module(self.db) {
|
if let Some(module) = dep.krate.root_module(self.db) {
|
||||||
let def_id = module.into();
|
let def = module.into();
|
||||||
self.add_module_item(
|
self.add_module_item(
|
||||||
&mut module_items,
|
&mut module_items,
|
||||||
dep.name.clone(),
|
dep.name.clone(),
|
||||||
PerNs::types(def_id),
|
PerNs::types(def),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ where
|
||||||
module_items.items.insert(
|
module_items.items.insert(
|
||||||
segment.name.clone(),
|
segment.name.clone(),
|
||||||
Resolution {
|
Resolution {
|
||||||
def_id: PerNs::none(),
|
def: PerNs::none(),
|
||||||
import: Some(import_id),
|
import: Some(import_id),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -235,11 +235,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Populate explicitly declared items, except modules
|
// Populate explicitly declared items, except modules
|
||||||
for (name, &def_id) in input.declarations.iter() {
|
for (name, &def) in input.declarations.iter() {
|
||||||
let resolution = Resolution {
|
let resolution = Resolution { def, import: None };
|
||||||
def_id,
|
|
||||||
import: None,
|
|
||||||
};
|
|
||||||
module_items.items.insert(name.clone(), resolution);
|
module_items.items.insert(name.clone(), resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,16 +252,8 @@ where
|
||||||
self.result.per_module.insert(module_id, module_items);
|
self.result.per_module.insert(module_id, module_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_module_item(
|
fn add_module_item(&self, module_items: &mut ModuleScope, name: Name, def: PerNs<ModuleDef>) {
|
||||||
&self,
|
let resolution = Resolution { def, import: None };
|
||||||
module_items: &mut ModuleScope,
|
|
||||||
name: Name,
|
|
||||||
def_id: PerNs<ModuleDef>,
|
|
||||||
) {
|
|
||||||
let resolution = Resolution {
|
|
||||||
def_id,
|
|
||||||
import: None,
|
|
||||||
};
|
|
||||||
module_items.items.insert(name, resolution);
|
module_items.items.insert(name, resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +284,7 @@ where
|
||||||
krate: self.krate,
|
krate: self.krate,
|
||||||
module_id,
|
module_id,
|
||||||
};
|
};
|
||||||
let (def_id, reached_fixedpoint) =
|
let (def, reached_fixedpoint) =
|
||||||
self.result
|
self.result
|
||||||
.resolve_path_fp(self.db, original_module, &import.path);
|
.resolve_path_fp(self.db, original_module, &import.path);
|
||||||
|
|
||||||
|
@ -303,7 +292,7 @@ where
|
||||||
let last_segment = import.path.segments.last().unwrap();
|
let last_segment = import.path.segments.last().unwrap();
|
||||||
self.update(module_id, |items| {
|
self.update(module_id, |items| {
|
||||||
let res = Resolution {
|
let res = Resolution {
|
||||||
def_id,
|
def,
|
||||||
import: Some(import_id),
|
import: Some(import_id),
|
||||||
};
|
};
|
||||||
items.items.insert(last_segment.name.clone(), res);
|
items.items.insert(last_segment.name.clone(), res);
|
||||||
|
@ -312,7 +301,7 @@ where
|
||||||
"resolved import {:?} ({:?}) cross-source root to {:?}",
|
"resolved import {:?} ({:?}) cross-source root to {:?}",
|
||||||
last_segment.name,
|
last_segment.name,
|
||||||
import,
|
import,
|
||||||
def_id,
|
def,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
reached_fixedpoint
|
reached_fixedpoint
|
||||||
|
@ -388,12 +377,12 @@ impl ItemMap {
|
||||||
kind: PathKind::Crate,
|
kind: PathKind::Crate,
|
||||||
};
|
};
|
||||||
log::debug!("resolving {:?} in other crate", path);
|
log::debug!("resolving {:?} in other crate", path);
|
||||||
let def_id = module.resolve_path(db, &path);
|
let def = module.resolve_path(db, &path);
|
||||||
return (def_id, ReachedFixedPoint::Yes);
|
return (def, ReachedFixedPoint::Yes);
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.per_module[&module.module_id].items.get(&segment.name) {
|
match self.per_module[&module.module_id].items.get(&segment.name) {
|
||||||
Some(res) if !res.def_id.is_none() => res.def_id,
|
Some(res) if !res.def.is_none() => res.def,
|
||||||
_ => {
|
_ => {
|
||||||
log::debug!("path segment {:?} not found", segment.name);
|
log::debug!("path segment {:?} not found", segment.name);
|
||||||
return (PerNs::none(), ReachedFixedPoint::No);
|
return (PerNs::none(), ReachedFixedPoint::No);
|
||||||
|
|
|
@ -37,8 +37,8 @@ fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) {
|
||||||
|
|
||||||
fn dump_resolution(resolution: &Resolution) -> &'static str {
|
fn dump_resolution(resolution: &Resolution) -> &'static str {
|
||||||
match (
|
match (
|
||||||
resolution.def_id.types.is_some(),
|
resolution.def.types.is_some(),
|
||||||
resolution.def_id.values.is_some(),
|
resolution.def.values.is_some(),
|
||||||
) {
|
) {
|
||||||
(true, true) => "t v",
|
(true, true) => "t v",
|
||||||
(true, false) => "t",
|
(true, false) => "t",
|
||||||
|
|
|
@ -209,10 +209,7 @@ impl Builder {
|
||||||
ctx: &CompletionContext,
|
ctx: &CompletionContext,
|
||||||
resolution: &hir::Resolution,
|
resolution: &hir::Resolution,
|
||||||
) -> Builder {
|
) -> Builder {
|
||||||
let def = resolution
|
let def = resolution.def.take_types().or(resolution.def.take_values());
|
||||||
.def_id
|
|
||||||
.take_types()
|
|
||||||
.or(resolution.def_id.take_values());
|
|
||||||
let def = match def {
|
let def = match def {
|
||||||
None => return self,
|
None => return self,
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue