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

Remove formatting provider #933

Open
remcohaszing opened this issue Oct 27, 2023 · 6 comments
Open

Remove formatting provider #933

remcohaszing opened this issue Oct 27, 2023 · 6 comments

Comments

@remcohaszing
Copy link
Contributor

Is your enhancement related to a problem? Please describe.

yaml-language-server supports formatting YAML files. Under the hood this delegates the formatting to Pretttier. However, this integration is very limited. It doesn’t support Prettier options or a Prettier configuration file.

Additionally, the dependency on Prettier is huge. This isn’t great when yaml-language-server is used as part of a web bundle.

Describe the solution you would like

Remove the formatting provider entirely. Maybe recommend Prettier and their official VS Code extension instead in the readme.

Describe alternatives you have considered

Keep the formatting provider and close this issue.

Additional context

@gorkem
Copy link
Collaborator

gorkem commented Nov 6, 2023

I am not against the idea. There is a lot of users who are not happy with the prettier based formatter. My concern is the silent crowd who are happy with it. If we can devise a plan that will allow them to replace the function they depend on easily that would be ideal.

@remcohaszing
Copy link
Contributor Author

I mostly reported this, because I’ve seen other users complain here as well as in relation to monaco-yaml.

Prettier has an Editor Integration page which lists several editor integrations.

Unfortunately there’s no Prettier language server (that I know of).

For Monaco editor I would be willing to create a Prettier integration if there’s user demand.

It’s also possible for yaml-language-server to provide a formatter based on YAML.stringify instead. That would mean formatting is still possible, but the formatted output will be different.

@znd4
Copy link
Contributor

znd4 commented Nov 8, 2023

I really like using prettier for yaml formatting, but it needs to respect .editorconfig / .prettierrc.

This can be set up with prettierd for most usecases, but it would be preferable for yaml-language-server to support formatting.

A way to "make everyone happy" would be to break out prettier support as a plugin, so that users can choose which formatting provider yaml-language-server invokes (or to choose none and have a minimal yaml-language-server installation)

That being said, it seems like a decent chunk of work, and I'm currently disabling yaml-language-server's formatting, so I wouldn't be upset about a decision to remove it completely

@remcohaszing
Copy link
Contributor Author

I also like using Prettier, but it’s a generic formatter that supports a bunch of languages. For them YAML is just one of them. Better integrations already exist.

I think it’s the responsibility of an editor to allow the user to pick a formatter, not that of a language server. I.e. VS Code supports this using the per language editor.defaultFormatter setting. I don’t think it’s a good idea to add a plugin system to yaml-language-server, because I see the editor as the plugin system and yaml-language-server as the plugin.

remcohaszing added a commit to remcohaszing/yaml-language-server that referenced this issue Jul 24, 2024
This replaces Prettier as the LSP formatting solution with the `yaml`
package. The `yaml` package can format YAML just fine, and we already
have it as a dependency. Prettier is a big dependency.

If people want to use Prettier, other Prettier integrations are probably
better suited for them. For example, the YAML language server doesn’t
respect Prettier configuration files.

This is a proof of concept. I tried to map existing options to the new
implementation. A more ideal solution might be to change the formatting
options.

Refs redhat-developer#933
@remcohaszing
Copy link
Contributor Author

I replaced Prettier an alternative formatter in #983. I think that caters to the silent crowd who just want to have some formatting options, but probably don’t care about the implementation used.

@Princesseuh
Copy link

+1 to this issue, using yaml-language-server as a dependency is annoying because the old Prettier version it uses sometimes override other versions of Prettier installed. This is causing issue for us here: withastro/language-tools#627 (comment)

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

No branches or pull requests

4 participants