NextEditProvider in Continue: How AI Suggests Your Next Code Edit
The NextEditProvider is a core feature in the Continue extension that uses an LLM to predict and suggest the next code edit after your current change, working alongside tab-autocomplete to create a "write-then-refine" workflow.
Built into the continuedev/continue repository, the NextEditProvider transforms a simple file edit into an intelligent suggestion pipeline. It captures the context of your recent changes, sends them to a configured language model, and presents the predicted next edit directly in VS Code. This enables developers to maintain flow state by accepting AI-driven refinements with a single keystroke.
How NextEditProvider Works: The 5-Step Workflow
The provider operates through a structured pipeline that bridges user actions and model inference. Each step is traceable through specific source files in the codebase.
1. Context Collection
When you edit a file, the NextEditProvider immediately gathers contextual data to inform the model. According to the type definitions in core/nextEdit/types.ts, the system captures:
- File location:
fileUriandworkspaceDirUrito establish project context - Edit history:
userEditscontaining the diff of recent changes - Code excerpts:
userExcerptsshowing surrounding code for context - Editable region:
originalEditableRangedefining the scope of modification
This data is packaged into a NextEditOutcome object that travels through the entire pipeline.
2. Prompt Construction
The provider uses template-based prompting defined in core/nextEdit/constants.ts. Depending on the configured model, it selects templates like Mercury or Instinct to format the context. The prompt includes the current code state, the diff of your recent edits, and metadata required by the specific model provider.
3. LLM Request
The constructed prompt is sent to your configured model provider via the generic LLM client. In core/core.ts, the NextEdit logic is invoked immediately after a normal autocomplete request finishes. The request includes extra fields defined in NextEditOutcome such as modelName and completionId, allowing full traceability of the inference call.
4. Suggestion Processing
When the model returns a completion, the provider interprets it as the next edit. The system enriches the raw completion with:
- Timing data:
elapsedfield tracking inference duration - Cursor positioning:
finalCursorPositionfor accurate insertion - Diff analysis:
diffLines,editableRegionStartLine, andeditableRegionEndLinemapping the suggestion to specific line numbers
This creates a complete NextEditOutcome object ready for UI presentation.
5. UI Presentation and Feedback
The VS Code interface handles the final delivery. The NextEditWindowManager.ts in the extensions layer creates a floating suggestion window, while statusBar.ts displays a "Next Edit is enabled" indicator in the status bar. Users can accept the suggestion with Tab (which inserts text and moves the cursor) or reject it with Esc. These actions are logged back to the provider through accepted or aborted status updates, enabling the model to learn from your preferences.
Key Source Files and Architecture
Understanding the NextEditProvider requires familiarity with these specific files in the continuedev/continue repository:
core/nextEdit/types.ts: Defines the data model includingNextEditOutcome,Prompt, and related interfaces used throughout the feature lifecycle.core/nextEdit/constants.ts: Holds model-specific token identifiers and default prompt templates for Mercury and Instinct models.core/core.ts: Serves as the integration point where NextEdit logic is triggered after autocomplete requests complete.extensions/vscode/src/commands.ts: Registers VS Code commands including "Continue: Force Next Edit" and validates that the model supports NextEdit before execution.extensions/vscode/src/autocomplete/statusBar.ts: Manages the status bar indicator and toggle functionality for enabling or disabling the feature.extensions/vscode/src/activation/NextEditWindowManager.ts: Controls the floating suggestion widget and routes Tab/Esc keybindings to the provider's accept and abort methods.
Working with NextEditProvider Programmatically
You can interact with the NextEditProvider directly through the VS Code extension API or internal core methods.
Trigger a NextEdit Suggestion
Force the provider to generate a suggestion for the active editor using the registered command:
// From extensions/vscode/src/commands.ts
registerCommand("Continue: Force Next Edit", async () => {
await nextEditProvider.forceNextEdit(); // Forces immediate suggestion generation
});
Accept a Suggestion
When a suggestion appears, accept it programmatically to insert the text and log the outcome:
// From extensions/vscode/src/activation/NextEditWindowManager.ts
const accept = async () => {
await nextEditProvider.acceptSuggestion(); // Inserts completion and records acceptance
};
Reject a Suggestion
Abort the current suggestion and record the rejection:
// Capture Esc key to abort
const reject = async () => {
await nextEditProvider.abortSuggestion(); // Removes widget and logs abort event
};
Inspect the Outcome Object
For debugging or custom analytics, examine the complete NextEditOutcome structure:
import { NextEditOutcome } from "core/nextEdit/types";
function logOutcome(outcome: NextEditOutcome) {
console.log({
model: `${outcome.modelProvider}/${outcome.modelName}`,
accepted: outcome.accepted,
elapsedMs: outcome.elapsed,
cursor: outcome.finalCursorPosition,
diff: outcome.diffLines.map(l => `${l.type} ${l.content}`).join("\n")
});
}
Summary
- The NextEditProvider predicts your next code edit using LLM inference triggered by file changes.
- It collects context from
core/nextEdit/types.tsfields includinguserEdits,fileUri, andoriginalEditableRange. - Prompts are built using templates from
core/nextEdit/constants.tsand executed throughcore/core.ts. - The VS Code integration layers handle UI rendering in
NextEditWindowManager.tsand command registration incommands.ts. - Users accept suggestions with Tab or reject with Esc, with outcomes logged via
acceptedandabortedflags.
Frequently Asked Questions
What is the difference between NextEditProvider and regular autocomplete?
Regular autocomplete suggests code completions based on cursor position and context, typically filling in the current line or block. NextEditProvider specifically analyzes the diff of your recent edits and predicts the next logical change you should make, creating a sequential editing workflow rather than just completion. While autocomplete runs continuously, NextEdit activates after you make a change and suggests the subsequent modification.
How do I enable or disable NextEditProvider in VS Code?
The feature can be toggled through the status bar indicator managed in extensions/vscode/src/autocomplete/statusBar.ts. The code checks that tab-autocomplete is enabled before activating NextEdit, and displays a warning if your configured model does not support the feature. You can also force a NextEdit session using the "Continue: Force Next Edit" command registered in extensions/vscode/src/commands.ts.
Which models support NextEditProvider?
Support depends on the model's ability to process diff-based prompts and return structured completions. The core/nextEdit/constants.ts file defines model-specific constants and templates for supported models like Mercury and Instinct. If your model lacks support, the system will show a warning when you attempt to enable the feature, as implemented in the command validation logic in commands.ts.
How does NextEditProvider learn from my feedback?
Every accept or reject action is logged back to the provider through the NextEditOutcome object. The accepted boolean field tracks whether you pressed Tab to insert the suggestion, while the aborted field records Esc rejections. This feedback loop, implemented in NextEditWindowManager.ts, allows the system to track suggestion quality and can be used to fine-tune model performance or prompt templates over time.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →