diff options
Diffstat (limited to 'crates/ra_analysis/src/completion/reference_completion.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/reference_completion.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs index f708f07a0..6c5fd0be6 100644 --- a/crates/ra_analysis/src/completion/reference_completion.rs +++ b/crates/ra_analysis/src/completion/reference_completion.rs | |||
@@ -105,6 +105,9 @@ fn classify_name_ref(name_ref: ast::NameRef) -> Option<NameRefKind> { | |||
105 | let parent = name_ref.syntax().parent()?; | 105 | let parent = name_ref.syntax().parent()?; |
106 | if let Some(segment) = ast::PathSegment::cast(parent) { | 106 | if let Some(segment) = ast::PathSegment::cast(parent) { |
107 | let path = segment.parent_path(); | 107 | let path = segment.parent_path(); |
108 | if let Some(crate_path) = crate_path(path) { | ||
109 | return Some(NameRefKind::CratePath(crate_path)); | ||
110 | } | ||
108 | if path.qualifier().is_none() { | 111 | if path.qualifier().is_none() { |
109 | let enclosing_fn = name_ref | 112 | let enclosing_fn = name_ref |
110 | .syntax() | 113 | .syntax() |
@@ -113,9 +116,6 @@ fn classify_name_ref(name_ref: ast::NameRef) -> Option<NameRefKind> { | |||
113 | .find_map(ast::FnDef::cast); | 116 | .find_map(ast::FnDef::cast); |
114 | return Some(NameRefKind::LocalRef { enclosing_fn }); | 117 | return Some(NameRefKind::LocalRef { enclosing_fn }); |
115 | } | 118 | } |
116 | if let Some(crate_path) = crate_path(path) { | ||
117 | return Some(NameRefKind::CratePath(crate_path)); | ||
118 | } | ||
119 | } | 119 | } |
120 | None | 120 | None |
121 | } | 121 | } |
@@ -129,10 +129,21 @@ fn crate_path(mut path: ast::Path) -> Option<Vec<ast::NameRef>> { | |||
129 | ast::PathSegmentKind::CrateKw => break, | 129 | ast::PathSegmentKind::CrateKw => break, |
130 | ast::PathSegmentKind::SelfKw | ast::PathSegmentKind::SuperKw => return None, | 130 | ast::PathSegmentKind::SelfKw | ast::PathSegmentKind::SuperKw => return None, |
131 | } | 131 | } |
132 | path = path.qualifier()?; | 132 | path = qualifier(path)?; |
133 | } | 133 | } |
134 | res.reverse(); | 134 | res.reverse(); |
135 | Some(res) | 135 | return Some(res); |
136 | |||
137 | fn qualifier(path: ast::Path) -> Option<ast::Path> { | ||
138 | if let Some(q) = path.qualifier() { | ||
139 | return Some(q); | ||
140 | } | ||
141 | // TODO: this bottom up traversal is not too precise. | ||
142 | // Should we handle do a top-down analysiss, recording results? | ||
143 | let use_tree_list = path.syntax().ancestors().find_map(ast::UseTreeList::cast)?; | ||
144 | let use_tree = use_tree_list.parent_use_tree(); | ||
145 | use_tree.path() | ||
146 | } | ||
136 | } | 147 | } |
137 | 148 | ||
138 | fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) { | 149 | fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) { |