@@ -402,7 +402,7 @@ local has_notified_ft_no_formatters = {}
402402--- -- Asynchronously format the current buffer; will not block the UI
403403--- conform.format({ async = true }, function(err, did_edit)
404404--- -- called after formatting
405- --- end
405+ --- end)
406406--- -- Format the current buffer with a specific formatter
407407--- conform.format({ formatters = { "ruff_fix" } })
408408M .format = function (opts , callback )
700700--- @param formatter string
701701--- @param bufnr ? integer
702702--- @return nil | conform.FormatterConfig
703+ --- @return nil | string error_msg
703704M .get_formatter_config = function (formatter , bufnr )
704705 if not bufnr or bufnr == 0 then
705706 bufnr = vim .api .nvim_get_current_buf ()
@@ -710,32 +711,41 @@ M.get_formatter_config = function(formatter, bufnr)
710711 override = override (bufnr )
711712 end
712713 if override and override .command and override .format then
713- local msg =
714- string.format (" Formatter '%s' cannot define both 'command' and 'format' function" , formatter )
715- notify_once (msg , vim .log .levels .ERROR )
716- return nil
714+ return nil , " Cannot define both 'command' and 'format' function"
717715 end
718716
719717 --- @type nil | conform.FormatterConfig
720- local config = override
721- if not override or override .inherit ~= false then
722- local ok , mod_config = pcall (require , " conform.formatters." .. formatter )
718+ local config
719+ local inherit = (override or {}).inherit
720+ if inherit == nil then
721+ inherit = true
722+ end
723+ if inherit then
724+ local parent_formatter_name = formatter
725+ if type (inherit ) == " string" then
726+ parent_formatter_name = inherit
727+ end
728+ local ok , mod_config = pcall (require , " conform.formatters." .. parent_formatter_name )
723729 if ok then
724730 if override then
725731 config = require (" conform.util" ).merge_formatter_configs (mod_config , override )
726732 else
727733 config = mod_config
728734 end
729735 elseif override then
730- if override .command or override .format then
736+ if override .inherit then
737+ -- We attempted to explicitly inherit, but the `require` failed
738+ return nil ,
739+ string.format (
740+ " Attempting to inherit from non-existent built-in formatter '%s'" ,
741+ parent_formatter_name
742+ )
743+ elseif override .command or override .format then
744+ -- No built-in formatter to inherit from, but this is a complete definition
731745 config = override
732746 else
733- local msg = string.format (
734- " Formatter '%s' missing built-in definition\n Set `command` to get rid of this error." ,
735- formatter
736- )
737- notify_once (msg , vim .log .levels .ERROR )
738- return nil
747+ -- No built-in formatter to inherit from, and this is missing a `command` or `format` function
748+ return nil , " Missing built-in definition. Set `command` to get rid of this error."
739749 end
740750 else
741751 return nil
@@ -756,13 +766,14 @@ M.get_formatter_info = function(formatter, bufnr)
756766 if not bufnr or bufnr == 0 then
757767 bufnr = vim .api .nvim_get_current_buf ()
758768 end
759- local config = M .get_formatter_config (formatter , bufnr )
769+ local config , missing_config_err = M .get_formatter_config (formatter , bufnr )
760770 if not config then
761771 return {
762772 name = formatter ,
763773 command = formatter ,
764774 available = false ,
765- available_msg = " Unknown formatter. Formatter config missing or incomplete" ,
775+ available_msg = missing_config_err
776+ or " Unknown formatter. Formatter config missing or incomplete" ,
766777 error = true ,
767778 }
768779 end
0 commit comments