From d8d60215dacc3eeddeda4d6af7007e2129fdb00e Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Fri, 21 Dec 2018 22:29:59 +0000 Subject: Fix handling of nested self in paths --- crates/ra_hir/src/path.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/path.rs') diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index 4a2e427cd..1b3fb4306 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs @@ -76,14 +76,32 @@ fn expand_use_tree( ) { if let Some(use_tree_list) = tree.use_tree_list() { let prefix = match tree.path() { + // E.g. use something::{{{inner}}}; None => prefix, + // E.g. `use something::{inner}` (prefix is `None`, path is `something`) + // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`) Some(path) => match convert_path(prefix, path) { Some(it) => Some(it), None => return, // TODO: report errors somewhere }, }; - for tree in use_tree_list.use_trees() { - expand_use_tree(prefix.clone(), tree, cb); + for child_tree in use_tree_list.use_trees() { + // Handle self in a path. + // E.g. `use something::{self, <...>}` + if let Some(path) = child_tree.path() { + if path.qualifier().is_none() { + if let Some(segment) = path.segment() { + if segment.kind() == Some(ast::PathSegmentKind::SelfKw) { + /* TODO: Work out what on earth range means in this callback */ + if let Some(prefix) = prefix.clone() { + cb(prefix, Some(segment.syntax().range())); + continue; + } + } + } + } + } + expand_use_tree(prefix.clone(), child_tree, cb); } } else { if let Some(ast_path) = tree.path() { -- cgit v1.2.3