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

Function withStatementsAt

src/resolution/pascal-scope.ts:1184–1205  ·  view source on GitHub ↗

The `with` statements whose bodies hold a reference, the innermost first.

(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1182
1183/** The `with` statements whose bodies hold a reference, the innermost first. */
1184function withStatementsAt(ref: UnresolvedRef, context: ResolutionContext): WithStatement[] {
1185 const { statements, lineStarts } = withOutlineOf(ref.filePath!, context);
1186 if (statements.length === 0) return [];
1187 const at = (lineStarts[ref.line - 1] ?? Infinity) + (ref.column ?? 0);
1188 // The last statement whose body starts at or before the reference; the
1189 // statements holding the reference are it or the ones around it.
1190 let lo = 0;
1191 let hi = statements.length - 1;
1192 let k = -1;
1193 while (lo <= hi) {
1194 const mid = (lo + hi) >> 1;
1195 if (statements[mid]!.start <= at) {
1196 k = mid;
1197 lo = mid + 1;
1198 } else {
1199 hi = mid - 1;
1200 }
1201 }
1202 const holding: WithStatement[] = [];
1203 for (; k >= 0; k = statements[k]!.parent) if (statements[k]!.end > at) holding.push(statements[k]!);
1204 return holding;
1205}
1206
1207/** A file's `with` statements (see scanWithStatements), and where each of its lines starts in its text. */
1208function withOutlineOf(filePath: string, context: ResolutionContext): { statements: WithStatement[]; lineStarts: number[] } {

Callers 2

withSubjectMemberFunction · 0.85
matchPascalHelperCallFunction · 0.85

Calls 2

withOutlineOfFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected