rust-analyzer: Invalid offset -32603 when editing an empty .rs file
rust-analyzer version: 2024-05-09
rustc version: (eg. output of rustc -V): 1.78.0
editor or extension: neovim with Mason+Lspconfig+RustAnalyzer
relevant settings: none
repository link (if public, optional): none
code snippet to reproduce:
Rust analyzer is printing this error if I start editing an empty .rs file before it has completed its startup. There are no settings involved, just an empty cargo project with a main.rs. Once that error pops up, it will keep appearing on every keystroke until I close the buffer, reopen it, wait for it to fully initialize and then start writing. This does not happen if the file is not empty.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 57
- Comments: 57 (11 by maintainers)
Links to this issue
Commits related to this issue
- Auto merge of #17347 - Veykril:inv-offset-err, r=Veykril minor: Add debug info to invalid offset error cc https://github.com/rust-lang/rust-analyzer/issues/17289 — committed to rust-lang/rust-analyzer by bors 2 years ago
- Auto merge of #17347 - Veykril:inv-offset-err, r=Veykril minor: Add debug info to invalid offset error cc https://github.com/rust-lang/rust-analyzer/issues/17289 — committed to lnicola/rust by bors 2 years ago
It’s still not fixed.
I am still have this error even though I have the most recent version of rust-analyzer installed via rustup and NVIM is picking it up.
I do NOT have rust-analyzer installed via Mason:
However, when saving a file I still get these errors (disregard the circles I drew, they’re not related to this issue)
@lnicola @Veykril Is there any update on this? It’s quite hard to use rust-analyzer with Neovim as it currently is.
Potential Fix
Mason downloads
rust-analyzerversion 0.35 on my system, while rustup downloads version 1.80. This is most likely an issue with Mason specifically and not Neovim, as using the updated binary fixes the issue on my end. YMMV as always, but given that’s a massively out of date binary, I imagine it’s a compatibility issue with the oldrust-analyzerbinary and newer LSP protocols.Check Mason’s
rust-analyzerversionIf this is an older version, proceed with the following:
Download the newest
rust-analyzerversion viarustupThis will download the newest version, which can be found in
~/.cargo/bin/rust-analyzer. Now remove the one Mason downloaded at~/.local/share/nvim/mason/bin/rust-analyzervia anrmcall as follows, then create a symlink to the new one from rustup:Create symlink to
rustupversionThis will likely need to be repeated if you update
rust-analyzerthrough Mason. Consider creating a shell script with the second snippet to run in case of update.In the case that this resolves the issue for everyone, this is not an issue for this repo, but williamboman/mason.nvim.
This issue still persists in v0.10.4:
https://github.com/rust-lang/rust-analyzer/pull/17742 fixed the remaining issue. For other requests, rust-analyzer has been correctly reporting errors due to invalid offset as “content modified” error, which is ignored by the client UI. However, inlay hint handler in the versions prior to #17742 reported it as an internal error (which is shown to the user) because inlay hint request was marked as retry-able. #17742 fixes this by marking it as not retry-able.
I installed rust-analyzer using Mason (Rust itself is installed using Rustup but not rust-analyzer).
BTW this error seems to happen in other times than just editing an empty file. It happens to me once in a while when coding in Neovim, which is a real bummer as I have to reopen Neovim and lose the state of my project (doing LspRestart doesn’t solve this… I must reopen Neovim to fix it).
Can confirm I get this error on both vscode and neovim, I have tried installing rust-analyzer both from mason and rustup but it does not solve the issue.
I experienced the same issue with neovim. They have a fix for it in nightly.
The issue has been fixed for me in the nightly neovim release.
I’m still having this issue on v0.10.3:
I found a temporary solution to it:
I am using
noice.nvim, so I hide this message through configuration:notify can use override
vim.lsp.handlersto hidden it.I also do experience this issue, using Rust edition 2024 and nightly rust-analyzer seem to occur more frequently for me.
It seems that both neovim and rust-analyzer have some issues. Here is what I found, but I wouldn’t have enough time to investigate further.
environment
ubuntu 22.04
cargo new bug. This createssrc/main.rswith the follwoing content in the new workspaceapply the following patch to rust-analyzer (3cf17dcfc)
patch
nvim 0.11 dev version, with rustaceanvim configured to use the patched rust-analyzer
reproduction step: open main.rs, wait until indexing and etc finishes, then
ggdG.Then you will get something like this in nvim’s lsp log file
messages
This issue can be fixed with the following patch to nvim.
(Or alternatively, rust-analyzer could be modified to gracefully handle the last line eol.)
update: the following is invalid. see https://github.com/rust-lang/rust-analyzer/issues/17289#issuecomment-2255637976
outdated
Now repeat the same repro steps. Then you will get a similar error with slightly different contents:
messages
What happens here is that
ggdG, and the change is sent via didChangeThis is odd because rust-analyzer is using some form of snapshot for global state, which would prevent such issues. So it seems either
I have the same error with latest stable neovim, mason, and rust-analyzer. $ cargo new helloworld, $ edit the src/main.rs and start deleting all lines, and it will start getting into a error flooding these errors and making it hard to navigate in nvim.
Is there any work around / fix to this issue?
I had the same issue today using Mason+Lspconfig+RustAnalyzer as installed by Mason. I tried
rust-analyzer -Vin the terminal and the output waserror: Unknown binary 'rust-analyzer' in official toolchain 'stable-x86_64-apple-darwin'.I’m not sure what the root cause of this error is, but following this Stack Overflow link, I tried
I no longer had the terminal
Unknown binaryerror or the bufferInvalid offseterror in neovim. Could be some Mason issue.not fixed on linux with neovim@0.12-dev and rust-analyzer@2025-06-14
I have the same issue, would be nice to have a fix for this pushed
I have no knowledge about neovim/mason, so I’d recommend someone who has the problem in here to open an issue regarding that for them (as I don’t believe anyone here has done so yet).
Right there shouldn’t be any backtraces, this is not a panic but a general error being bubbled up back to the client.
It has to be, otherwise we’d observe this in other clients as well. Might be good to see if an older neovim doesn’t have this problem