Skip to content

NES: donate leftover above-cursor budget to below-cursor in paged clipping#319998

Merged
ulugbekna merged 1 commit into
mainfrom
ulugbekna/xtab-current-file-leftover-budget
Jun 4, 2026
Merged

NES: donate leftover above-cursor budget to below-cursor in paged clipping#319998
ulugbekna merged 1 commit into
mainfrom
ulugbekna/xtab-current-file-leftover-budget

Conversation

@ulugbekna
Copy link
Copy Markdown
Contributor

Problem

Change

Add an opt-in useLeftoverBudgetFromAbove flag that donates the unused upper half to the lower-half expansion.

expandRangeToPageRange is shared by two call sites, so this is exposed as two independent team-internal (experiment-based) settings:

  • chat.advanced.inlineEdits.xtabProvider.currentFile. current file (clipPreservingRange)useLeftoverBudgetFromAbove
  • chat.advanced.inlineEdits.xtabProvider.recentlyViewedDocuments. other / recently-viewed files (clipAroundFocalRanges)useLeftoverBudgetFromAbove

Both default to false, so existing behavior is unchanged until enabled.

Notes

  • New useLeftoverBudgetFromAbove field added to CurrentFileOptions and RecentlyViewedDocumentsOptions (with validators + defaults).
  • Only affects the even-split branch; the prioritizeAboveCursor branch already cascades leftover budget downward.

Tests

  • Added unit coverage in promptCrafting.spec.ts for donate-on vs donate-off behavior.
  • vitest (xtab prompt + recentFiles specs): all tsgo typecheck: eslint: clean.clean pass

…pping

When clipping context with an even split between code above and below the
cursor (the `!prioritizeAboveCursor` path of `expandRangeToPageRange`), any
budget left unused by the above-cursor pass was discarded instead of being
given to the below-cursor pass.

Add an opt-in `useLeftoverBudgetFromAbove` flag that donates the unused upper
half to the lower half. Because `expandRangeToPageRange` is shared by both the
current file (`clipPreservingRange`) and other/recently-viewed files
(`clipAroundFocalRanges`), expose it as two independent team-internal settings:

- chat.advanced.inlineEdits.xtabProvider.currentFile.useLeftoverBudgetFromAbove
- chat.advanced.inlineEdits.xtabProvider.recentlyViewedDocuments.useLeftoverBudgetFromAbove

Both default to false, preserving existing behavior. Adds unit coverage for the
donate-on vs donate-off behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 4, 2026 20:15
@ulugbekna ulugbekna enabled auto-merge (squash) June 4, 2026 20:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in “budget donation” behavior for paged clipping in the Copilot inline-edits (xtab) prompt builder: when using the even-split expansion logic, any unused token budget from the “above” half can be reassigned to expand further “below” the cursor/focal range. This is wired through separate experiment-based team-internal settings for current-file vs recently-viewed document clipping, defaulting to false to preserve existing behavior.

Changes:

  • Introduce useLeftoverBudgetFromAbove to CurrentFileOptions and RecentlyViewedDocumentsOptions, with validators and default values.
  • Extend expandRangeToPageRange to optionally donate leftover above-budget to below-range expansion in the even-split branch.
  • Add unit tests covering donate-off vs donate-on behavior.
Show a summary per file
File Description
extensions/copilot/src/platform/inlineEdits/common/dataTypes/xtabPromptOptions.ts Adds new options field + validator entries + defaults for both current-file and recently-viewed clipping.
extensions/copilot/src/platform/configuration/common/configurationService.ts Registers two new experiment-based team-internal config keys for the new behavior.
extensions/copilot/src/extension/xtab/node/xtabProvider.ts Plumbs the two new config values into the resolved prompt options passed to prompt construction.
extensions/copilot/src/extension/xtab/common/promptCrafting.ts Implements the “donate leftover above budget to below” logic in expandRangeToPageRange and threads the option through current-file clipping.
extensions/copilot/src/extension/xtab/common/recentFilesForPrompt.ts Threads the option into focal-range-based clipping for recently-viewed documents.
extensions/copilot/src/extension/xtab/test/common/promptCrafting.spec.ts Adds test coverage validating default (no donation) and enabled (donation) outcomes.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 0

@ulugbekna ulugbekna merged commit 0cfba36 into main Jun 4, 2026
26 checks passed
@ulugbekna ulugbekna deleted the ulugbekna/xtab-current-file-leftover-budget branch June 4, 2026 20:35
@vs-code-engineering vs-code-engineering Bot added this to the 1.124.0 milestone Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants