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

Method pascalScopeAt

src/extraction/tree-sitter.ts:10049–10071  ·  view source on GitHub ↗

* The class and routine a name at `line` belongs to; null outside any code. * Where the tree has errors, a routine whose header didn't parse is a block * outside any routine, or part of the routine above it, so the source text * says: a header between the tree's routine and the name is the

(line: number)

Source from the content-addressed store, hash-verified

10047 * with the declarations the text gives it.
10048 */
10049 private pascalScopeAt(line: number): { classQn: string | null; routine: string | null; locals: Map<string, string | null> | null } | null {
10050 const scope = this.pascalScopes[this.pascalScopes.length - 1];
10051 if (!scope) return null;
10052 const own = { classQn: scope.classQn, routine: scope.routine, locals: null };
10053 if (!this.tree?.rootNode.hasError) return own;
10054 const routines = (this.pascalTextRoutines ??= this.readPascalTextRoutines());
10055 let lo = 0;
10056 let hi = routines.length - 1;
10057 let hit = -1;
10058 while (lo <= hi) {
10059 const mid = (lo + hi) >> 1;
10060 if (routines[mid]!.line <= line) {
10061 hit = mid;
10062 lo = mid + 1;
10063 } else {
10064 hi = mid - 1;
10065 }
10066 }
10067 const text = hit >= 0 ? routines[hit]! : null;
10068 // Inside a routine the tree parsed, only a later header overrides it.
10069 if (!text || text.line <= scope.startLine || (scope.startLine > 0 && text.routine === null)) return own;
10070 return text;
10071 }
10072
10073 /**
10074 * Each routine header of the source text (`procedure TFoo.Bar(…)`), with

Callers 3

pushPascalChainCallMethod · 0.95
learnPascalVariableMethod · 0.95

Calls 1

Tested by

no test coverage detected