aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/utils/insert_use.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-28 21:43:13 +0000
committerAleksey Kladov <[email protected]>2020-02-28 21:43:13 +0000
commit067cb928f09482c63ec2bfbdafb04fbd53b754e1 (patch)
tree4a39fe02cab714a84eca5742ecaa2592cfe5d57b /crates/ra_assists/src/utils/insert_use.rs
parent61ba56d433a4d3d2651999efee43be8917ada747 (diff)
Simplify
Diffstat (limited to 'crates/ra_assists/src/utils/insert_use.rs')
-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()