[clangd] Handle type template parameters in findExplicitReferences

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68120

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@373067 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clangd/FindTarget.cpp b/clangd/FindTarget.cpp
index 3f3c029..6bbaa5e 100644
--- a/clangd/FindTarget.cpp
+++ b/clangd/FindTarget.cpp
@@ -489,6 +489,11 @@
           ReferenceLoc{NestedNameSpecifierLoc(), L.getNameLoc(), {L.getDecl()}};
     }
 
+    void VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc L) {
+      Ref =
+          ReferenceLoc{NestedNameSpecifierLoc(), L.getNameLoc(), {L.getDecl()}};
+    }
+
     void VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) {
       Ref = ReferenceLoc{
           NestedNameSpecifierLoc(), L.getTemplateNameLoc(),
diff --git a/clangd/unittests/FindTargetTests.cpp b/clangd/unittests/FindTargetTests.cpp
index d7d1889..32aa25a 100644
--- a/clangd/unittests/FindTargetTests.cpp
+++ b/clangd/unittests/FindTargetTests.cpp
@@ -706,6 +706,26 @@
            "0: targets = {x}\n"
            "1: targets = {X::func, X::func}\n"
            "2: targets = {t}\n"},
+          // Type template parameters.
+          {R"cpp(
+            template <class T>
+            void foo() {
+              static_cast<$0^T>(0);
+              $1^T();
+              $2^T t;
+            }
+        )cpp",
+           "0: targets = {T}\n"
+           "1: targets = {T}\n"
+           "2: targets = {T}\n"},
+          // Non-type template parameters.
+          {R"cpp(
+            template <int I>
+            void foo() {
+              int x = $0^I;
+            }
+        )cpp",
+           "0: targets = {I}\n"},
       };
 
   for (const auto &C : Cases) {