CodeEditApp / CodeEditSourceEditor

A code editor view written in Swift powered by tree-sitter.
https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor
MIT License
504 stars 74 forks source link

Add Injected Language Support #150

Closed thecoolwinter closed 1 year ago

thecoolwinter commented 1 year ago

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:

Details

This PR is a rework of the TreeSitterClient class. Specifically it:

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.

Screenshot 2023-02-28 at 3 08 52 PM

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

Screenshot 2023-03-24 at 2 45 15 PM
lukepistrol commented 1 year ago

Is this still WIP?

thecoolwinter commented 1 year ago

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 commented 1 year ago

@thecoolwinter Are there any breaking changes regarding the public API? Need to know when releasing a new version.

thecoolwinter commented 1 year ago

@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.