aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/module
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module')
-rw-r--r--crates/ra_analysis/src/descriptors/module/nameres.rs82
1 files changed, 6 insertions, 76 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/nameres.rs b/crates/ra_analysis/src/descriptors/module/nameres.rs
index 526e42af3..bf671470c 100644
--- a/crates/ra_analysis/src/descriptors/module/nameres.rs
+++ b/crates/ra_analysis/src/descriptors/module/nameres.rs
@@ -195,86 +195,16 @@ impl InputModuleItems {
195 } 195 }
196 196
197 fn add_use_item(&mut self, item: ast::UseItem) { 197 fn add_use_item(&mut self, item: ast::UseItem) {
198 if let Some(tree) = item.use_tree() { 198 Path::expand_use_item(item, |path, ptr| {
199 self.add_use_tree(None, tree); 199 let kind = match ptr {
200 } 200 None => ImportKind::Glob,
201 } 201 Some(ptr) => ImportKind::Named(ptr),
202
203 fn add_use_tree(&mut self, prefix: Option<Path>, tree: ast::UseTree) {
204 if let Some(use_tree_list) = tree.use_tree_list() {
205 let prefix = match tree.path() {
206 None => prefix,
207 Some(path) => match convert_path(prefix, path) {
208 Some(it) => Some(it),
209 None => return, // TODO: report errors somewhere
210 },
211 }; 202 };
212 for tree in use_tree_list.use_trees() { 203 self.imports.push(Import { kind, path })
213 self.add_use_tree(prefix.clone(), tree); 204 })
214 }
215 } else {
216 if let Some(ast_path) = tree.path() {
217 if let Some(path) = convert_path(prefix, ast_path) {
218 let kind = if tree.has_star() {
219 ImportKind::Glob
220 } else {
221 let ptr = LocalSyntaxPtr::new(ast_path.segment().unwrap().syntax());
222 ImportKind::Named(ptr)
223 };
224 self.imports.push(Import { kind, path })
225 }
226 }
227 }
228 } 205 }
229} 206}
230 207
231fn convert_path(prefix: Option<Path>, path: ast::Path) -> Option<Path> {
232 let prefix = if let Some(qual) = path.qualifier() {
233 Some(convert_path(prefix, qual)?)
234 } else {
235 None
236 };
237 let segment = path.segment()?;
238 let res = match segment.kind()? {
239 ast::PathSegmentKind::Name(name) => {
240 let mut res = prefix.unwrap_or_else(|| Path {
241 kind: PathKind::Abs,
242 segments: Vec::with_capacity(1),
243 });
244 res.segments.push(name.text());
245 res
246 }
247 ast::PathSegmentKind::CrateKw => {
248 if prefix.is_some() {
249 return None;
250 }
251 Path {
252 kind: PathKind::Crate,
253 segments: Vec::new(),
254 }
255 }
256 ast::PathSegmentKind::SelfKw => {
257 if prefix.is_some() {
258 return None;
259 }
260 Path {
261 kind: PathKind::Self_,
262 segments: Vec::new(),
263 }
264 }
265 ast::PathSegmentKind::SuperKw => {
266 if prefix.is_some() {
267 return None;
268 }
269 Path {
270 kind: PathKind::Super,
271 segments: Vec::new(),
272 }
273 }
274 };
275 Some(res)
276}
277
278impl ModuleItem { 208impl ModuleItem {
279 fn new<'a>(item: impl ast::NameOwner<'a>) -> Option<ModuleItem> { 209 fn new<'a>(item: impl ast::NameOwner<'a>) -> Option<ModuleItem> {
280 let name = item.name()?.text(); 210 let name = item.name()?.text();