feat(daemon): serve IDE workspace and compdb metadata over the Unix socket
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 1m2s

This commit is contained in:
faumaray committed 2026-12-03 20:08:20 +03:00
1 parent e97f3905e5
commit 118c0dc860
9 files changed
+152 -8

No files matched your search

+47 -1
View File
@@ -3,6 +3,7 @@
#include <Void/Build.hpp>
#include <Void/Build/BootstrapConfig.hpp>
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Editor/CompDb.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Package/Lockfile.hpp>
@@ -12,6 +13,7 @@
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Build/Util/Json.hpp>
#include <Void/Build/Watch/Watcher.hpp>
#include <Void/Configuration/Env.hpp>
#include <Void/Data/StrictJson.hpp>
@@ -557,6 +559,47 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
return serialize_response(JsonValue{std::move(object)});
}
// Publishes the profile compilation database and returns the IDE query metadata JSON.
std::string ide_query_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "ide_query");
if (!evaluated) {
return error_response(evaluated.error());
}
auto graph = lower_graph(options, *evaluated, {}, "ide_query");
if (!graph) {
return error_response(graph.error());
}
const auto frontend = make_frontend_options(options);
const auto existing_selection =
Editor::read_selection_state(options.project_root).value_or(std::nullopt);
Editor::PublishOptions publish;
publish.project_root = options.project_root;
publish.build_root = options.build_root;
publish.update_selection = !existing_selection.has_value();
publish.sdk_include_dir = frontend.sdk_include_dir;
auto published = Editor::publish_profile_compdb(*graph, publish);
if (!published) {
return error_response(std::format("ide_query: {}", published.error().format()));
}
std::error_code ec;
const auto root_compdb = options.build_root / "compile_commands.json";
const auto compdb_path =
std::filesystem::exists(root_compdb, ec) ? root_compdb : published->compdb_path;
std::string query =
Editor::format_ide_query_json(*graph, compdb_path, frontend.sdk_include_dir);
// The socket protocol is one JSON object per line: the embedded query must not contain
// newlines before the final response terminator.
while (!query.empty() && (query.back() == '\n' || query.back() == '\r')) {
query.pop_back();
}
return "{\"ok\":true,\"op\":\"ide_query\",\"compdb\":" +
Util::json_quote(compdb_path.string()) + ",\"query\":" + query + '}';
}
// Lowers the project graph to a bounded summary without executing it.
std::string describe_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
@@ -713,7 +756,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "status") {
return {status_response(), false};
}
if (*name == "describe" || *name == "build") {
if (*name == "describe" || *name == "build" || *name == "ide_query") {
std::string profile_name{"debug"};
if (const auto entry = object->find("profile"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
@@ -743,6 +786,9 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "describe") {
return {describe_project(options, profile_name, compiler_override), false};
}
if (*name == "ide_query") {
return {ide_query_project(options, profile_name, compiler_override), false};
}
std::vector<std::string> selected_targets;
if (const auto entry = object->find("targets"); entry != object->end()) {