mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Return all usages inside macros in usage searches
This commit is contained in:
parent
512135920d
commit
72bfbb0691
3 changed files with 10 additions and 10 deletions
|
@ -181,7 +181,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
) -> Option<N> {
|
) -> Option<N> {
|
||||||
self.imp.descend_node_at_offset(node, offset).find_map(N::cast)
|
self.imp.descend_node_at_offset(node, offset).flatten().find_map(N::cast)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hir_file_for(&self, syntax_node: &SyntaxNode) -> HirFileId {
|
pub fn hir_file_for(&self, syntax_node: &SyntaxNode) -> HirFileId {
|
||||||
|
@ -235,7 +235,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
return Some(it);
|
return Some(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.imp.descend_node_at_offset(node, offset).find_map(N::cast)
|
self.imp.descend_node_at_offset(node, offset).flatten().find_map(N::cast)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find an AstNode by offset inside SyntaxNode, if it is inside *MacroCall*,
|
/// Find an AstNode by offset inside SyntaxNode, if it is inside *MacroCall*,
|
||||||
|
@ -245,7 +245,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
) -> impl Iterator<Item = N> + 'slf {
|
) -> impl Iterator<Item = N> + 'slf {
|
||||||
self.imp.descend_node_at_offset(node, offset).flat_map(N::cast)
|
self.imp.descend_node_at_offset(node, offset).filter_map(|mut it| it.find_map(N::cast))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_lifetime_param(&self, lifetime: &ast::Lifetime) -> Option<LifetimeParam> {
|
pub fn resolve_lifetime_param(&self, lifetime: &ast::Lifetime) -> Option<LifetimeParam> {
|
||||||
|
@ -542,11 +542,11 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
&self,
|
&self,
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
) -> impl Iterator<Item = SyntaxNode> + '_ {
|
) -> impl Iterator<Item = impl Iterator<Item = SyntaxNode> + '_> + '_ {
|
||||||
// Handle macro token cases
|
// Handle macro token cases
|
||||||
node.token_at_offset(offset)
|
node.token_at_offset(offset)
|
||||||
.flat_map(move |token| self.descend_into_macros(token))
|
.map(move |token| self.descend_into_macros(token))
|
||||||
.map(move |it| self.token_ancestors_with_macros(it))
|
.map(|it| it.into_iter().map(move |it| self.token_ancestors_with_macros(it)))
|
||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -424,6 +424,7 @@ macro_rules! foo {
|
||||||
foo!(bar$0);
|
foo!(bar$0);
|
||||||
// ^^^
|
// ^^^
|
||||||
// ^^^
|
// ^^^
|
||||||
|
// ^^^
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let bar: bar = bar();
|
let bar: bar = bar();
|
||||||
// ^^^
|
// ^^^
|
||||||
|
@ -442,6 +443,7 @@ macro_rules! foo {
|
||||||
|
|
||||||
foo!(bar);
|
foo!(bar);
|
||||||
// ^^^
|
// ^^^
|
||||||
|
// ^^^
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let bar: bar$0 = bar();
|
let bar: bar$0 = bar();
|
||||||
// ^^^
|
// ^^^
|
||||||
|
|
|
@ -393,7 +393,7 @@ impl<'a> FindUsages<'a> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = sema.find_node_at_offset_with_descend(&tree, offset) {
|
for name in sema.find_nodes_at_offset_with_descend(&tree, offset) {
|
||||||
if match name {
|
if match name {
|
||||||
ast::NameLike::NameRef(name_ref) => self.found_name_ref(&name_ref, sink),
|
ast::NameLike::NameRef(name_ref) => self.found_name_ref(&name_ref, sink),
|
||||||
ast::NameLike::Name(name) => self.found_name(&name, sink),
|
ast::NameLike::Name(name) => self.found_name(&name, sink),
|
||||||
|
@ -410,9 +410,7 @@ impl<'a> FindUsages<'a> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ast::NameLike::NameRef(name_ref)) =
|
for name_ref in sema.find_nodes_at_offset_with_descend(&tree, offset) {
|
||||||
sema.find_node_at_offset_with_descend(&tree, offset)
|
|
||||||
{
|
|
||||||
if self.found_self_ty_name_ref(self_ty, &name_ref, sink) {
|
if self.found_self_ty_name_ref(self_ty, &name_ref, sink) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue