[PATCH] D87225: [clangd] When finding refs for a renaming alias, do not return refs to underlying decls

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 28 18:18:59 PDT 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc6d1f8029b0: [clangd] When finding refs for a renaming alias, do not return refs to… (authored by nridge).

Changed prior to commit:
  https://reviews.llvm.org/D87225?vs=294851&id=294853#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87225/new/

https://reviews.llvm.org/D87225

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1588,6 +1588,13 @@
           auto lambda = [x = [[waldo]]](){};
         }
       )cpp",
+      R"cpp(// Renaming alias
+        template <typename> class Vector {};
+        using [[^X]] = Vector<int>;
+        [[X]] x1;
+        Vector<int> x2;
+        Vector<double> y;
+      )cpp",
   };
   for (const char *Test : Tests) {
     Annotations T(Test);
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1140,11 +1140,21 @@
   } else {
     // Handle references to Decls.
 
-    // We also show references to the targets of using-decls, so we include
-    // DeclRelation::Underlying.
-    DeclRelationSet Relations = DeclRelation::TemplatePattern |
-                                DeclRelation::Alias | DeclRelation::Underlying;
-    auto Decls = getDeclAtPosition(AST, *CurLoc, Relations);
+    DeclRelationSet Relations =
+        DeclRelation::TemplatePattern | DeclRelation::Alias;
+    std::vector<const NamedDecl *> Decls =
+        getDeclAtPosition(AST, *CurLoc, Relations);
+    std::vector<const NamedDecl *> NonrenamingAliasUnderlyingDecls;
+    // If the results include a *non-renaming* alias, get its
+    // underlying decls as well. (See similar logic in locateASTReferent()).
+    for (const NamedDecl *D : Decls) {
+      if (llvm::isa<UsingDecl>(D) || llvm::isa<UnresolvedUsingValueDecl>(D)) {
+        for (const NamedDecl *AD :
+             getDeclAtPosition(AST, *CurLoc, DeclRelation::Underlying))
+          NonrenamingAliasUnderlyingDecls.push_back(AD);
+      }
+    }
+    llvm::copy(NonrenamingAliasUnderlyingDecls, std::back_inserter(Decls));
 
     // We traverse the AST to find references in the main file.
     auto MainFileRefs = findRefs(Decls, AST);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87225.294853.patch
Type: text/x-patch
Size: 2071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200929/b0c4af5e/attachment-0001.bin>


More information about the cfe-commits mailing list