Index: clangd/FindSymbols.cpp =================================================================== --- clangd/FindSymbols.cpp +++ clangd/FindSymbols.cpp @@ -116,6 +116,8 @@ // not). if (IsGlobalQuery || !Names.first.empty()) Req.Scopes = {Names.first}; + else + Req.AnyScope = true; if (Limit) Req.Limit = Limit; TopN Top( Index: clangd/index/Index.h =================================================================== --- clangd/index/Index.h +++ clangd/index/Index.h @@ -460,9 +460,6 @@ /// 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 Scopes; /// If set to true, allow symbols from any scope. Scopes explicitly listed /// above will be ranked higher. Index: clangd/index/MemIndex.cpp =================================================================== --- clangd/index/MemIndex.cpp +++ clangd/index/MemIndex.cpp @@ -39,8 +39,7 @@ 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)) Index: clangd/index/dex/Dex.cpp =================================================================== --- clangd/index/dex/Dex.cpp +++ clangd/index/dex/Dex.cpp @@ -178,7 +178,7 @@ std::vector> 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))); Index: unittests/clangd/DexTests.cpp =================================================================== --- unittests/clangd/DexTests.cpp +++ unittests/clangd/DexTests.cpp @@ -485,6 +485,7 @@ 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", @@ -496,6 +497,7 @@ symbol("2") /* duplicate */}; FuzzyFindRequest Req; Req.Query = "2"; + Req.AnyScope = true; Dex I(Symbols, RefSlab(), URISchemes); EXPECT_THAT(match(I, Req), ElementsAre("2")); } @@ -504,6 +506,7 @@ 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); @@ -518,6 +521,7 @@ RefSlab(), URISchemes); FuzzyFindRequest Req; Req.Query = "lol"; + Req.AnyScope = true; Req.Limit = 2; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("LaughingOutLoud", "LittleOldLady")); @@ -527,6 +531,7 @@ auto I = Dex::build(generateSymbols({"OneTwoThreeFour"}), RefSlab(), URISchemes); FuzzyFindRequest Req; + Req.AnyScope = true; bool Incomplete; EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("OneTwoThreeFour")); @@ -549,6 +554,7 @@ 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")); } @@ -593,9 +599,9 @@ 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")); } @@ -635,6 +641,7 @@ std::vector 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; @@ -651,6 +658,7 @@ 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; Index: unittests/clangd/IndexTests.cpp =================================================================== --- unittests/clangd/IndexTests.cpp +++ unittests/clangd/IndexTests.cpp @@ -90,6 +90,7 @@ 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 @@ 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 @@ RefSlab()); FuzzyFindRequest Req; Req.Query = "lol"; + Req.AnyScope = true; Req.Limit = 2; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("LaughingOutLoud", "LittleOldLady")); @@ -122,6 +125,7 @@ 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")); } Index: unittests/clangd/SyncAPI.cpp =================================================================== --- unittests/clangd/SyncAPI.cpp +++ unittests/clangd/SyncAPI.cpp @@ -129,6 +129,7 @@ SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query) { FuzzyFindRequest Req; Req.Query = Query; + Req.AnyScope = true; return runFuzzyFind(Index, Req); }