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

feature request: prefer ["_"] over lsp fallback #609

Closed
1 task done
blyedev opened this issue Dec 27, 2024 · 2 comments
Closed
1 task done

feature request: prefer ["_"] over lsp fallback #609

blyedev opened this issue Dec 27, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@blyedev
Copy link

blyedev commented Dec 27, 2024

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

Prefer ["_"] filetype over lsp format.

Provide background

I want to configure prettier so it's the default formatter for everything unless a different formatter was configured. If prettier does not format a file I would like the lsp to.

Currently the lsp is preffered over the ["_"] filetype which i would consider to be counterintuitive.

What is the significance of this feature?

nice to have

Additional details

Obviously I could just configure prettier for every file but that feels pretty annoying and verbose for the config

@blyedev blyedev added the enhancement New feature or request label Dec 27, 2024
@stevearc
Copy link
Owner

stevearc commented Jan 3, 2025

If prettier does not format a file I would like the lsp to.

I assume that by this you mean that you want to attempt to run prettier and, if it does not format the file, fall back to LSP. Conform doesn't do this kind of logic because it would require parsing errors from the formatters to determine if they failed because the file isn't supported or for some other reason. Better to just let the user configure the formatters they want for the filetypes they want.

If the current syntax doesn't support exactly what you need, I recommend writing your own function to define what formatters to use. You can do that on a per-filetype basis like we do in this example, or you can do it for all filetypes by defining a custom format-on-save function like we do here. In any case, you have to decide which formatters to use ahead of time. The fallback behavior is only for situations where a formatter is not installed, or the LSP is not available, or a formatter has a condition that returns false.

@stevearc stevearc closed this as completed Jan 3, 2025
@blyedev
Copy link
Author

blyedev commented Jan 3, 2025

I now realize I forgot to add the context as to why I was using ["_"] mistakenly assuming it self-explanatory.

I wanted prettier to run only if nothing else was configured and only then fall back to the lsp if prettier fails.

Nonetheless the suggestion you provided answers my question either way. Thank you for your support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants