[clangd] Set Incompleteness for spec fuzzyfind requests

Differential Revision: https://reviews.llvm.org/D133479
This commit is contained in:
Kadir Cetinkaya 2022-09-08 11:19:40 +02:00
parent b090ef9e4f
commit 71c4fb1d64
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
3 changed files with 14 additions and 8 deletions

View File

@ -70,6 +70,7 @@
#include <algorithm>
#include <iterator>
#include <limits>
#include <utility>
// We log detailed candidate here if you run with -debug-only=codecomplete.
#define DEBUG_TYPE "CodeComplete"
@ -1363,13 +1364,14 @@ bool includeSymbolFromIndex(CodeCompletionContext::Kind Kind,
return true;
}
std::future<SymbolSlab> startAsyncFuzzyFind(const SymbolIndex &Index,
const FuzzyFindRequest &Req) {
return runAsync<SymbolSlab>([&Index, Req]() {
std::future<std::pair<bool, SymbolSlab>>
startAsyncFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req) {
return runAsync<std::pair<bool, SymbolSlab>>([&Index, Req]() {
trace::Span Tracer("Async fuzzyFind");
SymbolSlab::Builder Syms;
Index.fuzzyFind(Req, [&Syms](const Symbol &Sym) { Syms.insert(Sym); });
return std::move(Syms).build();
bool Incomplete =
Index.fuzzyFind(Req, [&Syms](const Symbol &Sym) { Syms.insert(Sym); });
return std::make_pair(Incomplete, std::move(Syms).build());
});
}
@ -1721,7 +1723,9 @@ private:
SPAN_ATTACH(Tracer, "Speculative results", true);
trace::Span WaitSpec("Wait speculative results");
return SpecFuzzyFind->Result.get();
auto SpecRes = SpecFuzzyFind->Result.get();
Incomplete |= SpecRes.first;
return std::move(SpecRes.second);
}
SPAN_ATTACH(Tracer, "Speculative results", false);

View File

@ -31,6 +31,7 @@
#include "llvm/ADT/StringRef.h"
#include <functional>
#include <future>
#include <utility>
namespace clang {
class NamedDecl;
@ -262,7 +263,7 @@ struct SpeculativeFuzzyFind {
llvm::Optional<FuzzyFindRequest> NewReq;
/// The result is consumed by `codeComplete()` if speculation succeeded.
/// NOTE: the destructor will wait for the async call to finish.
std::future<SymbolSlab> Result;
std::future<std::pair<bool /*Incomplete*/, SymbolSlab>> Result;
};
/// Gets code completions at a specified \p Pos in \p FileName.

View File

@ -2594,7 +2594,8 @@ TEST(CompletionTest, EnableSpeculativeIndexRequest) {
Opts.Index = &Requests;
auto CompleteAtPoint = [&](StringRef P) {
cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
auto CCR = cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
EXPECT_TRUE(CCR.HasMore);
};
CompleteAtPoint("1");