MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / targetsOf

Function targetsOf

__tests__/rust-use-path-module.test.ts:30–40  ·  view source on GitHub ↗
(cg: CodeGraph, file: string, name: string, kinds: string[])

Source from the content-addressed store, hash-verified

28
29/** What `name`, written in `file`, links to, as `file@line` of each target, sorted. */
30const targetsOf = (cg: CodeGraph, file: string, name: string, kinds: string[]): string[] => {
31 const out: string[] = [];
32 for (const node of cg.getNodesInFile(file)) {
33 for (const edge of cg.getOutgoingEdges(node.id)) {
34 if (!kinds.includes(edge.kind)) continue;
35 const target = cg.getNode(edge.target)!;
36 if (target.name === name) out.push(`${target.filePath}@${target.startLine}`);
37 }
38 }
39 return [...new Set(out)].sort();
40};
41
42describe('a name a Rust `use` binds, by the module its path walks', () => {
43 let root = '';

Callers 1

Calls 4

getNodeMethod · 0.80
pushMethod · 0.80
getNodesInFileMethod · 0.65
getOutgoingEdgesMethod · 0.45

Tested by

no test coverage detected