diff options
author | Aleksey Kladov <[email protected]> | 2019-01-05 09:13:16 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-06 14:35:29 +0000 |
commit | 8c4d2770362f3c2950f110f8e116ed8f537ec1a1 (patch) | |
tree | 4375e70e9f29d11dd3688fd57fe9080069e493b4 | |
parent | 147b0f94e60f66c73ee1ca1726de97d76721bfda (diff) |
switch source-binders to Module
-rw-r--r-- | crates/ra_hir/src/code_model_impl.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 26 |
2 files changed, 20 insertions, 9 deletions
diff --git a/crates/ra_hir/src/code_model_impl.rs b/crates/ra_hir/src/code_model_impl.rs index 22079ba33..659af548c 100644 --- a/crates/ra_hir/src/code_model_impl.rs +++ b/crates/ra_hir/src/code_model_impl.rs | |||
@@ -4,7 +4,6 @@ use crate::{HirFileId, db::HirDatabase, Crate, CrateDependency, AsName, DefId, D | |||
4 | 4 | ||
5 | use crate::code_model_api::Module; | 5 | use crate::code_model_api::Module; |
6 | 6 | ||
7 | |||
8 | impl Crate { | 7 | impl Crate { |
9 | pub(crate) fn new(crate_id: CrateId) -> Crate { | 8 | pub(crate) fn new(crate_id: CrateId) -> Crate { |
10 | Crate { crate_id } | 9 | Crate { crate_id } |
@@ -45,7 +44,7 @@ impl Crate { | |||
45 | } | 44 | } |
46 | 45 | ||
47 | impl Module { | 46 | impl Module { |
48 | fn new(def_id: DefId) -> Self { | 47 | pub(crate) fn new(def_id: DefId) -> Self { |
49 | crate::code_model_api::Module { def_id } | 48 | crate::code_model_api::Module { def_id } |
50 | } | 49 | } |
51 | 50 | ||
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 29a3960e9..ac097e81a 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -13,11 +13,13 @@ use ra_syntax::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | HirDatabase, Module, Function, SourceItemId, | 16 | HirDatabase, Function, SourceItemId, |
17 | module::ModuleSource, | 17 | module::ModuleSource, |
18 | DefKind, DefLoc, AsName, | 18 | DefKind, DefLoc, AsName, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | use crate::code_model_api::Module; | ||
22 | |||
21 | /// Locates the module by `FileId`. Picks topmost module in the file. | 23 | /// Locates the module by `FileId`. Picks topmost module in the file. |
22 | pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable<Option<Module>> { | 24 | pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Cancelable<Option<Module>> { |
23 | let module_source = ModuleSource::new_file(file_id.into()); | 25 | let module_source = ModuleSource::new_file(file_id.into()); |
@@ -34,7 +36,7 @@ pub fn module_from_declaration( | |||
34 | let child_name = decl.name(); | 36 | let child_name = decl.name(); |
35 | match (parent_module, child_name) { | 37 | match (parent_module, child_name) { |
36 | (Some(parent_module), Some(child_name)) => { | 38 | (Some(parent_module), Some(child_name)) => { |
37 | if let Some(child) = parent_module.child(&child_name.as_name()) { | 39 | if let Some(child) = parent_module.child(db, &child_name.as_name())? { |
38 | return Ok(Some(child)); | 40 | return Ok(Some(child)); |
39 | } | 41 | } |
40 | } | 42 | } |
@@ -84,7 +86,15 @@ fn module_from_source( | |||
84 | .modules_with_sources() | 86 | .modules_with_sources() |
85 | .find(|(_id, src)| src == &module_source); | 87 | .find(|(_id, src)| src == &module_source); |
86 | let module_id = ctry!(m).0; | 88 | let module_id = ctry!(m).0; |
87 | Ok(Some(Module::new(db, source_root_id, module_id)?)) | 89 | let def_loc = DefLoc { |
90 | kind: DefKind::Module, | ||
91 | source_root_id, | ||
92 | module_id, | ||
93 | source_item_id: module_source.0, | ||
94 | }; | ||
95 | let def_id = def_loc.id(db); | ||
96 | |||
97 | Ok(Some(Module::new(def_id))) | ||
88 | } | 98 | } |
89 | 99 | ||
90 | pub fn function_from_position( | 100 | pub fn function_from_position( |
@@ -114,7 +124,8 @@ pub fn function_from_module( | |||
114 | module: &Module, | 124 | module: &Module, |
115 | fn_def: ast::FnDef, | 125 | fn_def: ast::FnDef, |
116 | ) -> Function { | 126 | ) -> Function { |
117 | let file_id = module.source().file_id(); | 127 | let loc = module.def_id.loc(db); |
128 | let file_id = loc.source_item_id.file_id; | ||
118 | let file_items = db.file_items(file_id); | 129 | let file_items = db.file_items(file_id); |
119 | let item_id = file_items.id_of(file_id, fn_def.syntax()); | 130 | let item_id = file_items.id_of(file_id, fn_def.syntax()); |
120 | let source_item_id = SourceItemId { | 131 | let source_item_id = SourceItemId { |
@@ -123,8 +134,8 @@ pub fn function_from_module( | |||
123 | }; | 134 | }; |
124 | let def_loc = DefLoc { | 135 | let def_loc = DefLoc { |
125 | kind: DefKind::Function, | 136 | kind: DefKind::Function, |
126 | source_root_id: module.source_root_id, | 137 | source_root_id: loc.source_root_id, |
127 | module_id: module.module_id, | 138 | module_id: loc.module_id, |
128 | source_item_id, | 139 | source_item_id, |
129 | }; | 140 | }; |
130 | Function::new(def_loc.id(db)) | 141 | Function::new(def_loc.id(db)) |
@@ -147,7 +158,8 @@ pub fn macro_symbols( | |||
147 | Some(it) => it, | 158 | Some(it) => it, |
148 | None => return Ok(Vec::new()), | 159 | None => return Ok(Vec::new()), |
149 | }; | 160 | }; |
150 | let items = db.input_module_items(module.source_root_id, module.module_id)?; | 161 | let loc = module.def_id.loc(db); |
162 | let items = db.input_module_items(loc.source_root_id, loc.module_id)?; | ||
151 | let mut res = Vec::new(); | 163 | let mut res = Vec::new(); |
152 | 164 | ||
153 | for macro_call_id in items | 165 | for macro_call_id in items |