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

Function buildFileRail

ui/src/lib/file-model.ts:91–129  ·  view source on GitHub ↗
(
  paths: readonly string[],
  importRows: readonly WireImportRow[],
  unresolved: ReadonlyArray<{ name: string; line: number }> = []
)

Source from the content-addressed store, hash-verified

89 * and on a hub like `src/types.ts` they would otherwise be most of the rail.
90 */
91export function buildFileRail(
92 paths: readonly string[],
93 importRows: readonly WireImportRow[],
94 unresolved: ReadonlyArray<{ name: string; line: number }> = []
95): FileRailModel {
96 const detail = new Map(importRows.map((row) => [row.file, row]));
97
98 const rows: FileRailRow[] = [...new Set(paths)].map((path) => {
99 const row = detail.get(path);
100 const symbols = namedSymbols(row);
101 return {
102 path,
103 test: row?.test ?? looksLikeTest(path),
104 imported: row !== undefined,
105 symbols,
106 symbolCount: symbols.length,
107 };
108 });
109
110 rows.sort(
111 (a, b) => Number(a.test) - Number(b.test) || a.path.localeCompare(b.path)
112 );
113
114 const byName = new Map<string, number[]>();
115 for (const item of unresolved) {
116 const lines = byName.get(item.name);
117 if (lines) lines.push(item.line);
118 else byName.set(item.name, [item.line]);
119 }
120
121 return {
122 rows,
123 total: rows.length,
124 testCount: rows.filter((row) => row.test).length,
125 outside: [...byName.entries()]
126 .map(([name, lines]) => ({ name, lines: [...lines].sort((a, b) => a - b) }))
127 .sort((a, b) => a.name.localeCompare(b.name)),
128 };
129}
130
131/**
132 * Whether a path looks like test code, for the rows no import edge described.

Callers 1

Calls 7

namedSymbolsFunction · 0.85
looksLikeTestFunction · 0.85
NumberInterface · 0.85
mapMethod · 0.80
pushMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected