[PATCH] D58294: [clangd] Enable indexing of template type parameters

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 15 10:49:43 PST 2019


kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric.
Herald added a project: clang.

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


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D58294

Files:
  clangd/XRefs.cpp
  clangd/index/FileIndex.cpp
  unittests/clangd/SymbolInfoTests.cpp
  unittests/clangd/XRefsTests.cpp


Index: unittests/clangd/XRefsTests.cpp
===================================================================
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -285,11 +285,10 @@
         }
       )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(// Namespace
         namespace $decl[[ns]] {
Index: unittests/clangd/SymbolInfoTests.cpp
===================================================================
--- unittests/clangd/SymbolInfoTests.cpp
+++ unittests/clangd/SymbolInfoTests.cpp
@@ -213,14 +213,14 @@
             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 {
Index: clangd/index/FileIndex.cpp
===================================================================
--- clangd/index/FileIndex.cpp
+++ clangd/index/FileIndex.cpp
@@ -42,6 +42,7 @@
   IndexOpts.SystemSymbolFilter =
       index::IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly;
   IndexOpts.IndexFunctionLocals = false;
+  IndexOpts.IndexTemplateParmDecls = true;
   if (IsIndexMainAST) {
     // We only collect refs when indexing main AST.
     CollectorOpts.RefFilter = RefKind::All;
Index: clangd/XRefs.cpp
===================================================================
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -39,7 +39,7 @@
   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)) // except cases above
     return D;
   // Multiple definitions are allowed.
   return nullptr; // except cases above
@@ -243,6 +243,7 @@
       index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
   IndexOpts.IndexParametersInDeclarations = true;
+  IndexOpts.IndexTemplateParmDecls = true;
   indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
                      AST.getLocalTopLevelDecls(), DeclMacrosFinder, IndexOpts);
 
@@ -441,6 +442,7 @@
       index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
   IndexOpts.IndexParametersInDeclarations = true;
+  IndexOpts.IndexTemplateParmDecls = true;
   indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
                      AST.getLocalTopLevelDecls(), RefFinder, IndexOpts);
   return std::move(RefFinder).take();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58294.187049.patch
Type: text/x-patch
Size: 3070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190215/5eae4a6d/attachment.bin>


More information about the cfe-commits mailing list