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

<template> tag breaks VS Code highlighting #694

Closed
ShadowfeindX opened this issue Dec 3, 2020 · 10 comments
Closed

<template> tag breaks VS Code highlighting #694

ShadowfeindX opened this issue Dec 3, 2020 · 10 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@ShadowfeindX
Copy link

Describe the bug

Text on the same line as html closing tags breaks syntax highlighting in VS Code.

To Reproduce

  • Include any template tag containing any html elements with text nodes in a Svelte file.

Expected behavior

<template>
    <h1> Hello world
    </h1>
</template>

should highlight the same as

<template>
    <h1> Hello world </h1>
</template>

Screenshots
Expected highlighting:
Expected

Actual Highlighting:
Actual

Highlighting with Svelte Block:
Svelte

System (please complete the following information):

  • OS: [Windows]
  • IDE: [VSCode]
  • Plugin/Package: ["Svelte for VSCode"]

Additional context
I get no warnings, errors, or hints from svelte-check.

@ShadowfeindX ShadowfeindX added the bug Something isn't working label Dec 3, 2020
@dummdidumm
Copy link
Member

@Monkatraz any idea? To me it seems like the tag-regex inside template eats up the rest of the document without stopping at </h1. I tried fiddling around a little, but no luck so far.

@Monkatraz
Copy link
Contributor

I'll have to take a crack at it. I think the template 'inside' pattern is taking priority over the newly introduced scope tag patterns and ending prematurely at the first </ it finds. Liberal usage of applyEndPatternLast: 1 might fix it.

@dummdidumm
Copy link
Member

dummdidumm commented Dec 3, 2020

It seems it's something within the attribute definitions that causes this. If I remove this section, it works. I don't get why .. If I remove only parts of the attributes, it still doesn't work, only if I remove all of them.

@Monkatraz
Copy link
Contributor

Textmate grammars are... um, "hungry". A pattern starts with reckless disregard of the rest of the document, so its probably something with an attribute starting and eating all the characters until it finds a character matching (?=/?>) or something.

@dummdidumm
Copy link
Member

Okay now I'm completely confused ... If I comment out all references to #attributes, it still does not work. But if I remove the definition, it works.

@Monkatraz
Copy link
Contributor

okay that's cursed

If you don't figure out whatever is causing it, I'll take a crack at it later today.

@dummdidumm
Copy link
Member

Some more food for thought: If I comment out usage of tags-lang, it works, too.

@dummdidumm
Copy link
Member

After some more digging it seems to me that the culprit is the begin regex of the injections part. If I change it to (?<=>)\s everything's ok as long as there is one space after the > of <template> - which there will be in 99% of the case, and I'm inclined to use this as a fix because I cannot find a better regex that does not eat up a char of the inner scope.

@Monkatraz
Copy link
Contributor

Go for it, sounds reasonable.

dummdidumm added a commit that referenced this issue Dec 4, 2020
This change means that there needs to be a whitespace between the `>` and the start of the template contents, but that should be the case 99%. If someone comes up with a better solution, we are happy to accept a PR.
#694
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Dec 4, 2020
@GrygrFlzr
Copy link
Member

Even if I follow the "have at least one space after the opening tag", this is not quite fixed:
image

All closing tags inside the <template> block are missing syntax highlighting.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Feb 10, 2021
Match `</template` specifically so it does not end prematurely on inner closing tags
sveltejs#694
dummdidumm added a commit that referenced this issue Feb 10, 2021
Match `</template` specifically so it does not end prematurely on inner closing tags
#694
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

4 participants