Inline Chat and AI Edits

Purpose and Scope

Inline chat is the editor-local Copilot surface for asking a question, generating code, or changing a focused region without moving the user into a separate conversation panel. The user experience described in the product documentation starts from an active file, often a selected block, and returns an inline diff that can be kept or undone. The source files on this page show how the Copilot extension narrows that experience into prompt construction, command routing, code actions, notebook cell affordances, and review entry points. Inline completions, ghost-text style suggestions, and next-edit capture serve the same broader goal of keeping assistance in the editor flow, while this implementation evidence is strongest for explicit inline chat requests and generated edits.

Sources: extensions/copilot/src/extension/inlineChat/node/codeContextRegion.ts, extensions/copilot/src/extension/prompts/node/inline/inlineChatEditCodePrompt.tsx, extensions/copilot/src/extension/prompts/node/inline/inlineChatGenerateCodePrompt.tsx

The important distinction for readers is scope. Inline chat is appropriate when the current editor context is enough to answer the request, especially when the user highlights the code to modify. Broader, multi-file, multi-step tasks belong in Chat view or the Agents window, where sessions retain longer conversation state and can coordinate edits across a project. The inline code here follows that product boundary: it summarizes a document region, guards against ignored files, refuses surfaces that need different handling, and interprets model output as edits or insertions tied to the active document.

Sources: extensions/copilot/src/extension/prompts/node/inline/inlineChatEditCodePrompt.tsx, extensions/copilot/src/extension/prompts/node/inline/inlineChatGenerateCodePrompt.tsx, extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCommands.ts

Relevant Source Files

  • extensions/copilot/src/extension/inlineChat/node/codeContextRegion.ts: Defines the line-budgeted code context region used to surround a selection with promptable source text, fenced language metadata, and file path markers.
  • extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts: Contributes Copilot quick fixes, explain actions, review actions, and image alt-text actions through VS Code code action APIs while respecting configuration and ignore rules.
  • extensions/copilot/src/extension/prompts/node/inline/inlineChatEditCodePrompt.tsx: Builds the prompt for editing existing code, including document summarization, selection splitting, custom instructions, language server context, and streaming edit interpretation.
  • extensions/copilot/src/extension/prompts/node/inline/inlineChatGenerateCodePrompt.tsx: Builds the prompt for generating new code at a selection boundary, using similar context services but interpreting the reply as insertion-oriented streaming output.
  • extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCommands.ts: Registers inline chat related commands, wires services, and connects explain, review, editor chat, code action, and notebook status bar pieces.
  • extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatNotebookActions.ts: Adds notebook cell status bar actions for generating code from markdown cells and fixing execution errors through editor chat commands.

System-to-Code Mapping

The smallest unit in the inline chat path is not the whole workspace; it is a bounded document context. CodeContextTracker records how many characters have already been included and rejects additional lines when the limit would be exceeded. CodeContextRegion then grows before or after a target range, tracks whether the collected text contains non-whitespace content, trims unnecessary blank lines, and emits a prompt fragment as a fenced code block with a language identifier and a file marker. This is the source-level mechanism that makes inline chat feel local: context is intentionally nearby, formatted for the model, and constrained before it reaches the prompt renderer.

Sources: extensions/copilot/src/extension/inlineChat/node/codeContextRegion.ts

The edit and generate prompt classes share a common shape but represent different user intentions. Both receive generic inline invocation properties, inspect the document context, consult the ignore service, obtain the prompt query, conversation history, and chat variables, and build summarized document data through the parser service. The edit prompt uses an adjusted selection split and a replacement streaming interpreter because the model response should transform existing code. The generate prompt uses an original-end split and an insertion streaming interpreter because the response should add code at the chosen location. This separation keeps insertion and replacement behavior explicit rather than relying on the model to infer how the editor should apply text.

Sources: extensions/copilot/src/extension/prompts/node/inline/inlineChatEditCodePrompt.tsx, extensions/copilot/src/extension/prompts/node/inline/inlineChatGenerateCodePrompt.tsx

User-facing capabilitySource-level componentPractical effect
Focused context around a selectionCodeContextTracker and CodeContextRegionLimits nearby source text and formats it for prompting
Edit selected or surrounding codeInlineChatEditCodePromptProduces replacement-oriented streaming edits
Generate code at an insertion pointInlineChatGenerateCodePromptProduces insertion-oriented streaming output
Quick fix, explain, and review entry pointsQuickFixesProviderAdds AI code actions when enabled and allowed
Notebook markdown-to-code and error fixingNotebookExectionStatusBarItemProviderAdds sparkle status bar actions for eligible cells
Command registration and service wiringregisterInlineChatCommandsConnects extension services to VS Code commands

Execution Flow

A typical editor inline chat request starts with the user opening inline chat from the active editor, entering a prompt, and optionally selecting code first. The command layer obtains extension services such as configuration, ignore handling, review, logging, telemetry, parser access, scope selection, and tabs/editors coordination. It can build special commands for explanation or review and route requests into the editor chat participant pipeline. Downstream, the prompt renderer chooses whether the request is an edit or generation scenario, summarizes the active document, includes applicable chat variables and instructions, and configures a reply interpreter that converts streamed model text into editor changes.

Sources: extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCommands.ts, extensions/copilot/src/extension/prompts/node/inline/inlineChatEditCodePrompt.tsx, extensions/copilot/src/extension/prompts/node/inline/inlineChatGenerateCodePrompt.tsx

The code action path is a parallel entry into the same kind of experience. QuickFixesProvider is a VS Code CodeActionProvider with Copilot-specific quick fix, explain, and review kinds. It first checks the Copilot code action configuration, then asks the ignore service whether the document is excluded, then exits early if cancellation has already been requested. It can contribute image alt-text generation actions, a review action when code feedback is enabled and the active selection is non-empty, and diagnostic-driven fix or explain options when warnings or errors are present. The provider is therefore conservative: it contributes only when the document, selection, configuration, and diagnostics support a useful action.

Sources: extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts

Notebook inline chat follows the same editor-in-flow principle but uses notebook cell status bar items rather than text editor code actions. For markup cells, the provider checks notebook experimental cell chat configuration and requires non-empty markdown content before offering a sparkle action that starts notebook cell chat and auto-sends the markdown as the prompt for generating code in the next cell. For code cells with execution error output, it parses the notebook error MIME payload, removes volatile in-memory file and line references from the message, and starts editor chat with a fix request. If core notebook diagnostics are configured to own quick fixes, this provider stays silent.

Sources: extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatNotebookActions.ts

API Components and Configuration

The public contracts used here are VS Code extension APIs rather than application-private UI calls. AICodeAction extends vscode.CodeAction and marks actions as AI-backed. QuickFixesProvider implements vscode.CodeActionProvider and declares provided action kinds for Copilot quick fixes, Copilot explanations, and Copilot review rewrites. NotebookExectionStatusBarItemProvider implements vscode.NotebookCellStatusBarItemProvider and returns cell status bar items with commands such as notebook.cell.chat.start and vscode.editorChat.start. The command registration function returns a disposable collection, matching VS Code extension lifecycle expectations so registrations can be cleaned up with the extension context.

Sources: extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts, extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatNotebookActions.ts, extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCommands.ts

Several configuration and policy gates shape behavior before a prompt is sent. Copilot code actions depend on the EnableCodeActions configuration key. Inline affordance behavior is checked through the inlineChat affordance setting, and the product documentation also describes inlineChat.askInChat for deciding whether files that belong to an active chat editing session should open Ask in Chat instead of regular inline chat. Notebook actions check notebook.cellFailureDiagnostics and notebook.experimental.cellChat. Prompt rendering checks whether the current URI is ignored by Copilot. These gates matter because inline assistance can be highly visible, so the implementation avoids offering actions when another subsystem owns the experience or the file is outside Copilot scope.

Sources: extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts, extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatNotebookActions.ts, extensions/copilot/src/extension/prompts/node/inline/inlineChatEditCodePrompt.tsx, extensions/copilot/src/extension/prompts/node/inline/inlineChatGenerateCodePrompt.tsx

Implementation Details and Edge Cases

The prompt classes explicitly reject notebook cell or notebook chat input documents, and they also reject markdown documents for these inline code prompt types. That does not mean notebooks and markdown are unsupported surfaces; instead, they are routed through different entry points, such as notebook cell chat generation for markdown cells. This split prevents a text-editor prompt renderer from applying code-edit assumptions to documents whose lifecycle, cell boundaries, or rendering semantics differ from ordinary source files. It also explains why the notebook status bar provider has its own logic for extracting markdown content and execution errors.

Sources: extensions/copilot/src/extension/prompts/node/inline/inlineChatEditCodePrompt.tsx, extensions/copilot/src/extension/prompts/node/inline/inlineChatGenerateCodePrompt.tsx, extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatNotebookActions.ts

AI-generated edit review is represented by both the code action layer and the command layer. The quick fix provider can surface a Review action when review feedback is enabled and a non-empty selection is active. The command registration imports CodeReviewInput, ReviewComment, ReviewSuggestionChange, reviewFileChanges, ReviewSession, and sendReviewActionTelemetry, showing that review is treated as a structured workflow rather than just another prompt string. Product documentation describes the visible review experience as pending file changes with inline diffs, keep or undo decisions, and session restoration. In this source slice, the important mapping is that selected code can enter a review command and the extension has services for comments, suggestions, sessions, and telemetry around that action.

Sources: extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts, extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCommands.ts

Inline completions, ghost text, and next-edit style suggestions should be understood as adjacent editor prediction experiences. They are similar to inline chat because the suggestion appears where the user is already editing, but they differ in initiation and review. Ghost text usually appears proactively or as a completion, while inline chat is explicitly prompted and usually produces a diff or streamed edit. Next-edit style capture is closer to predicting the next transformation after observing user edits. When documenting or extending this area, keep those concepts separate: use inline chat prompt and code action files for explicit requests, and use completion-specific sources for predictive ghost text behavior.

Sources: extensions/copilot/src/extension/prompts/node/inline/inlineChatEditCodePrompt.tsx, extensions/copilot/src/extension/prompts/node/inline/inlineChatGenerateCodePrompt.tsx

Next Steps

For user education, start with the inline chat workflow: open a file, select the smallest useful region, ask for a targeted change, then review the inline diff before keeping or undoing it. For repository work, follow the source path that matches the feature being changed. Prompt changes usually belong near the edit or generate prompt classes. Entry point changes usually belong near command registration, code action providers, or notebook status bar items. Review behavior should be checked against the review service integration and the product review-edits concepts. If the task grows beyond a single focused region, continue to the Chat View, Chat Sessions, or Agents Window pages because those surfaces manage broader conversation context and multi-file work.