module-scoped defloc
This commit is contained in:
parent
45fce90349
commit
947e3350e0
3 changed files with 43 additions and 24 deletions
|
@ -61,15 +61,18 @@ impl FnId {
|
|||
pub struct DefId(u32);
|
||||
ra_db::impl_numeric_id!(DefId);
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum DefKind {
|
||||
Module,
|
||||
Item,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum DefLoc {
|
||||
Module {
|
||||
id: ModuleId,
|
||||
source_root: SourceRootId,
|
||||
},
|
||||
Item {
|
||||
source_item_id: SourceItemId,
|
||||
},
|
||||
pub struct DefLoc {
|
||||
pub(crate) kind: DefKind,
|
||||
source_root_id: SourceRootId,
|
||||
module_id: ModuleId,
|
||||
source_item_id: SourceItemId,
|
||||
}
|
||||
|
||||
impl DefId {
|
||||
|
@ -92,12 +95,12 @@ pub enum Def {
|
|||
impl DefId {
|
||||
pub fn resolve(self, db: &impl HirDatabase) -> Cancelable<Def> {
|
||||
let loc = self.loc(db);
|
||||
let res = match loc {
|
||||
DefLoc::Module { id, source_root } => {
|
||||
let descr = Module::new(db, source_root, id)?;
|
||||
let res = match loc.kind {
|
||||
DefKind::Module => {
|
||||
let descr = Module::new(db, loc.source_root_id, loc.module_id)?;
|
||||
Def::Module(descr)
|
||||
}
|
||||
DefLoc::Item { .. } => Def::Item,
|
||||
DefKind::Item => Def::Item,
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use ra_db::{SourceRootId, FileId, FilePosition, Cancelable};
|
|||
use relative_path::RelativePathBuf;
|
||||
|
||||
use crate::{
|
||||
DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId,
|
||||
DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId,
|
||||
arena::{Arena, Id},
|
||||
};
|
||||
|
||||
|
@ -127,9 +127,11 @@ impl Module {
|
|||
}
|
||||
|
||||
pub fn def_id(&self, db: &impl HirDatabase) -> DefId {
|
||||
let def_loc = DefLoc::Module {
|
||||
id: self.module_id,
|
||||
source_root: self.source_root_id,
|
||||
let def_loc = DefLoc {
|
||||
kind: DefKind::Module,
|
||||
source_root_id: self.source_root_id,
|
||||
module_id: self.module_id,
|
||||
source_item_id: self.module_id.source(&self.tree).0,
|
||||
};
|
||||
def_loc.id(db)
|
||||
}
|
||||
|
@ -161,7 +163,12 @@ impl Module {
|
|||
let segments = path.segments;
|
||||
for name in segments.iter() {
|
||||
let module = match curr.loc(db) {
|
||||
DefLoc::Module { id, source_root } => Module::new(db, source_root, id)?,
|
||||
DefLoc {
|
||||
kind: DefKind::Module,
|
||||
source_root_id,
|
||||
module_id,
|
||||
..
|
||||
} => Module::new(db, source_root_id, module_id)?,
|
||||
_ => return Ok(None),
|
||||
};
|
||||
let scope = module.scope(db)?;
|
||||
|
|
|
@ -28,7 +28,7 @@ use ra_db::SourceRootId;
|
|||
|
||||
use crate::{
|
||||
Cancelable, FileId,
|
||||
DefId, DefLoc,
|
||||
DefId, DefLoc, DefKind,
|
||||
SourceItemId, SourceFileItemId, SourceFileItems,
|
||||
Path, PathKind,
|
||||
HirDatabase,
|
||||
|
@ -247,7 +247,10 @@ where
|
|||
// handle submodules separatelly
|
||||
continue;
|
||||
}
|
||||
let def_loc = DefLoc::Item {
|
||||
let def_loc = DefLoc {
|
||||
kind: DefKind::Item,
|
||||
source_root_id: self.source_root,
|
||||
module_id,
|
||||
source_item_id: SourceItemId {
|
||||
file_id,
|
||||
item_id: item.id,
|
||||
|
@ -261,10 +264,12 @@ where
|
|||
module_items.items.insert(item.name.clone(), resolution);
|
||||
}
|
||||
|
||||
for (name, mod_id) in module_id.children(&self.module_tree) {
|
||||
let def_loc = DefLoc::Module {
|
||||
id: mod_id,
|
||||
source_root: self.source_root,
|
||||
for (name, module_id) in module_id.children(&self.module_tree) {
|
||||
let def_loc = DefLoc {
|
||||
kind: DefKind::Module,
|
||||
source_root_id: self.source_root,
|
||||
module_id,
|
||||
source_item_id: module_id.source(&self.module_tree).0,
|
||||
};
|
||||
let def_id = def_loc.id(self.db);
|
||||
let resolution = Resolution {
|
||||
|
@ -316,7 +321,11 @@ where
|
|||
|
||||
if !is_last {
|
||||
curr = match def_id.loc(self.db) {
|
||||
DefLoc::Module { id, .. } => id,
|
||||
DefLoc {
|
||||
kind: DefKind::Module,
|
||||
module_id,
|
||||
..
|
||||
} => module_id,
|
||||
_ => return,
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue