diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52906266..b49358bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,13 +36,15 @@ jobs: - name: Parse C++ source files (WASI toolchain) run: | - for i in src/parser/cxx/*.cc src/frontend/cxx/*.cc; do + for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do echo "Parsing $i" ./build/src/frontend/cxx \ -I src/parser \ + -I src/lsp \ -I build/_deps/fmt-src/include \ -I build/_deps/utfcpp-src/source \ -I build/_deps/flatbuffers-src/include \ + -I build/_deps/nlohmann_json-src/include \ -I build/src/parser \ -DCXX_NO_FILESYSTEM \ $i @@ -50,14 +52,16 @@ jobs: - name: Parse C++ source files (Linux toolchain) run: | - for i in src/parser/cxx/*.cc src/frontend/cxx/*.cc; do + for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do echo "Parsing $i" ./build/src/frontend/cxx \ -toolchain linux \ -I src/parser \ + -I src/lsp \ -I build/_deps/fmt-src/include \ -I build/_deps/utfcpp-src/source \ -I build/_deps/flatbuffers-src/include \ + -I build/_deps/nlohmann_json-src/include \ -I build/src/parser \ $i done @@ -153,14 +157,16 @@ jobs: - name: Parse C++ source files (macOS toolchain) run: | - for i in src/parser/cxx/*.cc src/frontend/cxx/*.cc; do + for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do echo "Parsing $i" ./build/src/frontend/cxx \ -toolchain macos \ -I src/parser \ + -I src/lsp \ -I build/_deps/fmt-src/include \ -I build/_deps/utfcpp-src/source \ -I build/_deps/flatbuffers-src/include \ + -I build/_deps/nlohmann_json-src/include \ -I build/src/parser \ $i done @@ -195,18 +201,21 @@ jobs: run: | PATH=~/wasmtime-v${{ env.WASMTIME_VERSION }}-x86_64-linux:$PATH - for i in src/parser/cxx/*.cc src/frontend/cxx/*.cc; do + for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do echo "Parsing $i" wasmtime \ --dir=src::/src \ --dir=build.wasi/_deps::/build.wasi/_deps \ --dir=build.wasi/src/parser::build.wasi/src/parser \ + --dir=build.wasi/src/lsp::build.wasi/src/lsp \ --dir=build.wasi/install/usr::/usr \ build.wasi/install/usr/bin/cxx.wasm \ -I src/parser \ + -I src/lsp \ -I build.wasi/_deps/fmt-src/include \ -I build.wasi/_deps/utfcpp-src/source \ -I build.wasi/_deps/flatbuffers-src/include \ + -I build.wasi/_deps/nlohmann_json-src/include \ -I build.wasi/src/parser \ -DCXX_NO_FILESYSTEM \ $i diff --git a/packages/cxx-gen-lsp/src/gen_requests_cc.ts b/packages/cxx-gen-lsp/src/gen_requests_cc.ts index 7ecf2e6e..461fd19a 100644 --- a/packages/cxx-gen-lsp/src/gen_requests_cc.ts +++ b/packages/cxx-gen-lsp/src/gen_requests_cc.ts @@ -88,23 +88,63 @@ class RequestGenerator { } if (isRequest(request) && request.result) { - const resultTypeName = typeName.replace(/Request$/, "Response"); + const responseTypeName = typeName.replace(/Request$/, "Response"); + const resultTypeName = toCppType(request.result); + this.emit(); - this.emit(`auto ${resultTypeName}::id() const -> std::variant {`); + this.emit(`auto ${responseTypeName}::id() const -> std::variant {`); 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 ${resultTypeName}::id(long id) -> ${resultTypeName}& {`); + this.emit(`auto ${responseTypeName}::id(long id) -> ${responseTypeName}& {`); this.emit(` (*repr_)["id"] = id;`); this.emit(` return *this;`); this.emit(`}`); this.emit(); - this.emit(`auto ${resultTypeName}::id(std::string id) -> ${resultTypeName}& {`); + 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(`}`); } }); diff --git a/packages/cxx-gen-lsp/src/gen_requests_h.ts b/packages/cxx-gen-lsp/src/gen_requests_h.ts index 824cdff4..82d4f906 100644 --- a/packages/cxx-gen-lsp/src/gen_requests_h.ts +++ b/packages/cxx-gen-lsp/src/gen_requests_h.ts @@ -44,6 +44,22 @@ export function gen_requests_h({ model, outputDirectory }: { model: MetaModel; o const requestsAndNotifications: Array = [...model.requests, ...model.notifications]; + emit(); + emit(`#define FOR_EACH_LSP_REQUEST_TYPE(V) \\`); + model.requests.forEach((request, index) => { + const nameWithoutSuffix = request.typeName.replace(/Request$/, ""); + const sep = index + 1 < model.requests.length ? " \\" : ""; + emit(` V(${nameWithoutSuffix}, "${request.method}")${sep}`); + }); + + emit(); + emit(`#define FOR_EACH_LSP_NOTIFICATION_TYPE(V) \\`); + model.notifications.forEach((notification, index) => { + const nameWithoutSuffix = notification.typeName.replace(/Notification$/, ""); + const sep = index + 1 < model.notifications.length ? " \\" : ""; + emit(` V(${nameWithoutSuffix}, "${notification.method}")${sep}`); + }); + requestsAndNotifications.forEach((request) => { const typeName = request.typeName; emit(); @@ -89,6 +105,35 @@ export function gen_requests_h({ model, outputDirectory }: { model: MetaModel; o } }); + emit(); + emit(`template `); + emit(`auto visitRequest(Visitor&& visitor, const LSPRequest& request, const std::string_view& method) -> void {`); + emit(`#define PROCESS_REQUEST_TYPE(NAME, METHOD) \\`); + emit(` if (method == METHOD) \\`); + emit(` return visitor(static_cast(request));`); + emit(); + emit(`FOR_EACH_LSP_REQUEST_TYPE(PROCESS_REQUEST_TYPE)`); + emit(); + emit(`#undef PROCESS_REQUEST_TYPE`); + emit(); + emit(` lsp_runtime_error("unknown request type");`); + emit(`}`); + emit(); + emit(`template `); + emit( + `auto visitNotification(Visitor&& visitor, const LSPRequest& notification, const std::string_view& method) -> void {`, + ); + emit(`#define PROCESS_NOTIFICATION_TYPE(NAME, METHOD) \\`); + emit(` if (method == METHOD) \\`); + emit(` return visitor(static_cast(notification));`); + emit(); + emit(`FOR_EACH_LSP_NOTIFICATION_TYPE(PROCESS_NOTIFICATION_TYPE)`); + emit(); + emit(`#undef PROCESS_NOTIFICATION_TYPE`); + emit(); + emit(` lsp_runtime_error("unknown notification type");`); + emit(`}`); + emit(); emit(`}`); diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index 66a7da1f..ead7ab4c 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -21,7 +21,7 @@ aux_source_directory(cxx SOURCES) add_executable(cxx ${SOURCES}) -target_link_libraries(cxx cxx-parser) +target_link_libraries(cxx cxx-parser cxx-lsp) if(EMSCRIPTEN) target_link_options(cxx PUBLIC diff --git a/src/frontend/cxx/cli.cc b/src/frontend/cxx/cli.cc index 94118999..78275efc 100644 --- a/src/frontend/cxx/cli.cc +++ b/src/frontend/cxx/cli.cc @@ -196,6 +196,8 @@ std::vector options{ {"-verify", "Verify the diagnostic messages", &CLI::opt_verify}, + {"-lsp", "Start Language Server", &CLI::opt_lsp}, + {"-v", "Show commands to run and use verbose output", &CLI::opt_v}, }; diff --git a/src/frontend/cxx/cli.h b/src/frontend/cxx/cli.h index e0822402..10ce3de0 100644 --- a/src/frontend/cxx/cli.h +++ b/src/frontend/cxx/cli.h @@ -73,6 +73,7 @@ class CLI { bool opt_verify = false; bool opt_v = false; bool opt_emit_ast = false; + bool opt_lsp = false; void parse(int& argc, char**& argv); diff --git a/src/frontend/cxx/frontend.cc b/src/frontend/cxx/frontend.cc index 5b40c2ff..c0032d14 100644 --- a/src/frontend/cxx/frontend.cc +++ b/src/frontend/cxx/frontend.cc @@ -37,6 +37,7 @@ #include #include "ast_printer.h" +#include "lsp_server.h" #include "verify_diagnostics_client.h" // std @@ -304,7 +305,7 @@ auto main(int argc, char* argv[]) -> int { const auto& inputFiles = cli.positionals(); - if (inputFiles.empty()) { + if (!cli.opt_lsp && inputFiles.empty()) { std::cerr << "cxx: no input files" << std::endl << "Usage: cxx [options] file..." << std::endl; return EXIT_FAILURE; @@ -312,9 +313,13 @@ auto main(int argc, char* argv[]) -> int { int existStatus = EXIT_SUCCESS; - for (const auto& fileName : inputFiles) { - if (!runOnFile(cli, fileName)) { - existStatus = EXIT_FAILURE; + if (cli.opt_lsp) { + existStatus = lsp::startServer(cli); + } else { + for (const auto& fileName : inputFiles) { + if (!runOnFile(cli, fileName)) { + existStatus = EXIT_FAILURE; + } } } diff --git a/src/frontend/cxx/lsp_server.cc b/src/frontend/cxx/lsp_server.cc new file mode 100644 index 00000000..0793bb09 --- /dev/null +++ b/src/frontend/cxx/lsp_server.cc @@ -0,0 +1,310 @@ +// Copyright (c) 2024 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include "lsp_server.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace cxx::lsp { + +struct Header { + std::string name; + std::string value; +}; + +} // namespace cxx::lsp + +template <> +struct std::less { + using is_transparent = void; + + auto operator()(const cxx::lsp::Header& lhs, + const cxx::lsp::Header& rhs) const -> bool { + return lhs.name < rhs.name; + } + + auto operator()(const cxx::lsp::Header& lhs, + const std::string_view& rhs) const -> bool { + return lhs.name < rhs; + } + + auto operator()(const std::string_view& lhs, + const cxx::lsp::Header& rhs) const -> bool { + return lhs < rhs.name; + } +}; + +namespace cxx::lsp { + +using Headers = std::set
; + +auto readHeaders(std::istream& input) -> Headers { + Headers headers; + + std::string line; + + while (std::getline(input, line)) { + if (line.empty() || line == "\r") { + break; + } + + const auto pos = line.find_first_of(':'); + + if (pos == std::string::npos) { + continue; + } + + auto name = line.substr(0, pos); + auto value = line.substr(pos + 1); + + // trim whitespace + name.erase(name.find_last_not_of(" \t\r\n") + 1); + value.erase(0, value.find_first_not_of(" \t\r\n")); + value.erase(value.find_last_not_of(" \t\r\n") + 1); + + headers.insert({name, value}); + } + + return headers; +} + +void sendToClient(const json& message, std::ostream& output = std::cout) { + const auto text = message.dump(); + output << "Content-Length: " << text.size() << "\r\n\r\n"; + output << text; + output.flush(); +}; + +struct Input { + struct Diagnostics final : cxx::DiagnosticsClient { + json messages = json::array(); + Vector diagnostics{messages}; + + void report(const cxx::Diagnostic& diag) override { + std::string_view fileName; + std::uint32_t line = 0; + std::uint32_t column = 0; + + preprocessor()->getTokenStartPosition(diag.token(), &line, &column, + &fileName); + + std::uint32_t endLine = 0; + std::uint32_t endColumn = 0; + + preprocessor()->getTokenEndPosition(diag.token(), &endLine, &endColumn, + nullptr); + + auto tmp = json::object(); + + auto d = diagnostics.emplace_back(); + + int s = std::max(int(line) - 1, 0); + int sc = std::max(int(column) - 1, 0); + int e = std::max(int(endLine) - 1, 0); + int ec = std::max(int(endColumn) - 1, 0); + + d.message(diag.message()); + d.range().start(lsp::Position(tmp).line(s).character(sc)); + d.range().end(lsp::Position(tmp).line(e).character(ec)); + } + }; + + const CLI& cli; + Control control; + Diagnostics diagnosticsClient; + TranslationUnit unit; + std::unique_ptr toolchain; + + Input(const CLI& cli) : cli(cli), unit(&control, &diagnosticsClient) {} + + void parse(std::string source, std::string fileName) { + configure(); + + unit.setSource(std::move(source), fileName); + + auto preprocessor = unit.preprocessor(); + preprocessor->squeeze(); + + unit.parse(ParserConfiguration{ + .checkTypes = cli.opt_fcheck, + .fuzzyTemplateResolution = true, + .staticAssert = cli.opt_fstatic_assert || cli.opt_fcheck, + .reflect = !cli.opt_fno_reflect, + .templates = cli.opt_ftemplates, + }); + } + + private: + void configure() { + auto preprocesor = unit.preprocessor(); + + auto toolchainId = cli.getSingle("-toolchain"); + + if (!toolchainId) { + toolchainId = "wasm32"; + } + + if (toolchainId == "darwin" || toolchainId == "macos") { + toolchain = std::make_unique(preprocesor); + } else if (toolchainId == "wasm32") { + auto wasmToolchain = std::make_unique(preprocesor); + + fs::path app_dir; + +#if __wasi__ + app_dir = fs::path("/usr/bin/"); +#elif !defined(CXX_NO_FILESYSTEM) + app_dir = std::filesystem::canonical( + std::filesystem::path(cli.app_name).remove_filename()); +#elif __unix__ || __APPLE__ + char* app_name = realpath(cli.app_name.c_str(), nullptr); + app_dir = fs::path(app_name).remove_filename().string(); + std::free(app_name); +#endif + + wasmToolchain->setAppdir(app_dir.string()); + + if (auto paths = cli.get("--sysroot"); !paths.empty()) { + wasmToolchain->setSysroot(paths.back()); + } else { + auto sysroot_dir = app_dir / std::string("../lib/wasi-sysroot"); + wasmToolchain->setSysroot(sysroot_dir.string()); + } + + toolchain = std::move(wasmToolchain); + } else if (toolchainId == "linux") { + std::string host; +#ifdef __aarch64__ + host = "aarch64"; +#elif __x86_64__ + host = "x86_64"; +#endif + + std::string arch = cli.getSingle("-arch").value_or(host); + toolchain = std::make_unique(preprocesor, arch); + } else if (toolchainId == "windows") { + auto windowsToolchain = std::make_unique(preprocesor); + + if (auto paths = cli.get("-vctoolsdir"); !paths.empty()) { + windowsToolchain->setVctoolsdir(paths.back()); + } + + if (auto paths = cli.get("-winsdkdir"); !paths.empty()) { + windowsToolchain->setWinsdkdir(paths.back()); + } + + if (auto versions = cli.get("-winsdkversion"); !versions.empty()) { + windowsToolchain->setWinsdkversion(versions.back()); + } + + toolchain = std::move(windowsToolchain); + } + + if (toolchain) { + control.setMemoryLayout(toolchain->memoryLayout()); + + if (!cli.opt_nostdinc) toolchain->addSystemIncludePaths(); + + if (!cli.opt_nostdincpp) toolchain->addSystemCppIncludePaths(); + + toolchain->addPredefinedMacros(); + } + + for (const auto& path : cli.get("-I")) { + preprocesor->addSystemIncludePath(path); + } + + if (cli.opt_v) { + std::cerr << std::format("#include <...> search starts here:\n"); + const auto& paths = preprocesor->systemIncludePaths(); + for (auto it = rbegin(paths); it != rend(paths); ++it) { + std::cerr << std::format(" {}\n", *it); + } + std::cerr << std::format("End of search list.\n"); + } + + for (const auto& macro : cli.get("-D")) { + auto sep = macro.find_first_of("="); + + if (sep == std::string::npos) { + preprocesor->defineMacro(macro, "1"); + } else { + preprocesor->defineMacro(macro.substr(0, sep), macro.substr(sep + 1)); + } + } + + for (const auto& macro : cli.get("-U")) { + preprocesor->undefMacro(macro); + } + + std::cerr << "Starting LSP server\n"; + } +}; + +auto nextRequest() -> std::optional { + auto& input = std::cin; + + const auto headers = readHeaders(input); + + // Get Content-Length + const auto it = headers.find("Content-Length"); + + if (it == headers.end()) { + return std::nullopt; + }; + + const auto contentLength = std::stoi(it->value); + + // Read content + std::string content(contentLength, '\0'); + input.read(content.data(), content.size()); + + // Parse JSON + auto request = json::parse(content); + return request; +} + +int startServer(const CLI& cli) { + cxx_runtime_error("not implemented"); + return 0; +} + +} // namespace cxx::lsp diff --git a/src/frontend/cxx/lsp_server.h b/src/frontend/cxx/lsp_server.h new file mode 100644 index 00000000..82b2fa5c --- /dev/null +++ b/src/frontend/cxx/lsp_server.h @@ -0,0 +1,29 @@ +// Copyright (c) 2024 Roberto Raggi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include "cli.h" + +namespace cxx::lsp { + +int startServer(const CLI& cli); + +} diff --git a/src/lsp/cxx/lsp/requests.cc b/src/lsp/cxx/lsp/requests.cc index 7371a020..62c390f8 100644 --- a/src/lsp/cxx/lsp/requests.cc +++ b/src/lsp/cxx/lsp/requests.cc @@ -77,6 +77,18 @@ auto ImplementationResponse::id(std::string id) -> ImplementationResponse& { return *this; } +auto ImplementationResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("ImplementationResponse::result() - not implemented yet"); +} + +auto ImplementationResponse::result( + std::variant, std::nullptr_t> result) + -> ImplementationResponse& { + lsp_runtime_error("ImplementationResponse::result() - not implemented yet"); + return *this; +} + auto TypeDefinitionRequest::method() const -> std::string { return repr_->at("method"); } @@ -130,6 +142,18 @@ auto TypeDefinitionResponse::id(std::string id) -> TypeDefinitionResponse& { return *this; } +auto TypeDefinitionResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("TypeDefinitionResponse::result() - not implemented yet"); +} + +auto TypeDefinitionResponse::result( + std::variant, std::nullptr_t> result) + -> TypeDefinitionResponse& { + lsp_runtime_error("TypeDefinitionResponse::result() - not implemented yet"); + return *this; +} + auto WorkspaceFoldersRequest::method() const -> std::string { return repr_->at("method"); } @@ -172,6 +196,18 @@ auto WorkspaceFoldersResponse::id(std::string id) -> WorkspaceFoldersResponse& { return *this; } +auto WorkspaceFoldersResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("WorkspaceFoldersResponse::result() - not implemented yet"); +} + +auto WorkspaceFoldersResponse::result( + std::variant, std::nullptr_t> result) + -> WorkspaceFoldersResponse& { + lsp_runtime_error("WorkspaceFoldersResponse::result() - not implemented yet"); + return *this; +} + auto ConfigurationRequest::method() const -> std::string { return repr_->at("method"); } @@ -224,6 +260,16 @@ auto ConfigurationResponse::id(std::string id) -> ConfigurationResponse& { return *this; } +auto ConfigurationResponse::result() const -> Vector { + lsp_runtime_error("ConfigurationResponse::result() - not implemented yet"); +} + +auto ConfigurationResponse::result(Vector result) + -> ConfigurationResponse& { + lsp_runtime_error("ConfigurationResponse::result() - not implemented yet"); + return *this; +} + auto DocumentColorRequest::method() const -> std::string { return repr_->at("method"); } @@ -276,6 +322,16 @@ auto DocumentColorResponse::id(std::string id) -> DocumentColorResponse& { return *this; } +auto DocumentColorResponse::result() const -> Vector { + lsp_runtime_error("DocumentColorResponse::result() - not implemented yet"); +} + +auto DocumentColorResponse::result(Vector result) + -> DocumentColorResponse& { + lsp_runtime_error("DocumentColorResponse::result() - not implemented yet"); + return *this; +} + auto ColorPresentationRequest::method() const -> std::string { return repr_->at("method"); } @@ -330,6 +386,18 @@ auto ColorPresentationResponse::id(std::string id) return *this; } +auto ColorPresentationResponse::result() const -> Vector { + lsp_runtime_error( + "ColorPresentationResponse::result() - not implemented yet"); +} + +auto ColorPresentationResponse::result(Vector result) + -> ColorPresentationResponse& { + lsp_runtime_error( + "ColorPresentationResponse::result() - not implemented yet"); + return *this; +} + auto FoldingRangeRequest::method() const -> std::string { return repr_->at("method"); } @@ -382,6 +450,18 @@ auto FoldingRangeResponse::id(std::string id) -> FoldingRangeResponse& { return *this; } +auto FoldingRangeResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("FoldingRangeResponse::result() - not implemented yet"); +} + +auto FoldingRangeResponse::result( + std::variant, std::nullptr_t> result) + -> FoldingRangeResponse& { + lsp_runtime_error("FoldingRangeResponse::result() - not implemented yet"); + return *this; +} + auto FoldingRangeRefreshRequest::method() const -> std::string { return repr_->at("method"); } @@ -427,6 +507,16 @@ auto FoldingRangeRefreshResponse::id(std::string id) return *this; } +auto FoldingRangeRefreshResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto FoldingRangeRefreshResponse::result(std::nullptr_t result) + -> FoldingRangeRefreshResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto DeclarationRequest::method() const -> std::string { return repr_->at("method"); } @@ -479,6 +569,18 @@ auto DeclarationResponse::id(std::string id) -> DeclarationResponse& { return *this; } +auto DeclarationResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("DeclarationResponse::result() - not implemented yet"); +} + +auto DeclarationResponse::result( + std::variant, std::nullptr_t> result) + -> DeclarationResponse& { + lsp_runtime_error("DeclarationResponse::result() - not implemented yet"); + return *this; +} + auto SelectionRangeRequest::method() const -> std::string { return repr_->at("method"); } @@ -532,6 +634,18 @@ auto SelectionRangeResponse::id(std::string id) -> SelectionRangeResponse& { return *this; } +auto SelectionRangeResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("SelectionRangeResponse::result() - not implemented yet"); +} + +auto SelectionRangeResponse::result( + std::variant, std::nullptr_t> result) + -> SelectionRangeResponse& { + lsp_runtime_error("SelectionRangeResponse::result() - not implemented yet"); + return *this; +} + auto WorkDoneProgressCreateRequest::method() const -> std::string { return repr_->at("method"); } @@ -592,6 +706,16 @@ auto WorkDoneProgressCreateResponse::id(std::string id) return *this; } +auto WorkDoneProgressCreateResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto WorkDoneProgressCreateResponse::result(std::nullptr_t result) + -> WorkDoneProgressCreateResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto CallHierarchyPrepareRequest::method() const -> std::string { return repr_->at("method"); } @@ -650,6 +774,20 @@ auto CallHierarchyPrepareResponse::id(std::string id) return *this; } +auto CallHierarchyPrepareResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "CallHierarchyPrepareResponse::result() - not implemented yet"); +} + +auto CallHierarchyPrepareResponse::result( + std::variant, std::nullptr_t> result) + -> CallHierarchyPrepareResponse& { + lsp_runtime_error( + "CallHierarchyPrepareResponse::result() - not implemented yet"); + return *this; +} + auto CallHierarchyIncomingCallsRequest::method() const -> std::string { return repr_->at("method"); } @@ -711,6 +849,20 @@ auto CallHierarchyIncomingCallsResponse::id(std::string id) return *this; } +auto CallHierarchyIncomingCallsResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "CallHierarchyIncomingCallsResponse::result() - not implemented yet"); +} + +auto CallHierarchyIncomingCallsResponse::result( + std::variant, std::nullptr_t> result) + -> CallHierarchyIncomingCallsResponse& { + lsp_runtime_error( + "CallHierarchyIncomingCallsResponse::result() - not implemented yet"); + return *this; +} + auto CallHierarchyOutgoingCallsRequest::method() const -> std::string { return repr_->at("method"); } @@ -772,6 +924,20 @@ auto CallHierarchyOutgoingCallsResponse::id(std::string id) return *this; } +auto CallHierarchyOutgoingCallsResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "CallHierarchyOutgoingCallsResponse::result() - not implemented yet"); +} + +auto CallHierarchyOutgoingCallsResponse::result( + std::variant, std::nullptr_t> result) + -> CallHierarchyOutgoingCallsResponse& { + lsp_runtime_error( + "CallHierarchyOutgoingCallsResponse::result() - not implemented yet"); + return *this; +} + auto SemanticTokensRequest::method() const -> std::string { return repr_->at("method"); } @@ -825,6 +991,18 @@ auto SemanticTokensResponse::id(std::string id) -> SemanticTokensResponse& { return *this; } +auto SemanticTokensResponse::result() const + -> std::variant { + lsp_runtime_error("SemanticTokensResponse::result() - not implemented yet"); +} + +auto SemanticTokensResponse::result( + std::variant result) + -> SemanticTokensResponse& { + lsp_runtime_error("SemanticTokensResponse::result() - not implemented yet"); + return *this; +} + auto SemanticTokensDeltaRequest::method() const -> std::string { return repr_->at("method"); } @@ -881,6 +1059,20 @@ auto SemanticTokensDeltaResponse::id(std::string id) return *this; } +auto SemanticTokensDeltaResponse::result() const + -> std::variant { + lsp_runtime_error( + "SemanticTokensDeltaResponse::result() - not implemented yet"); +} + +auto SemanticTokensDeltaResponse::result( + std::variant result) + -> SemanticTokensDeltaResponse& { + lsp_runtime_error( + "SemanticTokensDeltaResponse::result() - not implemented yet"); + return *this; +} + auto SemanticTokensRangeRequest::method() const -> std::string { return repr_->at("method"); } @@ -937,6 +1129,20 @@ auto SemanticTokensRangeResponse::id(std::string id) return *this; } +auto SemanticTokensRangeResponse::result() const + -> std::variant { + lsp_runtime_error( + "SemanticTokensRangeResponse::result() - not implemented yet"); +} + +auto SemanticTokensRangeResponse::result( + std::variant result) + -> SemanticTokensRangeResponse& { + lsp_runtime_error( + "SemanticTokensRangeResponse::result() - not implemented yet"); + return *this; +} + auto SemanticTokensRefreshRequest::method() const -> std::string { return repr_->at("method"); } @@ -985,6 +1191,16 @@ auto SemanticTokensRefreshResponse::id(std::string id) return *this; } +auto SemanticTokensRefreshResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto SemanticTokensRefreshResponse::result(std::nullptr_t result) + -> SemanticTokensRefreshResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto ShowDocumentRequest::method() const -> std::string { return repr_->at("method"); } @@ -1037,6 +1253,17 @@ auto ShowDocumentResponse::id(std::string id) -> ShowDocumentResponse& { return *this; } +auto ShowDocumentResponse::result() const -> ShowDocumentResult { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return ShowDocumentResult(repr_->at("result")); // reference +} + +auto ShowDocumentResponse::result(ShowDocumentResult result) + -> ShowDocumentResponse& { + lsp_runtime_error("ShowDocumentResponse::result() - not implemented yet"); + return *this; +} + auto LinkedEditingRangeRequest::method() const -> std::string { return repr_->at("method"); } @@ -1092,6 +1319,20 @@ auto LinkedEditingRangeResponse::id(std::string id) return *this; } +auto LinkedEditingRangeResponse::result() const + -> std::variant { + lsp_runtime_error( + "LinkedEditingRangeResponse::result() - not implemented yet"); +} + +auto LinkedEditingRangeResponse::result( + std::variant result) + -> LinkedEditingRangeResponse& { + lsp_runtime_error( + "LinkedEditingRangeResponse::result() - not implemented yet"); + return *this; +} + auto WillCreateFilesRequest::method() const -> std::string { return repr_->at("method"); } @@ -1145,6 +1386,18 @@ auto WillCreateFilesResponse::id(std::string id) -> WillCreateFilesResponse& { return *this; } +auto WillCreateFilesResponse::result() const + -> std::variant { + lsp_runtime_error("WillCreateFilesResponse::result() - not implemented yet"); +} + +auto WillCreateFilesResponse::result( + std::variant result) + -> WillCreateFilesResponse& { + lsp_runtime_error("WillCreateFilesResponse::result() - not implemented yet"); + return *this; +} + auto WillRenameFilesRequest::method() const -> std::string { return repr_->at("method"); } @@ -1198,6 +1451,18 @@ auto WillRenameFilesResponse::id(std::string id) -> WillRenameFilesResponse& { return *this; } +auto WillRenameFilesResponse::result() const + -> std::variant { + lsp_runtime_error("WillRenameFilesResponse::result() - not implemented yet"); +} + +auto WillRenameFilesResponse::result( + std::variant result) + -> WillRenameFilesResponse& { + lsp_runtime_error("WillRenameFilesResponse::result() - not implemented yet"); + return *this; +} + auto WillDeleteFilesRequest::method() const -> std::string { return repr_->at("method"); } @@ -1251,6 +1516,18 @@ auto WillDeleteFilesResponse::id(std::string id) -> WillDeleteFilesResponse& { return *this; } +auto WillDeleteFilesResponse::result() const + -> std::variant { + lsp_runtime_error("WillDeleteFilesResponse::result() - not implemented yet"); +} + +auto WillDeleteFilesResponse::result( + std::variant result) + -> WillDeleteFilesResponse& { + lsp_runtime_error("WillDeleteFilesResponse::result() - not implemented yet"); + return *this; +} + auto MonikerRequest::method() const -> std::string { return repr_->at("method"); } @@ -1302,6 +1579,17 @@ auto MonikerResponse::id(std::string id) -> MonikerResponse& { return *this; } +auto MonikerResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("MonikerResponse::result() - not implemented yet"); +} + +auto MonikerResponse::result( + std::variant, std::nullptr_t> result) -> MonikerResponse& { + lsp_runtime_error("MonikerResponse::result() - not implemented yet"); + return *this; +} + auto TypeHierarchyPrepareRequest::method() const -> std::string { return repr_->at("method"); } @@ -1360,6 +1648,20 @@ auto TypeHierarchyPrepareResponse::id(std::string id) return *this; } +auto TypeHierarchyPrepareResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "TypeHierarchyPrepareResponse::result() - not implemented yet"); +} + +auto TypeHierarchyPrepareResponse::result( + std::variant, std::nullptr_t> result) + -> TypeHierarchyPrepareResponse& { + lsp_runtime_error( + "TypeHierarchyPrepareResponse::result() - not implemented yet"); + return *this; +} + auto TypeHierarchySupertypesRequest::method() const -> std::string { return repr_->at("method"); } @@ -1420,6 +1722,20 @@ auto TypeHierarchySupertypesResponse::id(std::string id) return *this; } +auto TypeHierarchySupertypesResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "TypeHierarchySupertypesResponse::result() - not implemented yet"); +} + +auto TypeHierarchySupertypesResponse::result( + std::variant, std::nullptr_t> result) + -> TypeHierarchySupertypesResponse& { + lsp_runtime_error( + "TypeHierarchySupertypesResponse::result() - not implemented yet"); + return *this; +} + auto TypeHierarchySubtypesRequest::method() const -> std::string { return repr_->at("method"); } @@ -1480,6 +1796,20 @@ auto TypeHierarchySubtypesResponse::id(std::string id) return *this; } +auto TypeHierarchySubtypesResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "TypeHierarchySubtypesResponse::result() - not implemented yet"); +} + +auto TypeHierarchySubtypesResponse::result( + std::variant, std::nullptr_t> result) + -> TypeHierarchySubtypesResponse& { + lsp_runtime_error( + "TypeHierarchySubtypesResponse::result() - not implemented yet"); + return *this; +} + auto InlineValueRequest::method() const -> std::string { return repr_->at("method"); } @@ -1532,6 +1862,18 @@ auto InlineValueResponse::id(std::string id) -> InlineValueResponse& { return *this; } +auto InlineValueResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("InlineValueResponse::result() - not implemented yet"); +} + +auto InlineValueResponse::result( + std::variant, std::nullptr_t> result) + -> InlineValueResponse& { + lsp_runtime_error("InlineValueResponse::result() - not implemented yet"); + return *this; +} + auto InlineValueRefreshRequest::method() const -> std::string { return repr_->at("method"); } @@ -1576,6 +1918,16 @@ auto InlineValueRefreshResponse::id(std::string id) return *this; } +auto InlineValueRefreshResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto InlineValueRefreshResponse::result(std::nullptr_t result) + -> InlineValueRefreshResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto InlayHintRequest::method() const -> std::string { return repr_->at("method"); } @@ -1627,6 +1979,18 @@ auto InlayHintResponse::id(std::string id) -> InlayHintResponse& { return *this; } +auto InlayHintResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("InlayHintResponse::result() - not implemented yet"); +} + +auto InlayHintResponse::result( + std::variant, std::nullptr_t> result) + -> InlayHintResponse& { + lsp_runtime_error("InlayHintResponse::result() - not implemented yet"); + return *this; +} + auto InlayHintResolveRequest::method() const -> std::string { return repr_->at("method"); } @@ -1680,6 +2044,17 @@ auto InlayHintResolveResponse::id(std::string id) -> InlayHintResolveResponse& { return *this; } +auto InlayHintResolveResponse::result() const -> InlayHint { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return InlayHint(repr_->at("result")); // reference +} + +auto InlayHintResolveResponse::result(InlayHint result) + -> InlayHintResolveResponse& { + lsp_runtime_error("InlayHintResolveResponse::result() - not implemented yet"); + return *this; +} + auto InlayHintRefreshRequest::method() const -> std::string { return repr_->at("method"); } @@ -1722,6 +2097,16 @@ auto InlayHintRefreshResponse::id(std::string id) -> InlayHintRefreshResponse& { return *this; } +auto InlayHintRefreshResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto InlayHintRefreshResponse::result(std::nullptr_t result) + -> InlayHintRefreshResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto DocumentDiagnosticRequest::method() const -> std::string { return repr_->at("method"); } @@ -1777,6 +2162,18 @@ auto DocumentDiagnosticResponse::id(std::string id) return *this; } +auto DocumentDiagnosticResponse::result() const -> DocumentDiagnosticReport { + lsp_runtime_error( + "DocumentDiagnosticResponse::result() - not implemented yet"); +} + +auto DocumentDiagnosticResponse::result(DocumentDiagnosticReport result) + -> DocumentDiagnosticResponse& { + lsp_runtime_error( + "DocumentDiagnosticResponse::result() - not implemented yet"); + return *this; +} + auto WorkspaceDiagnosticRequest::method() const -> std::string { return repr_->at("method"); } @@ -1833,6 +2230,18 @@ auto WorkspaceDiagnosticResponse::id(std::string id) return *this; } +auto WorkspaceDiagnosticResponse::result() const -> WorkspaceDiagnosticReport { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return WorkspaceDiagnosticReport(repr_->at("result")); // reference +} + +auto WorkspaceDiagnosticResponse::result(WorkspaceDiagnosticReport result) + -> WorkspaceDiagnosticResponse& { + lsp_runtime_error( + "WorkspaceDiagnosticResponse::result() - not implemented yet"); + return *this; +} + auto DiagnosticRefreshRequest::method() const -> std::string { return repr_->at("method"); } @@ -1876,6 +2285,16 @@ auto DiagnosticRefreshResponse::id(std::string id) return *this; } +auto DiagnosticRefreshResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto DiagnosticRefreshResponse::result(std::nullptr_t result) + -> DiagnosticRefreshResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto InlineCompletionRequest::method() const -> std::string { return repr_->at("method"); } @@ -1929,6 +2348,20 @@ auto InlineCompletionResponse::id(std::string id) -> InlineCompletionResponse& { return *this; } +auto InlineCompletionResponse::result() const + -> std::variant, + std::nullptr_t> { + lsp_runtime_error("InlineCompletionResponse::result() - not implemented yet"); +} + +auto InlineCompletionResponse::result( + std::variant, + std::nullptr_t> + result) -> InlineCompletionResponse& { + lsp_runtime_error("InlineCompletionResponse::result() - not implemented yet"); + return *this; +} + auto TextDocumentContentRequest::method() const -> std::string { return repr_->at("method"); } @@ -1985,6 +2418,18 @@ auto TextDocumentContentResponse::id(std::string id) return *this; } +auto TextDocumentContentResponse::result() const -> TextDocumentContentResult { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return TextDocumentContentResult(repr_->at("result")); // reference +} + +auto TextDocumentContentResponse::result(TextDocumentContentResult result) + -> TextDocumentContentResponse& { + lsp_runtime_error( + "TextDocumentContentResponse::result() - not implemented yet"); + return *this; +} + auto TextDocumentContentRefreshRequest::method() const -> std::string { return repr_->at("method"); } @@ -2046,6 +2491,16 @@ auto TextDocumentContentRefreshResponse::id(std::string id) return *this; } +auto TextDocumentContentRefreshResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto TextDocumentContentRefreshResponse::result(std::nullptr_t result) + -> TextDocumentContentRefreshResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto RegistrationRequest::method() const -> std::string { return repr_->at("method"); } @@ -2098,6 +2553,14 @@ auto RegistrationResponse::id(std::string id) -> RegistrationResponse& { return *this; } +auto RegistrationResponse::result() const -> std::nullptr_t { return nullptr; } + +auto RegistrationResponse::result(std::nullptr_t result) + -> RegistrationResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto UnregistrationRequest::method() const -> std::string { return repr_->at("method"); } @@ -2151,6 +2614,16 @@ auto UnregistrationResponse::id(std::string id) -> UnregistrationResponse& { return *this; } +auto UnregistrationResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto UnregistrationResponse::result(std::nullptr_t result) + -> UnregistrationResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto InitializeRequest::method() const -> std::string { return repr_->at("method"); } @@ -2202,6 +2675,17 @@ auto InitializeResponse::id(std::string id) -> InitializeResponse& { return *this; } +auto InitializeResponse::result() const -> InitializeResult { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return InitializeResult(repr_->at("result")); // reference +} + +auto InitializeResponse::result(InitializeResult result) + -> InitializeResponse& { + lsp_runtime_error("InitializeResponse::result() - not implemented yet"); + return *this; +} + auto ShutdownRequest::method() const -> std::string { return repr_->at("method"); } @@ -2243,6 +2727,13 @@ auto ShutdownResponse::id(std::string id) -> ShutdownResponse& { return *this; } +auto ShutdownResponse::result() const -> std::nullptr_t { return nullptr; } + +auto ShutdownResponse::result(std::nullptr_t result) -> ShutdownResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto ShowMessageRequest::method() const -> std::string { return repr_->at("method"); } @@ -2295,6 +2786,18 @@ auto ShowMessageResponse::id(std::string id) -> ShowMessageResponse& { return *this; } +auto ShowMessageResponse::result() const + -> std::variant { + lsp_runtime_error("ShowMessageResponse::result() - not implemented yet"); +} + +auto ShowMessageResponse::result( + std::variant result) + -> ShowMessageResponse& { + lsp_runtime_error("ShowMessageResponse::result() - not implemented yet"); + return *this; +} + auto WillSaveTextDocumentWaitUntilRequest::method() const -> std::string { return repr_->at("method"); } @@ -2356,6 +2859,20 @@ auto WillSaveTextDocumentWaitUntilResponse::id(std::string id) return *this; } +auto WillSaveTextDocumentWaitUntilResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "WillSaveTextDocumentWaitUntilResponse::result() - not implemented yet"); +} + +auto WillSaveTextDocumentWaitUntilResponse::result( + std::variant, std::nullptr_t> result) + -> WillSaveTextDocumentWaitUntilResponse& { + lsp_runtime_error( + "WillSaveTextDocumentWaitUntilResponse::result() - not implemented yet"); + return *this; +} + auto CompletionRequest::method() const -> std::string { return repr_->at("method"); } @@ -2407,6 +2924,18 @@ auto CompletionResponse::id(std::string id) -> CompletionResponse& { return *this; } +auto CompletionResponse::result() const + -> std::variant, CompletionList, std::nullptr_t> { + lsp_runtime_error("CompletionResponse::result() - not implemented yet"); +} + +auto CompletionResponse::result( + std::variant, CompletionList, std::nullptr_t> result) + -> CompletionResponse& { + lsp_runtime_error("CompletionResponse::result() - not implemented yet"); + return *this; +} + auto CompletionResolveRequest::method() const -> std::string { return repr_->at("method"); } @@ -2461,6 +2990,18 @@ auto CompletionResolveResponse::id(std::string id) return *this; } +auto CompletionResolveResponse::result() const -> CompletionItem { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return CompletionItem(repr_->at("result")); // reference +} + +auto CompletionResolveResponse::result(CompletionItem result) + -> CompletionResolveResponse& { + lsp_runtime_error( + "CompletionResolveResponse::result() - not implemented yet"); + return *this; +} + auto HoverRequest::method() const -> std::string { return repr_->at("method"); } auto HoverRequest::method(std::string method) -> HoverRequest& { @@ -2510,6 +3051,16 @@ auto HoverResponse::id(std::string id) -> HoverResponse& { return *this; } +auto HoverResponse::result() const -> std::variant { + lsp_runtime_error("HoverResponse::result() - not implemented yet"); +} + +auto HoverResponse::result(std::variant result) + -> HoverResponse& { + lsp_runtime_error("HoverResponse::result() - not implemented yet"); + return *this; +} + auto SignatureHelpRequest::method() const -> std::string { return repr_->at("method"); } @@ -2562,6 +3113,18 @@ auto SignatureHelpResponse::id(std::string id) -> SignatureHelpResponse& { return *this; } +auto SignatureHelpResponse::result() const + -> std::variant { + lsp_runtime_error("SignatureHelpResponse::result() - not implemented yet"); +} + +auto SignatureHelpResponse::result( + std::variant result) + -> SignatureHelpResponse& { + lsp_runtime_error("SignatureHelpResponse::result() - not implemented yet"); + return *this; +} + auto DefinitionRequest::method() const -> std::string { return repr_->at("method"); } @@ -2613,6 +3176,18 @@ auto DefinitionResponse::id(std::string id) -> DefinitionResponse& { return *this; } +auto DefinitionResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("DefinitionResponse::result() - not implemented yet"); +} + +auto DefinitionResponse::result( + std::variant, std::nullptr_t> result) + -> DefinitionResponse& { + lsp_runtime_error("DefinitionResponse::result() - not implemented yet"); + return *this; +} + auto ReferencesRequest::method() const -> std::string { return repr_->at("method"); } @@ -2664,6 +3239,18 @@ auto ReferencesResponse::id(std::string id) -> ReferencesResponse& { return *this; } +auto ReferencesResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("ReferencesResponse::result() - not implemented yet"); +} + +auto ReferencesResponse::result( + std::variant, std::nullptr_t> result) + -> ReferencesResponse& { + lsp_runtime_error("ReferencesResponse::result() - not implemented yet"); + return *this; +} + auto DocumentHighlightRequest::method() const -> std::string { return repr_->at("method"); } @@ -2718,6 +3305,20 @@ auto DocumentHighlightResponse::id(std::string id) return *this; } +auto DocumentHighlightResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "DocumentHighlightResponse::result() - not implemented yet"); +} + +auto DocumentHighlightResponse::result( + std::variant, std::nullptr_t> result) + -> DocumentHighlightResponse& { + lsp_runtime_error( + "DocumentHighlightResponse::result() - not implemented yet"); + return *this; +} + auto DocumentSymbolRequest::method() const -> std::string { return repr_->at("method"); } @@ -2771,6 +3372,20 @@ auto DocumentSymbolResponse::id(std::string id) -> DocumentSymbolResponse& { return *this; } +auto DocumentSymbolResponse::result() const + -> std::variant, Vector, + std::nullptr_t> { + lsp_runtime_error("DocumentSymbolResponse::result() - not implemented yet"); +} + +auto DocumentSymbolResponse::result( + std::variant, Vector, + std::nullptr_t> + result) -> DocumentSymbolResponse& { + lsp_runtime_error("DocumentSymbolResponse::result() - not implemented yet"); + return *this; +} + auto CodeActionRequest::method() const -> std::string { return repr_->at("method"); } @@ -2822,6 +3437,18 @@ auto CodeActionResponse::id(std::string id) -> CodeActionResponse& { return *this; } +auto CodeActionResponse::result() const + -> std::variant>, std::nullptr_t> { + lsp_runtime_error("CodeActionResponse::result() - not implemented yet"); +} + +auto CodeActionResponse::result( + std::variant>, std::nullptr_t> + result) -> CodeActionResponse& { + lsp_runtime_error("CodeActionResponse::result() - not implemented yet"); + return *this; +} + auto CodeActionResolveRequest::method() const -> std::string { return repr_->at("method"); } @@ -2876,6 +3503,18 @@ auto CodeActionResolveResponse::id(std::string id) return *this; } +auto CodeActionResolveResponse::result() const -> CodeAction { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return CodeAction(repr_->at("result")); // reference +} + +auto CodeActionResolveResponse::result(CodeAction result) + -> CodeActionResolveResponse& { + lsp_runtime_error( + "CodeActionResolveResponse::result() - not implemented yet"); + return *this; +} + auto WorkspaceSymbolRequest::method() const -> std::string { return repr_->at("method"); } @@ -2929,6 +3568,20 @@ auto WorkspaceSymbolResponse::id(std::string id) -> WorkspaceSymbolResponse& { return *this; } +auto WorkspaceSymbolResponse::result() const + -> std::variant, Vector, + std::nullptr_t> { + lsp_runtime_error("WorkspaceSymbolResponse::result() - not implemented yet"); +} + +auto WorkspaceSymbolResponse::result( + std::variant, Vector, + std::nullptr_t> + result) -> WorkspaceSymbolResponse& { + lsp_runtime_error("WorkspaceSymbolResponse::result() - not implemented yet"); + return *this; +} + auto WorkspaceSymbolResolveRequest::method() const -> std::string { return repr_->at("method"); } @@ -2988,6 +3641,18 @@ auto WorkspaceSymbolResolveResponse::id(std::string id) return *this; } +auto WorkspaceSymbolResolveResponse::result() const -> WorkspaceSymbol { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return WorkspaceSymbol(repr_->at("result")); // reference +} + +auto WorkspaceSymbolResolveResponse::result(WorkspaceSymbol result) + -> WorkspaceSymbolResolveResponse& { + lsp_runtime_error( + "WorkspaceSymbolResolveResponse::result() - not implemented yet"); + return *this; +} + auto CodeLensRequest::method() const -> std::string { return repr_->at("method"); } @@ -3039,6 +3704,18 @@ auto CodeLensResponse::id(std::string id) -> CodeLensResponse& { return *this; } +auto CodeLensResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("CodeLensResponse::result() - not implemented yet"); +} + +auto CodeLensResponse::result( + std::variant, std::nullptr_t> result) + -> CodeLensResponse& { + lsp_runtime_error("CodeLensResponse::result() - not implemented yet"); + return *this; +} + auto CodeLensResolveRequest::method() const -> std::string { return repr_->at("method"); } @@ -3092,6 +3769,17 @@ auto CodeLensResolveResponse::id(std::string id) -> CodeLensResolveResponse& { return *this; } +auto CodeLensResolveResponse::result() const -> CodeLens { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return CodeLens(repr_->at("result")); // reference +} + +auto CodeLensResolveResponse::result(CodeLens result) + -> CodeLensResolveResponse& { + lsp_runtime_error("CodeLensResolveResponse::result() - not implemented yet"); + return *this; +} + auto CodeLensRefreshRequest::method() const -> std::string { return repr_->at("method"); } @@ -3134,6 +3822,16 @@ auto CodeLensRefreshResponse::id(std::string id) -> CodeLensRefreshResponse& { return *this; } +auto CodeLensRefreshResponse::result() const -> std::nullptr_t { + return nullptr; +} + +auto CodeLensRefreshResponse::result(std::nullptr_t result) + -> CodeLensRefreshResponse& { + (*repr_)["result"] = std::move(result); // base + return *this; +} + auto DocumentLinkRequest::method() const -> std::string { return repr_->at("method"); } @@ -3186,6 +3884,18 @@ auto DocumentLinkResponse::id(std::string id) -> DocumentLinkResponse& { return *this; } +auto DocumentLinkResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error("DocumentLinkResponse::result() - not implemented yet"); +} + +auto DocumentLinkResponse::result( + std::variant, std::nullptr_t> result) + -> DocumentLinkResponse& { + lsp_runtime_error("DocumentLinkResponse::result() - not implemented yet"); + return *this; +} + auto DocumentLinkResolveRequest::method() const -> std::string { return repr_->at("method"); } @@ -3242,6 +3952,18 @@ auto DocumentLinkResolveResponse::id(std::string id) return *this; } +auto DocumentLinkResolveResponse::result() const -> DocumentLink { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return DocumentLink(repr_->at("result")); // reference +} + +auto DocumentLinkResolveResponse::result(DocumentLink result) + -> DocumentLinkResolveResponse& { + lsp_runtime_error( + "DocumentLinkResolveResponse::result() - not implemented yet"); + return *this; +} + auto DocumentFormattingRequest::method() const -> std::string { return repr_->at("method"); } @@ -3297,6 +4019,20 @@ auto DocumentFormattingResponse::id(std::string id) return *this; } +auto DocumentFormattingResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "DocumentFormattingResponse::result() - not implemented yet"); +} + +auto DocumentFormattingResponse::result( + std::variant, std::nullptr_t> result) + -> DocumentFormattingResponse& { + lsp_runtime_error( + "DocumentFormattingResponse::result() - not implemented yet"); + return *this; +} + auto DocumentRangeFormattingRequest::method() const -> std::string { return repr_->at("method"); } @@ -3357,6 +4093,20 @@ auto DocumentRangeFormattingResponse::id(std::string id) return *this; } +auto DocumentRangeFormattingResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "DocumentRangeFormattingResponse::result() - not implemented yet"); +} + +auto DocumentRangeFormattingResponse::result( + std::variant, std::nullptr_t> result) + -> DocumentRangeFormattingResponse& { + lsp_runtime_error( + "DocumentRangeFormattingResponse::result() - not implemented yet"); + return *this; +} + auto DocumentRangesFormattingRequest::method() const -> std::string { return repr_->at("method"); } @@ -3417,6 +4167,20 @@ auto DocumentRangesFormattingResponse::id(std::string id) return *this; } +auto DocumentRangesFormattingResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "DocumentRangesFormattingResponse::result() - not implemented yet"); +} + +auto DocumentRangesFormattingResponse::result( + std::variant, std::nullptr_t> result) + -> DocumentRangesFormattingResponse& { + lsp_runtime_error( + "DocumentRangesFormattingResponse::result() - not implemented yet"); + return *this; +} + auto DocumentOnTypeFormattingRequest::method() const -> std::string { return repr_->at("method"); } @@ -3477,6 +4241,20 @@ auto DocumentOnTypeFormattingResponse::id(std::string id) return *this; } +auto DocumentOnTypeFormattingResponse::result() const + -> std::variant, std::nullptr_t> { + lsp_runtime_error( + "DocumentOnTypeFormattingResponse::result() - not implemented yet"); +} + +auto DocumentOnTypeFormattingResponse::result( + std::variant, std::nullptr_t> result) + -> DocumentOnTypeFormattingResponse& { + lsp_runtime_error( + "DocumentOnTypeFormattingResponse::result() - not implemented yet"); + return *this; +} + auto RenameRequest::method() const -> std::string { return repr_->at("method"); } @@ -3528,6 +4306,17 @@ auto RenameResponse::id(std::string id) -> RenameResponse& { return *this; } +auto RenameResponse::result() const + -> std::variant { + lsp_runtime_error("RenameResponse::result() - not implemented yet"); +} + +auto RenameResponse::result(std::variant result) + -> RenameResponse& { + lsp_runtime_error("RenameResponse::result() - not implemented yet"); + return *this; +} + auto PrepareRenameRequest::method() const -> std::string { return repr_->at("method"); } @@ -3580,6 +4369,18 @@ auto PrepareRenameResponse::id(std::string id) -> PrepareRenameResponse& { return *this; } +auto PrepareRenameResponse::result() const + -> std::variant { + lsp_runtime_error("PrepareRenameResponse::result() - not implemented yet"); +} + +auto PrepareRenameResponse::result( + std::variant result) + -> PrepareRenameResponse& { + lsp_runtime_error("PrepareRenameResponse::result() - not implemented yet"); + return *this; +} + auto ExecuteCommandRequest::method() const -> std::string { return repr_->at("method"); } @@ -3633,6 +4434,17 @@ auto ExecuteCommandResponse::id(std::string id) -> ExecuteCommandResponse& { return *this; } +auto ExecuteCommandResponse::result() const + -> std::variant { + lsp_runtime_error("ExecuteCommandResponse::result() - not implemented yet"); +} + +auto ExecuteCommandResponse::result(std::variant result) + -> ExecuteCommandResponse& { + lsp_runtime_error("ExecuteCommandResponse::result() - not implemented yet"); + return *this; +} + auto ApplyWorkspaceEditRequest::method() const -> std::string { return repr_->at("method"); } @@ -3688,6 +4500,18 @@ auto ApplyWorkspaceEditResponse::id(std::string id) return *this; } +auto ApplyWorkspaceEditResponse::result() const -> ApplyWorkspaceEditResult { + if (!repr_->contains("result")) (*repr_)["result"] = nullptr; + return ApplyWorkspaceEditResult(repr_->at("result")); // reference +} + +auto ApplyWorkspaceEditResponse::result(ApplyWorkspaceEditResult result) + -> ApplyWorkspaceEditResponse& { + lsp_runtime_error( + "ApplyWorkspaceEditResponse::result() - not implemented yet"); + return *this; +} + auto DidChangeWorkspaceFoldersNotification::method() const -> std::string { return repr_->at("method"); } diff --git a/src/lsp/cxx/lsp/requests.h b/src/lsp/cxx/lsp/requests.h index d8cbc053..d52acb4f 100644 --- a/src/lsp/cxx/lsp/requests.h +++ b/src/lsp/cxx/lsp/requests.h @@ -24,6 +24,105 @@ namespace cxx::lsp { +#define FOR_EACH_LSP_REQUEST_TYPE(V) \ + V(Implementation, "textDocument/implementation") \ + V(TypeDefinition, "textDocument/typeDefinition") \ + V(WorkspaceFolders, "workspace/workspaceFolders") \ + V(Configuration, "workspace/configuration") \ + V(DocumentColor, "textDocument/documentColor") \ + V(ColorPresentation, "textDocument/colorPresentation") \ + V(FoldingRange, "textDocument/foldingRange") \ + V(FoldingRangeRefresh, "workspace/foldingRange/refresh") \ + V(Declaration, "textDocument/declaration") \ + V(SelectionRange, "textDocument/selectionRange") \ + V(WorkDoneProgressCreate, "window/workDoneProgress/create") \ + V(CallHierarchyPrepare, "textDocument/prepareCallHierarchy") \ + V(CallHierarchyIncomingCalls, "callHierarchy/incomingCalls") \ + V(CallHierarchyOutgoingCalls, "callHierarchy/outgoingCalls") \ + V(SemanticTokens, "textDocument/semanticTokens/full") \ + V(SemanticTokensDelta, "textDocument/semanticTokens/full/delta") \ + V(SemanticTokensRange, "textDocument/semanticTokens/range") \ + V(SemanticTokensRefresh, "workspace/semanticTokens/refresh") \ + V(ShowDocument, "window/showDocument") \ + V(LinkedEditingRange, "textDocument/linkedEditingRange") \ + V(WillCreateFiles, "workspace/willCreateFiles") \ + V(WillRenameFiles, "workspace/willRenameFiles") \ + V(WillDeleteFiles, "workspace/willDeleteFiles") \ + V(Moniker, "textDocument/moniker") \ + V(TypeHierarchyPrepare, "textDocument/prepareTypeHierarchy") \ + V(TypeHierarchySupertypes, "typeHierarchy/supertypes") \ + V(TypeHierarchySubtypes, "typeHierarchy/subtypes") \ + V(InlineValue, "textDocument/inlineValue") \ + V(InlineValueRefresh, "workspace/inlineValue/refresh") \ + V(InlayHint, "textDocument/inlayHint") \ + V(InlayHintResolve, "inlayHint/resolve") \ + V(InlayHintRefresh, "workspace/inlayHint/refresh") \ + V(DocumentDiagnostic, "textDocument/diagnostic") \ + V(WorkspaceDiagnostic, "workspace/diagnostic") \ + V(DiagnosticRefresh, "workspace/diagnostic/refresh") \ + V(InlineCompletion, "textDocument/inlineCompletion") \ + V(TextDocumentContent, "workspace/textDocumentContent") \ + V(TextDocumentContentRefresh, "workspace/textDocumentContent/refresh") \ + V(Registration, "client/registerCapability") \ + V(Unregistration, "client/unregisterCapability") \ + V(Initialize, "initialize") \ + V(Shutdown, "shutdown") \ + V(ShowMessage, "window/showMessageRequest") \ + V(WillSaveTextDocumentWaitUntil, "textDocument/willSaveWaitUntil") \ + V(Completion, "textDocument/completion") \ + V(CompletionResolve, "completionItem/resolve") \ + V(Hover, "textDocument/hover") \ + V(SignatureHelp, "textDocument/signatureHelp") \ + V(Definition, "textDocument/definition") \ + V(References, "textDocument/references") \ + V(DocumentHighlight, "textDocument/documentHighlight") \ + V(DocumentSymbol, "textDocument/documentSymbol") \ + V(CodeAction, "textDocument/codeAction") \ + V(CodeActionResolve, "codeAction/resolve") \ + V(WorkspaceSymbol, "workspace/symbol") \ + V(WorkspaceSymbolResolve, "workspaceSymbol/resolve") \ + V(CodeLens, "textDocument/codeLens") \ + V(CodeLensResolve, "codeLens/resolve") \ + V(CodeLensRefresh, "workspace/codeLens/refresh") \ + V(DocumentLink, "textDocument/documentLink") \ + V(DocumentLinkResolve, "documentLink/resolve") \ + V(DocumentFormatting, "textDocument/formatting") \ + V(DocumentRangeFormatting, "textDocument/rangeFormatting") \ + V(DocumentRangesFormatting, "textDocument/rangesFormatting") \ + V(DocumentOnTypeFormatting, "textDocument/onTypeFormatting") \ + V(Rename, "textDocument/rename") \ + V(PrepareRename, "textDocument/prepareRename") \ + V(ExecuteCommand, "workspace/executeCommand") \ + V(ApplyWorkspaceEdit, "workspace/applyEdit") + +#define FOR_EACH_LSP_NOTIFICATION_TYPE(V) \ + V(DidChangeWorkspaceFolders, "workspace/didChangeWorkspaceFolders") \ + V(WorkDoneProgressCancel, "window/workDoneProgress/cancel") \ + V(DidCreateFiles, "workspace/didCreateFiles") \ + V(DidRenameFiles, "workspace/didRenameFiles") \ + V(DidDeleteFiles, "workspace/didDeleteFiles") \ + V(DidOpenNotebookDocument, "notebookDocument/didOpen") \ + V(DidChangeNotebookDocument, "notebookDocument/didChange") \ + V(DidSaveNotebookDocument, "notebookDocument/didSave") \ + V(DidCloseNotebookDocument, "notebookDocument/didClose") \ + V(Initialized, "initialized") \ + V(Exit, "exit") \ + V(DidChangeConfiguration, "workspace/didChangeConfiguration") \ + V(ShowMessage, "window/showMessage") \ + V(LogMessage, "window/logMessage") \ + V(TelemetryEvent, "telemetry/event") \ + V(DidOpenTextDocument, "textDocument/didOpen") \ + V(DidChangeTextDocument, "textDocument/didChange") \ + V(DidCloseTextDocument, "textDocument/didClose") \ + V(DidSaveTextDocument, "textDocument/didSave") \ + V(WillSaveTextDocument, "textDocument/willSave") \ + V(DidChangeWatchedFiles, "workspace/didChangeWatchedFiles") \ + V(PublishDiagnostics, "textDocument/publishDiagnostics") \ + V(SetTrace, "$/setTrace") \ + V(LogTrace, "$/logTrace") \ + V(Cancel, "$/cancelRequest") \ + V(Progress, "$/progress") + class ImplementationRequest final : public LSPRequest { public: using LSPRequest::LSPRequest; @@ -2444,4 +2543,32 @@ class ProgressNotification final : public LSPRequest { auto params(ProgressParams result) -> ProgressNotification&; }; +template +auto visitRequest(Visitor&& visitor, const LSPRequest& request, + const std::string_view& method) -> void { +#define PROCESS_REQUEST_TYPE(NAME, METHOD) \ + if (method == METHOD) \ + return visitor(static_cast(request)); + + FOR_EACH_LSP_REQUEST_TYPE(PROCESS_REQUEST_TYPE) + +#undef PROCESS_REQUEST_TYPE + + lsp_runtime_error("unknown request type"); +} + +template +auto visitNotification(Visitor&& visitor, const LSPRequest& notification, + const std::string_view& method) -> void { +#define PROCESS_NOTIFICATION_TYPE(NAME, METHOD) \ + if (method == METHOD) \ + return visitor(static_cast(notification)); + + FOR_EACH_LSP_NOTIFICATION_TYPE(PROCESS_NOTIFICATION_TYPE) + +#undef PROCESS_NOTIFICATION_TYPE + + lsp_runtime_error("unknown notification type"); +} + } // namespace cxx::lsp diff --git a/src/parser/cxx/macos_toolchain.cc b/src/parser/cxx/macos_toolchain.cc index db65f2a3..48aaf50e 100644 --- a/src/parser/cxx/macos_toolchain.cc +++ b/src/parser/cxx/macos_toolchain.cc @@ -49,6 +49,7 @@ void MacOSToolchain::addSystemIncludePaths() { addSystemIncludePath(std::format("{}/usr/include", platformPath_)); std::vector versions{ + "16.0.0", "15.0.0", }; @@ -74,6 +75,7 @@ void MacOSToolchain::addPredefinedMacros() { defineMacro("_Nullable", ""); defineMacro("_Nonnull", ""); defineMacro("__autoreleasing", ""); + defineMacro("__building_module(a)", "0"); defineMacro("_LP64", "1"); defineMacro("__AARCH64EL__", "1");