Index: clangd/index/SymbolCollector.cpp =================================================================== --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -109,6 +109,14 @@ if (ND->isInAnonymousNamespace()) return true; + // Don't index template specializations. + if (!match(decl(anyOf(functionDecl(isExplicitTemplateSpecialization()), + cxxRecordDecl(isExplicitTemplateSpecialization()), + varDecl(isExplicitTemplateSpecialization()))), + *ND, *ASTCtx) + .empty()) + return true; + // We only want: // * symbols in namespaces or translation unit scopes (e.g. no class // members) 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) {