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(tree-sitter): pass node text to grammar #860

Merged

Conversation

claytonrcarter
Copy link
Contributor

Identify the Bug

The WASM tree-sitter language mode does not pass node text into the grammar when calling idForScope. This is a breaking change from the legacy tree-sitter language mode that prevents the semanticolor package from working with Pulsar's new tree-sitter modes. I believe that this only affects semanticolor, as the original change was made explicitly for that package. (See atom/atom#20212)

References

Description of the Change

I updated ScopeResolver and WASMTreeSitterLanguageMode to pass the syntax node text through to WASMTreeSitterGrammar. I also updated WASMTreeSitterGrammar and TreeSitterGrammar to highlight why the seemingly unused parameter is needed. Once I identified what was needed, the change was easy.

Alternate Designs

I looked around to see if there was a better way of getting the package working w/ the new mode, but didn't see anything obvious. Open to suggestions if there are other ways that I didn't see.

Possible Drawbacks

It is a little strange to make a change like this only to support a single package. That said, I love that package and I'm happy to be able to keep it going.

Verification Process

I did not add or update any tests, but I could attempt to do so if desired. I verified this by

  1. making this change in Pulsar
  2. making another small change in semanticolor so that it recognizes WASMTreeSitterGrammars, in addition to legacy grammars
  3. loading a dev window and confirming that colors were applied in a modern tree-sitter grammar

Release Notes

Added support for the semanticolor package in modern tree-sitter grammars.

@claytonrcarter claytonrcarter force-pushed the wasm-tree-sitter-compat branch from df46adf to 47876e4 Compare January 15, 2024 01:13
This fixes a subtle breaking change in the WASM tree-sitter modes that
affected the semanticolor package. (And probably only that package.)

Although the node text is unused in `idForScope` in the core editor, the
legacy tree-sitter mode was specifically modified to pass the node text
into `idForScope` so that the semanticolor package could make use of it
to give custom scopes (and thus colors) to different symbols. (On
activation, semanticolor monkey patches that method in relevant
grammars.)

This alone is not enough to get sematicolor working with Pulsar's new
WASM tree-sitter modes, but it's one piece of the puzzle.

Ref: 97b905a
Ref: atom/atom#20212
Ref: https://github.com/pulsar-edit/pulsar/blob/1bf7fc4025f0b10623058e4e8340e166954ed188/src/tree-sitter-language-mode.js#L1321-L1324
Ref: https://github.com/digitallyserviced/semanticolor/blob/d219ef9a1f8fa5251025b74dc6dc0a7f7c38d102/lib/semanticolor-grammar.js#L44-L65
@claytonrcarter claytonrcarter force-pushed the wasm-tree-sitter-compat branch from 47876e4 to ae03e1e Compare January 16, 2024 12:42
@claytonrcarter claytonrcarter marked this pull request as ready for review January 16, 2024 22:22
@claytonrcarter
Copy link
Contributor Author

I'm marking this ready for review because it's working for me locally. I'm pretty sure that the CI failure is just a flaky test because it's not related to anything I changed, only the macOS test is failing (ubuntu is passing) and it's a different failure that I got last time. 😆

Copy link
Contributor

@savetheclocktower savetheclocktower left a comment

Choose a reason for hiding this comment

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

My only possible hangup here was performance, but after a few batches of profiling I'm not seeing any difference of statistical significance, even when loading a very large file.

I'll keep poking the CI until it complies, but I'm 👍 on this.

@savetheclocktower savetheclocktower merged commit 4a91444 into pulsar-edit:master Jan 20, 2024
102 checks passed
@claytonrcarter claytonrcarter deleted the wasm-tree-sitter-compat branch January 20, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants