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

Function keptByLine

src/resolution/synth-utils.ts:112–131  ·  view source on GitHub ↗
(
  kept: WeakMap<readonly Node[], Map<number, Node | null>>,
  nodesInFile: readonly Node[],
  line: number,
  find: () => Node | null,
)

Source from the content-addressed store, hash-verified

110const ENCLOSING_VALUE = new WeakMap<readonly Node[], Map<number, Node | null>>();
111
112function keptByLine(
113 kept: WeakMap<readonly Node[], Map<number, Node | null>>,
114 nodesInFile: readonly Node[],
115 line: number,
116 find: () => Node | null,
117): Node | null {
118 // A few nodes are gone through as quickly as an answer is looked up.
119 if (nodesInFile.length < KEEP_FROM_NODES) return find();
120 let byLine = kept.get(nodesInFile);
121 if (!byLine) {
122 byLine = new Map();
123 kept.set(nodesInFile, byLine);
124 }
125 let found = byLine.get(line);
126 if (found === undefined) {
127 found = find();
128 byLine.set(line, found);
129 }
130 return found;
131}
132
133/** Innermost function/method node whose line range contains `line`. */
134export function enclosingFn(nodesInFile: readonly Node[], line: number): Node | null {

Callers 2

enclosingFnFunction · 0.85
enclosingValueFunction · 0.85

Calls 3

findFunction · 0.70
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected