* The ±SOURCE_WINDOW lines a card shows. * * Anchored on the line that makes the next call. The last card has no next * call, so it anchors on the definition instead — a reader who followed seven * hops to get there wants to see what they arrived at.
( cg: CodeGraph, projectRoot: string, cache: Map<string, FileCache>, node: Node, anchor: number )
| 406 | * hops to get there wants to see what they arrived at. |
| 407 | */ |
| 408 | async function windowFor( |
| 409 | cg: CodeGraph, |
| 410 | projectRoot: string, |
| 411 | cache: Map<string, FileCache>, |
| 412 | node: Node, |
| 413 | anchor: number |
| 414 | ): Promise<WireFlowSource | null> { |
| 415 | const file = loadFile(cg, projectRoot, cache, node.filePath); |
| 416 | if (!file) return null; |
| 417 | const posix = toRequestPath(node.filePath); |
| 418 | if (file.lines === null) { |
| 419 | return { |
| 420 | file: posix, |
| 421 | language: file.language, |
| 422 | from: anchor, |
| 423 | to: anchor, |
| 424 | drift: file.drift, |
| 425 | ...(file.reason ? { reason: file.reason } : {}), |
| 426 | }; |
| 427 | } |
| 428 | |
| 429 | const total = file.lines.length; |
| 430 | const from = Math.max(1, Math.min(anchor - SOURCE_WINDOW, total)); |
| 431 | const to = Math.max(from, Math.min(anchor + SOURCE_WINDOW, total)); |
| 432 | // Tokenise with the lead-in, then keep only the window — see HIGHLIGHT_LEAD_MAX. |
| 433 | const leadFrom = Math.max(1, Math.min(from, Math.max(node.startLine, from - HIGHLIGHT_LEAD_MAX))); |
| 434 | const highlighted = await highlightLines(file.lines.slice(leadFrom - 1, to), { |
| 435 | language: file.language, |
| 436 | cacheKey: `${posix}:${leadFrom}:${to}`, |
| 437 | }); |
| 438 | return { |
| 439 | file: posix, |
| 440 | language: file.language, |
| 441 | from, |
| 442 | to, |
| 443 | lines: file.lines.slice(from - 1, to), |
| 444 | highlight: { |
| 445 | ...highlighted, |
| 446 | lines: highlighted.lines.slice(from - leadFrom), |
| 447 | }, |
| 448 | drift: false, |
| 449 | }; |
| 450 | } |
| 451 | |
| 452 | /** The branch label for `edge`'s call site in `siteNode`'s file, or ''. */ |
| 453 | async function whenAt( |
no test coverage detected