@codemirror/language 0.19.9 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/index.cjs +1209 -41
- package/dist/index.d.ts +497 -50
- package/dist/index.js +1193 -44
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { NodeProp,
|
|
1
|
+
import { NodeProp, Parser, Tree, TreeFragment, SyntaxNode, NodeType } from '@lezer/common';
|
|
2
2
|
import { LRParser, ParserConfig } from '@lezer/lr';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import * as _codemirror_state from '@codemirror/state';
|
|
4
|
+
import { Facet, Extension, EditorState, Range } from '@codemirror/state';
|
|
5
|
+
import { EditorView, DecorationSet, Command, KeyBinding, BlockInfo, Decoration } from '@codemirror/view';
|
|
6
|
+
import { Highlighter, Tag } from '@lezer/highlight';
|
|
7
|
+
import { StyleModule, StyleSpec } from 'style-mod';
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
|
-
Node prop stored in a
|
|
8
|
-
facet that stores language data for that language.
|
|
10
|
+
Node prop stored in a parser's top syntax node to provide the
|
|
11
|
+
facet that stores language-specific data for that language.
|
|
9
12
|
*/
|
|
10
13
|
declare const languageDataProp: NodeProp<Facet<{
|
|
11
14
|
[name: string]: any;
|
|
@@ -30,26 +33,22 @@ declare function defineLanguageFacet(baseData?: {
|
|
|
30
33
|
/**
|
|
31
34
|
A language object manages parsing and per-language
|
|
32
35
|
[metadata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). Parse data is
|
|
33
|
-
managed as a [Lezer](https://lezer.codemirror.net) tree.
|
|
34
|
-
|
|
35
|
-
[
|
|
36
|
-
[`StreamLanguage`](https://codemirror.net/6/docs/ref/#
|
|
37
|
-
|
|
36
|
+
managed as a [Lezer](https://lezer.codemirror.net) tree. The class
|
|
37
|
+
can be used directly, via the [`LRLanguage`](https://codemirror.net/6/docs/ref/#language.LRLanguage)
|
|
38
|
+
subclass for [Lezer](https://lezer.codemirror.net/) LR parsers, or
|
|
39
|
+
via the [`StreamLanguage`](https://codemirror.net/6/docs/ref/#language.StreamLanguage) subclass
|
|
40
|
+
for stream parsers.
|
|
38
41
|
*/
|
|
39
42
|
declare class Language {
|
|
40
43
|
/**
|
|
41
|
-
The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt)
|
|
42
|
-
|
|
44
|
+
The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
|
|
45
|
+
used for this language.
|
|
43
46
|
*/
|
|
44
47
|
readonly data: Facet<{
|
|
45
48
|
[name: string]: any;
|
|
46
49
|
}>;
|
|
47
50
|
/**
|
|
48
|
-
The
|
|
49
|
-
*/
|
|
50
|
-
readonly topNode: NodeType;
|
|
51
|
-
/**
|
|
52
|
-
The extension value to install this provider.
|
|
51
|
+
The extension value to install this as the document language.
|
|
53
52
|
*/
|
|
54
53
|
readonly extension: Extension;
|
|
55
54
|
/**
|
|
@@ -58,23 +57,20 @@ declare class Language {
|
|
|
58
57
|
*/
|
|
59
58
|
parser: Parser;
|
|
60
59
|
/**
|
|
61
|
-
Construct a language object.
|
|
62
|
-
|
|
63
|
-
[`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet)
|
|
64
|
-
|
|
60
|
+
Construct a language object. If you need to invoke this
|
|
61
|
+
directly, first define a data facet with
|
|
62
|
+
[`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
|
|
63
|
+
configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
|
|
64
|
+
to the language's outer syntax node.
|
|
65
65
|
*/
|
|
66
66
|
constructor(
|
|
67
67
|
/**
|
|
68
|
-
The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt)
|
|
69
|
-
|
|
68
|
+
The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
|
|
69
|
+
used for this language.
|
|
70
70
|
*/
|
|
71
71
|
data: Facet<{
|
|
72
72
|
[name: string]: any;
|
|
73
|
-
}>, parser: Parser,
|
|
74
|
-
/**
|
|
75
|
-
The node type of the top node of trees produced by this parser.
|
|
76
|
-
*/
|
|
77
|
-
topNode: NodeType, extraExtensions?: Extension[]);
|
|
73
|
+
}>, parser: Parser, extraExtensions?: Extension[]);
|
|
78
74
|
/**
|
|
79
75
|
Query whether this language is active at the given position.
|
|
80
76
|
*/
|
|
@@ -129,8 +125,9 @@ declare class LRLanguage extends Language {
|
|
|
129
125
|
}
|
|
130
126
|
/**
|
|
131
127
|
Get the syntax tree for a state, which is the current (possibly
|
|
132
|
-
incomplete) parse tree of active
|
|
133
|
-
or the empty tree if there is no
|
|
128
|
+
incomplete) parse tree of the active
|
|
129
|
+
[language](https://codemirror.net/6/docs/ref/#language.Language), or the empty tree if there is no
|
|
130
|
+
language available.
|
|
134
131
|
*/
|
|
135
132
|
declare function syntaxTree(state: EditorState): Tree;
|
|
136
133
|
/**
|
|
@@ -144,12 +141,19 @@ Queries whether there is a full syntax tree available up to the
|
|
|
144
141
|
given document position. If there isn't, the background parse
|
|
145
142
|
process _might_ still be working and update the tree further, but
|
|
146
143
|
there is no guarantee of that—the parser will [stop
|
|
147
|
-
working](https://codemirror.net/6/docs/ref/#language.
|
|
144
|
+
working](https://codemirror.net/6/docs/ref/#language.syntaxParserRunning) when it has spent a
|
|
148
145
|
certain amount of time or has moved beyond the visible viewport.
|
|
149
146
|
Always returns false if no language has been enabled.
|
|
150
147
|
*/
|
|
151
148
|
declare function syntaxTreeAvailable(state: EditorState, upto?: number): boolean;
|
|
152
149
|
/**
|
|
150
|
+
Move parsing forward, and update the editor state afterwards to
|
|
151
|
+
reflect the new tree. Will work for at most `timeout`
|
|
152
|
+
milliseconds. Returns true if the parser managed get to the given
|
|
153
|
+
position in that time.
|
|
154
|
+
*/
|
|
155
|
+
declare function forceParsing(view: EditorView, upto?: number, timeout?: number): boolean;
|
|
156
|
+
/**
|
|
153
157
|
Tells you whether the language parser is planning to do more
|
|
154
158
|
parsing work (in a `requestIdleCallback` pseudo-thread) or has
|
|
155
159
|
stopped running, either because it parsed the entire document,
|
|
@@ -170,7 +174,6 @@ declare class ParseContext {
|
|
|
170
174
|
Tree fragments that can be reused by incremental re-parses.
|
|
171
175
|
*/
|
|
172
176
|
fragments: readonly TreeFragment[];
|
|
173
|
-
treeLen: number;
|
|
174
177
|
/**
|
|
175
178
|
The current editor viewport (or some overapproximation
|
|
176
179
|
thereof). Intended to be used for opportunistically avoiding
|
|
@@ -184,6 +187,7 @@ declare class ParseContext {
|
|
|
184
187
|
to: number;
|
|
185
188
|
};
|
|
186
189
|
private parse;
|
|
190
|
+
private constructor();
|
|
187
191
|
private startParse;
|
|
188
192
|
private withContext;
|
|
189
193
|
private withoutTempSkipped;
|
|
@@ -202,20 +206,7 @@ declare class ParseContext {
|
|
|
202
206
|
When `until` is given, a reparse will be scheduled when that
|
|
203
207
|
promise resolves.
|
|
204
208
|
*/
|
|
205
|
-
static getSkippingParser(until?: Promise<unknown>):
|
|
206
|
-
createParse(input: Input, fragments: readonly TreeFragment[], ranges: readonly {
|
|
207
|
-
from: number;
|
|
208
|
-
to: number;
|
|
209
|
-
}[]): PartialParse;
|
|
210
|
-
startParse(input: string | Input, fragments?: readonly TreeFragment[] | undefined, ranges?: readonly {
|
|
211
|
-
from: number;
|
|
212
|
-
to: number;
|
|
213
|
-
}[] | undefined): PartialParse;
|
|
214
|
-
parse(input: string | Input, fragments?: readonly TreeFragment[] | undefined, ranges?: readonly {
|
|
215
|
-
from: number;
|
|
216
|
-
to: number;
|
|
217
|
-
}[] | undefined): Tree;
|
|
218
|
-
};
|
|
209
|
+
static getSkippingParser(until?: Promise<unknown>): Parser;
|
|
219
210
|
/**
|
|
220
211
|
Get the context for the current parse, or `null` if no editor
|
|
221
212
|
parse is in progress.
|
|
@@ -227,7 +218,7 @@ The facet used to associate a language with an editor state.
|
|
|
227
218
|
*/
|
|
228
219
|
declare const language: Facet<Language, Language | null>;
|
|
229
220
|
/**
|
|
230
|
-
This class bundles a [language
|
|
221
|
+
This class bundles a [language](https://codemirror.net/6/docs/ref/#language.Language) with an
|
|
231
222
|
optional set of supporting extensions. Language packages are
|
|
232
223
|
encouraged to export a function that optionally takes a
|
|
233
224
|
configuration object and returns a `LanguageSupport` instance, as
|
|
@@ -252,7 +243,7 @@ declare class LanguageSupport {
|
|
|
252
243
|
*/
|
|
253
244
|
extension: Extension;
|
|
254
245
|
/**
|
|
255
|
-
Create a support object.
|
|
246
|
+
Create a language support object.
|
|
256
247
|
*/
|
|
257
248
|
constructor(
|
|
258
249
|
/**
|
|
@@ -484,7 +475,7 @@ definitive indentation can be determined.
|
|
|
484
475
|
declare const indentNodeProp: NodeProp<(context: TreeIndentContext) => number | null>;
|
|
485
476
|
/**
|
|
486
477
|
Objects of this type provide context information and helper
|
|
487
|
-
methods to indentation functions.
|
|
478
|
+
methods to indentation functions registered on syntax nodes.
|
|
488
479
|
*/
|
|
489
480
|
declare class TreeIndentContext extends IndentContext {
|
|
490
481
|
private base;
|
|
@@ -497,6 +488,7 @@ declare class TreeIndentContext extends IndentContext {
|
|
|
497
488
|
applies.
|
|
498
489
|
*/
|
|
499
490
|
readonly node: SyntaxNode;
|
|
491
|
+
private constructor();
|
|
500
492
|
/**
|
|
501
493
|
Get the text directly after `this.pos`, either the entire line
|
|
502
494
|
or the next 100 characters, whichever is shorter.
|
|
@@ -608,5 +600,460 @@ declare function foldable(state: EditorState, lineStart: number, lineEnd: number
|
|
|
608
600
|
from: number;
|
|
609
601
|
to: number;
|
|
610
602
|
} | null;
|
|
603
|
+
declare type DocRange = {
|
|
604
|
+
from: number;
|
|
605
|
+
to: number;
|
|
606
|
+
};
|
|
607
|
+
/**
|
|
608
|
+
State effect that can be attached to a transaction to fold the
|
|
609
|
+
given range. (You probably only need this in exceptional
|
|
610
|
+
circumstances—usually you'll just want to let
|
|
611
|
+
[`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode) and the [fold
|
|
612
|
+
gutter](https://codemirror.net/6/docs/ref/#language.foldGutter) create the transactions.)
|
|
613
|
+
*/
|
|
614
|
+
declare const foldEffect: _codemirror_state.StateEffectType<DocRange>;
|
|
615
|
+
/**
|
|
616
|
+
State effect that unfolds the given range (if it was folded).
|
|
617
|
+
*/
|
|
618
|
+
declare const unfoldEffect: _codemirror_state.StateEffectType<DocRange>;
|
|
619
|
+
/**
|
|
620
|
+
Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
|
|
621
|
+
in the given state.
|
|
622
|
+
*/
|
|
623
|
+
declare function foldedRanges(state: EditorState): DecorationSet;
|
|
624
|
+
/**
|
|
625
|
+
Fold the lines that are selected, if possible.
|
|
626
|
+
*/
|
|
627
|
+
declare const foldCode: Command;
|
|
628
|
+
/**
|
|
629
|
+
Unfold folded ranges on selected lines.
|
|
630
|
+
*/
|
|
631
|
+
declare const unfoldCode: Command;
|
|
632
|
+
/**
|
|
633
|
+
Fold all top-level foldable ranges. Note that, in most cases,
|
|
634
|
+
folding information will depend on the [syntax
|
|
635
|
+
tree](https://codemirror.net/6/docs/ref/#language.syntaxTree), and folding everything may not work
|
|
636
|
+
reliably when the document hasn't been fully parsed (either
|
|
637
|
+
because the editor state was only just initialized, or because the
|
|
638
|
+
document is so big that the parser decided not to parse it
|
|
639
|
+
entirely).
|
|
640
|
+
*/
|
|
641
|
+
declare const foldAll: Command;
|
|
642
|
+
/**
|
|
643
|
+
Unfold all folded code.
|
|
644
|
+
*/
|
|
645
|
+
declare const unfoldAll: Command;
|
|
646
|
+
/**
|
|
647
|
+
Default fold-related key bindings.
|
|
648
|
+
|
|
649
|
+
- Ctrl-Shift-[ (Cmd-Alt-[ on macOS): [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode).
|
|
650
|
+
- Ctrl-Shift-] (Cmd-Alt-] on macOS): [`unfoldCode`](https://codemirror.net/6/docs/ref/#language.unfoldCode).
|
|
651
|
+
- Ctrl-Alt-[: [`foldAll`](https://codemirror.net/6/docs/ref/#language.foldAll).
|
|
652
|
+
- Ctrl-Alt-]: [`unfoldAll`](https://codemirror.net/6/docs/ref/#language.unfoldAll).
|
|
653
|
+
*/
|
|
654
|
+
declare const foldKeymap: readonly KeyBinding[];
|
|
655
|
+
interface FoldConfig {
|
|
656
|
+
/**
|
|
657
|
+
A function that creates the DOM element used to indicate the
|
|
658
|
+
position of folded code. The `onclick` argument is the default
|
|
659
|
+
click event handler, which toggles folding on the line that
|
|
660
|
+
holds the element, and should probably be added as an event
|
|
661
|
+
handler to the returned element.
|
|
662
|
+
|
|
663
|
+
When this option isn't given, the `placeholderText` option will
|
|
664
|
+
be used to create the placeholder element.
|
|
665
|
+
*/
|
|
666
|
+
placeholderDOM?: ((view: EditorView, onclick: (event: Event) => void) => HTMLElement) | null;
|
|
667
|
+
/**
|
|
668
|
+
Text to use as placeholder for folded text. Defaults to `"…"`.
|
|
669
|
+
Will be styled with the `"cm-foldPlaceholder"` class.
|
|
670
|
+
*/
|
|
671
|
+
placeholderText?: string;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
Create an extension that configures code folding.
|
|
675
|
+
*/
|
|
676
|
+
declare function codeFolding(config?: FoldConfig): Extension;
|
|
677
|
+
declare type Handlers = {
|
|
678
|
+
[event: string]: (view: EditorView, line: BlockInfo, event: Event) => boolean;
|
|
679
|
+
};
|
|
680
|
+
interface FoldGutterConfig {
|
|
681
|
+
/**
|
|
682
|
+
A function that creates the DOM element used to indicate a
|
|
683
|
+
given line is folded or can be folded.
|
|
684
|
+
When not given, the `openText`/`closeText` option will be used instead.
|
|
685
|
+
*/
|
|
686
|
+
markerDOM?: ((open: boolean) => HTMLElement) | null;
|
|
687
|
+
/**
|
|
688
|
+
Text used to indicate that a given line can be folded.
|
|
689
|
+
Defaults to `"⌄"`.
|
|
690
|
+
*/
|
|
691
|
+
openText?: string;
|
|
692
|
+
/**
|
|
693
|
+
Text used to indicate that a given line is folded.
|
|
694
|
+
Defaults to `"›"`.
|
|
695
|
+
*/
|
|
696
|
+
closedText?: string;
|
|
697
|
+
/**
|
|
698
|
+
Supply event handlers for DOM events on this gutter.
|
|
699
|
+
*/
|
|
700
|
+
domEventHandlers?: Handlers;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
Create an extension that registers a fold gutter, which shows a
|
|
704
|
+
fold status indicator before foldable lines (which can be clicked
|
|
705
|
+
to fold or unfold the line).
|
|
706
|
+
*/
|
|
707
|
+
declare function foldGutter(config?: FoldGutterConfig): Extension;
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
A highlight style associates CSS styles with higlighting
|
|
711
|
+
[tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
|
|
712
|
+
*/
|
|
713
|
+
declare class HighlightStyle implements Highlighter {
|
|
714
|
+
/**
|
|
715
|
+
A style module holding the CSS rules for this highlight style.
|
|
716
|
+
When using
|
|
717
|
+
[`highlightTree`](https://lezer.codemirror.net/docs/ref#highlight.highlightTree)
|
|
718
|
+
outside of the editor, you may want to manually mount this
|
|
719
|
+
module to show the highlighting.
|
|
720
|
+
*/
|
|
721
|
+
readonly module: StyleModule | null;
|
|
722
|
+
readonly style: (tags: readonly Tag[]) => string | null;
|
|
723
|
+
readonly scope: ((type: NodeType) => boolean) | undefined;
|
|
724
|
+
private constructor();
|
|
725
|
+
/**
|
|
726
|
+
Create a highlighter style that associates the given styles to
|
|
727
|
+
the given tags. The specs must be objects that hold a style tag
|
|
728
|
+
or array of tags in their `tag` property, and either a single
|
|
729
|
+
`class` property providing a static CSS class (for highlighter
|
|
730
|
+
that rely on external styling), or a
|
|
731
|
+
[`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
|
|
732
|
+
set of CSS properties (which define the styling for those tags).
|
|
733
|
+
|
|
734
|
+
The CSS rules created for a highlighter will be emitted in the
|
|
735
|
+
order of the spec's properties. That means that for elements that
|
|
736
|
+
have multiple tags associated with them, styles defined further
|
|
737
|
+
down in the list will have a higher CSS precedence than styles
|
|
738
|
+
defined earlier.
|
|
739
|
+
*/
|
|
740
|
+
static define(specs: readonly TagStyle[], options?: {
|
|
741
|
+
/**
|
|
742
|
+
By default, highlighters apply to the entire document. You can
|
|
743
|
+
scope them to a single language by providing the language
|
|
744
|
+
object or a language's top node type here.
|
|
745
|
+
*/
|
|
746
|
+
scope?: Language | NodeType;
|
|
747
|
+
/**
|
|
748
|
+
Add a style to _all_ content. Probably only useful in
|
|
749
|
+
combination with `scope`.
|
|
750
|
+
*/
|
|
751
|
+
all?: string | StyleSpec;
|
|
752
|
+
/**
|
|
753
|
+
Specify that this highlight style should only be active then
|
|
754
|
+
the theme is dark or light. By default, it is active
|
|
755
|
+
regardless of theme.
|
|
756
|
+
*/
|
|
757
|
+
themeType?: "dark" | "light";
|
|
758
|
+
}): HighlightStyle;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
Wrap a highlighter in an editor extension that uses it to apply
|
|
762
|
+
syntax highlighting to the editor content.
|
|
763
|
+
|
|
764
|
+
When multiple (non-fallback) styles are provided, the styling
|
|
765
|
+
applied is the union of the classes they emit.
|
|
766
|
+
*/
|
|
767
|
+
declare function syntaxHighlighting(highlighter: Highlighter, options?: {
|
|
768
|
+
/**
|
|
769
|
+
When enabled, this marks the highlighter as a fallback, which
|
|
770
|
+
only takes effect if no other highlighters are registered.
|
|
771
|
+
*/
|
|
772
|
+
fallback: boolean;
|
|
773
|
+
}): Extension;
|
|
774
|
+
/**
|
|
775
|
+
Returns the CSS classes (if any) that the highlighters active in
|
|
776
|
+
the state would assign to the given style
|
|
777
|
+
[tags](https://lezer.codemirror.net/docs/ref#highlight.Tag) and
|
|
778
|
+
(optional) language
|
|
779
|
+
[scope](https://codemirror.net/6/docs/ref/#language.HighlightStyle^define^options.scope).
|
|
780
|
+
*/
|
|
781
|
+
declare function highlightingFor(state: EditorState, tags: readonly Tag[], scope?: NodeType): string | null;
|
|
782
|
+
/**
|
|
783
|
+
The type of object used in
|
|
784
|
+
[`HighlightStyle.define`](https://codemirror.net/6/docs/ref/#language.HighlightStyle^define).
|
|
785
|
+
Assigns a style to one or more highlighting
|
|
786
|
+
[tags](https://lezer.codemirror.net/docs/ref#highlight.Tag), which can either be a fixed class name
|
|
787
|
+
(which must be defined elsewhere), or a set of CSS properties, for
|
|
788
|
+
which the library will define an anonymous class.
|
|
789
|
+
*/
|
|
790
|
+
interface TagStyle {
|
|
791
|
+
/**
|
|
792
|
+
The tag or tags to target.
|
|
793
|
+
*/
|
|
794
|
+
tag: Tag | readonly Tag[];
|
|
795
|
+
/**
|
|
796
|
+
If given, this maps the tags to a fixed class name.
|
|
797
|
+
*/
|
|
798
|
+
class?: string;
|
|
799
|
+
/**
|
|
800
|
+
Any further properties (if `class` isn't given) will be
|
|
801
|
+
interpreted as in style objects given to
|
|
802
|
+
[style-mod](https://github.com/marijnh/style-mod#documentation).
|
|
803
|
+
(The type here is `any` because of TypeScript limitations.)
|
|
804
|
+
*/
|
|
805
|
+
[styleProperty: string]: any;
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
A default highlight style (works well with light themes).
|
|
809
|
+
*/
|
|
810
|
+
declare const defaultHighlightStyle: HighlightStyle;
|
|
811
|
+
|
|
812
|
+
interface Config {
|
|
813
|
+
/**
|
|
814
|
+
Whether the bracket matching should look at the character after
|
|
815
|
+
the cursor when matching (if the one before isn't a bracket).
|
|
816
|
+
Defaults to true.
|
|
817
|
+
*/
|
|
818
|
+
afterCursor?: boolean;
|
|
819
|
+
/**
|
|
820
|
+
The bracket characters to match, as a string of pairs. Defaults
|
|
821
|
+
to `"()[]{}"`. Note that these are only used as fallback when
|
|
822
|
+
there is no [matching
|
|
823
|
+
information](https://lezer.codemirror.net/docs/ref/#common.NodeProp^closedBy)
|
|
824
|
+
in the syntax tree.
|
|
825
|
+
*/
|
|
826
|
+
brackets?: string;
|
|
827
|
+
/**
|
|
828
|
+
The maximum distance to scan for matching brackets. This is only
|
|
829
|
+
relevant for brackets not encoded in the syntax tree. Defaults
|
|
830
|
+
to 10 000.
|
|
831
|
+
*/
|
|
832
|
+
maxScanDistance?: number;
|
|
833
|
+
/**
|
|
834
|
+
Can be used to configure the way in which brackets are
|
|
835
|
+
decorated. The default behavior is to add the
|
|
836
|
+
`cm-matchingBracket` class for matching pairs, and
|
|
837
|
+
`cm-nonmatchingBracket` for mismatched pairs or single brackets.
|
|
838
|
+
*/
|
|
839
|
+
renderMatch?: (match: MatchResult, state: EditorState) => readonly Range<Decoration>[];
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
Create an extension that enables bracket matching. Whenever the
|
|
843
|
+
cursor is next to a bracket, that bracket and the one it matches
|
|
844
|
+
are highlighted. Or, when no matching bracket is found, another
|
|
845
|
+
highlighting style is used to indicate this.
|
|
846
|
+
*/
|
|
847
|
+
declare function bracketMatching(config?: Config): Extension;
|
|
848
|
+
/**
|
|
849
|
+
The result returned from `matchBrackets`.
|
|
850
|
+
*/
|
|
851
|
+
interface MatchResult {
|
|
852
|
+
/**
|
|
853
|
+
The extent of the bracket token found.
|
|
854
|
+
*/
|
|
855
|
+
start: {
|
|
856
|
+
from: number;
|
|
857
|
+
to: number;
|
|
858
|
+
};
|
|
859
|
+
/**
|
|
860
|
+
The extent of the matched token, if any was found.
|
|
861
|
+
*/
|
|
862
|
+
end?: {
|
|
863
|
+
from: number;
|
|
864
|
+
to: number;
|
|
865
|
+
};
|
|
866
|
+
/**
|
|
867
|
+
Whether the tokens match. This can be false even when `end` has
|
|
868
|
+
a value, if that token doesn't match the opening token.
|
|
869
|
+
*/
|
|
870
|
+
matched: boolean;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
Find the matching bracket for the token at `pos`, scanning
|
|
874
|
+
direction `dir`. Only the `brackets` and `maxScanDistance`
|
|
875
|
+
properties are used from `config`, if given. Returns null if no
|
|
876
|
+
bracket was found at `pos`, or a match result otherwise.
|
|
877
|
+
*/
|
|
878
|
+
declare function matchBrackets(state: EditorState, pos: number, dir: -1 | 1, config?: Config): MatchResult | null;
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
Encapsulates a single line of input. Given to stream syntax code,
|
|
882
|
+
which uses it to tokenize the content.
|
|
883
|
+
*/
|
|
884
|
+
declare class StringStream {
|
|
885
|
+
/**
|
|
886
|
+
The line.
|
|
887
|
+
*/
|
|
888
|
+
string: string;
|
|
889
|
+
private tabSize;
|
|
890
|
+
/**
|
|
891
|
+
The current indent unit size.
|
|
892
|
+
*/
|
|
893
|
+
indentUnit: number;
|
|
894
|
+
/**
|
|
895
|
+
The current position on the line.
|
|
896
|
+
*/
|
|
897
|
+
pos: number;
|
|
898
|
+
/**
|
|
899
|
+
The start position of the current token.
|
|
900
|
+
*/
|
|
901
|
+
start: number;
|
|
902
|
+
private lastColumnPos;
|
|
903
|
+
private lastColumnValue;
|
|
904
|
+
/**
|
|
905
|
+
Create a stream.
|
|
906
|
+
*/
|
|
907
|
+
constructor(
|
|
908
|
+
/**
|
|
909
|
+
The line.
|
|
910
|
+
*/
|
|
911
|
+
string: string, tabSize: number,
|
|
912
|
+
/**
|
|
913
|
+
The current indent unit size.
|
|
914
|
+
*/
|
|
915
|
+
indentUnit: number);
|
|
916
|
+
/**
|
|
917
|
+
True if we are at the end of the line.
|
|
918
|
+
*/
|
|
919
|
+
eol(): boolean;
|
|
920
|
+
/**
|
|
921
|
+
True if we are at the start of the line.
|
|
922
|
+
*/
|
|
923
|
+
sol(): boolean;
|
|
924
|
+
/**
|
|
925
|
+
Get the next code unit after the current position, or undefined
|
|
926
|
+
if we're at the end of the line.
|
|
927
|
+
*/
|
|
928
|
+
peek(): string | undefined;
|
|
929
|
+
/**
|
|
930
|
+
Read the next code unit and advance `this.pos`.
|
|
931
|
+
*/
|
|
932
|
+
next(): string | void;
|
|
933
|
+
/**
|
|
934
|
+
Match the next character against the given string, regular
|
|
935
|
+
expression, or predicate. Consume and return it if it matches.
|
|
936
|
+
*/
|
|
937
|
+
eat(match: string | RegExp | ((ch: string) => boolean)): string | void;
|
|
938
|
+
/**
|
|
939
|
+
Continue matching characters that match the given string,
|
|
940
|
+
regular expression, or predicate function. Return true if any
|
|
941
|
+
characters were consumed.
|
|
942
|
+
*/
|
|
943
|
+
eatWhile(match: string | RegExp | ((ch: string) => boolean)): boolean;
|
|
944
|
+
/**
|
|
945
|
+
Consume whitespace ahead of `this.pos`. Return true if any was
|
|
946
|
+
found.
|
|
947
|
+
*/
|
|
948
|
+
eatSpace(): boolean;
|
|
949
|
+
/**
|
|
950
|
+
Move to the end of the line.
|
|
951
|
+
*/
|
|
952
|
+
skipToEnd(): void;
|
|
953
|
+
/**
|
|
954
|
+
Move to directly before the given character, if found on the
|
|
955
|
+
current line.
|
|
956
|
+
*/
|
|
957
|
+
skipTo(ch: string): boolean | void;
|
|
958
|
+
/**
|
|
959
|
+
Move back `n` characters.
|
|
960
|
+
*/
|
|
961
|
+
backUp(n: number): void;
|
|
962
|
+
/**
|
|
963
|
+
Get the column position at `this.pos`.
|
|
964
|
+
*/
|
|
965
|
+
column(): number;
|
|
966
|
+
/**
|
|
967
|
+
Get the indentation column of the current line.
|
|
968
|
+
*/
|
|
969
|
+
indentation(): number;
|
|
970
|
+
/**
|
|
971
|
+
Match the input against the given string or regular expression
|
|
972
|
+
(which should start with a `^`). Return true or the regexp match
|
|
973
|
+
if it matches.
|
|
974
|
+
|
|
975
|
+
Unless `consume` is set to `false`, this will move `this.pos`
|
|
976
|
+
past the matched text.
|
|
977
|
+
|
|
978
|
+
When matching a string `caseInsensitive` can be set to true to
|
|
979
|
+
make the match case-insensitive.
|
|
980
|
+
*/
|
|
981
|
+
match(pattern: string | RegExp, consume?: boolean, caseInsensitive?: boolean): boolean | RegExpMatchArray | null;
|
|
982
|
+
/**
|
|
983
|
+
Get the current token.
|
|
984
|
+
*/
|
|
985
|
+
current(): string;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
A stream parser parses or tokenizes content from start to end,
|
|
990
|
+
emitting tokens as it goes over it. It keeps a mutable (but
|
|
991
|
+
copyable) object with state, in which it can store information
|
|
992
|
+
about the current context.
|
|
993
|
+
*/
|
|
994
|
+
interface StreamParser<State> {
|
|
995
|
+
/**
|
|
996
|
+
Produce a start state for the parser.
|
|
997
|
+
*/
|
|
998
|
+
startState?(indentUnit: number): State;
|
|
999
|
+
/**
|
|
1000
|
+
Read one token, advancing the stream past it, and returning a
|
|
1001
|
+
string indicating the token's style tag—either the name of one
|
|
1002
|
+
of the tags in
|
|
1003
|
+
[`tags`](https://lezer.codemirror.net/docs/ref#highlight.tags),
|
|
1004
|
+
or such a name suffixed by one or more tag
|
|
1005
|
+
[modifier](https://lezer.codemirror.net/docs/ref#highlight.Tag^defineModifier)
|
|
1006
|
+
names, separated by periods. For example `"keyword"` or
|
|
1007
|
+
"`variableName.constant"`.
|
|
1008
|
+
|
|
1009
|
+
It is okay to return a zero-length token, but only if that
|
|
1010
|
+
updates the state so that the next call will return a non-empty
|
|
1011
|
+
token again.
|
|
1012
|
+
*/
|
|
1013
|
+
token(stream: StringStream, state: State): string | null;
|
|
1014
|
+
/**
|
|
1015
|
+
This notifies the parser of a blank line in the input. It can
|
|
1016
|
+
update its state here if it needs to.
|
|
1017
|
+
*/
|
|
1018
|
+
blankLine?(state: State, indentUnit: number): void;
|
|
1019
|
+
/**
|
|
1020
|
+
Copy a given state. By default, a shallow object copy is done
|
|
1021
|
+
which also copies arrays held at the top level of the object.
|
|
1022
|
+
*/
|
|
1023
|
+
copyState?(state: State): State;
|
|
1024
|
+
/**
|
|
1025
|
+
Compute automatic indentation for the line that starts with the
|
|
1026
|
+
given state and text.
|
|
1027
|
+
*/
|
|
1028
|
+
indent?(state: State, textAfter: string, context: IndentContext): number | null;
|
|
1029
|
+
/**
|
|
1030
|
+
Default [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) to
|
|
1031
|
+
attach to this language.
|
|
1032
|
+
*/
|
|
1033
|
+
languageData?: {
|
|
1034
|
+
[name: string]: any;
|
|
1035
|
+
};
|
|
1036
|
+
/**
|
|
1037
|
+
Extra tokens to use in this parser. When the tokenizer returns a
|
|
1038
|
+
token name that exists as a property in this object, the
|
|
1039
|
+
corresponding tag will be assigned to the token.
|
|
1040
|
+
*/
|
|
1041
|
+
tokenTable?: {
|
|
1042
|
+
[name: string]: Tag;
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
|
|
1047
|
+
5-style [streaming parser](https://codemirror.net/6/docs/ref/#language.StreamParser).
|
|
1048
|
+
*/
|
|
1049
|
+
declare class StreamLanguage<State> extends Language {
|
|
1050
|
+
private constructor();
|
|
1051
|
+
/**
|
|
1052
|
+
Define a stream language.
|
|
1053
|
+
*/
|
|
1054
|
+
static define<State>(spec: StreamParser<State>): StreamLanguage<State>;
|
|
1055
|
+
private getIndent;
|
|
1056
|
+
get allowsNesting(): boolean;
|
|
1057
|
+
}
|
|
611
1058
|
|
|
612
|
-
export { IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, TreeIndentContext, continuedIndent, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldInside, foldNodeProp, foldService, foldable, getIndentUnit, getIndentation, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, syntaxParserRunning, syntaxTree, syntaxTreeAvailable };
|
|
1059
|
+
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, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
|