feat(daemon): list editor generation history
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 2s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 30s

This commit is contained in:
faumaray committed 2026-12-03 23:43:03 +03:00
1 parent ba682e8bd1
commit 41a74bc925
8 files changed
+217 -2

No files matched your search

+116
View File
@@ -22,6 +22,7 @@
#include <Void/System/Path.hpp>
#include <algorithm>
#include <cctype>
#include <cerrno>
#include <chrono>
#include <cstddef>
@@ -64,6 +65,7 @@ constexpr std::size_t kMaxBuildTargets = 64U;
constexpr std::size_t kMaxCompdbArguments = 256U;
constexpr std::size_t kMaxCompdbArgumentBytes = 1024U;
constexpr std::size_t kMaxCompdbEntries = 500U;
constexpr std::size_t kMaxCompdbGenerations = 128U;
constexpr std::size_t kMaxPendingChanges = 4096U;
constexpr std::int64_t kMaxWatchWaitMs = 5000;
constexpr std::int64_t kDefaultWatchWaitMs = 2000;
@@ -950,6 +952,109 @@ std::string graph_project(const DaemonOptions &options, std::string_view profile
",\"graph\":" + Util::json_quote(rendered) + '}';
}
// Lists immutable editor generations for a profile, including the active selection.
std::string compdb_generations_project(const DaemonOptions &options,
std::string_view profile_name) {
const bool valid_profile =
!profile_name.empty() && profile_name.size() <= 128 &&
std::ranges::all_of(profile_name, [](char c) {
return std::isalnum(static_cast<unsigned char>(c)) || c == '.' || c == '_' || c == '-';
});
if (!valid_profile) {
return error_response("compdb_generations: profile must be 1-128 chars of [A-Za-z0-9._-]");
}
const auto profile_dir = options.build_root / "profiles" / std::string{profile_name} / "editor";
const auto generation_root = profile_dir / "generations";
std::string active_generation;
auto selection = Editor::read_selection_state(options.project_root);
if (selection && selection->has_value()) {
active_generation = (*selection)->selected_generation_id;
}
// The per-profile status record describes the most recently published generation.
std::string status_generation;
std::string status_value{"unknown"};
std::string status_diagnostic;
std::int64_t status_entries = 0;
if (auto text = Void::FileSystem::read_file(profile_dir / "status.json"); text) {
if (auto parsed = Void::Json::Strict::parse(*text); parsed) {
if (const auto *object = std::get_if<JsonValue::Object>(&parsed->value)) {
const auto read_string = [&](std::string_view key, std::string &out) {
if (const auto it = object->find(key); it != object->end()) {
if (const auto *value = std::get_if<std::string>(&it->second.value)) {
out = *value;
}
}
};
read_string("generation_id", status_generation);
read_string("status", status_value);
read_string("diagnostic", status_diagnostic);
if (const auto it = object->find("entry_count"); it != object->end()) {
if (const auto *value = std::get_if<std::int64_t>(&it->second.value)) {
status_entries = *value;
}
}
}
}
}
JsonValue::Array generations;
std::error_code ec;
if (std::filesystem::is_directory(generation_root, ec)) {
std::vector<std::filesystem::path> directories;
for (const auto &entry : std::filesystem::directory_iterator(generation_root, ec)) {
if (entry.is_directory()) {
directories.push_back(entry.path());
}
}
std::ranges::sort(directories);
for (const auto &directory : directories) {
if (generations.size() >= kMaxCompdbGenerations) {
break;
}
const auto compdb = directory / "compile_commands.json";
if (!std::filesystem::is_regular_file(compdb, ec)) {
continue;
}
const std::string generation_id = directory.filename().string();
const bool is_status_generation = generation_id == status_generation;
JsonValue::Object generation;
generation.emplace("id", JsonValue{generation_id});
generation.emplace("active", JsonValue{generation_id == active_generation});
generation.emplace(
"status", JsonValue{is_status_generation ? status_value : std::string{"archived"}});
generation.emplace("diagnostic",
JsonValue{is_status_generation ? status_diagnostic : std::string{}});
std::int64_t entry_count = is_status_generation ? status_entries : 0;
if (!is_status_generation) {
if (auto text = Void::FileSystem::read_file(compdb); text) {
if (auto parsed = Void::Json::Strict::parse(*text); parsed) {
if (const auto *array = std::get_if<JsonValue::Array>(&parsed->value)) {
entry_count = static_cast<std::int64_t>(array->size());
}
}
}
}
generation.emplace("entries", JsonValue{entry_count});
generations.emplace_back(std::move(generation));
}
}
JsonValue::Object object;
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"compdb_generations"}});
object.emplace("profile", JsonValue{std::string{profile_name}});
if (active_generation.empty()) {
object.emplace("active", JsonValue{nullptr});
} else {
object.emplace("active", JsonValue{active_generation});
}
object.emplace("generations", JsonValue{std::move(generations)});
return serialize_response(JsonValue{std::move(object)});
}
// Reports which editor configuration files are present for the project.
std::string ide_configs_project(const DaemonOptions &options) {
struct ConfigEntry {
@@ -1502,6 +1607,17 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "ide_configs") {
return {ide_configs_project(options), false};
}
if (*name == "compdb_generations") {
const auto entry = object->find("profile");
if (entry == object->end()) {
return {error_response("compdb_generations requires \"profile\""), false};
}
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr || value->empty() || value->size() > kMaxDescribeProfileBytes) {
return {error_response("\"profile\" must be a bounded non-empty string"), false};
}
return {compdb_generations_project(options, *value), false};
}
if (*name == "compdb_entries") {
std::string file_filter;
if (const auto entry = object->find("file"); entry != object->end()) {