feat(daemon): support member-scoped IDE requests for workspaces
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 19s

This commit is contained in:
faumaray committed 2026-12-03 21:29:26 +03:00
1 parent d6bbd95ced
commit 359783d2ad
8 files changed
+149 -65

No files matched your search

+84 -51
View File
@@ -442,6 +442,32 @@ DaemonOptions member_options(const DaemonOptions &options,
return member;
}
// Resolves an optional workspace member selector into effective daemon options. Non-workspace
// roots reject a member selector; workspace roots require one.
Void::Result::Result<DaemonOptions, std::string>
resolve_member_options(const DaemonOptions &options, std::string_view member) {
if (!Config::is_workspace_root(options.project_root)) {
if (!member.empty()) {
return std::unexpected{
std::format("\"member\" is only valid for workspace roots (got '{}')", member)};
}
return options;
}
auto members = evaluate_workspace_members(options);
if (!members) {
return std::unexpected{members.error()};
}
if (member.empty()) {
return std::unexpected{std::string{"workspace roots require \"member\""}};
}
const auto match = std::ranges::find_if(
*members, [&](const WorkspaceMemberDir &candidate) { return candidate.name == member; });
if (match == members->end()) {
return std::unexpected{std::format("unknown workspace member '{}'", member)};
}
return member_options(options, match->path);
}
JsonValue::Array bounded_target_names(const Graph::BuildGraph &graph, bool &truncated) {
std::vector<std::string> target_names;
target_names.reserve(graph.targets.size());
@@ -590,26 +616,14 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
std::optional<CompilerFamily> compiler_override,
const std::vector<std::string> &selected_targets, std::size_t jobs,
std::string_view selected_member) {
DaemonOptions effective = options;
std::string member_name;
if (Config::is_workspace_root(options.project_root)) {
auto members = evaluate_workspace_members(options);
if (!members) {
return error_response(members.error());
}
if (selected_member.empty()) {
return error_response("build: workspace roots require \"member\"");
}
const auto match = std::ranges::find_if(*members, [&](const WorkspaceMemberDir &member) {
return member.name == selected_member;
});
if (match == members->end()) {
return error_response(
std::format("build: unknown workspace member '{}'", selected_member));
}
effective = member_options(options, match->path);
member_name = match->name;
auto effective_result = resolve_member_options(options, selected_member);
if (!effective_result) {
return error_response(std::format("build: {}", effective_result.error()));
}
const DaemonOptions &effective = *effective_result;
const std::string member_name = Config::is_workspace_root(options.project_root)
? std::string{selected_member}
: std::string{};
auto evaluated = evaluate_project_graph(effective, profile_name, compiler_override, "build");
if (!evaluated) {
@@ -691,16 +705,22 @@ std::filesystem::path effective_compdb_path(const DaemonOptions &options,
// Publishes the compilation database and reports its path and entry count.
std::string compdb_export_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "compdb");
std::optional<CompilerFamily> compiler_override,
std::string_view member) {
auto effective_result = resolve_member_options(options, member);
if (!effective_result) {
return error_response(std::format("compdb: {}", effective_result.error()));
}
const DaemonOptions &effective = *effective_result;
auto evaluated = evaluate_project_graph(effective, profile_name, compiler_override, "compdb");
if (!evaluated) {
return error_response(evaluated.error());
}
auto graph = lower_graph(options, *evaluated, {}, "compdb");
auto graph = lower_graph(effective, *evaluated, {}, "compdb");
if (!graph) {
return error_response(graph.error());
}
auto published = publish_compdb(options, *graph);
auto published = publish_compdb(effective, *graph);
if (!published) {
return error_response(std::format("compdb: {}", published.error()));
}
@@ -709,7 +729,7 @@ std::string compdb_export_project(const DaemonOptions &options, std::string_view
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"compdb"}});
object.emplace("profile", JsonValue{evaluated->context.name});
object.emplace("compdb", JsonValue{effective_compdb_path(options, *published).string()});
object.emplace("compdb", JsonValue{effective_compdb_path(effective, *published).string()});
object.emplace("entries", JsonValue{static_cast<std::int64_t>(published->entry_count)});
return serialize_response(JsonValue{std::move(object)});
}
@@ -717,31 +737,37 @@ std::string compdb_export_project(const DaemonOptions &options, std::string_view
// 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,
std::string_view editor_name, bool force) {
std::string_view editor_name, bool force,
std::string_view member) {
auto kind = Editor::parse_ide_kind(editor_name);
if (!kind) {
return error_response(kind.error().format());
}
auto effective_result = resolve_member_options(options, member);
if (!effective_result) {
return error_response(std::format("ide_generate: {}", effective_result.error()));
}
const DaemonOptions &effective = *effective_result;
auto evaluated =
evaluate_project_graph(options, profile_name, compiler_override, "ide_generate");
evaluate_project_graph(effective, profile_name, compiler_override, "ide_generate");
if (!evaluated) {
return error_response(evaluated.error());
}
auto graph = lower_graph(options, *evaluated, {}, "ide_generate");
auto graph = lower_graph(effective, *evaluated, {}, "ide_generate");
if (!graph) {
return error_response(graph.error());
}
auto published = publish_compdb(options, *graph);
auto published = publish_compdb(effective, *graph);
if (!published) {
return error_response(std::format("ide_generate: {}", published.error()));
}
const auto frontend = make_frontend_options(options);
const auto frontend = make_frontend_options(effective);
Editor::IdeConfigOptions ide;
ide.project_root = options.project_root;
ide.build_root = options.build_root;
ide.project_root = effective.project_root;
ide.build_root = effective.build_root;
ide.sdk_include_dir = frontend.sdk_include_dir;
ide.compdb_path = effective_compdb_path(options, *published);
ide.compdb_path = effective_compdb_path(effective, *published);
ide.editor = *kind;
ide.force = force;
std::error_code ec;
@@ -775,23 +801,30 @@ std::string ide_generate_project(const DaemonOptions &options, std::string_view
// Publishes the profile compilation database and returns the IDE query metadata JSON.
std::string ide_query_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "ide_query");
std::optional<CompilerFamily> compiler_override,
std::string_view member) {
auto effective_result = resolve_member_options(options, member);
if (!effective_result) {
return error_response(std::format("ide_query: {}", effective_result.error()));
}
const DaemonOptions &effective = *effective_result;
auto evaluated =
evaluate_project_graph(effective, profile_name, compiler_override, "ide_query");
if (!evaluated) {
return error_response(evaluated.error());
}
auto graph = lower_graph(options, *evaluated, {}, "ide_query");
auto graph = lower_graph(effective, *evaluated, {}, "ide_query");
if (!graph) {
return error_response(graph.error());
}
const auto frontend = make_frontend_options(options);
auto published = publish_compdb(options, *graph);
const auto frontend = make_frontend_options(effective);
auto published = publish_compdb(effective, *graph);
if (!published) {
return error_response(std::format("ide_query: {}", published.error()));
}
const auto compdb_path = effective_compdb_path(options, *published);
const auto compdb_path = effective_compdb_path(effective, *published);
std::string query =
Editor::format_ide_query_json(*graph, compdb_path, frontend.sdk_include_dir);
// The socket protocol is one JSON object per line: the embedded query must not contain
@@ -1090,14 +1123,22 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
return {error_response(ex.what()), false};
}
}
std::string member;
if (const auto entry = object->find("member"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr || value->empty() || value->size() > 128) {
return {error_response("\"member\" must be a bounded non-empty string"), false};
}
member = *value;
}
if (*name == "describe") {
return {describe_project(options, profile_name, compiler_override), false};
}
if (*name == "ide_query") {
return {ide_query_project(options, profile_name, compiler_override), false};
return {ide_query_project(options, profile_name, compiler_override, member), false};
}
if (*name == "compdb_export") {
return {compdb_export_project(options, profile_name, compiler_override), false};
return {compdb_export_project(options, profile_name, compiler_override, member), false};
}
if (*name == "ide_generate") {
std::string editor_name{"all"};
@@ -1116,9 +1157,9 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
}
force = *value;
}
return {
ide_generate_project(options, profile_name, compiler_override, editor_name, force),
false};
return {ide_generate_project(options, profile_name, compiler_override, editor_name,
force, member),
false};
}
std::vector<std::string> selected_targets;
@@ -1148,14 +1189,6 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
}
jobs = static_cast<std::size_t>(*value);
}
std::string member;
if (const auto entry = object->find("member"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr || value->empty() || value->size() > 128) {
return {error_response("\"member\" must be a bounded non-empty string"), false};
}
member = *value;
}
return {build_project(options, state_store, profile_name, compiler_override,
selected_targets, jobs, member),
false};