-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
feature: extending the typescript tree-sitter grammar to enable more advanced and contextual parsing #10
Comments
I'll keep typing my way through this until I figure out a better idea, because I don't even like any of the options I proposed. Option 1 has the best chance of shipping soon, but it couples things that shouldn't be coupled. Things that would ideally be highlighted by the editor's separate TS/JS Tree-sitter parsers:
Things that would be highlighted by coupled, special-purpose TS/JS rules pulled into
Things that are in between, but are almost certainly better off being highlighted by the editor’s separate TS/JS parsers:
The painful part here is:
|
You're right, this isn't a simple issue to solve, even if we go with option 1. we will still need to replicate the typescript Perhaps my issue in tree-sitter may address it |
I said it before, I'll say it again: Tree-sitter is simply a poor fit for templating languages, and you'll be fighting the tool all the way. Since you're coming from Zed, you may have Max's ear so you could try to explain (very generally!) what is lacking from tree-sitter; maybe he'll see a way around it. (For the record, 2. seems to be the most popular option -- see glimmer-javascript etc.) |
@savetheclocktower just linking this issue comment here Currently, typescript thinks that this is a function call expression, so the |
Did you check the tree-sitter docs?
Is your feature request related to a problem? Please describe.
Currently, we have a few places where language injections will fail due to the nature of how tree-sitter works.
As far as I am aware, it does not seem possible to have tree-sitter treat a specific injection as a subnode within a sublanguage.
Let's take the following example:
If we treat the attribute_value inside of the generics attribute as
typescript
, this will error in the typescript parser, sinceT extends string
is not a valid top-level typescript statement.This occurs in various other locations.
For example, we will want to treat the function in here as a function definition
or likewise here as a function call expression
This would bring the svelte tree-sitter more inline with how the
tsx
treesitter extends the typescript language definition to become a more precise and accurate parser that removes some of the complications around expression parsing.Describe the solution you'd like
Per @savetheclocktower's suggestions (zed-industries/zed#17529 (comment)), there are a few ways to implement support this.
I'm not so sure whether something like
3.
is possible with treesitter unfortunately, therefore I think going with1.
will be best.Describe alternatives you've considered
No response
Additional context
The text was updated successfully, but these errors were encountered: