conform.nvim icon indicating copy to clipboard operation
conform.nvim copied to clipboard

feature request: add a flag similar to `stop_after_first` but instead it tries formatters in sequence until one succeeds

Open koshell opened this issue 5 months ago • 0 comments
trafficstars

Did you check existing requests?

  • [x] I have searched the existing issues

Describe the feature

My understanding is stop_after_first = true means the conform.nvim will sequentially search through the list of formatters, executing the first one it finds and not searching any further.

I would propose a flag like stop_after_success which would make conform.nvim try each formatter one by one until one returned success then stop.

For simplicity sake I would assume stop_after_first = true is assumed when stop_after_success = true but that's just my preference.

Provide background

I primarily code in rust, making heavy use of rustfmt. Personally I like a lot of the nightly rustfmt features so I often run something akin to rustfmt +nightly.

However due to the nature of using a nightly release sometimes it fails to handle things that the stable version could, in my experience running stable rustfmt if nightly fails formats the document well enough that nightly can succeed afterwards.

Ideally I would want to be able to configure conform.nvim to run rustfmt +nightly then if that fails run rustfmt and only report an error if both fail.

What is the significance of this feature?

strongly desired

Additional details

I imagined this as a flag similar to stop_after_first since I assume the machinery to handle such flags already exists.

Alternatively allowing some kind of fallback field in the formatter config would also work, something like:

---@type conform.setupOpts
local opts = {
  ...
  formatters = {
    rustfmt_nightly = {
      ...
      ---@type nil
      ---| string # name of another formatter to try when this formatter fails
      ---| conform.FormatterConfigOverride # fallback config to try for the current formatter
      ---| (string|conform.FormatterConfigOverride)[] # multiple fallbacks to try in order
      fallback = "rustfmt",
      ...
    },
  },
  ...
}

koshell avatar May 31 '25 02:05 koshell