[PATCH] D42484: [clangd] Limit completion results.
Haojian Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 25 01:24:03 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL323408: [clangd] Limit completion results. (authored by hokein, committed by ).
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
https://reviews.llvm.org/D42484
Files:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
@@ -529,6 +529,19 @@
UnorderedElementsAre(Named("local"), Named("Index"), Named("both")));
}
+TEST(CompletionTest, SemaIndexMergeWithLimit) {
+ clangd::CodeCompleteOptions Opts;
+ Opts.Limit = 1;
+ auto Results = completions(
+ R"cpp(
+ namespace ns { int local; void both(); }
+ void f() { ::ns::^ }
+ )cpp",
+ {func("ns::both"), cls("ns::Index")}, Opts);
+ EXPECT_EQ(Results.items.size(), Opts.Limit);
+ EXPECT_TRUE(Results.isIncomplete);
+}
+
TEST(CompletionTest, IndexSuppressesPreambleCompletions) {
MockFSProvider FS;
MockCompilationDatabase CDB;
Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -86,6 +86,12 @@
clEnumValN(PCHStorageFlag::Memory, "memory", "store PCHs in memory")),
llvm::cl::init(PCHStorageFlag::Disk));
+static llvm::cl::opt<int> LimitCompletionResult(
+ "limit-completion",
+ llvm::cl::desc("Limit the number of completion results returned by clangd. "
+ "0 means no limit."),
+ llvm::cl::init(0));
+
static llvm::cl::opt<bool> RunSynchronously(
"run-synchronously",
llvm::cl::desc("Parse on main thread. If set, -j is ignored"),
@@ -215,6 +221,7 @@
clangd::CodeCompleteOptions CCOpts;
CCOpts.EnableSnippets = EnableSnippets;
CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
+ CCOpts.Limit = LimitCompletionResult;
// Initialize and run ClangdLSPServer.
ClangdLSPServer LSPServer(Out, WorkerThreadsCount, StorePreamblesInMemory,
CCOpts, ResourceDirRef, CompileCommandsDirPath,
Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -864,6 +864,8 @@
SymbolSlab::Builder ResultsBuilder;
// Build the query.
FuzzyFindRequest Req;
+ if (Opts.Limit)
+ Req.MaxCandidateCount = Opts.Limit;
Req.Query = Filter->pattern();
Req.Scopes =
getQueryScopes(Recorder.CCContext, Recorder.CCSema->getSourceManager());
Index: clang-tools-extra/trunk/clangd/index/Merge.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/index/Merge.cpp
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp
@@ -50,7 +50,7 @@
for (const Symbol &S : Dyn)
if (!SeenDynamicSymbols.count(S.ID))
Callback(S);
- return More;
+ return !More; // returning true indicates the result is complete.
}
private:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42484.131396.patch
Type: text/x-patch
Size: 3022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180125/a31098d6/attachment.bin>
More information about the llvm-commits
mailing list