diff options
author | Aleksey Kladov <[email protected]> | 2018-12-04 20:52:14 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-04 20:52:14 +0000 |
commit | 54d053c881514b024ba399ce2edc678e3f710ab7 (patch) | |
tree | be2864c8f1906f096e37e0778fa18524e2ddbe67 /crates/ra_hir | |
parent | d8b0379e1063941331253905795699a918233ef9 (diff) |
minor
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/function/mod.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 16 |
2 files changed, 17 insertions, 7 deletions
diff --git a/crates/ra_hir/src/function/mod.rs b/crates/ra_hir/src/function/mod.rs index a6757601e..e00bca6e3 100644 --- a/crates/ra_hir/src/function/mod.rs +++ b/crates/ra_hir/src/function/mod.rs | |||
@@ -27,6 +27,11 @@ pub struct Function { | |||
27 | } | 27 | } |
28 | 28 | ||
29 | impl Function { | 29 | impl Function { |
30 | pub(crate) fn new(def_id: DefId) -> Function { | ||
31 | let fn_id = FnId(def_id); | ||
32 | Function { fn_id } | ||
33 | } | ||
34 | |||
30 | pub fn guess_from_source( | 35 | pub fn guess_from_source( |
31 | db: &impl HirDatabase, | 36 | db: &impl HirDatabase, |
32 | file_id: FileId, | 37 | file_id: FileId, |
@@ -42,8 +47,7 @@ impl Function { | |||
42 | module_id: module.module_id, | 47 | module_id: module.module_id, |
43 | source_item_id, | 48 | source_item_id, |
44 | }; | 49 | }; |
45 | let fn_id = FnId(def_loc.id(db)); | 50 | Ok(Some(Function::new(def_loc.id(db)))) |
46 | Ok(Some(Function { fn_id })) | ||
47 | } | 51 | } |
48 | 52 | ||
49 | pub fn guess_for_name_ref( | 53 | pub fn guess_for_name_ref( |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index dbcc5e46d..9168dad3b 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -41,6 +41,8 @@ pub use self::{ | |||
41 | 41 | ||
42 | pub use self::function::FnSignatureInfo; | 42 | pub use self::function::FnSignatureInfo; |
43 | 43 | ||
44 | /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) | ||
45 | /// in a specific module. | ||
44 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 46 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
45 | pub struct DefId(u32); | 47 | pub struct DefId(u32); |
46 | ra_db::impl_numeric_id!(DefId); | 48 | ra_db::impl_numeric_id!(DefId); |
@@ -61,13 +63,13 @@ pub struct DefLoc { | |||
61 | } | 63 | } |
62 | 64 | ||
63 | impl DefId { | 65 | impl DefId { |
64 | pub fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { | 66 | pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { |
65 | db.as_ref().id2loc(self) | 67 | db.as_ref().id2loc(self) |
66 | } | 68 | } |
67 | } | 69 | } |
68 | 70 | ||
69 | impl DefLoc { | 71 | impl DefLoc { |
70 | pub fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId { | 72 | pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId { |
71 | db.as_ref().loc2id(&self) | 73 | db.as_ref().loc2id(&self) |
72 | } | 74 | } |
73 | } | 75 | } |
@@ -83,10 +85,14 @@ impl DefId { | |||
83 | let loc = self.loc(db); | 85 | let loc = self.loc(db); |
84 | let res = match loc.kind { | 86 | let res = match loc.kind { |
85 | DefKind::Module => { | 87 | DefKind::Module => { |
86 | let descr = Module::new(db, loc.source_root_id, loc.module_id)?; | 88 | let module = Module::new(db, loc.source_root_id, loc.module_id)?; |
87 | Def::Module(descr) | 89 | Def::Module(module) |
88 | } | 90 | } |
89 | DefKind::Item | DefKind::Function => Def::Item, | 91 | DefKind::Function => { |
92 | let function = Function::new(self); | ||
93 | Def::Function(function) | ||
94 | } | ||
95 | DefKind::Item => Def::Item, | ||
90 | }; | 96 | }; |
91 | Ok(res) | 97 | Ok(res) |
92 | } | 98 | } |