Skip to content

Conversation

@xulongwu4
Copy link
Contributor

@xulongwu4 xulongwu4 commented Dec 24, 2025

The options for formatexpr is different than those used in conform.format(). This discrepancy causes issues when one sets up filetype-specific values for lsp_format or timeout_ms. For example, I use the following values for formatters_by_ft:

formatters_by_ft = {["_"] = { "trim_newlines", "trim_whitespace", lsp_format = "prefer" }}

I also format buffers on save.

Now when I edit a .C file and run wq, clangd kicks in as I set lsp_format = "prefer". The file is formatted by clangd and saved correctly. Everything is good.

Now if I try to use gq, the format is performed by trim_newlines and trim_whitespace, because the default values for lsp_format in formatexpr is fallback. This inconsistency causes confusion when using conform. See also #824 #408 #752

This PR resolves this issue so that formatexpr will respect options used by formatters_by_ft.

Copilot AI review requested due to automatic review settings December 24, 2025 05:32
@github-actions github-actions bot requested a review from stevearc December 24, 2025 05:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes formatexpr use the same option defaults as conform.format() by removing the hardcoded timeout_ms = 500 and lsp_format = "fallback" values. This allows formatexpr to respect filetype-specific options configured in formatters_by_ft and default_format_opts, resolving inconsistencies where gq formatting would use different settings than format-on-save.

Key changes:

  • Removed hardcoded timeout_ms and lsp_format defaults from formatexpr function
  • formatexpr now inherits options from formatters_by_ft configuration, default_format_opts, and finally the hardcoded defaults in conform.format()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@stevearc
Copy link
Owner

Hmmm...yes I think that behavior predates the default_format_opts and some of the other methods of configuring formatting options by filetype. Doesn't really make sense to override those values anymore. Thanks for the PR!

@stevearc stevearc merged commit df83eea into stevearc:master Dec 30, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants