feat(nvim): allow Formatter.nvim to exclude some language servers
Some checks failed
Check Formatting of Files / Check-Formatting (push) Has been cancelled

This commit is contained in:
Price Hiller 2024-03-18 06:16:31 -05:00
parent 2b65013e3d
commit 417c18767d
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB

View File

@ -5,7 +5,22 @@ return {
{ {
"<leader>lf", "<leader>lf",
function() function()
local active_clients = vim.lsp.get_clients({ bufnr = 0, method = "textDocument/formatting" }) local active_clients = vim.iter(
vim.lsp.get_clients({ bufnr = 0, method = "textDocument/formatting" })
)
:filter(function(lsp_client)
-- Exclude some language server formatters.
--
-- I chose not to override the `textDocument/formatting` handler because
-- it felt kinda hacky and some language servers don't play nice with
-- changing their handlers. Figured this was easier.
if lsp_client.config and lsp_client.config.name then
return not vim.list_contains({
"lua_ls",
}, lsp_client.config.name)
end
return true
end)
if #active_clients > 0 then if #active_clients > 0 then
vim.lsp.buf.format({ async = true }) vim.lsp.buf.format({ async = true })
else else