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

Function nestedRoutineInScope

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

* The routine nested in the calling routine, or in one around it, that a * bare name there names (`procedure Inner;` between `procedure TFoo.Bar;` * and its `begin`, `TFoo::Bar::Inner`): the innermost one declared above the * call, the calling routine itself among them, or declared `forward` abov

(lower: string, ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

355 * unit. Null when none is.
356 */
357function nestedRoutineInScope(lower: string, ref: UnresolvedRef, context: ResolutionContext): Found | null {
358 // Most names no nested routine has: settled before any other lookup.
359 const named = pascalNamed(lower, context);
360 if (!named.some((n) => n.kind === 'function' && n.qualifiedName.includes('::'))) return null;
361 const memo = memos(context).nestedInScope;
362 const key = `${ref.fromNodeId}|${lower}`;
363 if (memo.has(key)) return memo.get(key)!;
364 let found: Found | null = null;
365 const caller = routineNode(ref.fromNodeId, context);
366 if (caller && caller.language === 'pascal') {
367 const chain = caller.qualifiedName.toLowerCase();
368 let best: Node | null = null;
369 let depth = -1;
370 for (const n of named) {
371 if (n.filePath !== caller.filePath || !isNestedRoutine(n, context)) continue;
372 if (n.startLine > ref.line && !declaredForward(n, ref.line, context)) continue;
373 const outer = ownerOf(n);
374 // Nested in the caller, or in a routine the caller is nested in.
375 if (chain !== outer && !chain.startsWith(`${outer}::`)) continue;
376 if (outer.length > depth || (outer.length === depth && n.startLine < best!.startLine)) {
377 best = n;
378 depth = outer.length;
379 }
380 }
381 if (best) found = { node: best, resolvedBy: 'exact-match', confidence: 0.95 };
382 }
383 memo.set(key, found);
384 return found;
385}
386
387/**
388 * Whether a routine nested in another is declared `forward` above a line

Callers 2

matchPascalNestedCallFunction · 0.85
declarationInScopeFunction · 0.85

Calls 9

pascalNamedFunction · 0.85
memosFunction · 0.85
routineNodeFunction · 0.85
isNestedRoutineFunction · 0.85
declaredForwardFunction · 0.85
hasMethod · 0.80
ownerOfFunction · 0.70
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected