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

Function withoutPreviews

src/ui-server/api/entrypoints.ts:288–315  ·  view source on GitHub ↗

* The ranking with a Swift file's `#Preview { … }` calls taken out. * * A preview sits at the top level of a SwiftUI view's file, so its body's * constructions are module-level edges out of the file — and every view with * a preview ranked as "a file that runs something". A preview is Xcode's *

(cg: CodeGraph, rows: T[])

Source from the content-addressed store, hash-verified

286 * previews leaves the list; the rest are re-ranked on what is left.
287 */
288function withoutPreviews<T extends { nodeId: string; filePath: string; calls: number; reaches: number; score: number }>(cg: CodeGraph, rows: T[]): T[] {
289 let adjusted = false;
290 const out: T[] = [];
291 for (const row of rows) {
292 if (!row.filePath.endsWith('.swift')) {
293 out.push(row);
294 continue;
295 }
296 const text = readIndexedFileText(cg, cg.getProjectRoot(), row.filePath, MAX_PREVIEW_SCAN);
297 const spans = text && text.includes('#Preview') ? swiftPreviewSpans(text) : [];
298 if (spans.length === 0) {
299 out.push(row);
300 continue;
301 }
302 const inPreview = cg
303 .getOutgoingEdges(row.nodeId)
304 .filter((e) => (e.kind === 'calls' || e.kind === 'instantiates') && e.line != null && spans.some(([from, to]) => e.line! >= from && e.line! <= to)).length;
305 if (inPreview === 0) {
306 out.push(row);
307 continue;
308 }
309 adjusted = true;
310 const calls = row.calls - inPreview;
311 if (calls > 0) out.push({ ...row, calls, score: calls * (1 + row.reaches) });
312 }
313 if (adjusted) out.sort((a, b) => b.score - a.score || b.calls - a.calls || (a.filePath < b.filePath ? -1 : a.filePath > b.filePath ? 1 : 0));
314 return out;
315}
316
317/**
318 * The line spans (1-based, inclusive) of a Swift file's top-level

Callers 1

executableFilesFunction · 0.85

Calls 5

readIndexedFileTextFunction · 0.90
swiftPreviewSpansFunction · 0.85
pushMethod · 0.80
getProjectRootMethod · 0.65
getOutgoingEdgesMethod · 0.45

Tested by

no test coverage detected