aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/auto_import.rs26
1 files changed, 10 insertions, 16 deletions
diff --git a/crates/ra_assists/src/auto_import.rs b/crates/ra_assists/src/auto_import.rs
index 4cac5a926..2ac19ab27 100644
--- a/crates/ra_assists/src/auto_import.rs
+++ b/crates/ra_assists/src/auto_import.rs
@@ -48,8 +48,8 @@ fn collect_path_segments(path: &ast::Path) -> Option<Vec<&ast::PathSegment>> {
48 return Some(v); 48 return Some(v);
49} 49}
50 50
51fn collect_path_segments_raw<'b, 'a: 'b>( 51fn collect_path_segments_raw<'a>(
52 segments: &'b mut Vec<&'a ast::PathSegment>, 52 segments: &mut Vec<&'a ast::PathSegment>,
53 mut path: &'a ast::Path, 53 mut path: &'a ast::Path,
54) -> Option<usize> { 54) -> Option<usize> {
55 let oldlen = segments.len(); 55 let oldlen = segments.len();
@@ -105,8 +105,6 @@ fn fmt_segments_raw(segments: &[&ast::PathSegment], buf: &mut String) {
105enum PathSegmentsMatch { 105enum PathSegmentsMatch {
106 // Patch matches exactly 106 // Patch matches exactly
107 Full, 107 Full,
108 // None of the segments matched. It's a more explicit Partial(0)
109 Empty,
110 // When some of the segments matched 108 // When some of the segments matched
111 Partial(usize), 109 Partial(usize),
112 // When all the segments of the right path are matched against the left path, 110 // When all the segments of the right path are matched against the left path,
@@ -129,11 +127,7 @@ fn compare_path_segments(
129 if compare_path_segment(left, right) { 127 if compare_path_segment(left, right) {
130 matching += 1 128 matching += 1
131 } else { 129 } else {
132 return if matching == 0 { 130 return PathSegmentsMatch::Partial(matching);
133 PathSegmentsMatch::Empty
134 } else {
135 PathSegmentsMatch::Partial(matching)
136 };
137 } 131 }
138 } 132 }
139 EitherOrBoth::Left(_) => { 133 EitherOrBoth::Left(_) => {
@@ -149,7 +143,7 @@ fn compare_path_segments(
149 143
150fn compare_path_segment(a: &ast::PathSegment, b: &ast::PathSegment) -> bool { 144fn compare_path_segment(a: &ast::PathSegment, b: &ast::PathSegment) -> bool {
151 if let (Some(ka), Some(kb)) = (a.kind(), b.kind()) { 145 if let (Some(ka), Some(kb)) = (a.kind(), b.kind()) {
152 return match (ka, kb) { 146 match (ka, kb) {
153 (ast::PathSegmentKind::Name(nameref_a), ast::PathSegmentKind::Name(nameref_b)) => { 147 (ast::PathSegmentKind::Name(nameref_a), ast::PathSegmentKind::Name(nameref_b)) => {
154 nameref_a.text() == nameref_b.text() 148 nameref_a.text() == nameref_b.text()
155 } 149 }
@@ -157,7 +151,7 @@ fn compare_path_segment(a: &ast::PathSegment, b: &ast::PathSegment) -> bool {
157 (ast::PathSegmentKind::SuperKw, ast::PathSegmentKind::SuperKw) => true, 151 (ast::PathSegmentKind::SuperKw, ast::PathSegmentKind::SuperKw) => true,
158 (ast::PathSegmentKind::CrateKw, ast::PathSegmentKind::CrateKw) => true, 152 (ast::PathSegmentKind::CrateKw, ast::PathSegmentKind::CrateKw) => true,
159 (_, _) => false, 153 (_, _) => false,
160 }; 154 }
161 } else { 155 } else {
162 false 156 false
163 } 157 }
@@ -226,11 +220,11 @@ impl<'a> ImportAction<'a> {
226 220
227// Find out the best ImportAction to import target path against current_use_tree. 221// Find out the best ImportAction to import target path against current_use_tree.
228// If current_use_tree has a nested import the function gets called recursively on every UseTree inside a UseTreeList. 222// If current_use_tree has a nested import the function gets called recursively on every UseTree inside a UseTreeList.
229fn walk_use_tree_for_best_action<'b, 'c, 'a: 'b + 'c>( 223fn walk_use_tree_for_best_action<'a>(
230 current_path_segments: &'b mut Vec<&'a ast::PathSegment>, // buffer containing path segments 224 current_path_segments: &mut Vec<&'a ast::PathSegment>, // buffer containing path segments
231 current_parent_use_tree_list: Option<&'a ast::UseTreeList>, // will be Some value if we are in a nested import 225 current_parent_use_tree_list: Option<&'a ast::UseTreeList>, // will be Some value if we are in a nested import
232 current_use_tree: &'a ast::UseTree, // the use tree we are currently examinating 226 current_use_tree: &'a ast::UseTree, // the use tree we are currently examinating
233 target: &'c [&'a ast::PathSegment], // the path we want to import 227 target: &[&'a ast::PathSegment], // the path we want to import
234) -> ImportAction<'a> { 228) -> ImportAction<'a> {
235 // We save the number of segments in the buffer so we can restore the correct segments 229 // We save the number of segments in the buffer so we can restore the correct segments
236 // before returning. Recursive call will add segments so we need to delete them. 230 // before returning. Recursive call will add segments so we need to delete them.
@@ -295,7 +289,7 @@ fn walk_use_tree_for_best_action<'b, 'c, 'a: 'b + 'c>(
295 ImportAction::Nothing 289 ImportAction::Nothing
296 } 290 }
297 } 291 }
298 PathSegmentsMatch::Empty => ImportAction::AddNewUse( 292 PathSegmentsMatch::Partial(0) => ImportAction::AddNewUse(
299 // e.g: target is std::fmt and we can have 293 // e.g: target is std::fmt and we can have
300 // use foo::bar 294 // use foo::bar
301 // We add a brand new use statement 295 // We add a brand new use statement
@@ -346,7 +340,7 @@ fn walk_use_tree_for_best_action<'b, 'c, 'a: 'b + 'c>(
346 better_action 340 better_action
347 } 341 }
348 PathSegmentsMatch::PartialRight(n) => { 342 PathSegmentsMatch::PartialRight(n) => {
349 // e.g: target std::fmt and we can have 343 // e.g: target is std::fmt and we can have
350 // use std::fmt::Debug; 344 // use std::fmt::Debug;
351 let segments_to_split = current_path_segments.split_at(prev_len + n).1; 345 let segments_to_split = current_path_segments.split_at(prev_len + n).1;
352 ImportAction::AddNestedImport(prev_len + n, path, Some(segments_to_split[0]), true) 346 ImportAction::AddNestedImport(prev_len + n, path, Some(segments_to_split[0]), true)