-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
VSCode plugin: Syntax highlighting not correctly applied to embedded svelte component in markdown #1094
Comments
Currently the syntax highlighting isn't quite right, probably related to a bug in the underlying Svelte highlighter for vscode: sveltejs/language-tools#1094 I'd like to fix the above issue before asking this to be merged, but I thought I'd file this initial PR for feedback.
Seem like the injection rules here doesn't work in the markdown code block for some reason. We'll see whether that's possible to fix. |
I spent a bit of time today trying to debug this. I used this toy example to test: ```svelte
<script>
var x = 5;
</script>
``` After giving things slightly more unique names, I found out that vscode's textmate parser seems to be "stuck" in this directive when in markdown:
That is to say, when I'm at
What's odd is when I put the cursor at the very end of the script block above (i.e. just after the
So it's noticing the end of the block, but somehow not transitioning into the state where it's actually looking at the JavaScript. I assume that's:
Why would it be triggering |
@Monkatraz any ideas on ^^^ ? |
Apologies for my flailing around. Dug into things more and realized that @jasonlyu123 was correct all along: the injection rules are not being applied in an embedded context. The weird behaviour I'm describing above is only due to the fact that the injection rules are not there, and it's falling back to whatever else is defined in the file. I'm now pretty sure this is an issue upstream so filed an issue there: microsoft/vscode-textmate#152 -- that has some more details as well as confirmation of the problem described. It's likely possible to make the grammar not depend on injections (e.g. I got it working for bare script tags without them), though I think it would be less elegant. |
Thank you for digging into this! |
Based on the response in microsoft/vscode-textmate#152, it looks like we might have to rewrite this not to use injection grammars (at least if we care about fixing this bug). |
Doing that will be horribly messy... How frustrating. |
At least this comment gave me another possibility on how to better debug grammar matches |
Okay I guess I need to do three things sooner or later:
I've been working with CodeMirror 6 a lot recently and the highlighting there is so much better it's jarring going back to VSCode lol (I should make a Svelte grammar for it) |
Although I should add that one alternative is to use a different grammar for markdown, I think one that always uses TypeScript would be a decent compromise. Obviously that has edge cases (what if you're using something nutty like CoffeeScript or Rescript) |
This sounds like a decent short-time solution. It would solve the issue for the majority of users, for those drinking coffee or otherwise it's still as buggy as before inside the script tag. |
Mostly fixes sveltejs#1094. Do this by injecting rules to parse typescript and css for svelte script/style blocks inside markdown only. This should cover *most* cases of embedded svelte blocks inside markdown. It would not be *too* difficult to extend this further to handle other types of embedded script/style tags (as is done in the original grammar), though it would be somewhat tedious.
Not sure if this is what you had in mind, but I tried something like this in #1537. Basically reinjecting enough rules to make script/style tags do something sensible if they're embedded in markdown. |
Mostly fixes_ #1094. Do this by injecting rules to parse typescript and css for svelte script/style blocks inside markdown only. This should cover *most* cases of embedded svelte blocks inside markdown. It would not be *too* difficult to extend this further to handle other types of embedded script/style tags (as is done in the original grammar), though it would be somewhat tedious.
Mostly fixed by #1537 through adding additional injection rules for markdown files. I'll keep this open, maybe we find a way someday to solve this in a way that these addition injections are not needed. |
Describe the bug
Syntax highlighting not correctly applied to embedded svelte component in markdown when using "Svelte for VSCode"
To Reproduce
Steps to reproduce the behavior:
Put the following inside a markdown document:
For example a code snippet that is treated in a way you don't expect.
Expected behavior
Expected similar syntax highlighting to what I see when viewing a svelte file with that content.
Actual behaviour
Get somewhat incorrect / inconsistent formatting (see screenshots)
Screenshots
If applicable, add screenshots to help explain your problem.
View for a svelte component (correct):
View for a svelte component embedded in markdown (incorrect):
System (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: