* 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)
| 486 | * names. |
| 487 | */ |
| 488 | function 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 |
no test coverage detected