Detect legacy formatters

This commit is contained in:
Sonny Bakker 2025-03-21 09:00:22 +01:00
parent 8b7ad62cff
commit 12297f538e

View file

@ -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,
})