Skip to content

Fix formatting edits for CRLF files and files without trailing newline - #311

Merged
mattn merged 1 commit into
masterfrom
fix-format-edit-ranges
Jul 8, 2026
Merged

Fix formatting edits for CRLF files and files without trailing newline#311
mattn merged 1 commit into
masterfrom
fix-format-edit-ranges

Conversation

@mattn

@mattn mattn commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Two formatting bugs around line endings:

  • Formatter output had all \r stripped but was then diffed against the original CRLF text, so on CRLF files every line appeared changed and even a no-op format produced whole-file edits with mixed line endings. Restore CRLF in the output before diffing when the original uses it.
  • When the document does not end with a newline, ComputeEdits emitted ranges referencing the nonexistent line past the end; clients clamp such out-of-spec positions inconsistently, producing the stray blank lines reported in Unexpected newline at the end of file when formatting it #241/Erroneous newlines using efm in neovim #181. Clamp those positions to the end of the last line.

Adds tests that verify the produced edits apply cleanly. Fixes #241. Fixes #181.

@mattn
mattn merged commit 13de040 into master Jul 8, 2026
6 checks passed
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.

Unexpected newline at the end of file when formatting it Erroneous newlines using efm in neovim

1 participant