windwp / nvim-ts-autotag

Use treesitter to auto close and auto rename html tag
MIT License
1.62k stars 86 forks source link

Svelte Autorename Issue: Only Works When HTML is Above the Script Block #122

Closed alcibiadesc closed 10 months ago

alcibiadesc commented 1 year ago

Describe the bug The autorename feature of nvim-ts-autotag doesn't work as expected when the HTML is below the script block in Svelte files. The autorename only works correctly when the HTML is above the script block.

To Reproduce Steps to reproduce the behavior:

  1. Open a Svelte file in lunarvim.
  2. Place the HTML block below the script block.
  3. Try to rename a tag in the HTML block.
  4. Notice that the corresponding closing tag doesn't get renamed.

Expected behavior I expect the corresponding closing tag to get renamed, regardless of whether the HTML block is above or below the script block in Svelte files.

GIF: error

alcibiadesc commented 1 year ago

Update: if you put a commented script at the end of the svelte document, you will not have the problem, although it is not practical at all

randomfix

m-gail commented 1 year ago

I have the same problem, though it seems like it happens on the last tag in the file in general. It also only happens, if the tag is on a single line.

For example:

<script>
  export let data;
</script>

<div>{data}</div> <!-- renaming this causes the issue -->
<script>
  export let data;
</script>

<div>  <!-- renaming this does not cause the issue -->
  {data}
</div>
cassepipe commented 1 year ago

Wow congrats on finding out that if you put the html above the script, it works, I thought it just didn't work for svelte files.

I confirm I have the same problem. It's totally useless then I am not event sure svelte accepts a script block under the component's body and even if it could, people reading your code wouldn't be very happy about it

TheBlckbird commented 1 year ago

Wow congrats on finding out that if you put the html above the script, it works, I thought it just didn't work for svelte files.

I confirm I have the same problem. It's totally useless then I am not event sure svelte accepts a script block under the component's body and even if it could, people reading your code wouldn't be very happy about it

It does, but you shouldn't do it as it's against the coventions.

TheBlckbird commented 1 year ago

And prettier automatically formats the component in that way

stale[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.