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

Function stateOf

__tests__/sync-module-config-change.test.ts:54–72  ·  view source on GitHub ↗

Every edge by its ends' natural keys, and every reference left unresolved.

(root: string, graph: CodeGraph)

Source from the content-addressed store, hash-verified

52
53/** Every edge by its ends' natural keys, and every reference left unresolved. */
54function stateOf(root: string, graph: CodeGraph): string[] {
55 const keys = new Map(
56 graph.getFiles()
57 .flatMap((file) => graph.getNodesInFile(file.path))
58 .map((n) => [n.id, `${n.kind} ${n.filePath}:${n.qualifiedName}:${n.startLine}`] as const)
59 );
60 const edges = graph.getOutgoingEdgesFrom([...keys.keys()])
61 .map((e) => `${e.kind} ${keys.get(e.source)} -> ${keys.get(e.target) ?? e.target} @${e.line}:${e.column} ${JSON.stringify(e.metadata ?? {})}`);
62 const db = DatabaseConnection.open(getDatabasePath(root));
63 try {
64 const refs = (db.getDb()
65 .prepare('SELECT reference_name, reference_kind, file_path, line, col, status, name_tail FROM unresolved_refs')
66 .all() as Array<Record<string, unknown>>)
67 .map((r) => `ref ${r.file_path}:${r.line}:${r.col} ${r.reference_kind} ${r.reference_name} ${r.status} ${r.name_tail}`);
68 return [...edges, ...refs].sort();
69 } finally {
70 db.close();
71 }
72}
73
74/** The files the calls written in `caller` land in. */
75function callTargets(graph: CodeGraph, caller: string): string[] {

Callers 3

fullIndexWithDbFunction · 0.70
syncEditFunction · 0.70

Calls 11

getDatabasePathFunction · 0.90
mapMethod · 0.80
getFilesMethod · 0.80
getDbMethod · 0.80
getNodesInFileMethod · 0.65
getMethod · 0.65
openMethod · 0.65
allMethod · 0.65
prepareMethod · 0.65
closeMethod · 0.65
getOutgoingEdgesFromMethod · 0.45

Tested by

no test coverage detected