From 2034002413a62fb999d9372231905393ed5c0383 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 3 May 2020 03:24:55 +0800 Subject: Support auto-import in macro --- crates/ra_assists/src/utils/insert_use.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'crates/ra_assists/src/utils') diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs index c507e71e0..c1f447efe 100644 --- a/crates/ra_assists/src/utils/insert_use.rs +++ b/crates/ra_assists/src/utils/insert_use.rs @@ -2,6 +2,7 @@ // FIXME: rewrite according to the plan, outlined in // https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553 +use crate::assist_ctx::ActionBuilder; use hir::{self, ModPath}; use ra_syntax::{ ast::{self, NameOwner}, @@ -14,14 +15,14 @@ use ra_text_edit::TextEditBuilder; /// Creates and inserts a use statement for the given path to import. /// The use statement is inserted in the scope most appropriate to the /// the cursor position given, additionally merged with the existing use imports. -pub fn insert_use_statement( +pub(crate) fn insert_use_statement( // Ideally the position of the cursor, used to position: &SyntaxNode, path_to_import: &ModPath, - edit: &mut TextEditBuilder, + edit: &mut ActionBuilder, ) { let target = path_to_import.to_string().split("::").map(SmolStr::new).collect::>(); - let container = position.ancestors().find_map(|n| { + let container = edit.ctx().sema.ancestors_with_macros(position.clone()).find_map(|n| { if let Some(module) = ast::Module::cast(n.clone()) { return module.item_list().map(|it| it.syntax().clone()); } @@ -30,7 +31,7 @@ pub fn insert_use_statement( if let Some(container) = container { let action = best_action_for_target(container, position.clone(), &target); - make_assist(&action, &target, edit); + make_assist(&action, &target, edit.text_edit_builder()); } } -- cgit v1.2.3