setup format on save

This commit is contained in:
sloane 2024-08-30 16:25:15 -04:00
parent ecf482a2c6
commit 2f2cafbc71
Signed by: sloanelybutsurely
SSH key fingerprint: SHA256:8SBnwhl+RY3oEyQxy1a9wByPzxWM0x+/Ejc+sIlY5qQ

View file

@ -13,8 +13,21 @@ return {
config = function () config = function ()
local lsp_zero = require('lsp-zero') local lsp_zero = require('lsp-zero')
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
local function lsp_format_on_save(bufnr)
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
local lsp_attach = function (client, bufnr) local lsp_attach = function (client, bufnr)
lsp_zero.default_keymaps({ buffer = bufnr, preserve_mappings = false }) lsp_zero.default_keymaps({ buffer = bufnr, preserve_mappings = false })
lsp_format_on_save(bufnr)
end end
lsp_zero.extend_lspconfig({ lsp_zero.extend_lspconfig({