From c383509ce69c691a8d2bfb3b61f1d7003f1c58be Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Fri, 27 Sep 2019 10:55:53 +0000 Subject: [PATCH] [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 llvm-svn: 373067 --- clang-tools-extra/clangd/FindTarget.cpp | 5 +++++ .../clangd/unittests/FindTargetTests.cpp | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index 3f3c0296d175..6bbaa5e616bc 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -489,6 +489,11 @@ Optional refInTypeLoc(TypeLoc L) { 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/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp index d7d1889e4671..32aa25a1bd5d 100644 --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -706,6 +706,26 @@ TEST_F(FindExplicitReferencesTest, All) { "0: targets = {x}\n" "1: targets = {X::func, X::func}\n" "2: targets = {t}\n"}, + // Type template parameters. + {R"cpp( + template + 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 + void foo() { + int x = $0^I; + } + )cpp", + "0: targets = {I}\n"}, }; for (const auto &C : Cases) {