[clang-tools-extra] ca13f55 - [clangd] Add `limit` extension on completion and workspace-symbols
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 16 04:30:37 PDT 2021
Author: Sam McCall
Date: 2021-03-16T12:28:01+01:00
New Revision: ca13f5595ae8dc7326f29c8658de70bbc1854db0
URL: https://github.com/llvm/llvm-project/commit/ca13f5595ae8dc7326f29c8658de70bbc1854db0
DIFF: https://github.com/llvm/llvm-project/commit/ca13f5595ae8dc7326f29c8658de70bbc1854db0.diff
LOG: [clangd] Add `limit` extension on completion and workspace-symbols
This overrides the --limit-results command-line flag, and is not constrained
by it.
See https://github.com/clangd/clangd/issues/707
Differential Revision: https://reviews.llvm.org/D97801
Added:
Modified:
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index b4a5cf337296..aef849d8d8d9 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -780,7 +780,7 @@ void ClangdLSPServer::onWorkspaceSymbol(
const WorkspaceSymbolParams &Params,
Callback<std::vector<SymbolInformation>> Reply) {
Server->workspaceSymbols(
- Params.query, Opts.CodeComplete.Limit,
+ Params.query, Params.limit.getValueOr(Opts.CodeComplete.Limit),
[Reply = std::move(Reply),
this](llvm::Expected<std::vector<SymbolInformation>> Items) mutable {
if (!Items)
@@ -1031,21 +1031,24 @@ void ClangdLSPServer::onCompletion(const CompletionParams &Params,
vlog("ignored auto-triggered completion, preceding char did not match");
return Reply(CompletionList());
}
- Server->codeComplete(
- Params.textDocument.uri.file(), Params.position, Opts.CodeComplete,
- [Reply = std::move(Reply),
- this](llvm::Expected<CodeCompleteResult> List) mutable {
- if (!List)
- return Reply(List.takeError());
- CompletionList LSPList;
- LSPList.isIncomplete = List->HasMore;
- for (const auto &R : List->Completions) {
- CompletionItem C = R.render(Opts.CodeComplete);
- C.kind = adjustKindToCapability(C.kind, SupportedCompletionItemKinds);
- LSPList.items.push_back(std::move(C));
- }
- return Reply(std::move(LSPList));
- });
+ auto Opts = this->Opts.CodeComplete;
+ if (Params.limit && *Params.limit >= 0)
+ Opts.Limit = *Params.limit;
+ Server->codeComplete(Params.textDocument.uri.file(), Params.position, Opts,
+ [Reply = std::move(Reply), Opts,
+ this](llvm::Expected<CodeCompleteResult> List) mutable {
+ if (!List)
+ return Reply(List.takeError());
+ CompletionList LSPList;
+ LSPList.isIncomplete = List->HasMore;
+ for (const auto &R : List->Completions) {
+ CompletionItem C = R.render(Opts);
+ C.kind = adjustKindToCapability(
+ C.kind, SupportedCompletionItemKinds);
+ LSPList.items.push_back(std::move(C));
+ }
+ return Reply(std::move(LSPList));
+ });
}
void ClangdLSPServer::onSignatureHelp(const TextDocumentPositionParams &Params,
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index 42ca721ebcbb..099c8531d341 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -750,7 +750,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const SymbolDetails &S) {
bool fromJSON(const llvm::json::Value &Params, WorkspaceSymbolParams &R,
llvm::json::Path P) {
llvm::json::ObjectMapper O(Params, P);
- return O && O.map("query", R.query);
+ return O && O.map("query", R.query) &&
+ mapOptOrNull(Params, "limit", R.limit, P);
}
llvm::json::Value toJSON(const Command &C) {
@@ -851,7 +852,8 @@ bool fromJSON(const llvm::json::Value &Params, CompletionContext &R,
bool fromJSON(const llvm::json::Value &Params, CompletionParams &R,
llvm::json::Path P) {
- if (!fromJSON(Params, static_cast<TextDocumentPositionParams &>(R), P))
+ if (!fromJSON(Params, static_cast<TextDocumentPositionParams &>(R), P) ||
+ !mapOptOrNull(Params, "limit", R.limit, P))
return false;
if (auto *Context = Params.getAsObject()->get("context"))
return fromJSON(*Context, R.context, P.field("context"));
diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h
index 1334ddf4b5ce..8e90f1f47831 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -1056,8 +1056,13 @@ bool operator==(const SymbolDetails &, const SymbolDetails &);
/// The parameters of a Workspace Symbol Request.
struct WorkspaceSymbolParams {
- /// A non-empty query string
+ /// A query string to filter symbols by.
+ /// Clients may send an empty string here to request all the symbols.
std::string query;
+
+ /// Max results to return, overriding global default. 0 means no limit.
+ /// Clangd extension.
+ llvm::Optional<int> limit;
};
bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &,
llvm::json::Path);
@@ -1106,6 +1111,10 @@ bool fromJSON(const llvm::json::Value &, CompletionContext &, llvm::json::Path);
struct CompletionParams : TextDocumentPositionParams {
CompletionContext context;
+
+ /// Max results to return, overriding global default. 0 means no limit.
+ /// Clangd extension.
+ llvm::Optional<int> limit;
};
bool fromJSON(const llvm::json::Value &, CompletionParams &, llvm::json::Path);
More information about the cfe-commits
mailing list