From 9be1ab7ff948d89334a8acbc309c8235d4ab374f Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 27 Jan 2020 14:42:45 +0200 Subject: Code review fixes --- crates/ra_assists/src/assists/auto_import.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_assists/src/assists') diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs index 4c3793ac7..9163cc662 100644 --- a/crates/ra_assists/src/assists/auto_import.rs +++ b/crates/ra_assists/src/assists/auto_import.rs @@ -1,4 +1,4 @@ -use hir::{db::HirDatabase, AsName}; +use hir::db::HirDatabase; use ra_syntax::{ ast::{self, AstNode}, SmolStr, SyntaxElement, @@ -48,7 +48,7 @@ pub(crate) fn auto_import( return None; } - let name_to_import = &find_applicable_name_ref(ctx.covering_element())?.as_name(); + let name_to_import = &find_applicable_name_ref(ctx.covering_element())?.syntax().to_string(); let proposed_imports = imports_locator .find_imports(&name_to_import.to_string()) .into_iter() @@ -64,7 +64,7 @@ pub(crate) fn auto_import( ctx.add_assist_group(AssistId("auto_import"), "auto import", || { proposed_imports .into_iter() - .map(|import| import_to_action(import, &position, &path_to_import)) + .map(|import| import_to_action(import, &position, &path_to_import.syntax())) .collect() }) } @@ -84,12 +84,12 @@ fn find_applicable_name_ref(element: SyntaxElement) -> Option { } } -fn import_to_action(import: String, position: &SyntaxNode, path: &ast::Path) -> ActionBuilder { +fn import_to_action(import: String, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { let mut action_builder = ActionBuilder::default(); action_builder.label(format!("Import `{}`", &import)); auto_import_text_edit( position, - &path.syntax().clone(), + anchor, &[SmolStr::new(import)], action_builder.text_edit_builder(), ); -- cgit v1.2.3