aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs30
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs9
2 files changed, 38 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
979fn main() {
980 std::fmt::Debug<|>
981}
982 ",
983 "
984#![allow(dead_code)]
985use std::fmt::Debug;
986
987fn main() {
988 Debug<|>
989}
990 ",
991 );
992 }
965} 993}
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index 7dcf084de..a297ae110 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -71,6 +71,15 @@ impl ast::Attr {
71 _ => None, 71 _ => None,
72 } 72 }
73 } 73 }
74
75 pub fn is_inner_attribute(&self) -> bool {
76 let first_token = self.syntax().first_token();
77 let first_token_kind = first_token.as_ref().map(SyntaxToken::kind);
78 let second_token_kind =
79 first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::kind);
80 return first_token_kind == Some(SyntaxKind::POUND)
81 && second_token_kind == Some(SyntaxKind::EXCL);
82 }
74} 83}
75 84
76#[derive(Debug, Clone, PartialEq, Eq)] 85#[derive(Debug, Clone, PartialEq, Eq)]