Enable formatting on save
Requires `ENABLE_FORMATTING` to be set
This commit is contained in:
parent
eb14a601fb
commit
5aa08aef39
1 changed files with 25 additions and 0 deletions
|
|
@ -156,3 +156,28 @@ vim.diagnostic.config({
|
||||||
border = border
|
border = border
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local enable_formatting = os.getenv("ENABLE_FORMATTING", False)
|
||||||
|
|
||||||
|
-- format buffers before saving for specific LSPs
|
||||||
|
if (enable_formatting) then
|
||||||
|
local excluded_clients = { 'pyright' }
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
|
group = vim.api.nvim_create_augroup('lsp', { clear = true }),
|
||||||
|
callback = function(args)
|
||||||
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||||
|
buffer = args.buf,
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.format {
|
||||||
|
filter = function(client)
|
||||||
|
return not vim.list_contains(excluded_clients, client.name)
|
||||||
|
end,
|
||||||
|
async = false,
|
||||||
|
id = args.data.client_id
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue