Skip to content

fix: force UI flush after RPC-created diff on Windows conhost (cmd.exe)#78

Merged
Cannon07 merged 1 commit into
mainfrom
fix/windows-conhost-redraw-flush
Jun 6, 2026
Merged

fix: force UI flush after RPC-created diff on Windows conhost (cmd.exe)#78
Cannon07 merged 1 commit into
mainfrom
fix/windows-conhost-redraw-flush

Conversation

@Cannon07
Copy link
Copy Markdown
Owner

@Cannon07 Cannon07 commented Jun 6, 2026

Problem

On Windows, when Neovim runs inside the legacy cmd.exe / conhost console, an agent edit would mark the file in neo-tree but the diff tab would not appear until the next edit. Reproduced and root-caused with debug logs: the Lua pipeline (show_diffmark_change_and_reveal → tab creation) runs identically on every edit — the diff tab is created in Neovim's state each time. The failure is purely a screen flush.

The diff is opened via the hook shim's nvim --headless --server <pipe> --remote-expr … call. The post-tab repaint relied on a single deferred vim.cmd("redraw!"). conhost does not flush that timer-driven redraw when it's triggered from an idle --remote-expr, so the grid is only pushed on the next event (the user's next edit). neo-tree updates meanwhile because it forces its own redraw — hence "marking shows, diff doesn't".

Confirmed terminal-dependent: PowerShell terminal / Windows Terminal → fine; cmd.exe → broken.

Fix

Extract the repaint into a force_redraw() helper. On Windows only, after redraw!:

  • nvim__redraw({ flush = true }) — explicitly pushes the grid to the UI, and
  • an <Ignore> feedkeys nudge — wakes the input loop so conhost delivers the flush immediately.

Both are pcall-wrapped (nvim__redraw is 0.10+ / semi-private), and the whole block is behind vim.fn.has("win32"), so all other platforms keep byte-identical prior behaviour. Applied to both the inline and side-by-side/tab paths in show_diff.

Not a regression

This is pre-existing Windows behaviour, not introduced by the hook-entry consolidation (#77): the timer_start(10, redraw!) predates Windows support (since #37), and the RPC call path (nvim-call.ps1, --headless) was unchanged by that PR. This fix applies equally to the state already on main.

Testing

  • require("code-preview.diff") loads clean under headless nvim.
  • diff_lifecycle_spec.lua results are identical before/after this change (verified via stash). Note: that spec currently has pre-existing failures on Windows (config.diff returns nil under minimal_init.lua — a separate Windows test-harness gap, unrelated to this change).
  • Manually verified in a cmd terminal: the diff now appears on the first edit.

Suggested manual checks for reviewers (in cmd.exe)

  • Single Edit, Write (new file → virtual node), MultiEdit — all paint first try
  • Multiple files edited in one turn (several diff tabs)
  • Re-edit same file twice (close-then-reopen)
  • Accept (post-tool close) and reject (<leader>dq) close cleanly
  • PowerShell terminal still works (no regression)

🤖 Generated with Claude Code

When Neovim runs in the legacy Windows console (cmd.exe / conhost), a diff
opened via the hook's `nvim --remote-expr` call did not paint until the next
event — the user's next edit. neo-tree updated meanwhile (it forces its own
redraw), producing the "marking shows but diff doesn't" symptom. The deferred
`redraw!` is simply not flushed by conhost from an idle --remote-expr.

Extract the post-tab repaint into force_redraw() and, on Windows only, follow
the `redraw!` with nvim__redraw({ flush = true }) (pushes the grid to the UI)
plus an <Ignore> feedkeys nudge (wakes the input loop so conhost delivers it).
Both pcall'd (__redraw is 0.10+ / semi-private); the whole block is behind
has('win32'), so every other platform keeps byte-identical prior behaviour.

Pre-existing behaviour, not a regression from the hook-entry consolidation
(#77): the redraw timer predates Windows support and the RPC call path was
unchanged. Verified manually in a cmd terminal — the diff now appears on the
first edit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Cannon07 Cannon07 merged commit e538e69 into main Jun 6, 2026
3 checks passed
@Cannon07 Cannon07 deleted the fix/windows-conhost-redraw-flush branch June 6, 2026 04:28
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.

1 participant