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

Function localTypeText

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

* The declared type, as written, of a parameter or a local the calling * routine declares above a reference, the nearest one (`Writer: TWriter;`, * `A, Writer: TWriter`, `var Writer := TWriter.Create;`); not one a routine * nested in it declares for itself. Undefined when it declares none.

(lower: string, ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1708 * nested in it declares for itself. Undefined when it declares none.
1709 */
1710function localTypeText(lower: string, ref: UnresolvedRef, context: ResolutionContext): string | undefined {
1711 const lines = fileLines(ref.filePath!, context);
1712 const from = routineHeaderAt(ref.filePath!, ref.line, context);
1713 const name = escapeRegExp(lower);
1714 const mentions = new RegExp(`\\b${name}\\b`, 'i');
1715 const declares = new RegExp(`(?:^|[^.\\w])${name}(?:\\s*,\\s*&?[A-Za-z_]\\w*)*\\s*:(?!=)\\s*([^;=)]*)`, 'i');
1716 const created = new RegExp(`\\bvar\\s+${name}\\s*:=\\s*&?([A-Za-z_][\\w.]*)\\s*\\.\\s*create\\b`, 'i');
1717 const elsewhere = nestedRoutineSpans(ref.filePath!, context).filter(([start, end]) => ref.line < start || ref.line > end);
1718 let found: string | undefined;
1719 for (let i = Math.max(1, from); i <= ref.line && i <= lines.length; i++) {
1720 const raw = lines[i - 1]!;
1721 if (!mentions.test(raw) || elsewhere.some(([start, end]) => i >= start && i <= end)) continue;
1722 const text = raw.replace(/\/\/.*$|\{[^}]*\}|\(\*.*?\*\)|'(?:[^']|'')*'/g, ' ');
1723 const m = declares.exec(text) ?? created.exec(text);
1724 if (m && m[1]!.trim()) found = m[1]!.trim();
1725 }
1726 return found;
1727}
1728
1729/** The lines (first, last) of the routines a file nests in others. */
1730function nestedRoutineSpans(filePath: string, context: ResolutionContext): Array<[number, number]> {

Callers 1

typeOfLinksFunction · 0.85

Calls 5

fileLinesFunction · 0.85
routineHeaderAtFunction · 0.85
nestedRoutineSpansFunction · 0.85
escapeRegExpFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected