Native VBS and CMake builds of the server and every registered suite: protocol and document sync, VBS/compdb providers, stock GCC diagnostics (including in-process default profile preparation), the stock occurrence observer and hover/definition, the bounded Scheduler, C++ module graph, scan and artifact cache with real CMI production, the context-aware symbol index with schema-2 snapshot migration, navigation and guarded rename, reflection provenance with splice-origin extraction, index-backed completion and signature help, live GCC worker control with a registered DAP suite, and the Neovim and VS Code clients. VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced from the versioned patches and verified stepping reflection/template code with projected values 17/34 and 41/82.
91 lines
3.7 KiB
C++
91 lines
3.7 KiB
C++
#pragma once
|
|
|
|
#include <vls/Framing.hpp>
|
|
#include <vls/Json.hpp>
|
|
#include <vls/Server.hpp>
|
|
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace test {
|
|
|
|
inline std::string frame(std::string_view text) {
|
|
std::ostringstream output;
|
|
Void::Testing::require(vls::write_frame(output, text).has_value());
|
|
return output.str();
|
|
}
|
|
|
|
inline std::vector<vls::Json> responses(std::string_view wire) {
|
|
std::istringstream input{std::string{wire}};
|
|
std::vector<vls::Json> result;
|
|
for (;;) {
|
|
const auto next = vls::read_frame(input);
|
|
Void::Testing::require(next.has_value());
|
|
if (!*next)
|
|
return result;
|
|
auto json = vls::parse_json(**next);
|
|
Void::Testing::require(json.has_value());
|
|
result.push_back(std::move(*json));
|
|
}
|
|
}
|
|
|
|
inline const vls::Json &field(const vls::Json &json, std::string_view key) {
|
|
const auto *object = std::get_if<vls::Json::Object>(&json.value);
|
|
Void::Testing::require(object != nullptr);
|
|
const auto found = object->find(key);
|
|
Void::Testing::require(found != object->end());
|
|
return found->second;
|
|
}
|
|
|
|
inline vls::Json response(vls::Server &server, std::string_view request) {
|
|
const auto result = server.handle(request);
|
|
Void::Testing::require(result.response.has_value());
|
|
auto parsed = vls::parse_json(*result.response);
|
|
Void::Testing::require(parsed.has_value());
|
|
Void::Testing::expect(!result.exit_code.has_value());
|
|
return std::move(*parsed);
|
|
}
|
|
|
|
inline std::int64_t error_code(const vls::Json &response) {
|
|
return std::get<std::int64_t>(field(field(response, "error"), "code").value);
|
|
}
|
|
|
|
inline void expect_error(vls::Server &server, std::string_view request, std::int64_t code) {
|
|
Void::Testing::expect_eq(error_code(response(server, request)), code);
|
|
}
|
|
|
|
inline void expect_sync_capabilities(const vls::Json &result,
|
|
std::string_view encoding = "utf-16") {
|
|
const auto &capabilities = field(result, "capabilities");
|
|
Void::Testing::expect_eq(std::get<vls::Json::Object>(capabilities.value).size(),
|
|
std::size_t{3});
|
|
const auto &folders = field(field(capabilities, "workspace"), "workspaceFolders");
|
|
Void::Testing::expect(std::get<bool>(field(folders, "supported").value));
|
|
Void::Testing::expect(std::get<bool>(field(folders, "changeNotifications").value));
|
|
Void::Testing::expect_eq(std::get<std::string>(field(capabilities, "positionEncoding").value),
|
|
std::string{encoding});
|
|
const auto &sync = field(capabilities, "textDocumentSync");
|
|
Void::Testing::expect(std::get<bool>(field(sync, "openClose").value));
|
|
Void::Testing::expect_eq(std::get<std::int64_t>(field(sync, "change").value), std::int64_t{2});
|
|
}
|
|
|
|
inline void initialize(vls::Server &server) {
|
|
const auto result =
|
|
response(server, R"({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}})");
|
|
expect_sync_capabilities(field(result, "result"));
|
|
}
|
|
|
|
inline constexpr std::string_view initialize_request =
|
|
R"({"jsonrpc":"2.0","id":"init","method":"initialize","params":{"processId":null,"clientInfo":{"name":"test client","version":"1"},"locale":"en","rootUri":"file:///tmp/workspace","capabilities":{"general":{"positionEncodings":["utf-16"]}},"workspaceFolders":null,"initializationOptions":{"ignored":true},"unknownExtension":{}}})";
|
|
inline constexpr std::string_view initialized =
|
|
R"({"jsonrpc":"2.0","method":"initialized","params":{}})";
|
|
inline constexpr std::string_view shutdown = R"({"jsonrpc":"2.0","id":2,"method":"shutdown"})";
|
|
inline constexpr std::string_view exit = R"({"jsonrpc":"2.0","method":"exit"})";
|
|
|
|
} // namespace test
|