Author: ioeric Date: Tue Nov 6 03:08:17 2018 New Revision: 346223 URL: http://llvm.org/viewvc/llvm-project?rev=346223&view=rev Log: [clangd] Get rid of QueryScopes.empty() == AnyScope special case.
Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53933 Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/MemIndex.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.cpp clang-tools-extra/trunk/unittests/clangd/DexTests.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=346223&r1=346222&r2=346223&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original) +++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Tue Nov 6 03:08:17 2018 @@ -116,6 +116,8 @@ getWorkspaceSymbols(StringRef Query, int // not). if (IsGlobalQuery || !Names.first.empty()) Req.Scopes = {Names.first}; + else + Req.AnyScope = true; if (Limit) Req.Limit = Limit; TopN<ScoredSymbolInfo, ScoredSymbolGreater> Top( Modified: clang-tools-extra/trunk/clangd/index/Index.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=346223&r1=346222&r2=346223&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/Index.h (original) +++ clang-tools-extra/trunk/clangd/index/Index.h Tue Nov 6 03:08:17 2018 @@ -460,9 +460,6 @@ struct FuzzyFindRequest { /// namespace xyz::abc. /// /// The global scope is "", a top level scope is "foo::", etc. - /// FIXME: drop the special case for empty list, which is the same as - /// `AnyScope = true`. - /// FIXME: support scope proximity. std::vector<std::string> Scopes; /// If set to true, allow symbols from any scope. Scopes explicitly listed /// above will be ranked higher. Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=346223&r1=346222&r2=346223&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Tue Nov 6 03:08:17 2018 @@ -39,8 +39,7 @@ bool MemIndex::fuzzyFind(const FuzzyFind const Symbol *Sym = Pair.second; // Exact match against all possible scopes. - if (!Req.AnyScope && !Req.Scopes.empty() && - !is_contained(Req.Scopes, Sym->Scope)) + if (!Req.AnyScope && !is_contained(Req.Scopes, Sym->Scope)) continue; if (Req.RestrictForCodeCompletion && !(Sym->Flags & Symbol::IndexedForCodeCompletion)) Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=346223&r1=346222&r2=346223&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original) +++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Tue Nov 6 03:08:17 2018 @@ -178,7 +178,7 @@ bool Dex::fuzzyFind(const FuzzyFindReque std::vector<std::unique_ptr<Iterator>> ScopeIterators; for (const auto &Scope : Req.Scopes) ScopeIterators.push_back(iterator(Token(Token::Kind::Scope, Scope))); - if (Req.AnyScope || /*legacy*/ Req.Scopes.empty()) + if (Req.AnyScope) ScopeIterators.push_back( Corpus.boost(Corpus.all(), ScopeIterators.empty() ? 1.0 : 0.2)); Criteria.push_back(Corpus.unionOf(move(ScopeIterators))); Modified: clang-tools-extra/trunk/unittests/clangd/DexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DexTests.cpp?rev=346223&r1=346222&r2=346223&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/DexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/DexTests.cpp Tue Nov 6 03:08:17 2018 @@ -485,6 +485,7 @@ TEST(Dex, FuzzyFind) { UnorderedElementsAre("other::A", "other::ABC")); Req.Query = ""; Req.Scopes = {}; + Req.AnyScope = true; EXPECT_THAT(match(*Index, Req), UnorderedElementsAre("ns::ABC", "ns::BCD", "::ABC", "ns::nested::ABC", "other::ABC", @@ -495,6 +496,7 @@ TEST(DexTest, DexLimitedNumMatches) { auto I = Dex::build(generateNumSymbols(0, 100), RefSlab(), URISchemes); FuzzyFindRequest Req; Req.Query = "5"; + Req.AnyScope = true; Req.Limit = 3; bool Incomplete; auto Matches = match(*I, Req, &Incomplete); @@ -509,6 +511,7 @@ TEST(DexTest, FuzzyMatch) { RefSlab(), URISchemes); FuzzyFindRequest Req; Req.Query = "lol"; + Req.AnyScope = true; Req.Limit = 2; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("LaughingOutLoud", "LittleOldLady")); @@ -518,6 +521,7 @@ TEST(DexTest, ShortQuery) { auto I = Dex::build(generateSymbols({"OneTwoThreeFour"}), RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; bool Incomplete; EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("OneTwoThreeFour")); @@ -540,6 +544,7 @@ TEST(DexTest, MatchQualifiedNamesWithout auto I = Dex::build(generateSymbols({"a::y1", "b::y2", "y3"}), RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; Req.Query = "y"; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "b::y2", "y3")); } @@ -584,9 +589,9 @@ TEST(DexTest, WildcardScope) { auto I = Dex::build(generateSymbols({"a::y1", "a::b::y2", "c::y3"}), RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; Req.Query = "y"; Req.Scopes = {"a::"}; - Req.AnyScope = true; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "a::b::y2", "c::y3")); } @@ -626,6 +631,7 @@ TEST(DexTest, SymbolIndexOptionsFilter) std::vector<Symbol> Symbols{CodeCompletionSymbol, NonCodeCompletionSymbol}; Dex I(Symbols, RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; Req.RestrictForCodeCompletion = false; EXPECT_THAT(match(I, Req), ElementsAre("Completion", "NoCompletion")); Req.RestrictForCodeCompletion = true; @@ -642,6 +648,7 @@ TEST(DexTest, ProximityPathsBoosting) { Dex I(Symbols, RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; Req.Query = "abc"; // The best candidate can change depending on the proximity paths. Req.Limit = 1; Modified: clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp?rev=346223&r1=346222&r2=346223&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp Tue Nov 6 03:08:17 2018 @@ -90,6 +90,7 @@ TEST(MemIndexTest, MemIndexDeduplicate) symbol("2") /* duplicate */}; FuzzyFindRequest Req; Req.Query = "2"; + Req.AnyScope = true; MemIndex I(Symbols, RefSlab()); EXPECT_THAT(match(I, Req), ElementsAre("2")); } @@ -98,6 +99,7 @@ TEST(MemIndexTest, MemIndexLimitedNumMat auto I = MemIndex::build(generateNumSymbols(0, 100), RefSlab()); FuzzyFindRequest Req; Req.Query = "5"; + Req.AnyScope = true; Req.Limit = 3; bool Incomplete; auto Matches = match(*I, Req, &Incomplete); @@ -112,6 +114,7 @@ TEST(MemIndexTest, FuzzyMatch) { RefSlab()); FuzzyFindRequest Req; Req.Query = "lol"; + Req.AnyScope = true; Req.Limit = 2; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("LaughingOutLoud", "LittleOldLady")); @@ -122,6 +125,7 @@ TEST(MemIndexTest, MatchQualifiedNamesWi MemIndex::build(generateSymbols({"a::y1", "b::y2", "y3"}), RefSlab()); FuzzyFindRequest Req; Req.Query = "y"; + Req.AnyScope = true; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "b::y2", "y3")); } Modified: clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp?rev=346223&r1=346222&r2=346223&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp Tue Nov 6 03:08:17 2018 @@ -130,6 +130,7 @@ runDocumentSymbols(ClangdServer &Server, SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query) { FuzzyFindRequest Req; Req.Query = Query; + Req.AnyScope = true; return runFuzzyFind(Index, Req); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits