feat(daemon): select the active editor profile over the socket
This commit is contained in:
1 parent
343e03c27c
commit
502f2b0c51
9 files changed
+120
-2
No files matched your search
@@ -810,6 +810,23 @@ std::string compdb_export_project(const DaemonOptions &options, std::string_view
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
|
||||
// Switches the active editor profile to an already-published compilation database.
|
||||
std::string compdb_use_project(const DaemonOptions &options, std::string_view profile_name) {
|
||||
auto state =
|
||||
Editor::select_editor_profile(options.project_root, options.build_root, profile_name);
|
||||
if (!state) {
|
||||
return error_response(std::format("compdb_use: {}", state.error().format()));
|
||||
}
|
||||
JsonValue::Object object;
|
||||
object.emplace("ok", JsonValue{true});
|
||||
object.emplace("op", JsonValue{std::string{"compdb_use"}});
|
||||
object.emplace("profile", JsonValue{state->selected_profile});
|
||||
object.emplace("generation_id", JsonValue{state->selected_generation_id});
|
||||
object.emplace("ticket", JsonValue{static_cast<std::int64_t>(state->ticket)});
|
||||
object.emplace("compdb", JsonValue{state->selected_compdb_path.string()});
|
||||
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);
|
||||
@@ -1179,6 +1196,17 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
if (*name == "editor_status") {
|
||||
return {editor_status_project(options), false};
|
||||
}
|
||||
if (*name == "compdb_use") {
|
||||
const auto entry = object->find("profile");
|
||||
if (entry == object->end()) {
|
||||
return {error_response("compdb_use 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_use_project(options, *value), false};
|
||||
}
|
||||
if (*name == "watch_wait") {
|
||||
std::int64_t timeout_ms = kDefaultWatchWaitMs;
|
||||
if (const auto entry = object->find("timeout_ms"); entry != object->end()) {
|
||||
|
||||
@@ -1578,6 +1578,13 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
opts.force ? "true" : "false",
|
||||
opts.member_arg ? std::format(",\"member\":{}", Util::json_quote(*opts.member_arg))
|
||||
: std::string{});
|
||||
} else if (sub == "compdb_use") {
|
||||
if (opts.profile_arg.empty()) {
|
||||
std::cerr << "vbs daemon compdb use: --profile must not be empty\n";
|
||||
return 2;
|
||||
}
|
||||
request_json = std::format(R"({{"op":"compdb_use","profile":{}}})",
|
||||
Util::json_quote(opts.profile_arg));
|
||||
} else if (sub == "compdb_export") {
|
||||
if (opts.profile_arg.empty()) {
|
||||
std::cerr << "vbs daemon compdb export: --profile must not be empty\n";
|
||||
@@ -1622,6 +1629,7 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
const auto request_timeout =
|
||||
sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}}
|
||||
: (sub == "watch_poll" || sub == "editor_status") ? std::chrono::milliseconds{5000}
|
||||
: sub == "compdb_use" ? std::chrono::milliseconds{10000}
|
||||
: sub == "watch_wait" ? std::chrono::milliseconds{10000}
|
||||
: sub == "describe" ? std::chrono::milliseconds{15000}
|
||||
: (sub == "ide_query" || sub == "ide_generate" || sub == "compdb_export")
|
||||
@@ -2607,6 +2615,11 @@ int main(int argc, char **argv) {
|
||||
daemon_opts.jobs_arg, "0");
|
||||
auto &daemon_compdb_cmd =
|
||||
daemon_cmd.subcommand("compdb", "Editor compilation database served by the daemon");
|
||||
auto &daemon_compdb_use_cmd =
|
||||
daemon_compdb_cmd.subcommand("use", "Select an already-published editor profile");
|
||||
configure_daemon_common(daemon_compdb_use_cmd);
|
||||
daemon_compdb_use_cmd.option_default("--profile", "-p", "Profile to select",
|
||||
daemon_opts.profile_arg, "debug");
|
||||
auto &daemon_compdb_export_cmd =
|
||||
daemon_compdb_cmd.subcommand("export", "Publish the profile compilation database");
|
||||
configure_daemon_common(daemon_compdb_export_cmd);
|
||||
@@ -2761,6 +2774,9 @@ int main(int argc, char **argv) {
|
||||
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "export") {
|
||||
daemon_sub = "compdb_export";
|
||||
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "use") {
|
||||
daemon_sub = "compdb_use";
|
||||
}
|
||||
return execute_daemon_command(daemon_sub, daemon_opts);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user