Skip to content

Commit

Permalink
Some reorganizing, clarify TextKit 2 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Feb 9, 2024
1 parent c8fe131 commit 5cb19c6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ Many of these support versionable content. If you are working with a backing sto

It might be surprising to see that many of the types in RangeState are marked `@MainActor`. Right now, I have found no way to both support the hybrid sync/async functionality while also not being tied to a global actor. I think this is the most resonable trade-off, but I would very much like to lift this restriction. However, I believe it will require [language changes](https://forums.swift.org/t/isolation-assumptions/69514/47).

### TreeSitterClient

This library is a hybrid sync/async interface to [SwiftTreeSitter][SwiftTreeSitter]. It features:

- UTF-16 code-point (`NSString`-compatible) API for edits, invalidations, and queries
- Processing edits of `String` objects, or raw bytes
- Invalidation translation to the current content state regardless of background processing
- On-demand nested language resolution via tree-sitter's injection system
- Background processing when needed to scale to large documents

Tree-sitter uses separate compiled parsers for each language. There are a variety of ways to use tree-sitter parsers with SwiftTreeSitter. Check out that project for details.

### Neon

The top-level module includes systems for managing text styling. It is also text-system independent. It makes very few assumptions about how text is stored, displayed, or styled. It also includes some components for use with stock AppKit and UIKit systems. These are provided for easy integration, not maximum performance.
Expand All @@ -85,6 +73,18 @@ The top-level module includes systems for managing text styling. It is also text

There is also an example project that demonstrates how to use `TextViewHighlighter` for macOS and iOS.

### TreeSitterClient

This library is a hybrid sync/async interface to [SwiftTreeSitter][SwiftTreeSitter]. It features:

- UTF-16 code-point (`NSString`-compatible) API for edits, invalidations, and queries
- Processing edits of `String` objects, or raw bytes
- Invalidation translation to the current content state regardless of background processing
- On-demand nested language resolution via tree-sitter's injection system
- Background processing when needed to scale to large documents

Tree-sitter uses separate compiled parsers for each language. There are a variety of ways to use tree-sitter parsers with SwiftTreeSitter. Check out that project for details.

### Token Data Sources

Neon was designed to accept and overlay token data from multiple sources simultaneously. Here's a real-world example of how this is used:
Expand All @@ -105,6 +105,8 @@ In a traditional `NSTextStorage`-backed system (TextKit 1 and 2), it can be chal

But, even that isn't quite enough unfortunately. You still need to precisely control the timing of invalidation and styling. This is where `RangeInvalidationBuffer` comes in.

I have not yet figured out a way to do this with TextKit 2, and it may not be possible without new API.

## Usage

### TreeSitterClient
Expand Down

0 comments on commit 5cb19c6

Please sign in to comment.