33 lines
797 B
Lua
33 lines
797 B
Lua
-- example of a project specific nvim configuration file using :exrc and lsp formatting
|
|
|
|
local format_clients = {
|
|
'ruff',
|
|
'lua_ls',
|
|
'bashls',
|
|
'jsonls',
|
|
'ts_ls',
|
|
'ansiblels',
|
|
'yamlls',
|
|
'cssls',
|
|
'html',
|
|
}
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('lsp', { clear = true }),
|
|
callback = function(args)
|
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
|
|
if client:supports_method('textDocument/formatting')
|
|
and vim.tbl_contains(format_clients, client.name) then
|
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
|
buffer = args.buf,
|
|
callback = function()
|
|
vim.lsp.buf.format {
|
|
async = false,
|
|
id = args.data.client_id
|
|
}
|
|
end,
|
|
})
|
|
end
|
|
end
|
|
})
|