sammccall created this revision. sammccall added a reviewer: ioeric. Herald added subscribers: cfe-commits, jkorous-apple, ilya-biryukov, klimek.
These have different USRs than the underlying entity, but are not typically interesting in their own right and can be numerous (e.g. generated traits). Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D44298 Files: clangd/index/SymbolCollector.cpp unittests/clangd/SymbolCollectorTests.cpp 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 <class T> struct Tmpl; + template <> struct Tmpl<int> {}; + 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) { 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 <class T> struct Tmpl; + template <> struct Tmpl<int> {}; + 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) { 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)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits