diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -780,7 +780,7 @@ const WorkspaceSymbolParams &Params, Callback> Reply) { Server->workspaceSymbols( - Params.query, Opts.CodeComplete.Limit, + Params.query, Params.limit.getValueOr(Opts.CodeComplete.Limit), [Reply = std::move(Reply), this](llvm::Expected> Items) mutable { if (!Items) @@ -1031,21 +1031,24 @@ 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 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 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.h b/clang-tools-extra/clangd/Protocol.h --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -1056,8 +1056,13 @@ /// 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 limit; }; bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &, llvm::json::Path); @@ -1106,6 +1111,10 @@ struct CompletionParams : TextDocumentPositionParams { CompletionContext context; + + /// Max results to return, overriding global default. 0 means no limit. + /// Clangd extension. + llvm::Optional limit; }; bool fromJSON(const llvm::json::Value &, CompletionParams &, llvm::json::Path); diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -750,7 +750,8 @@ 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, CompletionParams &R, llvm::json::Path P) { - if (!fromJSON(Params, static_cast(R), P)) + if (!fromJSON(Params, static_cast(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"));