Skip to content

Volar wrongly auto-closes some HTML tags #970

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

Closed
mariusa opened this issue Feb 18, 2022 · 8 comments
Closed

Volar wrongly auto-closes some HTML tags #970

mariusa opened this issue Feb 18, 2022 · 8 comments
Labels

Comments

@mariusa
Copy link

mariusa commented Feb 18, 2022

Hi and hope you are getting better!

VSCode auto-closing tags works fine on .html files. It considers which elements are valid
https://stackoverflow.com/questions/1946426/html-5-is-it-br-br-or-br

eg it leaves <br> alone.

Volar changes <br> to <br /> on save. (found out by disabling all other extensions)

Please let VSCode handle the HTML inside <template> for .vue files, as it already has all kinds of rules which work fine.

@yaegassy
Copy link
Collaborator

yaegassy commented Feb 19, 2022

The built-in formatter feature of volar uses prettyhtml for <template>.

It is the behavior of prettyhtml that <br> becomes <br /> when saved. There is no option to control this behavior in prettyhtml, so it may not be easy to deal with.

Also, it may be a more difficult approach to have the formatting features of VSCode's html language feature used only for the <template> part.

@mariusa
Copy link
Author

mariusa commented Feb 20, 2022

it may be a more difficult approach to have the formatting features of VSCode's html language feature used only for the <template> part.

I see. Is there something missing in the vscode API that the team could help with? eg implement an API to format some code similar to what prettyhtml provides. I'm sure other extensions would use this too, since it's built-in.

@yaegassy
Copy link
Collaborator

Volar formatter is designed to be used out of the box. If you want to use more custom rules, it is recommended to use prettier or other formatter extensions.

As a side note, <br> becomes <br /> even when using prettier.

You may want to find a formatter extension that matches your expected behavior. (Or you may need to develop your own formatter extension)

  • Tips #53
    • See: "Formatting tab size config & Change formatter"

@johnsoncodehk
Copy link
Member

it may be a more difficult approach to have the formatting features of VSCode's html language feature used only for the <template> part.

I see. Is there something missing in the vscode API that the team could help with? eg implement an API to format some code similar to what prettyhtml provides. I'm sure other extensions would use this too, since it's built-in.

Hi @mariusa, I have tries customize vscode-html-languageservice format settings and yes it can't imitate prettyhtml, in my experience prettyhtml is much better then vscode-html-languageservice / Prettier with html formatting with out of box usage so we choice it.

@mariusa
Copy link
Author

mariusa commented Mar 15, 2022

Hi Johnson,

Would this be possible to implement
microsoft/vscode#145147

or it also depends on completely replacing prettyhtml with vscode-html-languageservice ?

Thanks!

@johnsoncodehk
Copy link
Member

johnsoncodehk commented Mar 15, 2022

Just have a quick look, I think we have supported js/ts.implicitProjectConfig.checkJs already: https://github.com/johnsoncodehk/volar/blob/26b68b6852546285d6066536d5425de9ef8634c1/packages/vue-language-server/src/inferredCompilerOptions.ts#L10-L11

But why you mention prettyhtml? This is not related to js/ts.implicitProjectConfig.checkJs. Btw you can also change html formatter yourself now. See #1027.

@mariusa
Copy link
Author

mariusa commented Mar 15, 2022

I think we have supported js/ts.implicitProjectConfig.checkJs already:

Fantastic news, thanks! So in the next release, volar will apply vscode checks for js/ts inside <script> ?
For example, abc = 2 will show a warning for undefined var, as in .js/.ts files?

In the current version this doesn't work yet:

Marketplace Info
Last updated
14/03/2022, 20:34:12

@mariusa
Copy link
Author

mariusa commented May 9, 2022

This works fine now with latest release, which changed prettyhtml to vscode formatter :D

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

No branches or pull requests

3 participants