Package-level declarations

Types

Link copied to clipboard

A stateful, single-threaded highlighter that reuses prior parse / capture / span work across successive update calls. Use this for editor-style scenarios where the source code changes incrementally; for one-shot or whole-file recomposition the existing highlight / rememberHighlightedString paths remain the right choice.

Link copied to clipboard
data class SyntaxTheme(val baseStyle: SpanStyle = SpanStyle(), val background: Color? = null, val keyword: SpanStyle? = null, val function: SpanStyle? = null, val type: SpanStyle? = null, val string: SpanStyle? = null, val stringEscape: SpanStyle? = null, val number: SpanStyle? = null, val boolean: SpanStyle? = null, val comment: SpanStyle? = null, val constant: SpanStyle? = null, val property: SpanStyle? = null, val variable: SpanStyle? = null, val namespace: SpanStyle? = null, val operator: SpanStyle? = null, val punctuation: SpanStyle? = null, val extras: Map<String, SpanStyle> = emptyMap())

Maps tree-sitter highlight captures to SpanStyle values.

Link copied to clipboard
class Utf8ByteIndex(text: String)

Properties

Link copied to clipboard

Composition local providing the active SyntaxTheme. Defaults to SyntaxTheme.DarkDefault. SyntaxHighlightedText reads from this local when its theme parameter is omitted.

Functions

Link copied to clipboard
fun highlight(code: String, language: Language, theme: SyntaxTheme): AnnotatedString

Returns an AnnotatedString of code with theme styles applied to tree-sitter capture spans defined by language. Each capture name is resolved through SyntaxTheme.resolve, which falls back along dotted prefixes (e.g. string.escape ->string) before yielding null.

Link copied to clipboard

Composable wrapper around highlight that caches the parsed tree-sitter Tree across theme-only changes. The first stage is keyed on (code, language) and re-parses only when one of those changes; the second stage applies theme to the cached tree. Native memory of the dropped tree is reclaimed by the JVM Cleaner registered in ktreesitter's Parser/Tree init blocks (no explicit disposal API exists).

Link copied to clipboard
fun rememberHighlightedStringAsync(code: String, language: Language, theme: SyntaxTheme, context: CoroutineContext = Dispatchers.Default): State<AnnotatedString>

Async variant of rememberHighlightedString that runs highlight off the calling thread.