- Notifications
You must be signed in to change notification settings - Fork 110
Add Injected Language Support #150
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
Add Injected Language Support #150
Conversation
| Is this still WIP? |
Yeah it is. There are still some glaring issues right now that I thought would be trivial to fix but are ending up being trickier than expected. |
lukepistrol left a comment
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.
Just a couple of code style considerations about function parameter indentation. I provided fixes for most of them.
Refs: Code Style
Sources/CodeEditTextView/Extensions/NSRange+/NSRange+TSRange.swift Outdated Show resolved Hide resolved
Sources/CodeEditTextView/TreeSitter/TreeSitterClient+Edit.swift Outdated Show resolved Hide resolved
Sources/CodeEditTextView/TreeSitter/TreeSitterClient+Edit.swift Outdated Show resolved Hide resolved
Sources/CodeEditTextView/TreeSitter/TreeSitterClient+Edit.swift Outdated Show resolved Hide resolved
Sources/CodeEditTextView/TreeSitter/TreeSitterClient+Edit.swift Outdated Show resolved Hide resolved
Sources/CodeEditTextView/Extensions/NSRange+/NSRange+Comparable.swift Outdated Show resolved Hide resolved
lukepistrol left a comment
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.
LGTM 👍
austincondiff left a comment
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.
This is really great work @thecoolwinter! 👏
| @thecoolwinter Are there any breaking changes regarding the public API? Need to know when releasing a new version. |
Yes, there's an additional method on |
Description
This PR adds support for injected languages using tree-sitter as described in #16 and in the tree-sitter documentation. Languages can contain injected languages which are described in a language's
injections.scmfile. Some examples of injected languages are:styleandscripttags<phptagsDetails
This PR is a rework of the
TreeSitterClientclass. Specifically it:layersarray andprimaryLayerproperty.layerscontains all language layers in the document, andprimaryLayeris the ID of the document's primary language.LanguageLayerobject. These objects represent an injected language-range(s) combination. Each layer can have one or more range associated with it depending on if it should be parsed as one document or multiple.The highlight query algorithm is largely the same, but keeps track of any ranges not used by any injected layers, and only queries the primary layer for those ranges so as not to override any injected highlights.
Related Issues
Screenshots
Before, other languages were detected but parsed and highlighted as normal text.

With Injected languages, in this case CSS and JS embedded in HTML and a second layer of Regex embedded in JS embedded in HTML:
