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.
557 lines
26 KiB
C++
557 lines
26 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 <atomic>
|
|
#include <chrono>
|
|
#include <fstream>
|
|
#include <future>
|
|
#include <semaphore>
|
|
#include <string_view>
|
|
#include <utility>
|
|
|
|
namespace {
|
|
namespace fs = std::filesystem;
|
|
namespace Workspace = Void::LanguageServer::Workspace;
|
|
namespace Docs = Void::LanguageServer::Documents;
|
|
namespace Protocol = Void::LanguageServer::Protocol;
|
|
using Protocol::Json;
|
|
using Void::Testing::expect;
|
|
using Void::Testing::require;
|
|
using namespace std::chrono_literals;
|
|
|
|
Json str(std::string_view value) { return Json{std::string{value}}; }
|
|
Json integer(std::int64_t value) { return Json{value}; }
|
|
Json object(Json::Object fields = {}) { return Json{std::move(fields)}; }
|
|
Json uri(const fs::path &path) { return Json{Docs::path_to_file_uri(path)}; }
|
|
|
|
const Json *field(const Json &value, std::string_view name) {
|
|
const auto *fields = Protocol::as_object(&value);
|
|
return fields ? Protocol::find_member(*fields, name) : nullptr;
|
|
}
|
|
|
|
std::string read_string(const Json &value, std::string_view name) {
|
|
const auto *text = Protocol::as_string(field(value, name));
|
|
require(text != nullptr);
|
|
return *text;
|
|
}
|
|
|
|
const Json &nested(const Json &value, std::string_view name) {
|
|
const auto *entry = field(value, name);
|
|
require(entry != nullptr);
|
|
return *entry;
|
|
}
|
|
|
|
std::string issue(const Json &value) {
|
|
const auto *issues = Protocol::as_array(field(value, "issues"));
|
|
require(issues && !issues->empty());
|
|
return read_string(issues->front(), "code");
|
|
}
|
|
|
|
Json folder(const fs::path &root) { return object({{"uri", uri(root)}, {"name", str("C++")}}); }
|
|
|
|
Json initialize(Json::Array roots, Json settings = object()) {
|
|
return object(
|
|
{{"workspaceFolders", Json{std::move(roots)}},
|
|
{"initializationOptions", object({{"voidLanguageServer", std::move(settings)}})}});
|
|
}
|
|
|
|
Json change(Json::Array added, Json::Array removed) {
|
|
auto event = object({{"added", Json{std::move(added)}}, {"removed", Json{std::move(removed)}}});
|
|
return object({{"event", std::move(event)}});
|
|
}
|
|
|
|
Json configuration(Json::Object entries) {
|
|
return object({{"settings", object({{"voidLanguageServer", object(std::move(entries))}})}});
|
|
}
|
|
|
|
Json query(const fs::path &root = {}, const fs::path &file = {}) {
|
|
Json::Object params;
|
|
if (!root.empty())
|
|
params.emplace("workspaceUri", uri(root));
|
|
if (!file.empty())
|
|
params.emplace("textDocument", object({{"uri", uri(file)}}));
|
|
return object(std::move(params));
|
|
}
|
|
|
|
Json status(vls::WorkspaceSession &session, const Json ¶ms = object()) {
|
|
auto result = session.provider_status(¶ms);
|
|
require(result.has_value());
|
|
auto wire = Protocol::serialize_json(*result);
|
|
require(wire.has_value());
|
|
expect(wire->size() < 512 * 1024);
|
|
return std::move(*result);
|
|
}
|
|
|
|
void write(const fs::path &path, std::string_view text) {
|
|
fs::create_directories(path.parent_path());
|
|
std::ofstream file{path, std::ios::binary};
|
|
file << text;
|
|
file.close();
|
|
require(file.good());
|
|
}
|
|
|
|
void write_json(const fs::path &path, const Json &value) {
|
|
auto text = Protocol::serialize_json(value);
|
|
require(text.has_value());
|
|
write(path, *text);
|
|
}
|
|
|
|
struct Fixture {
|
|
Void::FileSystem::TempDir temp{"vls_provider_session_"};
|
|
fs::path base = fs::canonical(temp.path());
|
|
fs::path one = base / "one", two = base / "one-more", external = base / "external";
|
|
Fixture() {
|
|
write(one / "main.cpp", "int one;\n");
|
|
write(two / "main.cpp", "int two;\n");
|
|
fs::create_directories(external);
|
|
}
|
|
|
|
static void compdb(const fs::path &root, const fs::path &path, unsigned count = 1,
|
|
std::string_view compiler = "g++") {
|
|
Json::Array records;
|
|
for (auto i = 0U; i < count; ++i) {
|
|
records.push_back(
|
|
object({{"directory", Json{root.native()}},
|
|
{"file", str("main.cpp")},
|
|
{"arguments", Json{Json::Array{str(compiler), str("-c"), str("main.cpp"),
|
|
Json{"-DCASE=" + std::to_string(i)}}}}}));
|
|
}
|
|
write_json(path, Json{std::move(records)});
|
|
}
|
|
|
|
static fs::path native(const fs::path &root, const fs::path &build, unsigned count = 1,
|
|
const fs::path &selector = {}) {
|
|
constexpr std::string_view id = "0123456789abcdef";
|
|
const auto editor = build / "profiles/debug/editor";
|
|
const auto database = editor / "generations" / id / "compile_commands.json";
|
|
compdb(root, database, count);
|
|
write_json(editor / "status.json", object({{"schema_version", integer(1)},
|
|
{"profile", str("debug")},
|
|
{"status", str("valid")},
|
|
{"diagnostic", str("")},
|
|
{"generation_id", str(id)},
|
|
{"compdb_path", Json{database.native()}},
|
|
{"entry_count", integer(count)},
|
|
{"readiness_warnings", Json{Json::Array{}}}}));
|
|
write_json(selector.empty() ? root / ".vbs/editor_selection.json" : selector,
|
|
object({{"schema_version", integer(1)},
|
|
{"ticket", integer(7)},
|
|
{"selected_profile", str("debug")},
|
|
{"selected_build_root", Json{build.native()}},
|
|
{"selected_generation_id", str(id)},
|
|
{"selected_compdb_path", Json{database.native()}}}));
|
|
return database;
|
|
}
|
|
};
|
|
|
|
struct PauseObservation {
|
|
std::atomic_bool pause_next{};
|
|
std::binary_semaphore paused{0}, resume{0};
|
|
|
|
void hook() {
|
|
if (pause_next.exchange(false)) {
|
|
paused.release();
|
|
resume.acquire();
|
|
}
|
|
}
|
|
|
|
template <typename F>
|
|
Json run(vls::WorkspaceSession &session, F action, const Json ¶ms = object()) {
|
|
pause_next = true;
|
|
auto old = std::async(std::launch::async, [&] { return status(session, params); });
|
|
{
|
|
struct Resume {
|
|
std::binary_semaphore &gate;
|
|
~Resume() { gate.release(); }
|
|
} release{resume};
|
|
require(paused.try_acquire_for(5s));
|
|
action();
|
|
}
|
|
return old.get();
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
VOID_TEST(ProviderSession, workspace_folders_precedence_and_legacy_root) {
|
|
Fixture f;
|
|
vls::WorkspaceSession absent, empty, explicit_null, legacy, invalid;
|
|
require(absent.initialize(object()).has_value());
|
|
require(empty
|
|
.initialize(object({{"workspaceFolders", Json{Json::Array{}}},
|
|
{"rootUri", str("invalid but unused")}}))
|
|
.has_value());
|
|
require(explicit_null
|
|
.initialize(object({{"workspaceFolders", Json{nullptr}}, {"rootUri", uri(f.one)}}))
|
|
.has_value());
|
|
for (auto *session : {&absent, &empty, &explicit_null})
|
|
expect(read_string(status(*session), "state") == "documentOnly");
|
|
require(legacy.initialize(object({{"rootUri", uri(f.one)}})).has_value());
|
|
const auto legacy_status = status(legacy);
|
|
expect(read_string(legacy_status, "workspaceUri") == Docs::path_to_file_uri(f.one));
|
|
expect(read_string(legacy_status, "state") == "missing");
|
|
expect(!invalid.initialize(object({{"rootUri", str("file://remote/tmp")}})));
|
|
expect(!invalid.initialize(initialize({folder(f.one / "main.cpp")})));
|
|
expect(!invalid.initialize(initialize({folder(f.base / "absent" / ".." / "one")})));
|
|
expect(!invalid.initialize(initialize(Json::Array(65, folder(f.one)))));
|
|
fs::create_directory_symlink(f.one, f.base / "alias");
|
|
expect(!invalid.initialize(initialize({folder(f.one), folder(f.base / "alias")})));
|
|
require(invalid.initialize(initialize({folder(f.base / "alias")})).has_value());
|
|
expect(read_string(status(invalid, query(f.base / "alias")), "workspaceUri") ==
|
|
Docs::path_to_file_uri(f.one));
|
|
fs::remove(f.base / "alias");
|
|
fs::create_directory(f.base / "alias");
|
|
fs::create_directory_symlink(f.base / "alias", f.base / "other-alias");
|
|
auto colliding = change({folder(f.base / "other-alias")}, {});
|
|
expect(!invalid.update_folders(&colliding));
|
|
expect(read_string(status(invalid, query(f.base / "alias")), "workspaceUri") ==
|
|
Docs::path_to_file_uri(f.one));
|
|
const auto virtual_query =
|
|
object({{"textDocument", object({{"uri", str("untitled:buffer")}})}});
|
|
expect(read_string(status(invalid, virtual_query), "state") == "documentOnly");
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, independent_roots_and_deterministic_contexts) {
|
|
Fixture f;
|
|
f.native(f.one, f.one / "build", 20);
|
|
f.compdb(f.two, f.two / "editor/build.json", 2);
|
|
const auto settings =
|
|
object({{"selectedProfile", str("debug")},
|
|
{"workspaces", object({{Docs::path_to_file_uri(f.two),
|
|
object({{"provider", str("compdb")},
|
|
{"compdbPath", str("editor/build.json")}})}})}});
|
|
vls::WorkspaceSession session;
|
|
require(session.initialize(initialize({folder(f.one), folder(f.two)}, settings)).has_value());
|
|
expect(!session.provider_status(nullptr));
|
|
const auto first = status(session, query({}, f.one / "main.cpp"));
|
|
const auto second = status(session, query({}, f.two / "main.cpp"));
|
|
expect(read_string(first, "provider") == "vbs" && read_string(first, "state") == "ready");
|
|
expect(read_string(first, "nativeGeneration") == "0123456789abcdef");
|
|
expect(Protocol::as_int64(field(first, "ticket")) == 7);
|
|
expect(Protocol::as_int64(field(first, "contextCount")) == 20);
|
|
expect(Protocol::as_bool(field(first, "alternativesTruncated")) == true);
|
|
expect(read_string(nested(first, "selected"), "profile") == "debug");
|
|
expect(read_string(nested(first, "selected"), "owningTu") ==
|
|
Docs::path_to_file_uri(f.one / "main.cpp"));
|
|
expect(read_string(second, "provider") == "compdb" && read_string(second, "state") == "ready");
|
|
expect(read_string(first, "incarnation") != read_string(second, "incarnation"));
|
|
const auto *alternatives = Protocol::as_array(field(second, "alternatives"));
|
|
require(alternatives && alternatives->size() == 2);
|
|
const auto selected = read_string(nested(second, "selected"), "alternative");
|
|
expect(selected == read_string(alternatives->front(), "alternative"));
|
|
const auto again = status(session, query(f.two, f.two / "main.cpp"));
|
|
expect(read_string(nested(again, "selected"), "alternative") == selected);
|
|
|
|
fs::create_directories(f.one / "nested");
|
|
auto added = change({folder(f.one / "nested")}, {});
|
|
require(session.update_folders(&added).has_value());
|
|
auto ambiguous = query({}, f.one / "nested/main.cpp");
|
|
expect(!session.provider_status(&ambiguous));
|
|
expect(read_string(status(session, query(f.one, f.one / "nested/main.cpp")), "state") ==
|
|
"ready");
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, malformed_updates_preserve_roots_settings_and_history) {
|
|
Fixture f;
|
|
const auto database = f.one / "compile_commands.json";
|
|
f.compdb(f.one, database);
|
|
vls::WorkspaceSession session;
|
|
require(session.initialize(initialize({folder(f.one), folder(f.two)})).has_value());
|
|
const auto valid = status(session, query(f.one));
|
|
auto bad_configuration = configuration(
|
|
{{"provider", str("none")},
|
|
{"workspaces",
|
|
object({{Docs::path_to_file_uri(f.two), object({{"selectedProfile", integer(2)}})}})}});
|
|
expect(!session.configure(&bad_configuration));
|
|
auto bad_folders = change({folder(f.external / "absent")}, {folder(f.one)});
|
|
expect(!session.update_folders(&bad_folders));
|
|
auto malformed = object({{"workspaceUri", integer(5)}});
|
|
expect(!session.provider_status(&malformed));
|
|
write(database, "invalid");
|
|
const auto degraded = status(session, query(f.one));
|
|
expect(read_string(degraded, "state") == "degraded");
|
|
expect(read_string(degraded, "incarnation") == read_string(valid, "incarnation"));
|
|
expect(read_string(nested(degraded, "lastGood"), "generation") ==
|
|
read_string(valid, "generation"));
|
|
expect(!field(degraded, "generation"));
|
|
|
|
auto disable_two = configuration(
|
|
{{"workspaces",
|
|
object({{Docs::path_to_file_uri(f.two), object({{"provider", str("none")}})}})}});
|
|
require(session.configure(&disable_two).has_value());
|
|
expect(read_string(status(session, query(f.two)), "state") == "disabled");
|
|
expect(read_string(status(session, query(f.one)), "state") == "degraded");
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, broken_native_authority_suppresses_automatic_fallback) {
|
|
Fixture f;
|
|
f.compdb(f.one, f.one / "compile_commands.json");
|
|
const auto selector = f.one / ".vbs/editor_selection.json";
|
|
vls::WorkspaceSession session;
|
|
require(session.initialize(initialize({folder(f.one)})).has_value());
|
|
expect(read_string(status(session), "provider") == "compdb");
|
|
|
|
auto vbs = configuration({{"provider", str("vbs")}});
|
|
require(session.configure(&vbs).has_value());
|
|
const auto missing = status(session);
|
|
expect(read_string(missing, "provider") == "vbs" && read_string(missing, "state") == "missing");
|
|
auto automatic = configuration({});
|
|
require(session.configure(&automatic).has_value());
|
|
fs::create_directories(selector.parent_path());
|
|
fs::create_symlink(f.one / "absent.json", selector);
|
|
const auto denied = status(session);
|
|
expect(read_string(denied, "provider") == "vbs" && issue(denied) == "outside_scope");
|
|
fs::remove(selector);
|
|
write(selector, "{");
|
|
const auto corrupt = status(session);
|
|
expect(read_string(corrupt, "provider") == "vbs" && issue(corrupt) == "invalid_metadata");
|
|
const auto build = f.one / "build";
|
|
const auto db = f.native(f.one, build);
|
|
auto status_path = build / "profiles/debug/editor/status.json";
|
|
fs::remove(status_path);
|
|
const auto unavailable = status(session);
|
|
expect(read_string(unavailable, "provider") == "vbs" &&
|
|
issue(unavailable) == "missing_reference");
|
|
f.native(f.one, build);
|
|
const auto ready = status(session);
|
|
write_json(status_path, object({{"schema_version", integer(1)},
|
|
{"profile", str("debug")},
|
|
{"status", str("valid")},
|
|
{"diagnostic", str("")},
|
|
{"generation_id", str("1123456789abcdef")},
|
|
{"compdb_path", Json{db.native()}},
|
|
{"entry_count", integer(1)},
|
|
{"readiness_warnings", Json{Json::Array{}}}}));
|
|
const auto mismatch = status(session);
|
|
expect(read_string(mismatch, "state") == "stale" && issue(mismatch) == "generation_mismatch");
|
|
write_json(status_path, object({{"schema_version", integer(1)},
|
|
{"profile", str("debug")},
|
|
{"status", str("stale")},
|
|
{"diagnostic", str("build failed")}}));
|
|
const auto stale = status(session);
|
|
expect(read_string(stale, "state") == "stale" && issue(stale) == "vbs_stale");
|
|
expect(read_string(nested(stale, "lastGood"), "generation") ==
|
|
read_string(ready, "generation"));
|
|
fs::remove(db);
|
|
auto compdb = configuration({{"provider", str("compdb")}});
|
|
require(session.configure(&compdb).has_value());
|
|
expect(read_string(status(session), "provider") == "compdb");
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, managed_native_aliases_are_ineligible_for_automatic_compdb) {
|
|
Fixture f;
|
|
const auto build = f.one / "out";
|
|
const auto generation = f.native(f.one, build);
|
|
fs::remove(f.one / ".vbs/editor_selection.json");
|
|
vls::WorkspaceSession session;
|
|
require(session.initialize(initialize({folder(f.one)})).has_value());
|
|
for (const auto *relative : {"compile_commands.json", "out/compile_commands.json",
|
|
"out/profiles/debug/editor/compile_commands.json"}) {
|
|
fs::create_symlink(generation, f.one / relative);
|
|
auto config = configuration({{"compdbPath", str(relative)}});
|
|
require(session.configure(&config).has_value());
|
|
const auto result = status(session);
|
|
expect(read_string(result, "state") == "degraded" && issue(result) == "vbs_managed_alias");
|
|
expect(!field(result, "generation"));
|
|
}
|
|
auto manual = configuration(
|
|
{{"provider", str("compdb")}, {"compdbPath", str("out/compile_commands.json")}});
|
|
require(session.configure(&manual).has_value());
|
|
expect(read_string(status(session), "state") == "ready");
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, passive_commands_never_execute_and_launcher_grants_stay_root_bound) {
|
|
Fixture f;
|
|
const auto tool = f.one / "marker-tool";
|
|
const auto marker = f.one / "ran";
|
|
write(tool, "#!/bin/sh\n: > '" + marker.native() + "'\n");
|
|
fs::permissions(tool, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec);
|
|
const auto database = f.external / "selected.json";
|
|
f.compdb(f.one, database, 1, tool.native());
|
|
Workspace::SettingsOverrides flags;
|
|
flags.compdb_path = database;
|
|
flags.tool_approvals = {{f.one, Workspace::AuthorityLevel::compiler_use, tool}};
|
|
vls::WorkspaceSession session(
|
|
{.root = f.one, .cli_settings = Workspace::settings_from_cli(flags, f.base)});
|
|
auto settings = object({{"provider", str("compdb")},
|
|
{"compdbPath", Json{database.native()}},
|
|
{"allowExplicitBuildActions", Json{true}}});
|
|
require(session.initialize(initialize({folder(f.one), folder(f.two)}, settings)).has_value());
|
|
expect(read_string(status(session, query(f.one)), "state") == "ready");
|
|
const auto denied = status(session, query(f.two));
|
|
expect(read_string(denied, "state") == "degraded" && issue(denied) == "outside_scope");
|
|
expect(!fs::exists(marker));
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, launcher_anchors_survive_configuration_and_root_readdition) {
|
|
Fixture f;
|
|
const auto database = f.external / "chosen.json";
|
|
f.compdb(f.one, database);
|
|
Workspace::SettingsOverrides flags{.provider = Workspace::ProviderPreference::compdb,
|
|
.compdb_path = database};
|
|
vls::WorkspaceSession session(
|
|
{.root = f.one, .cli_settings = Workspace::settings_from_cli(flags, f.base)});
|
|
require(session.initialize(initialize({folder(f.one)})).has_value());
|
|
const auto initial = status(session);
|
|
auto replacement = database.parent_path() / "replacement.json";
|
|
f.compdb(f.one, replacement, 2);
|
|
fs::rename(replacement, database);
|
|
const auto good = status(session);
|
|
expect(read_string(good, "generation") != read_string(initial, "generation"));
|
|
|
|
// The next launcher receives exactly this directory, which will be replaced before init.
|
|
vls::WorkspaceSession before_init(
|
|
{.root = f.one, .cli_settings = Workspace::settings_from_cli(flags, f.base)});
|
|
fs::rename(f.external, f.base / "retired-external");
|
|
f.compdb(f.one, database, 3);
|
|
auto config = configuration({{"selectedProfile", str("debug")}});
|
|
require(session.configure(&config).has_value());
|
|
const auto replaced = status(session);
|
|
expect(read_string(replaced, "state") == "stale" && !field(replaced, "generation"));
|
|
expect(read_string(nested(replaced, "lastGood"), "generation") ==
|
|
read_string(good, "generation"));
|
|
auto reincarnate = change({folder(f.one)}, {folder(f.one)});
|
|
require(session.update_folders(&reincarnate).has_value());
|
|
const auto readded = status(session);
|
|
expect(read_string(readded, "state") == "stale" && issue(readded) == "changed");
|
|
expect(read_string(readded, "incarnation") != read_string(good, "incarnation"));
|
|
expect(!field(readded, "lastGood") && !field(readded, "generation"));
|
|
require(before_init.initialize(initialize({folder(f.one)})).has_value());
|
|
const auto initially_replaced = status(before_init);
|
|
expect(read_string(initially_replaced, "state") == "stale" &&
|
|
issue(initially_replaced) == "changed");
|
|
expect(!field(initially_replaced, "generation") && !field(initially_replaced, "lastGood"));
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, selector_appearance_invalidates_successful_fallback) {
|
|
Fixture f;
|
|
f.compdb(f.one, f.one / "compile_commands.json");
|
|
PauseObservation gate;
|
|
vls::WorkspaceSession session({}, [&] { gate.hook(); });
|
|
require(session.initialize(initialize({folder(f.one)})).has_value());
|
|
const auto discarded = gate.run(session, [&] { f.native(f.one, f.one / "native"); });
|
|
expect(read_string(discarded, "state") == "stale" && issue(discarded) == "inputs_changed");
|
|
expect(!field(discarded, "generation") && !field(discarded, "lastGood"));
|
|
const auto ready = status(session);
|
|
expect(read_string(ready, "provider") == "vbs" && read_string(ready, "state") == "ready");
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, appearing_native_status_and_replaced_db_invalidate_old_reads) {
|
|
Fixture f;
|
|
auto build = f.one / "native";
|
|
auto database = f.native(f.one, build);
|
|
const auto profile_status = build / "profiles/debug/editor/status.json";
|
|
fs::rename(profile_status, f.base / "saved.json");
|
|
PauseObservation gate;
|
|
vls::WorkspaceSession session({}, [&] { gate.hook(); });
|
|
require(session.initialize(initialize({folder(f.one)})).has_value());
|
|
auto stale = gate.run(session, [&] { fs::rename(f.base / "saved.json", profile_status); });
|
|
expect(issue(stale) == "inputs_changed");
|
|
const auto ready = status(session);
|
|
expect(read_string(ready, "state") == "ready");
|
|
stale = gate.run(session, [&] { write(database, "invalid"); });
|
|
expect(issue(stale) == "inputs_changed" && !field(stale, "generation"));
|
|
expect(read_string(nested(stale, "lastGood"), "generation") ==
|
|
read_string(ready, "generation"));
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, changing_the_queried_alias_invalidates_an_inflight_selection) {
|
|
Fixture f;
|
|
f.compdb(f.one, f.one / "compile_commands.json");
|
|
const auto alias = f.one / "alias.cpp";
|
|
write(f.one / "other.cpp", "int other;\n");
|
|
fs::create_symlink("main.cpp", alias);
|
|
PauseObservation gate;
|
|
vls::WorkspaceSession session({}, [&] { gate.hook(); });
|
|
require(session.initialize(initialize({folder(f.one)})).has_value());
|
|
const auto params = query(f.one, alias);
|
|
const auto initial = status(session, params);
|
|
expect(read_string(nested(initial, "selected"), "owningTu") ==
|
|
Docs::path_to_file_uri(f.one / "main.cpp"));
|
|
const auto stale = gate.run(
|
|
session,
|
|
[&] {
|
|
fs::remove(alias);
|
|
fs::create_symlink("other.cpp", alias);
|
|
},
|
|
params);
|
|
expect(issue(stale) == "inputs_changed" && !field(stale, "generation"));
|
|
expect(
|
|
std::holds_alternative<std::nullptr_t>(nested(status(session, params), "selected").value));
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, newer_success_and_failure_displace_older_observations) {
|
|
Fixture f;
|
|
const auto database = f.one / "compile_commands.json";
|
|
f.compdb(f.one, database);
|
|
PauseObservation gate;
|
|
vls::WorkspaceSession session({}, [&] { gate.hook(); });
|
|
require(session.initialize(initialize({folder(f.one)})).has_value());
|
|
const auto first = status(session);
|
|
// Both snapshots are good and use the same file identities. Sequence alone displaces the first.
|
|
auto stale =
|
|
gate.run(session, [&] { expect(read_string(status(session), "state") == "ready"); });
|
|
expect(issue(stale) == "superseded");
|
|
|
|
f.compdb(f.one, database, 2);
|
|
stale = gate.run(session, [&] {
|
|
write(database, "invalid");
|
|
expect(read_string(status(session), "state") == "degraded");
|
|
});
|
|
expect(issue(stale) == "superseded");
|
|
expect(read_string(nested(status(session), "lastGood"), "generation") ==
|
|
read_string(first, "generation"));
|
|
|
|
stale = gate.run(session, [&] {
|
|
f.compdb(f.one, database, 3);
|
|
expect(read_string(status(session), "state") == "ready");
|
|
});
|
|
expect(issue(stale) == "superseded");
|
|
const auto last = status(session);
|
|
write(database, "invalid");
|
|
expect(read_string(nested(status(session), "lastGood"), "generation") ==
|
|
read_string(last, "generation"));
|
|
}
|
|
|
|
VOID_TEST(ProviderSession, configuration_revocation_and_incarnation_reject_late_work) {
|
|
Fixture f;
|
|
f.compdb(f.one, f.one / "compile_commands.json");
|
|
f.compdb(f.one, f.one / "different.json", 2);
|
|
Workspace::SettingsOverrides flags;
|
|
flags.tool_approvals = {
|
|
{f.one, Workspace::AuthorityLevel::compiler_use, f.one / "marker-tool"}};
|
|
PauseObservation gate;
|
|
vls::WorkspaceSession session(
|
|
{.root = f.one, .cli_settings = Workspace::settings_from_cli(flags, f.base)},
|
|
[&] { gate.hook(); });
|
|
require(session.initialize(initialize({folder(f.one)})).has_value());
|
|
|
|
auto stale = gate.run(session, [&] {
|
|
auto config = configuration({{"compdbPath", str("different.json")}});
|
|
require(session.configure(&config).has_value());
|
|
});
|
|
expect(issue(stale) == "superseded" && !field(stale, "lastGood"));
|
|
const auto ready = status(session);
|
|
expect(Protocol::as_int64(field(ready, "contextCount")) == 2);
|
|
|
|
stale = gate.run(session, [&] { session.revoke_root_authority(f.one); });
|
|
expect(issue(stale) == "superseded" && !field(stale, "generation"));
|
|
|
|
std::string new_incarnation;
|
|
stale = gate.run(session, [&] {
|
|
auto removed = change({}, {folder(f.one)});
|
|
require(session.update_folders(&removed).has_value());
|
|
expect(read_string(status(session), "state") == "documentOnly");
|
|
auto added = change({folder(f.one)}, {});
|
|
require(session.update_folders(&added).has_value());
|
|
new_incarnation = read_string(status(session), "incarnation");
|
|
});
|
|
expect(issue(stale) == "superseded" && !field(stale, "lastGood"));
|
|
expect(read_string(stale, "incarnation") == read_string(ready, "incarnation"));
|
|
expect(read_string(stale, "incarnation") != new_incarnation);
|
|
expect(read_string(status(session), "incarnation") == new_incarnation);
|
|
}
|