SyntaxTheme

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 tag: SpanStyle? = null, val attribute: 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.

Deliberately not a data class: a compiler-generated copy cannot survive the addition of a new capture field, because the added parameter changes copy's mangled JVM name and shifts every componentN. Hand-writing copy lets a future field keep the previous overload as a @Deprecated(level = DeprecationLevel.HIDDEN) signature, so new captures stay binary compatible — the same approach androidx.compose.ui.text.SpanStyle takes.

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, tag: SpanStyle? = null, attribute: SpanStyle? = null, extras: Map<String, SpanStyle> = emptyMap())

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Style for attribute captures (markup attributes, annotations).

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 tag captures (markup element and selector names).

Link copied to clipboard

Style for type captures.

Link copied to clipboard

Style for variable captures.

Functions

Link copied to clipboard
fun copy(baseStyle: SpanStyle = this.baseStyle, background: Color? = this.background, keyword: SpanStyle? = this.keyword, function: SpanStyle? = this.function, type: SpanStyle? = this.type, string: SpanStyle? = this.string, stringEscape: SpanStyle? = this.stringEscape, number: SpanStyle? = this.number, boolean: SpanStyle? = this.boolean, comment: SpanStyle? = this.comment, constant: SpanStyle? = this.constant, property: SpanStyle? = this.property, variable: SpanStyle? = this.variable, namespace: SpanStyle? = this.namespace, operator: SpanStyle? = this.operator, punctuation: SpanStyle? = this.punctuation, tag: SpanStyle? = this.tag, attribute: SpanStyle? = this.attribute, extras: Map<String, SpanStyle> = this.extras): SyntaxTheme
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun resolve(captureName: String): SpanStyle?

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

Link copied to clipboard
open override fun toString(): String