* Shortlist candidate runtime targets for a dispatch key surfaced by * buildDynamicBoundaries. Exact conventional names first (`save` → * `onSave`/`handleSave`; `CreateCmd` → `CreateCmdHandler`), then FTS, with a * normalized-containment post-filter (FTS camel-splitting is fuzzier t
(cg: CodeGraph, key: string, keyIsType: boolean, named: Map<string, Node>, selfId: string)
| 2257 | * are marked — that's the "you were right, here's the wiring" case. |
| 2258 | */ |
| 2259 | private boundaryCandidates(cg: CodeGraph, key: string, keyIsType: boolean, named: Map<string, Node>, selfId: string): string { |
| 2260 | const CALLABLE = new Set(['method', 'function', 'component', 'constructor', 'class']); |
| 2261 | const norm = (s: string) => s.toLowerCase().replace(/[^a-z0-9]/g, ''); |
| 2262 | const keyNorm = norm(key); |
| 2263 | if (keyNorm.length < 3) return ''; |
| 2264 | const cands = new Map<string, Node>(); |
| 2265 | const consider = (n: Node | undefined | null) => { |
| 2266 | if (!n || n.id === selfId || !CALLABLE.has(n.kind) || cands.has(n.id)) return; |
| 2267 | const nameNorm = norm(n.name || ''); |
| 2268 | if (nameNorm.length < 3) return; |
| 2269 | if (!nameNorm.includes(keyNorm) && !keyNorm.includes(nameNorm)) return; |
| 2270 | cands.set(n.id, n); |
| 2271 | }; |
| 2272 | const cap = key.charAt(0).toUpperCase() + key.slice(1); |
| 2273 | const probes = keyIsType |
| 2274 | ? [`${key}Handler`, key] |
| 2275 | : [key, `on${cap}`, `handle${cap}`, `${key}Handler`, `handle_${key}`]; |
| 2276 | for (const p of probes) { |
| 2277 | try { for (const n of cg.getNodesByName(p)) consider(n); } catch { /* exact probe miss is fine */ } |
| 2278 | } |
| 2279 | let raw = 0; |
| 2280 | try { |
| 2281 | const results = cg.searchNodes(key, { limit: 12 }); |
| 2282 | raw = results.length; |
| 2283 | for (const r of results) consider(r.node); |
| 2284 | } catch { /* FTS syntax edge — exact probes already ran */ } |
| 2285 | if (cands.size === 0) { |
| 2286 | return raw >= 12 && key.length < 5 ? `key \`${key}\` is too generic to shortlist (${raw}+ matches)` : ''; |
| 2287 | } |
| 2288 | // A constructor candidate duplicates its class: extractors emit ctors as |
| 2289 | // METHOD nodes named like the class (C#/Java `Foo::Foo`) — keep the class. |
| 2290 | const all = [...cands.values()]; |
| 2291 | const classKey = new Set(all.filter((n) => n.kind === 'class').map((n) => `${n.name}|${n.filePath}`)); |
| 2292 | const namedNames = new Set([...named.values()].map((n) => n.name)); |
| 2293 | const isNamed = (n: Node) => named.has(n.id) || namedNames.has(n.name); // the flow's named set holds callables only — transfer the mark to the class |
| 2294 | const list = all |
| 2295 | .filter((n) => !(n.kind !== 'class' && classKey.has(`${n.name}|${n.filePath}`))) |
| 2296 | .sort((a, b) => (isNamed(b) ? 1 : 0) - (isNamed(a) ? 1 : 0)) |
| 2297 | .slice(0, 4) |
| 2298 | .map((n) => { |
| 2299 | // Typed-bus convention: the runtime target is the candidate class's |
| 2300 | // Handle/Execute/Consume method — name the exact node, not just the class. |
| 2301 | let display = n.qualifiedName || n.name; |
| 2302 | let at = `${n.filePath}:${n.startLine}`; |
| 2303 | if (keyIsType && n.kind === 'class') { |
| 2304 | try { |
| 2305 | const HANDLER_METHODS = /^(handle|handleAsync|execute|executeAsync|consume|consumeAsync|run|__invoke)$/i; |
| 2306 | const method = cg.getOutgoingEdges(n.id) |
| 2307 | .filter((e) => e.kind === 'contains') |
| 2308 | .map((e) => { try { return cg.getNode(e.target); } catch { return null; } }) |
| 2309 | .find((c): c is Node => !!c && c.kind === 'method' && HANDLER_METHODS.test(c.name)); |
| 2310 | if (method) { display = `${n.name}.${method.name}`; at = `${method.filePath}:${method.startLine}`; } |
| 2311 | } catch { /* class without resolvable members — show the class itself */ } |
| 2312 | } |
| 2313 | return `\`${display}\` (${at})${isNamed(n) ? ' ← you named this' : ''}`; |
| 2314 | }); |
| 2315 | return `candidates for key \`${key}\`: ${list.join(', ')}`; |
| 2316 | } |
no test coverage detected