[clangd] Invert return value of fuzzyFind() (fix MemIndex's return value)

Have had way too many bugs by converting between "isComplete" and
"isIncomplete". LSP is immovable, so use isIncomplete everywhere.

llvm-svn: 325493
This commit is contained in:
Sam McCall 2018-02-19 13:04:41 +00:00
parent 167961f6dc
commit ab8e393f62
5 changed files with 16 additions and 10 deletions

View File

@ -919,8 +919,9 @@ private:
Req.Query,
llvm::join(Req.Scopes.begin(), Req.Scopes.end(), ",")));
// Run the query against the index.
Incomplete |= !Opts.Index->fuzzyFind(
Req, [&](const Symbol &Sym) { ResultsBuilder.insert(Sym); });
if (Opts.Index->fuzzyFind(
Req, [&](const Symbol &Sym) { ResultsBuilder.insert(Sym); }))
Incomplete = true;
return std::move(ResultsBuilder).build();
}
@ -978,7 +979,8 @@ private:
NSema += bool(SemaResult);
NIndex += bool(IndexResult);
NBoth += SemaResult && IndexResult;
Incomplete |= Candidates.push({C, Scores});
if (Candidates.push({C, Scores}))
Incomplete = true;
}
CompletionItem toCompletionItem(const CompletionCandidate &Candidate,

View File

@ -255,8 +255,7 @@ public:
/// each matched symbol before returning.
/// If returned Symbols are used outside Callback, they must be deep-copied!
///
/// Returns true if the result list is complete, false if it was truncated due
/// to MaxCandidateCount
/// Returns true if there may be more results (limited by MaxCandidateCount).
virtual bool
fuzzyFind(const FuzzyFindRequest &Req,
llvm::function_ref<void(const Symbol &)> Callback) const = 0;

View File

@ -49,7 +49,7 @@ class MergedIndex : public SymbolIndex {
for (const Symbol &S : Dyn)
if (!SeenDynamicSymbols.count(S.ID))
Callback(S);
return !More; // returning true indicates the result is complete.
return More;
}
private:

View File

@ -698,7 +698,7 @@ public:
fuzzyFind(const FuzzyFindRequest &Req,
llvm::function_ref<void(const Symbol &)> Callback) const override {
Requests.push_back(Req);
return false;
return true;
}
const std::vector<FuzzyFindRequest> allRequests() const { return Requests; }

View File

@ -90,12 +90,15 @@ generateNumSymbols(int Begin, int End,
}
std::vector<std::string> match(const SymbolIndex &I,
const FuzzyFindRequest &Req) {
const FuzzyFindRequest &Req,
bool *Incomplete = nullptr) {
std::vector<std::string> Matches;
I.fuzzyFind(Req, [&](const Symbol &Sym) {
bool IsIncomplete = I.fuzzyFind(Req, [&](const Symbol &Sym) {
Matches.push_back(
(Sym.Scope + (Sym.Scope.empty() ? "" : "::") + Sym.Name).str());
});
if (Incomplete)
*Incomplete = IsIncomplete;
return Matches;
}
@ -144,8 +147,10 @@ TEST(MemIndexTest, MemIndexLimitedNumMatches) {
FuzzyFindRequest Req;
Req.Query = "5";
Req.MaxCandidateCount = 3;
auto Matches = match(I, Req);
bool Incomplete;
auto Matches = match(I, Req, &Incomplete);
EXPECT_EQ(Matches.size(), Req.MaxCandidateCount);
EXPECT_TRUE(Incomplete);
}
TEST(MemIndexTest, FuzzyMatch) {