feat(daemon): report editor selection and compdb status
This commit is contained in:
1 parent
1a884fd931
commit
343e03c27c
9 files changed
+140
-6
No files matched your search
@@ -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()) {
|
||||
|
||||
+12
-4
@@ -1551,6 +1551,8 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
}
|
||||
request_json =
|
||||
std::format(R"({{"op":"describe","profile":{}}})", Util::json_quote(opts.profile_arg));
|
||||
} else if (sub == "editor_status") {
|
||||
request_json = R"({"op":"editor_status"})";
|
||||
} else if (sub == "watch_poll") {
|
||||
request_json = R"({"op":"watch_poll"})";
|
||||
} else if (sub == "watch_wait") {
|
||||
@@ -1618,10 +1620,10 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
// Describe evaluates the whole project graph (descriptor compile, toolchain probe, lowering),
|
||||
// which can exceed the 2 s default; the daemon bounds evaluation at 10 s.
|
||||
const auto request_timeout =
|
||||
sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}}
|
||||
: sub == "watch_poll" ? std::chrono::milliseconds{5000}
|
||||
: sub == "watch_wait" ? std::chrono::milliseconds{10000}
|
||||
: sub == "describe" ? std::chrono::milliseconds{15000}
|
||||
sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}}
|
||||
: (sub == "watch_poll" || sub == "editor_status") ? std::chrono::milliseconds{5000}
|
||||
: sub == "watch_wait" ? std::chrono::milliseconds{10000}
|
||||
: sub == "describe" ? std::chrono::milliseconds{15000}
|
||||
: (sub == "ide_query" || sub == "ide_generate" || sub == "compdb_export")
|
||||
? std::chrono::milliseconds{30000}
|
||||
: std::chrono::milliseconds{2000};
|
||||
@@ -2621,6 +2623,9 @@ int main(int argc, char **argv) {
|
||||
.option_default("--profile", "-p", "Profile to query", daemon_opts.profile_arg, "debug")
|
||||
.option("--member", "", "Workspace member (required for workspace roots)",
|
||||
daemon_opts.member_arg);
|
||||
auto &daemon_ide_status_cmd =
|
||||
daemon_ide_cmd.subcommand("status", "Report the active editor selection and compdb state");
|
||||
configure_daemon_common(daemon_ide_status_cmd);
|
||||
auto &daemon_ide_poll_cmd = daemon_ide_cmd.subcommand(
|
||||
"poll", "Poll pending project file changes (editor extension protocol)");
|
||||
configure_daemon_common(daemon_ide_poll_cmd);
|
||||
@@ -2744,6 +2749,9 @@ int main(int argc, char **argv) {
|
||||
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "generate") {
|
||||
daemon_sub = "ide_generate";
|
||||
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "status") {
|
||||
daemon_sub = "editor_status";
|
||||
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "poll") {
|
||||
daemon_sub = "watch_poll";
|
||||
|
||||
Reference in new issue
Block a user