UserNobody14 / tree-sitter-dart

Attempt to make a tree-sitter grammar for dart
MIT License
62 stars 40 forks source link

Use named nodes for things surrounded by braces #34

Closed seb-bl closed 2 years ago

seb-bl commented 2 years ago

This PR creates new named nodes for braces wrapping things. This makes them easily captured.

I'm trying to improve indentation for dart in the helix editor. Computing the indent level is based on tree-sitter and on the nodes surrounding the cursor. In order to correctly capture the nodes which should result in indentation, I made some changes to create such nodes.

For example: the for_statement was composed of

optional('await'), 'for', '(', $._for_loop_parts, ')', field('body', $._statement)

with no specific node containing just the parenthesis and the _for_loop_parts. Thus I created a new named node. The for_statement becomes:

optional('await'), 'for', $.for_loop_parts, field('body', $._statement)

And the new node for_loop_parts is simply:

'(', $._for_loop_parts, ')'

I had to adapt the tests to reflect the new nodes.

My work in progress for the queries for indent is here (if useful in any way)