diff options
author | Kirill Bulatov <[email protected]> | 2020-02-12 14:44:52 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-02-12 14:44:52 +0000 |
commit | 848c5762667101c8a017e561da2fa7e39b212929 (patch) | |
tree | 26a6acb0eb0d4099003ed455f89fde4d196a363a | |
parent | 1596b31698acd1ca8fe25a1b699bef4a9a6feb1d (diff) |
Introduce AttrKind
-rw-r--r-- | crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 15 |
3 files changed, 16 insertions, 8 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 4b5e37c11..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 | |||
@@ -434,8 +434,7 @@ fn best_action_for_target( | |||
434 | let add_after_anchor = anchor | 434 | let add_after_anchor = anchor |
435 | .clone() | 435 | .clone() |
436 | .and_then(ast::Attr::cast) | 436 | .and_then(ast::Attr::cast) |
437 | .as_ref() | 437 | .map(|attr| attr.kind() == ast::AttrKind::Inner) |
438 | .map(ast::Attr::is_inner_attribute) | ||
439 | .unwrap_or(false); | 438 | .unwrap_or(false); |
440 | ImportAction::add_new_use(anchor, add_after_anchor) | 439 | ImportAction::add_new_use(anchor, add_after_anchor) |
441 | } | 440 | } |
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index d3e8888bd..50441e75b 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -18,8 +18,8 @@ use crate::{ | |||
18 | pub use self::{ | 18 | pub use self::{ |
19 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, | 19 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, |
20 | extensions::{ | 20 | extensions::{ |
21 | FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, | 21 | AttrKind, FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, |
22 | VisibilityKind, | 22 | TypeBoundKind, VisibilityKind, |
23 | }, | 23 | }, |
24 | generated::*, | 24 | generated::*, |
25 | tokens::*, | 25 | tokens::*, |
@@ -218,7 +218,7 @@ fn test_doc_comment_multi_line_block_strips_suffix() { | |||
218 | fn test_comments_preserve_trailing_whitespace() { | 218 | fn test_comments_preserve_trailing_whitespace() { |
219 | let file = SourceFile::parse( | 219 | let file = SourceFile::parse( |
220 | r#" | 220 | r#" |
221 | /// Representation of a Realm. | 221 | /// Representation of a Realm. |
222 | /// In the specification these are called Realm Records. | 222 | /// In the specification these are called Realm Records. |
223 | struct Realm {}"#, | 223 | struct Realm {}"#, |
224 | ) | 224 | ) |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index a297ae110..44de4af89 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -37,6 +37,12 @@ fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { | |||
37 | node.green().children().next().and_then(|it| it.into_token()).unwrap().text() | 37 | node.green().children().next().and_then(|it| it.into_token()).unwrap().text() |
38 | } | 38 | } |
39 | 39 | ||
40 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
41 | pub enum AttrKind { | ||
42 | Inner, | ||
43 | Outer, | ||
44 | } | ||
45 | |||
40 | impl ast::Attr { | 46 | impl ast::Attr { |
41 | pub fn as_simple_atom(&self) -> Option<SmolStr> { | 47 | pub fn as_simple_atom(&self) -> Option<SmolStr> { |
42 | match self.input() { | 48 | match self.input() { |
@@ -72,13 +78,16 @@ impl ast::Attr { | |||
72 | } | 78 | } |
73 | } | 79 | } |
74 | 80 | ||
75 | pub fn is_inner_attribute(&self) -> bool { | 81 | pub fn kind(&self) -> AttrKind { |
76 | let first_token = self.syntax().first_token(); | 82 | let first_token = self.syntax().first_token(); |
77 | let first_token_kind = first_token.as_ref().map(SyntaxToken::kind); | 83 | let first_token_kind = first_token.as_ref().map(SyntaxToken::kind); |
78 | let second_token_kind = | 84 | let second_token_kind = |
79 | first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::kind); | 85 | first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::kind); |
80 | return first_token_kind == Some(SyntaxKind::POUND) | 86 | |
81 | && second_token_kind == Some(SyntaxKind::EXCL); | 87 | match (first_token_kind, second_token_kind) { |
88 | (Some(SyntaxKind::POUND), Some(SyntaxKind::EXCL)) => AttrKind::Inner, | ||
89 | _ => AttrKind::Outer, | ||
90 | } | ||
82 | } | 91 | } |
83 | } | 92 | } |
84 | 93 | ||