feat(cli,daemon): show lockfile contents; export mermaid graphs
This commit is contained in:
1 parent
eabcb92d0b
commit
da7e8233ce
8 files changed
+115
-6
No files matched your search
+25
-3
@@ -1031,13 +1031,13 @@ std::string compdb_export_project(const DaemonOptions &options, std::string_view
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
|
||||
// Renders the evaluated target dependency graph as Graphviz DOT or JSON.
|
||||
// Renders the evaluated target dependency graph as Graphviz DOT, JSON or Mermaid.
|
||||
std::string graph_project(const DaemonOptions &options, std::string_view profile_name,
|
||||
std::optional<CompilerFamily> compiler_override, std::string_view member,
|
||||
std::string_view format) {
|
||||
if (format != "dot" && format != "json") {
|
||||
if (format != "dot" && format != "json" && format != "mermaid") {
|
||||
return error_response(
|
||||
std::format("graph: unsupported format '{}' (expected dot or json)", format));
|
||||
std::format("graph: unsupported format '{}' (expected dot, json or mermaid)", format));
|
||||
}
|
||||
auto effective_result = resolve_member_options(options, member);
|
||||
if (!effective_result) {
|
||||
@@ -1070,6 +1070,28 @@ std::string graph_project(const DaemonOptions &options, std::string_view profile
|
||||
'}';
|
||||
});
|
||||
rendered += '}';
|
||||
} else if (format == "mermaid") {
|
||||
// Mermaid has no escaping for quotes inside node ids/labels, so replace them.
|
||||
const auto mermaid_name = [](std::string_view name) {
|
||||
std::string safe{name};
|
||||
std::replace(safe.begin(), safe.end(), '"', '\'');
|
||||
return safe;
|
||||
};
|
||||
rendered = "flowchart LR\n";
|
||||
for (const auto &target : description.targets) {
|
||||
rendered += " \"" + mermaid_name(target.name) + "\"[\"" + mermaid_name(target.name) +
|
||||
" (" + std::string{target_kind_name(target.kind)} + ")\"]\n";
|
||||
}
|
||||
for (const auto &target : description.targets) {
|
||||
for (const auto &prerequisite : target.prerequisites) {
|
||||
rendered += " \"" + mermaid_name(target.name) + "\" -.-> \"" +
|
||||
mermaid_name(prerequisite) + "\"\n";
|
||||
}
|
||||
for (const auto &link : target.links) {
|
||||
rendered += " \"" + mermaid_name(target.name) + "\" --> \"" +
|
||||
mermaid_name(link_name(link)) + "\"\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rendered = "digraph vbs_targets {\n rankdir=LR;\n";
|
||||
for (const auto &target : description.targets) {
|
||||
|
||||
Reference in new issue
Block a user