From fe141a8c10eb31c8793a6f6ecec522011d59a653 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Feb 2020 16:13:29 +0100 Subject: Set auto-import target closes #3067 --- crates/ra_assists/src/handlers/auto_import.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index d13332f37..e88c121eb 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -66,6 +66,7 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option { 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| { + edit.target(path_to_import_syntax.text_range()); insert_use_statement( &position, path_to_import_syntax, @@ -79,7 +80,7 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option { #[cfg(test)] mod tests { - use crate::helpers::{check_assist, check_assist_not_applicable}; + use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; use super::*; @@ -250,4 +251,19 @@ mod tests { ", ); } + + #[test] + fn auto_import_target() { + check_assist_target( + auto_import, + r" + struct AssistInfo { + group_label: Option<<|>GroupLabel>, + } + + mod m { pub struct GroupLabel; } + ", + "GroupLabel", + ) + } } -- cgit v1.2.3