mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Add functions to DefId
This commit is contained in:
parent
947e3350e0
commit
d8b0379e10
10 changed files with 90 additions and 83 deletions
|
@ -41,22 +41,6 @@ pub use self::{
|
|||
|
||||
pub use self::function::FnSignatureInfo;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct FnId(u32);
|
||||
ra_db::impl_numeric_id!(FnId);
|
||||
|
||||
impl FnId {
|
||||
pub fn from_loc(
|
||||
db: &impl AsRef<LocationIntener<SourceItemId, FnId>>,
|
||||
loc: &SourceItemId,
|
||||
) -> FnId {
|
||||
db.as_ref().loc2id(loc)
|
||||
}
|
||||
pub fn loc(self, db: &impl AsRef<LocationIntener<SourceItemId, FnId>>) -> SourceItemId {
|
||||
db.as_ref().id2loc(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct DefId(u32);
|
||||
ra_db::impl_numeric_id!(DefId);
|
||||
|
@ -64,6 +48,7 @@ ra_db::impl_numeric_id!(DefId);
|
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum DefKind {
|
||||
Module,
|
||||
Function,
|
||||
Item,
|
||||
}
|
||||
|
||||
|
@ -89,6 +74,7 @@ impl DefLoc {
|
|||
|
||||
pub enum Def {
|
||||
Module(Module),
|
||||
Function(Function),
|
||||
Item,
|
||||
}
|
||||
|
||||
|
@ -100,7 +86,7 @@ impl DefId {
|
|||
let descr = Module::new(db, loc.source_root_id, loc.module_id)?;
|
||||
Def::Module(descr)
|
||||
}
|
||||
DefKind::Item => Def::Item,
|
||||
DefKind::Item | DefKind::Function => Def::Item,
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue