diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-09 15:04:20 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-09 15:04:20 +0000 |
commit | a836247de45d7187a3902c2f14034d2817dbfbc3 (patch) | |
tree | bb0bf39dee21d5720e5f1070b09805dfbc120cd9 /crates/ra_assists/src/handlers/auto_import.rs | |
parent | aa5f80aed1464881575fe635557c3965313a7ecf (diff) | |
parent | 9769c5140c9c406a4cc880e698593a6c4bcc6826 (diff) |
Merge #3069
3069: Simplify Assists interface r=matklad a=matklad
Instead of building a physical tree structure, just tag related
assists with the same group
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers/auto_import.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/auto_import.rs | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index 4514b8691..d13332f37 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs | |||
@@ -1,12 +1,8 @@ | |||
1 | use hir::ModPath; | ||
2 | use ra_ide_db::imports_locator::ImportsLocator; | 1 | use ra_ide_db::imports_locator::ImportsLocator; |
3 | use ra_syntax::{ | 2 | use ra_syntax::ast::{self, AstNode}; |
4 | ast::{self, AstNode}, | ||
5 | SyntaxNode, | ||
6 | }; | ||
7 | 3 | ||
8 | use crate::{ | 4 | use crate::{ |
9 | assist_ctx::{ActionBuilder, Assist, AssistCtx}, | 5 | assist_ctx::{Assist, AssistCtx}, |
10 | insert_use_statement, AssistId, | 6 | insert_use_statement, AssistId, |
11 | }; | 7 | }; |
12 | use std::collections::BTreeSet; | 8 | use std::collections::BTreeSet; |
@@ -67,19 +63,18 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> { | |||
67 | return None; | 63 | return None; |
68 | } | 64 | } |
69 | 65 | ||
70 | ctx.add_assist_group(AssistId("auto_import"), format!("Import {}", name_to_import), || { | 66 | let mut group = ctx.add_assist_group(format!("Import {}", name_to_import)); |
71 | proposed_imports | 67 | for import in proposed_imports { |
72 | .into_iter() | 68 | group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| { |
73 | .map(|import| import_to_action(import, &position, &path_to_import_syntax)) | 69 | insert_use_statement( |
74 | .collect() | 70 | &position, |
75 | }) | 71 | path_to_import_syntax, |
76 | } | 72 | &import, |
77 | 73 | edit.text_edit_builder(), | |
78 | fn import_to_action(import: ModPath, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { | 74 | ); |
79 | let mut action_builder = ActionBuilder::default(); | 75 | }); |
80 | action_builder.label(format!("Import `{}`", &import)); | 76 | } |
81 | insert_use_statement(position, anchor, &import, action_builder.text_edit_builder()); | 77 | group.finish() |
82 | action_builder | ||
83 | } | 78 | } |
84 | 79 | ||
85 | #[cfg(test)] | 80 | #[cfg(test)] |