From 12297f538e556bb312a270439b1204d65bac156b Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Fri, 21 Mar 2025 09:00:22 +0100 Subject: [PATCH] Detect legacy formatters --- templates/nvim/lua/formatting.lua.j2 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/templates/nvim/lua/formatting.lua.j2 b/templates/nvim/lua/formatting.lua.j2 index 10c6332..36a4279 100644 --- a/templates/nvim/lua/formatting.lua.j2 +++ b/templates/nvim/lua/formatting.lua.j2 @@ -1,6 +1,18 @@ -- {{ ansible_managed }} local enable_formatting = vim.env.enable_formatting == 'true'; +local legacy_formatting = nil; + +-- TODO: move to utils file +-- TODO: add efm-languageserver to lsp.lua +if vim.env.VIRTUAL_ENV ~= nil and enable_formatting == true then + local formatters = vim.fs.find( + { 'isort', 'black' }, + { limit = 1, type = 'file', path = vim.fs.joinpath(vim.env.VIRTUAL_ENV, 'bin') } + ) + + legacy_formatting = #formatters > 0; +end if (enable_formatting) then vim.api.nvim_create_autocmd('LspAttach', { @@ -14,7 +26,10 @@ if (enable_formatting) then callback = function() vim.lsp.buf.format { async = false, - id = args.data.client_id + id = args.data.client_id, + filter = function(format_client) + return format_client.name ~= 'ruff' or not legacy_formatting + end } end, })