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

Function declarationInScope

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

* The first declaration a bare name reaches from a routine of class `cls` * (null: a free routine), whatever it declares: a routine nested in the * calling routine or one around it, a member of the class or its ancestors, * then a declaration of the unit, then of the units it uses, last first. *

(lower: string, cls: Node | null, ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

486 * names.
487 */
488function declarationInScope(lower: string, cls: Node | null, ref: UnresolvedRef, context: ResolutionContext): Found | null {
489 const nested = nestedRoutineInScope(lower, ref, context);
490 if (nested) return nested;
491 const memo = memos(context).inScope;
492 const key = `${cls?.id ?? ''}|${ref.filePath}|${lower}`;
493 if (memo.has(key)) return memo.get(key)!;
494 let found: Found | null = null;
495 const member = cls ? memberInHierarchy(cls, lower, context) : null;
496 if (member) {
497 found = { node: member, resolvedBy: 'instance-method', confidence: 0.9 };
498 } else {
499 const own = ownUnitDeclaration(ref.filePath!, lower, context);
500 if (own) {
501 found = { node: own, resolvedBy: 'exact-match', confidence: 0.9 };
502 } else {
503 const used = usedUnitFiles(ref.filePath!, context);
504 for (let i = used.length - 1; i >= 0 && !found; i--) {
505 const decl = unitDeclaration(used[i]!, lower, context, ref.filePath!);
506 if (decl) found = { node: decl, resolvedBy: 'import', confidence: 0.85 };
507 }
508 }
509 }
510 memo.set(key, found);
511 return found;
512}
513
514/**
515 * A dotted name: the method its receiver's declared type has; with

Callers 6

matchPascalSystemCallFunction · 0.85
gatePascalDataCallFunction · 0.85
nameInScopeFunction · 0.85
matchPascalNestedCallFunction · 0.85
gatePascalNestedTargetFunction · 0.85
assignedRoutineTypeFunction · 0.85

Calls 9

nestedRoutineInScopeFunction · 0.85
memosFunction · 0.85
memberInHierarchyFunction · 0.85
ownUnitDeclarationFunction · 0.85
usedUnitFilesFunction · 0.85
unitDeclarationFunction · 0.85
hasMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected