Skip to content

nes: dedupe NextEditProvider streamed-edit handling into shared helper - #324451

Merged
Ulugbek Abdullaev (ulugbekna) merged 5 commits into
mainfrom
agents/simplify-nexteditprovider-class
Jul 6, 2026
Merged

nes: dedupe NextEditProvider streamed-edit handling into shared helper#324451
Ulugbek Abdullaev (ulugbekna) merged 5 commits into
mainfrom
agents/simplify-nexteditprovider-class

Conversation

@ulugbekna

Copy link
Copy Markdown
Contributor
  • nes: dedupe NextEditProvider streamed-edit handling into shared helper
  • nes: rename _cacheStreamedEdit to _rebaseAndCacheStreamedEdit
  • nes: pass _rebaseAndCacheStreamedEdit args as an options object
  • nes: let _rebaseAndCacheStreamedEdit own docContents advancement

Copilot AI review requested due to automatic review settings July 6, 2026 08:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Copilot NES (Next Edit Suggestions) inline-edits pipeline by deduplicating the streamed-edit processing logic used by both the regular and speculative NextEditProvider flows into a shared helper, while also clarifying the helper’s responsibilities and call signature.

Changes:

  • Introduces a shared _rebaseAndCacheStreamedEdit helper to handle rebasing, caching, cross-file association, and per-doc content advancement for a single streamed edit.
  • Replaces duplicated streamed-edit loop logic in both the regular request path and the speculative request path with calls into the shared helper.
  • Introduces small supporting types (DocState, RebaseAndCacheStreamedEditArgs) to make the shared logic’s contract explicit.
Show a summary per file
File Description
extensions/copilot/src/extension/inlineEdits/node/nextEditProvider.ts Deduplicates regular/speculative streamed-edit handling into _rebaseAndCacheStreamedEdit, updates logging/caching flow, and adds supporting types for clearer state management.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Low

Extract the per-edit rebase+cache logic shared by the regular fetch path
(`_executeNewNextEditRequest`) and the speculative path
(`_runSpeculativeProviderCall`) into a single `_cacheStreamedEdit` method.
Both loops previously open-coded the same convert -> rebase -> compose ->
setKthNextEdit -> cross-file cache pipeline, which had started to drift.

Also:
- extract the inline doc-state type into a named `DocState` interface and
  mark the non-reassigned fields `readonly`
- reuse the existing exported `StreamedEdit` type instead of a local
  duplicate

Behavior-preserving: the only differences are trace-level log messages.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The method does more than cache: it also rebases the streamed edit onto the
edits applied so far and mutates the per-doc accumulators. The new name
reflects that wider responsibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the nine positional parameters with a single typed
RebaseAndCacheStreamedEditArgs object and group the active-document fields
(id, contents, cursorOffset) under `activeDoc`. This removes the
call-site ambiguity of several same-typed/optional positional arguments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Previously the helper mutated editsSoFar/nextEdits/patchIndices and the
cache, but left advancing the target document's running `docContents` to
each caller (a foot-gun: a future caller could forget it, desyncing the
cache key from subsequent edits).

The helper now owns the full per-edit state transition: it snapshots the
pre-edit contents, populates the cache against that snapshot, then advances
`docContents`. The snapshot is returned as `docContentsBeforeEdit` so the
regular path can still log the first edit against the pre-edit contents.
`targetDocState` is no longer returned, so callers can't mutate it.

Behavior-preserving.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…dEdit

StreamedEdit.targetDocument is a required DocumentId, so the
`?? activeDoc.id` fallback was dead code that could mislead readers into
thinking targetDocument may be omitted. Addresses PR review feedback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants