Skip to content

Copilot CLI: Send Selection via Command/Context Menu#3668

Merged
DonJayamanne merged 4 commits intomainfrom
mrayermannmsft/feat/sendselectiontocli
Feb 11, 2026
Merged

Copilot CLI: Send Selection via Command/Context Menu#3668
DonJayamanne merged 4 commits intomainfrom
mrayermannmsft/feat/sendselectiontocli

Conversation

@MRayermannMSFT
Copy link
Member

@MRayermannMSFT MRayermannMSFT commented Feb 11, 2026

What

Adds a new "Add Selection to Copilot CLI" command that allows users to send their current editor selection to a connected CLI session. The command appears in the editor context menu when text is selected and a CLI session is connected.

Why

Users can already send file references to CLI sessions, but there's no way to quickly send just a selection of code. This is a common workflow when asking the CLI agent about a specific piece of code—you want to highlight it and send it directly rather than describing where it is or sending the entire file.

Behavior

  • When text is selected: sends the file path, selection range, and selected text
  • When no selection: falls back to sending just the file reference (same as "Add File to Copilot CLI")
  • Virtual files (output panels, chat code blocks, untitled files) are rejected with a warning
  • If multiple CLI sessions are connected, prompts the user to pick which one

Testing

Added unit tests covering selection sending, no-selection fallback, URI scheme validation, and session picker behavior.

Related: #3668

Copy link
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

This PR adds a new "Add Selection to Copilot CLI" command that enables users to quickly send their current editor selection (or the entire file if no selection) to a connected CLI session. This complements the existing "Add File to Copilot CLI" command by providing a more targeted way to share specific code snippets with the CLI agent.

Changes:

  • Refactored file reference sending logic into shared utilities in sendContext.ts for better code reuse
  • Added new addSelection command that sends the current editor selection (or falls back to file reference when no selection)
  • Enhanced URI scheme validation to reject virtual files (output panels, untitled files, chat code blocks) with appropriate user warnings
  • Added comprehensive unit tests covering selection sending, fallback behavior, session picking, and URI validation

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/extension/agents/copilotcli/vscode-node/commands/sendContext.ts New file consolidating shared logic for sending file references and selections to CLI sessions, including URI scheme validation
src/extension/agents/copilotcli/vscode-node/commands/addSelection.ts New command registration for sending editor selections to CLI sessions
src/extension/agents/copilotcli/vscode-node/commands/addFileReference.ts Refactored to use shared utilities from sendContext.ts, reducing code duplication
src/extension/agents/copilotcli/vscode-node/commands/index.ts Updated exports to include new command and shared utilities
src/extension/agents/copilotcli/vscode-node/contribution.ts Registers the new addSelection command in the extension
src/extension/agents/copilotcli/vscode-node/test/addSelection.spec.ts Comprehensive unit tests for the selection command covering various scenarios
src/extension/agents/copilotcli/vscode-node/test/addFileReference.spec.ts Enhanced with URI scheme validation tests and updated mocks
src/extension/agents/copilotcli/vscode-node/test/testHelpers.ts Added scheme property to mock editor for URI validation testing
package.json Added command definition and context menu entry (shown only when text is selected)
package.nls.json Added localization string for the new command title

@MRayermannMSFT MRayermannMSFT marked this pull request as ready for review February 11, 2026 20:49
DonJayamanne
DonJayamanne previously approved these changes Feb 11, 2026
@vs-code-engineering vs-code-engineering bot added this to the February 2026 milestone Feb 11, 2026
@DonJayamanne DonJayamanne added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit c7e028d Feb 11, 2026
19 checks passed
@DonJayamanne DonJayamanne deleted the mrayermannmsft/feat/sendselectiontocli branch February 11, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants