aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/hir/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/hir/mod.rs')
-rw-r--r--crates/ra_analysis/src/hir/mod.rs45
1 files changed, 44 insertions, 1 deletions
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs
index 61e6c9913..83131384d 100644
--- a/crates/ra_analysis/src/hir/mod.rs
+++ b/crates/ra_analysis/src/hir/mod.rs
@@ -14,11 +14,11 @@ mod path;
14use std::ops::Index; 14use std::ops::Index;
15 15
16use ra_syntax::{SyntaxNodeRef, SyntaxNode}; 16use ra_syntax::{SyntaxNodeRef, SyntaxNode};
17use ra_db::{LocationIntener, SourceRootId};
17 18
18use crate::{ 19use crate::{
19 FileId, 20 FileId,
20 hir::db::HirDatabase, 21 hir::db::HirDatabase,
21 loc2id::{DefId, DefLoc},
22 Cancelable, 22 Cancelable,
23 arena::{Arena, Id}, 23 arena::{Arena, Id},
24}; 24};
@@ -31,6 +31,49 @@ pub(crate) use self::{
31 31
32pub use self::function::FnSignatureInfo; 32pub use self::function::FnSignatureInfo;
33 33
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
35pub(crate) struct FnId(u32);
36ra_db::impl_numeric_id!(FnId);
37
38impl FnId {
39 pub(crate) fn from_loc(
40 db: &impl AsRef<LocationIntener<SourceItemId, FnId>>,
41 loc: &SourceItemId,
42 ) -> FnId {
43 db.as_ref().loc2id(loc)
44 }
45 pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<SourceItemId, FnId>>) -> SourceItemId {
46 db.as_ref().id2loc(self)
47 }
48}
49
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
51pub(crate) struct DefId(u32);
52ra_db::impl_numeric_id!(DefId);
53
54#[derive(Clone, Debug, PartialEq, Eq, Hash)]
55pub(crate) enum DefLoc {
56 Module {
57 id: ModuleId,
58 source_root: SourceRootId,
59 },
60 Item {
61 source_item_id: SourceItemId,
62 },
63}
64
65impl DefId {
66 pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc {
67 db.as_ref().id2loc(self)
68 }
69}
70
71impl DefLoc {
72 pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId {
73 db.as_ref().loc2id(&self)
74 }
75}
76
34pub(crate) enum Def { 77pub(crate) enum Def {
35 Module(Module), 78 Module(Module),
36 Item, 79 Item,