diff options
author | Kirill Bulatov <[email protected]> | 2020-02-12 14:21:55 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-02-12 14:21:55 +0000 |
commit | 1596b31698acd1ca8fe25a1b699bef4a9a6feb1d (patch) | |
tree | 4f248f05afd6e1bdbfbc66d6e7d111708cacab45 /crates/ra_assists/src/handlers | |
parent | 759100fb0dcb41518f2a593dae5de5bbedd07776 (diff) |
Do not add imports before inner attributes
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r-- | crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs | 30 |
1 files changed, 29 insertions, 1 deletions
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( | |||
431 | .find(|n| n.text_range().start() < anchor.text_range().start()) | 431 | .find(|n| n.text_range().start() < anchor.text_range().start()) |
432 | .or_else(|| Some(anchor)); | 432 | .or_else(|| Some(anchor)); |
433 | 433 | ||
434 | ImportAction::add_new_use(anchor, false) | 434 | let add_after_anchor = anchor |
435 | .clone() | ||
436 | .and_then(ast::Attr::cast) | ||
437 | .as_ref() | ||
438 | .map(ast::Attr::is_inner_attribute) | ||
439 | .unwrap_or(false); | ||
440 | ImportAction::add_new_use(anchor, add_after_anchor) | ||
435 | } | 441 | } |
436 | } | 442 | } |
437 | } | 443 | } |
@@ -962,4 +968,26 @@ mod foo { | |||
962 | ", | 968 | ", |
963 | ); | 969 | ); |
964 | } | 970 | } |
971 | |||
972 | #[test] | ||
973 | fn inserts_imports_after_inner_attributes() { | ||
974 | check_assist( | ||
975 | replace_qualified_name_with_use, | ||
976 | " | ||
977 | #![allow(dead_code)] | ||
978 | |||
979 | fn main() { | ||
980 | std::fmt::Debug<|> | ||
981 | } | ||
982 | ", | ||
983 | " | ||
984 | #![allow(dead_code)] | ||
985 | use std::fmt::Debug; | ||
986 | |||
987 | fn main() { | ||
988 | Debug<|> | ||
989 | } | ||
990 | ", | ||
991 | ); | ||
992 | } | ||
965 | } | 993 | } |