Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -1510,6 +1510,13 @@ } }; +template bool explicitTemplateSpecialization(const NamedDecl &ND) { + if (const auto *TD = dyn_cast(&ND)) + if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) + return true; + return false; +} + } // namespace clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { @@ -1603,6 +1610,13 @@ }; return false; }; + // We index explicit template specializations merely for code navigation + // support. + if (explicitTemplateSpecialization(ND) || + explicitTemplateSpecialization(ND) || + explicitTemplateSpecialization(ND)) + return false; + if (InTopLevelScope(ND)) return true; Index: clangd/index/SymbolCollector.cpp =================================================================== --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -221,13 +221,6 @@ return static_cast(static_cast(RefKind::All) & Roles); } -template bool explicitTemplateSpecialization(const NamedDecl &ND) { - if (const auto *TD = dyn_cast(&ND)) - if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) - return true; - return false; -} - } // namespace SymbolCollector::SymbolCollector(Options Opts) : Opts(std::move(Opts)) {} @@ -279,10 +272,6 @@ if (!isa(DeclCtx)) return false; } - if (explicitTemplateSpecialization(ND) || - explicitTemplateSpecialization(ND) || - explicitTemplateSpecialization(ND)) - return false; // Avoid indexing internal symbols in protobuf generated headers. if (isPrivateProtoDecl(ND)) Index: unittests/clangd/SymbolCollectorTests.cpp =================================================================== --- unittests/clangd/SymbolCollectorTests.cpp +++ unittests/clangd/SymbolCollectorTests.cpp @@ -392,17 +392,24 @@ TEST_F(SymbolCollectorTest, Template) { Annotations Header(R"( - // Template is indexed, specialization and instantiation is not. - template struct [[Tmpl]] {T $xdecl[[x]] = 0;}; - template <> struct Tmpl {}; - extern template struct Tmpl; - template struct Tmpl; + // Template and explicit specialization is indexed, instantiation is not. + template struct [[Tmpl]] {T $xdecl[[x]] = 0;}; + template <> struct $specdecl[[Tmpl]] {}; + template struct $partspecdecl[[Tmpl]] {}; + extern template struct Tmpl; + template struct Tmpl; )"); runSymbolCollector(Header.code(), /*Main=*/""); EXPECT_THAT(Symbols, - UnorderedElementsAreArray( - {AllOf(QName("Tmpl"), DeclRange(Header.range())), - AllOf(QName("Tmpl::x"), DeclRange(Header.range("xdecl")))})); + UnorderedElementsAre( + AllOf(QName("Tmpl"), DeclRange(Header.range()), + ForCodeCompletion(true)), + AllOf(QName("Tmpl"), DeclRange(Header.range("specdecl")), + ForCodeCompletion(false)), + AllOf(QName("Tmpl"), DeclRange(Header.range("partspecdecl")), + ForCodeCompletion(false)), + AllOf(QName("Tmpl::x"), DeclRange(Header.range("xdecl")), + ForCodeCompletion(false)))); } TEST_F(SymbolCollectorTest, ObjCSymbols) {