Skip to content

Add action to attach diff hunk to chat#288378

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-copilot-comments-on-diffs
Draft

Add action to attach diff hunk to chat#288378
Copilot wants to merge 2 commits intomainfrom
copilot/add-copilot-comments-on-diffs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 16, 2026

Adds ability to attach a specific diff hunk to chat directly from the hunk toolbar. When reviewing Copilot's code changes, users can now click the attach icon to add that exact change as context for follow-up comments.

Changes

  • IModifiedFileEntryChangeHunk interface: Added getModifiedLineRange() to expose the modified line range
  • DiffHunkWidget: Implements getModifiedLineRange() returning start/end line numbers from the underlying DetailedLineRangeMapping
  • AddHunkToChatAction: New action in ChatEditingEditorHunk menu with:
    • Codicon.attach icon (paperclip)
    • Order 20 (renders after diff toggle at order 10)
    • Attaches hunk range to chat widget and focuses input
  • Notebook hunks: Return undefined for line range (not applicable to cell-based changes)

Testing

  1. Have Copilot make edits to a file
  2. Hover over a diff hunk to reveal the toolbar
  3. Click the paperclip icon
  4. Verify the hunk's code range is attached to chat and input is focused
Original prompt

This section details on the original issue you should resolve

<issue_title>Ability to add Copilot-targeted comments on diffs</issue_title>
<issue_description>

Image

It would be helpful to the ability to add a comment to Copilot directly on a diff of a code change it applied. When there are many changes, it takes quite some effort to accurately explain what my comment is referring to. Say we had an icon on the toolbar next to the diff icon, it would make it very convenient to add comments targeting that particular piece of change. Copilot would then figure out how to pass it to the underlying LLM so that it has the necessary context to apply the change.</issue_description>

<agent_instructions>This should be an action in the ChatEditingEditorHunk-menu. Use the AttachSelectionToChatAction action, give it an icon (paperclip?) let it render after the diff action</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jrieken <1794099+jrieken@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ability to add Copilot-targeted comments on diffs Add action to attach diff hunk to chat Jan 16, 2026
Copilot AI requested a review from jrieken January 16, 2026 15:16
@nidhishgajjar
Copy link
Copy Markdown

Orb Code Review (powered by GLM 5.1 on Orb Cloud)

Summary

Excellent feature implementation that adds the ability to attach specific diff hunks to chat from the hunk toolbar. Clean architecture, focused scope, and enhances the Copilot editing workflow significantly.

Architecture

Interface-Driven Design: Extends IModifiedFileEntryChangeHunk with getModifiedLineRange() method
Consistent Patterns: Follows existing action registration and menu integration patterns
Proper Abstractions: Handles both code editor and notebook scenarios appropriately
Clean Separation: Chat integration through IChatWidgetService without tight coupling

Implementation Quality

Type Safety: Proper TypeScript interfaces and type checking
Error Handling: Graceful handling when line range or widget unavailable
Context Awareness: Appropriate preconditions using existing context keys
Resource Management: No new disposables or memory concerns

// Clean interface extension
interface IModifiedFileEntryChangeHunk {
  accept(): Promise<boolean>;
  reject(): Promise<boolean>;
  getModifiedLineRange(): { startLineNumber: number; endLineNumberExclusive: number } | undefined;
}

Code Quality

Focused Implementation: Each file has clear, single responsibility
Consistent Naming: AddHunkToChatAction follows VS Code naming conventions
Proper Imports: Only imports what's needed, no circular dependencies
Icon Choice: Paperclip (Codicon.attach) is intuitive for "attach to chat"

Cross-file Impact

Minimal Surface Area: Only 5 files changed, 54 additions, 0 deletions
Interface Compliance: All implementers properly handle new interface requirement
Backward Compatibility: No breaking changes to existing functionality
Menu Integration: Clean integration into existing ChatEditingEditorHunk menu

User Experience

Intuitive Workflow: Click paperclip → hunk attached to chat → input focused
Visual Consistency: Uses established VS Code iconography
Contextual Availability: Only appears when relevant (has modifications, not being modified)
Smart Defaults: Focuses input after attachment for immediate use

Edge Cases Handled

Notebook Cells: Returns undefined for line ranges (not applicable)
Missing Widget: Graceful handling when chat widget unavailable
No Line Range: Proper early return when hunk has no modifiable range
Range Construction: Correctly constructs Range from line numbers

Testing Considerations

Clear Test Plan: PR description provides step-by-step testing instructions
Multiple Scenarios: Should work with both single and multi-line hunks
Integration Points: Tests chat attachment and input focus behavior

Assessment

Recommendation: ✅ APPROVE

This is a textbook example of excellent feature development:

  1. Clear User Value: Solves a real problem (difficult to reference specific changes in chat)
  2. Clean Architecture: Proper interface extension with consistent implementation
  3. Focused Scope: Does exactly what's needed, nothing more
  4. Quality Implementation: Type-safe, error-handled, follows conventions
  5. Good UX: Intuitive icon placement and workflow

Strengths:

  • Interface design allows for different hunk types (code vs notebook)
  • Proper separation of concerns between editing and chat systems
  • Excellent use of existing VS Code infrastructure
  • No over-engineering or unnecessary complexity

Minor Observations (non-blocking):

  • Consider adding telemetry for feature usage tracking
  • Documentation in interface comment is helpful

Ready to merge - this enhances the Copilot editing experience with zero risk and high value.

User Impact: Developers can now easily attach specific code changes to chat for targeted feedback, making the Copilot editing workflow much more efficient.

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.

Ability to add Copilot-targeted comments on diffs

3 participants