mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Introduce AttrKind
This commit is contained in:
parent
1596b31698
commit
848c576266
3 changed files with 16 additions and 8 deletions
|
@ -434,8 +434,7 @@ fn best_action_for_target(
|
||||||
let add_after_anchor = anchor
|
let add_after_anchor = anchor
|
||||||
.clone()
|
.clone()
|
||||||
.and_then(ast::Attr::cast)
|
.and_then(ast::Attr::cast)
|
||||||
.as_ref()
|
.map(|attr| attr.kind() == ast::AttrKind::Inner)
|
||||||
.map(ast::Attr::is_inner_attribute)
|
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
ImportAction::add_new_use(anchor, add_after_anchor)
|
ImportAction::add_new_use(anchor, add_after_anchor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ use crate::{
|
||||||
pub use self::{
|
pub use self::{
|
||||||
expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp},
|
expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp},
|
||||||
extensions::{
|
extensions::{
|
||||||
FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind,
|
AttrKind, FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind,
|
||||||
VisibilityKind,
|
TypeBoundKind, VisibilityKind,
|
||||||
},
|
},
|
||||||
generated::*,
|
generated::*,
|
||||||
tokens::*,
|
tokens::*,
|
||||||
|
|
|
@ -37,6 +37,12 @@ fn text_of_first_token(node: &SyntaxNode) -> &SmolStr {
|
||||||
node.green().children().next().and_then(|it| it.into_token()).unwrap().text()
|
node.green().children().next().and_then(|it| it.into_token()).unwrap().text()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum AttrKind {
|
||||||
|
Inner,
|
||||||
|
Outer,
|
||||||
|
}
|
||||||
|
|
||||||
impl ast::Attr {
|
impl ast::Attr {
|
||||||
pub fn as_simple_atom(&self) -> Option<SmolStr> {
|
pub fn as_simple_atom(&self) -> Option<SmolStr> {
|
||||||
match self.input() {
|
match self.input() {
|
||||||
|
@ -72,13 +78,16 @@ impl ast::Attr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_inner_attribute(&self) -> bool {
|
pub fn kind(&self) -> AttrKind {
|
||||||
let first_token = self.syntax().first_token();
|
let first_token = self.syntax().first_token();
|
||||||
let first_token_kind = first_token.as_ref().map(SyntaxToken::kind);
|
let first_token_kind = first_token.as_ref().map(SyntaxToken::kind);
|
||||||
let second_token_kind =
|
let second_token_kind =
|
||||||
first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::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);
|
match (first_token_kind, second_token_kind) {
|
||||||
|
(Some(SyntaxKind::POUND), Some(SyntaxKind::EXCL)) => AttrKind::Inner,
|
||||||
|
_ => AttrKind::Outer,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue