Conversation
An insert at the end of the buffer produced a zero-width edit with empty newText, relying on vim.lsp.util.apply_text_edits adding the line anyway. Neovim 0.12 no longer does, which is correct: that edit is a no-op. The result is that a trailing blank line from a formatter is silently dropped. Anchor the edit to the end of the last line and lead with the newline instead. Same edit on every supported Neovim version.
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.
Fixes #891. Root cause writeup is in this comment, short version below.
When the diff wants to insert at the end of the buffer,
create_text_editfell into the branch that skips appending the newline, on the grounds that it is implicit at EOF. That leaves a zero-width range with emptynewText, which is a no-op. It happened to work because the oldvim.lsp.util.apply_text_editsadded the line anyway. Neovim 0.12 no longer does, and I think 0.12 is right there.The visible effect is not limited to the tests: a formatter whose output ends with an extra blank line has that line silently dropped on 0.12.
This anchors the edit to the end of the last line and leads with the newline, so the same edit is produced on every supported version:
On master
./run_tests.shfails two tests for me on 0.12.5,runner e2e sets the correct outputandfuzzer formats correctly. With this patch the whole suite passes, 65 tests, no failures. I did not add a test since the existing cases already cover it, including the multi-line variants likerun_formatter_test("hello", "hello\n\n").Checked the resulting buffer on both 0.11.7 and 0.12.5 with the same formatter output, and both now end up with
{"hello", ""}.stylua --checkis clean.If you would rather shape the fix differently, say so and I will rework it.