Unnamed repository; edit this file 'description' to name the repository.
Return all usages inside macros in usage searches
Lukas Wirth 2021-08-29
parent 5121359 · commit 72bfbb0
-rw-r--r--crates/hir/src/semantics.rs12
-rw-r--r--crates/ide/src/highlight_related.rs2
-rw-r--r--crates/ide_db/src/search.rs6
3 files changed, 10 insertions, 10 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 3d3ef92fff..cb1efb90ab 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -181,7 +181,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
node: &SyntaxNode,
offset: TextSize,
) -> 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 {
@@ -235,7 +235,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
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*,
@@ -245,7 +245,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
node: &SyntaxNode,
offset: TextSize,
) -> 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> {
@@ -542,11 +542,11 @@ impl<'db> SemanticsImpl<'db> {
&self,
node: &SyntaxNode,
offset: TextSize,
- ) -> impl Iterator<Item = SyntaxNode> + '_ {
+ ) -> impl Iterator<Item = impl Iterator<Item = SyntaxNode> + '_> + '_ {
// Handle macro token cases
node.token_at_offset(offset)
- .flat_map(move |token| self.descend_into_macros(token))
- .map(move |it| self.token_ancestors_with_macros(it))
+ .map(move |token| self.descend_into_macros(token))
+ .map(|it| it.into_iter().map(move |it| self.token_ancestors_with_macros(it)))
.flatten()
}
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs
index 71e7a8544e..e442cf7c4f 100644
--- a/crates/ide/src/highlight_related.rs
+++ b/crates/ide/src/highlight_related.rs
@@ -424,6 +424,7 @@ macro_rules! foo {
foo!(bar$0);
// ^^^
// ^^^
+ // ^^^
fn foo() {
let bar: bar = bar();
// ^^^
@@ -442,6 +443,7 @@ macro_rules! foo {
foo!(bar);
// ^^^
+ // ^^^
fn foo() {
let bar: bar$0 = bar();
// ^^^
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 431a36d8a2..b125d1666f 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -393,7 +393,7 @@ impl<'a> FindUsages<'a> {
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 {
ast::NameLike::NameRef(name_ref) => self.found_name_ref(&name_ref, sink),
ast::NameLike::Name(name) => self.found_name(&name, sink),
@@ -410,9 +410,7 @@ impl<'a> FindUsages<'a> {
continue;
}
- if let Some(ast::NameLike::NameRef(name_ref)) =
- sema.find_node_at_offset_with_descend(&tree, offset)
- {
+ for name_ref in sema.find_nodes_at_offset_with_descend(&tree, offset) {
if self.found_self_ty_name_ref(self_ty, &name_ref, sink) {
return;
}