Copilot CLI: Send Selection via Command/Context Menu#3668
Merged
DonJayamanne merged 4 commits intomainfrom Feb 11, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.tsfor better code reuse - Added new
addSelectioncommand 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 |
src/extension/agents/copilotcli/vscode-node/test/addSelection.spec.ts
Outdated
Show resolved
Hide resolved
DonJayamanne
previously approved these changes
Feb 11, 2026
DonJayamanne
approved these changes
Feb 11, 2026
karthiknadig
approved these changes
Feb 11, 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.
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
Testing
Added unit tests covering selection sending, no-selection fallback, URI scheme validation, and session picker behavior.
Related: #3668