minor
This commit is contained in:
parent
d8b0379e10
commit
54d053c881
2 changed files with 17 additions and 7 deletions
|
@ -27,6 +27,11 @@ pub struct Function {
|
|||
}
|
||||
|
||||
impl Function {
|
||||
pub(crate) fn new(def_id: DefId) -> Function {
|
||||
let fn_id = FnId(def_id);
|
||||
Function { fn_id }
|
||||
}
|
||||
|
||||
pub fn guess_from_source(
|
||||
db: &impl HirDatabase,
|
||||
file_id: FileId,
|
||||
|
@ -42,8 +47,7 @@ impl Function {
|
|||
module_id: module.module_id,
|
||||
source_item_id,
|
||||
};
|
||||
let fn_id = FnId(def_loc.id(db));
|
||||
Ok(Some(Function { fn_id }))
|
||||
Ok(Some(Function::new(def_loc.id(db))))
|
||||
}
|
||||
|
||||
pub fn guess_for_name_ref(
|
||||
|
|
|
@ -41,6 +41,8 @@ pub use self::{
|
|||
|
||||
pub use self::function::FnSignatureInfo;
|
||||
|
||||
/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
|
||||
/// in a specific module.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct DefId(u32);
|
||||
ra_db::impl_numeric_id!(DefId);
|
||||
|
@ -61,13 +63,13 @@ pub struct DefLoc {
|
|||
}
|
||||
|
||||
impl DefId {
|
||||
pub fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc {
|
||||
pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc {
|
||||
db.as_ref().id2loc(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl DefLoc {
|
||||
pub fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId {
|
||||
pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId {
|
||||
db.as_ref().loc2id(&self)
|
||||
}
|
||||
}
|
||||
|
@ -83,10 +85,14 @@ impl DefId {
|
|||
let loc = self.loc(db);
|
||||
let res = match loc.kind {
|
||||
DefKind::Module => {
|
||||
let descr = Module::new(db, loc.source_root_id, loc.module_id)?;
|
||||
Def::Module(descr)
|
||||
let module = Module::new(db, loc.source_root_id, loc.module_id)?;
|
||||
Def::Module(module)
|
||||
}
|
||||
DefKind::Item | DefKind::Function => Def::Item,
|
||||
DefKind::Function => {
|
||||
let function = Function::new(self);
|
||||
Def::Function(function)
|
||||
}
|
||||
DefKind::Item => Def::Item,
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue