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

Function resolveAnchor

src/ui-server/api/steps.ts:1599–1616  ·  view source on GitHub ↗

* The anchor: `anchor= `, or `symbol= ` resolved to the most * screen-like symbol of that name — a route first, then a component or * function, then a method — with the rest reported as `ambiguous`.

(cg: CodeGraph, query: URLSearchParams)

Source from the content-addressed store, hash-verified

1597 * function, then a method — with the rest reported as `ambiguous`.
1598 */
1599function resolveAnchor(cg: CodeGraph, query: URLSearchParams): { anchor: Node; ambiguous: WireNodeRef[] } {
1600 const id = query.get('anchor');
1601 if (id !== null && id.trim() !== '') {
1602 const node = cg.getNode(id);
1603 if (!node) throw notFound(`No symbol with id "${id}" in this index.`, 'It may have moved in a re-index; open it from search or the Screens view.');
1604 return { anchor: node, ambiguous: [] };
1605 }
1606 const name = query.get('symbol');
1607 if (name === null || name.trim() === '') throw badRequest('Give the picture an anchor: ?anchor=<node id> or ?symbol=<name>.');
1608 const rank: Record<string, number> = { route: 0, component: 1, function: 2, method: 3, class: 4, constant: 5, variable: 6 };
1609 const matches = cg
1610 .getNodesByName(name.trim())
1611 .filter((n) => n.kind !== 'file' && n.kind !== 'import' && n.kind !== 'export')
1612 .sort((a, b) => (rank[a.kind] ?? 9) - (rank[b.kind] ?? 9) || a.filePath.localeCompare(b.filePath) || a.startLine - b.startLine);
1613 const anchor = matches[0];
1614 if (!anchor) throw notFound(`Nothing in this index is named "${name}".`, 'Try the search box; names are matched exactly.');
1615 return { anchor, ambiguous: matches.slice(1, 9).map(toNodeRef) };
1616}
1617
1618/** How many distinct parents render this node as a JSX child. Memoised per request. */
1619function renderParents(cg: CodeGraph, node: Node, memo: Map<string, number>): number {

Callers 1

buildStepsFunction · 0.85

Calls 6

notFoundFunction · 0.90
badRequestFunction · 0.90
getNodeMethod · 0.80
mapMethod · 0.80
getMethod · 0.65
getNodesByNameMethod · 0.65

Tested by

no test coverage detected