A powerful VS Code extension that allows you to add comments to diff views, just like in GitHub Pull Requests. Keep track of your code review thoughts, bug reports, and improvement suggestions directly in your development environment.

Features
- Diff View Comments: Add comments when viewing diffs between commits
- File-Specific Comments: Comments are tied to specific commits and file changes
- Smart Commit Detection: Automatically detects the relevant commit and parent commit for each comment
- Add Comments: Right-click in diff views or use the command palette to add comments
- Edit Comments: Modify existing comments inline
- Delete Comments: Remove comments you no longer need
- Jump to Comments: Click on comments to navigate to the exact diff location
🔍 Advanced Diff Navigation
- Commit-to-Commit Diffs: View changes between specific commits (parent → current)
- Commit-to-Workspace Diffs: Compare commits with your current workspace
- File History Awareness: Comments are linked to the actual commits that modified each file
💾 Persistent Storage
- Comments are stored in
.vscode/diff-comments.yaml
in your workspace
- YAML format for easy reading and version control
- Backward compatible with existing comment formats
Installation
- Open VS Code
- Go to the Extensions view (
Ctrl+Shift+X
or Cmd+Shift+X
)
- Search for "Diff Comments"
- Click Install
How to Use
Quick Start Guide
- Open a Git repository in VS Code
- Open the Diff Comments view by clicking on the Diff Comments icon in the Activity Bar
- Add your first comment using one of the methods below
- View and manage comments in the dedicated tree view
Step-by-Step Usage
- Open a diff view using any of these methods:
- Git History: Open Source Control → Click on a commit → Select a modified file
- Compare Files: Use
Ctrl+Shift+P
→ "Git: Compare File with..."
- Git Diff: Open terminal →
git diff HEAD~1 HEAD filename.ts
- Add a comment:
- Right-click on any line in the diff view
- Select "Add Diff Comment" from the context menu
- Type your comment in the input box
- Press Enter to save
- Your comment is now saved and visible in the Diff Comments tree view
- Open any file in your Git repository
- Position your cursor on the line you want to comment on
- Add a comment:
- Press
Ctrl+Shift+P
(or Cmd+Shift+P
on Mac)
- Type "Add Diff Comment" and press Enter
- Or use the right-click context menu
- Enter your comment and press Enter
💡 Note: When adding comments to regular files, the extension automatically detects the last commit that modified the file and creates appropriate diff context.
Method 3: Using Keyboard Shortcuts
- Position your cursor on the desired line
- Press the shortcut (if configured in your keybindings)
- Type your comment and press Enter
- Open the Diff Comments view in the Activity Bar (left sidebar)
- Comments are grouped by file and show:
- 📝 Comment text
- 📁 File path
- 🔗 Commit information (e.g.,
a1b2c3d → b2c3d4e
)
- ✅ Completion status
- Locate the comment in the Diff Comments tree view
- Click the edit icon (✏️) next to the comment
- Modify the text in the input dialog
- Press Enter to save changes
- Find the comment in the tree view
- Click the delete icon (🗑️)
- Confirm deletion when prompted
- Click on any comment in the tree view
- VS Code will automatically:
- Open the relevant diff view
- Navigate to the exact line
- Highlight the commented code
- Right-click on a comment in the tree view
- Select "Toggle Completed"
- Completed comments will show a ✅ icon and move to the bottom of the list
Advanced Usage Scenarios
Code Review Workflow
- Review a pull request or commit
- Add comments for issues, suggestions, or questions
- Mark comments as complete after addressing them
- Jump back to comments during implementation
Bug Tracking
- Add comments when you find bugs during development
- Include details about reproduction steps or expected behavior
- Track progress by marking comments as complete
- Reference specific commits where bugs were introduced
Documentation and Notes
- Add comments to document complex code sections
- Track TODOs and improvement ideas
- Link comments to specific commits for context
- Share insights with team members
Tips and Best Practices
✅ Best Practices:
- Write clear, descriptive comments
- Use comments for code review feedback
- Mark comments as complete when resolved
- Include context about why changes are needed
⚠️ Things to Remember:
- Comments are stored in
.vscode/diff-comments.yaml
- Comments are tied to specific commits and file changes
- Make sure your project is a Git repository
- Comments persist across VS Code sessions
Troubleshooting
Comment not showing up?
- Ensure you're in a Git repository
- Check that the file has been committed to Git
- Try refreshing the Diff Comments view
Can't add comments?
- Verify Git is installed and working
- Make sure the file is part of a Git repository
- Check that you have write permissions to the workspace
Diff view not opening?
- Ensure the referenced commits still exist
- Try refreshing the Git repository
- Check that Git extension is enabled
Usage
- In Diff View:
- Open a diff view (e.g., from Git history, Source Control, or using
git diff
)
- Right-click at the line where you want to add a comment
- Select "Add Diff Comment" or use
Ctrl+Shift+P
→ "Add Diff Comment"
- In Regular Files:
- Open any file in a Git repository
- Use the command palette (
Ctrl+Shift+P
) → "Add Diff Comment"
- The extension will automatically find the last commit that modified the file
- Open the Diff Comments view in the Activity Bar
- Comments are displayed with file paths and commit information
- Format:
filename (parentHash → commitHash)
for diff comments
- Format:
filename (commitHash)
for single-commit comments
- Edit: Click the edit icon (✏️) next to any comment in the tree view
- Delete: Click the delete icon (🗑️) next to any comment
- Jump: Click on a comment to open the diff view at that exact location
Commands
Command |
Description |
diff-comments.addComment |
Add a new comment to the current file/diff |
diff-comments.refresh |
Refresh the comments tree view |
diff-comments.editComment |
Edit an existing comment |
diff-comments.deleteComment |
Delete a comment |
diff-comments.jumpToComment |
Jump to the diff location of a comment |
diff-comments.showDiffInfo |
Show detailed information about the current diff |
Comments are stored in .vscode/diff-comments.yaml
with the following structure:
- id: "unique-comment-id"
text: "Your comment text"
fileUri: "relative/path/to/file.ts"
lineNumber: 42
commitHash: "abc123def456" # The commit being commented on
parentHash: "def456abc123" # The parent commit (for diff context)
Fields Explanation
- id: Unique identifier for the comment
- text: The comment content
- fileUri: Relative path to the file within the workspace
- lineNumber: Zero-based line number where the comment was added
- commitHash: The commit hash that the comment refers to
- parentHash: The parent commit hash (used for creating proper diff views)
Key Benefits
🚀 Enhanced Code Review
- Add review comments directly in your IDE
- Track comments across different commits
- Perfect for solo development or team code reviews
🎯 Precise Context
- Each comment is tied to specific file changes
- Comments show the exact diff where they were added
- No more losing track of what you were thinking about
🔄 Workflow Integration
- Works seamlessly with Git workflows
- Comments persist across VS Code sessions
- Easy to share via version control (optional)
Examples
1. Open Git history for a file
2. Select a commit to view its diff
3. Right-click on a line in the diff
4. Select "Add Diff Comment"
5. Enter your comment: "This function should handle edge cases"
Diff Comments View:
├── 📝 This function should handle edge cases
│ └── src/utils/helper.ts (a1b2c3d → b2c3d4e)
├── 📝 Consider adding unit tests
│ └── src/components/Button.tsx (c3d4e5f → d4e5f6a)
└── 📝 Performance optimization needed
└── src/services/api.ts (e5f6a7b → f6a7b8c)
Configuration
Currently, the extension works out of the box with no configuration required. Comments are automatically stored in your workspace's .vscode
directory.
Requirements
- VS Code 1.85.0 or higher
- Git repository (for commit detection)
- Git extension enabled in VS Code
Known Limitations
- Comments are workspace-specific
- Requires Git repository for full functionality
- Binary files are not supported for diff comments
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Changelog
0.0.1
- Initial release
- Basic comment functionality
- Diff view support
- YAML storage format
- Context-aware commit detection
License
MIT License - see LICENSE file for details
Support
If you encounter any issues or have feature requests, please file an issue on the GitHub repository.
Happy coding with contextual comments! 🎉