about summary refs log tree commit diff
path: root/crates/syntax/src/ast
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-30 22:08:25 +0000
committerGitHub <noreply@github.com>2022-01-30 22:08:25 +0000
commitfd3942eb620e37a4e4bfdd587d8a2893ccf6fea0 (patch)
treef9f387ca6d71551eecda7ca359be7322456f249b /crates/syntax/src/ast
parentc08df0f1f5e188e2e1e8f1715ff3a6d583cfb9f3 (diff)
parentddf7b70a0f8f7fc1e49d2bf0365752be3b4aab8b (diff)
downloadrust-fd3942eb620e37a4e4bfdd587d8a2893ccf6fea0.tar.gz
rust-fd3942eb620e37a4e4bfdd587d8a2893ccf6fea0.zip
Merge #11382
11382: fix: Fix `cfg_attr` invalidating derive identifier IDE functionalities r=Veykril a=Veykril

Proper fix for https://github.com/rust-analyzer/rust-analyzer/issues/11298
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r--crates/syntax/src/ast/node_ext.rs11
-rw-r--r--crates/syntax/src/ast/traits.rs20
2 files changed, 16 insertions, 15 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 705aa5edac4..7211c77e880 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -160,14 +160,9 @@ impl ast::Attr {
     }
 
     pub fn kind(&self) -> AttrKind {
-        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);
-
-        match (first_token_kind, second_token_kind) {
-            (Some(T![#]), Some(T![!])) => AttrKind::Inner,
-            _ => AttrKind::Outer,
+        match self.excl_token() {
+            Some(_) => AttrKind::Inner,
+            None => AttrKind::Outer,
         }
     }
 
diff --git a/crates/syntax/src/ast/traits.rs b/crates/syntax/src/ast/traits.rs
index 98b1087e641..aa2b7ed5c8b 100644
--- a/crates/syntax/src/ast/traits.rs
+++ b/crates/syntax/src/ast/traits.rs
@@ -76,8 +76,8 @@ pub trait HasDocComments: HasAttrs {
     fn doc_comments(&self) -> DocCommentIter {
         DocCommentIter { iter: self.syntax().children_with_tokens() }
     }
-    fn doc_comments_and_attrs(&self) -> AttrCommentIter {
-        AttrCommentIter { iter: self.syntax().children_with_tokens() }
+    fn doc_comments_and_attrs(&self) -> AttrDocCommentIter {
+        AttrDocCommentIter { iter: self.syntax().children_with_tokens() }
     }
 }
 
@@ -113,17 +113,23 @@ impl Iterator for DocCommentIter {
     }
 }
 
-pub struct AttrCommentIter {
+pub struct AttrDocCommentIter {
     iter: SyntaxElementChildren,
 }
 
-impl Iterator for AttrCommentIter {
-    type Item = Either<ast::Comment, ast::Attr>;
+impl AttrDocCommentIter {
+    pub fn from_syntax_node(syntax_node: &ast::SyntaxNode) -> AttrDocCommentIter {
+        AttrDocCommentIter { iter: syntax_node.children_with_tokens() }
+    }
+}
+
+impl Iterator for AttrDocCommentIter {
+    type Item = Either<ast::Attr, ast::Comment>;
     fn next(&mut self) -> Option<Self::Item> {
         self.iter.by_ref().find_map(|el| match el {
-            SyntaxElement::Node(node) => ast::Attr::cast(node).map(Either::Right),
+            SyntaxElement::Node(node) => ast::Attr::cast(node).map(Either::Left),
             SyntaxElement::Token(tok) => {
-                ast::Comment::cast(tok).filter(ast::Comment::is_doc).map(Either::Left)
+                ast::Comment::cast(tok).filter(ast::Comment::is_doc).map(Either::Right)
             }
         })
     }