MCPcopy
hub / github.com/continuedev/continue / hasCycle

Function hasCycle

extensions/cli/src/services/circular-dependencies.test.ts:48–72  ·  view source on GitHub ↗
(node: string, path: string[])

Source from the content-addressed store, hash-verified

46 const cycle: string[] = [];
47
48 const hasCycle = (node: string, path: string[]): boolean => {
49 if (recStack.has(node)) {
50 // Found a cycle - capture the cycle path
51 const cycleStart = path.indexOf(node);
52 cycle.push(...path.slice(cycleStart), node);
53 return true;
54 }
55
56 if (visited.has(node)) {
57 return false;
58 }
59
60 visited.add(node);
61 recStack.add(node);
62
63 const deps = dependencies[node] || [];
64 for (const dep of deps) {
65 if (hasCycle(dep, [...path, node])) {
66 return true;
67 }
68 }
69
70 recStack.delete(node);
71 return false;
72 };
73
74 // Check each service for cycles
75 for (const service of Object.keys(dependencies)) {

Callers 1

Calls 3

pushMethod · 0.65
addMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected