| 7378 | * is not being sent — spending the file's budget on nothing. |
| 7379 | */ |
| 7380 | const renderCluster = ( |
| 7381 | c: ExploreCluster, |
| 7382 | cap: number, |
| 7383 | /** |
| 7384 | * Hard bound on the rendered result (CG-30). `cap` is what selection asks |
| 7385 | * for; this is how far a single oversize member is allowed to overshoot it |
| 7386 | * before being windowed. Always >= `cap`, so a cluster that already fits is |
| 7387 | * never touched. |
| 7388 | */ |
| 7389 | ceiling: number = Infinity, |
| 7390 | /** |
| 7391 | * What this cluster's INCIDENTAL members may render into, when a cluster |
| 7392 | * ranked below it holds a member the query asked for — see the selection |
| 7393 | * loop. |
| 7394 | */ |
| 7395 | incidentalCap?: number, |
| 7396 | ): { parts: SectionPart[]; covered: ExploreLineRange[]; shrunk: boolean } => { |
| 7397 | const base = dedupeSpans(buildSection(c)); |
| 7398 | // In a cluster holding a member the query asked for, incidental members |
| 7399 | // are never kept past `ceiling` either. The member shrink estimates on raw |
| 7400 | // source, which runs well under the rendered size, so it kept helpers the |
| 7401 | // render then had no room for, and the window back to the ceiling cut in |
| 7402 | // source order — through the tail of a named body (gin's |
| 7403 | // `handleHTTPRequest` lost 10 of 71 lines to the helpers above it), or, |
| 7404 | // when its minimum windows overran a later cluster's room, costing that |
| 7405 | // cluster its place. Every re-render into an exact room is the same case. |
| 7406 | const guard = Number.isFinite(ceiling) && c.members.some(isProtectedMember) |
| 7407 | ? Math.min(incidentalCap ?? Infinity, ceiling) |
| 7408 | : incidentalCap; |
| 7409 | // A windowed spine method elides source even when nothing else is cut, so |
| 7410 | // it counts as shrunk: reported unclipped, the one-file-head-plus-a-call- |
| 7411 | // site render hid in the diagnostic as a complete section. |
| 7412 | const windowed = windowsSpineIn(c.start, c.end); |
| 7413 | const bound = ( |
| 7414 | r: { parts: SectionPart[]; covered: ExploreLineRange[]; shrunk: boolean }, |
| 7415 | ) => { |
| 7416 | if (!Number.isFinite(ceiling) || sectionText(r.parts).length <= ceiling) return r; |
| 7417 | // Windows are subsets of spans dedupeSpans already cleared, so the record |
| 7418 | // still only ever claims source that was actually sent. |
| 7419 | // A body the window cuts says so where it is cut, with the query for |
| 7420 | // the rest (#2486): the agent otherwise learns of the cut only from a |
| 7421 | // footer whose advice — ask for the symbol by name — returns this same |
| 7422 | // window. |
| 7423 | const focus = focusLinesOf(c); |
| 7424 | const parts = noteCutBodies(windowToCeiling(r.parts, ceiling, focus), r.parts, c, focus); |
| 7425 | return { parts, covered: r.covered, shrunk: true }; |
| 7426 | }; |
| 7427 | if (sectionText(base.parts).length <= Math.min(cap, guard ?? Infinity)) { |
| 7428 | return { parts: base.parts, covered: base.covered, shrunk: windowed }; |
| 7429 | } |
| 7430 | const shrunk = shrinkCluster(c, cap, guard); |
| 7431 | if (shrunk === null) { |
| 7432 | return bound({ parts: base.parts, covered: base.covered, shrunk: windowed }); |
| 7433 | } |
| 7434 | const dd = dedupeSpans(shrunk); |
| 7435 | return bound({ parts: dd.parts, covered: dd.covered, shrunk: true }); |
| 7436 | }; |
| 7437 | |