aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/utils')
-rw-r--r--crates/ra_assists/src/utils/insert_use.rs9
1 files changed, 2 insertions, 7 deletions
diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs
index 7ae3440ca..36fd2fc0b 100644
--- a/crates/ra_assists/src/utils/insert_use.rs
+++ b/crates/ra_assists/src/utils/insert_use.rs
@@ -15,8 +15,6 @@ use ra_text_edit::TextEditBuilder;
15pub fn insert_use_statement( 15pub fn insert_use_statement(
16 // Ideally the position of the cursor, used to 16 // Ideally the position of the cursor, used to
17 position: &SyntaxNode, 17 position: &SyntaxNode,
18 // The statement to use as anchor (last resort)
19 anchor: &SyntaxNode,
20 path_to_import: &ModPath, 18 path_to_import: &ModPath,
21 edit: &mut TextEditBuilder, 19 edit: &mut TextEditBuilder,
22) { 20) {
@@ -29,7 +27,7 @@ pub fn insert_use_statement(
29 }); 27 });
30 28
31 if let Some(container) = container { 29 if let Some(container) = container {
32 let action = best_action_for_target(container, anchor.clone(), &target); 30 let action = best_action_for_target(container, position.clone(), &target);
33 make_assist(&action, &target, edit); 31 make_assist(&action, &target, edit);
34 } 32 }
35} 33}
@@ -379,10 +377,7 @@ fn best_action_for_target(
379 // another item and we use it as anchor. 377 // another item and we use it as anchor.
380 // If there are no items above, we choose the target path itself as anchor. 378 // If there are no items above, we choose the target path itself as anchor.
381 // todo: we should include even whitespace blocks as anchor candidates 379 // todo: we should include even whitespace blocks as anchor candidates
382 let anchor = container 380 let anchor = container.children().next().or_else(|| Some(anchor));
383 .children()
384 .find(|n| n.text_range().start() < anchor.text_range().start())
385 .or_else(|| Some(anchor));
386 381
387 let add_after_anchor = anchor 382 let add_after_anchor = anchor
388 .clone() 383 .clone()