-
Notifications
You must be signed in to change notification settings - Fork 91
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
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. |
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
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 👍
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.scm
file. Some examples of injected languages are:style
andscript
tags<php
tagsDetails
This PR is a rework of the
TreeSitterClient
class. Specifically it:layers
array andprimaryLayer
property.layers
contains all language layers in the document, andprimaryLayer
is the ID of the document's primary language.LanguageLayer
object. 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:
