From fb99831cb044e5fbf171bdd950a7486a01ce0d51 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Feb 2020 14:30:27 +0100 Subject: Slightly simpler API for groups --- crates/ra_assists/src/handlers/auto_import.rs | 33 ++++++++++++--------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'crates/ra_assists/src/handlers') 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 @@ -use hir::ModPath; use ra_ide_db::imports_locator::ImportsLocator; -use ra_syntax::{ - ast::{self, AstNode}, - SyntaxNode, -}; +use ra_syntax::ast::{self, AstNode}; use crate::{ - assist_ctx::{ActionBuilder, Assist, AssistCtx}, + assist_ctx::{Assist, AssistCtx}, insert_use_statement, AssistId, }; use std::collections::BTreeSet; @@ -67,19 +63,18 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option { return None; } - ctx.add_assist_group(AssistId("auto_import"), format!("Import {}", name_to_import), || { - proposed_imports - .into_iter() - .map(|import| import_to_action(import, &position, &path_to_import_syntax)) - .collect() - }) -} - -fn import_to_action(import: ModPath, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { - let mut action_builder = ActionBuilder::default(); - action_builder.label(format!("Import `{}`", &import)); - insert_use_statement(position, anchor, &import, action_builder.text_edit_builder()); - action_builder + let mut group = ctx.add_assist_group(format!("Import {}", name_to_import)); + for import in proposed_imports { + group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| { + insert_use_statement( + &position, + path_to_import_syntax, + &import, + edit.text_edit_builder(), + ); + }); + } + group.finish() } #[cfg(test)] -- cgit v1.2.3