sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.25k stars 200 forks source link

Option to use VSCode internal language formatter instead of prettier #1707

Open SiNONiMiTY opened 2 years ago

SiNONiMiTY commented 2 years ago

Description

Title says, For me, VSCode HTML formatter does a better job formatting the *.svelte files I have rather than Prettier.

A simple option to choose what formatter is enabled by the extension would be very appreciated.

Proposed solution

Enable an option to use VSCode's internal formatter rather than being dependent on prettier.

Alternatives

No response

Additional Information, eg. Screenshots

No response

dummdidumm commented 2 years ago

Is it possible to do this yourself? I beliefe you can choose through the settings.json which formatter runs for what file. If so, I'm not sure we want to add an option for that.

SiNONiMiTY commented 2 years ago

Yes I tried that, but I need to associate .svelte to HTML, and I would lose TS and ESLint features.

Also, you will be greeted with an error message that the HTML formatter cannot format svelte files.

I can probably do this manually, just suggesting that if the extension can use prettier, it should be also capable of using the VSCode internal vscode.html-language-features

brunnerh commented 1 year ago

Personally, I think the extension should not use Prettier at all.

It is fine to use Prettier in your own personal project or in organizations that one is responsible for, but to have such a restrictive and arbitrary formatter in an extension that is used by many vastly different people and companies, each with their own coding styles, is just not good.

The only reasonable course of action if there is some divergence is usually to opt out of formatting completely because there just are not enough ways to configure it otherwise.

jasonlyu123 commented 1 year ago

This is not a drop-in replacement. So even if we want to do it. It won't be a high-priority one. It would be more possible to happen if someone can help us with it.

SiNONiMiTY commented 1 year ago

This is not a plug-in replacement. So even if we want to do it. It won't be a high-priority one. It would be more possible to happen if someone can help us with it.

I am not familiar with the inner workings of VSCode, but is there any VSCode API that the Svelte plugin can call to use the internal formatter instead of prettier?

jasonlyu123 commented 1 year ago

Sort of, but not what you think it is. We use some low-level APIs that VSCode also uses. We must glue it together like VSCode HTML features do instead of just calling it.

We also need to add support for svelte tags and mustache. Some of the svelte syntaxes are also not strict in compliance with HTML.