aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-12 15:08:34 +0000
committerGitHub <[email protected]>2020-02-12 15:08:34 +0000
commit5bf669860984a2c058b3bdc3e43b4993a0f25b31 (patch)
treeb7811c88a671bc43bb35149f15e3ad7724e87214 /crates/ra_assists/src
parent421609225a5e38eb48dd42a4394898c7ae74b7f3 (diff)
parent2a7d97d82911ad03c549fa3c8c014e4b74c9696d (diff)
Merge #3121
3121: Do not add imports before inner attributes r=matklad a=SomeoneToIgnore Current `insert_use_statement` function adds imports before inner attributes which results in compiler errors: <img width="1440" alt="image" src="https://user-images.githubusercontent.com/2690773/74344019-a3749500-4db4-11ea-9d88-f71e903e795a.png"> Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs29
1 files changed, 28 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..eac452413 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,12 @@ 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 .map(|attr| attr.kind() == ast::AttrKind::Inner)
438 .unwrap_or(false);
439 ImportAction::add_new_use(anchor, add_after_anchor)
435 } 440 }
436 } 441 }
437} 442}
@@ -962,4 +967,26 @@ mod foo {
962 ", 967 ",
963 ); 968 );
964 } 969 }
970
971 #[test]
972 fn inserts_imports_after_inner_attributes() {
973 check_assist(
974 replace_qualified_name_with_use,
975 "
976#![allow(dead_code)]
977
978fn main() {
979 std::fmt::Debug<|>
980}
981 ",
982 "
983#![allow(dead_code)]
984use std::fmt::Debug;
985
986fn main() {
987 Debug<|>
988}
989 ",
990 );
991 }
965} 992}