stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
2.55k stars 135 forks source link

fix: avoid returning a filetype if its formatter array is empty #463

Closed Frederick888 closed 2 weeks ago

Frederick888 commented 2 weeks ago

When using the below configuration

{
    format = { lsp_fallback = true, lsp_format = 'fallback' },  // old and new
    formatters = { injected = { options = { ignore_errors = true } }, },
    formatters_by_ft = { lua = {} },  // to override the default LazyVim setting [1]
}

Previously when explicit_formatters [2] was true, it relied on lsp_fallback and lsp_format.get_format_clients() [3], so LSP formatters were called normally.

However now in has_filetype_formatters(), it relies on get_matching_filetype() directly, hence revealing this issue.

[1] https://github.com/LazyVim/LazyVim/blob/8a89c0360e4a076b99b09fe673fbd947f71577fc/lua/lazyvim/plugins/formatting.lua#L73 [2] https://github.com/stevearc/conform.nvim/commit/9228b2ff4efd58b6e081defec643bf887ebadff6#diff-04c07f595c94cd9a5acd85c268fac3d332438f3f9658740ab348e99bb82db631L354 [3] https://github.com/stevearc/conform.nvim/commit/9228b2ff4efd58b6e081defec643bf887ebadff6#diff-04c07f595c94cd9a5acd85c268fac3d332438f3f9658740ab348e99bb82db631L411

Frederick888 commented 2 weeks ago

Nah this isn't right... LazyVim doesn't pass formatters to conform.nvim in its <leader>cf keymap callback. #462 fixed the issue for me too.