From 417c18767d318ecc3d7803ffe71bcf0db6c5a7db Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Mon, 18 Mar 2024 06:16:31 -0500 Subject: [PATCH] feat(nvim): allow `Formatter.nvim` to exclude some language servers --- .../nvim/lua/plugins/configs/formatter.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dots/.config/nvim/lua/plugins/configs/formatter.lua b/dots/.config/nvim/lua/plugins/configs/formatter.lua index 36147e15..07703113 100644 --- a/dots/.config/nvim/lua/plugins/configs/formatter.lua +++ b/dots/.config/nvim/lua/plugins/configs/formatter.lua @@ -5,7 +5,22 @@ return { { "lf", 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 vim.lsp.buf.format({ async = true }) else