11230: fix: Fix attribute stripping ignoring doc comments r=Veykril a=Veykril

Follow up to https://github.com/rust-analyzer/rust-analyzer/pull/11225#pullrequestreview-846779237


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2022-01-07 18:06:33 +00:00 committed by GitHub
commit 41a0e95d61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 18 deletions

View file

@ -68,7 +68,7 @@ use once_cell::unsync::Lazy;
use rustc_hash::FxHashSet;
use stdx::{format_to, impl_from};
use syntax::{
ast::{self, HasAttrs as _, HasName},
ast::{self, HasAttrs as _, HasDocComments, HasName},
AstNode, AstPtr, SmolStr, SyntaxKind, SyntaxNodePtr,
};
use tt::{Ident, Leaf, Literal, TokenTree};
@ -612,10 +612,13 @@ impl Module {
}
MacroCallKind::Attr { ast_id, invoc_attr_index, attr_name, .. } => {
let node = ast_id.to_node(db.upcast());
let attr =
node.attrs().nth((*invoc_attr_index) as usize).unwrap_or_else(
|| panic!("cannot find attribute #{}", invoc_attr_index),
);
let attr = node
.doc_comments_and_attrs()
.nth((*invoc_attr_index) as usize)
.and_then(Either::right)
.unwrap_or_else(|| {
panic!("cannot find attribute #{}", invoc_attr_index)
});
(
ast_id.with_value(SyntaxNodePtr::from(AstPtr::new(&attr))),
Some(attr_name.clone()),