Add autoformating on save for rust

This commit is contained in:
Martin Larsson 2024-04-08 10:55:39 +02:00
parent 4b66d3bbcb
commit a0167322fc

View file

@ -13,8 +13,18 @@ return {
}, },
}, },
server = { server = {
on_attach = function(_, bufnr) on_attach = function(client, bufnr)
vim.lsp.inlay_hint.enable(bufnr, true) vim.lsp.inlay_hint.enable(bufnr, true)
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 })
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
vim.lsp.buf.format()
end,
})
end
end, end,
} }
} }