Index: clangd/index/SymbolCollector.cpp =================================================================== --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -115,10 +115,16 @@ // * enum constants in unscoped enum decl (e.g. "red" in "enum {red};") auto InTopLevelScope = hasDeclContext( anyOf(namespaceDecl(), translationUnitDecl(), linkageSpecDecl())); + // Don't index template specializations. + auto IsSpecialization = + anyOf(functionDecl(isExplicitTemplateSpecialization()), + cxxRecordDecl(isExplicitTemplateSpecialization()), + varDecl(isExplicitTemplateSpecialization())); if (match(decl(allOf(unless(isExpansionInMainFile()), anyOf(InTopLevelScope, hasDeclContext(enumDecl(InTopLevelScope, - unless(isScoped())))))), + unless(isScoped())))), + unless(IsSpecialization))), *ND, *ASTCtx) .empty()) return true; Index: unittests/clangd/SymbolCollectorTests.cpp =================================================================== --- unittests/clangd/SymbolCollectorTests.cpp +++ unittests/clangd/SymbolCollectorTests.cpp @@ -162,6 +162,10 @@ static const int KInt = 2; const char* kStr = "123"; + // Template is indexed, specialization is not. + template struct Tmpl; + template <> struct Tmpl {}; + namespace { void ff() {} // ignore } @@ -190,12 +194,13 @@ } // namespace foo )"; runSymbolCollector(Header, /*Main=*/""); - EXPECT_THAT(Symbols, - UnorderedElementsAreArray( - {QName("Foo"), QName("f1"), QName("f2"), QName("KInt"), - QName("kStr"), QName("foo"), QName("foo::bar"), - QName("foo::int32"), QName("foo::int32_t"), QName("foo::v1"), - QName("foo::bar::v2"), QName("foo::baz")})); + EXPECT_THAT( + Symbols, + UnorderedElementsAreArray( + {QName("Foo"), QName("f1"), QName("f2"), QName("KInt"), QName("Tmpl"), + QName("kStr"), QName("foo"), QName("foo::bar"), QName("foo::int32"), + QName("foo::int32_t"), QName("foo::v1"), QName("foo::bar::v2"), + QName("foo::baz")})); } TEST_F(SymbolCollectorTest, Locations) {