Skip to content

fix: use signal-based diff acceptance instead of direct file writes #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 14, 2025

Conversation

ThomasK33
Copy link
Member

Summary

Fixes #33 by changing the diff acceptance approach from direct file writing to signal-based communication with Claude Code.

Changes Made

  • Signal-based acceptance: Instead of writing to files directly, the plugin now sends an acceptance signal to Claude Code
  • Claude Code handles file writes: Claude Code receives the signal and performs the actual file modifications
  • Buffer reload after changes: Plugin reloads buffers after Claude Code completes the file writes
  • Unified behavior: Both <leader>da keymap and :w command now use the same signal-based approach
  • Cleaned up logging: Removed verbose debug logs and outdated comments

Technical Details

Previously, the plugin was directly writing to files when accepting diffs, which could cause issues. Now the plugin sends Claude Code a signal that the diff was accepted, Claude Code handles the actual file modifications, and the plugin reloads the affected buffers to reflect the changes.

Fixes #33

- Change from direct file writing to signal-based communication with Claude Code
- Plugin sends acceptance signal, Claude Code handles actual file modifications
- Plugin reloads buffers after Claude Code completes file writes
- Unified behavior for both <leader>da keymap and :w command
- Clean up verbose debug logging and outdated comments

Previously the plugin was directly writing to files when accepting diffs,
which could cause issues. Now the plugin properly delegates file modifications
to Claude Code through signal-based acceptance.

Change-Id: Iae72c91da515c4167590cea75d123ff30d10c5f8
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33 ThomasK33 force-pushed the fix/unified-diff-acceptance-behavior branch from 2b60f1f to 8003708 Compare June 14, 2025 12:05
@ThomasK33 ThomasK33 requested a review from Copilot June 14, 2025 12:11
Copilot

This comment was marked as outdated.

- Document how to accept changes with :w and <leader>da
- Document how to reject changes with :q, <leader>dq, etc.
- Explain signal-based approach and buffer reloading
- Note that users can edit diff buffer before accepting
- Provide clear user guidance for diff workflows

Change-Id: Ic000567fafabecea06aa1ac95a5c5465a0290622
Signed-off-by: Thomas Kosiewski <tk@coder.com>
- Use dynamic filename derivation instead of hardcoded 'new.lua.new'
- Address Copilot feedback about brittle filename verification
- Extract expected suffix from new_file_path for better maintainability

Change-Id: Ie2c6932ce36f54863a6262956eb7cfc02c4ca9df
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33 ThomasK33 requested a review from Copilot June 14, 2025 12:46
Copy link

@Copilot 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

Updates the diff acceptance flow to use a signal-based approach instead of direct file writes and aligns tests and docs with the new API.

  • Switches plugin tests from _create_temp_file to _open_native_diff, updating assertions for success, temp_file, and error fields
  • Adds a new filetype annotation in the vim metadata module
  • Documents the native diff workflow and key mappings in the README

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/unit/diff_spec.lua Refactored tests to call _open_native_diff and adjust result validations
lua/claudecode/meta/vim.lua Added vim_filetype_module class and filetype field annotation
README.md Added "Working with Diffs" section detailing new diff behavior

- Add temp_file field to mocked _open_native_diff implementation
- Ensure error case returns temp_file = nil explicitly
- Add comprehensive error validation in tests
- Improve test robustness and consistency

docs: add terminal-based diff acceptance/rejection option

- Document that users can accept/reject diffs from Claude Code terminal
- Provide alternative workflow for terminal-focused users

Change-Id: I5bee1fffb5cec40d0d593795ec1d8bb2dd2208be
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33 ThomasK33 merged commit da78309 into main Jun 14, 2025
3 checks passed
@ThomasK33 ThomasK33 deleted the fix/unified-diff-acceptance-behavior branch June 14, 2025 13:24
ThomasK33 added a commit that referenced this pull request Jun 18, 2025
This release includes significant feature additions and bug fixes:

**Version Updates:**
- Updated main version table in lua/claudecode/init.lua (0.1.0-alpha → 0.2.0)
- Updated client versions in scripts/claude_interactive.sh (3 locations)
- Updated ClaudeCodeNvim version in scripts/lib_claude.sh
- Removed prerelease flag for stable release

**Documentation:**
- Added comprehensive CHANGELOG.md with v0.2.0 release notes
- Documented all merged PRs since v0.1.0 with proper references
- Updated CLAUDE.md with detailed release process documentation
- Fixed diff keymap references in README.md (<leader>da → <leader>aa)

**Features Added (since v0.1.0):**
- Diagnostics integration (#34)
- File explorer support for oil.nvim, nvim-tree, neotree (#27, #22)
- Enhanced terminal management with ClaudeCodeFocus command (#40)
- Auto terminal provider detection (#36)
- Customizable diff keymaps via LazyVim spec (#47)

**Bug Fixes:**
- Terminal focus errors when buffer hidden (#43)
- Improved diff acceptance behavior (#41)
- Fixed syntax highlighting in proposed diff view (#32)
- Visual selection range handling improvements (#26)
- Native terminal bufhidden behavior (#39)

All code quality checks pass and documentation is updated for maintainability.

Change-Id: I0e4e7c9bae98df922356dc8b8aa0acd7e8293a48
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33 ThomasK33 mentioned this pull request Jun 18, 2025
ThomasK33 added a commit that referenced this pull request Jun 18, 2025
This release includes significant feature additions and bug fixes:

**Version Updates:**
- Updated main version table in lua/claudecode/init.lua (0.1.0-alpha → 0.2.0)
- Updated client versions in scripts/claude_interactive.sh (3 locations)
- Updated ClaudeCodeNvim version in scripts/lib_claude.sh
- Removed prerelease flag for stable release

**Documentation:**
- Added comprehensive CHANGELOG.md with v0.2.0 release notes
- Documented all merged PRs since v0.1.0 with proper references
- Updated CLAUDE.md with detailed release process documentation
- Fixed diff keymap references in README.md (<leader>da → <leader>aa)

**Features Added (since v0.1.0):**
- Diagnostics integration (#34)
- File explorer support for oil.nvim, nvim-tree, neotree (#27, #22)
- Enhanced terminal management with ClaudeCodeFocus command (#40)
- Auto terminal provider detection (#36)
- Customizable diff keymaps via LazyVim spec (#47)

**Bug Fixes:**
- Terminal focus errors when buffer hidden (#43)
- Improved diff acceptance behavior (#41)
- Fixed syntax highlighting in proposed diff view (#32)
- Visual selection range handling improvements (#26)
- Native terminal bufhidden behavior (#39)

All code quality checks pass and documentation is updated for maintainability.

Change-Id: I0e4e7c9bae98df922356dc8b8aa0acd7e8293a48
Signed-off-by: Thomas Kosiewski <tk@coder.com>
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.

[BUG] Error after accepting edits in diff view
1 participant