You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in lua/conform/formatters/init.lua's M.format() function, the below statement is not logically very correct.
local formatter_names = opts.formatters or M.list_formatters_for_buffer(opts.bufnr)
Because, when opts.formatters = {}, then even if M.list_formatters_for_buffer(opts.bufnr) has value, which is totally correct and useful (when you configured formatters_by_ft = {lua = { "stylua" }, it will not be applied. this will cause formatter_names to be {} and thus all the later formatters be {}. but obviously you have the formatter stylua available.
Therefore, I think you should merge opts.formatters and M.list_formatters_for_buffer(opts.bufnr) instead of pick only one of them.
or at least, test if opts.formatters is empty, then use M.list_formatters_for_buffer(opts.bufnr) otherwise. like below:
local formatter_names = is_empty(opts.formatters) or M.list_formatters_for_buffer(opts.bufnr)
Warn on missing
also in lua/conform/init.lua, the warn message (3rd arg) is hardcodet to false (M.resolve_formatters(formatters, bufnr, false, false)`, this will mute errors when an incorrect formatter is configured. this setting may be improved.
M.list_formatters = function(bufnr)
if not bufnr or bufnr == 0 then
bufnr = vim.api.nvim_get_current_buf()
end
local formatters = M.list_formatters_for_buffer(bufnr)
return M.resolve_formatters(formatters, bufnr, hardcoded_false, false)
end
The text was updated successfully, but these errors were encountered:
These are both intentional. There is no fancy merging logic for the formatters parameter because I want the behavior of format() to be very easy to understand when you pass in explicit arguments. If the built-in mechanisms of setting formatters_by_ft cover your use case, great. If not, then it's up to you to decide what formatters to run and when, and to pass them into the function.
We do not warn on missing formatters in list_formatters because that function is designed to be used for purposes like a statusline, where spamming notifications is not desired. If you want to find missing formatters programmatically, you can use list_all_formatters or get_formatter_info
Neovim version (nvim -v)
NVIM v0.11.0
Operating system/version
MacOS 15.1.1
Describe the bug
in
lua/conform/formatters/init.lua
's M.format() function, the below statement is not logically very correct.Because, when
opts.formatters = {}
, then even ifM.list_formatters_for_buffer(opts.bufnr)
has value, which is totally correct and useful (when you configuredformatters_by_ft = {lua = { "stylua" }
, it will not be applied. this will causeformatter_names
to be{}
and thus all the later formatters be {}. but obviously you have the formatterstylua
available.Therefore, I think you should merge
opts.formatters
andM.list_formatters_for_buffer(opts.bufnr)
instead of pick only one of them.or at least, test if
opts.formatters
is empty, then useM.list_formatters_for_buffer(opts.bufnr)
otherwise. like below:Warn on missing
also in
lua/conform/init.lua
, the warn message (3rd arg) is hardcodet to false (M.resolve_formatters(formatters, bufnr, false, false)`, this will mute errors when an incorrect formatter is configured. this setting may be improved.The text was updated successfully, but these errors were encountered: