diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/nameres.rs')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/nameres.rs | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/nameres.rs b/crates/ra_analysis/src/descriptors/module/nameres.rs index 34127e78f..c5bf467ca 100644 --- a/crates/ra_analysis/src/descriptors/module/nameres.rs +++ b/crates/ra_analysis/src/descriptors/module/nameres.rs | |||
@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap; | |||
8 | 8 | ||
9 | use ra_syntax::{ | 9 | use ra_syntax::{ |
10 | SmolStr, SyntaxKind::{self, *}, | 10 | SmolStr, SyntaxKind::{self, *}, |
11 | ast::{self, NameOwner, AstNode, ModuleItemOwner} | 11 | ast::{self, AstNode, ModuleItemOwner} |
12 | }; | 12 | }; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
@@ -26,13 +26,13 @@ use crate::{ | |||
26 | /// module, the set of visible items. | 26 | /// module, the set of visible items. |
27 | #[derive(Default, Debug, PartialEq, Eq)] | 27 | #[derive(Default, Debug, PartialEq, Eq)] |
28 | pub(crate) struct ItemMap { | 28 | pub(crate) struct ItemMap { |
29 | per_module: FxHashMap<ModuleId, ModuleItems>, | 29 | pub(crate) per_module: FxHashMap<ModuleId, ModuleScope>, |
30 | } | 30 | } |
31 | 31 | ||
32 | #[derive(Debug, Default, PartialEq, Eq)] | 32 | #[derive(Debug, Default, PartialEq, Eq, Clone)] |
33 | struct ModuleItems { | 33 | pub(crate) struct ModuleScope { |
34 | items: FxHashMap<SmolStr, Resolution>, | 34 | pub(crate) items: FxHashMap<SmolStr, Resolution>, |
35 | import_resolutions: FxHashMap<LocalSyntaxPtr, DefId>, | 35 | pub(crate) import_resolutions: FxHashMap<LocalSyntaxPtr, DefId>, |
36 | } | 36 | } |
37 | 37 | ||
38 | /// A set of items and imports declared inside a module, without relation to | 38 | /// A set of items and imports declared inside a module, without relation to |
@@ -117,22 +117,25 @@ pub(crate) fn item_map( | |||
117 | /// Resolution is basically `DefId` atm, but it should account for stuff like | 117 | /// Resolution is basically `DefId` atm, but it should account for stuff like |
118 | /// multiple namespaces, ambiguity and errors. | 118 | /// multiple namespaces, ambiguity and errors. |
119 | #[derive(Debug, Clone, PartialEq, Eq)] | 119 | #[derive(Debug, Clone, PartialEq, Eq)] |
120 | struct Resolution { | 120 | pub(crate) struct Resolution { |
121 | /// None for unresolved | 121 | /// None for unresolved |
122 | def_id: Option<DefId>, | 122 | pub(crate) def_id: Option<DefId>, |
123 | /// ident by whitch this is imported into local scope. | ||
124 | /// TODO: make this offset-independent. | ||
125 | pub(crate) import_name: Option<LocalSyntaxPtr>, | ||
123 | } | 126 | } |
124 | 127 | ||
125 | #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | 128 | // #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
126 | enum Namespace { | 129 | // enum Namespace { |
127 | Types, | 130 | // Types, |
128 | Values, | 131 | // Values, |
129 | } | 132 | // } |
130 | 133 | ||
131 | #[derive(Debug)] | 134 | // #[derive(Debug)] |
132 | struct PerNs<T> { | 135 | // struct PerNs<T> { |
133 | types: Option<T>, | 136 | // types: Option<T>, |
134 | values: Option<T>, | 137 | // values: Option<T>, |
135 | } | 138 | // } |
136 | 139 | ||
137 | #[derive(Debug, PartialEq, Eq)] | 140 | #[derive(Debug, PartialEq, Eq)] |
138 | struct ModuleItem { | 141 | struct ModuleItem { |
@@ -144,7 +147,7 @@ struct ModuleItem { | |||
144 | 147 | ||
145 | #[derive(Debug, PartialEq, Eq)] | 148 | #[derive(Debug, PartialEq, Eq)] |
146 | enum Vis { | 149 | enum Vis { |
147 | Priv, | 150 | // Priv, |
148 | Other, | 151 | Other, |
149 | } | 152 | } |
150 | 153 | ||
@@ -302,13 +305,17 @@ where | |||
302 | fn populate_module(&mut self, module_id: ModuleId, input: &InputModuleItems) { | 305 | fn populate_module(&mut self, module_id: ModuleId, input: &InputModuleItems) { |
303 | let file_id = module_id.source(&self.module_tree).file_id(); | 306 | let file_id = module_id.source(&self.module_tree).file_id(); |
304 | 307 | ||
305 | let mut module_items = ModuleItems::default(); | 308 | let mut module_items = ModuleScope::default(); |
306 | 309 | ||
307 | for import in input.imports.iter() { | 310 | for import in input.imports.iter() { |
308 | if let Some((_, name)) = import.segments.last() { | 311 | if let Some((ptr, name)) = import.segments.last() { |
309 | module_items | 312 | module_items.items.insert( |
310 | .items | 313 | name.clone(), |
311 | .insert(name.clone(), Resolution { def_id: None }); | 314 | Resolution { |
315 | def_id: None, | ||
316 | import_name: Some(*ptr), | ||
317 | }, | ||
318 | ); | ||
312 | } | 319 | } |
313 | } | 320 | } |
314 | 321 | ||
@@ -322,6 +329,7 @@ where | |||
322 | let def_id = self.db.id_maps().def_id(def_loc); | 329 | let def_id = self.db.id_maps().def_id(def_loc); |
323 | let resolution = Resolution { | 330 | let resolution = Resolution { |
324 | def_id: Some(def_id), | 331 | def_id: Some(def_id), |
332 | import_name: None, | ||
325 | }; | 333 | }; |
326 | module_items.items.insert(item.name.clone(), resolution); | 334 | module_items.items.insert(item.name.clone(), resolution); |
327 | } | 335 | } |
@@ -334,6 +342,7 @@ where | |||
334 | let def_id = self.db.id_maps().def_id(def_loc); | 342 | let def_id = self.db.id_maps().def_id(def_loc); |
335 | let resolution = Resolution { | 343 | let resolution = Resolution { |
336 | def_id: Some(def_id), | 344 | def_id: Some(def_id), |
345 | import_name: None, | ||
337 | }; | 346 | }; |
338 | module_items.items.insert(name, resolution); | 347 | module_items.items.insert(name, resolution); |
339 | } | 348 | } |
@@ -386,6 +395,7 @@ where | |||
386 | self.update(module_id, |items| { | 395 | self.update(module_id, |items| { |
387 | let res = Resolution { | 396 | let res = Resolution { |
388 | def_id: Some(def_id), | 397 | def_id: Some(def_id), |
398 | import_name: Some(*ptr), | ||
389 | }; | 399 | }; |
390 | items.items.insert(name.clone(), res); | 400 | items.items.insert(name.clone(), res); |
391 | }) | 401 | }) |
@@ -393,7 +403,7 @@ where | |||
393 | } | 403 | } |
394 | } | 404 | } |
395 | 405 | ||
396 | fn update(&mut self, module_id: ModuleId, f: impl FnOnce(&mut ModuleItems)) { | 406 | fn update(&mut self, module_id: ModuleId, f: impl FnOnce(&mut ModuleScope)) { |
397 | let module_items = self.result.per_module.get_mut(&module_id).unwrap(); | 407 | let module_items = self.result.per_module.get_mut(&module_id).unwrap(); |
398 | f(module_items) | 408 | f(module_items) |
399 | } | 409 | } |