mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Handle attribute macros in descend_into_macros
This commit is contained in:
parent
13da28cc2b
commit
8d87f9b298
6 changed files with 86 additions and 22 deletions
|
@ -362,25 +362,57 @@ impl<'db> SemanticsImpl<'db> {
|
|||
|
||||
let token = successors(Some(InFile::new(sa.file_id, token)), |token| {
|
||||
self.db.unwind_if_cancelled();
|
||||
let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?;
|
||||
let tt = macro_call.token_tree()?;
|
||||
if !tt.syntax().text_range().contains_range(token.value.text_range()) {
|
||||
return None;
|
||||
}
|
||||
let file_id = sa.expand(self.db, token.with_value(¯o_call))?;
|
||||
let token = self
|
||||
.expansion_info_cache
|
||||
.borrow_mut()
|
||||
.entry(file_id)
|
||||
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
|
||||
.as_ref()?
|
||||
.map_token_down(token.as_ref())?;
|
||||
|
||||
if let Some(parent) = token.value.parent() {
|
||||
self.cache(find_root(&parent), token.file_id);
|
||||
for node in token.value.ancestors() {
|
||||
match_ast! {
|
||||
match node {
|
||||
ast::MacroCall(macro_call) => {
|
||||
let tt = macro_call.token_tree()?;
|
||||
if !tt.syntax().text_range().contains_range(token.value.text_range()) {
|
||||
return None;
|
||||
}
|
||||
let file_id = sa.expand(self.db, token.with_value(¯o_call))?;
|
||||
let token = self
|
||||
.expansion_info_cache
|
||||
.borrow_mut()
|
||||
.entry(file_id)
|
||||
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
|
||||
.as_ref()?
|
||||
.map_token_down(token.as_ref())?;
|
||||
|
||||
if let Some(parent) = token.value.parent() {
|
||||
self.cache(find_root(&parent), token.file_id);
|
||||
}
|
||||
|
||||
return Some(token);
|
||||
},
|
||||
ast::Item(item) => {
|
||||
match self.with_ctx(|ctx| ctx.item_to_macro_call(token.with_value(item))) {
|
||||
Some(call_id) => {
|
||||
let file_id = call_id.as_file();
|
||||
let token = self
|
||||
.expansion_info_cache
|
||||
.borrow_mut()
|
||||
.entry(file_id)
|
||||
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
|
||||
.as_ref()?
|
||||
.map_token_down(token.as_ref())?;
|
||||
|
||||
if let Some(parent) = token.value.parent() {
|
||||
self.cache(find_root(&parent), token.file_id);
|
||||
}
|
||||
|
||||
return Some(token);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(token)
|
||||
None
|
||||
})
|
||||
.last()
|
||||
.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue