Skip to content

Commit 848c576

Browse files
Introduce AttrKind
1 parent 1596b31 commit 848c576

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ fn best_action_for_target(
434434
let add_after_anchor = anchor
435435
.clone()
436436
.and_then(ast::Attr::cast)
437-
.as_ref()
438-
.map(ast::Attr::is_inner_attribute)
437+
.map(|attr| attr.kind() == ast::AttrKind::Inner)
439438
.unwrap_or(false);
440439
ImportAction::add_new_use(anchor, add_after_anchor)
441440
}

crates/ra_syntax/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::{
1818
pub use self::{
1919
expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp},
2020
extensions::{
21-
FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind,
22-
VisibilityKind,
21+
AttrKind, FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind,
22+
TypeBoundKind, VisibilityKind,
2323
},
2424
generated::*,
2525
tokens::*,
@@ -218,7 +218,7 @@ fn test_doc_comment_multi_line_block_strips_suffix() {
218218
fn test_comments_preserve_trailing_whitespace() {
219219
let file = SourceFile::parse(
220220
r#"
221-
/// Representation of a Realm.
221+
/// Representation of a Realm.
222222
/// In the specification these are called Realm Records.
223223
struct Realm {}"#,
224224
)

crates/ra_syntax/src/ast/extensions.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ fn text_of_first_token(node: &SyntaxNode) -> &SmolStr {
3737
node.green().children().next().and_then(|it| it.into_token()).unwrap().text()
3838
}
3939

40+
#[derive(Debug, Clone, PartialEq, Eq)]
41+
pub enum AttrKind {
42+
Inner,
43+
Outer,
44+
}
45+
4046
impl ast::Attr {
4147
pub fn as_simple_atom(&self) -> Option<SmolStr> {
4248
match self.input() {
@@ -72,13 +78,16 @@ impl ast::Attr {
7278
}
7379
}
7480

75-
pub fn is_inner_attribute(&self) -> bool {
81+
pub fn kind(&self) -> AttrKind {
7682
let first_token = self.syntax().first_token();
7783
let first_token_kind = first_token.as_ref().map(SyntaxToken::kind);
7884
let second_token_kind =
7985
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);
86+
87+
match (first_token_kind, second_token_kind) {
88+
(Some(SyntaxKind::POUND), Some(SyntaxKind::EXCL)) => AttrKind::Inner,
89+
_ => AttrKind::Outer,
90+
}
8291
}
8392
}
8493

0 commit comments

Comments
 (0)