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

Function calleeChainText

src/graph/branch-guards.ts:591–613  ·  view source on GitHub ↗

The text of a call before its arguments, normalised to a member chain.

(call: SyntaxNode, container: SyntaxNode)

Source from the content-addressed store, hash-verified

589
590/** The text of a call before its arguments, normalised to a member chain. */
591function calleeChainText(call: SyntaxNode, container: SyntaxNode): string {
592 // Kotlin and Swift wrap the arguments in a `call_suffix`; the callee is
593 // everything before that suffix.
594 let end = container.startIndex;
595 const suffix = container.parent && container.parent.type === 'call_suffix' ? container.parent : null;
596 if (suffix) end = suffix.startIndex;
597 let text = collapse(call.text.slice(0, Math.max(0, end - call.startIndex)));
598 text = text.replace(/^(?:await|new|yield|return)\s+/, '').replace(/^(?:await|new)\s+/, '');
599 // Empty every nested argument list, innermost first: `a(b(c)).d` → `a().d`
600 // — keeping one short literal or name (`res.status(404).json`,
601 // `ResponseEntity.status(HttpStatus.NOT_FOUND).body`), which is the fact a
602 // reader of the chain wants.
603 for (let i = 0; i < 6 && /\([^()]*\)/.test(text); i++) {
604 text = text.replace(/\(([^()]*)\)/g, (_m, inner: string) => (/^\s*[\w.]{1,28}\s*$/.test(inner) ? `(${inner.trim()})` : '()'));
605 }
606 text = text
607 .replace(/\?\./g, '.')
608 .replace(/!\./g, '.')
609 .replace(/\s+/g, '')
610 .replace(/<[^<>]*>/g, '')
611 .replace(/\([^()]*\)$/, '');
612 return text.length > MAX_CALLEE_TEXT ? `${text.slice(0, MAX_CALLEE_TEXT - 1)}…` : text;
613}
614
615/** Both halves of every site, keyed by {@link siteKey}, from one cached tree. */
616export async function callSitesForFile(

Callers 3

enclosingCallTextFunction · 0.85
callAtFunction · 0.85
callSiteInTreeFunction · 0.85

Calls 1

collapseFunction · 0.70

Tested by

no test coverage detected