about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2021-08-29 00:36:26 +0200
committerLukas Wirth <lukastw97@gmail.com>2021-08-29 00:49:57 +0200
commit72bfbb0691d7d229c49b76afe6eeb82500a62806 (patch)
tree51ff293687cae514481c81a541b77cf648aaf016
parent512135920d6f904b316cfa5d508cf830db0d6461 (diff)
downloadrust-72bfbb0691d7d229c49b76afe6eeb82500a62806.tar.gz
rust-72bfbb0691d7d229c49b76afe6eeb82500a62806.zip
Return all usages inside macros in usage searches
-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 3d3ef92fff3..cb1efb90ab9 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 71e7a8544e6..e442cf7c4fa 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 431a36d8a28..b125d1666f0 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;
                         }