-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: bugCategory: bug
Description
rust-analyzer version: rust-analyzer 1.86.0-nightly (f7cc13a 2025-01-25)
rustc version: rustc 1.86.0-nightly (f7cc13a 2025-01-25)
rustfmt version: rustfmt 1.8.0-nightly (f7cc13a 2025-01-25)
editor or extension: neovim 0.10.4, lspconfig 1.6.0 00dae9f
relevant settings:
-- can skip these first two lines if you have a plugin manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/nvim-lspconfig"
vim.opt.rtp:prepend(lazypath)
local lspconfig = require('lspconfig')
local settings = { ['rust-analyzer'] = { rustfmt = { rangeFormatting = { enable = true } } } }
lspconfig.rust_analyzer.setup {
settings = settings,
-- https://github.com/rust-lang/rust-analyzer/issues/17301
init_options = settings,
on_init = function(client)
-- the real code checks if rustfmt is nightly or not
vim.opt_local.formatexpr = 'v:lua.vim.lsp.formatexpr()'
client.on_attach = function()
vim.opt_local.formatexpr = 'v:lua.vim.lspformatexpr()'
end
end
}
code snippet to reproduce:
fn main() {
let unit_offsets_cache = collect(dwarf.units ()) ?;
}
steps to reproduce:
- verify that formatting with RA is enabled:
set formatexpr?
(should showformatexpr=v:lua.vim.lsp.formatexpr()
) - move your cursor to line 2. run
Vgq
to format the current line. observe that nothing happens. - move your cursor to line 3. run
Vgq
. observe that line 2 is formatted.
I debugged that nvim is sending 0-indexed lines, so maybe RA or rustfmt is expecting 1-indexed lines?
Metadata
Metadata
Assignees
Labels
C-bugCategory: bugCategory: bug