[PATCH] D125684: [clangd] Support UnresolvedUsingTypeLoc AST node in FindTarget.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 16 06:03:07 PDT 2022


hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

to make features like hover, go-to-def work when the cursor is on the
UnresolvedUsingTypeLoc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125684

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -268,6 +268,17 @@
   EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc",
                {"using ns::S", Rel::Alias}, {"template <typename T> class S"},
                {"class S", Rel::TemplatePattern});
+
+  Code = R"cpp(
+    template<typename T>
+    class Foo { public: class foo {}; };
+    template <class T> class A : public Foo<T> {
+      using typename Foo<T>::foo;
+      [[foo]] abc;
+    };
+  )cpp";
+  EXPECT_DECLS("UnresolvedUsingTypeLoc",
+               {"using typename Foo<T>::foo", Rel::Alias});
 }
 
 TEST_F(TargetDeclTest, BaseSpecifier) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -127,11 +127,6 @@
 //      template<class X> using pvec = vector<x*>; pvec<int> x;
 //    There's no Decl `pvec<int>`, we must choose `pvec<X>` or `vector<int*>`
 //    and both are lossy. We must know upfront what the caller ultimately wants.
-//
-// FIXME: improve common dependent scope using name lookup in primary templates.
-// We currently handle several dependent constructs, but some others remain to
-// be handled:
-//  - UnresolvedUsingTypenameDecl
 struct TargetFinder {
   using RelSet = DeclRelationSet;
   using Rel = DeclRelation;
@@ -207,6 +202,10 @@
         }
       }
       Flags |= Rel::Alias; // continue with the alias
+    } else if (isa<UnresolvedUsingTypenameDecl>(D)) {
+      // FIXME: improve common dependent scope using name lookup in primary
+      // templates.
+      Flags |= Rel::Alias;
     } else if (const UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D)) {
       // Include the Introducing decl, but don't traverse it. This may end up
       // including *all* shadows, which we don't want.
@@ -382,6 +381,9 @@
         // TypeLoc never has a deduced type. https://llvm.org/PR42914
         Outer.add(DT->getDeducedType(), Flags);
       }
+      void VisitUnresolvedUsingType(const UnresolvedUsingType * UUT) {
+        Outer.add(UUT->getDecl(), Flags);
+      }
       void VisitDeducedTemplateSpecializationType(
           const DeducedTemplateSpecializationType *DTST) {
         if (const auto *USD = DTST->getTemplateName().getAsUsingShadowDecl())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125684.429694.patch
Type: text/x-patch
Size: 2523 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220516/8a2a7428/attachment.bin>


More information about the cfe-commits mailing list