Skip to content

Commit 32f0901

Browse files
Vzaatjdevries
authored andcommitted
Don't pass args to vim.lsp.buf.format/formatting
Args passed by nvim_buf_create_user_command to the callback creates errors with rust-analyzer on nvim 0.7.x and vim.lsp.buf.formatting.
1 parent f2dedf6 commit 32f0901

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

init.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,13 @@ local on_attach = function(_, bufnr)
289289
end, '[W]orkspace [L]ist Folders')
290290

291291
-- Create a command `:Format` local to the LSP buffer
292-
vim.api.nvim_buf_create_user_command(bufnr, 'Format', vim.lsp.buf.format or vim.lsp.buf.formatting, { desc = 'Format current buffer with LSP' })
292+
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
293+
if vim.lsp.buf.format then
294+
vim.lsp.buf.format()
295+
elseif vim.lsp.buf.formatting then
296+
vim.lsp.buf.formatting()
297+
end
298+
end, { desc = 'Format current buffer with LSP' })
293299
end
294300

295301
-- nvim-cmp supports additional completion capabilities

0 commit comments

Comments
 (0)