auto format

This commit is contained in:
2026-06-29 22:39:09 +02:00
parent 02721b097e
commit 453e599a57

View File

@@ -18,6 +18,7 @@ local mason_lspconfig = require("mason-lspconfig")
vim.opt.completeopt = { "menu", "menuone", "noselect", "popup", "fuzzy" } vim.opt.completeopt = { "menu", "menuone", "noselect", "popup", "fuzzy" }
vim.opt.pumheight = 8 vim.opt.pumheight = 8
local format_augroup = vim.api.nvim_create_augroup("RomanzyFormatOnSave", { clear = true })
local diag_inline_enabled = true local diag_inline_enabled = true
local function diag_virtual_text() local function diag_virtual_text()
@@ -59,6 +60,26 @@ vim.api.nvim_create_autocmd("LspAttach", {
end, end,
}) })
vim.api.nvim_create_autocmd("BufWritePre", {
group = format_augroup,
callback = function(ev)
local bufnr = ev.buf
if not vim.bo[bufnr].modifiable or vim.bo[bufnr].buftype ~= "" then
return
end
vim.lsp.buf.format({
bufnr = bufnr,
async = false,
timeout_ms = 2000,
filter = function(client)
return client.supports_method("textDocument/formatting")
end,
})
end,
})
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
local managed_servers = { local managed_servers = {
"bashls", "bashls",