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

Function declarationInScope

src/resolution/pascal-scope.ts:997–1021  ·  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

995 * names.
996 */
997function declarationInScope(lower: string, cls: Node | null, ref: UnresolvedRef, context: ResolutionContext): Found | null {
998 const nested = nestedRoutineInScope(lower, ref, context);
999 if (nested) return nested;
1000 const memo = memos(context).inScope;
1001 const key = `${cls?.id ?? ''}|${ref.filePath}|${lower}`;
1002 if (memo.has(key)) return memo.get(key)!;
1003 let found: Found | null = null;
1004 const member = cls ? memberOfSelf(cls, lower, ref.filePath!, context) : null;
1005 if (member) {
1006 found = { node: member, resolvedBy: 'instance-method', confidence: 0.9 };
1007 } else {
1008 const own = ownUnitDeclaration(ref.filePath!, lower, context);
1009 if (own) {
1010 found = { node: own, resolvedBy: 'exact-match', confidence: 0.9 };
1011 } else {
1012 const used = usedUnitFiles(ref.filePath!, context);
1013 for (let i = used.length - 1; i >= 0 && !found; i--) {
1014 const decl = unitDeclaration(used[i]!, lower, context, ref.filePath!);
1015 if (decl) found = { node: decl, resolvedBy: 'import', confidence: 0.85 };
1016 }
1017 }
1018 }
1019 memo.set(key, found);
1020 return found;
1021}
1022
1023/**
1024 * A dotted name: the method its receiver's declared type has; with

Callers 7

matchPascalSystemCallFunction · 0.85
gatePascalCallFunction · 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
memberOfSelfFunction · 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