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.
590 lines
28 KiB
C++
590 lines
28 KiB
C++
#include <vls/WorkspaceSession.hpp>
|
|
|
|
#include <Void/LanguageServer/Documents/Uri.hpp>
|
|
#include <Void/System/TempDir.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <fstream>
|
|
#include <future>
|
|
#include <semaphore>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
namespace fs = std::filesystem;
|
|
namespace Build = Void::LanguageServer::Build;
|
|
namespace Docs = Void::LanguageServer::Documents;
|
|
namespace Protocol = Void::LanguageServer::Protocol;
|
|
namespace Workspace = Void::LanguageServer::Workspace;
|
|
using Protocol::Json;
|
|
using vls::SemanticContextIssue;
|
|
using vls::SemanticContextLease;
|
|
using vls::SemanticDriver;
|
|
using vls::WorkspaceSession;
|
|
using Void::Testing::expect;
|
|
using Void::Testing::require;
|
|
using Strings = std::vector<std::string>;
|
|
using namespace std::chrono_literals;
|
|
using namespace std::string_view_literals;
|
|
|
|
template <typename T, typename E> T take(std::expected<T, E> result) {
|
|
require(result.has_value());
|
|
return std::move(*result);
|
|
}
|
|
|
|
void write_file(const fs::path &path, std::string_view bytes) {
|
|
fs::create_directories(path.parent_path());
|
|
std::ofstream file{path, std::ios::binary};
|
|
file << bytes;
|
|
file.close();
|
|
require(file.good());
|
|
}
|
|
|
|
void write_json(const fs::path &path, const Json &json) {
|
|
write_file(path, take(Protocol::serialize_json(json)));
|
|
}
|
|
|
|
const Json &field(const Json &json, std::string_view key) {
|
|
const auto *object = Protocol::as_object(&json);
|
|
require(object != nullptr);
|
|
const auto *value = Protocol::find_member(*object, key);
|
|
require(value != nullptr);
|
|
return *value;
|
|
}
|
|
|
|
std::string text(const Json &json, std::string_view key) {
|
|
const auto *value = Protocol::as_string(&field(json, key));
|
|
require(value != nullptr);
|
|
return *value;
|
|
}
|
|
|
|
Json object(Json::Object fields) { return Json{std::move(fields)}; }
|
|
Json str(std::string_view value) { return Json{std::string{value}}; }
|
|
Json folder(const fs::path &root) { return object({{"uri", str(Docs::path_to_file_uri(root))}}); }
|
|
|
|
void initialize(WorkspaceSession &session, const fs::path &root, Json settings = object({})) {
|
|
auto params =
|
|
object({{"workspaceFolders", Json{Json::Array{folder(root)}}},
|
|
{"initializationOptions", object({{"voidLanguageServer", std::move(settings)}})}});
|
|
require(session.initialize(params).has_value());
|
|
}
|
|
|
|
void update(WorkspaceSession &session, Json::Array add, Json::Array remove) {
|
|
auto event = object({{"added", Json{std::move(add)}}, {"removed", Json{std::move(remove)}}});
|
|
auto params = object({{"event", std::move(event)}});
|
|
require(session.update_folders(¶ms).has_value());
|
|
}
|
|
|
|
Json status(WorkspaceSession &session, const fs::path &root, const fs::path &file) {
|
|
const auto params = object(
|
|
{{"workspaceUri", str(Docs::path_to_file_uri(root))}, {"textDocument", folder(file)}});
|
|
return take(session.provider_status(¶ms));
|
|
}
|
|
|
|
auto acquire(WorkspaceSession &session, const fs::path &file, const SemanticDriver &driver,
|
|
const fs::path &workspace = {}) {
|
|
const auto uri = Docs::path_to_file_uri(workspace);
|
|
return session.acquire_semantic_context(
|
|
Docs::path_to_file_uri(file),
|
|
workspace.empty() ? std::nullopt : std::optional<std::string_view>{uri}, driver);
|
|
}
|
|
|
|
template <typename T>
|
|
void fails(const std::expected<T, vls::SemanticContextError> &result, SemanticContextIssue issue) {
|
|
require(!result.has_value());
|
|
expect(result.error().issue == issue);
|
|
expect(!result.error().message.empty());
|
|
}
|
|
|
|
struct Gate {
|
|
std::atomic_bool armed{};
|
|
std::binary_semaphore entered{0}, resume{0};
|
|
|
|
void hook() {
|
|
if (armed.exchange(false)) {
|
|
entered.release();
|
|
resume.acquire();
|
|
}
|
|
}
|
|
|
|
template <typename Operation, typename Mutation>
|
|
auto during(Operation operation, Mutation mutation) {
|
|
armed = true;
|
|
auto pending = std::async(std::launch::async, std::move(operation));
|
|
{
|
|
struct Release {
|
|
std::binary_semaphore &semaphore;
|
|
~Release() { semaphore.release(); }
|
|
} release{resume};
|
|
require(entered.try_acquire_for(5s));
|
|
mutation();
|
|
}
|
|
return pending.get();
|
|
}
|
|
};
|
|
|
|
struct Fixture {
|
|
Void::FileSystem::TempDir temporary{"vls_semantic_lease_"};
|
|
fs::path base = fs::canonical(temporary.path()), root = base / "workspace";
|
|
fs::path a = root / "src/a.cpp", b = root / "src/b.cpp";
|
|
fs::path database = root / "compile_commands.json",
|
|
selector = root / ".vbs/editor_selection.json";
|
|
SemanticDriver gcc{base / "g++", Workspace::CompilerDriver::gcc};
|
|
SemanticDriver clang{base / "clang++", Workspace::CompilerDriver::clang};
|
|
fs::path marker = base / "executed";
|
|
|
|
Fixture() {
|
|
write_file(a, "int a;\n");
|
|
write_file(b, "int b;\n");
|
|
executable(gcc.executable, "first");
|
|
executable(clang.executable, "second");
|
|
}
|
|
|
|
void executable(const fs::path &path, std::string_view label) const {
|
|
write_file(path,
|
|
"#!/bin/sh\n# " + std::string{label} + "\ntouch '" + marker.native() + "'\n");
|
|
fs::permissions(path, fs::perms::owner_all);
|
|
}
|
|
|
|
vls::WorkspaceLaunch launch(bool authorized = true) const {
|
|
Workspace::SettingsOverrides settings;
|
|
if (authorized)
|
|
settings.tool_approvals = {
|
|
{root, Workspace::AuthorityLevel::compiler_use, gcc.executable},
|
|
{root, Workspace::AuthorityLevel::compiler_use, clang.executable}};
|
|
return {.root = root,
|
|
.cli_settings = Workspace::settings_from_cli(std::move(settings), base)};
|
|
}
|
|
|
|
Json row(const fs::path &file, const SemanticDriver &driver, Strings flags = {}) const {
|
|
Json::Array argv{str(driver.executable.native())};
|
|
for (const auto &flag : flags)
|
|
argv.push_back(str(flag));
|
|
argv.push_back(str("-c"));
|
|
const auto relative = file.lexically_relative(root).native();
|
|
argv.push_back(str(relative));
|
|
return object({{"file", str(relative)},
|
|
{"directory", str(root.native())},
|
|
{"arguments", Json{std::move(argv)}}});
|
|
}
|
|
|
|
fs::path native_database() const {
|
|
return root /
|
|
"out/profiles/debug/editor/generations/0123456789abcdef/compile_commands.json";
|
|
}
|
|
|
|
void select_native(int ticket) const {
|
|
write_json(selector, object({{"schema_version", Json{std::int64_t{1}}},
|
|
{"ticket", Json{std::int64_t{ticket}}},
|
|
{"selected_profile", str("debug")},
|
|
{"selected_build_root", str((root / "out").native())},
|
|
{"selected_generation_id", str("0123456789abcdef")},
|
|
{"selected_compdb_path", str(native_database().native())}}));
|
|
}
|
|
|
|
void native_status(std::string_view health) const {
|
|
write_json(root / "out/profiles/debug/editor/status.json",
|
|
object({{"schema_version", Json{std::int64_t{1}}},
|
|
{"profile", str("debug")},
|
|
{"status", str(health)},
|
|
{"diagnostic", str("")},
|
|
{"generation_id", str("0123456789abcdef")},
|
|
{"compdb_path", str(native_database().native())},
|
|
{"entry_count", Json{std::int64_t{2}}},
|
|
{"readiness_warnings", Json{Json::Array{}}}}));
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
VOID_TEST(SemanticLease, checked_compdb_command_and_selection_survive_unchanged_status) {
|
|
Fixture f;
|
|
const auto command = "ccache " + f.gcc.executable.native() +
|
|
" -DORDER=1 -freflection -freflection -o unit.o -c src/a.cpp";
|
|
const auto first = object({{"directory", str(f.root.native())},
|
|
{"file", str("src/a.cpp")},
|
|
{"command", str(command)},
|
|
{"output", str("unit.o")}});
|
|
write_json(f.database, Json{Json::Array{first, f.row(f.b, f.gcc)}});
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
const auto lease = take(acquire(session, f.a, f.gcc));
|
|
const auto &selection = lease.selection();
|
|
require(selection->selected != nullptr);
|
|
const auto &context = *selection->selected;
|
|
expect(selection->generation->identity().provider == "compdb");
|
|
expect(selection->generation->contexts().size() == 2);
|
|
expect(selection->scope->file == f.a && context.key.owning_tu == f.a);
|
|
expect(lease.document_uri() == Docs::path_to_file_uri(f.a));
|
|
expect(lease.selection_state().scope() == selection->scope);
|
|
expect(context.working_directory == f.root && context.source_language == "c++");
|
|
expect(context.original && context.original->command == command);
|
|
expect(context.semantic_arguments == Strings{f.gcc.executable.native(), "-DORDER=1",
|
|
"-freflection", "-freflection", "-c",
|
|
f.a.native()});
|
|
expect(!context.prerequisites && !context.standard_library);
|
|
expect(lease.driver().tool.operation == Workspace::AuthorityLevel::compiler_use);
|
|
expect(lease.driver().tool.identity.content_hash_hex.size() == 64);
|
|
expect(lease.driver().tool.selection_origin.layer == Workspace::ConfigLayer::cli);
|
|
expect(text(status(session, f.root, f.b), "state") == "ready");
|
|
const auto again = take(acquire(session, f.a, f.gcc));
|
|
expect(again.selection() == selection && &again.selection_state() == &lease.selection_state());
|
|
const auto explicit_root = take(acquire(session, f.a, f.gcc, f.root));
|
|
expect(explicit_root.selection() == selection &&
|
|
&explicit_root.selection_state() == &lease.selection_state());
|
|
expect(again.configuration_generation() == lease.configuration_generation());
|
|
expect(session.validate_semantic_context(lease).has_value());
|
|
expect(!fs::exists(f.marker));
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, native_ticket_and_stale_status_fence_the_immutable_row) {
|
|
Fixture f;
|
|
const auto rows = Json{Json::Array{f.row(f.a, f.gcc, {"-DNATIVE=7"}), f.row(f.b, f.gcc)}};
|
|
write_json(f.native_database(), rows);
|
|
f.native_status("valid");
|
|
f.select_native(7);
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc, {"-DFALLBACK"})}});
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
const auto first = take(acquire(session, f.a, f.gcc));
|
|
expect(first.selection()->generation->contexts().size() == 2);
|
|
expect(first.selection()->generation->identity().provider == "vbs");
|
|
expect(first.selection()->selected->original->metadata_file == f.native_database());
|
|
expect(std::ranges::contains(*first.selection()->selected->semantic_arguments, "-DNATIVE=7"sv));
|
|
f.select_native(8);
|
|
const auto next = take(acquire(session, f.a, f.gcc));
|
|
expect(first.selection()->generation->identity().revision ==
|
|
next.selection()->generation->identity().revision);
|
|
expect(first.selection() != next.selection());
|
|
fails(session.validate_semantic_context(first), SemanticContextIssue::superseded);
|
|
f.native_status("stale");
|
|
expect(text(status(session, f.root, f.a), "state") == "stale");
|
|
fails(acquire(session, f.a, f.gcc), SemanticContextIssue::unavailable);
|
|
fails(session.validate_semantic_context(next), SemanticContextIssue::superseded);
|
|
f.native_status("valid");
|
|
expect(acquire(session, f.a, f.gcc).has_value());
|
|
expect(!fs::exists(f.marker));
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, passive_status_does_not_pin_and_workspace_settings_cannot_grant) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
expect(text(status(session, f.root, f.a), "state") == "ready");
|
|
const auto replacement = f.base / "new-driver";
|
|
f.executable(replacement, "selected after passive status");
|
|
fs::rename(replacement, f.gcc.executable);
|
|
expect(acquire(session, f.a, f.gcc).has_value());
|
|
fails(acquire(session, f.a, f.clang), SemanticContextIssue::wrong_command);
|
|
fails(acquire(session, f.a, {f.gcc.executable, Workspace::CompilerDriver::clang}),
|
|
SemanticContextIssue::wrong_command);
|
|
auto settings =
|
|
object({{"toolApprovals",
|
|
Json{Json::Array{object({{"root", str(f.root.native())},
|
|
{"operation", str("compilerUse")},
|
|
{"executable", str(f.gcc.executable.native())}})}}}});
|
|
WorkspaceSession unapproved{f.launch(false)};
|
|
initialize(unapproved, f.root, settings);
|
|
expect(text(status(unapproved, f.root, f.a), "state") == "ready");
|
|
fails(acquire(unapproved, f.a, f.gcc), SemanticContextIssue::unavailable);
|
|
WorkspaceSession passive;
|
|
initialize(passive, f.root);
|
|
fails(acquire(passive, f.a, f.gcc), SemanticContextIssue::disabled);
|
|
const auto other = f.base / "other";
|
|
fs::create_directory(other);
|
|
update(session, {folder(other)}, {});
|
|
fails(acquire(session, other / "a.cpp", f.gcc), SemanticContextIssue::disabled);
|
|
expect(!fs::exists(f.marker));
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, selection_precedes_checked_driver_admission) {
|
|
Fixture f;
|
|
write_json(f.database,
|
|
Json{Json::Array{f.row(f.a, f.clang, {"-DCLANG"}), f.row(f.a, f.gcc, {"-DGCC"})}});
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
const auto passive_key = text(field(status(session, f.root, f.a), "selected"), "alternative");
|
|
const auto gcc = acquire(session, f.a, f.gcc);
|
|
const auto clang = acquire(session, f.a, f.clang);
|
|
require(gcc.has_value() != clang.has_value());
|
|
const auto &selected = (gcc ? *gcc : *clang).selection();
|
|
fails(gcc ? clang : gcc, SemanticContextIssue::wrong_command);
|
|
expect(selected->alternatives().size() == 2);
|
|
expect(selected->selected->key.alternative == passive_key);
|
|
expect(std::ranges::contains(*selected->selected->semantic_arguments,
|
|
gcc ? "-DGCC"sv : "-DCLANG"sv));
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, identical_database_replacement_requires_a_new_capture) {
|
|
Fixture f;
|
|
const auto rows = Json{Json::Array{f.row(f.a, f.gcc)}};
|
|
write_json(f.database, rows);
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
const auto original = take(acquire(session, f.a, f.gcc));
|
|
const auto old_file = f.root / "first.json";
|
|
fs::rename(f.database, old_file);
|
|
write_json(f.database, rows);
|
|
const auto replacement = take(acquire(session, f.a, f.gcc));
|
|
expect(replacement.selection() != original.selection());
|
|
expect(replacement.selection()->generation->identity().revision ==
|
|
original.selection()->generation->identity().revision);
|
|
expect(session.validate_semantic_context(replacement).has_value());
|
|
fails(session.validate_semantic_context(original), SemanticContextIssue::superseded);
|
|
fs::rename(old_file, f.database);
|
|
fails(session.validate_semantic_context(replacement), SemanticContextIssue::superseded);
|
|
fails(session.validate_semantic_context(original), SemanticContextIssue::superseded);
|
|
expect(acquire(session, f.a, f.gcc).has_value());
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, observed_native_precedence_cannot_restore_an_old_fallback_lease) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
const auto original = take(acquire(session, f.a, f.gcc));
|
|
write_file(f.selector, "{");
|
|
const auto invalid = status(session, f.root, f.a);
|
|
expect(text(invalid, "provider") == "vbs" && text(invalid, "state") == "degraded");
|
|
fs::remove(f.selector);
|
|
// The original database, TU, driver and selector absence all match again.
|
|
fails(session.validate_semantic_context(original), SemanticContextIssue::superseded);
|
|
const auto fresh = take(acquire(session, f.a, f.gcc));
|
|
expect(fresh.selection() != original.selection());
|
|
expect(session.validate_semantic_context(fresh).has_value());
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, failed_final_status_check_permanently_expires_a_fallback_lease) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
|
Gate gate;
|
|
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
|
initialize(session, f.root);
|
|
const auto fallback = take(acquire(session, f.a, f.gcc));
|
|
const auto discarded = gate.during([&] { return status(session, f.root, f.b); },
|
|
[&] { write_file(f.selector, "{"); });
|
|
expect(text(discarded, "state") == "stale");
|
|
fs::remove(f.selector);
|
|
fails(session.validate_semantic_context(fallback), SemanticContextIssue::superseded);
|
|
expect(acquire(session, f.a, f.gcc).has_value());
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, disproved_selector_absence_retires_both_checked_driver_imports) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.clang)}});
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
const auto a = take(acquire(session, f.a, f.gcc));
|
|
const auto b = take(acquire(session, f.b, f.clang));
|
|
write_file(f.selector, "{");
|
|
fails(session.validate_semantic_context(a), SemanticContextIssue::superseded);
|
|
fs::remove(f.selector);
|
|
fails(session.validate_semantic_context(b), SemanticContextIssue::superseded);
|
|
expect(acquire(session, f.b, f.clang).has_value());
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, changed_pin_revokes_old_work_and_preserves_the_other_approved_driver) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.clang)}});
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
const auto a = take(acquire(session, f.a, f.gcc));
|
|
const auto b = take(acquire(session, f.b, f.clang));
|
|
expect(a.driver().tool.trust_generation == b.driver().tool.trust_generation);
|
|
auto former = f.base / "former-driver";
|
|
fs::rename(f.gcc.executable, former);
|
|
f.executable(f.gcc.executable, "replacement");
|
|
fails(session.validate_semantic_context(a), SemanticContextIssue::superseded);
|
|
fails(session.validate_semantic_context(b), SemanticContextIssue::superseded);
|
|
const auto recovered = take(acquire(session, f.b, f.clang));
|
|
expect(recovered.driver().tool.trust_generation > b.driver().tool.trust_generation);
|
|
expect(recovered.configuration_generation() == b.configuration_generation());
|
|
expect(text(status(session, f.root, f.b), "state") == "ready");
|
|
fs::rename(former, f.gcc.executable);
|
|
fails(acquire(session, f.a, f.gcc), SemanticContextIssue::unavailable);
|
|
expect(session.validate_semantic_context(recovered).has_value());
|
|
expect(!fs::exists(f.marker));
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, nested_folder_fences_implicit_acquisition_and_validation_only) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
|
Gate gate;
|
|
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
|
initialize(session, f.root);
|
|
const auto explicit_outer = take(acquire(session, f.a, f.gcc, f.root));
|
|
const auto inner = folder(f.a.parent_path());
|
|
auto late = gate.during([&] { return acquire(session, f.a, f.gcc); },
|
|
[&] { update(session, {inner}, {}); });
|
|
fails(late, SemanticContextIssue::superseded);
|
|
fails(acquire(session, f.a, f.gcc), SemanticContextIssue::unavailable);
|
|
expect(session.validate_semantic_context(explicit_outer).has_value());
|
|
update(session, {}, {inner});
|
|
const auto implicit = take(acquire(session, f.a, f.gcc));
|
|
auto stale = gate.during([&] { return session.validate_semantic_context(implicit); },
|
|
[&] {
|
|
update(session, {inner}, {});
|
|
update(session, {}, {inner});
|
|
});
|
|
fails(stale, SemanticContextIssue::superseded);
|
|
expect(session.validate_semantic_context(explicit_outer).has_value());
|
|
fails(session.validate_semantic_context(implicit), SemanticContextIssue::superseded);
|
|
expect(acquire(session, f.a, f.gcc).has_value());
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, independent_cold_document_observations_and_status_can_complete) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.gcc)}});
|
|
Gate gate;
|
|
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
|
initialize(session, f.root);
|
|
std::optional<SemanticContextLease> b;
|
|
const auto a =
|
|
take(gate.during([&] { return acquire(session, f.a, f.gcc); },
|
|
[&] {
|
|
b = take(acquire(session, f.b, f.gcc));
|
|
expect(text(status(session, f.root, f.b), "state") == "ready");
|
|
}));
|
|
require(b.has_value());
|
|
expect(a.selection()->selected->key.owning_tu == f.a);
|
|
expect(b->selection()->selected->key.owning_tu == f.b);
|
|
expect(session.validate_semantic_context(a).has_value());
|
|
expect(session.validate_semantic_context(*b).has_value());
|
|
expect(take(acquire(session, f.a, f.gcc)).selection() == a.selection());
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, newest_document_request_fences_older_success_and_failure) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
|
Gate gate;
|
|
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
|
initialize(session, f.root);
|
|
std::optional<SemanticContextLease> accepted;
|
|
const auto late_failure = gate.during([&] { return acquire(session, f.a, f.clang); },
|
|
[&] { accepted = take(acquire(session, f.a, f.gcc)); });
|
|
fails(late_failure, SemanticContextIssue::superseded);
|
|
require(accepted.has_value());
|
|
expect(session.validate_semantic_context(*accepted).has_value());
|
|
const auto late_success = gate.during(
|
|
[&] { return acquire(session, f.a, f.gcc); },
|
|
[&] { fails(acquire(session, f.a, f.clang), SemanticContextIssue::wrong_command); });
|
|
fails(late_success, SemanticContextIssue::superseded);
|
|
fails(session.validate_semantic_context(*accepted), SemanticContextIssue::superseded);
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, explicit_revocation_between_observation_and_installation) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.gcc)}});
|
|
Gate gate;
|
|
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
|
initialize(session, f.root);
|
|
const auto accepted = take(acquire(session, f.a, f.gcc));
|
|
const auto late = gate.during([&] { return acquire(session, f.b, f.gcc); },
|
|
[&] { session.revoke_root_authority(f.root); });
|
|
fails(late, SemanticContextIssue::superseded);
|
|
fails(session.validate_semantic_context(accepted), SemanticContextIssue::superseded);
|
|
fails(acquire(session, f.b, f.gcc), SemanticContextIssue::unavailable);
|
|
expect(text(status(session, f.root, f.a), "state") == "ready");
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, superseded_native_failure_cannot_retire_a_newer_fallback_selection) {
|
|
Fixture f;
|
|
const auto rows = Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.clang)}};
|
|
write_json(f.database, rows);
|
|
write_json(f.native_database(), rows);
|
|
f.native_status("valid");
|
|
Gate gate;
|
|
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
|
initialize(session, f.root);
|
|
auto latest = take(acquire(session, f.a, f.gcc));
|
|
f.select_native(9);
|
|
auto stale = gate.during([&] { return acquire(session, f.a, f.clang); },
|
|
[&] {
|
|
fs::remove(f.selector);
|
|
latest = take(acquire(session, f.a, f.gcc));
|
|
});
|
|
fails(stale, SemanticContextIssue::superseded);
|
|
expect(session.validate_semantic_context(latest).has_value());
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, negative_response_lookup_and_editor_alias_retarget_expire_leases) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc), f.row(f.b, f.gcc, {"@later.rsp"})}});
|
|
const auto alias = f.root / "alias.cpp";
|
|
fs::create_symlink("src/a.cpp", alias);
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
const auto a = take(acquire(session, alias, f.gcc));
|
|
expect(a.selection()->scope->file == f.a);
|
|
fails(acquire(session, f.b, f.gcc), SemanticContextIssue::wrong_command);
|
|
write_file(f.root / "later.rsp", "-DRESPONSE");
|
|
fails(session.validate_semantic_context(a), SemanticContextIssue::superseded);
|
|
const auto b = take(acquire(session, f.b, f.gcc));
|
|
expect(std::ranges::contains(*b.selection()->selected->semantic_arguments, "-DRESPONSE"sv));
|
|
const auto alias_a = take(acquire(session, alias, f.gcc));
|
|
const auto saved = f.root / "alias-saved.cpp";
|
|
fs::rename(alias, saved);
|
|
fs::create_symlink("src/b.cpp", alias);
|
|
fails(session.validate_semantic_context(alias_a), SemanticContextIssue::superseded);
|
|
const auto alias_b = take(acquire(session, alias, f.gcc));
|
|
expect(alias_b.selection()->scope->file == f.b &&
|
|
session.validate_semantic_context(b).has_value());
|
|
fs::rename(saved, alias);
|
|
fails(session.validate_semantic_context(alias_b), SemanticContextIssue::superseded);
|
|
fails(session.validate_semantic_context(alias_a), SemanticContextIssue::superseded);
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, settings_and_root_incarnation_are_stable_only_for_their_lifetimes) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
|
Gate gate;
|
|
WorkspaceSession session{f.launch(), [&] { gate.hook(); }};
|
|
initialize(session, f.root);
|
|
const auto first = take(acquire(session, f.a, f.gcc));
|
|
auto config =
|
|
object({{"settings",
|
|
object({{"voidLanguageServer", object({{"selectedProfile", str("debug")}})}})}});
|
|
const auto late = gate.during([&] { return acquire(session, f.a, f.gcc); },
|
|
[&] { require(session.configure(&config).has_value()); });
|
|
fails(late, SemanticContextIssue::superseded);
|
|
fails(session.validate_semantic_context(first), SemanticContextIssue::superseded);
|
|
const auto second = take(acquire(session, f.a, f.gcc));
|
|
expect(second.configuration_generation() > first.configuration_generation());
|
|
require(session.configure(&config).has_value());
|
|
expect(take(acquire(session, f.a, f.gcc)).selection() == second.selection());
|
|
const auto old_incarnation = second.selection()->scope->workspace.session;
|
|
const auto removed = gate.during([&] { return session.validate_semantic_context(second); },
|
|
[&] { update(session, {folder(f.root)}, {folder(f.root)}); });
|
|
fails(removed, SemanticContextIssue::superseded);
|
|
expect(text(status(session, f.root, f.a), "incarnation") != old_incarnation);
|
|
fails(acquire(session, f.a, f.gcc), SemanticContextIssue::unavailable);
|
|
}
|
|
|
|
VOID_TEST(SemanticLease, cache_eviction_and_session_shutdown_leave_immutable_inputs_readable) {
|
|
Fixture f;
|
|
write_json(f.database, Json{Json::Array{f.row(f.a, f.gcc)}});
|
|
std::optional<SemanticContextLease> retained;
|
|
{
|
|
WorkspaceSession session{f.launch()};
|
|
initialize(session, f.root);
|
|
retained = take(acquire(session, f.a, f.gcc));
|
|
for (int i = 0; i < 32; ++i)
|
|
fails(acquire(session, f.root / ("new-" + std::to_string(i) + ".cpp"), f.gcc),
|
|
SemanticContextIssue::no_command);
|
|
fails(session.validate_semantic_context(*retained), SemanticContextIssue::superseded);
|
|
retained = take(acquire(session, f.a, f.gcc));
|
|
WorkspaceSession other{f.launch()};
|
|
initialize(other, f.root);
|
|
fails(other.validate_semantic_context(*retained), SemanticContextIssue::superseded);
|
|
expect(session.validate_semantic_context(*retained).has_value());
|
|
}
|
|
require(retained.has_value());
|
|
expect(retained->selection()->selected->original->arguments->front() ==
|
|
f.gcc.executable.native());
|
|
expect(retained->selection_state().scope()->file == f.a);
|
|
expect(!fs::exists(f.marker));
|
|
}
|