[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

llvm-svn: 346223
This commit is contained in:
Eric Liu 2018-11-06 11:08:17 +00:00
parent cc297272c7
commit b04869a4aa
7 changed files with 17 additions and 7 deletions

View File

@ -116,6 +116,8 @@ getWorkspaceSymbols(StringRef Query, int Limit, const SymbolIndex *const Index,
// not).
if (IsGlobalQuery || !Names.first.empty())
Req.Scopes = {Names.first};
else
Req.AnyScope = true;
if (Limit)
Req.Limit = Limit;
TopN<ScoredSymbolInfo, ScoredSymbolGreater> Top(

View File

@ -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.

View File

@ -39,8 +39,7 @@ bool MemIndex::fuzzyFind(const FuzzyFindRequest &Req,
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))

View File

@ -178,7 +178,7 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req,
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)));

View File

@ -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, MatchQualifiedNamesWithoutSpecificScope) {
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;

View File

@ -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, MemIndexLimitedNumMatches) {
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, MatchQualifiedNamesWithoutSpecificScope) {
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"));
}

View File

@ -130,6 +130,7 @@ runDocumentSymbols(ClangdServer &Server, PathRef File) {
SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query) {
FuzzyFindRequest Req;
Req.Query = Query;
Req.AnyScope = true;
return runFuzzyFind(Index, Req);
}