From 84b584be6259acf352cc8662e0f0da02af347a27 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Thu, 21 Feb 2019 09:55:00 +0000 Subject: [PATCH] [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 llvm-svn: 354561 --- clang-tools-extra/clangd/XRefs.cpp | 5 ++++- clang-tools-extra/unittests/clangd/SymbolInfoTests.cpp | 4 ++-- clang-tools-extra/unittests/clangd/XRefsTests.cpp | 10 +++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index b296a056d0c6..9d470779f0b5 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -39,7 +39,8 @@ const Decl *getDefinition(const Decl *D) { if (const auto *FD = dyn_cast(D)) return FD->getDefinition(); // Only a single declaration is allowed. - if (isa(D)) // except cases above + if (isa(D) || isa(D) || + isa(D)) // except cases above return D; // Multiple definitions are allowed. return nullptr; // except cases above @@ -243,6 +244,7 @@ IdentifiedSymbol getSymbolAtPosition(ParsedAST &AST, SourceLocation Pos) { 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 &Decls, ParsedAST &AST) { 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(); diff --git a/clang-tools-extra/unittests/clangd/SymbolInfoTests.cpp b/clang-tools-extra/unittests/clangd/SymbolInfoTests.cpp index ed34c036f799..7494d90cf40c 100644 --- a/clang-tools-extra/unittests/clangd/SymbolInfoTests.cpp +++ b/clang-tools-extra/unittests/clangd/SymbolInfoTests.cpp @@ -213,14 +213,14 @@ TEST(SymbolInfoTests, All) { T^T t; }; )cpp", - {/* not implemented */}}, + {CreateExpectedSymbolDetails("TT", "bar::", "c:TestTU.cpp@65")}}, { R"cpp( // Template parameter reference - type param template struct bar { int a = N^N; }; )cpp", - {/* not implemented */}}, + {CreateExpectedSymbolDetails("NN", "bar::", "c:TestTU.cpp@65")}}, { R"cpp( // Class member reference - objec struct foo { diff --git a/clang-tools-extra/unittests/clangd/XRefsTests.cpp b/clang-tools-extra/unittests/clangd/XRefsTests.cpp index 3b9610cb0d36..f721cf9449e1 100644 --- a/clang-tools-extra/unittests/clangd/XRefsTests.cpp +++ b/clang-tools-extra/unittests/clangd/XRefsTests.cpp @@ -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 void foo() { ^T t; } - )cpp", */ + )cpp", + + R"cpp(// Template template type parameter + template class [[T]]> + void foo() { ^T t; } + )cpp", R"cpp(// Namespace namespace $decl[[ns]] {