-
Notifications
You must be signed in to change notification settings - Fork 3k
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
svelte: Migrate to tree-sitter-grammars/tree-sitter-svelte
#17529
Conversation
I was also experimenting on improving Svelte support, with improvements to the tree sitter but with a different technique. Instead of trying to reimplement a basic JS parser inside the Svelte tree sitter, I extended the I also fixed auto indent issues. |
@matubu I had this idea as well, however I realised it is possible to reliably parse the inside of expressions as raw text - because we end up re-parsing the javascript code as an Additionally, as svelte supports typescript within expressions now, it is important to support that, and I think the raw parsing right now is the best way to do that. I'd be happy to collaborate. Could you explain what you had to do in order to get directive props parsing? Were you using a modified version of tree-sitter-svelte? -- Anyhow, I think we should 100% stick with improving the tree-sitter-grammars/tree-sitter-svelte repository as it's important to centralise efforts here. I'll be creating a PR soon to add support for directives within their repository soon. |
@matubu in hindsight, you are right about some stuff with the JS parsing needing to be more consistent. For example, here we have a snippet function's name not being highlighted as a function like is done inside of I think it may be a wise idea (as a seperate PR, and within the From my understanding, we may be able to somehow import/extend the typescript tree-sitter and use it to parse specific node types more directly. I think it would also be interesting to get injected CSS syntax highlighting for things like `style="background: red" |
|
Well what I thought was if the js expression is not properly balanced tree sitter could maybe better recover from it.
Yes. I think you are required to parse the different part of the directive props to be able to highlighting them differently.
Yes that should be possible too.
Yes I've done it in my version. |
Since |
Good point, I will do that tomorrow, however I do think it still should be turned into an actual "raw_text_expression" or something so it can be properly delegated to the typescript syntax highlighting - which will work better for other stuff like function parameters and etc. |
tree-sitter-grammars/tree-sitter-svelte
We'll bump this separately.
Not quite, because in the case of {#snippet foo({ bar, baz })} the section foo({ bar, baz }) in isolation will be treated like a function call rather than a function definition. That matters for things like If you want to inject JavaScript into that whole example instead of just the |
{#snippet outer({ hello, bar )} I'm not sure if I misinterpreted you or if you misinterpreted me, but as you can see above, the snippet statement expression code is treated as svelte tree-sitter nodes (including the I think it would be wise to defer the handling of the syntax highlighting here to the typescript tree-sitter - where typescript would treat this as a function call expression (even though it should be a function definition expression) I would like to work on a larger PR at tree-sitter-svelte at some stage to fully parse every JS/TS expression much like the In the meantime, I will just highlight the snippet_name as a function |
@savetheclocktower we can continue this discussion in tree-sitter-grammars/tree-sitter-svelte#10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
This PR bumps the Svelte extension to v0.2.0. Changes: - #17529 Release Notes: - N/A
…zed#17529) > [!NOTE] > The https://github.com/tree-sitter-grammars/tree-sitter-svelte repository seems to be more well maintained, with higher quality code, and as per #1 it was suggested that we swap to this repository for Svelte grammars - Closes zed-industries/zed#17310 - Closes zed-industries/zed#10893 - Closes zed-industries/zed#12833 - Closes #1 - Closes zed-industries/zed#14943 - Closes #2 - Added: buffer/file symbol outlines for `.svelte` (`outlines.scm`) - Improved: Attribute directives & modifiers in `.svelte` files can be styled independently. - Fixed: issue where svelte expression inside quotes failed parsing - Improved: Svelte components in Markup are styled differently from tags. - Added: Support for Svelte 5 syntax (`{#snippet children()}`, `{@render foo()`) - Change: Svelte now using [tree-sitter-grammars/tree-sitter-svelte](https://github.com/tree-sitter-grammars/tree-sitter-svelte) for language highlighting - Added: Support for typescript syntax in svelte expressions ![image](https://github.com/user-attachments/assets/49d199ee-7550-49a7-912d-070cf691b029) ![image](https://github.com/user-attachments/assets/848ac5b6-62da-4c42-8e24-b7023504f8af) Release Notes: - N/A --- **tree-sitter-grammar things to improve** - [ ] snippet functions aren't being treated as JS code - [ ] we should be able to detect @component comments and treat them as markdown - [x] `foo:bar` style/class/prop directives - [x] `--foo="..."` var fields - [ ] snippet/if blocks's children may need to be indented a little further Will implement some of the rest of these in a separate PR --------- Co-authored-by: Marshall Bowers <[email protected]>
This PR bumps the Svelte extension to v0.2.0. Changes: - zed-industries/zed#17529 Release Notes: - N/A
…ustries#17529) > [!NOTE] > The https://github.com/tree-sitter-grammars/tree-sitter-svelte repository seems to be more well maintained, with higher quality code, and as per zed-extensions/svelte#1 it was suggested that we swap to this repository for Svelte grammars - Closes zed-industries#17310 - Closes zed-industries#10893 - Closes zed-industries#12833 - Closes zed-extensions/svelte#1 - Closes zed-industries#14943 - Closes zed-extensions/svelte#2 - Added: buffer/file symbol outlines for `.svelte` (`outlines.scm`) - Improved: Attribute directives & modifiers in `.svelte` files can be styled independently. - Fixed: issue where svelte expression inside quotes failed parsing - Improved: Svelte components in Markup are styled differently from tags. - Added: Support for Svelte 5 syntax (`{#snippet children()}`, `{@render foo()`) - Change: Svelte now using [tree-sitter-grammars/tree-sitter-svelte](https://github.com/tree-sitter-grammars/tree-sitter-svelte) for language highlighting - Added: Support for typescript syntax in svelte expressions ![image](https://github.com/user-attachments/assets/49d199ee-7550-49a7-912d-070cf691b029) ![image](https://github.com/user-attachments/assets/848ac5b6-62da-4c42-8e24-b7023504f8af) Release Notes: - N/A --- **tree-sitter-grammar things to improve** - [ ] snippet functions aren't being treated as JS code - [ ] we should be able to detect @component comments and treat them as markdown - [x] `foo:bar` style/class/prop directives - [x] `--foo="..."` var fields - [ ] snippet/if blocks's children may need to be indented a little further Will implement some of the rest of these in a separate PR --------- Co-authored-by: Marshall Bowers <[email protected]>
This PR bumps the Svelte extension to v0.2.0. Changes: - zed-industries#17529 Release Notes: - N/A
Note
The https://github.com/tree-sitter-grammars/tree-sitter-svelte repository seems to be more well maintained, with higher quality code, and as per zed-extensions/svelte#1 it was suggested that we swap to this repository for Svelte grammars
Closes Syntax highlighting for
Component
vselement
tags in.svelte
files #17310Closes Svelte syntax highlighting breaks using
context="module"
with Javascript #10893Closes Svelte syntax highlighting is lacking #12833
Closes Make syntax highlighting more complete, and support Svelte 5 zed-extensions/svelte#1
Closes Svelte quotations auto_close bug #14943
Closes Breadcrumbs/symbols repeating in svelte files zed-extensions/svelte#2
Added: buffer/file symbol outlines for
.svelte
(outlines.scm
)Improved: Attribute directives & modifiers in
.svelte
files can be styled independently.Fixed: issue where svelte expression inside quotes failed parsing
Improved: Svelte components in Markup are styled differently from tags.
Added: Support for Svelte 5 syntax (
{#snippet children()}
,{@render foo()
)Change: Svelte now using tree-sitter-grammars/tree-sitter-svelte for language highlighting
Added: Support for typescript syntax in svelte expressions
Release Notes:
tree-sitter-grammar things to improve
foo:bar
style/class/prop directives--foo="..."
var fieldsWill implement some of the rest of these in a separate PR