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

feat(lang-ts): add API for creating custom Spans in tree sitter languages #484

Merged
merged 4 commits into from
Sep 16, 2023

Conversation

itsaky
Copy link
Contributor

@itsaky itsaky commented Sep 15, 2023

This PR adds a new API that allows TsAnalyzeManager implementations to create custom Spans and styles for the captures.

API

TsAnalyzeManager implementations can provide a TsSpanFactory instance which is used to create the spans (and styles for the capture). The span factory is provided with the TSQueryCapture object representing the query capture along with the column index and styles for the Span.

The default implementation of the factory (DefaultTsSpanFactory) simply creates the spans using Span.obtain.

Example

As an example, the tree-sitter based Java language in the sample application uses a custom span factory to add a LineGutterBackground anchor style to lines which contain a HEX color string.

@Rosemoe
Copy link
Owner

Rosemoe commented Sep 16, 2023

Thanks for your contributions!

@Rosemoe Rosemoe merged commit 9eb5ef8 into Rosemoe:main Sep 16, 2023
2 checks passed
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.

None yet

2 participants