tom-anders updated this revision to Diff 472101. tom-anders marked 3 inline comments as done. tom-anders added a comment. Herald added a subscriber: wenlei.
Add test to CodeCompletionTests, only consider unscoped enums in this patch (move scoped enums to separate patch) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D136925/new/ https://reviews.llvm.org/D136925 Files: clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/index/Serialization.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.idx clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp clang-tools-extra/clangd/unittests/TestIndex.cpp clang-tools-extra/clangd/unittests/TestIndex.h
Index: clang-tools-extra/clangd/unittests/TestIndex.h =================================================================== --- clang-tools-extra/clangd/unittests/TestIndex.h +++ clang-tools-extra/clangd/unittests/TestIndex.h @@ -27,6 +27,8 @@ Symbol cls(llvm::StringRef Name); // Creates an enum symbol. Symbol enm(llvm::StringRef Name); +// Creates an enum constant symbol. +Symbol enmConstant(llvm::StringRef Name); // Creates a variable symbol. Symbol var(llvm::StringRef Name); // Creates a namespace symbol. Index: clang-tools-extra/clangd/unittests/TestIndex.cpp =================================================================== --- clang-tools-extra/clangd/unittests/TestIndex.cpp +++ clang-tools-extra/clangd/unittests/TestIndex.cpp @@ -69,6 +69,10 @@ return sym(Name, index::SymbolKind::Enum, "@E@\\0"); } +Symbol enmConstant(llvm::StringRef Name) { + return sym(Name, index::SymbolKind::EnumConstant, "@\\0"); +} + Symbol var(llvm::StringRef Name) { return sym(Name, index::SymbolKind::Variable, "@\\0"); } Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -1316,6 +1316,11 @@ Black }; } + class Color3 { + enum { + Blue + }; + }; )"; runSymbolCollector(Header, /*Main=*/""); EXPECT_THAT(Symbols, @@ -1325,6 +1330,8 @@ AllOf(qName("Green"), forCodeCompletion(true)), AllOf(qName("Color2"), forCodeCompletion(true)), AllOf(qName("Color2::Yellow"), forCodeCompletion(false)), + AllOf(qName("Color3"), forCodeCompletion(true)), + AllOf(qName("Color3::Blue"), forCodeCompletion(true)), AllOf(qName("ns"), forCodeCompletion(true)), AllOf(qName("ns::Black"), forCodeCompletion(true)))); } Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -1,4 +1,5 @@ -//===-- CodeCompleteTests.cpp -----------------------------------*- C++ -*-===// +//===-- CodeCompleteTests.cpp -----------------------------------*- C++ +//-*-===//codecom // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -2962,14 +2963,20 @@ } )cpp", {cls("nx::Clangd1"), cls("ny::Clangd2"), cls("Clangd3"), - cls("na::nb::Clangd4")}, + cls("na::nb::Clangd4"), enmConstant("na::C::Clangd5")}, Opts); EXPECT_THAT( Results.Completions, - UnorderedElementsAre(AllOf(qualifier("nx::"), named("Clangd1")), - AllOf(qualifier("ny::"), named("Clangd2")), - AllOf(qualifier(""), scope(""), named("Clangd3")), - AllOf(qualifier("nb::"), named("Clangd4")))); + UnorderedElementsAre(AllOf(qualifier("nx::"), named("Clangd1"), + kind(CompletionItemKind::Class)), + AllOf(qualifier("ny::"), named("Clangd2"), + kind(CompletionItemKind::Class)), + AllOf(qualifier(""), scope(""), named("Clangd3"), + kind(CompletionItemKind::Class)), + AllOf(qualifier("nb::"), named("Clangd4"), + kind(CompletionItemKind::Class)), + AllOf(qualifier("C::"), named("Clangd5"), + kind(CompletionItemKind::EnumMember)))); } TEST(CompletionTest, NoQualifierIfShadowed) { Index: clang-tools-extra/clangd/index/Serialization.cpp =================================================================== --- clang-tools-extra/clangd/index/Serialization.cpp +++ clang-tools-extra/clangd/index/Serialization.cpp @@ -455,7 +455,7 @@ // The current versioning scheme is simple - non-current versions are rejected. // If you make a breaking change, bump this version number to invalidate stored // data. Later we may want to support some backward compatibility. -constexpr static uint32_t Version = 17; +constexpr static uint32_t Version = 18; llvm::Expected<IndexFileIn> readRIFF(llvm::StringRef Data, SymbolOrigin Origin) { Index: clang-tools-extra/clangd/CodeComplete.cpp =================================================================== --- clang-tools-extra/clangd/CodeComplete.cpp +++ clang-tools-extra/clangd/CodeComplete.cpp @@ -2114,6 +2114,9 @@ }; return false; }; + auto InClassScope = [](const NamedDecl &ND) { + return ND.getDeclContext()->getDeclKind() == Decl::CXXRecord; + }; // We only complete symbol's name, which is the same as the name of the // *primary* template in case of template specializations. if (isExplicitTemplateSpecialization(&ND)) @@ -2129,8 +2132,11 @@ if (InTopLevelScope(ND)) return true; + // Always index enum constants, even if they're not in the top level scope: + // when + // --all-scopes-completion is set, we'll want to complete those as well. if (const auto *EnumDecl = dyn_cast<clang::EnumDecl>(ND.getDeclContext())) - return InTopLevelScope(*EnumDecl) && !EnumDecl->isScoped(); + return (InTopLevelScope(*EnumDecl) || InClassScope(*EnumDecl)) && !EnumDecl->isScoped(); return false; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits