| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080 |
- import { NodeProp, Parser, Tree, TreeFragment, SyntaxNode, NodeType } from '@lezer/common';
- import { LRParser, ParserConfig } from '@lezer/lr';
- import * as _codemirror_state from '@codemirror/state';
- import { Facet, Extension, EditorState, StateField, Range } from '@codemirror/state';
- import { EditorView, DecorationSet, Command, KeyBinding, ViewUpdate, BlockInfo, Decoration } from '@codemirror/view';
- import { Highlighter, Tag } from '@lezer/highlight';
- import { StyleModule, StyleSpec } from 'style-mod';
- /**
- Node prop stored in a parser's top syntax node to provide the
- facet that stores language-specific data for that language.
- */
- declare const languageDataProp: NodeProp<Facet<{
- [name: string]: any;
- }, readonly {
- [name: string]: any;
- }[]>>;
- /**
- Helper function to define a facet (to be added to the top syntax
- node(s) for a language via
- [`languageDataProp`](https://codemirror.net/6/docs/ref/#language.languageDataProp)), that will be
- used to associate language data with the language. You
- probably only need this when subclassing
- [`Language`](https://codemirror.net/6/docs/ref/#language.Language).
- */
- declare function defineLanguageFacet(baseData?: {
- [name: string]: any;
- }): Facet<{
- [name: string]: any;
- }, readonly {
- [name: string]: any;
- }[]>;
- /**
- A language object manages parsing and per-language
- [metadata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). Parse data is
- managed as a [Lezer](https://lezer.codemirror.net) tree. The class
- can be used directly, via the [`LRLanguage`](https://codemirror.net/6/docs/ref/#language.LRLanguage)
- subclass for [Lezer](https://lezer.codemirror.net/) LR parsers, or
- via the [`StreamLanguage`](https://codemirror.net/6/docs/ref/#language.StreamLanguage) subclass
- for stream parsers.
- */
- declare class Language {
- /**
- The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
- used for this language.
- */
- readonly data: Facet<{
- [name: string]: any;
- }>;
- /**
- The extension value to install this as the document language.
- */
- readonly extension: Extension;
- /**
- The parser object. Can be useful when using this as a [nested
- parser](https://lezer.codemirror.net/docs/ref#common.Parser).
- */
- parser: Parser;
- /**
- Construct a language object. If you need to invoke this
- directly, first define a data facet with
- [`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
- configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
- to the language's outer syntax node.
- */
- constructor(
- /**
- The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
- used for this language.
- */
- data: Facet<{
- [name: string]: any;
- }>, parser: Parser, extraExtensions?: Extension[]);
- /**
- Query whether this language is active at the given position.
- */
- isActiveAt(state: EditorState, pos: number, side?: -1 | 0 | 1): boolean;
- /**
- Find the document regions that were parsed using this language.
- The returned regions will _include_ any nested languages rooted
- in this language, when those exist.
- */
- findRegions(state: EditorState): {
- from: number;
- to: number;
- }[];
- /**
- Indicates whether this language allows nested languages. The
- default implementation returns true.
- */
- get allowsNesting(): boolean;
- }
- /**
- A subclass of [`Language`](https://codemirror.net/6/docs/ref/#language.Language) for use with Lezer
- [LR parsers](https://lezer.codemirror.net/docs/ref#lr.LRParser)
- parsers.
- */
- declare class LRLanguage extends Language {
- readonly parser: LRParser;
- private constructor();
- /**
- Define a language from a parser.
- */
- static define(spec: {
- /**
- The parser to use. Should already have added editor-relevant
- node props (and optionally things like dialect and top rule)
- configured.
- */
- parser: LRParser;
- /**
- [Language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt)
- to register for this language.
- */
- languageData?: {
- [name: string]: any;
- };
- }): LRLanguage;
- /**
- Create a new instance of this language with a reconfigured
- version of its parser.
- */
- configure(options: ParserConfig): LRLanguage;
- get allowsNesting(): boolean;
- }
- /**
- Get the syntax tree for a state, which is the current (possibly
- incomplete) parse tree of the active
- [language](https://codemirror.net/6/docs/ref/#language.Language), or the empty tree if there is no
- language available.
- */
- declare function syntaxTree(state: EditorState): Tree;
- /**
- Try to get a parse tree that spans at least up to `upto`. The
- method will do at most `timeout` milliseconds of work to parse
- up to that point if the tree isn't already available.
- */
- declare function ensureSyntaxTree(state: EditorState, upto: number, timeout?: number): Tree | null;
- /**
- Queries whether there is a full syntax tree available up to the
- given document position. If there isn't, the background parse
- process _might_ still be working and update the tree further, but
- there is no guarantee of that—the parser will [stop
- working](https://codemirror.net/6/docs/ref/#language.syntaxParserRunning) when it has spent a
- certain amount of time or has moved beyond the visible viewport.
- Always returns false if no language has been enabled.
- */
- declare function syntaxTreeAvailable(state: EditorState, upto?: number): boolean;
- /**
- Move parsing forward, and update the editor state afterwards to
- reflect the new tree. Will work for at most `timeout`
- milliseconds. Returns true if the parser managed get to the given
- position in that time.
- */
- declare function forceParsing(view: EditorView, upto?: number, timeout?: number): boolean;
- /**
- Tells you whether the language parser is planning to do more
- parsing work (in a `requestIdleCallback` pseudo-thread) or has
- stopped running, either because it parsed the entire document,
- because it spent too much time and was cut off, or because there
- is no language parser enabled.
- */
- declare function syntaxParserRunning(view: EditorView): boolean;
- /**
- A parse context provided to parsers working on the editor content.
- */
- declare class ParseContext {
- private parser;
- /**
- The current editor state.
- */
- readonly state: EditorState;
- /**
- Tree fragments that can be reused by incremental re-parses.
- */
- fragments: readonly TreeFragment[];
- /**
- The current editor viewport (or some overapproximation
- thereof). Intended to be used for opportunistically avoiding
- work (in which case
- [`skipUntilInView`](https://codemirror.net/6/docs/ref/#language.ParseContext.skipUntilInView)
- should be called to make sure the parser is restarted when the
- skipped region becomes visible).
- */
- viewport: {
- from: number;
- to: number;
- };
- private parse;
- private constructor();
- private startParse;
- private withContext;
- private withoutTempSkipped;
- /**
- Notify the parse scheduler that the given region was skipped
- because it wasn't in view, and the parse should be restarted
- when it comes into view.
- */
- skipUntilInView(from: number, to: number): void;
- /**
- Returns a parser intended to be used as placeholder when
- asynchronously loading a nested parser. It'll skip its input and
- mark it as not-really-parsed, so that the next update will parse
- it again.
-
- When `until` is given, a reparse will be scheduled when that
- promise resolves.
- */
- static getSkippingParser(until?: Promise<unknown>): Parser;
- /**
- Get the context for the current parse, or `null` if no editor
- parse is in progress.
- */
- static get(): ParseContext | null;
- }
- /**
- The facet used to associate a language with an editor state. Used
- by `Language` object's `extension` property (so you don't need to
- manually wrap your languages in this). Can be used to access the
- current language on a state.
- */
- declare const language: Facet<Language, Language | null>;
- /**
- This class bundles a [language](https://codemirror.net/6/docs/ref/#language.Language) with an
- optional set of supporting extensions. Language packages are
- encouraged to export a function that optionally takes a
- configuration object and returns a `LanguageSupport` instance, as
- the main way for client code to use the package.
- */
- declare class LanguageSupport {
- /**
- The language object.
- */
- readonly language: Language;
- /**
- An optional set of supporting extensions. When nesting a
- language in another language, the outer language is encouraged
- to include the supporting extensions for its inner languages
- in its own set of support extensions.
- */
- readonly support: Extension;
- /**
- An extension including both the language and its support
- extensions. (Allowing the object to be used as an extension
- value itself.)
- */
- extension: Extension;
- /**
- Create a language support object.
- */
- constructor(
- /**
- The language object.
- */
- language: Language,
- /**
- An optional set of supporting extensions. When nesting a
- language in another language, the outer language is encouraged
- to include the supporting extensions for its inner languages
- in its own set of support extensions.
- */
- support?: Extension);
- }
- /**
- Language descriptions are used to store metadata about languages
- and to dynamically load them. Their main role is finding the
- appropriate language for a filename or dynamically loading nested
- parsers.
- */
- declare class LanguageDescription {
- /**
- The name of this language.
- */
- readonly name: string;
- /**
- Alternative names for the mode (lowercased, includes `this.name`).
- */
- readonly alias: readonly string[];
- /**
- File extensions associated with this language.
- */
- readonly extensions: readonly string[];
- /**
- Optional filename pattern that should be associated with this
- language.
- */
- readonly filename: RegExp | undefined;
- private loadFunc;
- /**
- If the language has been loaded, this will hold its value.
- */
- support: LanguageSupport | undefined;
- private loading;
- private constructor();
- /**
- Start loading the the language. Will return a promise that
- resolves to a [`LanguageSupport`](https://codemirror.net/6/docs/ref/#language.LanguageSupport)
- object when the language successfully loads.
- */
- load(): Promise<LanguageSupport>;
- /**
- Create a language description.
- */
- static of(spec: {
- /**
- The language's name.
- */
- name: string;
- /**
- An optional array of alternative names.
- */
- alias?: readonly string[];
- /**
- An optional array of filename extensions associated with this
- language.
- */
- extensions?: readonly string[];
- /**
- An optional filename pattern associated with this language.
- */
- filename?: RegExp;
- /**
- A function that will asynchronously load the language.
- */
- load?: () => Promise<LanguageSupport>;
- /**
- Alternatively to `load`, you can provide an already loaded
- support object. Either this or `load` should be provided.
- */
- support?: LanguageSupport;
- }): LanguageDescription;
- /**
- Look for a language in the given array of descriptions that
- matches the filename. Will first match
- [`filename`](https://codemirror.net/6/docs/ref/#language.LanguageDescription.filename) patterns,
- and then [extensions](https://codemirror.net/6/docs/ref/#language.LanguageDescription.extensions),
- and return the first language that matches.
- */
- static matchFilename(descs: readonly LanguageDescription[], filename: string): LanguageDescription | null;
- /**
- Look for a language whose name or alias matches the the given
- name (case-insensitively). If `fuzzy` is true, and no direct
- matchs is found, this'll also search for a language whose name
- or alias occurs in the string (for names shorter than three
- characters, only when surrounded by non-word characters).
- */
- static matchLanguageName(descs: readonly LanguageDescription[], name: string, fuzzy?: boolean): LanguageDescription | null;
- }
- /**
- Facet that defines a way to provide a function that computes the
- appropriate indentation depth at the start of a given line, or
- `null` to indicate no appropriate indentation could be determined.
- */
- declare const indentService: Facet<(context: IndentContext, pos: number) => number | null, readonly ((context: IndentContext, pos: number) => number | null)[]>;
- /**
- Facet for overriding the unit by which indentation happens.
- Should be a string consisting either entirely of spaces or
- entirely of tabs. When not set, this defaults to 2 spaces.
- */
- declare const indentUnit: Facet<string, string>;
- /**
- Return the _column width_ of an indent unit in the state.
- Determined by the [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit)
- facet, and [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) when that
- contains tabs.
- */
- declare function getIndentUnit(state: EditorState): number;
- /**
- Create an indentation string that covers columns 0 to `cols`.
- Will use tabs for as much of the columns as possible when the
- [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit) facet contains
- tabs.
- */
- declare function indentString(state: EditorState, cols: number): string;
- /**
- Get the indentation at the given position. Will first consult any
- [indent services](https://codemirror.net/6/docs/ref/#language.indentService) that are registered,
- and if none of those return an indentation, this will check the
- syntax tree for the [indent node prop](https://codemirror.net/6/docs/ref/#language.indentNodeProp)
- and use that if found. Returns a number when an indentation could
- be determined, and null otherwise.
- */
- declare function getIndentation(context: IndentContext | EditorState, pos: number): number | null;
- /**
- Create a change set that auto-indents all lines touched by the
- given document range.
- */
- declare function indentRange(state: EditorState, from: number, to: number): _codemirror_state.ChangeSet;
- /**
- Indentation contexts are used when calling [indentation
- services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
- useful in indentation logic, and can selectively override the
- indentation reported for some lines.
- */
- declare class IndentContext {
- /**
- The editor state.
- */
- readonly state: EditorState;
- /**
- The indent unit (number of columns per indentation level).
- */
- unit: number;
- /**
- Create an indent context.
- */
- constructor(
- /**
- The editor state.
- */
- state: EditorState,
- /**
- @internal
- */
- options?: {
- /**
- Override line indentations provided to the indentation
- helper function, which is useful when implementing region
- indentation, where indentation for later lines needs to refer
- to previous lines, which may have been reindented compared to
- the original start state. If given, this function should
- return -1 for lines (given by start position) that didn't
- change, and an updated indentation otherwise.
- */
- overrideIndentation?: (pos: number) => number;
- /**
- Make it look, to the indent logic, like a line break was
- added at the given position (which is mostly just useful for
- implementing something like
- [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent)).
- */
- simulateBreak?: number;
- /**
- When `simulateBreak` is given, this can be used to make the
- simulate break behave like a double line break.
- */
- simulateDoubleBreak?: boolean;
- });
- /**
- Get a description of the line at the given position, taking
- [simulated line
- breaks](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
- into account. If there is such a break at `pos`, the `bias`
- argument determines whether the part of the line line before or
- after the break is used.
- */
- lineAt(pos: number, bias?: -1 | 1): {
- text: string;
- from: number;
- };
- /**
- Get the text directly after `pos`, either the entire line
- or the next 100 characters, whichever is shorter.
- */
- textAfterPos(pos: number, bias?: -1 | 1): string;
- /**
- Find the column for the given position.
- */
- column(pos: number, bias?: -1 | 1): number;
- /**
- Find the column position (taking tabs into account) of the given
- position in the given string.
- */
- countColumn(line: string, pos?: number): number;
- /**
- Find the indentation column of the line at the given point.
- */
- lineIndent(pos: number, bias?: -1 | 1): number;
- /**
- Returns the [simulated line
- break](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
- for this context, if any.
- */
- get simulatedBreak(): number | null;
- }
- /**
- A syntax tree node prop used to associate indentation strategies
- with node types. Such a strategy is a function from an indentation
- context to a column number or null, where null indicates that no
- definitive indentation can be determined.
- */
- declare const indentNodeProp: NodeProp<(context: TreeIndentContext) => number | null>;
- /**
- Objects of this type provide context information and helper
- methods to indentation functions registered on syntax nodes.
- */
- declare class TreeIndentContext extends IndentContext {
- private base;
- /**
- The position at which indentation is being computed.
- */
- readonly pos: number;
- /**
- The syntax tree node to which the indentation strategy
- applies.
- */
- readonly node: SyntaxNode;
- private constructor();
- /**
- Get the text directly after `this.pos`, either the entire line
- or the next 100 characters, whichever is shorter.
- */
- get textAfter(): string;
- /**
- Get the indentation at the reference line for `this.node`, which
- is the line on which it starts, unless there is a node that is
- _not_ a parent of this node covering the start of that line. If
- so, the line at the start of that node is tried, again skipping
- on if it is covered by another such node.
- */
- get baseIndent(): number;
- /**
- Continue looking for indentations in the node's parent nodes,
- and return the result of that.
- */
- continue(): number | null;
- }
- /**
- An indentation strategy for delimited (usually bracketed) nodes.
- Will, by default, indent one unit more than the parent's base
- indent unless the line starts with a closing token. When `align`
- is true and there are non-skipped nodes on the node's opening
- line, the content of the node will be aligned with the end of the
- opening node, like this:
- foo(bar,
- baz)
- */
- declare function delimitedIndent({ closing, align, units }: {
- closing: string;
- align?: boolean;
- units?: number;
- }): (context: TreeIndentContext) => number;
- /**
- An indentation strategy that aligns a node's content to its base
- indentation.
- */
- declare const flatIndent: (context: TreeIndentContext) => number;
- /**
- Creates an indentation strategy that, by default, indents
- continued lines one unit more than the node's base indentation.
- You can provide `except` to prevent indentation of lines that
- match a pattern (for example `/^else\b/` in `if`/`else`
- constructs), and you can change the amount of units used with the
- `units` option.
- */
- declare function continuedIndent({ except, units }?: {
- except?: RegExp;
- units?: number;
- }): (context: TreeIndentContext) => number;
- /**
- Enables reindentation on input. When a language defines an
- `indentOnInput` field in its [language
- data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt), which must hold a regular
- expression, the line at the cursor will be reindented whenever new
- text is typed and the input from the start of the line up to the
- cursor matches that regexp.
- To avoid unneccesary reindents, it is recommended to start the
- regexp with `^` (usually followed by `\s*`), and end it with `$`.
- For example, `/^\s*\}$/` will reindent when a closing brace is
- added at the start of a line.
- */
- declare function indentOnInput(): Extension;
- /**
- A facet that registers a code folding service. When called with
- the extent of a line, such a function should return a foldable
- range that starts on that line (but continues beyond it), if one
- can be found.
- */
- declare const foldService: Facet<(state: EditorState, lineStart: number, lineEnd: number) => ({
- from: number;
- to: number;
- } | null), readonly ((state: EditorState, lineStart: number, lineEnd: number) => ({
- from: number;
- to: number;
- } | null))[]>;
- /**
- This node prop is used to associate folding information with
- syntax node types. Given a syntax node, it should check whether
- that tree is foldable and return the range that can be collapsed
- when it is.
- */
- declare const foldNodeProp: NodeProp<(node: SyntaxNode, state: EditorState) => ({
- from: number;
- to: number;
- } | null)>;
- /**
- [Fold](https://codemirror.net/6/docs/ref/#language.foldNodeProp) function that folds everything but
- the first and the last child of a syntax node. Useful for nodes
- that start and end with delimiters.
- */
- declare function foldInside(node: SyntaxNode): {
- from: number;
- to: number;
- } | null;
- /**
- Check whether the given line is foldable. First asks any fold
- services registered through
- [`foldService`](https://codemirror.net/6/docs/ref/#language.foldService), and if none of them return
- a result, tries to query the [fold node
- prop](https://codemirror.net/6/docs/ref/#language.foldNodeProp) of syntax nodes that cover the end
- of the line.
- */
- declare function foldable(state: EditorState, lineStart: number, lineEnd: number): {
- from: number;
- to: number;
- } | null;
- declare type DocRange = {
- from: number;
- to: number;
- };
- /**
- State effect that can be attached to a transaction to fold the
- given range. (You probably only need this in exceptional
- circumstances—usually you'll just want to let
- [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode) and the [fold
- gutter](https://codemirror.net/6/docs/ref/#language.foldGutter) create the transactions.)
- */
- declare const foldEffect: _codemirror_state.StateEffectType<DocRange>;
- /**
- State effect that unfolds the given range (if it was folded).
- */
- declare const unfoldEffect: _codemirror_state.StateEffectType<DocRange>;
- /**
- The state field that stores the folded ranges (as a [decoration
- set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
- [`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
- [`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
- state.
- */
- declare const foldState: StateField<DecorationSet>;
- /**
- Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
- in the given state.
- */
- declare function foldedRanges(state: EditorState): DecorationSet;
- /**
- Fold the lines that are selected, if possible.
- */
- declare const foldCode: Command;
- /**
- Unfold folded ranges on selected lines.
- */
- declare const unfoldCode: Command;
- /**
- Fold all top-level foldable ranges. Note that, in most cases,
- folding information will depend on the [syntax
- tree](https://codemirror.net/6/docs/ref/#language.syntaxTree), and folding everything may not work
- reliably when the document hasn't been fully parsed (either
- because the editor state was only just initialized, or because the
- document is so big that the parser decided not to parse it
- entirely).
- */
- declare const foldAll: Command;
- /**
- Unfold all folded code.
- */
- declare const unfoldAll: Command;
- /**
- Default fold-related key bindings.
- - Ctrl-Shift-[ (Cmd-Alt-[ on macOS): [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode).
- - Ctrl-Shift-] (Cmd-Alt-] on macOS): [`unfoldCode`](https://codemirror.net/6/docs/ref/#language.unfoldCode).
- - Ctrl-Alt-[: [`foldAll`](https://codemirror.net/6/docs/ref/#language.foldAll).
- - Ctrl-Alt-]: [`unfoldAll`](https://codemirror.net/6/docs/ref/#language.unfoldAll).
- */
- declare const foldKeymap: readonly KeyBinding[];
- interface FoldConfig {
- /**
- A function that creates the DOM element used to indicate the
- position of folded code. The `onclick` argument is the default
- click event handler, which toggles folding on the line that
- holds the element, and should probably be added as an event
- handler to the returned element.
-
- When this option isn't given, the `placeholderText` option will
- be used to create the placeholder element.
- */
- placeholderDOM?: ((view: EditorView, onclick: (event: Event) => void) => HTMLElement) | null;
- /**
- Text to use as placeholder for folded text. Defaults to `"…"`.
- Will be styled with the `"cm-foldPlaceholder"` class.
- */
- placeholderText?: string;
- }
- /**
- Create an extension that configures code folding.
- */
- declare function codeFolding(config?: FoldConfig): Extension;
- declare type Handlers = {
- [event: string]: (view: EditorView, line: BlockInfo, event: Event) => boolean;
- };
- interface FoldGutterConfig {
- /**
- A function that creates the DOM element used to indicate a
- given line is folded or can be folded.
- When not given, the `openText`/`closeText` option will be used instead.
- */
- markerDOM?: ((open: boolean) => HTMLElement) | null;
- /**
- Text used to indicate that a given line can be folded.
- Defaults to `"⌄"`.
- */
- openText?: string;
- /**
- Text used to indicate that a given line is folded.
- Defaults to `"›"`.
- */
- closedText?: string;
- /**
- Supply event handlers for DOM events on this gutter.
- */
- domEventHandlers?: Handlers;
- /**
- When given, if this returns true for a given view update,
- recompute the fold markers.
- */
- foldingChanged?: (update: ViewUpdate) => boolean;
- }
- /**
- Create an extension that registers a fold gutter, which shows a
- fold status indicator before foldable lines (which can be clicked
- to fold or unfold the line).
- */
- declare function foldGutter(config?: FoldGutterConfig): Extension;
- /**
- A highlight style associates CSS styles with higlighting
- [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
- */
- declare class HighlightStyle implements Highlighter {
- /**
- A style module holding the CSS rules for this highlight style.
- When using
- [`highlightTree`](https://lezer.codemirror.net/docs/ref#highlight.highlightTree)
- outside of the editor, you may want to manually mount this
- module to show the highlighting.
- */
- readonly module: StyleModule | null;
- readonly style: (tags: readonly Tag[]) => string | null;
- readonly scope: ((type: NodeType) => boolean) | undefined;
- private constructor();
- /**
- Create a highlighter style that associates the given styles to
- the given tags. The specs must be objects that hold a style tag
- or array of tags in their `tag` property, and either a single
- `class` property providing a static CSS class (for highlighter
- that rely on external styling), or a
- [`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
- set of CSS properties (which define the styling for those tags).
-
- The CSS rules created for a highlighter will be emitted in the
- order of the spec's properties. That means that for elements that
- have multiple tags associated with them, styles defined further
- down in the list will have a higher CSS precedence than styles
- defined earlier.
- */
- static define(specs: readonly TagStyle[], options?: {
- /**
- By default, highlighters apply to the entire document. You can
- scope them to a single language by providing the language
- object or a language's top node type here.
- */
- scope?: Language | NodeType;
- /**
- Add a style to _all_ content. Probably only useful in
- combination with `scope`.
- */
- all?: string | StyleSpec;
- /**
- Specify that this highlight style should only be active then
- the theme is dark or light. By default, it is active
- regardless of theme.
- */
- themeType?: "dark" | "light";
- }): HighlightStyle;
- }
- /**
- Wrap a highlighter in an editor extension that uses it to apply
- syntax highlighting to the editor content.
- When multiple (non-fallback) styles are provided, the styling
- applied is the union of the classes they emit.
- */
- declare function syntaxHighlighting(highlighter: Highlighter, options?: {
- /**
- When enabled, this marks the highlighter as a fallback, which
- only takes effect if no other highlighters are registered.
- */
- fallback: boolean;
- }): Extension;
- /**
- Returns the CSS classes (if any) that the highlighters active in
- the state would assign to the given style
- [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag) and
- (optional) language
- [scope](https://codemirror.net/6/docs/ref/#language.HighlightStyle^define^options.scope).
- */
- declare function highlightingFor(state: EditorState, tags: readonly Tag[], scope?: NodeType): string | null;
- /**
- The type of object used in
- [`HighlightStyle.define`](https://codemirror.net/6/docs/ref/#language.HighlightStyle^define).
- Assigns a style to one or more highlighting
- [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag), which can either be a fixed class name
- (which must be defined elsewhere), or a set of CSS properties, for
- which the library will define an anonymous class.
- */
- interface TagStyle {
- /**
- The tag or tags to target.
- */
- tag: Tag | readonly Tag[];
- /**
- If given, this maps the tags to a fixed class name.
- */
- class?: string;
- /**
- Any further properties (if `class` isn't given) will be
- interpreted as in style objects given to
- [style-mod](https://github.com/marijnh/style-mod#documentation).
- (The type here is `any` because of TypeScript limitations.)
- */
- [styleProperty: string]: any;
- }
- /**
- A default highlight style (works well with light themes).
- */
- declare const defaultHighlightStyle: HighlightStyle;
- interface Config {
- /**
- Whether the bracket matching should look at the character after
- the cursor when matching (if the one before isn't a bracket).
- Defaults to true.
- */
- afterCursor?: boolean;
- /**
- The bracket characters to match, as a string of pairs. Defaults
- to `"()[]{}"`. Note that these are only used as fallback when
- there is no [matching
- information](https://lezer.codemirror.net/docs/ref/#common.NodeProp^closedBy)
- in the syntax tree.
- */
- brackets?: string;
- /**
- The maximum distance to scan for matching brackets. This is only
- relevant for brackets not encoded in the syntax tree. Defaults
- to 10 000.
- */
- maxScanDistance?: number;
- /**
- Can be used to configure the way in which brackets are
- decorated. The default behavior is to add the
- `cm-matchingBracket` class for matching pairs, and
- `cm-nonmatchingBracket` for mismatched pairs or single brackets.
- */
- renderMatch?: (match: MatchResult, state: EditorState) => readonly Range<Decoration>[];
- }
- /**
- Create an extension that enables bracket matching. Whenever the
- cursor is next to a bracket, that bracket and the one it matches
- are highlighted. Or, when no matching bracket is found, another
- highlighting style is used to indicate this.
- */
- declare function bracketMatching(config?: Config): Extension;
- /**
- The result returned from `matchBrackets`.
- */
- interface MatchResult {
- /**
- The extent of the bracket token found.
- */
- start: {
- from: number;
- to: number;
- };
- /**
- The extent of the matched token, if any was found.
- */
- end?: {
- from: number;
- to: number;
- };
- /**
- Whether the tokens match. This can be false even when `end` has
- a value, if that token doesn't match the opening token.
- */
- matched: boolean;
- }
- /**
- Find the matching bracket for the token at `pos`, scanning
- direction `dir`. Only the `brackets` and `maxScanDistance`
- properties are used from `config`, if given. Returns null if no
- bracket was found at `pos`, or a match result otherwise.
- */
- declare function matchBrackets(state: EditorState, pos: number, dir: -1 | 1, config?: Config): MatchResult | null;
- /**
- Encapsulates a single line of input. Given to stream syntax code,
- which uses it to tokenize the content.
- */
- declare class StringStream {
- /**
- The line.
- */
- string: string;
- private tabSize;
- /**
- The current indent unit size.
- */
- indentUnit: number;
- /**
- The current position on the line.
- */
- pos: number;
- /**
- The start position of the current token.
- */
- start: number;
- private lastColumnPos;
- private lastColumnValue;
- /**
- Create a stream.
- */
- constructor(
- /**
- The line.
- */
- string: string, tabSize: number,
- /**
- The current indent unit size.
- */
- indentUnit: number);
- /**
- True if we are at the end of the line.
- */
- eol(): boolean;
- /**
- True if we are at the start of the line.
- */
- sol(): boolean;
- /**
- Get the next code unit after the current position, or undefined
- if we're at the end of the line.
- */
- peek(): string | undefined;
- /**
- Read the next code unit and advance `this.pos`.
- */
- next(): string | void;
- /**
- Match the next character against the given string, regular
- expression, or predicate. Consume and return it if it matches.
- */
- eat(match: string | RegExp | ((ch: string) => boolean)): string | void;
- /**
- Continue matching characters that match the given string,
- regular expression, or predicate function. Return true if any
- characters were consumed.
- */
- eatWhile(match: string | RegExp | ((ch: string) => boolean)): boolean;
- /**
- Consume whitespace ahead of `this.pos`. Return true if any was
- found.
- */
- eatSpace(): boolean;
- /**
- Move to the end of the line.
- */
- skipToEnd(): void;
- /**
- Move to directly before the given character, if found on the
- current line.
- */
- skipTo(ch: string): boolean | void;
- /**
- Move back `n` characters.
- */
- backUp(n: number): void;
- /**
- Get the column position at `this.pos`.
- */
- column(): number;
- /**
- Get the indentation column of the current line.
- */
- indentation(): number;
- /**
- Match the input against the given string or regular expression
- (which should start with a `^`). Return true or the regexp match
- if it matches.
-
- Unless `consume` is set to `false`, this will move `this.pos`
- past the matched text.
-
- When matching a string `caseInsensitive` can be set to true to
- make the match case-insensitive.
- */
- match(pattern: string | RegExp, consume?: boolean, caseInsensitive?: boolean): boolean | RegExpMatchArray | null;
- /**
- Get the current token.
- */
- current(): string;
- }
- /**
- A stream parser parses or tokenizes content from start to end,
- emitting tokens as it goes over it. It keeps a mutable (but
- copyable) object with state, in which it can store information
- about the current context.
- */
- interface StreamParser<State> {
- /**
- Produce a start state for the parser.
- */
- startState?(indentUnit: number): State;
- /**
- Read one token, advancing the stream past it, and returning a
- string indicating the token's style tag—either the name of one
- of the tags in
- [`tags`](https://lezer.codemirror.net/docs/ref#highlight.tags),
- or such a name suffixed by one or more tag
- [modifier](https://lezer.codemirror.net/docs/ref#highlight.Tag^defineModifier)
- names, separated by periods. For example `"keyword"` or
- "`variableName.constant"`.
-
- It is okay to return a zero-length token, but only if that
- updates the state so that the next call will return a non-empty
- token again.
- */
- token(stream: StringStream, state: State): string | null;
- /**
- This notifies the parser of a blank line in the input. It can
- update its state here if it needs to.
- */
- blankLine?(state: State, indentUnit: number): void;
- /**
- Copy a given state. By default, a shallow object copy is done
- which also copies arrays held at the top level of the object.
- */
- copyState?(state: State): State;
- /**
- Compute automatic indentation for the line that starts with the
- given state and text.
- */
- indent?(state: State, textAfter: string, context: IndentContext): number | null;
- /**
- Default [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) to
- attach to this language.
- */
- languageData?: {
- [name: string]: any;
- };
- /**
- Extra tokens to use in this parser. When the tokenizer returns a
- token name that exists as a property in this object, the
- corresponding tag will be assigned to the token.
- */
- tokenTable?: {
- [name: string]: Tag;
- };
- }
- /**
- A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
- 5-style [streaming parser](https://codemirror.net/6/docs/ref/#language.StreamParser).
- */
- declare class StreamLanguage<State> extends Language {
- private constructor();
- /**
- Define a stream language.
- */
- static define<State>(spec: StreamParser<State>): StreamLanguage<State>;
- private getIndent;
- get allowsNesting(): boolean;
- }
- export { Config, HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, MatchResult, ParseContext, StreamLanguage, StreamParser, StringStream, TagStyle, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldState, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentRange, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
|