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

Function sfcElementLineRanges

src/extraction/sfc-script.ts:418–433  ·  view source on GitHub ↗
(source: string, elements: SfcMarkupElement[])

Source from the content-addressed store, hash-verified

416 * {@link sfcMarkupElements} found.
417 */
418export function sfcElementLineRanges(source: string, elements: SfcMarkupElement[]): Array<[number, number]> {
419 const ranges: Array<[number, number]> = [];
420 let line = 0;
421 let counted = 0;
422 const lineAt = (offset: number): number => {
423 for (let at = source.indexOf('\n', counted); at >= 0 && at < offset; at = source.indexOf('\n', at + 1)) line++;
424 counted = offset;
425 return line;
426 };
427 for (const element of elements) {
428 if (element.content === undefined) continue;
429 const start = lineAt(element.index);
430 ranges.push([start, lineAt(element.end)]);
431 }
432 return ranges;
433}
434
435/** The SFC's own file node — the whole file, as the tree-sitter extractor makes one. */
436export function sfcFileNode(filePath: string, source: string, language: Language): Node {

Callers 3

getCoveredRangesMethod · 0.90
extractTemplateCallsMethod · 0.90

Calls 2

pushMethod · 0.80
lineAtFunction · 0.70

Tested by

no test coverage detected