feat(daemon): report editor selection and compdb status
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 9s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 34s

This commit is contained in:
faumaray committed 2026-12-03 21:42:09 +03:00
1 parent 1a884fd931
commit 343e03c27c
9 files changed
+140 -6

No files matched your search

+47
View File
@@ -28,6 +28,7 @@
#include <cstring>
#include <fcntl.h>
#include <format>
#include <fstream>
#include <limits>
#include <optional>
#include <poll.h>
@@ -809,6 +810,49 @@ std::string compdb_export_project(const DaemonOptions &options, std::string_view
return serialize_response(JsonValue{std::move(object)});
}
// Reports the active editor selection and the published compilation database state.
std::string editor_status_project(const DaemonOptions &options) {
auto selection = Editor::read_selection_state(options.project_root);
if (!selection) {
return error_response(std::format("editor_status: {}", selection.error().format()));
}
JsonValue::Object object;
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"editor_status"}});
if (!selection->has_value()) {
object.emplace("selection", JsonValue{nullptr});
object.emplace("compdb_exists", JsonValue{false});
return serialize_response(JsonValue{std::move(object)});
}
const auto &state = **selection;
JsonValue::Object selected;
selected.emplace("ticket", JsonValue{static_cast<std::int64_t>(state.ticket)});
selected.emplace("profile", JsonValue{state.selected_profile});
selected.emplace("build_root", JsonValue{state.selected_build_root.string()});
selected.emplace("generation_id", JsonValue{state.selected_generation_id});
selected.emplace("compdb_path", JsonValue{state.selected_compdb_path.string()});
selected.emplace("alias_active", JsonValue{state.managed_root_alias_active});
selected.emplace("alias_warning", JsonValue{state.root_alias_warning});
object.emplace("selection", JsonValue{std::move(selected)});
std::ifstream compdb{state.selected_compdb_path};
const bool compdb_exists = compdb.good();
object.emplace("compdb_exists", JsonValue{compdb_exists});
if (compdb_exists) {
std::string text{std::istreambuf_iterator<char>{compdb}, std::istreambuf_iterator<char>{}};
auto parsed = Void::Json::Strict::parse(text);
if (parsed) {
if (const auto *array = std::get_if<JsonValue::Array>(&parsed->value)) {
object.emplace("compdb_entries",
JsonValue{static_cast<std::int64_t>(array->size())});
}
}
}
return serialize_response(JsonValue{std::move(object)});
}
// Publishes the compilation database and writes the requested editor configuration files.
std::string ide_generate_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
@@ -1132,6 +1176,9 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
object.emplace("rescan_required", JsonValue{batch->rescan_required});
return {serialize_response(JsonValue{std::move(object)}), false};
}
if (*name == "editor_status") {
return {editor_status_project(options), false};
}
if (*name == "watch_wait") {
std::int64_t timeout_ms = kDefaultWatchWaitMs;
if (const auto entry = object->find("timeout_ms"); entry != object->end()) {