aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/utils
diff options
context:
space:
mode:
authorBenjamin Coenen <[email protected]>2020-05-10 11:31:55 +0100
committerBenjamin Coenen <[email protected]>2020-05-10 11:31:55 +0100
commite80903a96564c2239489a8c630a4748bf21a3659 (patch)
tree12b31a1fd12deb2120065cea5a558425c8c1984f /crates/ra_assists/src/utils
parent6203e9c4faee288f16d93dbb7dd0f1f8df487d83 (diff)
parent4578154b608fa075595103d0c933da60d55b25c8 (diff)
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer into feat_4348
Diffstat (limited to 'crates/ra_assists/src/utils')
-rw-r--r--crates/ra_assists/src/utils/insert_use.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs
index c1f447efe..1214e3cd4 100644
--- a/crates/ra_assists/src/utils/insert_use.rs
+++ b/crates/ra_assists/src/utils/insert_use.rs
@@ -2,7 +2,6 @@
2// FIXME: rewrite according to the plan, outlined in 2// FIXME: rewrite according to the plan, outlined in
3// https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553 3// https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553
4 4
5use crate::assist_ctx::ActionBuilder;
6use hir::{self, ModPath}; 5use hir::{self, ModPath};
7use ra_syntax::{ 6use ra_syntax::{
8 ast::{self, NameOwner}, 7 ast::{self, NameOwner},
@@ -12,6 +11,8 @@ use ra_syntax::{
12}; 11};
13use ra_text_edit::TextEditBuilder; 12use ra_text_edit::TextEditBuilder;
14 13
14use crate::assist_context::{AssistBuilder, AssistContext};
15
15/// Creates and inserts a use statement for the given path to import. 16/// Creates and inserts a use statement for the given path to import.
16/// The use statement is inserted in the scope most appropriate to the 17/// The use statement is inserted in the scope most appropriate to the
17/// the cursor position given, additionally merged with the existing use imports. 18/// the cursor position given, additionally merged with the existing use imports.
@@ -19,10 +20,11 @@ pub(crate) fn insert_use_statement(
19 // Ideally the position of the cursor, used to 20 // Ideally the position of the cursor, used to
20 position: &SyntaxNode, 21 position: &SyntaxNode,
21 path_to_import: &ModPath, 22 path_to_import: &ModPath,
22 edit: &mut ActionBuilder, 23 ctx: &AssistContext,
24 builder: &mut AssistBuilder,
23) { 25) {
24 let target = path_to_import.to_string().split("::").map(SmolStr::new).collect::<Vec<_>>(); 26 let target = path_to_import.to_string().split("::").map(SmolStr::new).collect::<Vec<_>>();
25 let container = edit.ctx().sema.ancestors_with_macros(position.clone()).find_map(|n| { 27 let container = ctx.sema.ancestors_with_macros(position.clone()).find_map(|n| {
26 if let Some(module) = ast::Module::cast(n.clone()) { 28 if let Some(module) = ast::Module::cast(n.clone()) {
27 return module.item_list().map(|it| it.syntax().clone()); 29 return module.item_list().map(|it| it.syntax().clone());
28 } 30 }
@@ -31,7 +33,7 @@ pub(crate) fn insert_use_statement(
31 33
32 if let Some(container) = container { 34 if let Some(container) = container {
33 let action = best_action_for_target(container, position.clone(), &target); 35 let action = best_action_for_target(container, position.clone(), &target);
34 make_assist(&action, &target, edit.text_edit_builder()); 36 make_assist(&action, &target, builder.text_edit_builder());
35 } 37 }
36} 38}
37 39