Package-level declarations

Types

Link copied to clipboard
data class BracketMatchingConfig(val afterCursor: Boolean = true, val brackets: String = "()[]{}", val maxScanDistance: Int = 10000, val renderMatch: (match: MatchResult) -> DecorationSet? = null)

Configuration for bracket matching.

Link copied to clipboard
data class CommentTokens(val line: String? = null, val block: CommentTokens.BlockComment? = null)

Comment tokens for a language, used by comment toggle commands.

Link copied to clipboard
data class FoldRange(val from: DocPos, val to: DocPos)

A range that can be folded.

Link copied to clipboard

A highlight style maps Tags to SpanStyles.

Link copied to clipboard

Builder scope for defining a HighlightStyle via DSL.

Link copied to clipboard
annotation class HighlightStyleDsl

Marks DSL scope for HighlightStyleBuilder.

Link copied to clipboard
open class IndentContext(val state: EditorState, val simulateBreak: DocPos? = null, val simulateDoubleBreak: Boolean = false)

Context object passed to indent services and node prop strategies.

Link copied to clipboard
open class Language(val parser: Parser, val name: String = "")

A language object manages parsing and per-language metadata. Parse data is managed as a Lezer tree.

Link copied to clipboard
data class LanguageDescription(val name: String, val alias: List<String> = emptyList(), val extensions: List<String> = emptyList(), val filename: List<Regex> = emptyList(), val load: () -> LanguageSupport? = null)

Metadata descriptor for a language. Used for language detection and dynamic language loading.

Link copied to clipboard
class LanguageSupport(val language: Language, val support: Extension? = null)

Bundles a Language with optional supporting extensions.

Link copied to clipboard
class LRLanguage(parser: Parser, name: String = "") : Language

Subclass of Language for LR-parser-based languages.

Link copied to clipboard
data class MatchResult(val start: SelectionRange, val end: SelectionRange?, val matched: Boolean)

Result of a bracket-matching query.

Link copied to clipboard

A Language class based on a CodeMirror 5-style StreamParser.

Link copied to clipboard
interface StreamParser<State>

A stream parser parses or tokenizes content from start to end, emitting tokens as it goes. It keeps a mutable (but copyable) object with state.

Link copied to clipboard
class StringStream(val string: String, tabSize: Int, val indentUnit: Int, overrideIndent: Int? = null)

Encapsulates a single line of input. Given to stream syntax code, which uses it to tokenize the content.

Link copied to clipboard
data class TagStyleSpec(val tags: List<Tag>, val style: SpanStyle)

Specification for a tag-to-style mapping in HighlightStyle.define.

Link copied to clipboard
class TreeIndentContext(state: EditorState, val pos: DocPos, simulateBreak: DocPos? = null, simulateDoubleBreak: Boolean = false) : IndentContext

Extended indent context with access to the syntax tree for tree-based indentation strategies.

Properties

Link copied to clipboard

A NodeProp that language parsers can attach to node types to provide custom bracket-matching behavior. The function receives the syntax node and the document state, and returns a MatchResult if this node represents a bracket, or null otherwise.

Link copied to clipboard

Facet that provides comment token information for comment commands. Languages should register their comment tokens via this facet.

Link copied to clipboard

A default highlight style (works well with light themes).

Link copied to clipboard

Standard indent strategy: don't indent (return 0 columns).

Link copied to clipboard

Fold all foldable ranges in the document.

Link copied to clipboard

Fold the code at the current cursor line.

Link copied to clipboard

Effect to fold a range.

Link copied to clipboard

Default fold key bindings.

Link copied to clipboard

A node prop that attaches fold information to node types.

Link copied to clipboard

Facet for registering fold range providers.

Link copied to clipboard

State field that tracks the set of currently folded ranges. Folded ranges are represented as ReplaceDecorations.

Link copied to clipboard

A node prop that attaches indentation strategies to node types in the syntax tree.

Link copied to clipboard

Extension that automatically re-indents the current line when the user types a character that triggers indentation changes (e.g. a closing brace).

Link copied to clipboard

Facet used to register indent services. An indent service is a function that, given an IndentContext and a position, returns the desired indentation (in columns), or null if it has no opinion.

Link copied to clipboard

Facet for configuring the indent unit (number of spaces per indent level). Defaults to 2.

Link copied to clipboard

The facet used to associate a language with an editor state.

Link copied to clipboard

A NodeProp that can be attached to the top node of a language's syntax tree to associate language metadata with that node type.

Link copied to clipboard

One Dark inspired highlight style.

Link copied to clipboard

Toggle fold at the current cursor line.

Link copied to clipboard

Unfold all folded ranges.

Link copied to clipboard

Unfold the code at the current cursor position.

Link copied to clipboard

Effect to unfold a range.

Functions

Link copied to clipboard
fun bracketMatching(config: BracketMatchingConfig = BracketMatchingConfig()): Extension

Extension that highlights matching brackets near the cursor.

Link copied to clipboard

Core code folding extension that wires the fold state.

Link copied to clipboard
fun continuedIndent(units: Int = 1, except: Regex? = null): (TreeIndentContext) -> Int?

Standard indent strategy: continue the indentation of the previous line, optionally with additional units.

Link copied to clipboard
fun defineLanguageFacet(baseData: List<Extension> = emptyList()): Facet<Extension, List<Extension>>

Create a new language-specific data facet.

Link copied to clipboard
fun delimitedIndent(closing: String? = null, align: Boolean = true, units: Int = 1): (TreeIndentContext) -> Int?

Standard indent strategy: indent one level inside delimiters.

Link copied to clipboard
fun ensureSyntaxTree(state: EditorState, upto: Int, timeout: Int = 0): Tree?

Get the syntax tree for the state if it covers at least up to position upto. In Kodemirror's synchronous parsing model, the tree always covers the full document, so this always returns the tree when one is available.

Link copied to clipboard
fun foldable(state: EditorState, lineStart: DocPos): FoldRange?

Find a foldable range at the given line position, using registered fold services and tree-based fold props.

Link copied to clipboard

Query the currently folded ranges in a state.

Link copied to clipboard

Extension that adds a gutter column with fold indicators.

Link copied to clipboard

Helper that creates a fold range covering the inside of a node (excluding the first and last characters, typically brackets).

Link copied to clipboard

Force a complete re-parse of the document. In Kodemirror's synchronous parsing model, the tree is always current, so this returns the existing tree.

Link copied to clipboard
fun getIndentation(state: EditorState, pos: DocPos, simulateBreak: DocPos? = null, simulateDoubleBreak: Boolean = false): Int?

Query the indentation for a position using registered indent services and tree-based indentation strategies.

Link copied to clipboard

Get the indent unit (number of spaces per level) for the given state.

Link copied to clipboard

Resolve the SpanStyle that would be applied to a token with the given tags by the provided style.

Link copied to clipboard
fun indentRange(state: EditorState, from: DocPos, to: DocPos): ChangeSpec?

Generate a ChangeSpec.Multi that re-indents every line in the given range.

Link copied to clipboard
fun indentString(state: EditorState, cols: Int): String

Generate an indentation string for the given number of columns, using tabs if the state's indentUnit divides evenly, otherwise spaces.

Link copied to clipboard
fun <T> languageDataAt(state: EditorState, facet: Facet<T, *>, pos: Int): T?

Query language-specific data at a given position by walking up the syntax tree and looking for nodes with languageDataProp attached.

Link copied to clipboard
fun matchBrackets(state: EditorState, pos: DocPos, dir: Int = -1, config: BracketMatchingConfig = BracketMatchingConfig()): MatchResult?

Match brackets at a given position in the document.

Link copied to clipboard
fun syntaxHighlighting(highlighter: Highlighter, fallback: Boolean = false): Extension

Wrap a highlighter in an editor extension that uses it to apply syntax highlighting to the editor content.

Link copied to clipboard

Check whether the syntax parser is currently running in the background. In Kodemirror's synchronous parsing model, parsing completes immediately on every state update, so this always returns false.

Link copied to clipboard

Get the syntax tree for a state, which is the current parse tree of the active language, or Tree.empty if no language is configured.

Link copied to clipboard
fun syntaxTreeAvailable(state: EditorState, upto: Int = state.doc.length): Boolean

Check whether a complete syntax tree is available up to the given position. In Kodemirror's synchronous parsing model, the tree always covers the full document, so this returns true whenever a language is configured.

Link copied to clipboard