Apply lsp client filtering before filter callback
This commit is contained in:
parent
0f0a5e592b
commit
f7eb8dc56d
1 changed files with 22 additions and 3 deletions
|
|
@ -176,7 +176,7 @@ vim.diagnostic.config {
|
|||
},
|
||||
}
|
||||
|
||||
local enable_formatting = os.getenv("ENABLE_FORMATTING", False)
|
||||
local enable_formatting = os.getenv("ENABLE_FORMATTING")
|
||||
|
||||
-- format buffers before saving for specific LSPs
|
||||
if (enable_formatting) then
|
||||
|
|
@ -188,10 +188,29 @@ if (enable_formatting) then
|
|||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
buffer = args.buf,
|
||||
callback = function()
|
||||
local formatting_clients = vim.lsp.get_clients {
|
||||
bufnr = args.buf,
|
||||
method = 'textDocument/formatting'
|
||||
}
|
||||
|
||||
local filtered_clients = {}
|
||||
|
||||
for _, client in pairs(formatting_clients) do
|
||||
if vim.list_contains(excluded_clients, client.name) then
|
||||
goto skip
|
||||
end
|
||||
|
||||
table.insert(filtered_clients, client.name)
|
||||
::skip::
|
||||
end
|
||||
|
||||
if #filtered_clients == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
vim.lsp.buf.format {
|
||||
filter = function(client)
|
||||
if not client.supports_method('textDocument/formatting') then return end
|
||||
return not vim.list_contains(excluded_clients, client.name)
|
||||
return vim.list_contains(filtered_clients, client.name)
|
||||
end,
|
||||
async = false,
|
||||
id = args.data.client_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue