[clang-tools-extra] r354561 - [clangd] Enable indexing of template type parameters

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 21 01:55:00 PST 2019


Author: kadircet
Date: Thu Feb 21 01:55:00 2019
New Revision: 354561

URL: http://llvm.org/viewvc/llvm-project?rev=354561&view=rev
Log:
[clangd] Enable indexing of template type parameters

Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=36285

Reviewers: ilya-biryukov

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

Tags: #clang

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

Modified:
    clang-tools-extra/trunk/clangd/XRefs.cpp
    clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp
    clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=354561&r1=354560&r2=354561&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Feb 21 01:55:00 2019
@@ -39,7 +39,8 @@ const Decl *getDefinition(const Decl *D)
   if (const auto *FD = dyn_cast<FunctionDecl>(D))
     return FD->getDefinition();
   // Only a single declaration is allowed.
-  if (isa<ValueDecl>(D)) // except cases above
+  if (isa<ValueDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
+      isa<TemplateTemplateParmDecl>(D)) // except cases above
     return D;
   // Multiple definitions are allowed.
   return nullptr; // except cases above
@@ -243,6 +244,7 @@ IdentifiedSymbol getSymbolAtPosition(Par
       index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
   IndexOpts.IndexParametersInDeclarations = true;
+  IndexOpts.IndexTemplateParameters = true;
   indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
                      AST.getLocalTopLevelDecls(), DeclMacrosFinder, IndexOpts);
 
@@ -441,6 +443,7 @@ findRefs(const std::vector<const Decl *>
       index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
   IndexOpts.IndexParametersInDeclarations = true;
+  IndexOpts.IndexTemplateParameters = true;
   indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
                      AST.getLocalTopLevelDecls(), RefFinder, IndexOpts);
   return std::move(RefFinder).take();

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp?rev=354561&r1=354560&r2=354561&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp Thu Feb 21 01:55:00 2019
@@ -213,14 +213,14 @@ TEST(SymbolInfoTests, All) {
             T^T t;
           };
         )cpp",
-              {/* not implemented */}},
+              {CreateExpectedSymbolDetails("TT", "bar::", "c:TestTU.cpp at 65")}},
           {
               R"cpp( // Template parameter reference - type param
           template<int NN> struct bar {
             int a = N^N;
           };
         )cpp",
-              {/* not implemented */}},
+              {CreateExpectedSymbolDetails("NN", "bar::", "c:TestTU.cpp at 65")}},
           {
               R"cpp( // Class member reference - objec
           struct foo {

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=354561&r1=354560&r2=354561&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Thu Feb 21 01:55:00 2019
@@ -285,11 +285,15 @@ TEST(LocateSymbol, All) {
         }
       )cpp",
 
-      /* FIXME: clangIndex doesn't handle template type parameters
       R"cpp(// Template type parameter
-        template <[[typename T]]>
+        template <typename [[T]]>
         void foo() { ^T t; }
-      )cpp", */
+      )cpp",
+
+      R"cpp(// Template template type parameter
+        template <template<typename> class [[T]]>
+        void foo() { ^T<int> t; }
+      )cpp",
 
       R"cpp(// Namespace
         namespace $decl[[ns]] {




More information about the cfe-commits mailing list