A bounded core resolves quoted include directives from the document directory and reports the spelling range; the server advertises documentLinkProvider and serves textDocument/documentLink from snapshots, keeping only targets that exist on disk. Angle includes are skipped because their search roots are unknown. Registered feature tests cover resolution, indentation, line counting, skipping and bounds, and the exact-capability-set assertion was updated. A real stdio session linked extra.hpp and skipped <vector> and a missing file.
93 lines
3.8 KiB
C++
93 lines
3.8 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{4});
|
|
Void::Testing::expect(!std::get<bool>(
|
|
field(field(capabilities, "documentLinkProvider"), "resolveProvider").value));
|
|
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
|