SyntaxTheme

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.

Set the named field for each capture you want styled. Unset fields fall back to a parent prefix (e.g. string.escape falls back to string), and finally to baseStyle. For grammar-specific captures not covered by a field (e.g. keyword.return, variable.member), use extras; entries there win over typed fields for the same name.

Marked Immutable so Compose treats it as a stable parameter and skips recomposition when the same instance is passed. Callers must honor that contract: build a SyntaxTheme once (typically as a top-level/companion val or hoisted into a LocalSyntaxTheme) and never mutate the extras map after passing it in.

Constructors

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

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Background painted behind the highlighted text. The Material3 SyntaxHighlightedText applies it automatically; pass theme.copy(background = null) to disable.

Link copied to clipboard

Applied to the entire string before any capture-specific style. Set the default text color here.

Link copied to clipboard

Style for boolean captures.

Link copied to clipboard

Style for comment captures.

Link copied to clipboard

Style for constant captures.

Link copied to clipboard

Overrides for capture names not represented as typed fields. Wins over typed fields for the same name. Pass a stable map instance (e.g. an immutable mapOf(...) constructed once and reused) — mutating the map after handing it to SyntaxTheme breaks the Immutable contract and leads to stale recomposition.

Link copied to clipboard

Style for function captures.

Link copied to clipboard

Style for keyword captures.

Link copied to clipboard

Style for namespace captures.

Link copied to clipboard

Style for number captures.

Link copied to clipboard

Style for operator captures.

Link copied to clipboard

Style for property captures.

Link copied to clipboard

Style for punctuation captures.

Link copied to clipboard

Style for string captures.

Link copied to clipboard

Style for string.escape captures. Falls back to string when unset.

Link copied to clipboard

Style for type captures.

Link copied to clipboard

Style for variable captures.

Functions

Link copied to clipboard
fun resolve(captureName: String): SpanStyle?

Returns the SpanStyle for captureName, falling back along dotted prefixes.