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

Formatting triggers auto close tag #2167

Open
fourcels opened this issue Sep 25, 2023 · 6 comments
Open

Formatting triggers auto close tag #2167

fourcels opened this issue Sep 25, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@fourcels
Copy link

Describe the bug

vscode auto format not correct

Screen.Recording.2023-09-25.at.13.54.45.mov

Reproduction

<button class="text-slate-500 bg-red-500 rounded-sm text-ellipsis"
  > Show Popup
</button>

after auto format

<button class="text-slate-500 bg-red-500 rounded-sm text-ellipsis"></button>
  Show Popup
</button>

Expected behaviour

<button class="text-slate-500 bg-red-500 rounded-sm text-ellipsis">
  Show Popup
</button>

System Info

  • OS: MacOS
  • IDE: vscode 1.82.2

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

@fourcels fourcels added the bug Something isn't working label Sep 25, 2023
@jasonlyu123
Copy link
Member

I can't reproduce this. Can you elaborate more on what you mean by "auto format"? Is a format on save? Code action on save? Or do you trigger the format? Please also describe the steps to reproduce. I don't understand what is the implication of the video. Does the cursor position have anything to do with the issue?

@fourcels
Copy link
Author

@jasonlyu123
Both Format Document and format on save reproduction this bug
Have you try this snippet

<button class="text-slate-500 bg-red-500 rounded-sm text-ellipsis"
  > Show Popup
</button>

@jasonlyu123
Copy link
Member

Yeah, I tried both, but I can't reproduce it. That's why I thought there might be something else you didn't mention. It might be related to your config. Does this happen in an empty SvelteKit project? If not, please provide a reproduction repository. If it does, can you create an empty settings profile in VSCode to see if the problem persists and find the config or extension causing the problem?

@fourcels
Copy link
Author

@jasonlyu123
Conflict with html.autoClosingTags vscode setting
But the default setting is true

@jasonlyu123
Copy link
Member

If turning off html.autoClosingTags can stop the issue, the problem is that the formatting causes small changes to the file similar to when you manually typed > and therefore triggers the auto-closing tag. This is also an edge case that only happens if you have a single attribute that is very close to the prettier print width config and has the end start tag in the next line. Took me a long time to find the exact way to reproduce it.

By the time the auto-closing tag is triggered, there is no way to differentiate if the change is user input or formatting, so it'll be hard to fix without changing how auto-closing tags work. Until we can come up with a workaround you can "Ctrl+z"(Command-Z) to undo the closing tag whenever it happens.

@jasonlyu123 jasonlyu123 changed the title vscode auto format not correct format triggers auto close tag Sep 25, 2023
@jasonlyu123 jasonlyu123 changed the title format triggers auto close tag Formatting triggers auto close tag Sep 25, 2023
@jasonlyu123
Copy link
Member

Similar issue with HTML microsoft/vscode#137938

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants