* The class the nearest routine header at or above a line names * (`procedure TFoo.Bar;` → `TFoo`), or null when it is a free routine's, or * the unit's code resumes there: after an `end;` that starts its line, or at * `initialization`.
(filePath: string, line: number, context: ResolutionContext)
| 789 | * `initialization`. |
| 790 | */ |
| 791 | function headerClassAt(filePath: string, line: number, context: ResolutionContext): string | null { |
| 792 | const memo = memos(context).headerClasses; |
| 793 | let headers = memo.get(filePath); |
| 794 | if (!headers) { |
| 795 | headers = []; |
| 796 | const lines = fileLines(filePath, context); |
| 797 | const header = /^(?:class\s+)?(?:procedure|function|constructor|destructor|operator)\s+([A-Za-z_][\w.<>, ]*?)\s*[(:;]/i; |
| 798 | for (let i = 0; i < lines.length; i++) { |
| 799 | const text = lines[i]!; |
| 800 | // Each starts its line with one of c, d, e, f, i, o, p (either case). |
| 801 | const first = text.charCodeAt(0) | 0x20; |
| 802 | if (first !== 0x63 && first !== 0x64 && first !== 0x65 && first !== 0x66 && first !== 0x69 && first !== 0x6f && first !== 0x70) continue; |
| 803 | if (/^(?:end;|(?:initialization|finalization)\b)/i.test(text)) { |
| 804 | headers.push({ line: i + 1, classQn: null, routine: false, qn: null }); |
| 805 | continue; |
| 806 | } |
| 807 | const m = header.exec(text); |
| 808 | if (!m) continue; |
| 809 | const parts = m[1]!.replace(/<[^>]*>/g, '').replace(/\s+/g, '').split('.'); |
| 810 | headers.push({ line: i + 1, classQn: parts.length > 1 ? parts.slice(0, -1).join('::') : null, routine: true, qn: parts.join('::') }); |
| 811 | } |
| 812 | memo.set(filePath, headers); |
| 813 | } |
| 814 | return headerAt(headers, line)?.classQn ?? null; |
| 815 | } |
| 816 | |
| 817 | /** The qualified name of the routine the nearest routine header at or above a line names (`TFoo::Bar`), or null as for headerClassAt. */ |
| 818 | function headerRoutineAt(filePath: string, line: number, context: ResolutionContext): string | null { |
no test coverage detected