Replace attribute with equivalent whitespace

This is needed to that the `TokenMap` we create contains offsets that
match the source.
This commit is contained in:
Jonas Schievink 2021-06-06 15:51:49 +02:00
parent d616a6a456
commit 1d5c60ff54

View file

@ -1,7 +1,7 @@
//! Macro input conditioning.
use syntax::{
ast::{self, AttrsOwner},
ast::{self, make, AttrsOwner},
AstNode, SyntaxNode,
};
@ -61,7 +61,9 @@ fn remove_attr_invoc(item: ast::Item, attr_index: usize) -> ast::Item {
.attrs()
.nth(attr_index)
.unwrap_or_else(|| panic!("cannot find attribute #{}", attr_index));
attr.syntax().detach();
let syntax_index = attr.syntax().index();
let ws = make::tokens::whitespace(&" ".repeat(u32::from(attr.syntax().text().len()) as usize));
item.syntax().splice_children(syntax_index..syntax_index + 1, vec![ws.into()]);
item
}