[clangd] Invert return value of fuzzyFind() (fix MemIndex's return value)
authorSam McCall <sam.mccall@gmail.com>
Mon, 19 Feb 2018 13:04:41 +0000 (13:04 +0000)
committerSam McCall <sam.mccall@gmail.com>
Mon, 19 Feb 2018 13:04:41 +0000 (13:04 +0000)
Have had way too many bugs by converting between "isComplete" and
"isIncomplete". LSP is immovable, so use isIncomplete everywhere.

llvm-svn: 325493

clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/index/Index.h
clang-tools-extra/clangd/index/Merge.cpp
clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/unittests/clangd/IndexTests.cpp

index 3424ea2..35738fa 100644 (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,
index eeaef54..43ea459 100644 (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;
index 2b8f202..57c62c5 100644 (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:
index b369125..77ff77f 100644 (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; }
index f88942d..3c61533 100644 (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) {