feat(daemon): generate editor configuration files over the Unix socket
This commit is contained in:
1 parent
72f4237af2
commit
e15e2cb2b4
9 files changed
+189
-9
No files matched your search
+81
-1
@@ -609,6 +609,65 @@ std::string compdb_export_project(const DaemonOptions &options, std::string_view
|
||||
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,
|
||||
std::string_view editor_name, bool force) {
|
||||
auto kind = Editor::parse_ide_kind(editor_name);
|
||||
if (!kind) {
|
||||
return error_response(kind.error().format());
|
||||
}
|
||||
auto evaluated =
|
||||
evaluate_project_graph(options, profile_name, compiler_override, "ide_generate");
|
||||
if (!evaluated) {
|
||||
return error_response(evaluated.error());
|
||||
}
|
||||
auto graph = lower_graph(options, *evaluated, {}, "ide_generate");
|
||||
if (!graph) {
|
||||
return error_response(graph.error());
|
||||
}
|
||||
auto published = publish_compdb(options, *graph);
|
||||
if (!published) {
|
||||
return error_response(std::format("ide_generate: {}", published.error()));
|
||||
}
|
||||
|
||||
const auto frontend = make_frontend_options(options);
|
||||
Editor::IdeConfigOptions ide;
|
||||
ide.project_root = options.project_root;
|
||||
ide.build_root = options.build_root;
|
||||
ide.sdk_include_dir = frontend.sdk_include_dir;
|
||||
ide.compdb_path = effective_compdb_path(options, *published);
|
||||
ide.editor = *kind;
|
||||
ide.force = force;
|
||||
std::error_code ec;
|
||||
ide.vbs_executable = std::filesystem::read_symlink("/proc/self/exe", ec);
|
||||
if (ec || ide.vbs_executable.empty()) {
|
||||
ide.vbs_executable = "vbs";
|
||||
}
|
||||
|
||||
auto report = Editor::generate_ide_configs(*graph, ide);
|
||||
if (!report) {
|
||||
return error_response(std::format("ide_generate: {}", report.error().format()));
|
||||
}
|
||||
|
||||
JsonValue::Array written;
|
||||
for (const auto &path : report->written_files) {
|
||||
written.emplace_back(path.string());
|
||||
}
|
||||
JsonValue::Array skipped;
|
||||
for (const auto &path : report->skipped_existing_files) {
|
||||
skipped.emplace_back(path.string());
|
||||
}
|
||||
JsonValue::Object object;
|
||||
object.emplace("ok", JsonValue{true});
|
||||
object.emplace("op", JsonValue{std::string{"ide_generate"}});
|
||||
object.emplace("profile", JsonValue{evaluated->context.name});
|
||||
object.emplace("editor", JsonValue{std::string{Editor::ide_kind_name(*kind)}});
|
||||
object.emplace("written", JsonValue{std::move(written)});
|
||||
object.emplace("skipped", JsonValue{std::move(skipped)});
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -796,7 +855,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
return {status_response(), false};
|
||||
}
|
||||
if (*name == "describe" || *name == "build" || *name == "ide_query" ||
|
||||
*name == "compdb_export") {
|
||||
*name == "ide_generate" || *name == "compdb_export") {
|
||||
std::string profile_name{"debug"};
|
||||
if (const auto entry = object->find("profile"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::string>(&entry->second.value);
|
||||
@@ -832,6 +891,27 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
if (*name == "compdb_export") {
|
||||
return {compdb_export_project(options, profile_name, compiler_override), false};
|
||||
}
|
||||
if (*name == "ide_generate") {
|
||||
std::string editor_name{"all"};
|
||||
if (const auto entry = object->find("editor"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::string>(&entry->second.value);
|
||||
if (value == nullptr || value->empty()) {
|
||||
return {error_response("\"editor\" must be a non-empty string"), false};
|
||||
}
|
||||
editor_name = *value;
|
||||
}
|
||||
bool force = false;
|
||||
if (const auto entry = object->find("force"); entry != object->end()) {
|
||||
const auto *value = std::get_if<bool>(&entry->second.value);
|
||||
if (value == nullptr) {
|
||||
return {error_response("\"force\" must be a boolean"), false};
|
||||
}
|
||||
force = *value;
|
||||
}
|
||||
return {
|
||||
ide_generate_project(options, profile_name, compiler_override, editor_name, force),
|
||||
false};
|
||||
}
|
||||
|
||||
std::vector<std::string> selected_targets;
|
||||
if (const auto entry = object->find("targets"); entry != object->end()) {
|
||||
|
||||
Reference in new issue
Block a user