Closed thecoolwinter closed 1 year ago
Is this still WIP?
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.
@thecoolwinter Are there any breaking changes regarding the public API? Need to know when releasing a new version.
@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 HighlightProvider
which external highlight providers will have to implement when updating.
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: