diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -463,6 +463,26 @@ EXPECT_THAT( Results.Completions, UnorderedElementsAre(AllOf(Named("a"), Kind(CompletionItemKind::Field)))); + + // Completion kinds for templates should not be unknown. + Results = completions( + R"cpp( + template struct complete_class {}; + template void complete_function(); + template using complete_type_alias = int; + template int complete_variable = 10; + + auto x = complete_^ + )cpp"); + EXPECT_THAT( + Results.Completions, + UnorderedElementsAre( + AllOf(Named("complete_class"), Kind(CompletionItemKind::Class)), + AllOf(Named("complete_function"), Kind(CompletionItemKind::Function)), + AllOf(Named("complete_type_alias"), + Kind(CompletionItemKind::Reference)), + AllOf(Named("complete_variable"), + Kind(CompletionItemKind::Variable)))); } TEST(CompletionTest, NoDuplicates) { diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp --- a/clang/lib/Index/IndexSymbol.cpp +++ b/clang/lib/Index/IndexSymbol.cpp @@ -96,6 +96,13 @@ Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface; } + if (auto *VT = dyn_cast(D)) { + Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic; + Info.Lang = SymbolLanguage::CXX; + // All other fields are filled from the templated decl. + D = VT->getTemplatedDecl(); + } + if (const TagDecl *TD = dyn_cast(D)) { switch (TD->getTagKind()) { case TTK_Struct: @@ -333,6 +340,23 @@ Info.Lang = SymbolLanguage::CXX; } break; + case Decl::ClassTemplatePartialSpecialization: + case Decl::ClassScopeFunctionSpecialization: + case Decl::ClassTemplateSpecialization: + case Decl::CXXRecord: + case Decl::Enum: + case Decl::Record: + llvm_unreachable("records handled before"); + break; + case Decl::VarTemplateSpecialization: + case Decl::VarTemplatePartialSpecialization: + case Decl::ImplicitParam: + case Decl::ParmVar: + case Decl::Var: + case Decl::VarTemplate: + llvm_unreachable("variables handled before"); + break; + // Other decls get the 'unknown' kind. default: break; }