fix: prevent crash with render-markdown.nvim on new file diff accept#224
Open
bluzername wants to merge 1 commit intocoder:mainfrom
Open
fix: prevent crash with render-markdown.nvim on new file diff accept#224bluzername wants to merge 1 commit intocoder:mainfrom
bluzername wants to merge 1 commit intocoder:mainfrom
Conversation
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
Neovim crashes with exit code 139 (segfault) when you accept a new file diff by pressing
:wwhilerender-markdown.nvimis installed. Only happens with new files, existing file diffs work fine.I was losing my neovim session every time Claude suggested a new markdown file and I tried to accept it. Very annoying because you lose all your buffers.
Root Cause
After the
BufWriteCmdcallback finishes_resolve_diff_as_saved()and returns, Neovim does a post-write redraw. At this point the buffer is still in diff mode, andrender-markdown.nvimtries to render it during the redraw cycle. For new files (where no old file existed on disk), this combination triggers a segfault.The issue reporter (@tomerlevy1) did excellent debugging with breadcrumb logging and confirmed that all Lua code completes successfully - the crash happens after the callback returns control back to Neovim's C code.
Fix
Added
pcall(vim.cmd, "diffoff")after_resolve_diff_as_saved()but beforereturn truein the BufWriteCmd callback. This explicitly turns off diff mode before Neovim does the post-write redraw, so when render-markdown.nvim runs during redraw the buffer is no longer in diff state.Using
pcallbecause if diffoff fails for whatever reason we still want the callback to complete normally.Testing
Closes #218