feat(daemon): serve bounded compile command entries to editor extensions
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 41s

This commit is contained in:
faumaray committed 2026-12-03 22:58:17 +03:00
1 parent afea6f3fad
commit 40fef50a6f
9 files changed
+237 -2

No files matched your search

+68
View File
@@ -909,6 +909,74 @@ void build(Void::Build::Project &project) {
Void::Testing::expect_eq(int_field(*object, "tests_failed"), std::int64_t{1});
}
VOID_TEST(Daemon, compdb_entries_queries_published_database) {
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
Void::Testing::require(temp.has_value());
const auto options = make_options(temp->path());
{
std::ofstream descriptor{options.project_root / "build.cpp"};
descriptor << R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &project) {
auto app = project.executable("app");
app.sources({"main.cpp"});
}
)cpp";
Void::Testing::require(descriptor.good());
}
{
std::ofstream source{options.project_root / "main.cpp"};
source << "int main() { return 0; }\n";
Void::Testing::require(source.good());
}
auto server = Void::Build::Daemon::DaemonServer::create(options);
Void::Testing::require(server.has_value());
const auto socket = server->socket_path();
Void::Result::Result<void, Void::Result::Error> run_result;
std::jthread worker{[&] { run_result = server->run(); }};
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
auto unpublished = request_object(socket, R"({"op":"compdb_entries"})");
Void::Testing::require(unpublished.has_value());
Void::Testing::expect(!bool_field(*unpublished, "ok", true));
auto exported = request_object(socket, R"({"op":"compdb_export"})", std::chrono::seconds{120});
Void::Testing::require(exported.has_value());
Void::Testing::expect(bool_field(*exported, "ok"));
auto all = request_object(socket, R"({"op":"compdb_entries"})");
Void::Testing::require(all.has_value());
Void::Testing::expect(bool_field(*all, "ok"));
Void::Testing::expect(int_field(*all, "total") >= 1);
Void::Testing::expect(int_field(*all, "returned") >= 1);
auto filtered =
request_object(socket, R"({"op":"compdb_entries","file":"main.cpp","limit":1})");
Void::Testing::require(filtered.has_value());
Void::Testing::expect(bool_field(*filtered, "ok"));
Void::Testing::expect(int_field(*filtered, "returned") <= 1);
const auto *entries = field(*filtered, "entries");
Void::Testing::require(entries != nullptr);
const auto *entry_array = std::get_if<JsonValue::Array>(&entries->value);
Void::Testing::require(entry_array != nullptr && !entry_array->empty());
const auto *first = std::get_if<JsonObject>(&entry_array->front().value);
Void::Testing::require(first != nullptr);
Void::Testing::expect(str_field(*first, "file").find("main.cpp") != std::string::npos);
Void::Testing::expect(field(*first, "arguments") != nullptr);
auto invalid_limit = request_object(socket, R"({"op":"compdb_entries","limit":501})");
Void::Testing::require(invalid_limit.has_value());
Void::Testing::expect(!bool_field(*invalid_limit, "ok", true));
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
Void::Testing::expect(shutdown.has_value());
worker.join();
Void::Testing::expect(run_result.has_value());
}
VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) {
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
Void::Testing::require(temp.has_value());