mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Highlight all related tokens in macro inputs
This commit is contained in:
parent
c5059e0623
commit
512135920d
3 changed files with 99 additions and 27 deletions
|
@ -166,10 +166,12 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
|||
self.imp.speculative_expand(actual_macro_call, speculative_args, token_to_map)
|
||||
}
|
||||
|
||||
// FIXME: Rename to descend_into_macros_single
|
||||
pub fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
|
||||
self.imp.descend_into_macros(token).pop().unwrap()
|
||||
}
|
||||
|
||||
// FIXME: Rename to descend_into_macros
|
||||
pub fn descend_into_macros_many(&self, token: SyntaxToken) -> SmallVec<[SyntaxToken; 1]> {
|
||||
self.imp.descend_into_macros(token)
|
||||
}
|
||||
|
@ -236,6 +238,16 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
|||
self.imp.descend_node_at_offset(node, offset).find_map(N::cast)
|
||||
}
|
||||
|
||||
/// Find an AstNode by offset inside SyntaxNode, if it is inside *MacroCall*,
|
||||
/// descend it and find again
|
||||
pub fn find_nodes_at_offset_with_descend<'slf, N: AstNode + 'slf>(
|
||||
&'slf self,
|
||||
node: &SyntaxNode,
|
||||
offset: TextSize,
|
||||
) -> impl Iterator<Item = N> + 'slf {
|
||||
self.imp.descend_node_at_offset(node, offset).flat_map(N::cast)
|
||||
}
|
||||
|
||||
pub fn resolve_lifetime_param(&self, lifetime: &ast::Lifetime) -> Option<LifetimeParam> {
|
||||
self.imp.resolve_lifetime_param(lifetime)
|
||||
}
|
||||
|
@ -482,12 +494,13 @@ impl<'db> SemanticsImpl<'db> {
|
|||
.as_ref()?
|
||||
.map_token_down(self.db.upcast(), None, token.as_ref())?;
|
||||
|
||||
let len = queue.len();
|
||||
queue.extend(tokens.inspect(|token| {
|
||||
if let Some(parent) = token.value.parent() {
|
||||
self.cache(find_root(&parent), token.file_id);
|
||||
}
|
||||
}));
|
||||
return Some(());
|
||||
return (queue.len() != len).then(|| ());
|
||||
},
|
||||
ast::Item(item) => {
|
||||
match self.with_ctx(|ctx| ctx.item_to_macro_call(token.with_value(item))) {
|
||||
|
@ -500,12 +513,13 @@ impl<'db> SemanticsImpl<'db> {
|
|||
.as_ref()?
|
||||
.map_token_down(self.db.upcast(), None, token.as_ref())?;
|
||||
|
||||
let len = queue.len();
|
||||
queue.extend(tokens.inspect(|token| {
|
||||
if let Some(parent) = token.value.parent() {
|
||||
self.cache(find_root(&parent), token.file_id);
|
||||
}
|
||||
}));
|
||||
return Some(());
|
||||
return (queue.len() != len).then(|| ());
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue