diff --git a/packages/cxx-gen-lsp/src/MetaModel.ts b/packages/cxx-gen-lsp/src/MetaModel.ts index e8c10fee..07be9b0c 100644 --- a/packages/cxx-gen-lsp/src/MetaModel.ts +++ b/packages/cxx-gen-lsp/src/MetaModel.ts @@ -199,7 +199,7 @@ export function toCppType(type: Type): string { case "string": return "std::string"; case "integer": - return "int"; + return "long"; case "uinteger": return "long"; case "decimal": diff --git a/packages/cxx-gen-lsp/src/gen_fwd_h.ts b/packages/cxx-gen-lsp/src/gen_fwd_h.ts index f5849bc6..0b254e28 100644 --- a/packages/cxx-gen-lsp/src/gen_fwd_h.ts +++ b/packages/cxx-gen-lsp/src/gen_fwd_h.ts @@ -39,8 +39,12 @@ class LSPObject { explicit LSPObject(json& repr): repr_(&repr) {} [[nodiscard]] explicit operator bool() const { return repr_ != nullptr; } + [[nodiscard]] operator const json&() const { return *repr_; } - [[nodiscard]] auto get() const -> json& { return *repr_; } + [[nodiscard]] operator json&() { return *repr_; } + + [[nodiscard]] auto get() const -> const json& { return *repr_; } + [[nodiscard]] auto get() -> json& { return *repr_; } protected: json* repr_{nullptr}; @@ -51,12 +55,17 @@ class LSPRequest : public LSPObject { using LSPObject::LSPObject; [[nodiscard]] auto id() const -> std::optional>; + auto id(std::optional>) -> LSPRequest&; + [[nodiscard]] auto method() const -> std::string; }; class LSPResponse : public LSPObject { public: using LSPObject::LSPObject; + + [[nodiscard]] auto id() const -> std::optional>; + auto id(std::optional>) -> LSPResponse&; }; template diff --git a/packages/cxx-gen-lsp/src/gen_requests_cc.ts b/packages/cxx-gen-lsp/src/gen_requests_cc.ts index 8cc25795..b8989b9d 100644 --- a/packages/cxx-gen-lsp/src/gen_requests_cc.ts +++ b/packages/cxx-gen-lsp/src/gen_requests_cc.ts @@ -19,24 +19,14 @@ // SOFTWARE. import * as path from "node:path"; -import { Enumeration, isRequest, MetaModel, Structure, toCppType, Type, TypeAlias } from "./MetaModel.js"; +import { isRequest, MetaModel, Structure, toCppType, Type } from "./MetaModel.js"; import { writeFileSync } from "node:fs"; import { copyrightHeader } from "./copyrightHeader.js"; +import { TypeGenerator } from "./gen_types_cc.js"; -class RequestGenerator { - readonly structByName: Map; - readonly enumByName: Map; - readonly typeAliasByName: Map; - readonly model: MetaModel; - readonly outputDirectory: string; - out: string = ""; - +class RequestGenerator extends TypeGenerator { constructor({ model, outputDirectory }: { model: MetaModel; outputDirectory: string }) { - this.model = model; - this.outputDirectory = outputDirectory; - this.structByName = new Map(model.structures.map((s) => [s.name, s])); - this.enumByName = new Map(model.enumerations.map((e) => [e.name, e])); - this.typeAliasByName = new Map(model.typeAliases.map((t) => [t.name, t])); + super({ model, outputDirectory }); } genTypes() { @@ -50,9 +40,44 @@ class RequestGenerator { this.emit(` return id.get();`); this.emit(`}`); this.emit(); + this.emit(`auto LSPRequest::id(std::optional> id)`); + this.emit(` -> LSPRequest& {`); + this.emit(` if (!id.has_value()) {`); + this.emit(` repr_->erase("id");`); + this.emit(` return *this;`); + this.emit(` }`); + this.emit(` if (std::holds_alternative(*id)) {`); + this.emit(` (*repr_)["id"] = std::get(*id);`); + this.emit(` } else {`); + this.emit(` (*repr_)["id"] = std::get(*id);`); + this.emit(` }`); + this.emit(` return *this;`); + this.emit(`}`); + this.emit(); this.emit(`auto LSPRequest::method() const -> std::string {`); this.emit(` return repr_->at("method");`); this.emit(`}`); + this.emit(); + this.emit(`auto LSPResponse::id() const -> std::optional> {`); + this.emit(` if (!repr_->contains("id")) return std::nullopt;`); + this.emit(` const auto& id = repr_->at("id");`); + this.emit(` if (id.is_string()) return id.get();`); + this.emit(` return id.get();`); + this.emit(`}`); + this.emit(); + this.emit(`auto LSPResponse::id(std::optional> id)`); + this.emit(` -> LSPResponse& {`); + this.emit(` if (!id.has_value()) {`); + this.emit(` repr_->erase("id");`); + this.emit(` return *this;`); + this.emit(` }`); + this.emit(` if (std::holds_alternative(*id)) {`); + this.emit(` (*repr_)["id"] = std::get(*id);`); + this.emit(` } else {`); + this.emit(` (*repr_)["id"] = std::get(*id);`); + this.emit(` }`); + this.emit(` return *this;`); + this.emit(`}`); const requestsAndNotifications = [...this.model.requests, ...this.model.notifications]; @@ -65,12 +90,7 @@ class RequestGenerator { this.emit(`}`); this.emit(); this.emit(`auto ${typeName}::id(std::variant id) -> ${typeName}& {`); - this.emit(` if (std::holds_alternative(id)) {`); - this.emit(` (*repr_)["id"] = std::get(id);`); - this.emit(` } else {`); - this.emit(` (*repr_)["id"] = std::get(id);`); - this.emit(` }`); - this.emit(` return *this;`); + this.emit(` return static_cast<${typeName}&>(LSPRequest::id(std::move(id)));`); this.emit(`}`); if (request.params) { @@ -90,66 +110,26 @@ class RequestGenerator { if (isRequest(request) && request.result) { const responseTypeName = typeName.replace(/Request$/, "Response"); - const resultTypeName = toCppType(request.result); this.emit(); - this.emit(`auto ${responseTypeName}::id(long id) -> ${responseTypeName}& {`); - this.emit(` (*repr_)["id"] = id;`); - this.emit(` return *this;`); - this.emit(`}`); - this.emit(); - this.emit(`auto ${responseTypeName}::id(std::string id) -> ${responseTypeName}& {`); - this.emit(` (*repr_)["id"] = std::move(id);`); - this.emit(` return *this;`); - this.emit(`}`); - this.emit(); - this.emit(`auto ${responseTypeName}::result() const -> ${resultTypeName} {`); - switch (request.result.kind) { - case "base": { - if (request.result.name === "null") { - this.emit(` return nullptr;`); - } else { - this.emit(` return repr_->at("result").get<${toCppType(request.result)}>(); // base`); - } - break; - } - - case "reference": { - if (this.structByName.has(request.result.name)) { - this.emit(` if (!repr_->contains("result")) (*repr_)["result"] = nullptr;`); - this.emit(` return ${resultTypeName}(repr_->at("result")); // reference`); - } else { - this.emit(` lsp_runtime_error("${responseTypeName}::result() - not implemented yet");`); - } - break; - } - - default: { - this.emit(` lsp_runtime_error("${responseTypeName}::result() - not implemented yet");`); - } - } // swtch - this.emit(`}`); - this.emit(); - this.emit(`auto ${responseTypeName}::result(${resultTypeName} result) -> ${responseTypeName}& {`); - switch (request.result.kind) { - case "base": - this.emit(` (*repr_)["result"] = std::move(result); // base`); - break; - default: - this.emit(` lsp_runtime_error("${responseTypeName}::result() - not implemented yet");`); - } // switch - this.emit(` return *this;`); + this.emit(`auto ${responseTypeName}::id(std::variant id) -> ${responseTypeName}& {`); + this.emit(` return static_cast<${responseTypeName}&>(LSPResponse::id(std::move(id)));`); this.emit(`}`); + + // synthetic structure with result property + + const structure: Structure = { + name: responseTypeName, + properties: [{ name: "result", type: request.result, optional: false }], + }; + + this.generateGetters({ structure, properties: structure.properties }); } }); this.end(); } - emit(s: string = "") { - this.out += `${s}\n`; - } - getPropertyType({ type, optional }: { type: Type; optional?: boolean }): string { let propertyType = toCppType(type); diff --git a/packages/cxx-gen-lsp/src/gen_requests_h.ts b/packages/cxx-gen-lsp/src/gen_requests_h.ts index ede326d1..e5372b04 100644 --- a/packages/cxx-gen-lsp/src/gen_requests_h.ts +++ b/packages/cxx-gen-lsp/src/gen_requests_h.ts @@ -91,10 +91,10 @@ export function gen_requests_h({ model, outputDirectory }: { model: MetaModel; o emit(`class ${responseTypeName} final : public LSPResponse {`); emit(`public:`); emit(` using LSPResponse::LSPResponse;`); + emit(` using LSPResponse::id;`); + emit(` using Result = ${resultType};`); emit(); - emit(` [[nodiscard]] auto id() const -> std::variant;`); - emit(` auto id(long id) -> ${responseTypeName}&;`); - emit(` auto id(std::string id) -> ${responseTypeName}&;`); + emit(` auto id(std::variant id) -> ${responseTypeName}&;`); emit(); emit(` [[nodiscard]] auto result() const -> ${resultType};`); emit(); @@ -105,7 +105,7 @@ export function gen_requests_h({ model, outputDirectory }: { model: MetaModel; o emit(); emit(`template `); - emit(`auto visit(Visitor&& visitor, const LSPRequest& request) -> void {`); + emit(`auto visit(Visitor&& visitor, LSPRequest request) -> void {`); emit(`#define PROCESS_REQUEST_TYPE(NAME, METHOD) \\`); emit(` if (request.method() == METHOD) \\`); emit(` return visitor(static_cast(request));`); diff --git a/packages/cxx-gen-lsp/src/gen_types_cc.ts b/packages/cxx-gen-lsp/src/gen_types_cc.ts index 507ac91f..2dac5398 100644 --- a/packages/cxx-gen-lsp/src/gen_types_cc.ts +++ b/packages/cxx-gen-lsp/src/gen_types_cc.ts @@ -32,7 +32,7 @@ import { import { writeFileSync } from "node:fs"; import { copyrightHeader } from "./copyrightHeader.js"; -class TypeGenerator { +export class TypeGenerator { readonly structByName: Map; readonly enumByName: Map; readonly typeAliasByName: Map; @@ -202,7 +202,9 @@ class TypeGenerator { switch (property.type.name) { case "null": - throw new Error(`Unexpected null type`); + this.emit(`assert(value.is_null());`); + this.emit(`return nullptr;`); + return true; case "string": this.emit(`if (value.is_null()) value = "";`); diff --git a/src/frontend/cxx/lsp_server.cc b/src/frontend/cxx/lsp_server.cc index f632b8e0..4821380a 100644 --- a/src/frontend/cxx/lsp_server.cc +++ b/src/frontend/cxx/lsp_server.cc @@ -175,7 +175,7 @@ auto Server::readHeaders(std::istream& input) return headers; } -void Server::sendToClient(const json& message) { +void Server::sendMessage(const json& message) { #ifndef CXX_NO_THREADS auto locker = std::unique_lock(outputMutex_); #endif @@ -190,29 +190,16 @@ void Server::sendToClient(const json& message) { output.flush(); } -void Server::sendToClient(const LSPObject& result, - std::optional> id) { - auto response = json::object(); - response["jsonrpc"] = "2.0"; - - if (id.has_value()) { - if (std::holds_alternative(id.value())) { - response["id"] = std::get(id.value()); - } else { - response["id"] = std::get(id.value()); - } - } - - response["result"] = result; - - sendToClient(response); +void Server::sendToClient(LSPResponse response) { + json& message = response.get(); + message["jsonrpc"] = "2.0"; + sendMessage(message); } -void Server::sendNotification(const LSPRequest& notification) { +void Server::sendToClient(LSPRequest notification) { json response = notification; response["jsonrpc"] = "2.0"; - - sendToClient(response); + sendMessage(response); } void Server::logTrace(std::string message, std::optional verbose) { @@ -227,7 +214,7 @@ void Server::logTrace(std::string message, std::optional verbose) { if (verbose.has_value()) { logTrace.params().verbose(std::move(*verbose)); } - sendNotification(logTrace); + sendToClient(logTrace); }); } @@ -323,42 +310,48 @@ void Server::parse(const std::string& uri) { publishDiagnostics.params().diagnostics(doc->diagnostics()); publishDiagnostics.params().version(version); - sendNotification(publishDiagnostics); + sendToClient(publishDiagnostics); }); }); } -void Server::operator()(const InitializeRequest& request) { +void Server::operator()(InitializeRequest request) { logTrace(std::format("Did receive InitializeRequest")); withUnsafeJson([&](json storage) { - InitializeResult result(storage); - result.serverInfo().name("cxx-lsp").version(CXX_VERSION); - auto capabilities = result.capabilities(); + InitializeResponse response{storage}; + std::cerr << std::format("initializing response to {}\n", + request.get().dump()); + response.id(*request.id()); + auto capabilities = response.result().capabilities(); + response.result().serverInfo().name("cxx-lsp").version( + CXX_VERSION); capabilities.textDocumentSync(TextDocumentSyncKind::kIncremental); - sendToClient(result, request.id()); + sendToClient(response); }); } -void Server::operator()(const InitializedNotification& notification) { +void Server::operator()(InitializedNotification notification) { logTrace(std::format("Did receive InitializedNotification")); } -void Server::operator()(const ShutdownRequest& request) { +void Server::operator()(ShutdownRequest request) { logTrace(std::format("Did receive ShutdownRequest")); withUnsafeJson([&](json storage) { - LSPObject result(storage); - sendToClient(result, request.id()); + LSPResponse response(storage); + response.id(request.id()); + response.get().emplace("result", nullptr); + sendToClient(response); }); } -void Server::operator()(const ExitNotification& notification) { +void Server::operator()(ExitNotification notification) { logTrace(std::format("Did receive ExitNotification")); done_ = true; } -void Server::operator()(const DidOpenTextDocumentNotification& notification) { +void Server::operator()(DidOpenTextDocumentNotification notification) { logTrace(std::format("Did receive DidOpenTextDocumentNotification")); auto textDocument = notification.params().textDocument(); @@ -373,14 +366,14 @@ void Server::operator()(const DidOpenTextDocumentNotification& notification) { parse(textDocument.uri()); } -void Server::operator()(const DidCloseTextDocumentNotification& notification) { +void Server::operator()(DidCloseTextDocumentNotification notification) { logTrace(std::format("Did receive DidCloseTextDocumentNotification")); const auto uri = notification.params().textDocument().uri(); documents_.erase(uri); } -void Server::operator()(const DidChangeTextDocumentNotification& notification) { +void Server::operator()(DidChangeTextDocumentNotification notification) { logTrace(std::format("Did receive DidChangeTextDocumentNotification")); const auto textDocument = notification.params().textDocument(); @@ -431,34 +424,50 @@ auto Server::latestDocument(const std::string& uri) return documents_[uri]; } -void Server::operator()(const DocumentDiagnosticRequest& request) { +void Server::operator()(DocumentDiagnosticRequest request) { logTrace(std::format("Did receive DocumentDiagnosticRequest")); } -void Server::operator()(const CancelNotification& notification) { - auto id = notification.params().id(); - logTrace( - std::format("Did receive CancelNotification for request with id {}", id)); +void Server::operator()(CancelNotification notification) { + const auto id = notification.params().id(); + + if (std::holds_alternative(id)) { + logTrace( + std::format("Did receive CancelNotification for request with id {}", + std::get(id))); + } else { + logTrace( + std::format("Did receive CancelNotification for request with id {}", + std::get(id))); + } } -void Server::operator()(const SetTraceNotification& notification) { +void Server::operator()(SetTraceNotification notification) { logTrace(std::format("Did receive SetTraceNotification")); trace_ = notification.params().value(); -} -void Server::operator()(const LSPRequest& request) { - logTrace(std::format("Did receive LSPRequest {}", request.method())); + if (trace_ != TraceValue::kOff) { + logTrace("Trace level set to {}\n", to_string(trace_)); + return; + } +} +void Server::operator()(LSPRequest request) { if (!request.id().has_value()) { // nothing to do for notifications + logTrace(std::format("Did receive notification {}", request.method())); return; } + logTrace(std::format("Did receive request {}", request.method())); + // send an empty response. withUnsafeJson([&](json storage) { - LSPObject result(storage); - sendToClient(result, request.id()); + LSPResponse response(storage); + response.id(request.id()); + request.get().emplace("result", nullptr); + sendToClient(response); }); } diff --git a/src/frontend/cxx/lsp_server.h b/src/frontend/cxx/lsp_server.h index 8e07d51e..bdcf51e1 100644 --- a/src/frontend/cxx/lsp_server.h +++ b/src/frontend/cxx/lsp_server.h @@ -46,22 +46,22 @@ class Server { auto start() -> int; - void operator()(const InitializeRequest& request); - void operator()(const InitializedNotification& notification); + void operator()(InitializeRequest request); + void operator()(InitializedNotification notification); - void operator()(const ShutdownRequest& request); - void operator()(const ExitNotification& notification); + void operator()(ShutdownRequest request); + void operator()(ExitNotification notification); - void operator()(const DidOpenTextDocumentNotification& notification); - void operator()(const DidCloseTextDocumentNotification& notification); - void operator()(const DidChangeTextDocumentNotification& notification); + void operator()(DidOpenTextDocumentNotification notification); + void operator()(DidCloseTextDocumentNotification notification); + void operator()(DidChangeTextDocumentNotification notification); - void operator()(const DocumentDiagnosticRequest& request); + void operator()(DocumentDiagnosticRequest request); - void operator()(const SetTraceNotification& notification); + void operator()(SetTraceNotification notification); - void operator()(const CancelNotification& notification); - void operator()(const LSPRequest& request); + void operator()(CancelNotification notification); + void operator()(LSPRequest request); private: void startWorkersIfNeeded(); @@ -76,13 +76,9 @@ class Server { [[nodiscard]] auto nextRequest() -> std::optional; - void sendNotification(const LSPRequest& notification); - - void sendToClient(const json& message); - - void sendToClient( - const LSPObject& result, - std::optional> id = std::nullopt); + void sendToClient(LSPRequest notification); + void sendToClient(LSPResponse response); + void sendMessage(const json& message); void logTrace(std::string message, std::optional verbose = {}); diff --git a/src/lsp/cxx/lsp/fwd.h b/src/lsp/cxx/lsp/fwd.h index 36a9aa6f..17484bef 100644 --- a/src/lsp/cxx/lsp/fwd.h +++ b/src/lsp/cxx/lsp/fwd.h @@ -637,8 +637,12 @@ class LSPObject { explicit LSPObject(json& repr) : repr_(&repr) {} [[nodiscard]] explicit operator bool() const { return repr_ != nullptr; } + [[nodiscard]] operator const json&() const { return *repr_; } - [[nodiscard]] auto get() const -> json& { return *repr_; } + [[nodiscard]] operator json&() { return *repr_; } + + [[nodiscard]] auto get() const -> const json& { return *repr_; } + [[nodiscard]] auto get() -> json& { return *repr_; } protected: json* repr_{nullptr}; @@ -650,12 +654,18 @@ class LSPRequest : public LSPObject { [[nodiscard]] auto id() const -> std::optional>; + auto id(std::optional>) -> LSPRequest&; + [[nodiscard]] auto method() const -> std::string; }; class LSPResponse : public LSPObject { public: using LSPObject::LSPObject; + + [[nodiscard]] auto id() const + -> std::optional>; + auto id(std::optional>) -> LSPResponse&; }; template @@ -911,7 +921,7 @@ using WorkspaceDocumentDiagnosticReport = using ChangeAnnotationIdentifier = std::string; -using ProgressToken = std::variant; +using ProgressToken = std::variant; using DocumentSelector = Vector; diff --git a/src/lsp/cxx/lsp/requests.cc b/src/lsp/cxx/lsp/requests.cc index 50371447..2d817b75 100644 --- a/src/lsp/cxx/lsp/requests.cc +++ b/src/lsp/cxx/lsp/requests.cc @@ -31,8 +31,43 @@ auto LSPRequest::id() const -> std::optional> { return id.get(); } +auto LSPRequest::id(std::optional> id) + -> LSPRequest& { + if (!id.has_value()) { + repr_->erase("id"); + return *this; + } + if (std::holds_alternative(*id)) { + (*repr_)["id"] = std::get(*id); + } else { + (*repr_)["id"] = std::get(*id); + } + return *this; +} + auto LSPRequest::method() const -> std::string { return repr_->at("method"); } +auto LSPResponse::id() const -> std::optional> { + if (!repr_->contains("id")) return std::nullopt; + const auto& id = repr_->at("id"); + if (id.is_string()) return id.get(); + return id.get(); +} + +auto LSPResponse::id(std::optional> id) + -> LSPResponse& { + if (!id.has_value()) { + repr_->erase("id"); + return *this; + } + if (std::holds_alternative(*id)) { + (*repr_)["id"] = std::get(*id); + } else { + (*repr_)["id"] = std::get(*id); + } + return *this; +} + auto ImplementationRequest::method(std::string method) -> ImplementationRequest& { (*repr_)["method"] = std::move(method); @@ -41,12 +76,7 @@ auto ImplementationRequest::method(std::string method) auto ImplementationRequest::id(std::variant id) -> ImplementationRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ImplementationRequest::params() const -> ImplementationParams { @@ -60,26 +90,20 @@ auto ImplementationRequest::params(ImplementationParams params) return *this; } -auto ImplementationResponse::id(long id) -> ImplementationResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto ImplementationResponse::id(std::string id) -> ImplementationResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto ImplementationResponse::id(std::variant id) + -> ImplementationResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto ImplementationResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("ImplementationResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto ImplementationResponse::result( - std::variant, std::nullptr_t> result) - -> ImplementationResponse& { - lsp_runtime_error("ImplementationResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto TypeDefinitionRequest::method(std::string method) @@ -90,12 +114,7 @@ auto TypeDefinitionRequest::method(std::string method) auto TypeDefinitionRequest::id(std::variant id) -> TypeDefinitionRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto TypeDefinitionRequest::params() const -> TypeDefinitionParams { @@ -109,26 +128,20 @@ auto TypeDefinitionRequest::params(TypeDefinitionParams params) return *this; } -auto TypeDefinitionResponse::id(long id) -> TypeDefinitionResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto TypeDefinitionResponse::id(std::string id) -> TypeDefinitionResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto TypeDefinitionResponse::id(std::variant id) + -> TypeDefinitionResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto TypeDefinitionResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("TypeDefinitionResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto TypeDefinitionResponse::result( - std::variant, std::nullptr_t> result) - -> TypeDefinitionResponse& { - lsp_runtime_error("TypeDefinitionResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto WorkspaceFoldersRequest::method(std::string method) @@ -139,34 +152,23 @@ auto WorkspaceFoldersRequest::method(std::string method) auto WorkspaceFoldersRequest::id(std::variant id) -> WorkspaceFoldersRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } -auto WorkspaceFoldersResponse::id(long id) -> WorkspaceFoldersResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WorkspaceFoldersResponse::id(std::string id) -> WorkspaceFoldersResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto WorkspaceFoldersResponse::id(std::variant id) + -> WorkspaceFoldersResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto WorkspaceFoldersResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("WorkspaceFoldersResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto WorkspaceFoldersResponse::result( - std::variant, std::nullptr_t> result) - -> WorkspaceFoldersResponse& { - lsp_runtime_error("WorkspaceFoldersResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto ConfigurationRequest::method(std::string method) -> ConfigurationRequest& { @@ -176,12 +178,7 @@ auto ConfigurationRequest::method(std::string method) -> ConfigurationRequest& { auto ConfigurationRequest::id(std::variant id) -> ConfigurationRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ConfigurationRequest::params() const -> ConfigurationParams { @@ -195,24 +192,16 @@ auto ConfigurationRequest::params(ConfigurationParams params) return *this; } -auto ConfigurationResponse::id(long id) -> ConfigurationResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto ConfigurationResponse::id(std::string id) -> ConfigurationResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto ConfigurationResponse::id(std::variant id) + -> ConfigurationResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto ConfigurationResponse::result() const -> Vector { - lsp_runtime_error("ConfigurationResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto ConfigurationResponse::result(Vector result) - -> ConfigurationResponse& { - lsp_runtime_error("ConfigurationResponse::result() - not implemented yet"); - return *this; + if (value.is_null()) value = json::array(); + return Vector(value); } auto DocumentColorRequest::method(std::string method) -> DocumentColorRequest& { @@ -222,12 +211,7 @@ auto DocumentColorRequest::method(std::string method) -> DocumentColorRequest& { auto DocumentColorRequest::id(std::variant id) -> DocumentColorRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DocumentColorRequest::params() const -> DocumentColorParams { @@ -241,24 +225,16 @@ auto DocumentColorRequest::params(DocumentColorParams params) return *this; } -auto DocumentColorResponse::id(long id) -> DocumentColorResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentColorResponse::id(std::string id) -> DocumentColorResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto DocumentColorResponse::id(std::variant id) + -> DocumentColorResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto DocumentColorResponse::result() const -> Vector { - lsp_runtime_error("DocumentColorResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentColorResponse::result(Vector result) - -> DocumentColorResponse& { - lsp_runtime_error("DocumentColorResponse::result() - not implemented yet"); - return *this; + if (value.is_null()) value = json::array(); + return Vector(value); } auto ColorPresentationRequest::method(std::string method) @@ -269,12 +245,7 @@ auto ColorPresentationRequest::method(std::string method) auto ColorPresentationRequest::id(std::variant id) -> ColorPresentationRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ColorPresentationRequest::params() const -> ColorPresentationParams { @@ -288,27 +259,17 @@ auto ColorPresentationRequest::params(ColorPresentationParams params) return *this; } -auto ColorPresentationResponse::id(long id) -> ColorPresentationResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto ColorPresentationResponse::id(std::string id) +auto ColorPresentationResponse::id(std::variant id) -> ColorPresentationResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto ColorPresentationResponse::result() const -> Vector { - lsp_runtime_error( - "ColorPresentationResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto ColorPresentationResponse::result(Vector result) - -> ColorPresentationResponse& { - lsp_runtime_error( - "ColorPresentationResponse::result() - not implemented yet"); - return *this; + if (value.is_null()) value = json::array(); + return Vector(value); } auto FoldingRangeRequest::method(std::string method) -> FoldingRangeRequest& { @@ -318,12 +279,7 @@ auto FoldingRangeRequest::method(std::string method) -> FoldingRangeRequest& { auto FoldingRangeRequest::id(std::variant id) -> FoldingRangeRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto FoldingRangeRequest::params() const -> FoldingRangeParams { @@ -337,26 +293,20 @@ auto FoldingRangeRequest::params(FoldingRangeParams params) return *this; } -auto FoldingRangeResponse::id(long id) -> FoldingRangeResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto FoldingRangeResponse::id(std::string id) -> FoldingRangeResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto FoldingRangeResponse::id(std::variant id) + -> FoldingRangeResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto FoldingRangeResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("FoldingRangeResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto FoldingRangeResponse::result( - std::variant, std::nullptr_t> result) - -> FoldingRangeResponse& { - lsp_runtime_error("FoldingRangeResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto FoldingRangeRefreshRequest::method(std::string method) @@ -367,33 +317,21 @@ auto FoldingRangeRefreshRequest::method(std::string method) auto FoldingRangeRefreshRequest::id(std::variant id) -> FoldingRangeRefreshRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; -} - -auto FoldingRangeRefreshResponse::id(long id) -> FoldingRangeRefreshResponse& { - (*repr_)["id"] = id; - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } -auto FoldingRangeRefreshResponse::id(std::string id) +auto FoldingRangeRefreshResponse::id(std::variant id) -> FoldingRangeRefreshResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto FoldingRangeRefreshResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto FoldingRangeRefreshResponse::result(std::nullptr_t result) - -> FoldingRangeRefreshResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto DeclarationRequest::method(std::string method) -> DeclarationRequest& { @@ -403,12 +341,7 @@ auto DeclarationRequest::method(std::string method) -> DeclarationRequest& { auto DeclarationRequest::id(std::variant id) -> DeclarationRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DeclarationRequest::params() const -> DeclarationParams { @@ -422,26 +355,20 @@ auto DeclarationRequest::params(DeclarationParams params) return *this; } -auto DeclarationResponse::id(long id) -> DeclarationResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DeclarationResponse::id(std::string id) -> DeclarationResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto DeclarationResponse::id(std::variant id) + -> DeclarationResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto DeclarationResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("DeclarationResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DeclarationResponse::result( - std::variant, std::nullptr_t> result) - -> DeclarationResponse& { - lsp_runtime_error("DeclarationResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto SelectionRangeRequest::method(std::string method) @@ -452,12 +379,7 @@ auto SelectionRangeRequest::method(std::string method) auto SelectionRangeRequest::id(std::variant id) -> SelectionRangeRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto SelectionRangeRequest::params() const -> SelectionRangeParams { @@ -471,26 +393,20 @@ auto SelectionRangeRequest::params(SelectionRangeParams params) return *this; } -auto SelectionRangeResponse::id(long id) -> SelectionRangeResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto SelectionRangeResponse::id(std::string id) -> SelectionRangeResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto SelectionRangeResponse::id(std::variant id) + -> SelectionRangeResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto SelectionRangeResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("SelectionRangeResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto SelectionRangeResponse::result( - std::variant, std::nullptr_t> result) - -> SelectionRangeResponse& { - lsp_runtime_error("SelectionRangeResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto WorkDoneProgressCreateRequest::method(std::string method) @@ -501,12 +417,8 @@ auto WorkDoneProgressCreateRequest::method(std::string method) auto WorkDoneProgressCreateRequest::id(std::variant id) -> WorkDoneProgressCreateRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto WorkDoneProgressCreateRequest::params() const @@ -521,26 +433,17 @@ auto WorkDoneProgressCreateRequest::params(WorkDoneProgressCreateParams params) return *this; } -auto WorkDoneProgressCreateResponse::id(long id) - -> WorkDoneProgressCreateResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WorkDoneProgressCreateResponse::id(std::string id) +auto WorkDoneProgressCreateResponse::id(std::variant id) -> WorkDoneProgressCreateResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto WorkDoneProgressCreateResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto WorkDoneProgressCreateResponse::result(std::nullptr_t result) - -> WorkDoneProgressCreateResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto CallHierarchyPrepareRequest::method(std::string method) @@ -551,12 +454,8 @@ auto CallHierarchyPrepareRequest::method(std::string method) auto CallHierarchyPrepareRequest::id(std::variant id) -> CallHierarchyPrepareRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto CallHierarchyPrepareRequest::params() const -> CallHierarchyPrepareParams { @@ -570,30 +469,21 @@ auto CallHierarchyPrepareRequest::params(CallHierarchyPrepareParams params) return *this; } -auto CallHierarchyPrepareResponse::id(long id) - -> CallHierarchyPrepareResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CallHierarchyPrepareResponse::id(std::string id) +auto CallHierarchyPrepareResponse::id(std::variant id) -> CallHierarchyPrepareResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto CallHierarchyPrepareResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "CallHierarchyPrepareResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto CallHierarchyPrepareResponse::result( - std::variant, std::nullptr_t> result) - -> CallHierarchyPrepareResponse& { - lsp_runtime_error( - "CallHierarchyPrepareResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto CallHierarchyIncomingCallsRequest::method(std::string method) @@ -604,12 +494,8 @@ auto CallHierarchyIncomingCallsRequest::method(std::string method) auto CallHierarchyIncomingCallsRequest::id(std::variant id) -> CallHierarchyIncomingCallsRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto CallHierarchyIncomingCallsRequest::params() const @@ -625,30 +511,21 @@ auto CallHierarchyIncomingCallsRequest::params( return *this; } -auto CallHierarchyIncomingCallsResponse::id(long id) +auto CallHierarchyIncomingCallsResponse::id(std::variant id) -> CallHierarchyIncomingCallsResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CallHierarchyIncomingCallsResponse::id(std::string id) - -> CallHierarchyIncomingCallsResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto CallHierarchyIncomingCallsResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "CallHierarchyIncomingCallsResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto CallHierarchyIncomingCallsResponse::result( - std::variant, std::nullptr_t> result) - -> CallHierarchyIncomingCallsResponse& { - lsp_runtime_error( - "CallHierarchyIncomingCallsResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto CallHierarchyOutgoingCallsRequest::method(std::string method) @@ -659,12 +536,8 @@ auto CallHierarchyOutgoingCallsRequest::method(std::string method) auto CallHierarchyOutgoingCallsRequest::id(std::variant id) -> CallHierarchyOutgoingCallsRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto CallHierarchyOutgoingCallsRequest::params() const @@ -680,30 +553,21 @@ auto CallHierarchyOutgoingCallsRequest::params( return *this; } -auto CallHierarchyOutgoingCallsResponse::id(long id) +auto CallHierarchyOutgoingCallsResponse::id(std::variant id) -> CallHierarchyOutgoingCallsResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CallHierarchyOutgoingCallsResponse::id(std::string id) - -> CallHierarchyOutgoingCallsResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto CallHierarchyOutgoingCallsResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "CallHierarchyOutgoingCallsResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto CallHierarchyOutgoingCallsResponse::result( - std::variant, std::nullptr_t> result) - -> CallHierarchyOutgoingCallsResponse& { - lsp_runtime_error( - "CallHierarchyOutgoingCallsResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto SemanticTokensRequest::method(std::string method) @@ -714,12 +578,7 @@ auto SemanticTokensRequest::method(std::string method) auto SemanticTokensRequest::id(std::variant id) -> SemanticTokensRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto SemanticTokensRequest::params() const -> SemanticTokensParams { @@ -733,26 +592,20 @@ auto SemanticTokensRequest::params(SemanticTokensParams params) return *this; } -auto SemanticTokensResponse::id(long id) -> SemanticTokensResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto SemanticTokensResponse::id(std::string id) -> SemanticTokensResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto SemanticTokensResponse::id(std::variant id) + -> SemanticTokensResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto SemanticTokensResponse::result() const -> std::variant { - lsp_runtime_error("SemanticTokensResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto SemanticTokensResponse::result( - std::variant result) - -> SemanticTokensResponse& { - lsp_runtime_error("SemanticTokensResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto SemanticTokensDeltaRequest::method(std::string method) @@ -763,12 +616,8 @@ auto SemanticTokensDeltaRequest::method(std::string method) auto SemanticTokensDeltaRequest::id(std::variant id) -> SemanticTokensDeltaRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto SemanticTokensDeltaRequest::params() const -> SemanticTokensDeltaParams { @@ -782,29 +631,21 @@ auto SemanticTokensDeltaRequest::params(SemanticTokensDeltaParams params) return *this; } -auto SemanticTokensDeltaResponse::id(long id) -> SemanticTokensDeltaResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto SemanticTokensDeltaResponse::id(std::string id) +auto SemanticTokensDeltaResponse::id(std::variant id) -> SemanticTokensDeltaResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto SemanticTokensDeltaResponse::result() const -> std::variant { - lsp_runtime_error( - "SemanticTokensDeltaResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto SemanticTokensDeltaResponse::result( - std::variant result) - -> SemanticTokensDeltaResponse& { - lsp_runtime_error( - "SemanticTokensDeltaResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto SemanticTokensRangeRequest::method(std::string method) @@ -815,12 +656,8 @@ auto SemanticTokensRangeRequest::method(std::string method) auto SemanticTokensRangeRequest::id(std::variant id) -> SemanticTokensRangeRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto SemanticTokensRangeRequest::params() const -> SemanticTokensRangeParams { @@ -834,29 +671,21 @@ auto SemanticTokensRangeRequest::params(SemanticTokensRangeParams params) return *this; } -auto SemanticTokensRangeResponse::id(long id) -> SemanticTokensRangeResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto SemanticTokensRangeResponse::id(std::string id) +auto SemanticTokensRangeResponse::id(std::variant id) -> SemanticTokensRangeResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto SemanticTokensRangeResponse::result() const -> std::variant { - lsp_runtime_error( - "SemanticTokensRangeResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto SemanticTokensRangeResponse::result( - std::variant result) - -> SemanticTokensRangeResponse& { - lsp_runtime_error( - "SemanticTokensRangeResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto SemanticTokensRefreshRequest::method(std::string method) @@ -867,34 +696,21 @@ auto SemanticTokensRefreshRequest::method(std::string method) auto SemanticTokensRefreshRequest::id(std::variant id) -> SemanticTokensRefreshRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } -auto SemanticTokensRefreshResponse::id(long id) +auto SemanticTokensRefreshResponse::id(std::variant id) -> SemanticTokensRefreshResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto SemanticTokensRefreshResponse::id(std::string id) - -> SemanticTokensRefreshResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto SemanticTokensRefreshResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto SemanticTokensRefreshResponse::result(std::nullptr_t result) - -> SemanticTokensRefreshResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto ShowDocumentRequest::method(std::string method) -> ShowDocumentRequest& { @@ -904,12 +720,7 @@ auto ShowDocumentRequest::method(std::string method) -> ShowDocumentRequest& { auto ShowDocumentRequest::id(std::variant id) -> ShowDocumentRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ShowDocumentRequest::params() const -> ShowDocumentParams { @@ -923,25 +734,15 @@ auto ShowDocumentRequest::params(ShowDocumentParams params) return *this; } -auto ShowDocumentResponse::id(long id) -> ShowDocumentResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto ShowDocumentResponse::id(std::string id) -> ShowDocumentResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto ShowDocumentResponse::id(std::variant id) + -> ShowDocumentResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto ShowDocumentResponse::result() const -> ShowDocumentResult { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return ShowDocumentResult(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto ShowDocumentResponse::result(ShowDocumentResult result) - -> ShowDocumentResponse& { - lsp_runtime_error("ShowDocumentResponse::result() - not implemented yet"); - return *this; + return ShowDocumentResult(value); } auto LinkedEditingRangeRequest::method(std::string method) @@ -952,12 +753,7 @@ auto LinkedEditingRangeRequest::method(std::string method) auto LinkedEditingRangeRequest::id(std::variant id) -> LinkedEditingRangeRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto LinkedEditingRangeRequest::params() const -> LinkedEditingRangeParams { @@ -971,29 +767,21 @@ auto LinkedEditingRangeRequest::params(LinkedEditingRangeParams params) return *this; } -auto LinkedEditingRangeResponse::id(long id) -> LinkedEditingRangeResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto LinkedEditingRangeResponse::id(std::string id) +auto LinkedEditingRangeResponse::id(std::variant id) -> LinkedEditingRangeResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto LinkedEditingRangeResponse::result() const -> std::variant { - lsp_runtime_error( - "LinkedEditingRangeResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto LinkedEditingRangeResponse::result( - std::variant result) - -> LinkedEditingRangeResponse& { - lsp_runtime_error( - "LinkedEditingRangeResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto WillCreateFilesRequest::method(std::string method) @@ -1004,12 +792,7 @@ auto WillCreateFilesRequest::method(std::string method) auto WillCreateFilesRequest::id(std::variant id) -> WillCreateFilesRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto WillCreateFilesRequest::params() const -> CreateFilesParams { @@ -1023,26 +806,20 @@ auto WillCreateFilesRequest::params(CreateFilesParams params) return *this; } -auto WillCreateFilesResponse::id(long id) -> WillCreateFilesResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WillCreateFilesResponse::id(std::string id) -> WillCreateFilesResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto WillCreateFilesResponse::id(std::variant id) + -> WillCreateFilesResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto WillCreateFilesResponse::result() const -> std::variant { - lsp_runtime_error("WillCreateFilesResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto WillCreateFilesResponse::result( - std::variant result) - -> WillCreateFilesResponse& { - lsp_runtime_error("WillCreateFilesResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto WillRenameFilesRequest::method(std::string method) @@ -1053,12 +830,7 @@ auto WillRenameFilesRequest::method(std::string method) auto WillRenameFilesRequest::id(std::variant id) -> WillRenameFilesRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto WillRenameFilesRequest::params() const -> RenameFilesParams { @@ -1072,26 +844,20 @@ auto WillRenameFilesRequest::params(RenameFilesParams params) return *this; } -auto WillRenameFilesResponse::id(long id) -> WillRenameFilesResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WillRenameFilesResponse::id(std::string id) -> WillRenameFilesResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto WillRenameFilesResponse::id(std::variant id) + -> WillRenameFilesResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto WillRenameFilesResponse::result() const -> std::variant { - lsp_runtime_error("WillRenameFilesResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto WillRenameFilesResponse::result( - std::variant result) - -> WillRenameFilesResponse& { - lsp_runtime_error("WillRenameFilesResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto WillDeleteFilesRequest::method(std::string method) @@ -1102,12 +868,7 @@ auto WillDeleteFilesRequest::method(std::string method) auto WillDeleteFilesRequest::id(std::variant id) -> WillDeleteFilesRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto WillDeleteFilesRequest::params() const -> DeleteFilesParams { @@ -1121,26 +882,20 @@ auto WillDeleteFilesRequest::params(DeleteFilesParams params) return *this; } -auto WillDeleteFilesResponse::id(long id) -> WillDeleteFilesResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WillDeleteFilesResponse::id(std::string id) -> WillDeleteFilesResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto WillDeleteFilesResponse::id(std::variant id) + -> WillDeleteFilesResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto WillDeleteFilesResponse::result() const -> std::variant { - lsp_runtime_error("WillDeleteFilesResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto WillDeleteFilesResponse::result( - std::variant result) - -> WillDeleteFilesResponse& { - lsp_runtime_error("WillDeleteFilesResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto MonikerRequest::method(std::string method) -> MonikerRequest& { @@ -1149,12 +904,7 @@ auto MonikerRequest::method(std::string method) -> MonikerRequest& { } auto MonikerRequest::id(std::variant id) -> MonikerRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto MonikerRequest::params() const -> MonikerParams { @@ -1167,25 +917,20 @@ auto MonikerRequest::params(MonikerParams params) -> MonikerRequest& { return *this; } -auto MonikerResponse::id(long id) -> MonikerResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto MonikerResponse::id(std::string id) -> MonikerResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto MonikerResponse::id(std::variant id) + -> MonikerResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto MonikerResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("MonikerResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto MonikerResponse::result( - std::variant, std::nullptr_t> result) -> MonikerResponse& { - lsp_runtime_error("MonikerResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto TypeHierarchyPrepareRequest::method(std::string method) @@ -1196,12 +941,8 @@ auto TypeHierarchyPrepareRequest::method(std::string method) auto TypeHierarchyPrepareRequest::id(std::variant id) -> TypeHierarchyPrepareRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto TypeHierarchyPrepareRequest::params() const -> TypeHierarchyPrepareParams { @@ -1215,30 +956,21 @@ auto TypeHierarchyPrepareRequest::params(TypeHierarchyPrepareParams params) return *this; } -auto TypeHierarchyPrepareResponse::id(long id) +auto TypeHierarchyPrepareResponse::id(std::variant id) -> TypeHierarchyPrepareResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto TypeHierarchyPrepareResponse::id(std::string id) - -> TypeHierarchyPrepareResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto TypeHierarchyPrepareResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "TypeHierarchyPrepareResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto TypeHierarchyPrepareResponse::result( - std::variant, std::nullptr_t> result) - -> TypeHierarchyPrepareResponse& { - lsp_runtime_error( - "TypeHierarchyPrepareResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto TypeHierarchySupertypesRequest::method(std::string method) @@ -1249,12 +981,8 @@ auto TypeHierarchySupertypesRequest::method(std::string method) auto TypeHierarchySupertypesRequest::id(std::variant id) -> TypeHierarchySupertypesRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto TypeHierarchySupertypesRequest::params() const @@ -1269,30 +997,21 @@ auto TypeHierarchySupertypesRequest::params( return *this; } -auto TypeHierarchySupertypesResponse::id(long id) +auto TypeHierarchySupertypesResponse::id(std::variant id) -> TypeHierarchySupertypesResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto TypeHierarchySupertypesResponse::id(std::string id) - -> TypeHierarchySupertypesResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto TypeHierarchySupertypesResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "TypeHierarchySupertypesResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto TypeHierarchySupertypesResponse::result( - std::variant, std::nullptr_t> result) - -> TypeHierarchySupertypesResponse& { - lsp_runtime_error( - "TypeHierarchySupertypesResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto TypeHierarchySubtypesRequest::method(std::string method) @@ -1303,12 +1022,8 @@ auto TypeHierarchySubtypesRequest::method(std::string method) auto TypeHierarchySubtypesRequest::id(std::variant id) -> TypeHierarchySubtypesRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto TypeHierarchySubtypesRequest::params() const @@ -1323,30 +1038,21 @@ auto TypeHierarchySubtypesRequest::params(TypeHierarchySubtypesParams params) return *this; } -auto TypeHierarchySubtypesResponse::id(long id) +auto TypeHierarchySubtypesResponse::id(std::variant id) -> TypeHierarchySubtypesResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto TypeHierarchySubtypesResponse::id(std::string id) - -> TypeHierarchySubtypesResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto TypeHierarchySubtypesResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "TypeHierarchySubtypesResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto TypeHierarchySubtypesResponse::result( - std::variant, std::nullptr_t> result) - -> TypeHierarchySubtypesResponse& { - lsp_runtime_error( - "TypeHierarchySubtypesResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto InlineValueRequest::method(std::string method) -> InlineValueRequest& { @@ -1356,12 +1062,7 @@ auto InlineValueRequest::method(std::string method) -> InlineValueRequest& { auto InlineValueRequest::id(std::variant id) -> InlineValueRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto InlineValueRequest::params() const -> InlineValueParams { @@ -1375,26 +1076,20 @@ auto InlineValueRequest::params(InlineValueParams params) return *this; } -auto InlineValueResponse::id(long id) -> InlineValueResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto InlineValueResponse::id(std::string id) -> InlineValueResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto InlineValueResponse::id(std::variant id) + -> InlineValueResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto InlineValueResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("InlineValueResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto InlineValueResponse::result( - std::variant, std::nullptr_t> result) - -> InlineValueResponse& { - lsp_runtime_error("InlineValueResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto InlineValueRefreshRequest::method(std::string method) @@ -1405,33 +1100,20 @@ auto InlineValueRefreshRequest::method(std::string method) auto InlineValueRefreshRequest::id(std::variant id) -> InlineValueRefreshRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; -} - -auto InlineValueRefreshResponse::id(long id) -> InlineValueRefreshResponse& { - (*repr_)["id"] = id; - return *this; + return static_cast(LSPRequest::id(std::move(id))); } -auto InlineValueRefreshResponse::id(std::string id) +auto InlineValueRefreshResponse::id(std::variant id) -> InlineValueRefreshResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto InlineValueRefreshResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto InlineValueRefreshResponse::result(std::nullptr_t result) - -> InlineValueRefreshResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto InlayHintRequest::method(std::string method) -> InlayHintRequest& { @@ -1441,12 +1123,7 @@ auto InlayHintRequest::method(std::string method) -> InlayHintRequest& { auto InlayHintRequest::id(std::variant id) -> InlayHintRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto InlayHintRequest::params() const -> InlayHintParams { @@ -1459,26 +1136,20 @@ auto InlayHintRequest::params(InlayHintParams params) -> InlayHintRequest& { return *this; } -auto InlayHintResponse::id(long id) -> InlayHintResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto InlayHintResponse::id(std::string id) -> InlayHintResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto InlayHintResponse::id(std::variant id) + -> InlayHintResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto InlayHintResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("InlayHintResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto InlayHintResponse::result( - std::variant, std::nullptr_t> result) - -> InlayHintResponse& { - lsp_runtime_error("InlayHintResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto InlayHintResolveRequest::method(std::string method) @@ -1489,12 +1160,7 @@ auto InlayHintResolveRequest::method(std::string method) auto InlayHintResolveRequest::id(std::variant id) -> InlayHintResolveRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto InlayHintResolveRequest::params() const -> InlayHint { @@ -1508,25 +1174,15 @@ auto InlayHintResolveRequest::params(InlayHint params) return *this; } -auto InlayHintResolveResponse::id(long id) -> InlayHintResolveResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto InlayHintResolveResponse::id(std::string id) -> InlayHintResolveResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto InlayHintResolveResponse::id(std::variant id) + -> InlayHintResolveResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto InlayHintResolveResponse::result() const -> InlayHint { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return InlayHint(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto InlayHintResolveResponse::result(InlayHint result) - -> InlayHintResolveResponse& { - lsp_runtime_error("InlayHintResolveResponse::result() - not implemented yet"); - return *this; + return InlayHint(value); } auto InlayHintRefreshRequest::method(std::string method) @@ -1537,32 +1193,19 @@ auto InlayHintRefreshRequest::method(std::string method) auto InlayHintRefreshRequest::id(std::variant id) -> InlayHintRefreshRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; -} - -auto InlayHintRefreshResponse::id(long id) -> InlayHintRefreshResponse& { - (*repr_)["id"] = id; - return *this; + return static_cast(LSPRequest::id(std::move(id))); } -auto InlayHintRefreshResponse::id(std::string id) -> InlayHintRefreshResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto InlayHintRefreshResponse::id(std::variant id) + -> InlayHintRefreshResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto InlayHintRefreshResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto InlayHintRefreshResponse::result(std::nullptr_t result) - -> InlayHintRefreshResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto DocumentDiagnosticRequest::method(std::string method) @@ -1573,12 +1216,7 @@ auto DocumentDiagnosticRequest::method(std::string method) auto DocumentDiagnosticRequest::id(std::variant id) -> DocumentDiagnosticRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DocumentDiagnosticRequest::params() const -> DocumentDiagnosticParams { @@ -1587,32 +1225,25 @@ auto DocumentDiagnosticRequest::params() const -> DocumentDiagnosticParams { } auto DocumentDiagnosticRequest::params(DocumentDiagnosticParams params) - -> DocumentDiagnosticRequest& { - (*repr_)["params"] = std::move(params); - return *this; -} - -auto DocumentDiagnosticResponse::id(long id) -> DocumentDiagnosticResponse& { - (*repr_)["id"] = id; + -> DocumentDiagnosticRequest& { + (*repr_)["params"] = std::move(params); return *this; } -auto DocumentDiagnosticResponse::id(std::string id) +auto DocumentDiagnosticResponse::id(std::variant id) -> DocumentDiagnosticResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto DocumentDiagnosticResponse::result() const -> DocumentDiagnosticReport { - lsp_runtime_error( - "DocumentDiagnosticResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentDiagnosticResponse::result(DocumentDiagnosticReport result) - -> DocumentDiagnosticResponse& { - lsp_runtime_error( - "DocumentDiagnosticResponse::result() - not implemented yet"); - return *this; + DocumentDiagnosticReport result; + + details::try_emplace(result, value); + + return result; } auto WorkspaceDiagnosticRequest::method(std::string method) @@ -1623,12 +1254,8 @@ auto WorkspaceDiagnosticRequest::method(std::string method) auto WorkspaceDiagnosticRequest::id(std::variant id) -> WorkspaceDiagnosticRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto WorkspaceDiagnosticRequest::params() const -> WorkspaceDiagnosticParams { @@ -1642,27 +1269,16 @@ auto WorkspaceDiagnosticRequest::params(WorkspaceDiagnosticParams params) return *this; } -auto WorkspaceDiagnosticResponse::id(long id) -> WorkspaceDiagnosticResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WorkspaceDiagnosticResponse::id(std::string id) +auto WorkspaceDiagnosticResponse::id(std::variant id) -> WorkspaceDiagnosticResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto WorkspaceDiagnosticResponse::result() const -> WorkspaceDiagnosticReport { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return WorkspaceDiagnosticReport(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto WorkspaceDiagnosticResponse::result(WorkspaceDiagnosticReport result) - -> WorkspaceDiagnosticResponse& { - lsp_runtime_error( - "WorkspaceDiagnosticResponse::result() - not implemented yet"); - return *this; + return WorkspaceDiagnosticReport(value); } auto DiagnosticRefreshRequest::method(std::string method) @@ -1673,33 +1289,20 @@ auto DiagnosticRefreshRequest::method(std::string method) auto DiagnosticRefreshRequest::id(std::variant id) -> DiagnosticRefreshRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; -} - -auto DiagnosticRefreshResponse::id(long id) -> DiagnosticRefreshResponse& { - (*repr_)["id"] = id; - return *this; + return static_cast(LSPRequest::id(std::move(id))); } -auto DiagnosticRefreshResponse::id(std::string id) +auto DiagnosticRefreshResponse::id(std::variant id) -> DiagnosticRefreshResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto DiagnosticRefreshResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto DiagnosticRefreshResponse::result(std::nullptr_t result) - -> DiagnosticRefreshResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto InlineCompletionRequest::method(std::string method) @@ -1710,12 +1313,7 @@ auto InlineCompletionRequest::method(std::string method) auto InlineCompletionRequest::id(std::variant id) -> InlineCompletionRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto InlineCompletionRequest::params() const -> InlineCompletionParams { @@ -1729,28 +1327,23 @@ auto InlineCompletionRequest::params(InlineCompletionParams params) return *this; } -auto InlineCompletionResponse::id(long id) -> InlineCompletionResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto InlineCompletionResponse::id(std::string id) -> InlineCompletionResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto InlineCompletionResponse::id(std::variant id) + -> InlineCompletionResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto InlineCompletionResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("InlineCompletionResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto InlineCompletionResponse::result( - std::variant, - std::nullptr_t> - result) -> InlineCompletionResponse& { - lsp_runtime_error("InlineCompletionResponse::result() - not implemented yet"); - return *this; + std::variant, + std::nullptr_t> + result; + + details::try_emplace(result, value); + + return result; } auto TextDocumentContentRequest::method(std::string method) @@ -1761,12 +1354,8 @@ auto TextDocumentContentRequest::method(std::string method) auto TextDocumentContentRequest::id(std::variant id) -> TextDocumentContentRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto TextDocumentContentRequest::params() const -> TextDocumentContentParams { @@ -1780,27 +1369,16 @@ auto TextDocumentContentRequest::params(TextDocumentContentParams params) return *this; } -auto TextDocumentContentResponse::id(long id) -> TextDocumentContentResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto TextDocumentContentResponse::id(std::string id) +auto TextDocumentContentResponse::id(std::variant id) -> TextDocumentContentResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto TextDocumentContentResponse::result() const -> TextDocumentContentResult { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return TextDocumentContentResult(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto TextDocumentContentResponse::result(TextDocumentContentResult result) - -> TextDocumentContentResponse& { - lsp_runtime_error( - "TextDocumentContentResponse::result() - not implemented yet"); - return *this; + return TextDocumentContentResult(value); } auto TextDocumentContentRefreshRequest::method(std::string method) @@ -1811,12 +1389,8 @@ auto TextDocumentContentRefreshRequest::method(std::string method) auto TextDocumentContentRefreshRequest::id(std::variant id) -> TextDocumentContentRefreshRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto TextDocumentContentRefreshRequest::params() const @@ -1832,26 +1406,17 @@ auto TextDocumentContentRefreshRequest::params( return *this; } -auto TextDocumentContentRefreshResponse::id(long id) - -> TextDocumentContentRefreshResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto TextDocumentContentRefreshResponse::id(std::string id) +auto TextDocumentContentRefreshResponse::id(std::variant id) -> TextDocumentContentRefreshResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto TextDocumentContentRefreshResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto TextDocumentContentRefreshResponse::result(std::nullptr_t result) - -> TextDocumentContentRefreshResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto RegistrationRequest::method(std::string method) -> RegistrationRequest& { @@ -1861,12 +1426,7 @@ auto RegistrationRequest::method(std::string method) -> RegistrationRequest& { auto RegistrationRequest::id(std::variant id) -> RegistrationRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto RegistrationRequest::params() const -> RegistrationParams { @@ -1880,22 +1440,16 @@ auto RegistrationRequest::params(RegistrationParams params) return *this; } -auto RegistrationResponse::id(long id) -> RegistrationResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto RegistrationResponse::id(std::string id) -> RegistrationResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto RegistrationResponse::id(std::variant id) + -> RegistrationResponse& { + return static_cast(LSPResponse::id(std::move(id))); } -auto RegistrationResponse::result() const -> std::nullptr_t { return nullptr; } +auto RegistrationResponse::result() const -> std::nullptr_t { + auto& value = (*repr_)["result"]; -auto RegistrationResponse::result(std::nullptr_t result) - -> RegistrationResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto UnregistrationRequest::method(std::string method) @@ -1906,12 +1460,7 @@ auto UnregistrationRequest::method(std::string method) auto UnregistrationRequest::id(std::variant id) -> UnregistrationRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto UnregistrationRequest::params() const -> UnregistrationParams { @@ -1925,24 +1474,16 @@ auto UnregistrationRequest::params(UnregistrationParams params) return *this; } -auto UnregistrationResponse::id(long id) -> UnregistrationResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto UnregistrationResponse::id(std::string id) -> UnregistrationResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto UnregistrationResponse::id(std::variant id) + -> UnregistrationResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto UnregistrationResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto UnregistrationResponse::result(std::nullptr_t result) - -> UnregistrationResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto InitializeRequest::method(std::string method) -> InitializeRequest& { @@ -1952,12 +1493,7 @@ auto InitializeRequest::method(std::string method) -> InitializeRequest& { auto InitializeRequest::id(std::variant id) -> InitializeRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto InitializeRequest::params() const -> InitializeParams { @@ -1970,25 +1506,15 @@ auto InitializeRequest::params(InitializeParams params) -> InitializeRequest& { return *this; } -auto InitializeResponse::id(long id) -> InitializeResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto InitializeResponse::id(std::string id) -> InitializeResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto InitializeResponse::id(std::variant id) + -> InitializeResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto InitializeResponse::result() const -> InitializeResult { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return InitializeResult(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto InitializeResponse::result(InitializeResult result) - -> InitializeResponse& { - lsp_runtime_error("InitializeResponse::result() - not implemented yet"); - return *this; + return InitializeResult(value); } auto ShutdownRequest::method(std::string method) -> ShutdownRequest& { @@ -1998,29 +1524,19 @@ auto ShutdownRequest::method(std::string method) -> ShutdownRequest& { auto ShutdownRequest::id(std::variant id) -> ShutdownRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; -} - -auto ShutdownResponse::id(long id) -> ShutdownResponse& { - (*repr_)["id"] = id; - return *this; + return static_cast(LSPRequest::id(std::move(id))); } -auto ShutdownResponse::id(std::string id) -> ShutdownResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto ShutdownResponse::id(std::variant id) + -> ShutdownResponse& { + return static_cast(LSPResponse::id(std::move(id))); } -auto ShutdownResponse::result() const -> std::nullptr_t { return nullptr; } +auto ShutdownResponse::result() const -> std::nullptr_t { + auto& value = (*repr_)["result"]; -auto ShutdownResponse::result(std::nullptr_t result) -> ShutdownResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto ShowMessageRequest::method(std::string method) -> ShowMessageRequest& { @@ -2030,12 +1546,7 @@ auto ShowMessageRequest::method(std::string method) -> ShowMessageRequest& { auto ShowMessageRequest::id(std::variant id) -> ShowMessageRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ShowMessageRequest::params() const -> ShowMessageRequestParams { @@ -2049,26 +1560,20 @@ auto ShowMessageRequest::params(ShowMessageRequestParams params) return *this; } -auto ShowMessageResponse::id(long id) -> ShowMessageResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto ShowMessageResponse::id(std::string id) -> ShowMessageResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto ShowMessageResponse::id(std::variant id) + -> ShowMessageResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto ShowMessageResponse::result() const -> std::variant { - lsp_runtime_error("ShowMessageResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto ShowMessageResponse::result( - std::variant result) - -> ShowMessageResponse& { - lsp_runtime_error("ShowMessageResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto WillSaveTextDocumentWaitUntilRequest::method(std::string method) @@ -2080,12 +1585,8 @@ auto WillSaveTextDocumentWaitUntilRequest::method(std::string method) auto WillSaveTextDocumentWaitUntilRequest::id( std::variant id) -> WillSaveTextDocumentWaitUntilRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto WillSaveTextDocumentWaitUntilRequest::params() const @@ -2101,30 +1602,22 @@ auto WillSaveTextDocumentWaitUntilRequest::params( return *this; } -auto WillSaveTextDocumentWaitUntilResponse::id(long id) - -> WillSaveTextDocumentWaitUntilResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WillSaveTextDocumentWaitUntilResponse::id(std::string id) +auto WillSaveTextDocumentWaitUntilResponse::id( + std::variant id) -> WillSaveTextDocumentWaitUntilResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto WillSaveTextDocumentWaitUntilResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "WillSaveTextDocumentWaitUntilResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto WillSaveTextDocumentWaitUntilResponse::result( - std::variant, std::nullptr_t> result) - -> WillSaveTextDocumentWaitUntilResponse& { - lsp_runtime_error( - "WillSaveTextDocumentWaitUntilResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto CompletionRequest::method(std::string method) -> CompletionRequest& { @@ -2134,12 +1627,7 @@ auto CompletionRequest::method(std::string method) -> CompletionRequest& { auto CompletionRequest::id(std::variant id) -> CompletionRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto CompletionRequest::params() const -> CompletionParams { @@ -2152,26 +1640,20 @@ auto CompletionRequest::params(CompletionParams params) -> CompletionRequest& { return *this; } -auto CompletionResponse::id(long id) -> CompletionResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CompletionResponse::id(std::string id) -> CompletionResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto CompletionResponse::id(std::variant id) + -> CompletionResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto CompletionResponse::result() const -> std::variant, CompletionList, std::nullptr_t> { - lsp_runtime_error("CompletionResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto CompletionResponse::result( - std::variant, CompletionList, std::nullptr_t> result) - -> CompletionResponse& { - lsp_runtime_error("CompletionResponse::result() - not implemented yet"); - return *this; + std::variant, CompletionList, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto CompletionResolveRequest::method(std::string method) @@ -2182,12 +1664,7 @@ auto CompletionResolveRequest::method(std::string method) auto CompletionResolveRequest::id(std::variant id) -> CompletionResolveRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto CompletionResolveRequest::params() const -> CompletionItem { @@ -2201,27 +1678,16 @@ auto CompletionResolveRequest::params(CompletionItem params) return *this; } -auto CompletionResolveResponse::id(long id) -> CompletionResolveResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CompletionResolveResponse::id(std::string id) +auto CompletionResolveResponse::id(std::variant id) -> CompletionResolveResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto CompletionResolveResponse::result() const -> CompletionItem { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return CompletionItem(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto CompletionResolveResponse::result(CompletionItem result) - -> CompletionResolveResponse& { - lsp_runtime_error( - "CompletionResolveResponse::result() - not implemented yet"); - return *this; + return CompletionItem(value); } auto HoverRequest::method(std::string method) -> HoverRequest& { @@ -2230,12 +1696,7 @@ auto HoverRequest::method(std::string method) -> HoverRequest& { } auto HoverRequest::id(std::variant id) -> HoverRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto HoverRequest::params() const -> HoverParams { @@ -2248,24 +1709,18 @@ auto HoverRequest::params(HoverParams params) -> HoverRequest& { return *this; } -auto HoverResponse::id(long id) -> HoverResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto HoverResponse::id(std::string id) -> HoverResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto HoverResponse::id(std::variant id) -> HoverResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto HoverResponse::result() const -> std::variant { - lsp_runtime_error("HoverResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto HoverResponse::result(std::variant result) - -> HoverResponse& { - lsp_runtime_error("HoverResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto SignatureHelpRequest::method(std::string method) -> SignatureHelpRequest& { @@ -2275,12 +1730,7 @@ auto SignatureHelpRequest::method(std::string method) -> SignatureHelpRequest& { auto SignatureHelpRequest::id(std::variant id) -> SignatureHelpRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto SignatureHelpRequest::params() const -> SignatureHelpParams { @@ -2294,26 +1744,20 @@ auto SignatureHelpRequest::params(SignatureHelpParams params) return *this; } -auto SignatureHelpResponse::id(long id) -> SignatureHelpResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto SignatureHelpResponse::id(std::string id) -> SignatureHelpResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto SignatureHelpResponse::id(std::variant id) + -> SignatureHelpResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto SignatureHelpResponse::result() const -> std::variant { - lsp_runtime_error("SignatureHelpResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto SignatureHelpResponse::result( - std::variant result) - -> SignatureHelpResponse& { - lsp_runtime_error("SignatureHelpResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto DefinitionRequest::method(std::string method) -> DefinitionRequest& { @@ -2323,12 +1767,7 @@ auto DefinitionRequest::method(std::string method) -> DefinitionRequest& { auto DefinitionRequest::id(std::variant id) -> DefinitionRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DefinitionRequest::params() const -> DefinitionParams { @@ -2341,26 +1780,20 @@ auto DefinitionRequest::params(DefinitionParams params) -> DefinitionRequest& { return *this; } -auto DefinitionResponse::id(long id) -> DefinitionResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DefinitionResponse::id(std::string id) -> DefinitionResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto DefinitionResponse::id(std::variant id) + -> DefinitionResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto DefinitionResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("DefinitionResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DefinitionResponse::result( - std::variant, std::nullptr_t> result) - -> DefinitionResponse& { - lsp_runtime_error("DefinitionResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto ReferencesRequest::method(std::string method) -> ReferencesRequest& { @@ -2370,12 +1803,7 @@ auto ReferencesRequest::method(std::string method) -> ReferencesRequest& { auto ReferencesRequest::id(std::variant id) -> ReferencesRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ReferencesRequest::params() const -> ReferenceParams { @@ -2388,26 +1816,20 @@ auto ReferencesRequest::params(ReferenceParams params) -> ReferencesRequest& { return *this; } -auto ReferencesResponse::id(long id) -> ReferencesResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto ReferencesResponse::id(std::string id) -> ReferencesResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto ReferencesResponse::id(std::variant id) + -> ReferencesResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto ReferencesResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("ReferencesResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto ReferencesResponse::result( - std::variant, std::nullptr_t> result) - -> ReferencesResponse& { - lsp_runtime_error("ReferencesResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto DocumentHighlightRequest::method(std::string method) @@ -2418,12 +1840,7 @@ auto DocumentHighlightRequest::method(std::string method) auto DocumentHighlightRequest::id(std::variant id) -> DocumentHighlightRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DocumentHighlightRequest::params() const -> DocumentHighlightParams { @@ -2437,29 +1854,21 @@ auto DocumentHighlightRequest::params(DocumentHighlightParams params) return *this; } -auto DocumentHighlightResponse::id(long id) -> DocumentHighlightResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentHighlightResponse::id(std::string id) +auto DocumentHighlightResponse::id(std::variant id) -> DocumentHighlightResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto DocumentHighlightResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "DocumentHighlightResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentHighlightResponse::result( - std::variant, std::nullptr_t> result) - -> DocumentHighlightResponse& { - lsp_runtime_error( - "DocumentHighlightResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto DocumentSymbolRequest::method(std::string method) @@ -2470,12 +1879,7 @@ auto DocumentSymbolRequest::method(std::string method) auto DocumentSymbolRequest::id(std::variant id) -> DocumentSymbolRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DocumentSymbolRequest::params() const -> DocumentSymbolParams { @@ -2489,28 +1893,23 @@ auto DocumentSymbolRequest::params(DocumentSymbolParams params) return *this; } -auto DocumentSymbolResponse::id(long id) -> DocumentSymbolResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentSymbolResponse::id(std::string id) -> DocumentSymbolResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto DocumentSymbolResponse::id(std::variant id) + -> DocumentSymbolResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto DocumentSymbolResponse::result() const -> std::variant, Vector, std::nullptr_t> { - lsp_runtime_error("DocumentSymbolResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentSymbolResponse::result( - std::variant, Vector, - std::nullptr_t> - result) -> DocumentSymbolResponse& { - lsp_runtime_error("DocumentSymbolResponse::result() - not implemented yet"); - return *this; + std::variant, Vector, + std::nullptr_t> + result; + + details::try_emplace(result, value); + + return result; } auto CodeActionRequest::method(std::string method) -> CodeActionRequest& { @@ -2520,12 +1919,7 @@ auto CodeActionRequest::method(std::string method) -> CodeActionRequest& { auto CodeActionRequest::id(std::variant id) -> CodeActionRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto CodeActionRequest::params() const -> CodeActionParams { @@ -2538,26 +1932,21 @@ auto CodeActionRequest::params(CodeActionParams params) -> CodeActionRequest& { return *this; } -auto CodeActionResponse::id(long id) -> CodeActionResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CodeActionResponse::id(std::string id) -> CodeActionResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto CodeActionResponse::id(std::variant id) + -> CodeActionResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto CodeActionResponse::result() const -> std::variant>, std::nullptr_t> { - lsp_runtime_error("CodeActionResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto CodeActionResponse::result( - std::variant>, std::nullptr_t> - result) -> CodeActionResponse& { - lsp_runtime_error("CodeActionResponse::result() - not implemented yet"); - return *this; + std::variant>, std::nullptr_t> + result; + + details::try_emplace(result, value); + + return result; } auto CodeActionResolveRequest::method(std::string method) @@ -2568,12 +1957,7 @@ auto CodeActionResolveRequest::method(std::string method) auto CodeActionResolveRequest::id(std::variant id) -> CodeActionResolveRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto CodeActionResolveRequest::params() const -> CodeAction { @@ -2587,27 +1971,16 @@ auto CodeActionResolveRequest::params(CodeAction params) return *this; } -auto CodeActionResolveResponse::id(long id) -> CodeActionResolveResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CodeActionResolveResponse::id(std::string id) +auto CodeActionResolveResponse::id(std::variant id) -> CodeActionResolveResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto CodeActionResolveResponse::result() const -> CodeAction { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return CodeAction(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto CodeActionResolveResponse::result(CodeAction result) - -> CodeActionResolveResponse& { - lsp_runtime_error( - "CodeActionResolveResponse::result() - not implemented yet"); - return *this; + return CodeAction(value); } auto WorkspaceSymbolRequest::method(std::string method) @@ -2617,13 +1990,8 @@ auto WorkspaceSymbolRequest::method(std::string method) } auto WorkspaceSymbolRequest::id(std::variant id) - -> WorkspaceSymbolRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + -> WorkspaceSymbolRequest& { + return static_cast(LSPRequest::id(std::move(id))); } auto WorkspaceSymbolRequest::params() const -> WorkspaceSymbolParams { @@ -2637,28 +2005,23 @@ auto WorkspaceSymbolRequest::params(WorkspaceSymbolParams params) return *this; } -auto WorkspaceSymbolResponse::id(long id) -> WorkspaceSymbolResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WorkspaceSymbolResponse::id(std::string id) -> WorkspaceSymbolResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto WorkspaceSymbolResponse::id(std::variant id) + -> WorkspaceSymbolResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto WorkspaceSymbolResponse::result() const -> std::variant, Vector, std::nullptr_t> { - lsp_runtime_error("WorkspaceSymbolResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto WorkspaceSymbolResponse::result( - std::variant, Vector, - std::nullptr_t> - result) -> WorkspaceSymbolResponse& { - lsp_runtime_error("WorkspaceSymbolResponse::result() - not implemented yet"); - return *this; + std::variant, Vector, + std::nullptr_t> + result; + + details::try_emplace(result, value); + + return result; } auto WorkspaceSymbolResolveRequest::method(std::string method) @@ -2669,12 +2032,8 @@ auto WorkspaceSymbolResolveRequest::method(std::string method) auto WorkspaceSymbolResolveRequest::id(std::variant id) -> WorkspaceSymbolResolveRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto WorkspaceSymbolResolveRequest::params() const -> WorkspaceSymbol { @@ -2688,28 +2047,16 @@ auto WorkspaceSymbolResolveRequest::params(WorkspaceSymbol params) return *this; } -auto WorkspaceSymbolResolveResponse::id(long id) - -> WorkspaceSymbolResolveResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto WorkspaceSymbolResolveResponse::id(std::string id) +auto WorkspaceSymbolResolveResponse::id(std::variant id) -> WorkspaceSymbolResolveResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto WorkspaceSymbolResolveResponse::result() const -> WorkspaceSymbol { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return WorkspaceSymbol(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto WorkspaceSymbolResolveResponse::result(WorkspaceSymbol result) - -> WorkspaceSymbolResolveResponse& { - lsp_runtime_error( - "WorkspaceSymbolResolveResponse::result() - not implemented yet"); - return *this; + return WorkspaceSymbol(value); } auto CodeLensRequest::method(std::string method) -> CodeLensRequest& { @@ -2719,12 +2066,7 @@ auto CodeLensRequest::method(std::string method) -> CodeLensRequest& { auto CodeLensRequest::id(std::variant id) -> CodeLensRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto CodeLensRequest::params() const -> CodeLensParams { @@ -2737,26 +2079,20 @@ auto CodeLensRequest::params(CodeLensParams params) -> CodeLensRequest& { return *this; } -auto CodeLensResponse::id(long id) -> CodeLensResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CodeLensResponse::id(std::string id) -> CodeLensResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto CodeLensResponse::id(std::variant id) + -> CodeLensResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto CodeLensResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("CodeLensResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto CodeLensResponse::result( - std::variant, std::nullptr_t> result) - -> CodeLensResponse& { - lsp_runtime_error("CodeLensResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto CodeLensResolveRequest::method(std::string method) @@ -2767,12 +2103,7 @@ auto CodeLensResolveRequest::method(std::string method) auto CodeLensResolveRequest::id(std::variant id) -> CodeLensResolveRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto CodeLensResolveRequest::params() const -> CodeLens { @@ -2786,25 +2117,15 @@ auto CodeLensResolveRequest::params(CodeLens params) return *this; } -auto CodeLensResolveResponse::id(long id) -> CodeLensResolveResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto CodeLensResolveResponse::id(std::string id) -> CodeLensResolveResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto CodeLensResolveResponse::id(std::variant id) + -> CodeLensResolveResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto CodeLensResolveResponse::result() const -> CodeLens { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return CodeLens(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto CodeLensResolveResponse::result(CodeLens result) - -> CodeLensResolveResponse& { - lsp_runtime_error("CodeLensResolveResponse::result() - not implemented yet"); - return *this; + return CodeLens(value); } auto CodeLensRefreshRequest::method(std::string method) @@ -2815,32 +2136,19 @@ auto CodeLensRefreshRequest::method(std::string method) auto CodeLensRefreshRequest::id(std::variant id) -> CodeLensRefreshRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; -} - -auto CodeLensRefreshResponse::id(long id) -> CodeLensRefreshResponse& { - (*repr_)["id"] = id; - return *this; + return static_cast(LSPRequest::id(std::move(id))); } -auto CodeLensRefreshResponse::id(std::string id) -> CodeLensRefreshResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto CodeLensRefreshResponse::id(std::variant id) + -> CodeLensRefreshResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto CodeLensRefreshResponse::result() const -> std::nullptr_t { - return nullptr; -} + auto& value = (*repr_)["result"]; -auto CodeLensRefreshResponse::result(std::nullptr_t result) - -> CodeLensRefreshResponse& { - (*repr_)["result"] = std::move(result); // base - return *this; + assert(value.is_null()); + return nullptr; } auto DocumentLinkRequest::method(std::string method) -> DocumentLinkRequest& { @@ -2850,12 +2158,7 @@ auto DocumentLinkRequest::method(std::string method) -> DocumentLinkRequest& { auto DocumentLinkRequest::id(std::variant id) -> DocumentLinkRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DocumentLinkRequest::params() const -> DocumentLinkParams { @@ -2869,26 +2172,20 @@ auto DocumentLinkRequest::params(DocumentLinkParams params) return *this; } -auto DocumentLinkResponse::id(long id) -> DocumentLinkResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentLinkResponse::id(std::string id) -> DocumentLinkResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto DocumentLinkResponse::id(std::variant id) + -> DocumentLinkResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto DocumentLinkResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error("DocumentLinkResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentLinkResponse::result( - std::variant, std::nullptr_t> result) - -> DocumentLinkResponse& { - lsp_runtime_error("DocumentLinkResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto DocumentLinkResolveRequest::method(std::string method) @@ -2899,12 +2196,8 @@ auto DocumentLinkResolveRequest::method(std::string method) auto DocumentLinkResolveRequest::id(std::variant id) -> DocumentLinkResolveRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DocumentLinkResolveRequest::params() const -> DocumentLink { @@ -2918,27 +2211,16 @@ auto DocumentLinkResolveRequest::params(DocumentLink params) return *this; } -auto DocumentLinkResolveResponse::id(long id) -> DocumentLinkResolveResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentLinkResolveResponse::id(std::string id) +auto DocumentLinkResolveResponse::id(std::variant id) -> DocumentLinkResolveResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto DocumentLinkResolveResponse::result() const -> DocumentLink { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return DocumentLink(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto DocumentLinkResolveResponse::result(DocumentLink result) - -> DocumentLinkResolveResponse& { - lsp_runtime_error( - "DocumentLinkResolveResponse::result() - not implemented yet"); - return *this; + return DocumentLink(value); } auto DocumentFormattingRequest::method(std::string method) @@ -2949,12 +2231,7 @@ auto DocumentFormattingRequest::method(std::string method) auto DocumentFormattingRequest::id(std::variant id) -> DocumentFormattingRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DocumentFormattingRequest::params() const -> DocumentFormattingParams { @@ -2968,29 +2245,21 @@ auto DocumentFormattingRequest::params(DocumentFormattingParams params) return *this; } -auto DocumentFormattingResponse::id(long id) -> DocumentFormattingResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentFormattingResponse::id(std::string id) +auto DocumentFormattingResponse::id(std::variant id) -> DocumentFormattingResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto DocumentFormattingResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "DocumentFormattingResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentFormattingResponse::result( - std::variant, std::nullptr_t> result) - -> DocumentFormattingResponse& { - lsp_runtime_error( - "DocumentFormattingResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto DocumentRangeFormattingRequest::method(std::string method) @@ -3001,12 +2270,8 @@ auto DocumentRangeFormattingRequest::method(std::string method) auto DocumentRangeFormattingRequest::id(std::variant id) -> DocumentRangeFormattingRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DocumentRangeFormattingRequest::params() const @@ -3021,30 +2286,21 @@ auto DocumentRangeFormattingRequest::params( return *this; } -auto DocumentRangeFormattingResponse::id(long id) - -> DocumentRangeFormattingResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentRangeFormattingResponse::id(std::string id) +auto DocumentRangeFormattingResponse::id(std::variant id) -> DocumentRangeFormattingResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto DocumentRangeFormattingResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "DocumentRangeFormattingResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentRangeFormattingResponse::result( - std::variant, std::nullptr_t> result) - -> DocumentRangeFormattingResponse& { - lsp_runtime_error( - "DocumentRangeFormattingResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto DocumentRangesFormattingRequest::method(std::string method) @@ -3055,12 +2311,8 @@ auto DocumentRangesFormattingRequest::method(std::string method) auto DocumentRangesFormattingRequest::id(std::variant id) -> DocumentRangesFormattingRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DocumentRangesFormattingRequest::params() const @@ -3075,30 +2327,21 @@ auto DocumentRangesFormattingRequest::params( return *this; } -auto DocumentRangesFormattingResponse::id(long id) - -> DocumentRangesFormattingResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentRangesFormattingResponse::id(std::string id) +auto DocumentRangesFormattingResponse::id(std::variant id) -> DocumentRangesFormattingResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto DocumentRangesFormattingResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "DocumentRangesFormattingResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentRangesFormattingResponse::result( - std::variant, std::nullptr_t> result) - -> DocumentRangesFormattingResponse& { - lsp_runtime_error( - "DocumentRangesFormattingResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto DocumentOnTypeFormattingRequest::method(std::string method) @@ -3109,12 +2352,8 @@ auto DocumentOnTypeFormattingRequest::method(std::string method) auto DocumentOnTypeFormattingRequest::id(std::variant id) -> DocumentOnTypeFormattingRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DocumentOnTypeFormattingRequest::params() const @@ -3129,30 +2368,21 @@ auto DocumentOnTypeFormattingRequest::params( return *this; } -auto DocumentOnTypeFormattingResponse::id(long id) - -> DocumentOnTypeFormattingResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto DocumentOnTypeFormattingResponse::id(std::string id) +auto DocumentOnTypeFormattingResponse::id(std::variant id) -> DocumentOnTypeFormattingResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto DocumentOnTypeFormattingResponse::result() const -> std::variant, std::nullptr_t> { - lsp_runtime_error( - "DocumentOnTypeFormattingResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto DocumentOnTypeFormattingResponse::result( - std::variant, std::nullptr_t> result) - -> DocumentOnTypeFormattingResponse& { - lsp_runtime_error( - "DocumentOnTypeFormattingResponse::result() - not implemented yet"); - return *this; + std::variant, std::nullptr_t> result; + + details::try_emplace(result, value); + + return result; } auto RenameRequest::method(std::string method) -> RenameRequest& { @@ -3161,12 +2391,7 @@ auto RenameRequest::method(std::string method) -> RenameRequest& { } auto RenameRequest::id(std::variant id) -> RenameRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto RenameRequest::params() const -> RenameParams { @@ -3179,25 +2404,19 @@ auto RenameRequest::params(RenameParams params) -> RenameRequest& { return *this; } -auto RenameResponse::id(long id) -> RenameResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto RenameResponse::id(std::string id) -> RenameResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto RenameResponse::id(std::variant id) -> RenameResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto RenameResponse::result() const -> std::variant { - lsp_runtime_error("RenameResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto RenameResponse::result(std::variant result) - -> RenameResponse& { - lsp_runtime_error("RenameResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto PrepareRenameRequest::method(std::string method) -> PrepareRenameRequest& { @@ -3207,12 +2426,7 @@ auto PrepareRenameRequest::method(std::string method) -> PrepareRenameRequest& { auto PrepareRenameRequest::id(std::variant id) -> PrepareRenameRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto PrepareRenameRequest::params() const -> PrepareRenameParams { @@ -3226,26 +2440,20 @@ auto PrepareRenameRequest::params(PrepareRenameParams params) return *this; } -auto PrepareRenameResponse::id(long id) -> PrepareRenameResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto PrepareRenameResponse::id(std::string id) -> PrepareRenameResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto PrepareRenameResponse::id(std::variant id) + -> PrepareRenameResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto PrepareRenameResponse::result() const -> std::variant { - lsp_runtime_error("PrepareRenameResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto PrepareRenameResponse::result( - std::variant result) - -> PrepareRenameResponse& { - lsp_runtime_error("PrepareRenameResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto ExecuteCommandRequest::method(std::string method) @@ -3256,12 +2464,7 @@ auto ExecuteCommandRequest::method(std::string method) auto ExecuteCommandRequest::id(std::variant id) -> ExecuteCommandRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ExecuteCommandRequest::params() const -> ExecuteCommandParams { @@ -3275,25 +2478,20 @@ auto ExecuteCommandRequest::params(ExecuteCommandParams params) return *this; } -auto ExecuteCommandResponse::id(long id) -> ExecuteCommandResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto ExecuteCommandResponse::id(std::string id) -> ExecuteCommandResponse& { - (*repr_)["id"] = std::move(id); - return *this; +auto ExecuteCommandResponse::id(std::variant id) + -> ExecuteCommandResponse& { + return static_cast(LSPResponse::id(std::move(id))); } auto ExecuteCommandResponse::result() const -> std::variant { - lsp_runtime_error("ExecuteCommandResponse::result() - not implemented yet"); -} + auto& value = (*repr_)["result"]; -auto ExecuteCommandResponse::result(std::variant result) - -> ExecuteCommandResponse& { - lsp_runtime_error("ExecuteCommandResponse::result() - not implemented yet"); - return *this; + std::variant result; + + details::try_emplace(result, value); + + return result; } auto ApplyWorkspaceEditRequest::method(std::string method) @@ -3304,12 +2502,7 @@ auto ApplyWorkspaceEditRequest::method(std::string method) auto ApplyWorkspaceEditRequest::id(std::variant id) -> ApplyWorkspaceEditRequest& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ApplyWorkspaceEditRequest::params() const -> ApplyWorkspaceEditParams { @@ -3323,27 +2516,16 @@ auto ApplyWorkspaceEditRequest::params(ApplyWorkspaceEditParams params) return *this; } -auto ApplyWorkspaceEditResponse::id(long id) -> ApplyWorkspaceEditResponse& { - (*repr_)["id"] = id; - return *this; -} - -auto ApplyWorkspaceEditResponse::id(std::string id) +auto ApplyWorkspaceEditResponse::id(std::variant id) -> ApplyWorkspaceEditResponse& { - (*repr_)["id"] = std::move(id); - return *this; + return static_cast( + LSPResponse::id(std::move(id))); } auto ApplyWorkspaceEditResponse::result() const -> ApplyWorkspaceEditResult { - if (!repr_->contains("result")) (*repr_)["result"] = nullptr; - return ApplyWorkspaceEditResult(repr_->at("result")); // reference -} + auto& value = (*repr_)["result"]; -auto ApplyWorkspaceEditResponse::result(ApplyWorkspaceEditResult result) - -> ApplyWorkspaceEditResponse& { - lsp_runtime_error( - "ApplyWorkspaceEditResponse::result() - not implemented yet"); - return *this; + return ApplyWorkspaceEditResult(value); } auto DidChangeWorkspaceFoldersNotification::method(std::string method) @@ -3355,12 +2537,8 @@ auto DidChangeWorkspaceFoldersNotification::method(std::string method) auto DidChangeWorkspaceFoldersNotification::id( std::variant id) -> DidChangeWorkspaceFoldersNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidChangeWorkspaceFoldersNotification::params() const @@ -3384,12 +2562,8 @@ auto WorkDoneProgressCancelNotification::method(std::string method) auto WorkDoneProgressCancelNotification::id(std::variant id) -> WorkDoneProgressCancelNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto WorkDoneProgressCancelNotification::params() const @@ -3413,12 +2587,8 @@ auto DidCreateFilesNotification::method(std::string method) auto DidCreateFilesNotification::id(std::variant id) -> DidCreateFilesNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidCreateFilesNotification::params() const -> CreateFilesParams { @@ -3440,12 +2610,8 @@ auto DidRenameFilesNotification::method(std::string method) auto DidRenameFilesNotification::id(std::variant id) -> DidRenameFilesNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidRenameFilesNotification::params() const -> RenameFilesParams { @@ -3467,12 +2633,8 @@ auto DidDeleteFilesNotification::method(std::string method) auto DidDeleteFilesNotification::id(std::variant id) -> DidDeleteFilesNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidDeleteFilesNotification::params() const -> DeleteFilesParams { @@ -3494,12 +2656,8 @@ auto DidOpenNotebookDocumentNotification::method(std::string method) auto DidOpenNotebookDocumentNotification::id(std::variant id) -> DidOpenNotebookDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidOpenNotebookDocumentNotification::params() const @@ -3524,12 +2682,8 @@ auto DidChangeNotebookDocumentNotification::method(std::string method) auto DidChangeNotebookDocumentNotification::id( std::variant id) -> DidChangeNotebookDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidChangeNotebookDocumentNotification::params() const @@ -3553,12 +2707,8 @@ auto DidSaveNotebookDocumentNotification::method(std::string method) auto DidSaveNotebookDocumentNotification::id(std::variant id) -> DidSaveNotebookDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidSaveNotebookDocumentNotification::params() const @@ -3583,12 +2733,8 @@ auto DidCloseNotebookDocumentNotification::method(std::string method) auto DidCloseNotebookDocumentNotification::id( std::variant id) -> DidCloseNotebookDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidCloseNotebookDocumentNotification::params() const @@ -3612,12 +2758,7 @@ auto InitializedNotification::method(std::string method) auto InitializedNotification::id(std::variant id) -> InitializedNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto InitializedNotification::params() const -> InitializedParams { @@ -3638,12 +2779,7 @@ auto ExitNotification::method(std::string method) -> ExitNotification& { auto ExitNotification::id(std::variant id) -> ExitNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto DidChangeConfigurationNotification::method(std::string method) @@ -3654,12 +2790,8 @@ auto DidChangeConfigurationNotification::method(std::string method) auto DidChangeConfigurationNotification::id(std::variant id) -> DidChangeConfigurationNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidChangeConfigurationNotification::params() const @@ -3683,12 +2815,7 @@ auto ShowMessageNotification::method(std::string method) auto ShowMessageNotification::id(std::variant id) -> ShowMessageNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ShowMessageNotification::params() const -> ShowMessageParams { @@ -3710,12 +2837,7 @@ auto LogMessageNotification::method(std::string method) auto LogMessageNotification::id(std::variant id) -> LogMessageNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto LogMessageNotification::params() const -> LogMessageParams { @@ -3737,12 +2859,8 @@ auto TelemetryEventNotification::method(std::string method) auto TelemetryEventNotification::id(std::variant id) -> TelemetryEventNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto TelemetryEventNotification::params() const -> LSPAny { @@ -3764,12 +2882,8 @@ auto DidOpenTextDocumentNotification::method(std::string method) auto DidOpenTextDocumentNotification::id(std::variant id) -> DidOpenTextDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidOpenTextDocumentNotification::params() const @@ -3792,12 +2906,8 @@ auto DidChangeTextDocumentNotification::method(std::string method) auto DidChangeTextDocumentNotification::id(std::variant id) -> DidChangeTextDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidChangeTextDocumentNotification::params() const @@ -3820,12 +2930,8 @@ auto DidCloseTextDocumentNotification::method(std::string method) auto DidCloseTextDocumentNotification::id(std::variant id) -> DidCloseTextDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidCloseTextDocumentNotification::params() const @@ -3848,12 +2954,8 @@ auto DidSaveTextDocumentNotification::method(std::string method) auto DidSaveTextDocumentNotification::id(std::variant id) -> DidSaveTextDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidSaveTextDocumentNotification::params() const @@ -3876,12 +2978,8 @@ auto WillSaveTextDocumentNotification::method(std::string method) auto WillSaveTextDocumentNotification::id(std::variant id) -> WillSaveTextDocumentNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto WillSaveTextDocumentNotification::params() const @@ -3904,12 +3002,8 @@ auto DidChangeWatchedFilesNotification::method(std::string method) auto DidChangeWatchedFilesNotification::id(std::variant id) -> DidChangeWatchedFilesNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto DidChangeWatchedFilesNotification::params() const @@ -3932,12 +3026,8 @@ auto PublishDiagnosticsNotification::method(std::string method) auto PublishDiagnosticsNotification::id(std::variant id) -> PublishDiagnosticsNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast( + LSPRequest::id(std::move(id))); } auto PublishDiagnosticsNotification::params() const @@ -3959,12 +3049,7 @@ auto SetTraceNotification::method(std::string method) -> SetTraceNotification& { auto SetTraceNotification::id(std::variant id) -> SetTraceNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto SetTraceNotification::params() const -> SetTraceParams { @@ -3985,12 +3070,7 @@ auto LogTraceNotification::method(std::string method) -> LogTraceNotification& { auto LogTraceNotification::id(std::variant id) -> LogTraceNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto LogTraceNotification::params() const -> LogTraceParams { @@ -4011,12 +3091,7 @@ auto CancelNotification::method(std::string method) -> CancelNotification& { auto CancelNotification::id(std::variant id) -> CancelNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto CancelNotification::params() const -> CancelParams { @@ -4036,12 +3111,7 @@ auto ProgressNotification::method(std::string method) -> ProgressNotification& { auto ProgressNotification::id(std::variant id) -> ProgressNotification& { - if (std::holds_alternative(id)) { - (*repr_)["id"] = std::get(id); - } else { - (*repr_)["id"] = std::get(id); - } - return *this; + return static_cast(LSPRequest::id(std::move(id))); } auto ProgressNotification::params() const -> ProgressParams { diff --git a/src/lsp/cxx/lsp/requests.h b/src/lsp/cxx/lsp/requests.h index 6c511364..c7623006 100644 --- a/src/lsp/cxx/lsp/requests.h +++ b/src/lsp/cxx/lsp/requests.h @@ -138,11 +138,12 @@ class ImplementationRequest final : public LSPRequest { class ImplementationResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ImplementationResponse&; - auto id(std::string id) -> ImplementationResponse&; + auto id(std::variant id) -> ImplementationResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -167,11 +168,12 @@ class TypeDefinitionRequest final : public LSPRequest { class TypeDefinitionResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> TypeDefinitionResponse&; - auto id(std::string id) -> TypeDefinitionResponse&; + auto id(std::variant id) -> TypeDefinitionResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -193,11 +195,11 @@ class WorkspaceFoldersRequest final : public LSPRequest { class WorkspaceFoldersResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WorkspaceFoldersResponse&; - auto id(std::string id) -> WorkspaceFoldersResponse&; + auto id(std::variant id) -> WorkspaceFoldersResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -221,11 +223,11 @@ class ConfigurationRequest final : public LSPRequest { class ConfigurationResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = Vector; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ConfigurationResponse&; - auto id(std::string id) -> ConfigurationResponse&; + auto id(std::variant id) -> ConfigurationResponse&; [[nodiscard]] auto result() const -> Vector; @@ -247,11 +249,11 @@ class DocumentColorRequest final : public LSPRequest { class DocumentColorResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = Vector; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentColorResponse&; - auto id(std::string id) -> DocumentColorResponse&; + auto id(std::variant id) -> DocumentColorResponse&; [[nodiscard]] auto result() const -> Vector; @@ -273,11 +275,11 @@ class ColorPresentationRequest final : public LSPRequest { class ColorPresentationResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = Vector; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ColorPresentationResponse&; - auto id(std::string id) -> ColorPresentationResponse&; + auto id(std::variant id) -> ColorPresentationResponse&; [[nodiscard]] auto result() const -> Vector; @@ -299,11 +301,11 @@ class FoldingRangeRequest final : public LSPRequest { class FoldingRangeResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> FoldingRangeResponse&; - auto id(std::string id) -> FoldingRangeResponse&; + auto id(std::variant id) -> FoldingRangeResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -324,11 +326,11 @@ class FoldingRangeRefreshRequest final : public LSPRequest { class FoldingRangeRefreshResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> FoldingRangeRefreshResponse&; - auto id(std::string id) -> FoldingRangeRefreshResponse&; + auto id(std::variant id) -> FoldingRangeRefreshResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -350,11 +352,12 @@ class DeclarationRequest final : public LSPRequest { class DeclarationResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DeclarationResponse&; - auto id(std::string id) -> DeclarationResponse&; + auto id(std::variant id) -> DeclarationResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -379,11 +382,11 @@ class SelectionRangeRequest final : public LSPRequest { class SelectionRangeResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> SelectionRangeResponse&; - auto id(std::string id) -> SelectionRangeResponse&; + auto id(std::variant id) -> SelectionRangeResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -408,11 +411,12 @@ class WorkDoneProgressCreateRequest final : public LSPRequest { class WorkDoneProgressCreateResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WorkDoneProgressCreateResponse&; - auto id(std::string id) -> WorkDoneProgressCreateResponse&; + auto id(std::variant id) + -> WorkDoneProgressCreateResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -435,11 +439,11 @@ class CallHierarchyPrepareRequest final : public LSPRequest { class CallHierarchyPrepareResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CallHierarchyPrepareResponse&; - auto id(std::string id) -> CallHierarchyPrepareResponse&; + auto id(std::variant id) -> CallHierarchyPrepareResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -465,11 +469,13 @@ class CallHierarchyIncomingCallsRequest final : public LSPRequest { class CallHierarchyIncomingCallsResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CallHierarchyIncomingCallsResponse&; - auto id(std::string id) -> CallHierarchyIncomingCallsResponse&; + auto id(std::variant id) + -> CallHierarchyIncomingCallsResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -496,11 +502,13 @@ class CallHierarchyOutgoingCallsRequest final : public LSPRequest { class CallHierarchyOutgoingCallsResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CallHierarchyOutgoingCallsResponse&; - auto id(std::string id) -> CallHierarchyOutgoingCallsResponse&; + auto id(std::variant id) + -> CallHierarchyOutgoingCallsResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -525,11 +533,11 @@ class SemanticTokensRequest final : public LSPRequest { class SemanticTokensResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> SemanticTokensResponse&; - auto id(std::string id) -> SemanticTokensResponse&; + auto id(std::variant id) -> SemanticTokensResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -553,11 +561,12 @@ class SemanticTokensDeltaRequest final : public LSPRequest { class SemanticTokensDeltaResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> SemanticTokensDeltaResponse&; - auto id(std::string id) -> SemanticTokensDeltaResponse&; + auto id(std::variant id) -> SemanticTokensDeltaResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -582,11 +591,11 @@ class SemanticTokensRangeRequest final : public LSPRequest { class SemanticTokensRangeResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> SemanticTokensRangeResponse&; - auto id(std::string id) -> SemanticTokensRangeResponse&; + auto id(std::variant id) -> SemanticTokensRangeResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -607,11 +616,11 @@ class SemanticTokensRefreshRequest final : public LSPRequest { class SemanticTokensRefreshResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> SemanticTokensRefreshResponse&; - auto id(std::string id) -> SemanticTokensRefreshResponse&; + auto id(std::variant id) -> SemanticTokensRefreshResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -633,11 +642,11 @@ class ShowDocumentRequest final : public LSPRequest { class ShowDocumentResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = ShowDocumentResult; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ShowDocumentResponse&; - auto id(std::string id) -> ShowDocumentResponse&; + auto id(std::variant id) -> ShowDocumentResponse&; [[nodiscard]] auto result() const -> ShowDocumentResult; @@ -659,11 +668,11 @@ class LinkedEditingRangeRequest final : public LSPRequest { class LinkedEditingRangeResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> LinkedEditingRangeResponse&; - auto id(std::string id) -> LinkedEditingRangeResponse&; + auto id(std::variant id) -> LinkedEditingRangeResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -687,11 +696,11 @@ class WillCreateFilesRequest final : public LSPRequest { class WillCreateFilesResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WillCreateFilesResponse&; - auto id(std::string id) -> WillCreateFilesResponse&; + auto id(std::variant id) -> WillCreateFilesResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -715,11 +724,11 @@ class WillRenameFilesRequest final : public LSPRequest { class WillRenameFilesResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WillRenameFilesResponse&; - auto id(std::string id) -> WillRenameFilesResponse&; + auto id(std::variant id) -> WillRenameFilesResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -743,11 +752,11 @@ class WillDeleteFilesRequest final : public LSPRequest { class WillDeleteFilesResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WillDeleteFilesResponse&; - auto id(std::string id) -> WillDeleteFilesResponse&; + auto id(std::variant id) -> WillDeleteFilesResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -771,11 +780,11 @@ class MonikerRequest final : public LSPRequest { class MonikerResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> MonikerResponse&; - auto id(std::string id) -> MonikerResponse&; + auto id(std::variant id) -> MonikerResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -800,11 +809,11 @@ class TypeHierarchyPrepareRequest final : public LSPRequest { class TypeHierarchyPrepareResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> TypeHierarchyPrepareResponse&; - auto id(std::string id) -> TypeHierarchyPrepareResponse&; + auto id(std::variant id) -> TypeHierarchyPrepareResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -830,11 +839,12 @@ class TypeHierarchySupertypesRequest final : public LSPRequest { class TypeHierarchySupertypesResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> TypeHierarchySupertypesResponse&; - auto id(std::string id) -> TypeHierarchySupertypesResponse&; + auto id(std::variant id) + -> TypeHierarchySupertypesResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -859,11 +869,11 @@ class TypeHierarchySubtypesRequest final : public LSPRequest { class TypeHierarchySubtypesResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> TypeHierarchySubtypesResponse&; - auto id(std::string id) -> TypeHierarchySubtypesResponse&; + auto id(std::variant id) -> TypeHierarchySubtypesResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -887,11 +897,11 @@ class InlineValueRequest final : public LSPRequest { class InlineValueResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> InlineValueResponse&; - auto id(std::string id) -> InlineValueResponse&; + auto id(std::variant id) -> InlineValueResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -912,11 +922,11 @@ class InlineValueRefreshRequest final : public LSPRequest { class InlineValueRefreshResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> InlineValueRefreshResponse&; - auto id(std::string id) -> InlineValueRefreshResponse&; + auto id(std::variant id) -> InlineValueRefreshResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -938,11 +948,11 @@ class InlayHintRequest final : public LSPRequest { class InlayHintResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> InlayHintResponse&; - auto id(std::string id) -> InlayHintResponse&; + auto id(std::variant id) -> InlayHintResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -966,11 +976,11 @@ class InlayHintResolveRequest final : public LSPRequest { class InlayHintResolveResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = InlayHint; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> InlayHintResolveResponse&; - auto id(std::string id) -> InlayHintResolveResponse&; + auto id(std::variant id) -> InlayHintResolveResponse&; [[nodiscard]] auto result() const -> InlayHint; @@ -989,11 +999,11 @@ class InlayHintRefreshRequest final : public LSPRequest { class InlayHintRefreshResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> InlayHintRefreshResponse&; - auto id(std::string id) -> InlayHintRefreshResponse&; + auto id(std::variant id) -> InlayHintRefreshResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -1015,11 +1025,11 @@ class DocumentDiagnosticRequest final : public LSPRequest { class DocumentDiagnosticResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = DocumentDiagnosticReport; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentDiagnosticResponse&; - auto id(std::string id) -> DocumentDiagnosticResponse&; + auto id(std::variant id) -> DocumentDiagnosticResponse&; [[nodiscard]] auto result() const -> DocumentDiagnosticReport; @@ -1041,11 +1051,11 @@ class WorkspaceDiagnosticRequest final : public LSPRequest { class WorkspaceDiagnosticResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = WorkspaceDiagnosticReport; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WorkspaceDiagnosticResponse&; - auto id(std::string id) -> WorkspaceDiagnosticResponse&; + auto id(std::variant id) -> WorkspaceDiagnosticResponse&; [[nodiscard]] auto result() const -> WorkspaceDiagnosticReport; @@ -1064,11 +1074,11 @@ class DiagnosticRefreshRequest final : public LSPRequest { class DiagnosticRefreshResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DiagnosticRefreshResponse&; - auto id(std::string id) -> DiagnosticRefreshResponse&; + auto id(std::variant id) -> DiagnosticRefreshResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -1090,11 +1100,12 @@ class InlineCompletionRequest final : public LSPRequest { class InlineCompletionResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> InlineCompletionResponse&; - auto id(std::string id) -> InlineCompletionResponse&; + auto id(std::variant id) -> InlineCompletionResponse&; [[nodiscard]] auto result() const -> std::variant, @@ -1120,11 +1131,11 @@ class TextDocumentContentRequest final : public LSPRequest { class TextDocumentContentResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = TextDocumentContentResult; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> TextDocumentContentResponse&; - auto id(std::string id) -> TextDocumentContentResponse&; + auto id(std::variant id) -> TextDocumentContentResponse&; [[nodiscard]] auto result() const -> TextDocumentContentResult; @@ -1148,11 +1159,12 @@ class TextDocumentContentRefreshRequest final : public LSPRequest { class TextDocumentContentRefreshResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> TextDocumentContentRefreshResponse&; - auto id(std::string id) -> TextDocumentContentRefreshResponse&; + auto id(std::variant id) + -> TextDocumentContentRefreshResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -1174,11 +1186,11 @@ class RegistrationRequest final : public LSPRequest { class RegistrationResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> RegistrationResponse&; - auto id(std::string id) -> RegistrationResponse&; + auto id(std::variant id) -> RegistrationResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -1200,11 +1212,11 @@ class UnregistrationRequest final : public LSPRequest { class UnregistrationResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> UnregistrationResponse&; - auto id(std::string id) -> UnregistrationResponse&; + auto id(std::variant id) -> UnregistrationResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -1226,11 +1238,11 @@ class InitializeRequest final : public LSPRequest { class InitializeResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = InitializeResult; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> InitializeResponse&; - auto id(std::string id) -> InitializeResponse&; + auto id(std::variant id) -> InitializeResponse&; [[nodiscard]] auto result() const -> InitializeResult; @@ -1249,11 +1261,11 @@ class ShutdownRequest final : public LSPRequest { class ShutdownResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ShutdownResponse&; - auto id(std::string id) -> ShutdownResponse&; + auto id(std::variant id) -> ShutdownResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -1275,11 +1287,11 @@ class ShowMessageRequest final : public LSPRequest { class ShowMessageResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ShowMessageResponse&; - auto id(std::string id) -> ShowMessageResponse&; + auto id(std::variant id) -> ShowMessageResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -1305,11 +1317,12 @@ class WillSaveTextDocumentWaitUntilRequest final : public LSPRequest { class WillSaveTextDocumentWaitUntilResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WillSaveTextDocumentWaitUntilResponse&; - auto id(std::string id) -> WillSaveTextDocumentWaitUntilResponse&; + auto id(std::variant id) + -> WillSaveTextDocumentWaitUntilResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1333,11 +1346,12 @@ class CompletionRequest final : public LSPRequest { class CompletionResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant, CompletionList, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CompletionResponse&; - auto id(std::string id) -> CompletionResponse&; + auto id(std::variant id) -> CompletionResponse&; [[nodiscard]] auto result() const -> std::variant, CompletionList, std::nullptr_t>; @@ -1362,11 +1376,11 @@ class CompletionResolveRequest final : public LSPRequest { class CompletionResolveResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = CompletionItem; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CompletionResolveResponse&; - auto id(std::string id) -> CompletionResolveResponse&; + auto id(std::variant id) -> CompletionResolveResponse&; [[nodiscard]] auto result() const -> CompletionItem; @@ -1388,11 +1402,11 @@ class HoverRequest final : public LSPRequest { class HoverResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> HoverResponse&; - auto id(std::string id) -> HoverResponse&; + auto id(std::variant id) -> HoverResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -1414,11 +1428,11 @@ class SignatureHelpRequest final : public LSPRequest { class SignatureHelpResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> SignatureHelpResponse&; - auto id(std::string id) -> SignatureHelpResponse&; + auto id(std::variant id) -> SignatureHelpResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -1442,11 +1456,12 @@ class DefinitionRequest final : public LSPRequest { class DefinitionResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DefinitionResponse&; - auto id(std::string id) -> DefinitionResponse&; + auto id(std::variant id) -> DefinitionResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1471,11 +1486,11 @@ class ReferencesRequest final : public LSPRequest { class ReferencesResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ReferencesResponse&; - auto id(std::string id) -> ReferencesResponse&; + auto id(std::variant id) -> ReferencesResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1499,11 +1514,11 @@ class DocumentHighlightRequest final : public LSPRequest { class DocumentHighlightResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentHighlightResponse&; - auto id(std::string id) -> DocumentHighlightResponse&; + auto id(std::variant id) -> DocumentHighlightResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1527,11 +1542,12 @@ class DocumentSymbolRequest final : public LSPRequest { class DocumentSymbolResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, Vector, + std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentSymbolResponse&; - auto id(std::string id) -> DocumentSymbolResponse&; + auto id(std::variant id) -> DocumentSymbolResponse&; [[nodiscard]] auto result() const -> std::variant, Vector, @@ -1557,11 +1573,12 @@ class CodeActionRequest final : public LSPRequest { class CodeActionResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = + std::variant>, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CodeActionResponse&; - auto id(std::string id) -> CodeActionResponse&; + auto id(std::variant id) -> CodeActionResponse&; [[nodiscard]] auto result() const -> std::variant>, @@ -1587,11 +1604,11 @@ class CodeActionResolveRequest final : public LSPRequest { class CodeActionResolveResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = CodeAction; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CodeActionResolveResponse&; - auto id(std::string id) -> CodeActionResolveResponse&; + auto id(std::variant id) -> CodeActionResolveResponse&; [[nodiscard]] auto result() const -> CodeAction; @@ -1613,11 +1630,12 @@ class WorkspaceSymbolRequest final : public LSPRequest { class WorkspaceSymbolResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, + Vector, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WorkspaceSymbolResponse&; - auto id(std::string id) -> WorkspaceSymbolResponse&; + auto id(std::variant id) -> WorkspaceSymbolResponse&; [[nodiscard]] auto result() const -> std::variant, Vector, @@ -1643,11 +1661,12 @@ class WorkspaceSymbolResolveRequest final : public LSPRequest { class WorkspaceSymbolResolveResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = WorkspaceSymbol; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> WorkspaceSymbolResolveResponse&; - auto id(std::string id) -> WorkspaceSymbolResolveResponse&; + auto id(std::variant id) + -> WorkspaceSymbolResolveResponse&; [[nodiscard]] auto result() const -> WorkspaceSymbol; @@ -1669,11 +1688,11 @@ class CodeLensRequest final : public LSPRequest { class CodeLensResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CodeLensResponse&; - auto id(std::string id) -> CodeLensResponse&; + auto id(std::variant id) -> CodeLensResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1697,11 +1716,11 @@ class CodeLensResolveRequest final : public LSPRequest { class CodeLensResolveResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = CodeLens; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CodeLensResolveResponse&; - auto id(std::string id) -> CodeLensResolveResponse&; + auto id(std::variant id) -> CodeLensResolveResponse&; [[nodiscard]] auto result() const -> CodeLens; @@ -1720,11 +1739,11 @@ class CodeLensRefreshRequest final : public LSPRequest { class CodeLensRefreshResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::nullptr_t; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> CodeLensRefreshResponse&; - auto id(std::string id) -> CodeLensRefreshResponse&; + auto id(std::variant id) -> CodeLensRefreshResponse&; [[nodiscard]] auto result() const -> std::nullptr_t; @@ -1746,11 +1765,11 @@ class DocumentLinkRequest final : public LSPRequest { class DocumentLinkResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentLinkResponse&; - auto id(std::string id) -> DocumentLinkResponse&; + auto id(std::variant id) -> DocumentLinkResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1774,11 +1793,11 @@ class DocumentLinkResolveRequest final : public LSPRequest { class DocumentLinkResolveResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = DocumentLink; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentLinkResolveResponse&; - auto id(std::string id) -> DocumentLinkResolveResponse&; + auto id(std::variant id) -> DocumentLinkResolveResponse&; [[nodiscard]] auto result() const -> DocumentLink; @@ -1800,11 +1819,11 @@ class DocumentFormattingRequest final : public LSPRequest { class DocumentFormattingResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentFormattingResponse&; - auto id(std::string id) -> DocumentFormattingResponse&; + auto id(std::variant id) -> DocumentFormattingResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1830,11 +1849,12 @@ class DocumentRangeFormattingRequest final : public LSPRequest { class DocumentRangeFormattingResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentRangeFormattingResponse&; - auto id(std::string id) -> DocumentRangeFormattingResponse&; + auto id(std::variant id) + -> DocumentRangeFormattingResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1860,11 +1880,12 @@ class DocumentRangesFormattingRequest final : public LSPRequest { class DocumentRangesFormattingResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentRangesFormattingResponse&; - auto id(std::string id) -> DocumentRangesFormattingResponse&; + auto id(std::variant id) + -> DocumentRangesFormattingResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1890,11 +1911,12 @@ class DocumentOnTypeFormattingRequest final : public LSPRequest { class DocumentOnTypeFormattingResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant, std::nullptr_t>; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> DocumentOnTypeFormattingResponse&; - auto id(std::string id) -> DocumentOnTypeFormattingResponse&; + auto id(std::variant id) + -> DocumentOnTypeFormattingResponse&; [[nodiscard]] auto result() const -> std::variant, std::nullptr_t>; @@ -1918,11 +1940,11 @@ class RenameRequest final : public LSPRequest { class RenameResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> RenameResponse&; - auto id(std::string id) -> RenameResponse&; + auto id(std::variant id) -> RenameResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -1946,11 +1968,11 @@ class PrepareRenameRequest final : public LSPRequest { class PrepareRenameResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> PrepareRenameResponse&; - auto id(std::string id) -> PrepareRenameResponse&; + auto id(std::variant id) -> PrepareRenameResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -1974,11 +1996,11 @@ class ExecuteCommandRequest final : public LSPRequest { class ExecuteCommandResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = std::variant; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ExecuteCommandResponse&; - auto id(std::string id) -> ExecuteCommandResponse&; + auto id(std::variant id) -> ExecuteCommandResponse&; [[nodiscard]] auto result() const -> std::variant; @@ -2001,11 +2023,11 @@ class ApplyWorkspaceEditRequest final : public LSPRequest { class ApplyWorkspaceEditResponse final : public LSPResponse { public: + using LSPResponse::id; using LSPResponse::LSPResponse; + using Result = ApplyWorkspaceEditResult; - [[nodiscard]] auto id() const -> std::variant; - auto id(long id) -> ApplyWorkspaceEditResponse&; - auto id(std::string id) -> ApplyWorkspaceEditResponse&; + auto id(std::variant id) -> ApplyWorkspaceEditResponse&; [[nodiscard]] auto result() const -> ApplyWorkspaceEditResult; @@ -2376,7 +2398,7 @@ class ProgressNotification final : public LSPRequest { }; template -auto visit(Visitor&& visitor, const LSPRequest& request) -> void { +auto visit(Visitor&& visitor, LSPRequest request) -> void { #define PROCESS_REQUEST_TYPE(NAME, METHOD) \ if (request.method() == METHOD) \ return visitor(static_cast(request)); diff --git a/src/lsp/cxx/lsp/types.cc b/src/lsp/cxx/lsp/types.cc index c824a3a8..cf3dcf8a 100644 --- a/src/lsp/cxx/lsp/types.cc +++ b/src/lsp/cxx/lsp/types.cc @@ -4974,10 +4974,10 @@ InitializeParams::operator bool() const { return true; } -auto InitializeParams::processId() const -> std::variant { +auto InitializeParams::processId() const -> std::variant { auto& value = (*repr_)["processId"]; - std::variant result; + std::variant result; details::try_emplace(result, value); @@ -5079,12 +5079,12 @@ auto InitializeParams::workspaceFolders() const return result; } -auto InitializeParams::processId(std::variant processId) +auto InitializeParams::processId(std::variant processId) -> InitializeParams& { struct { json* repr_; - void operator()(int processId) { + void operator()(long processId) { (*repr_)["processId"] = std::move(processId); } @@ -5824,7 +5824,7 @@ auto PublishDiagnosticsParams::uri() const -> std::string { return value.get(); } -auto PublishDiagnosticsParams::version() const -> std::optional { +auto PublishDiagnosticsParams::version() const -> std::optional { if (!repr_->contains("version")) return std::nullopt; auto& value = (*repr_)["version"]; @@ -5847,7 +5847,7 @@ auto PublishDiagnosticsParams::uri(std::string uri) return *this; } -auto PublishDiagnosticsParams::version(std::optional version) +auto PublishDiagnosticsParams::version(std::optional version) -> PublishDiagnosticsParams& { if (!version.has_value()) { repr_->erase("version"); @@ -10105,21 +10105,21 @@ CancelParams::operator bool() const { return true; } -auto CancelParams::id() const -> std::variant { +auto CancelParams::id() const -> std::variant { auto& value = (*repr_)["id"]; - std::variant result; + std::variant result; details::try_emplace(result, value); return result; } -auto CancelParams::id(std::variant id) -> CancelParams& { +auto CancelParams::id(std::variant id) -> CancelParams& { struct { json* repr_; - void operator()(int id) { (*repr_)["id"] = std::move(id); } + void operator()(long id) { (*repr_)["id"] = std::move(id); } void operator()(std::string id) { (*repr_)["id"] = std::move(id); } } v{repr_}; @@ -11414,7 +11414,7 @@ InlineValueContext::operator bool() const { return true; } -auto InlineValueContext::frameId() const -> int { +auto InlineValueContext::frameId() const -> long { auto& value = (*repr_)["frameId"]; if (value.is_null()) value = 0; @@ -11428,7 +11428,7 @@ auto InlineValueContext::stoppedLocation() const -> Range { return Range(value); } -auto InlineValueContext::frameId(int frameId) -> InlineValueContext& { +auto InlineValueContext::frameId(long frameId) -> InlineValueContext& { (*repr_)["frameId"] = std::move(frameId); return *this; } @@ -12140,7 +12140,7 @@ auto NotebookDocument::notebookType() const -> std::string { return value.get(); } -auto NotebookDocument::version() const -> int { +auto NotebookDocument::version() const -> long { auto& value = (*repr_)["version"]; if (value.is_null()) value = 0; @@ -12175,7 +12175,7 @@ auto NotebookDocument::notebookType(std::string notebookType) return *this; } -auto NotebookDocument::version(int version) -> NotebookDocument& { +auto NotebookDocument::version(long version) -> NotebookDocument& { (*repr_)["version"] = std::move(version); return *this; } @@ -12223,7 +12223,7 @@ auto TextDocumentItem::languageId() const -> LanguageKind { lsp_runtime_error("invalid value for LanguageKind enumeration"); } -auto TextDocumentItem::version() const -> int { +auto TextDocumentItem::version() const -> long { auto& value = (*repr_)["version"]; if (value.is_null()) value = 0; @@ -12250,7 +12250,7 @@ auto TextDocumentItem::languageId(LanguageKind languageId) return *this; } -auto TextDocumentItem::version(int version) -> TextDocumentItem& { +auto TextDocumentItem::version(long version) -> TextDocumentItem& { (*repr_)["version"] = std::move(version); return *this; } @@ -12311,7 +12311,7 @@ VersionedNotebookDocumentIdentifier::operator bool() const { return true; } -auto VersionedNotebookDocumentIdentifier::version() const -> int { +auto VersionedNotebookDocumentIdentifier::version() const -> long { auto& value = (*repr_)["version"]; if (value.is_null()) value = 0; @@ -12327,7 +12327,7 @@ auto VersionedNotebookDocumentIdentifier::uri() const -> std::string { return value.get(); } -auto VersionedNotebookDocumentIdentifier::version(int version) +auto VersionedNotebookDocumentIdentifier::version(long version) -> VersionedNotebookDocumentIdentifier& { (*repr_)["version"] = std::move(version); return *this; @@ -12614,10 +12614,11 @@ _InitializeParams::operator bool() const { return true; } -auto _InitializeParams::processId() const -> std::variant { +auto _InitializeParams::processId() const + -> std::variant { auto& value = (*repr_)["processId"]; - std::variant result; + std::variant result; details::try_emplace(result, value); @@ -12706,12 +12707,12 @@ auto _InitializeParams::workDoneToken() const -> std::optional { return result; } -auto _InitializeParams::processId(std::variant processId) +auto _InitializeParams::processId(std::variant processId) -> _InitializeParams& { struct { json* repr_; - void operator()(int processId) { + void operator()(long processId) { (*repr_)["processId"] = std::move(processId); } @@ -14218,7 +14219,7 @@ VersionedTextDocumentIdentifier::operator bool() const { return true; } -auto VersionedTextDocumentIdentifier::version() const -> int { +auto VersionedTextDocumentIdentifier::version() const -> long { auto& value = (*repr_)["version"]; if (value.is_null()) value = 0; @@ -14234,7 +14235,7 @@ auto VersionedTextDocumentIdentifier::uri() const -> std::string { return value.get(); } -auto VersionedTextDocumentIdentifier::version(int version) +auto VersionedTextDocumentIdentifier::version(long version) -> VersionedTextDocumentIdentifier& { (*repr_)["version"] = std::move(version); return *this; @@ -14362,12 +14363,13 @@ auto Diagnostic::severity() const -> std::optional { return DiagnosticSeverity(value); } -auto Diagnostic::code() const -> std::optional> { +auto Diagnostic::code() const + -> std::optional> { if (!repr_->contains("code")) return std::nullopt; auto& value = (*repr_)["code"]; - std::variant result; + std::variant result; details::try_emplace(result, value); @@ -14443,7 +14445,7 @@ auto Diagnostic::severity(std::optional severity) return *this; } -auto Diagnostic::code(std::optional> code) +auto Diagnostic::code(std::optional> code) -> Diagnostic& { if (!code.has_value()) { repr_->erase("code"); @@ -14453,7 +14455,7 @@ auto Diagnostic::code(std::optional> code) struct { json* repr_; - void operator()(int code) { (*repr_)["code"] = std::move(code); } + void operator()(long code) { (*repr_)["code"] = std::move(code); } void operator()(std::string code) { (*repr_)["code"] = std::move(code); } } v{repr_}; @@ -16158,10 +16160,10 @@ OptionalVersionedTextDocumentIdentifier::operator bool() const { } auto OptionalVersionedTextDocumentIdentifier::version() const - -> std::variant { + -> std::variant { auto& value = (*repr_)["version"]; - std::variant result; + std::variant result; details::try_emplace(result, value); @@ -16177,12 +16179,12 @@ auto OptionalVersionedTextDocumentIdentifier::uri() const -> std::string { } auto OptionalVersionedTextDocumentIdentifier::version( - std::variant version) + std::variant version) -> OptionalVersionedTextDocumentIdentifier& { struct { json* repr_; - void operator()(int version) { (*repr_)["version"] = std::move(version); } + void operator()(long version) { (*repr_)["version"] = std::move(version); } void operator()(std::nullptr_t version) { (*repr_)["version"] = std::move(version); @@ -16555,10 +16557,10 @@ auto WorkspaceFullDocumentDiagnosticReport::uri() const -> std::string { } auto WorkspaceFullDocumentDiagnosticReport::version() const - -> std::variant { + -> std::variant { auto& value = (*repr_)["version"]; - std::variant result; + std::variant result; details::try_emplace(result, value); @@ -16599,12 +16601,12 @@ auto WorkspaceFullDocumentDiagnosticReport::uri(std::string uri) } auto WorkspaceFullDocumentDiagnosticReport::version( - std::variant version) + std::variant version) -> WorkspaceFullDocumentDiagnosticReport& { struct { json* repr_; - void operator()(int version) { (*repr_)["version"] = std::move(version); } + void operator()(long version) { (*repr_)["version"] = std::move(version); } void operator()(std::nullptr_t version) { (*repr_)["version"] = std::move(version); @@ -16659,10 +16661,10 @@ auto WorkspaceUnchangedDocumentDiagnosticReport::uri() const -> std::string { } auto WorkspaceUnchangedDocumentDiagnosticReport::version() const - -> std::variant { + -> std::variant { auto& value = (*repr_)["version"]; - std::variant result; + std::variant result; details::try_emplace(result, value); @@ -16693,12 +16695,12 @@ auto WorkspaceUnchangedDocumentDiagnosticReport::uri(std::string uri) } auto WorkspaceUnchangedDocumentDiagnosticReport::version( - std::variant version) + std::variant version) -> WorkspaceUnchangedDocumentDiagnosticReport& { struct { json* repr_; - void operator()(int version) { (*repr_)["version"] = std::move(version); } + void operator()(long version) { (*repr_)["version"] = std::move(version); } void operator()(std::nullptr_t version) { (*repr_)["version"] = std::move(version); diff --git a/src/lsp/cxx/lsp/types.h b/src/lsp/cxx/lsp/types.h index 0f92584f..85b2724a 100644 --- a/src/lsp/cxx/lsp/types.h +++ b/src/lsp/cxx/lsp/types.h @@ -2533,7 +2533,7 @@ class InitializeParams final : public LSPObject { explicit operator bool() const; - [[nodiscard]] auto processId() const -> std::variant; + [[nodiscard]] auto processId() const -> std::variant; template [[nodiscard]] auto processId() -> T { @@ -2610,7 +2610,7 @@ class InitializeParams final : public LSPObject { return T(value); } - auto processId(std::variant processId) + auto processId(std::variant processId) -> InitializeParams&; auto clientInfo(std::optional clientInfo) -> InitializeParams&; @@ -2959,7 +2959,7 @@ class PublishDiagnosticsParams final : public LSPObject { [[nodiscard]] auto uri() const -> std::string; - [[nodiscard]] auto version() const -> std::optional; + [[nodiscard]] auto version() const -> std::optional; template [[nodiscard]] auto version() -> T { @@ -2971,7 +2971,7 @@ class PublishDiagnosticsParams final : public LSPObject { auto uri(std::string uri) -> PublishDiagnosticsParams&; - auto version(std::optional version) -> PublishDiagnosticsParams&; + auto version(std::optional version) -> PublishDiagnosticsParams&; auto diagnostics(Vector diagnostics) -> PublishDiagnosticsParams&; }; @@ -5197,7 +5197,7 @@ class CancelParams final : public LSPObject { explicit operator bool() const; - [[nodiscard]] auto id() const -> std::variant; + [[nodiscard]] auto id() const -> std::variant; template [[nodiscard]] auto id() -> T { @@ -5205,7 +5205,7 @@ class CancelParams final : public LSPObject { return T(value); } - auto id(std::variant id) -> CancelParams&; + auto id(std::variant id) -> CancelParams&; }; class ProgressParams final : public LSPObject { @@ -5909,11 +5909,11 @@ class InlineValueContext final : public LSPObject { explicit operator bool() const; - [[nodiscard]] auto frameId() const -> int; + [[nodiscard]] auto frameId() const -> long; [[nodiscard]] auto stoppedLocation() const -> Range; - auto frameId(int frameId) -> InlineValueContext&; + auto frameId(long frameId) -> InlineValueContext&; auto stoppedLocation(Range stoppedLocation) -> InlineValueContext&; }; @@ -6263,7 +6263,7 @@ class NotebookDocument final : public LSPObject { [[nodiscard]] auto notebookType() const -> std::string; - [[nodiscard]] auto version() const -> int; + [[nodiscard]] auto version() const -> long; [[nodiscard]] auto metadata() const -> std::optional; @@ -6279,7 +6279,7 @@ class NotebookDocument final : public LSPObject { auto notebookType(std::string notebookType) -> NotebookDocument&; - auto version(int version) -> NotebookDocument&; + auto version(long version) -> NotebookDocument&; auto metadata(std::optional metadata) -> NotebookDocument&; @@ -6296,7 +6296,7 @@ class TextDocumentItem final : public LSPObject { [[nodiscard]] auto languageId() const -> LanguageKind; - [[nodiscard]] auto version() const -> int; + [[nodiscard]] auto version() const -> long; [[nodiscard]] auto text() const -> std::string; @@ -6304,7 +6304,7 @@ class TextDocumentItem final : public LSPObject { auto languageId(LanguageKind languageId) -> TextDocumentItem&; - auto version(int version) -> TextDocumentItem&; + auto version(long version) -> TextDocumentItem&; auto text(std::string text) -> TextDocumentItem&; }; @@ -6340,11 +6340,11 @@ class VersionedNotebookDocumentIdentifier final : public LSPObject { explicit operator bool() const; - [[nodiscard]] auto version() const -> int; + [[nodiscard]] auto version() const -> long; [[nodiscard]] auto uri() const -> std::string; - auto version(int version) -> VersionedNotebookDocumentIdentifier&; + auto version(long version) -> VersionedNotebookDocumentIdentifier&; auto uri(std::string uri) -> VersionedNotebookDocumentIdentifier&; }; @@ -6512,7 +6512,7 @@ class _InitializeParams final : public LSPObject { explicit operator bool() const; - [[nodiscard]] auto processId() const -> std::variant; + [[nodiscard]] auto processId() const -> std::variant; template [[nodiscard]] auto processId() -> T { @@ -6580,7 +6580,7 @@ class _InitializeParams final : public LSPObject { return T(value); } - auto processId(std::variant processId) + auto processId(std::variant processId) -> _InitializeParams&; auto clientInfo(std::optional clientInfo) -> _InitializeParams&; @@ -7141,11 +7141,11 @@ class VersionedTextDocumentIdentifier final : public LSPObject { explicit operator bool() const; - [[nodiscard]] auto version() const -> int; + [[nodiscard]] auto version() const -> long; [[nodiscard]] auto uri() const -> std::string; - auto version(int version) -> VersionedTextDocumentIdentifier&; + auto version(long version) -> VersionedTextDocumentIdentifier&; auto uri(std::string uri) -> VersionedTextDocumentIdentifier&; }; @@ -7220,7 +7220,7 @@ class Diagnostic final : public LSPObject { } [[nodiscard]] auto code() const - -> std::optional>; + -> std::optional>; template [[nodiscard]] auto code() -> T { @@ -7275,7 +7275,7 @@ class Diagnostic final : public LSPObject { auto severity(std::optional severity) -> Diagnostic&; - auto code(std::optional> code) -> Diagnostic&; + auto code(std::optional> code) -> Diagnostic&; auto codeDescription(std::optional codeDescription) -> Diagnostic&; @@ -8307,7 +8307,7 @@ class OptionalVersionedTextDocumentIdentifier final : public LSPObject { explicit operator bool() const; - [[nodiscard]] auto version() const -> std::variant; + [[nodiscard]] auto version() const -> std::variant; template [[nodiscard]] auto version() -> T { @@ -8317,7 +8317,7 @@ class OptionalVersionedTextDocumentIdentifier final : public LSPObject { [[nodiscard]] auto uri() const -> std::string; - auto version(std::variant version) + auto version(std::variant version) -> OptionalVersionedTextDocumentIdentifier&; auto uri(std::string uri) -> OptionalVersionedTextDocumentIdentifier&; @@ -8517,7 +8517,7 @@ class WorkspaceFullDocumentDiagnosticReport final : public LSPObject { [[nodiscard]] auto uri() const -> std::string; - [[nodiscard]] auto version() const -> std::variant; + [[nodiscard]] auto version() const -> std::variant; template [[nodiscard]] auto version() -> T { @@ -8539,7 +8539,7 @@ class WorkspaceFullDocumentDiagnosticReport final : public LSPObject { auto uri(std::string uri) -> WorkspaceFullDocumentDiagnosticReport&; - auto version(std::variant version) + auto version(std::variant version) -> WorkspaceFullDocumentDiagnosticReport&; auto kind(std::string kind) -> WorkspaceFullDocumentDiagnosticReport&; @@ -8559,7 +8559,7 @@ class WorkspaceUnchangedDocumentDiagnosticReport final : public LSPObject { [[nodiscard]] auto uri() const -> std::string; - [[nodiscard]] auto version() const -> std::variant; + [[nodiscard]] auto version() const -> std::variant; template [[nodiscard]] auto version() -> T { @@ -8573,7 +8573,7 @@ class WorkspaceUnchangedDocumentDiagnosticReport final : public LSPObject { auto uri(std::string uri) -> WorkspaceUnchangedDocumentDiagnosticReport&; - auto version(std::variant version) + auto version(std::variant version) -> WorkspaceUnchangedDocumentDiagnosticReport&; auto kind(std::string kind) -> WorkspaceUnchangedDocumentDiagnosticReport&; diff --git a/tests/unit_tests/lsp/document_01.yml b/tests/unit_tests/lsp/document_01.yml index 36b7b99a..a657a336 100644 --- a/tests/unit_tests/lsp/document_01.yml +++ b/tests/unit_tests/lsp/document_01.yml @@ -1,8 +1,8 @@ # RUN: %cxx -lsp-test < %s | %filecheck %s -{ "method": "initialize" } +{ "method": "initialize", "id": 0 } -{ "method": "textDocument/didOpen", "params": { "textDocument": { "uri": "test:///source.cc", "version": 0, "text": "auto main() -> int;" } } } +{ "method": "textDocument/didOpen", "id": 1, "params": { "textDocument": { "uri": "test:///source.cc", "version": 0, "text": "auto main() -> int;" } } } # CHECK: "method": "textDocument/publishDiagnostics" # CHECK: "params": @@ -10,7 +10,7 @@ # CHECK: "uri": "test:///source.cc" # CHECK: "version": 0 -{ "method": "shutdown" } +{ "method": "shutdown", "id": 2 } { "method": "exit" } diff --git a/tests/unit_tests/lsp/lifecycle_01.yml b/tests/unit_tests/lsp/lifecycle_01.yml index f269afc8..6fec8633 100644 --- a/tests/unit_tests/lsp/lifecycle_01.yml +++ b/tests/unit_tests/lsp/lifecycle_01.yml @@ -1,6 +1,6 @@ # RUN: %cxx -lsp-test < %s | %filecheck %s -{ "method": "initialize" } +{ "method": "initialize", "id": 0 } # CHECK: "result": # CHECK: "capabilities": @@ -10,7 +10,7 @@ # CHECK: "name": # CHECK: "version": -{ "method": "shutdown" } +{ "method": "shutdown", "id": 1 } { "method": "exit" }