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

Function stateOf

__tests__/sync-object-members.test.ts:57–75  ·  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

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

Callers 2

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