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

Function typesNamed

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

* The project's Pascal types a name names, generic ones by the name before * their parameters: `TSetParams ` for `TSetParams`.

(lower: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1190 * their parameters: `TSetParams<T: class>` for `TSetParams`.
1191 */
1192function typesNamed(lower: string, context: ResolutionContext): Node[] {
1193 const m = memos(context);
1194 if (!m.genericTypes) {
1195 const generic = new Map<string, Node[]>();
1196 const add = (n: Node): void => {
1197 const open = n.name.indexOf('<');
1198 if (n.language !== 'pascal' || open <= 0 || !(n.kind === 'type_alias' || CLASS_KINDS.has(n.kind))) return;
1199 const base = n.name.slice(0, open).trim().toLowerCase();
1200 const list = generic.get(base);
1201 if (list) list.push(n);
1202 else generic.set(base, [n]);
1203 };
1204 const kinds = ['type_alias', 'class', 'struct', 'interface'] as const;
1205 // The names alone first, where the index can tell them, to fetch only
1206 // the generic types.
1207 const names = context.getNodeNamesOfKinds?.('pascal', kinds);
1208 if (names) {
1209 for (const name of new Set(names)) if (name.includes('<')) context.getNodesByName(name).forEach(add);
1210 } else {
1211 for (const kind of kinds) for (const n of context.iterateNodesByKind?.(kind) ?? context.getNodesByKind(kind)) add(n);
1212 }
1213 m.genericTypes = generic;
1214 }
1215 return pascalNamed(lower, context).filter((t) => t.kind === 'type_alias' || CLASS_KINDS.has(t.kind))
1216 .concat(m.genericTypes.get(lower) ?? []);
1217}
1218
1219/**
1220 * What a type declaration says after its `=`, which may start on the next

Callers 1

routineTypeVerdictFunction · 0.85

Calls 9

memosFunction · 0.85
pascalNamedFunction · 0.85
hasMethod · 0.80
addFunction · 0.70
getNodeNamesOfKindsMethod · 0.65
getNodesByNameMethod · 0.65
iterateNodesByKindMethod · 0.65
getNodesByKindMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected