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

Function makeLineAt

src/resolution/synth-utils.ts:19–36  ·  view source on GitHub ↗
(src: string, baseLine: number)

Source from the content-addressed store, hash-verified

17 * never produce a match — then answers each call with a binary search.
18 */
19export function makeLineAt(src: string, baseLine: number): (idx: number) => number {
20 let nl: number[] | null = null;
21 return (idx: number) => {
22 if (!nl) {
23 nl = [];
24 for (let i = src.indexOf('\n'); i !== -1; i = src.indexOf('\n', i + 1)) nl.push(i);
25 }
26 // Count newlines strictly before idx.
27 let lo = 0;
28 let hi = nl.length;
29 while (lo < hi) {
30 const mid = (lo + hi) >> 1;
31 if (nl[mid]! < idx) lo = mid + 1;
32 else hi = mid;
33 }
34 return baseLine + lo;
35 };
36}
37
38/** Innermost function/method node whose line range contains `line`. */
39export function enclosingFn(nodesInFile: readonly Node[], line: number): Node | null {

Callers 15

statedDefaultExportFunction · 0.90
readFactsFunction · 0.90
collectTestRequestsFunction · 0.90
svelteKitLinkEdgesFunction · 0.90
lineOfFunction · 0.90
closureCollectionEdgesFunction · 0.90
rnEventEdgesFunction · 0.90
objectRegistryEdgesFunction · 0.90
readRustFileFunction · 0.90
scanFileFunction · 0.90
reactRouterLinkEdgesFunction · 0.90
tanstackLinkEdgesFunction · 0.90

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected