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

Function swiftPreviewSpans

src/ui-server/api/entrypoints.ts:322–352  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

320 * `#Preview(as: .systemSmall) { … } timeline: { … }` is one preview.
321 */
322export function swiftPreviewSpans(text: string): Array<[number, number]> {
323 const lines = text.split(/\r?\n/);
324 const spans: Array<[number, number]> = [];
325 for (let i = 0; i < lines.length; i++) {
326 if (!/^#Preview\b/.test(lines[i]!)) continue;
327 let depth = 0;
328 let opened = false;
329 let end = -1;
330 for (let j = i; j < lines.length && end < 0; j++) {
331 const line = lines[j]!;
332 for (let c = 0; c < line.length; c++) {
333 const ch = line[c];
334 if (ch === '{') {
335 depth++;
336 opened = true;
337 } else if (ch === '}' && opened && --depth === 0) {
338 // Another trailing closure (`} timeline: {`) continues the macro.
339 const rest = `${line.slice(c + 1)} ${lines[j + 1] ?? ''}`;
340 if (!/^\s*\w+\s*:\s*\{/.test(rest)) {
341 end = j;
342 break;
343 }
344 }
345 }
346 }
347 if (end < 0) break;
348 spans.push([i + 1, end + 1]);
349 i = end;
350 }
351 return spans;
352}
353
354/**
355 * The suites that exercise the most of the project, widest first.

Callers 2

withoutPreviewsFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected