kadircet updated this revision to Diff 189817. kadircet marked 3 inline comments as done. kadircet added a comment.
- Address comments Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59083/new/ https://reviews.llvm.org/D59083 Files: clangd/CodeComplete.cpp clangd/index/SymbolCollector.cpp unittests/clangd/SymbolCollectorTests.cpp Index: unittests/clangd/SymbolCollectorTests.cpp =================================================================== --- unittests/clangd/SymbolCollectorTests.cpp +++ unittests/clangd/SymbolCollectorTests.cpp @@ -392,17 +392,25 @@ TEST_F(SymbolCollectorTest, Template) { Annotations Header(R"( - // Template is indexed, specialization and instantiation is not. - template <class T> struct [[Tmpl]] {T $xdecl[[x]] = 0;}; - template <> struct Tmpl<int> {}; - extern template struct Tmpl<float>; - template struct Tmpl<double>; + // Primary template and explicit specialization are indexed, instantiation + // is not. + template <class T, class U> struct [[Tmpl]] {T $xdecl[[x]] = 0;}; + template <> struct $specdecl[[Tmpl]]<int, bool> {}; + template <class U> struct $partspecdecl[[Tmpl]]<bool, U> {}; + extern template struct Tmpl<float, bool>; + template struct Tmpl<double, bool>; )"); 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) { Index: clangd/index/SymbolCollector.cpp =================================================================== --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -221,13 +221,6 @@ return static_cast<RefKind>(static_cast<unsigned>(RefKind::All) & Roles); } -template <class T> bool explicitTemplateSpecialization(const NamedDecl &ND) { - if (const auto *TD = dyn_cast<T>(&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<RecordDecl>(DeclCtx)) return false; } - if (explicitTemplateSpecialization<FunctionDecl>(ND) || - explicitTemplateSpecialization<CXXRecordDecl>(ND) || - explicitTemplateSpecialization<VarDecl>(ND)) - return false; // Avoid indexing internal symbols in protobuf generated headers. if (isPrivateProtoDecl(ND)) Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -1510,6 +1510,13 @@ } }; +template <class T> bool isExplicitTemplateSpecialization(const NamedDecl &ND) { + if (const auto *TD = dyn_cast<T>(&ND)) + if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) + return true; + return false; +} + } // namespace clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { @@ -1603,6 +1610,13 @@ }; return false; }; + // We only complete symbol's name, which is same as the class template in the + // case of template specializations. + if (isExplicitTemplateSpecialization<FunctionDecl>(ND) || + isExplicitTemplateSpecialization<CXXRecordDecl>(ND) || + isExplicitTemplateSpecialization<VarDecl>(ND)) + return false; + if (InTopLevelScope(ND)) return true;
Index: unittests/clangd/SymbolCollectorTests.cpp =================================================================== --- unittests/clangd/SymbolCollectorTests.cpp +++ unittests/clangd/SymbolCollectorTests.cpp @@ -392,17 +392,25 @@ TEST_F(SymbolCollectorTest, Template) { Annotations Header(R"( - // Template is indexed, specialization and instantiation is not. - template <class T> struct [[Tmpl]] {T $xdecl[[x]] = 0;}; - template <> struct Tmpl<int> {}; - extern template struct Tmpl<float>; - template struct Tmpl<double>; + // Primary template and explicit specialization are indexed, instantiation + // is not. + template <class T, class U> struct [[Tmpl]] {T $xdecl[[x]] = 0;}; + template <> struct $specdecl[[Tmpl]]<int, bool> {}; + template <class U> struct $partspecdecl[[Tmpl]]<bool, U> {}; + extern template struct Tmpl<float, bool>; + template struct Tmpl<double, bool>; )"); 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) { Index: clangd/index/SymbolCollector.cpp =================================================================== --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -221,13 +221,6 @@ return static_cast<RefKind>(static_cast<unsigned>(RefKind::All) & Roles); } -template <class T> bool explicitTemplateSpecialization(const NamedDecl &ND) { - if (const auto *TD = dyn_cast<T>(&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<RecordDecl>(DeclCtx)) return false; } - if (explicitTemplateSpecialization<FunctionDecl>(ND) || - explicitTemplateSpecialization<CXXRecordDecl>(ND) || - explicitTemplateSpecialization<VarDecl>(ND)) - return false; // Avoid indexing internal symbols in protobuf generated headers. if (isPrivateProtoDecl(ND)) Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -1510,6 +1510,13 @@ } }; +template <class T> bool isExplicitTemplateSpecialization(const NamedDecl &ND) { + if (const auto *TD = dyn_cast<T>(&ND)) + if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) + return true; + return false; +} + } // namespace clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { @@ -1603,6 +1610,13 @@ }; return false; }; + // We only complete symbol's name, which is same as the class template in the + // case of template specializations. + if (isExplicitTemplateSpecialization<FunctionDecl>(ND) || + isExplicitTemplateSpecialization<CXXRecordDecl>(ND) || + isExplicitTemplateSpecialization<VarDecl>(ND)) + return false; + if (InTopLevelScope(ND)) return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits