Replace formatting code
This commit is contained in:
parent
7f3dd527af
commit
747a1fe584
1 changed files with 14 additions and 31 deletions
|
|
@ -176,7 +176,7 @@ vim.diagnostic.config {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local enable_formatting = os.getenv("ENABLE_FORMATTING")
|
local enable_formatting = os.getenv("enable_formatting") == 'true';
|
||||||
|
|
||||||
-- format buffers before saving for specific LSPs
|
-- format buffers before saving for specific LSPs
|
||||||
if (enable_formatting) then
|
if (enable_formatting) then
|
||||||
|
|
@ -185,38 +185,21 @@ if (enable_formatting) then
|
||||||
vim.api.nvim_create_autocmd('LspAttach', {
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
group = vim.api.nvim_create_augroup('lsp', { clear = true }),
|
group = vim.api.nvim_create_augroup('lsp', { clear = true }),
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
buffer = args.buf,
|
|
||||||
callback = function()
|
|
||||||
local formatting_clients = vim.lsp.get_clients {
|
|
||||||
bufnr = args.buf,
|
|
||||||
method = 'textDocument/formatting'
|
|
||||||
}
|
|
||||||
|
|
||||||
local filtered_clients = {}
|
if vim.list_contains(excluded_clients, client.name) then return end;
|
||||||
|
|
||||||
for _, client in pairs(formatting_clients) do
|
if client.server_capabilities.documentFormattingProvider then
|
||||||
if vim.list_contains(excluded_clients, client.name) then
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||||
goto skip
|
buffer = args.buf,
|
||||||
end
|
callback = function()
|
||||||
|
vim.lsp.buf.format {
|
||||||
table.insert(filtered_clients, client.name)
|
async = false,
|
||||||
::skip::
|
id = args.data.client_id
|
||||||
end
|
}
|
||||||
|
end,
|
||||||
if #filtered_clients == 0 then
|
})
|
||||||
return
|
end
|
||||||
end
|
|
||||||
|
|
||||||
vim.lsp.buf.format {
|
|
||||||
filter = function(client)
|
|
||||||
return vim.list_contains(filtered_clients, client.name)
|
|
||||||
end,
|
|
||||||
async = false,
|
|
||||||
id = args.data.client_id
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue