feat(daemon): list workspace members without evaluating them
This commit is contained in:
1 parent
8f68ec56e9
commit
ca9ad1158a
8 files changed
+102
-2
No files matched your search
@@ -950,6 +950,32 @@ std::string graph_project(const DaemonOptions &options, std::string_view profile
|
||||
",\"graph\":" + Util::json_quote(rendered) + '}';
|
||||
}
|
||||
|
||||
// Lists declared workspace members without evaluating their build descriptions.
|
||||
std::string workspace_members_project(const DaemonOptions &options) {
|
||||
JsonValue::Object object;
|
||||
object.emplace("ok", JsonValue{true});
|
||||
object.emplace("op", JsonValue{std::string{"workspace_members"}});
|
||||
if (!Config::is_workspace_root(options.project_root)) {
|
||||
object.emplace("workspace", JsonValue{false});
|
||||
object.emplace("members", JsonValue{JsonValue::Array{}});
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
auto members = evaluate_workspace_members(options);
|
||||
if (!members) {
|
||||
return error_response(members.error());
|
||||
}
|
||||
JsonValue::Array member_array;
|
||||
for (const auto &member : *members) {
|
||||
JsonValue::Object entry;
|
||||
entry.emplace("name", JsonValue{member.name});
|
||||
entry.emplace("path", JsonValue{member.path.string()});
|
||||
member_array.emplace_back(std::move(entry));
|
||||
}
|
||||
object.emplace("workspace", JsonValue{true});
|
||||
object.emplace("members", JsonValue{std::move(member_array)});
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
|
||||
// Returns bounded compile_commands entries from the active compilation database, optionally
|
||||
// filtered by a path suffix. Editor extensions use this instead of parsing the file themselves.
|
||||
std::string compdb_entries_project(const DaemonOptions &options, std::string_view file_filter,
|
||||
@@ -1439,6 +1465,9 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
if (*name == "editor_status") {
|
||||
return {editor_status_project(options), false};
|
||||
}
|
||||
if (*name == "workspace_members") {
|
||||
return {workspace_members_project(options), false};
|
||||
}
|
||||
if (*name == "compdb_entries") {
|
||||
std::string file_filter;
|
||||
if (const auto entry = object->find("file"); entry != object->end()) {
|
||||
|
||||
@@ -1565,6 +1565,8 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
Util::json_quote(opts.graph_format_arg));
|
||||
} else if (sub == "editor_status") {
|
||||
request_json = R"({"op":"editor_status"})";
|
||||
} else if (sub == "workspace_members") {
|
||||
request_json = R"({"op":"workspace_members"})";
|
||||
} else if (sub == "compdb_entries") {
|
||||
request_json =
|
||||
std::format(R"({{"op":"compdb_entries","limit":{}{}}})", opts.limit_arg,
|
||||
@@ -2662,6 +2664,11 @@ int main(int argc, char **argv) {
|
||||
.option_default("--profile", "-p", "Profile to export", daemon_opts.profile_arg, "debug")
|
||||
.option("--member", "", "Workspace member (required for workspace roots)",
|
||||
daemon_opts.member_arg);
|
||||
auto &daemon_workspace_cmd =
|
||||
daemon_cmd.subcommand("workspace", "Workspace metadata served by the daemon");
|
||||
auto &daemon_workspace_members_cmd =
|
||||
daemon_workspace_cmd.subcommand("members", "List declared workspace members");
|
||||
configure_daemon_common(daemon_workspace_members_cmd);
|
||||
auto &daemon_graph_cmd =
|
||||
daemon_cmd.subcommand("graph", "Export the target dependency graph via the daemon");
|
||||
configure_daemon_common(daemon_graph_cmd);
|
||||
@@ -2821,6 +2828,9 @@ int main(int argc, char **argv) {
|
||||
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "use") {
|
||||
daemon_sub = "compdb_use";
|
||||
} else if (daemon_sub == "workspace" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "members") {
|
||||
daemon_sub = "workspace_members";
|
||||
}
|
||||
return execute_daemon_command(daemon_sub, daemon_opts);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user