Repository navigation
fix(diff): keep openDiff and diff.open_diff out of the preview window - #391
Conversation
With only the preview window and the Claude terminal in the tab, and the cursor in the preview window, openDiff splits the preview window, so the diff gets the preview window's 12 lines. The legacy diff.open_diff opens the file in the preview window itself. These tests fail until the fix. The vim mock now gives a vertical split the height of the window it splits, as Neovim does, so a test can see which row the diff went into. Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
The unified layout splits the Claude terminal into a 1-column diff when no editor window exists, because it sets the terminal back to its old width. Moving its split off the preview window would make that case worse, so this change leaves the unified layout as it is and drops its test. Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
With only the preview window and the Claude terminal in the tab, and the cursor in the preview window, openDiff split the preview window. The preview window has 'winfixheight', so the diff got its 12 lines. The legacy diff.open_diff opened the old file in the preview window itself. create_split() now splits the Claude terminal's window when the preview window is current and the terminal is a tiled window in the same tab, as the no-editor-window fallback does when the cursor is in the terminal. diff.open_diff splits instead of opening the file when it lands on the preview window. The comment in find_main_editor_window now gives the reasons openDiff skips the preview window. Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…ice fix Only the diff.lua file hash changed. No block or call site the model describes changed: the fix chooses which window a diff splits, and it cannot reach diff state, an openDiff answer, a disconnect or a diff command. check.sh passes on this tree. Part of #385 _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…rejected diffs (coder#392) Part of coder#385 (items 1 to 3). ## Why The goal is to close the open follow-up issues in this repo, which list bugs found while verifying earlier fixes. This PR covers items 1 to 3 of issue 385. They are all in the step where `:ClaudeCodeCloseAllDiffs` finishes a diff the user accepted after its Claude client exited (added in coder#376). The command puts the accepted text into the file's buffer as unsaved changes, and the user's `:w` writes it. 1. The buffer kept its `'fileformat'` and `'bomb'`, so `:w` wrote a CRLF proposal into a `dos` file as `\r\r\n`, and wrote a proposal's BOM twice into a `'bomb'` file. `'fixeol'` stayed off for every later write. 2. Every failure printed "its buffer has unsaved changes or cannot be written". A swap file from another Neovim (`E325`) or a `'nomodifiable'` buffer got that wrong reason. A failed hand-over also left the buffer listed. A new file in a missing folder failed the user's `:w` with `E212`, and a `€` into a latin1 buffer failed with `CONVERSION ERROR`, with no hint in either case. 3. A diff the user rejected stayed open forever when its client exited before it sent `close_tab`. `:ClaudeCodeCloseAllDiffs` said "No Claude diffs to close". ## What changed - `accepted_lines` now builds the lines for the file's buffer. In a `dos` buffer it drops the CR before each line break when every line break of the text is CRLF (the same rule Neovim's read uses). In a `'bomb'` buffer it drops a leading BOM. `buffer_holds_accepted_text` compares against these same lines. - `put_accepted_text_in_buffer` returns why it did not hand the text over. It passes a load or `nvim_buf_set_lines` error through, without the plugin's Lua position. It sets `'buflisted'` and `'bufhidden'` only after the lines are set. When it fails, it wipes a buffer it created, or unloads one it loaded. A text without a final line break turns `'fixeol'` off only until the buffer's next write or read. - `close_saved_diffs` returns, for each handed-over file, the command that writes it (`:w`, or when the folder is missing `:w ++p`, which Neovim 0.8 lacks, so there `:call mkdir(expand('%:p:h'), 'p') | w`) and a `'fileencoding'` that cannot hold the text. For each kept diff it returns the reason. The command prints both. - New `diff.close_rejected_diffs`. `:ClaudeCodeCloseAllDiffs` now runs `close_pending_diffs`, `close_rejected_diffs`, then `close_saved_diffs`, and prints "Closed N rejected Claude diff(s)". - The diff-lifecycle model (`.agents/skills/verify-diff-lifecycle`) gets the fact `UserCloseTakesRejected`. The `NoRejectedLeftover` rule now also covers the user command. `covered.lock` is re-recorded on the tree merged with main. This also refreshes the stale `lua/claudecode/tools/open_file.lua` entry that coder#387 left (`c0146253bf4cfc63` to `15f2a6f9d6cc9a7b`), so `check.sh` on main passes again once this merges. - Docs: README.md, `lua/claudecode/README.md` (including that a full reload of `claudecode.diff` forgets open diffs), the skill fact table, and `features/close-diffs.md`. ## Scope - Encoding: the plugin does not change `'fileencoding'`. Changing it would change the file's bytes beyond the accepted edit. The message tells the user to run `:set fileencoding=utf-8` first. - A plain LF proposal into a `dos` buffer is written as CRLF. The file keeps its own format. - A CRLF proposal into a `unix` buffer keeps its CRs in the buffer, so `:w` writes the CRLF bytes the user accepted. Dropping them would write bytes the user did not accept. - Plugin reload (item 3, second half) is documented, not fixed. `active_diffs` is module state, and the new module's `ClaudeCodeMCPDiff` augroup is created with `clear = true`. Keeping the table in `_G` would share state across test module instances, and the old diffs' autocmds are gone either way. - Item 2's "a `ClaudeCodeDiffClosed` handler accepts a diff while the command runs" case did not reproduce. On main, the handler-accepted diff is handed over by the same command (`ev-handler-before`). If a diff stays saved without a recorded failure, the message now says it changed while the command ran. - The window-choice part of coder#385 item 5 is in coder#391. ## Blast Radius - Only `:ClaudeCodeCloseAllDiffs` and the new `close_rejected_diffs` change behavior. The Claude tools (`closeAllDiffTabs`, `close_tab`), disconnect cleanup, and server stop are unchanged. - `close_saved_diffs` now returns tables instead of path strings. Its only caller is the user command. - The command now also closes rejected diffs of a client that is still connected. That client already has its answer, and its later `close_tab` for that tab finds nothing and returns as before. - The command no longer skips a dirty file buffer before loading it. `put_accepted_text_in_buffer` checks `'modified'` after the load instead, so the kept-diff result is the same, with the reason "its buffer has unsaved changes". ## Verification Red first: `tests/integration/diff_hand_over_spec.lua` (real Neovim, plenary) runs 7 tests. On main's code all 7 fail. With this PR all 7 pass. Real Neovim through the `verify-claudecode-nvim` harness (`vcn.sh`): Claude opens a diff, the user accepts it, Claude exits, the user runs `:ClaudeCodeCloseAllDiffs`, then writes the buffer the way the message says. | Case | Before | After | | --- | --- | --- | | CRLF proposal, `dos` file | disk `alpha\r\r\n...` | disk `alpha\r\n...` | | BOM proposal, `'bomb'` file | two BOMs on disk | one BOM | | No final line break | `'fixeol'` stays 0 | 1 after the `:w` | | `€` into a latin1 file | no hint, `:w` gives `CONVERSION ERROR` | message names `:set fileencoding=utf-8`, then `:w` writes UTF-8 | | New file, missing folder | `:w` fails with `E212` | message names `:w ++p` (Neovim 0.8: `:call mkdir(expand('%:p:h'), 'p') \| w`), which writes it | | Swap file from another Neovim | "unsaved changes or cannot be written" | "E325: ATTENTION", no buffer left | | `'nomodifiable'` from a `BufReadPost` autocmd | wrong reason, buffer stays listed | "Buffer is not 'modifiable'", no buffer left | | Rejected diff, client gone | "No Claude diffs to close", diff stays | "Closed 1 rejected Claude diff(s)" | Swap file, before:  Swap file, after:  latin1 file, after:  The real-Neovim spec passes 7 of 7 on Neovim 0.8.3, 0.9.5, and 0.12.3. Gates on the head: `mise run check` (0 warnings), `mise run test` (952 passed, shuffled), `./scripts/run_integration_tests_individually.sh` (29 passed), stylua and prettier clean. `.agents/skills/verify-diff-lifecycle/check.sh --mutants` catches every guard, `UserCloseTakesRejected=FALSE` by `NoRejectedLeftover`. `check.sh` passes after `--record`. All of this ran again on the tree merged with main after coder#387 and coder#391. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…f the terminal usable (coder#399) ## Why The operator goal is to close the open follow-up issues in claudecode.nvim, one small reviewed PR per fix. This PR takes item 2 of coder#393, the windows a diff picks. Two unified-layout bugs get fixed. A unified diff with `open_in_new_tab` left its new tab open after `close_tab` when that tab got no Claude terminal. With no editor window, a unified diff split the preview window, and a diff split off the Claude terminal was 1 column wide. The other two sub-items are documentation. ## What changed - `guard_inline_setup` in `diff_inline.lua` passes its results through as varargs. `unpack` stopped at the nil terminal window and dropped the new tab handle, so cleanup never closed the tab. - The unified fallback leaves the preview window for a tiled Claude terminal, as the vertical and horizontal layouts do since coder#391. A terminal it split is sized by the diff width policy the other layouts use (`diff_split_width_percentage`, `auto_resize_terminal`) instead of getting its old full width back. - `lua/claudecode/README.md` documents that the window search spans every tab, where each layout puts a diff it splits off the terminal, and the floating or hidden terminal limit. ## Scope Decision per sub-item of coder#393 item 2: - 2a, terminal in another tab: documented, not fixed. The diff goes to another tab because the window search covers every tab, first tab first. Keeping diffs in the current tab would move diffs for users who keep Claude alone in its own tab, and restoring a reused empty window would change the default `nvim` + `:ClaudeCode` flow, where the file stays open after `close_tab`. Follow-up below. - 2b, unified + `open_in_new_tab` leaving an empty tab: fixed. It also happened with no Claude terminal at all and with `hide_terminal_in_new_tab = true`. - 2c, unified 1-column diff and preview-window split: fixed for a tiled terminal. With a floating or hidden terminal and only the preview window in the tab, every layout still splits the preview window, now documented. That tab has no other tiled window to split, so the only other choice is a new tab, which `open_in_new_tab` already offers. - 2d, README vertical-layout line: rewritten to say the terminal sits between the preview window and the diff. Follow-ups, not in this PR: decide whether openDiff stays in the current tab (today a user in tab 2 with an editor window and the Claude terminal gets the diff in tab 1). A unified diff in a new tab still sizes the terminal with the raw `split_width_percentage`, as on main, not with the diff width policy. ## Blast Radius Only the unified layout changes behavior, in two cases: a new tab without a Claude terminal, and the fallback when no editor window exists. A 351-run headless matrix (13 window layouts, 3 focus choices, 3 layouts, new tab on and off, `hide_terminal_in_new_tab` on and off) shows no change for the vertical and horizontal layouts. ## Verification - New real-Neovim spec `tests/integration/diff_window_choice_spec.lua`: the 4 cases from the issue fail on main, and all 6 cases pass on this branch on Neovim 0.12.3 and 0.9.5. On 0.8.3 it is pending because the unified layout needs 0.9. - vcn.sh, real Neovim with a native Claude terminal, `:w` accept, then `close_tab`: terminal-only diff 1 → 53 columns. With the preview window above the terminal, the diff has 12 → 25 rows and the preview window keeps 160 columns. With `open_in_new_tab`, 2 → 1 tab after `close_tab`. - `mise run check`, `mise run test` (952 passed), and `run_integration_tests_individually.sh` (39 passed) on the head. The `verify-diff-lifecycle` model passes and `covered.lock` is recorded. Terminal is the only window, before and after:   Preview window above the terminal, before and after:   After `close_tab` with `open_in_new_tab` and only the preview window, before (tabline shows the leftover tab) and after:   Part of coder#393 --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Why
This PR is one of the small, reviewed fixes that close the open follow-up issues in claudecode.nvim (#385). It covers the openDiff and
diff.open_diffwindow-choice items of #385 item 5.'winfixheight', so both diff panes got its 12 lines while the terminal below kept 25.diff.open_diff(public Lua API, no caller in the plugin) opened the old file in the preview window itself whenwincmd tandwincmd llanded there. That happens with the cursor in the terminal too.find_main_editor_windowgave openFile's reason for skipping the preview window, not openDiff's.What changed
create_split()inlua/claudecode/diff.luafirst calls a newleave_preview_window(). When the preview window is current and the Claude terminal is a tiled window in the same tab, it makes the terminal's window current, so the split goes beside the terminal. The no-editor-window fallback ([BUG] when claude code is the only window left (no splits) , an error message is generated when claude tries to suggest changes #231) already puts the diff there when the cursor is in the terminal. Its fallback window is still tracked and closed on cleanup._open_native_diff(behinddiff.open_diff) splits instead of running:editwhen it lands on the preview window.find_main_editor_windowcomment now gives openDiff's reasons:'winfixheight'keeps the preview window at'previewheight'lines, and the next:peditshows another file in it and turns off its'diff'.lua/claudecode/README.md(Diffs) gets one bullet for the new rule.tests/unit/diff_preview_window_spec.lua. The vim mock now gives a vertical split the height of the window it splits, as Neovim does, so a test can see which row the diff went into.covered.lockis re-recorded. Only thediff.luafile hash changed. No block or call site that the model describes changed, and the fix cannot reach diff state, an openDiff answer, a disconnect or a diff command.Scope
diff_opts.layout = "unified") is unchanged, and it still splits the preview window in this layout. A split beside the terminal is worse there: with no editor window, the unified path sets the terminal back to its width from before the diff, so a diff split off the terminal is 1 column wide. Main does the same with only the Claude terminal in the tab (156 + 1 + 1 columns). Both are follow-ups.M._create_diff_view_from_windowis unchanged. Itswincmd t/wincmd lbranch runs only in the fresh tab thatopen_in_new_tabor a foreign-diff tab creates, and a fresh tab has no preview window.lua/claudecode/tools/open_file.luais not touched. fix(open_file): keep the user's Visual mode, unsaved changes and focus #387 owns openFile.Blast Radius
verticalorhorizontaldiff that has to split a window while the preview window is current now goes beside the Claude terminal, as it does when the cursor is in the terminal. When the preview window fills its own column, thehorizontallayout now stacks the panes in the terminal's column (48x12 each) instead of under the preview window (111x9 each).diff.open_diffchanges only whenwincmd tandwincmd lland on the preview window.keep_terminal_focusare unchanged.Verification
sh, the preview window (160x12) sits above it, and the cursor is in the preview window.other.txt.diff.open_diffbefore:hello.txtopens in the preview window. After: the preview window keepsother.txt, and the diff panes are 52x25 and 53x25.verticalandhorizontalresults now equal the terminal-cursor results, and unified is the same as main.diff.open_diffno longer replaces the preview window's file in either focus case. Withkeep_terminal_focus = true, the focus still ends in the terminal.leave_preview_window, the diff moved to the terminal's tab.mise run check,mise run test(919 passed, shuffled), the integration suite, and the diff-lifecyclecheck.sh(PASS) pass on the head.Before, the diff panes share the preview window's 12 lines:
After, the diff panes sit beside the terminal, 25 lines tall:
Part of #385
Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:xhigh