diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 74 |
1 files changed, 3 insertions, 71 deletions
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 6419d3934..480ec27bf 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -2,10 +2,10 @@ use ra_db::FileId; | |||
2 | use ra_syntax::{ast, SyntaxNode, TreeArc}; | 2 | use ra_syntax::{ast, SyntaxNode, TreeArc}; |
3 | 3 | ||
4 | use crate::{ | 4 | use crate::{ |
5 | Module, ModuleSource, Problem, ModuleDef, | 5 | Module, ModuleSource, Problem, |
6 | Crate, Name, Path, PathKind, PerNs, | 6 | Crate, Name, |
7 | module_tree::ModuleId, | 7 | module_tree::ModuleId, |
8 | nameres::{ModuleScope, lower::ImportId}, | 8 | nameres::{lower::ImportId}, |
9 | db::HirDatabase, | 9 | db::HirDatabase, |
10 | }; | 10 | }; |
11 | 11 | ||
@@ -90,74 +90,6 @@ impl Module { | |||
90 | Some(self.with_module_id(parent_id)) | 90 | Some(self.with_module_id(parent_id)) |
91 | } | 91 | } |
92 | 92 | ||
93 | /// Returns a `ModuleScope`: a set of items, visible in this module. | ||
94 | pub(crate) fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope { | ||
95 | let item_map = db.item_map(self.krate); | ||
96 | item_map.per_module[&self.module_id].clone() | ||
97 | } | ||
98 | |||
99 | pub(crate) fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs<ModuleDef> { | ||
100 | let mut curr_per_ns: PerNs<ModuleDef> = PerNs::types(match path.kind { | ||
101 | PathKind::Crate => self.crate_root(db).into(), | ||
102 | PathKind::Self_ | PathKind::Plain => self.clone().into(), | ||
103 | PathKind::Super => { | ||
104 | if let Some(p) = self.parent(db) { | ||
105 | p.into() | ||
106 | } else { | ||
107 | return PerNs::none(); | ||
108 | } | ||
109 | } | ||
110 | PathKind::Abs => { | ||
111 | // TODO: absolute use is not supported | ||
112 | return PerNs::none(); | ||
113 | } | ||
114 | }); | ||
115 | |||
116 | for segment in path.segments.iter() { | ||
117 | let curr = match curr_per_ns.as_ref().take_types() { | ||
118 | Some(r) => r, | ||
119 | None => { | ||
120 | // we still have path segments left, but the path so far | ||
121 | // didn't resolve in the types namespace => no resolution | ||
122 | // (don't break here because curr_per_ns might contain | ||
123 | // something in the value namespace, and it would be wrong | ||
124 | // to return that) | ||
125 | return PerNs::none(); | ||
126 | } | ||
127 | }; | ||
128 | // resolve segment in curr | ||
129 | |||
130 | curr_per_ns = match curr { | ||
131 | ModuleDef::Module(m) => { | ||
132 | let scope = m.scope(db); | ||
133 | match scope.get(&segment.name) { | ||
134 | Some(r) => r.def_id.clone(), | ||
135 | None => PerNs::none(), | ||
136 | } | ||
137 | } | ||
138 | ModuleDef::Enum(e) => { | ||
139 | // enum variant | ||
140 | let matching_variant = e | ||
141 | .variants(db) | ||
142 | .into_iter() | ||
143 | .find(|(n, _variant)| n == &segment.name); | ||
144 | |||
145 | match matching_variant { | ||
146 | Some((_n, variant)) => PerNs::both(variant.into(), (*e).into()), | ||
147 | None => PerNs::none(), | ||
148 | } | ||
149 | } | ||
150 | _ => { | ||
151 | // could be an inherent method call in UFCS form | ||
152 | // (`Struct::method`), or some other kind of associated | ||
153 | // item... Which we currently don't handle (TODO) | ||
154 | PerNs::none() | ||
155 | } | ||
156 | }; | ||
157 | } | ||
158 | curr_per_ns | ||
159 | } | ||
160 | |||
161 | pub(crate) fn problems_impl( | 93 | pub(crate) fn problems_impl( |
162 | &self, | 94 | &self, |
163 | db: &impl HirDatabase, | 95 | db: &impl HirDatabase, |