Auto format on save

This commit is contained in:
Dreaded_X 2023-04-10 02:08:00 +02:00
parent 0a18490729
commit 04fdd708b2
Signed by: Dreaded_X
GPG Key ID: FA5F485356B0D2D4

View File

@ -404,6 +404,19 @@ local on_attach = function(client, bufnr)
vim.lsp.buf.format() vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' }) end, { desc = 'Format current buffer with LSP' })
-- Format on save
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format()
end,
})
end
-- Attach document colour support -- Attach document colour support
if client.server_capabilities.colorProvider then if client.server_capabilities.colorProvider then
require("document-color").buf_attach(bufnr) require("document-color").buf_attach(bufnr)