diff options
Diffstat (limited to 'crates/ra_analysis/src/hir/mod.rs')
-rw-r--r-- | crates/ra_analysis/src/hir/mod.rs | 45 |
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; | |||
14 | use std::ops::Index; | 14 | use std::ops::Index; |
15 | 15 | ||
16 | use ra_syntax::{SyntaxNodeRef, SyntaxNode}; | 16 | use ra_syntax::{SyntaxNodeRef, SyntaxNode}; |
17 | use ra_db::{LocationIntener, SourceRootId}; | ||
17 | 18 | ||
18 | use crate::{ | 19 | use 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 | ||
32 | pub use self::function::FnSignatureInfo; | 32 | pub use self::function::FnSignatureInfo; |
33 | 33 | ||
34 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
35 | pub(crate) struct FnId(u32); | ||
36 | ra_db::impl_numeric_id!(FnId); | ||
37 | |||
38 | impl 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)] | ||
51 | pub(crate) struct DefId(u32); | ||
52 | ra_db::impl_numeric_id!(DefId); | ||
53 | |||
54 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
55 | pub(crate) enum DefLoc { | ||
56 | Module { | ||
57 | id: ModuleId, | ||
58 | source_root: SourceRootId, | ||
59 | }, | ||
60 | Item { | ||
61 | source_item_id: SourceItemId, | ||
62 | }, | ||
63 | } | ||
64 | |||
65 | impl DefId { | ||
66 | pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { | ||
67 | db.as_ref().id2loc(self) | ||
68 | } | ||
69 | } | ||
70 | |||
71 | impl DefLoc { | ||
72 | pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId { | ||
73 | db.as_ref().loc2id(&self) | ||
74 | } | ||
75 | } | ||
76 | |||
34 | pub(crate) enum Def { | 77 | pub(crate) enum Def { |
35 | Module(Module), | 78 | Module(Module), |
36 | Item, | 79 | Item, |