Skip to content

Commit 7b08b09

Browse files
Barnabás Domozibarnabasdomozi
authored andcommitted
[Diagrams] Use relative path
1 parent 4940e05 commit 7b08b09

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

plugins/python/service/src/diagram.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ util::Graph::Subgraph PythonDiagram::getFileSubgraph(util::Graph& graph_, const
196196
const std::string pathColor = (pyname.is_builtin && pyname.is_definition) ? "dodgerblue" : "limegreen";
197197
const std::string coloredLabel =
198198
"<table border=\"0\" cellborder=\"0\"><tr><td bgcolor=\"" + pathColor + "\">" +
199-
fileInfo.path +
199+
getRelativePath(fileInfo.path) +
200200
"</td></tr></table>";
201201
graph_.setSubgraphAttribute(subgraph, "label", coloredLabel, true);
202202

@@ -226,7 +226,8 @@ util::Graph::Node PythonDiagram::addPYNameNode(util::Graph& graph_, const model:
226226
util::Graph::Node PythonDiagram::addFileNode(util::Graph& graph_, const core::FileInfo& fileInfo)
227227
{
228228
util::Graph::Node node = graph_.getOrCreateNode("f" + fileInfo.id);
229-
graph_.setNodeAttribute(node, "label", fileInfo.path);
229+
const std::string path = getRelativePath(fileInfo.path);
230+
graph_.setNodeAttribute(node, "label", path);
230231

231232
return node;
232233
}
@@ -242,7 +243,8 @@ util::Graph::Node PythonDiagram::addFileNode(util::Graph& graph_, const core::Fi
242243
const std::string id = (nodeType == ImportedFilePathNode || nodeType == ImportedBuiltinFilePathNode) ? "d" + fileInfo.id : "s" + fileInfo.id;
243244

244245
util::Graph::Node node = graph_.getOrCreateNode(id);
245-
graph_.setNodeAttribute(node, "label", fileInfo.path);
246+
const std::string path = getRelativePath(fileInfo.path);
247+
graph_.setNodeAttribute(node, "label", path);
246248
decorateNode(graph_, node, nodeType);
247249

248250
if (nodeType == ImportedFilePathNode || nodeType == ImportedBuiltinFilePathNode) {
@@ -494,6 +496,27 @@ std::string PythonDiagram::getClassTable(const model::PYName& pyname)
494496
label += "</table>";
495497
return label;
496498
}
499+
500+
std::string PythonDiagram::getRelativePath(const std::string& path)
501+
{
502+
std::map<std::string, std::string> labels;
503+
m_projectService.getLabels(labels);
504+
505+
if (labels.count("src")) {
506+
std::string projectPath = labels["src"];
507+
std::string projectPathWithSlash = labels["src"] + "/";
508+
509+
if (path.substr(0, projectPathWithSlash.size()) == projectPathWithSlash) {
510+
return path.substr(projectPathWithSlash.size());
511+
}
512+
513+
if (path.substr(0, projectPath.size()) == projectPath) {
514+
return path.substr(projectPath.size());
515+
}
516+
}
517+
518+
return path;
519+
}
497520
} // language
498521
} // service
499522
} // cc

plugins/python/service/src/diagram.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace language
5757
util::Graph::Node addFileNode(util::Graph& graph_, const core::FileInfo& fileInfo);
5858
util::Graph::Subgraph getFileSubgraph(util::Graph& graph_, const model::PYName& pyname);
5959
std::string getClassTable(const model::PYName& pyname);
60+
std::string getRelativePath(const std::string& path);
6061
};
6162
} // language
6263
} // service

0 commit comments

Comments
 (0)