Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make lsp_fallback behavior more intuitive #59

Merged
merged 1 commit into from
Sep 17, 2023

Conversation

stevearc
Copy link
Owner

@stevearc stevearc commented Sep 17, 2023

Following up on #31, #33

I wasn't completely happy with the earlier solution. If you want to run { "trim_whitespace" } on all filetypes but still use LSP formatting, you would have to pass lsp_fallback = "always". But if you didn't want LSP formatting on filetypes where you have formatters configured, you would have to write a helper function to do some detection of the filetype and determine if you want to pass in true or "always" (#36). I think that the common case for formatting is:

  • Configure specific formatters to use for some filetypes, don't use LSP
  • For non-configured filetypes, default to using LSP formatting
  • If no LSP formatting is available, maybe use some generic formatters (e.g. trim_whitespace)

I would like to optimize for this common case. This PR makes it so that if you pass lsp_fallback = true, conform will prefer the LSP formatter over formatters configured with the "*" or "_" filetypes.

There are still some scenarios that will require helper functions or explicitly passing formatters, but hopefully fewer.

When lsp_fallback = true AND the only formatters for the buffer are from
the "*" or "_" filetype, format with LSP instead of the "*"/"_"
formatters.
@stevearc stevearc merged commit 1abbb82 into master Sep 17, 2023
7 checks passed
@stevearc stevearc deleted the stevearc-lsp-fallback branch September 17, 2023 17:02
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.

1 participant