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

Function indexProject

__tests__/objc-file-scope-variables.test.ts:91–109  ·  view source on GitHub ↗

Index `files` and return what a method's edges, `contains` aside, reach.

(files: Record<string, string>)

Source from the content-addressed store, hash-verified

89
90 /** Index `files` and return what a method's edges, `contains` aside, reach. */
91 async function indexProject(files: Record<string, string>): Promise<(method: string) => string[]> {
92 root = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-objc-globals-'));
93 for (const [rel, content] of Object.entries(files)) {
94 fs.mkdirSync(path.dirname(path.join(root, rel)), { recursive: true });
95 fs.writeFileSync(path.join(root, rel), content);
96 }
97 const graph = (cg = await CodeGraph.init(root, { index: true }));
98 return (method: string) => {
99 const node = graph.getNodesByName(method).find((n) => n.kind === 'method')!;
100 expect(node, method).toBeDefined();
101 return graph
102 .getOutgoingEdges(node.id)
103 .filter((e) => e.kind !== 'contains')
104 .map((e) => {
105 const t = graph.getNode(e.target)!;
106 return `${e.kind} ${t.kind} ${t.name} ${t.filePath}`;
107 });
108 };
109 }
110
111 it('reaches a global through the header that declares it', async () => {
112 const targetsOf = await indexProject({

Calls 6

mapMethod · 0.80
getNodeMethod · 0.80
getNodesByNameMethod · 0.65
joinMethod · 0.45
initMethod · 0.45
getOutgoingEdgesMethod · 0.45

Tested by

no test coverage detected