language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

<template> with a comment breaks VS Code highlighting

Open jangxyz opened this issue 10 months ago • 1 comments

Describe the bug

Adding a comment tag inside a template tag breaks the highlight, in somewhat look-alike with #694. It might be an edge case.

Reproduction

  1. In VS Code,
  2. Create a template tag with an element inside.
  3. Comment out the element.

Sample svelte code:

<template>
    <!--<div>
        <p>A paragraph.</p>
    </div>-->
</template>

Expected behaviour

The comment highlight should stop and the ending comment, and the </template> should be highlighted in pair with <template>.

System Info

  • Extension: svelte-vscode-109.5.2
  • IDE: VSCode 1.95.2
  • OS: MacOS 15.1

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

image

I don't have deep knowledge in tmLanguage files, but I skimming through svelte.tmLanguage.src.yaml I noticed the template tag is included in tags-lang.begin property, together with script and style (#L571). Is there a specific reason why it needs to be taken care of? I noticed it highlights correctly if I remove the template part and rebuild the grammar file.

image

jangxyz avatar Jan 14 '25 09:01 jangxyz

The reason for the lang check is because of <template lang="pug">. So the solution is probably similar to https://github.com/sveltejs/language-tools/issues/694 and some regex need to be tweaked.

jasonlyu123 avatar Jan 16 '25 04:01 jasonlyu123