[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
This commit is contained in:
Kadir Cetinkaya 2019-02-21 09:55:00 +00:00
parent b780517ca5
commit 84b584be62
3 changed files with 13 additions and 6 deletions

View File

@ -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(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<const Decl *> &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();

View File

@ -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<int NN> struct bar {
int a = N^N;
};
)cpp",
{/* not implemented */}},
{CreateExpectedSymbolDetails("NN", "bar::", "c:TestTU.cpp@65")}},
{
R"cpp( // Class member reference - objec
struct foo {

View File

@ -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]] {