Author: sammccall Date: Mon Feb 19 05:04:41 2018 New Revision: 325493 URL: http://llvm.org/viewvc/llvm-project?rev=325493&view=rev Log: [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. Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/Merge.cpp clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=325493&r1=325492&r2=325493&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon Feb 19 05:04:41 2018 @@ -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, 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=325493&r1=325492&r2=325493&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/Index.h (original) +++ clang-tools-extra/trunk/clangd/index/Index.h Mon Feb 19 05:04:41 2018 @@ -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; Modified: clang-tools-extra/trunk/clangd/index/Merge.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=325493&r1=325492&r2=325493&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/Merge.cpp (original) +++ clang-tools-extra/trunk/clangd/index/Merge.cpp Mon Feb 19 05:04:41 2018 @@ -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: Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=325493&r1=325492&r2=325493&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon Feb 19 05:04:41 2018 @@ -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; } 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=325493&r1=325492&r2=325493&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp Mon Feb 19 05:04:41 2018 @@ -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, MemIndexLimitedNumMat 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits