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

fix: replace kdl tree-sitter to fix highlighting #8652

Merged
merged 7 commits into from Nov 3, 2023

Conversation

cgahr
Copy link
Contributor

@cgahr cgahr commented Oct 28, 2023

The tree-sitter for the kdl language currently being used contains bugs.

Consider the following kdl config:

bigFlatItems "multiline \" \" \"\nstring\n" null
c "multiline string\nwith special characters:\n\t \n \" \"\n"

With the current tree-sitter implementation, escaped double quotes \" are being detected as characters ending a string. As such, they are improperly highlighted.

I propose to change the used implementation to https://github.com/amaanq/tree-sitter-kdl. It seems to be more up to date, more activate and highlights the previous example correctly.

grafik

@cgahr cgahr changed the title replace kdl tree-sitter fix: replace kdl tree-sitter to fix highlighting Oct 28, 2023
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queries in runtime/queries/kdl/*.scm will need to be updated to match the new grammar. For example cargo xtask query-check is currently failing because the queries match a comment node which doesn't exist in the new grammar (it has a single_line_comment node instead https://github.com/amaanq/tree-sitter-kdl/blob/e180e05132c4cb229a8ba679b298790ef1eca77c/grammar.js#L291)

@the-mikedavis the-mikedavis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. A-language-support Area: Support for programming/text languages labels Oct 29, 2023
@cgahr
Copy link
Contributor Author

cgahr commented Oct 29, 2023

Thanks for your comments. I updated highlights.scm to match the new tree-sitter. I had to remove bare_identifier since it does not exist (is not public) in the new tree-sitter.

Also, I added indent queries.

@cgahr
Copy link
Contributor Author

cgahr commented Oct 30, 2023

I added text object queries for tree sitter navigation:

  • class.* and function.* behave the same but the movement
  • both match the full node, inside the inside of the brackets, around the full surrounding node
  • class.movement moves to the next node
  • function.movement moves to the next identifier, I think this is very useful to cycle identifiers and is not bound to the hierarchy (in contrast to class.movement)
  • parameter work as well. inside selects the parameter, around the parameter with type if
  • parameter.movement moves to the next parameter without type, I think this matches the most common use-case of only editing the parameter without type
  • comment matching works too, however, comment.around for single line comments only selects the same and previous lines, not the following ones too. I don't know how to fix that.
  • lastly, test.* matches the types of values; tests don't exist in kdl and this type of movement might be useful but probably not very common.

I also added indents, they just work.

Lastly, I slightly improved the syntax highlighting. node identifiers are now variable colored, which afaik is normally the most common color, white. This removes colors, with them being the most common element of kdl documents, and removes color clashes with type annotations. Also, types and their brackets are differently colored.

@the-mikedavis the-mikedavis added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 3, 2023
@pascalkuthe pascalkuthe merged commit 5c325fe into helix-editor:master Nov 3, 2023
6 checks passed
acristoffers pushed a commit to acristoffers/helix that referenced this pull request Nov 18, 2023
* replace kdl tree-sitter

* kdl: adopt highlights for new tree-sitter

* kdl: add indent queries

* kdl: add textobjects

* kdl: improve syntax highlighting

* kdl: update lang-support

* kdl: make indents more concise

---------

Co-authored-by: Constantin Gahr <constantin.gahr@ipp.mpg.de>
danillos pushed a commit to danillos/helix that referenced this pull request Nov 21, 2023
* replace kdl tree-sitter

* kdl: adopt highlights for new tree-sitter

* kdl: add indent queries

* kdl: add textobjects

* kdl: improve syntax highlighting

* kdl: update lang-support

* kdl: make indents more concise

---------

Co-authored-by: Constantin Gahr <constantin.gahr@ipp.mpg.de>
dgkf pushed a commit to dgkf/helix that referenced this pull request Jan 30, 2024
* replace kdl tree-sitter

* kdl: adopt highlights for new tree-sitter

* kdl: add indent queries

* kdl: add textobjects

* kdl: improve syntax highlighting

* kdl: update lang-support

* kdl: make indents more concise

---------

Co-authored-by: Constantin Gahr <constantin.gahr@ipp.mpg.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants