The text of a call before its arguments, normalised to a member chain.
(call: SyntaxNode, container: SyntaxNode)
| 589 | |
| 590 | /** The text of a call before its arguments, normalised to a member chain. */ |
| 591 | function 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. */ |
| 616 | export async function callSitesForFile( |
no test coverage detected