mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 13:33:31 +00:00
Do not add imports before inner attributes
This commit is contained in:
parent
759100fb0d
commit
1596b31698
2 changed files with 38 additions and 1 deletions
|
@ -431,7 +431,13 @@ fn best_action_for_target(
|
||||||
.find(|n| n.text_range().start() < anchor.text_range().start())
|
.find(|n| n.text_range().start() < anchor.text_range().start())
|
||||||
.or_else(|| Some(anchor));
|
.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<|>
|
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<|>
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
|
@ -71,6 +71,15 @@ impl ast::Attr {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_inner_attribute(&self) -> bool {
|
||||||
|
let first_token = self.syntax().first_token();
|
||||||
|
let first_token_kind = first_token.as_ref().map(SyntaxToken::kind);
|
||||||
|
let second_token_kind =
|
||||||
|
first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::kind);
|
||||||
|
return first_token_kind == Some(SyntaxKind::POUND)
|
||||||
|
&& second_token_kind == Some(SyntaxKind::EXCL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
|
Loading…
Reference in a new issue