auto format
This commit is contained in:
@@ -18,6 +18,7 @@ local mason_lspconfig = require("mason-lspconfig")
|
||||
vim.opt.completeopt = { "menu", "menuone", "noselect", "popup", "fuzzy" }
|
||||
vim.opt.pumheight = 8
|
||||
|
||||
local format_augroup = vim.api.nvim_create_augroup("RomanzyFormatOnSave", { clear = true })
|
||||
local diag_inline_enabled = true
|
||||
|
||||
local function diag_virtual_text()
|
||||
@@ -59,6 +60,26 @@ vim.api.nvim_create_autocmd("LspAttach", {
|
||||
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 managed_servers = {
|
||||
"bashls",
|
||||
|
||||
Reference in New Issue
Block a user