NES: donate leftover above-cursor budget to below-cursor in paged clipping#319998
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
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
useLeftoverBudgetFromAbovetoCurrentFileOptionsandRecentlyViewedDocumentsOptions, with validators and default values. - Extend
expandRangeToPageRangeto 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
sandy081
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Change
Add an opt-in
useLeftoverBudgetFromAboveflag that donates the unused upper half to the lower-half expansion.expandRangeToPageRangeis 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)useLeftoverBudgetFromAbovechat.advanced.inlineEdits.xtabProvider.recentlyViewedDocuments. other / recently-viewed files (clipAroundFocalRanges)useLeftoverBudgetFromAboveBoth default to
false, so existing behavior is unchanged until enabled.Notes
useLeftoverBudgetFromAbovefield added toCurrentFileOptionsandRecentlyViewedDocumentsOptions(with validators + defaults).prioritizeAboveCursorbranch already cascades leftover budget downward.Tests
promptCrafting.spec.tsfor donate-on vs donate-off behavior.vitest(xtab prompt + recentFiles specs): alltsgotypecheck:eslint: clean.clean pass