From 1596b31698acd1ca8fe25a1b699bef4a9a6feb1d Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 12 Feb 2020 16:21:55 +0200 Subject: Do not add imports before inner attributes --- .../handlers/replace_qualified_name_with_use.rs | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs index b70c88ec2..4b5e37c11 100644 --- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs @@ -431,7 +431,13 @@ fn best_action_for_target( .find(|n| n.text_range().start() < anchor.text_range().start()) .or_else(|| Some(anchor)); - ImportAction::add_new_use(anchor, false) + let add_after_anchor = anchor + .clone() + .and_then(ast::Attr::cast) + .as_ref() + .map(ast::Attr::is_inner_attribute) + .unwrap_or(false); + ImportAction::add_new_use(anchor, add_after_anchor) } } } @@ -958,6 +964,28 @@ mod foo { Debug<|> } +} + ", + ); + } + + #[test] + fn inserts_imports_after_inner_attributes() { + check_assist( + replace_qualified_name_with_use, + " +#![allow(dead_code)] + +fn main() { + std::fmt::Debug<|> +} + ", + " +#![allow(dead_code)] +use std::fmt::Debug; + +fn main() { + Debug<|> } ", ); -- cgit v1.2.3