Skip to content

Commit e74d3f5

Browse files
committed
Refactor dependency link creation in graph visualization for improved efficiency
- Introduced a Set for quick lookup of node IDs to filter out external dependencies. - Ensured that dependencies are iterated only if they are in array format. - Added checks to confirm the existence of both source and target nodes before creating links.
1 parent 1bd288f commit e74d3f5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

vscode-rescriptdep/src/extension.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -842,19 +842,26 @@ function showGraphWebview(context: vscode.ExtensionContext, jsonContent: string,
842842
width: Math.max(module.name.length * 10, 100),
843843
height: 40
844844
}));
845-
846-
// Create links for all dependencies
845+
// Create a set of node IDs for quick lookup
846+
const nodeIds = new Set(nodes.map(n => n.id)); // Add set for efficient lookup
847+
848+
// Create links for all dependencies, filtering out external ones
847849
const links = [];
848850
data.modules.forEach(module => {
849-
module.dependencies.forEach(dep => {
851+
// Ensure dependencies is an array before iterating
852+
const dependencies = Array.isArray(module.dependencies) ? module.dependencies : [];
853+
dependencies.forEach(dep => {
850854
const targetName = typeof dep === 'object' ? dep.name : dep;
851-
links.push({
852-
source: module.name,
853-
target: targetName
854-
});
855+
// Check if both source and target nodes exist in our node list
856+
if (nodeIds.has(module.name) && nodeIds.has(targetName)) { // Filter links
857+
links.push({
858+
source: module.name,
859+
target: targetName
860+
});
861+
}
855862
});
856863
});
857-
864+
858865
// Create SVG element
859866
const svg = d3.select('#graph')
860867
.attr('width', width)

0 commit comments

Comments
 (0)