fix: force UI flush after RPC-created diff on Windows conhost (cmd.exe)#78
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_diff→mark_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 deferredvim.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, afterredraw!:nvim__redraw({ flush = true })— explicitly pushes the grid to the UI, and<Ignore>feedkeysnudge — wakes the input loop so conhost delivers the flush immediately.Both are
pcall-wrapped (nvim__redrawis 0.10+ / semi-private), and the whole block is behindvim.fn.has("win32"), so all other platforms keep byte-identical prior behaviour. Applied to both the inline and side-by-side/tab paths inshow_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 onmain.Testing
require("code-preview.diff")loads clean under headless nvim.diff_lifecycle_spec.luaresults are identical before/after this change (verified via stash). Note: that spec currently has pre-existing failures on Windows (config.diffreturns nil underminimal_init.lua— a separate Windows test-harness gap, unrelated to this change).Suggested manual checks for reviewers (in cmd.exe)
<leader>dq) close cleanly🤖 Generated with Claude Code