* 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)
| 995 | * names. |
| 996 | */ |
| 997 | function 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 |
no test coverage detected