helix
helix copied to clipboard
format on save becomes disabled, explicit :fmt breaks code by adding aribtrary newlines
Summary
When editing Rust code, sometimes format-on-save stops happening when I save. Then, when I explicitly call :fmt, arbitrary newlines are added: for example, comment lines may be broken, creating new, syntactically incorrect (and undesired/unintentional) new lines of uncommented code.
Reproduction Steps
Not sure how to reproduce this. In the most recent case, I'd had the editor open for less than an hour, with a single file/buffer, one vertical split, and had been using (c), find next (n), repeat (.), replace (r), and the diagnostic jump list to refactor many similar calls in a way that decreased parenthesization depth on the affected statements, and also tended to shorten those statements enough such that, if format-on-save had been working, they would have gone from multi-line to single line.
Helix log
Looking at the log for this most recent session, there was helix_lsp::transport error followed about 10 minutes later by LOTS of rust-analyzer err: flycheck 0: File with cargo diagnostic not found in VFS: file not found errors. The files listed were from through the project, not just the one I was editing. There were usually half a dozen adjacent such log entries per file. Note the \n at the end of filenames -- don't know if this is an actual incorrect path that's breaking something or just an artifact of how error messages are propagated to the log.
~/.cache/helix/helix.log
2025-06-12T12:35:28.096 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(564)), original request likely timed out
2025-06-12T12:43:08.606 helix_lsp::transport [ERROR] rust-analyzer err <- "2025-06-12T12:43:08.605813439-04:00 ERROR flycheck 0: File with cargo diagnostic not found in VFS: file not found: /path/to/project/file/a.rs\n"
Platform
Debian 12 Bookworm, Linux 6.1.0-37-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22) x86_64 GNU/Linux
Terminal Emulator
tmux 3.3a (installed via apt/Debian repositories) on Gnome Terminal 3.46.8
Installation Method
binary from releases page
Helix Version
helix 25.01.1 (e7ac2fcd)
Update: I am also now having the experience where format-on-save does not become entirely disabled, but the formatting is incorrect and causes syntactic errors (duplicates code, adds newlines, removes code). So far in these cases the changes appear to be limited to the area I was just editing.
I seem to have the same (or similar) bug and created a minimal, reproducible example:
Docker image: https://hub.docker.com/repository/docker/level8broccoli/helix-prettier-next-bug/tags/latest/sha256-a2562f066239f5fad2cec22536d1388ecc700e1b3d367a661bd48865ec304b80 Source: https://github.com/Level8Broccoli/helix-prettier-bug Environment: Docker image "rust", Helix (built from source, 25.01.1 (0043c165)), nodejs (18.19.0), prettier-next (3.6.2)
Steps to reproduce bug:
- run
hx /home/dummy.ts - run
:fmt
Result: Everything below line 2013 gets deleted
For comparison we created a bash script that wraps the formatter (write it first in a temporary file):
- Replace the formatter configuration in
/home/.helix/languages.tomlfrom[...]/prettier-nextto[...]/prettier.sh(both configuration are already in the file) - run
hx /home/dummy.ts - run
:fmt
Result: Formatting works fine, no code gets deleted
Update: I am also now having the experience where format-on-save does not become entirely disabled, but the formatting is incorrect and causes syntactic errors (duplicates code, adds newlines, removes code). So far in these cases the changes appear to be limited to the area I was just editing.
I get this same behaviour specifically with rust-analyzer in Helix, using various versions of rust-analyzer and Helix.
I can prevent the issue by using rustfmt directly, i.e. in languages.toml:
[[language]]
name = "rust"
formatter = { command = "rustfmt" }
Current versions with this issue:
rust-analyzer 2025-07-21
rustc 1.88.0 (6b00bc388 2025-06-23)
rustfmt 1.8.0-stable (6b00bc3880 2025-06-23)
helix 25.07.1 (43990ed0)
I couldn't see any relevant errors or info in the Helix log for this.
I am also able to reproduce this issue and using rustfmt directly also fixes the issue. I don't know the codebase but could this hint at an issue with the built-in Rust formatter functionality?
rust-analyzer 1.89.0 (29483883 2025-08-04)
rustc 1.89.0 (29483883e 2025-08-04)
rustfmt 1.8.0-stable (29483883ee 2025-08-04)
helix 25.07.1 (a05c151b)