Auto format on save
This commit is contained in:
parent
0a18490729
commit
04fdd708b2
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user