@codemirror/language 6.7.0 → 6.8.0

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.
@@ -0,0 +1,1185 @@
1
+ import { NodeProp, SyntaxNode, Parser, Tree, Input, TreeFragment, NodeType } from '@lezer/common';
2
+ import { LRParser, ParserConfig } from '@lezer/lr';
3
+ import * as _codemirror_state from '@codemirror/state';
4
+ import { Facet, EditorState, Extension, Text, StateField, Range } from '@codemirror/state';
5
+ import { EditorView, DecorationSet, Command, KeyBinding, ViewUpdate, BlockInfo, Decoration } from '@codemirror/view';
6
+ import { Highlighter, Tag } from '@lezer/highlight';
7
+ import { StyleModule, StyleSpec } from 'style-mod';
8
+
9
+ /**
10
+ Node prop stored in a parser's top syntax node to provide the
11
+ facet that stores language-specific data for that language.
12
+ */
13
+ declare const languageDataProp: NodeProp<Facet<{
14
+ [name: string]: any;
15
+ }, readonly {
16
+ [name: string]: any;
17
+ }[]>>;
18
+ /**
19
+ Helper function to define a facet (to be added to the top syntax
20
+ node(s) for a language via
21
+ [`languageDataProp`](https://codemirror.net/6/docs/ref/#language.languageDataProp)), that will be
22
+ used to associate language data with the language. You
23
+ probably only need this when subclassing
24
+ [`Language`](https://codemirror.net/6/docs/ref/#language.Language).
25
+ */
26
+ declare function defineLanguageFacet(baseData?: {
27
+ [name: string]: any;
28
+ }): Facet<{
29
+ [name: string]: any;
30
+ }, readonly {
31
+ [name: string]: any;
32
+ }[]>;
33
+ /**
34
+ Some languages need to return different [language
35
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) for some parts of their
36
+ tree. Sublanguages, registered by adding a [node
37
+ prop](https://codemirror.net/6/docs/ref/#language.sublanguageProp) to the language's top syntax
38
+ node, provide a mechanism to do this.
39
+
40
+ (Note that when using nested parsing, where nested syntax is
41
+ parsed by a different parser and has its own top node type, you
42
+ don't need a sublanguage.)
43
+ */
44
+ interface Sublanguage {
45
+ /**
46
+ Determines whether the data provided by this sublanguage should
47
+ completely replace the regular data or be added to it (with
48
+ higher-precedence). The default is `"extend"`.
49
+ */
50
+ type?: "replace" | "extend";
51
+ /**
52
+ A predicate that returns whether the node at the queried
53
+ position is part of the sublanguage.
54
+ */
55
+ test: (node: SyntaxNode, state: EditorState) => boolean;
56
+ /**
57
+ The language data facet that holds the sublanguage's data.
58
+ You'll want to use
59
+ [`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet) to create
60
+ this.
61
+ */
62
+ facet: Facet<{
63
+ [name: string]: any;
64
+ }>;
65
+ }
66
+ /**
67
+ Syntax node prop used to register sublanguages. Should be added to
68
+ the top level node type for the language.
69
+ */
70
+ declare const sublanguageProp: NodeProp<Sublanguage[]>;
71
+ /**
72
+ A language object manages parsing and per-language
73
+ [metadata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). Parse data is
74
+ managed as a [Lezer](https://lezer.codemirror.net) tree. The class
75
+ can be used directly, via the [`LRLanguage`](https://codemirror.net/6/docs/ref/#language.LRLanguage)
76
+ subclass for [Lezer](https://lezer.codemirror.net/) LR parsers, or
77
+ via the [`StreamLanguage`](https://codemirror.net/6/docs/ref/#language.StreamLanguage) subclass
78
+ for stream parsers.
79
+ */
80
+ declare class Language {
81
+ /**
82
+ The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
83
+ used for this language.
84
+ */
85
+ readonly data: Facet<{
86
+ [name: string]: any;
87
+ }>;
88
+ /**
89
+ A language name.
90
+ */
91
+ readonly name: string;
92
+ /**
93
+ The extension value to install this as the document language.
94
+ */
95
+ readonly extension: Extension;
96
+ /**
97
+ The parser object. Can be useful when using this as a [nested
98
+ parser](https://lezer.codemirror.net/docs/ref#common.Parser).
99
+ */
100
+ parser: Parser;
101
+ /**
102
+ Construct a language object. If you need to invoke this
103
+ directly, first define a data facet with
104
+ [`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
105
+ configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
106
+ to the language's outer syntax node.
107
+ */
108
+ constructor(
109
+ /**
110
+ The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
111
+ used for this language.
112
+ */
113
+ data: Facet<{
114
+ [name: string]: any;
115
+ }>, parser: Parser, extraExtensions?: Extension[],
116
+ /**
117
+ A language name.
118
+ */
119
+ name?: string);
120
+ /**
121
+ Query whether this language is active at the given position.
122
+ */
123
+ isActiveAt(state: EditorState, pos: number, side?: -1 | 0 | 1): boolean;
124
+ /**
125
+ Find the document regions that were parsed using this language.
126
+ The returned regions will _include_ any nested languages rooted
127
+ in this language, when those exist.
128
+ */
129
+ findRegions(state: EditorState): {
130
+ from: number;
131
+ to: number;
132
+ }[];
133
+ /**
134
+ Indicates whether this language allows nested languages. The
135
+ default implementation returns true.
136
+ */
137
+ get allowsNesting(): boolean;
138
+ }
139
+ /**
140
+ A subclass of [`Language`](https://codemirror.net/6/docs/ref/#language.Language) for use with Lezer
141
+ [LR parsers](https://lezer.codemirror.net/docs/ref#lr.LRParser)
142
+ parsers.
143
+ */
144
+ declare class LRLanguage extends Language {
145
+ readonly parser: LRParser;
146
+ private constructor();
147
+ /**
148
+ Define a language from a parser.
149
+ */
150
+ static define(spec: {
151
+ /**
152
+ The [name](https://codemirror.net/6/docs/ref/#Language.name) of the language.
153
+ */
154
+ name?: string;
155
+ /**
156
+ The parser to use. Should already have added editor-relevant
157
+ node props (and optionally things like dialect and top rule)
158
+ configured.
159
+ */
160
+ parser: LRParser;
161
+ /**
162
+ [Language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt)
163
+ to register for this language.
164
+ */
165
+ languageData?: {
166
+ [name: string]: any;
167
+ };
168
+ }): LRLanguage;
169
+ /**
170
+ Create a new instance of this language with a reconfigured
171
+ version of its parser and optionally a new name.
172
+ */
173
+ configure(options: ParserConfig, name?: string): LRLanguage;
174
+ get allowsNesting(): boolean;
175
+ }
176
+ /**
177
+ Get the syntax tree for a state, which is the current (possibly
178
+ incomplete) parse tree of the active
179
+ [language](https://codemirror.net/6/docs/ref/#language.Language), or the empty tree if there is no
180
+ language available.
181
+ */
182
+ declare function syntaxTree(state: EditorState): Tree;
183
+ /**
184
+ Try to get a parse tree that spans at least up to `upto`. The
185
+ method will do at most `timeout` milliseconds of work to parse
186
+ up to that point if the tree isn't already available.
187
+ */
188
+ declare function ensureSyntaxTree(state: EditorState, upto: number, timeout?: number): Tree | null;
189
+ /**
190
+ Queries whether there is a full syntax tree available up to the
191
+ given document position. If there isn't, the background parse
192
+ process _might_ still be working and update the tree further, but
193
+ there is no guarantee of that—the parser will [stop
194
+ working](https://codemirror.net/6/docs/ref/#language.syntaxParserRunning) when it has spent a
195
+ certain amount of time or has moved beyond the visible viewport.
196
+ Always returns false if no language has been enabled.
197
+ */
198
+ declare function syntaxTreeAvailable(state: EditorState, upto?: number): boolean;
199
+ /**
200
+ Move parsing forward, and update the editor state afterwards to
201
+ reflect the new tree. Will work for at most `timeout`
202
+ milliseconds. Returns true if the parser managed get to the given
203
+ position in that time.
204
+ */
205
+ declare function forceParsing(view: EditorView, upto?: number, timeout?: number): boolean;
206
+ /**
207
+ Tells you whether the language parser is planning to do more
208
+ parsing work (in a `requestIdleCallback` pseudo-thread) or has
209
+ stopped running, either because it parsed the entire document,
210
+ because it spent too much time and was cut off, or because there
211
+ is no language parser enabled.
212
+ */
213
+ declare function syntaxParserRunning(view: EditorView): boolean;
214
+ /**
215
+ Lezer-style
216
+ [`Input`](https://lezer.codemirror.net/docs/ref#common.Input)
217
+ object for a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) object.
218
+ */
219
+ declare class DocInput implements Input {
220
+ readonly doc: Text;
221
+ private cursor;
222
+ private cursorPos;
223
+ private string;
224
+ /**
225
+ Create an input object for the given document.
226
+ */
227
+ constructor(doc: Text);
228
+ get length(): number;
229
+ private syncTo;
230
+ chunk(pos: number): string;
231
+ get lineChunks(): boolean;
232
+ read(from: number, to: number): string;
233
+ }
234
+ /**
235
+ A parse context provided to parsers working on the editor content.
236
+ */
237
+ declare class ParseContext {
238
+ private parser;
239
+ /**
240
+ The current editor state.
241
+ */
242
+ readonly state: EditorState;
243
+ /**
244
+ Tree fragments that can be reused by incremental re-parses.
245
+ */
246
+ fragments: readonly TreeFragment[];
247
+ /**
248
+ The current editor viewport (or some overapproximation
249
+ thereof). Intended to be used for opportunistically avoiding
250
+ work (in which case
251
+ [`skipUntilInView`](https://codemirror.net/6/docs/ref/#language.ParseContext.skipUntilInView)
252
+ should be called to make sure the parser is restarted when the
253
+ skipped region becomes visible).
254
+ */
255
+ viewport: {
256
+ from: number;
257
+ to: number;
258
+ };
259
+ private parse;
260
+ private constructor();
261
+ private startParse;
262
+ private withContext;
263
+ private withoutTempSkipped;
264
+ /**
265
+ Notify the parse scheduler that the given region was skipped
266
+ because it wasn't in view, and the parse should be restarted
267
+ when it comes into view.
268
+ */
269
+ skipUntilInView(from: number, to: number): void;
270
+ /**
271
+ Returns a parser intended to be used as placeholder when
272
+ asynchronously loading a nested parser. It'll skip its input and
273
+ mark it as not-really-parsed, so that the next update will parse
274
+ it again.
275
+
276
+ When `until` is given, a reparse will be scheduled when that
277
+ promise resolves.
278
+ */
279
+ static getSkippingParser(until?: Promise<unknown>): Parser;
280
+ /**
281
+ Get the context for the current parse, or `null` if no editor
282
+ parse is in progress.
283
+ */
284
+ static get(): ParseContext | null;
285
+ }
286
+ /**
287
+ The facet used to associate a language with an editor state. Used
288
+ by `Language` object's `extension` property (so you don't need to
289
+ manually wrap your languages in this). Can be used to access the
290
+ current language on a state.
291
+ */
292
+ declare const language: Facet<Language, Language | null>;
293
+ /**
294
+ This class bundles a [language](https://codemirror.net/6/docs/ref/#language.Language) with an
295
+ optional set of supporting extensions. Language packages are
296
+ encouraged to export a function that optionally takes a
297
+ configuration object and returns a `LanguageSupport` instance, as
298
+ the main way for client code to use the package.
299
+ */
300
+ declare class LanguageSupport {
301
+ /**
302
+ The language object.
303
+ */
304
+ readonly language: Language;
305
+ /**
306
+ An optional set of supporting extensions. When nesting a
307
+ language in another language, the outer language is encouraged
308
+ to include the supporting extensions for its inner languages
309
+ in its own set of support extensions.
310
+ */
311
+ readonly support: Extension;
312
+ /**
313
+ An extension including both the language and its support
314
+ extensions. (Allowing the object to be used as an extension
315
+ value itself.)
316
+ */
317
+ extension: Extension;
318
+ /**
319
+ Create a language support object.
320
+ */
321
+ constructor(
322
+ /**
323
+ The language object.
324
+ */
325
+ language: Language,
326
+ /**
327
+ An optional set of supporting extensions. When nesting a
328
+ language in another language, the outer language is encouraged
329
+ to include the supporting extensions for its inner languages
330
+ in its own set of support extensions.
331
+ */
332
+ support?: Extension);
333
+ }
334
+ /**
335
+ Language descriptions are used to store metadata about languages
336
+ and to dynamically load them. Their main role is finding the
337
+ appropriate language for a filename or dynamically loading nested
338
+ parsers.
339
+ */
340
+ declare class LanguageDescription {
341
+ /**
342
+ The name of this language.
343
+ */
344
+ readonly name: string;
345
+ /**
346
+ Alternative names for the mode (lowercased, includes `this.name`).
347
+ */
348
+ readonly alias: readonly string[];
349
+ /**
350
+ File extensions associated with this language.
351
+ */
352
+ readonly extensions: readonly string[];
353
+ /**
354
+ Optional filename pattern that should be associated with this
355
+ language.
356
+ */
357
+ readonly filename: RegExp | undefined;
358
+ private loadFunc;
359
+ /**
360
+ If the language has been loaded, this will hold its value.
361
+ */
362
+ support: LanguageSupport | undefined;
363
+ private loading;
364
+ private constructor();
365
+ /**
366
+ Start loading the the language. Will return a promise that
367
+ resolves to a [`LanguageSupport`](https://codemirror.net/6/docs/ref/#language.LanguageSupport)
368
+ object when the language successfully loads.
369
+ */
370
+ load(): Promise<LanguageSupport>;
371
+ /**
372
+ Create a language description.
373
+ */
374
+ static of(spec: {
375
+ /**
376
+ The language's name.
377
+ */
378
+ name: string;
379
+ /**
380
+ An optional array of alternative names.
381
+ */
382
+ alias?: readonly string[];
383
+ /**
384
+ An optional array of filename extensions associated with this
385
+ language.
386
+ */
387
+ extensions?: readonly string[];
388
+ /**
389
+ An optional filename pattern associated with this language.
390
+ */
391
+ filename?: RegExp;
392
+ /**
393
+ A function that will asynchronously load the language.
394
+ */
395
+ load?: () => Promise<LanguageSupport>;
396
+ /**
397
+ Alternatively to `load`, you can provide an already loaded
398
+ support object. Either this or `load` should be provided.
399
+ */
400
+ support?: LanguageSupport;
401
+ }): LanguageDescription;
402
+ /**
403
+ Look for a language in the given array of descriptions that
404
+ matches the filename. Will first match
405
+ [`filename`](https://codemirror.net/6/docs/ref/#language.LanguageDescription.filename) patterns,
406
+ and then [extensions](https://codemirror.net/6/docs/ref/#language.LanguageDescription.extensions),
407
+ and return the first language that matches.
408
+ */
409
+ static matchFilename(descs: readonly LanguageDescription[], filename: string): LanguageDescription | null;
410
+ /**
411
+ Look for a language whose name or alias matches the the given
412
+ name (case-insensitively). If `fuzzy` is true, and no direct
413
+ matchs is found, this'll also search for a language whose name
414
+ or alias occurs in the string (for names shorter than three
415
+ characters, only when surrounded by non-word characters).
416
+ */
417
+ static matchLanguageName(descs: readonly LanguageDescription[], name: string, fuzzy?: boolean): LanguageDescription | null;
418
+ }
419
+
420
+ /**
421
+ Facet that defines a way to provide a function that computes the
422
+ appropriate indentation depth, as a column number (see
423
+ [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
424
+ line. A return value of `null` indicates no indentation can be
425
+ determined, and the line should inherit the indentation of the one
426
+ above it. A return value of `undefined` defers to the next indent
427
+ service.
428
+ */
429
+ declare const indentService: Facet<(context: IndentContext, pos: number) => number | null | undefined, readonly ((context: IndentContext, pos: number) => number | null | undefined)[]>;
430
+ /**
431
+ Facet for overriding the unit by which indentation happens. Should
432
+ be a string consisting either entirely of the same whitespace
433
+ character. When not set, this defaults to 2 spaces.
434
+ */
435
+ declare const indentUnit: Facet<string, string>;
436
+ /**
437
+ Return the _column width_ of an indent unit in the state.
438
+ Determined by the [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit)
439
+ facet, and [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) when that
440
+ contains tabs.
441
+ */
442
+ declare function getIndentUnit(state: EditorState): number;
443
+ /**
444
+ Create an indentation string that covers columns 0 to `cols`.
445
+ Will use tabs for as much of the columns as possible when the
446
+ [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit) facet contains
447
+ tabs.
448
+ */
449
+ declare function indentString(state: EditorState, cols: number): string;
450
+ /**
451
+ Get the indentation, as a column number, at the given position.
452
+ Will first consult any [indent services](https://codemirror.net/6/docs/ref/#language.indentService)
453
+ that are registered, and if none of those return an indentation,
454
+ this will check the syntax tree for the [indent node
455
+ prop](https://codemirror.net/6/docs/ref/#language.indentNodeProp) and use that if found. Returns a
456
+ number when an indentation could be determined, and null
457
+ otherwise.
458
+ */
459
+ declare function getIndentation(context: IndentContext | EditorState, pos: number): number | null;
460
+ /**
461
+ Create a change set that auto-indents all lines touched by the
462
+ given document range.
463
+ */
464
+ declare function indentRange(state: EditorState, from: number, to: number): _codemirror_state.ChangeSet;
465
+ /**
466
+ Indentation contexts are used when calling [indentation
467
+ services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
468
+ useful in indentation logic, and can selectively override the
469
+ indentation reported for some lines.
470
+ */
471
+ declare class IndentContext {
472
+ /**
473
+ The editor state.
474
+ */
475
+ readonly state: EditorState;
476
+ /**
477
+ The indent unit (number of columns per indentation level).
478
+ */
479
+ unit: number;
480
+ /**
481
+ Create an indent context.
482
+ */
483
+ constructor(
484
+ /**
485
+ The editor state.
486
+ */
487
+ state: EditorState,
488
+ /**
489
+ @internal
490
+ */
491
+ options?: {
492
+ /**
493
+ Override line indentations provided to the indentation
494
+ helper function, which is useful when implementing region
495
+ indentation, where indentation for later lines needs to refer
496
+ to previous lines, which may have been reindented compared to
497
+ the original start state. If given, this function should
498
+ return -1 for lines (given by start position) that didn't
499
+ change, and an updated indentation otherwise.
500
+ */
501
+ overrideIndentation?: (pos: number) => number;
502
+ /**
503
+ Make it look, to the indent logic, like a line break was
504
+ added at the given position (which is mostly just useful for
505
+ implementing something like
506
+ [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent)).
507
+ */
508
+ simulateBreak?: number;
509
+ /**
510
+ When `simulateBreak` is given, this can be used to make the
511
+ simulated break behave like a double line break.
512
+ */
513
+ simulateDoubleBreak?: boolean;
514
+ });
515
+ /**
516
+ Get a description of the line at the given position, taking
517
+ [simulated line
518
+ breaks](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
519
+ into account. If there is such a break at `pos`, the `bias`
520
+ argument determines whether the part of the line line before or
521
+ after the break is used.
522
+ */
523
+ lineAt(pos: number, bias?: -1 | 1): {
524
+ text: string;
525
+ from: number;
526
+ };
527
+ /**
528
+ Get the text directly after `pos`, either the entire line
529
+ or the next 100 characters, whichever is shorter.
530
+ */
531
+ textAfterPos(pos: number, bias?: -1 | 1): string;
532
+ /**
533
+ Find the column for the given position.
534
+ */
535
+ column(pos: number, bias?: -1 | 1): number;
536
+ /**
537
+ Find the column position (taking tabs into account) of the given
538
+ position in the given string.
539
+ */
540
+ countColumn(line: string, pos?: number): number;
541
+ /**
542
+ Find the indentation column of the line at the given point.
543
+ */
544
+ lineIndent(pos: number, bias?: -1 | 1): number;
545
+ /**
546
+ Returns the [simulated line
547
+ break](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
548
+ for this context, if any.
549
+ */
550
+ get simulatedBreak(): number | null;
551
+ }
552
+ /**
553
+ A syntax tree node prop used to associate indentation strategies
554
+ with node types. Such a strategy is a function from an indentation
555
+ context to a column number (see also
556
+ [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)) or null, where null
557
+ indicates that no definitive indentation can be determined.
558
+ */
559
+ declare const indentNodeProp: NodeProp<(context: TreeIndentContext) => number | null>;
560
+ /**
561
+ Objects of this type provide context information and helper
562
+ methods to indentation functions registered on syntax nodes.
563
+ */
564
+ declare class TreeIndentContext extends IndentContext {
565
+ private base;
566
+ /**
567
+ The position at which indentation is being computed.
568
+ */
569
+ readonly pos: number;
570
+ /**
571
+ The syntax tree node to which the indentation strategy
572
+ applies.
573
+ */
574
+ readonly node: SyntaxNode;
575
+ private constructor();
576
+ /**
577
+ Get the text directly after `this.pos`, either the entire line
578
+ or the next 100 characters, whichever is shorter.
579
+ */
580
+ get textAfter(): string;
581
+ /**
582
+ Get the indentation at the reference line for `this.node`, which
583
+ is the line on which it starts, unless there is a node that is
584
+ _not_ a parent of this node covering the start of that line. If
585
+ so, the line at the start of that node is tried, again skipping
586
+ on if it is covered by another such node.
587
+ */
588
+ get baseIndent(): number;
589
+ /**
590
+ Get the indentation for the reference line of the given node
591
+ (see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
592
+ */
593
+ baseIndentFor(node: SyntaxNode): number;
594
+ /**
595
+ Continue looking for indentations in the node's parent nodes,
596
+ and return the result of that.
597
+ */
598
+ continue(): number | null;
599
+ }
600
+ /**
601
+ An indentation strategy for delimited (usually bracketed) nodes.
602
+ Will, by default, indent one unit more than the parent's base
603
+ indent unless the line starts with a closing token. When `align`
604
+ is true and there are non-skipped nodes on the node's opening
605
+ line, the content of the node will be aligned with the end of the
606
+ opening node, like this:
607
+
608
+ foo(bar,
609
+ baz)
610
+ */
611
+ declare function delimitedIndent({ closing, align, units }: {
612
+ closing: string;
613
+ align?: boolean;
614
+ units?: number;
615
+ }): (context: TreeIndentContext) => number;
616
+ /**
617
+ An indentation strategy that aligns a node's content to its base
618
+ indentation.
619
+ */
620
+ declare const flatIndent: (context: TreeIndentContext) => number;
621
+ /**
622
+ Creates an indentation strategy that, by default, indents
623
+ continued lines one unit more than the node's base indentation.
624
+ You can provide `except` to prevent indentation of lines that
625
+ match a pattern (for example `/^else\b/` in `if`/`else`
626
+ constructs), and you can change the amount of units used with the
627
+ `units` option.
628
+ */
629
+ declare function continuedIndent({ except, units }?: {
630
+ except?: RegExp;
631
+ units?: number;
632
+ }): (context: TreeIndentContext) => number;
633
+ /**
634
+ Enables reindentation on input. When a language defines an
635
+ `indentOnInput` field in its [language
636
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt), which must hold a regular
637
+ expression, the line at the cursor will be reindented whenever new
638
+ text is typed and the input from the start of the line up to the
639
+ cursor matches that regexp.
640
+
641
+ To avoid unneccesary reindents, it is recommended to start the
642
+ regexp with `^` (usually followed by `\s*`), and end it with `$`.
643
+ For example, `/^\s*\}$/` will reindent when a closing brace is
644
+ added at the start of a line.
645
+ */
646
+ declare function indentOnInput(): Extension;
647
+
648
+ /**
649
+ A facet that registers a code folding service. When called with
650
+ the extent of a line, such a function should return a foldable
651
+ range that starts on that line (but continues beyond it), if one
652
+ can be found.
653
+ */
654
+ declare const foldService: Facet<(state: EditorState, lineStart: number, lineEnd: number) => ({
655
+ from: number;
656
+ to: number;
657
+ } | null), readonly ((state: EditorState, lineStart: number, lineEnd: number) => ({
658
+ from: number;
659
+ to: number;
660
+ } | null))[]>;
661
+ /**
662
+ This node prop is used to associate folding information with
663
+ syntax node types. Given a syntax node, it should check whether
664
+ that tree is foldable and return the range that can be collapsed
665
+ when it is.
666
+ */
667
+ declare const foldNodeProp: NodeProp<(node: SyntaxNode, state: EditorState) => ({
668
+ from: number;
669
+ to: number;
670
+ } | null)>;
671
+ /**
672
+ [Fold](https://codemirror.net/6/docs/ref/#language.foldNodeProp) function that folds everything but
673
+ the first and the last child of a syntax node. Useful for nodes
674
+ that start and end with delimiters.
675
+ */
676
+ declare function foldInside(node: SyntaxNode): {
677
+ from: number;
678
+ to: number;
679
+ } | null;
680
+ /**
681
+ Check whether the given line is foldable. First asks any fold
682
+ services registered through
683
+ [`foldService`](https://codemirror.net/6/docs/ref/#language.foldService), and if none of them return
684
+ a result, tries to query the [fold node
685
+ prop](https://codemirror.net/6/docs/ref/#language.foldNodeProp) of syntax nodes that cover the end
686
+ of the line.
687
+ */
688
+ declare function foldable(state: EditorState, lineStart: number, lineEnd: number): {
689
+ from: number;
690
+ to: number;
691
+ } | null;
692
+ declare type DocRange = {
693
+ from: number;
694
+ to: number;
695
+ };
696
+ /**
697
+ State effect that can be attached to a transaction to fold the
698
+ given range. (You probably only need this in exceptional
699
+ circumstances—usually you'll just want to let
700
+ [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode) and the [fold
701
+ gutter](https://codemirror.net/6/docs/ref/#language.foldGutter) create the transactions.)
702
+ */
703
+ declare const foldEffect: _codemirror_state.StateEffectType<DocRange>;
704
+ /**
705
+ State effect that unfolds the given range (if it was folded).
706
+ */
707
+ declare const unfoldEffect: _codemirror_state.StateEffectType<DocRange>;
708
+ /**
709
+ The state field that stores the folded ranges (as a [decoration
710
+ set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
711
+ [`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
712
+ [`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
713
+ state.
714
+ */
715
+ declare const foldState: StateField<DecorationSet>;
716
+ /**
717
+ Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
718
+ in the given state.
719
+ */
720
+ declare function foldedRanges(state: EditorState): DecorationSet;
721
+ /**
722
+ Fold the lines that are selected, if possible.
723
+ */
724
+ declare const foldCode: Command;
725
+ /**
726
+ Unfold folded ranges on selected lines.
727
+ */
728
+ declare const unfoldCode: Command;
729
+ /**
730
+ Fold all top-level foldable ranges. Note that, in most cases,
731
+ folding information will depend on the [syntax
732
+ tree](https://codemirror.net/6/docs/ref/#language.syntaxTree), and folding everything may not work
733
+ reliably when the document hasn't been fully parsed (either
734
+ because the editor state was only just initialized, or because the
735
+ document is so big that the parser decided not to parse it
736
+ entirely).
737
+ */
738
+ declare const foldAll: Command;
739
+ /**
740
+ Unfold all folded code.
741
+ */
742
+ declare const unfoldAll: Command;
743
+ /**
744
+ Toggle folding at cursors. Unfolds if there is an existing fold
745
+ starting in that line, tries to find a foldable range around it
746
+ otherwise.
747
+ */
748
+ declare const toggleFold: Command;
749
+ /**
750
+ Default fold-related key bindings.
751
+
752
+ - Ctrl-Shift-[ (Cmd-Alt-[ on macOS): [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode).
753
+ - Ctrl-Shift-] (Cmd-Alt-] on macOS): [`unfoldCode`](https://codemirror.net/6/docs/ref/#language.unfoldCode).
754
+ - Ctrl-Alt-[: [`foldAll`](https://codemirror.net/6/docs/ref/#language.foldAll).
755
+ - Ctrl-Alt-]: [`unfoldAll`](https://codemirror.net/6/docs/ref/#language.unfoldAll).
756
+ */
757
+ declare const foldKeymap: readonly KeyBinding[];
758
+ interface FoldConfig {
759
+ /**
760
+ A function that creates the DOM element used to indicate the
761
+ position of folded code. The `onclick` argument is the default
762
+ click event handler, which toggles folding on the line that
763
+ holds the element, and should probably be added as an event
764
+ handler to the returned element.
765
+
766
+ When this option isn't given, the `placeholderText` option will
767
+ be used to create the placeholder element.
768
+ */
769
+ placeholderDOM?: ((view: EditorView, onclick: (event: Event) => void) => HTMLElement) | null;
770
+ /**
771
+ Text to use as placeholder for folded text. Defaults to `"…"`.
772
+ Will be styled with the `"cm-foldPlaceholder"` class.
773
+ */
774
+ placeholderText?: string;
775
+ }
776
+ /**
777
+ Create an extension that configures code folding.
778
+ */
779
+ declare function codeFolding(config?: FoldConfig): Extension;
780
+ declare type Handlers = {
781
+ [event: string]: (view: EditorView, line: BlockInfo, event: Event) => boolean;
782
+ };
783
+ interface FoldGutterConfig {
784
+ /**
785
+ A function that creates the DOM element used to indicate a
786
+ given line is folded or can be folded.
787
+ When not given, the `openText`/`closeText` option will be used instead.
788
+ */
789
+ markerDOM?: ((open: boolean) => HTMLElement) | null;
790
+ /**
791
+ Text used to indicate that a given line can be folded.
792
+ Defaults to `"⌄"`.
793
+ */
794
+ openText?: string;
795
+ /**
796
+ Text used to indicate that a given line is folded.
797
+ Defaults to `"›"`.
798
+ */
799
+ closedText?: string;
800
+ /**
801
+ Supply event handlers for DOM events on this gutter.
802
+ */
803
+ domEventHandlers?: Handlers;
804
+ /**
805
+ When given, if this returns true for a given view update,
806
+ recompute the fold markers.
807
+ */
808
+ foldingChanged?: (update: ViewUpdate) => boolean;
809
+ }
810
+ /**
811
+ Create an extension that registers a fold gutter, which shows a
812
+ fold status indicator before foldable lines (which can be clicked
813
+ to fold or unfold the line).
814
+ */
815
+ declare function foldGutter(config?: FoldGutterConfig): Extension;
816
+
817
+ /**
818
+ A highlight style associates CSS styles with higlighting
819
+ [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
820
+ */
821
+ declare class HighlightStyle implements Highlighter {
822
+ /**
823
+ The tag styles used to create this highlight style.
824
+ */
825
+ readonly specs: readonly TagStyle[];
826
+ /**
827
+ A style module holding the CSS rules for this highlight style.
828
+ When using
829
+ [`highlightTree`](https://lezer.codemirror.net/docs/ref#highlight.highlightTree)
830
+ outside of the editor, you may want to manually mount this
831
+ module to show the highlighting.
832
+ */
833
+ readonly module: StyleModule | null;
834
+ readonly style: (tags: readonly Tag[]) => string | null;
835
+ readonly scope: ((type: NodeType) => boolean) | undefined;
836
+ private constructor();
837
+ /**
838
+ Create a highlighter style that associates the given styles to
839
+ the given tags. The specs must be objects that hold a style tag
840
+ or array of tags in their `tag` property, and either a single
841
+ `class` property providing a static CSS class (for highlighter
842
+ that rely on external styling), or a
843
+ [`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
844
+ set of CSS properties (which define the styling for those tags).
845
+
846
+ The CSS rules created for a highlighter will be emitted in the
847
+ order of the spec's properties. That means that for elements that
848
+ have multiple tags associated with them, styles defined further
849
+ down in the list will have a higher CSS precedence than styles
850
+ defined earlier.
851
+ */
852
+ static define(specs: readonly TagStyle[], options?: {
853
+ /**
854
+ By default, highlighters apply to the entire document. You can
855
+ scope them to a single language by providing the language
856
+ object or a language's top node type here.
857
+ */
858
+ scope?: Language | NodeType;
859
+ /**
860
+ Add a style to _all_ content. Probably only useful in
861
+ combination with `scope`.
862
+ */
863
+ all?: string | StyleSpec;
864
+ /**
865
+ Specify that this highlight style should only be active then
866
+ the theme is dark or light. By default, it is active
867
+ regardless of theme.
868
+ */
869
+ themeType?: "dark" | "light";
870
+ }): HighlightStyle;
871
+ }
872
+ /**
873
+ Wrap a highlighter in an editor extension that uses it to apply
874
+ syntax highlighting to the editor content.
875
+
876
+ When multiple (non-fallback) styles are provided, the styling
877
+ applied is the union of the classes they emit.
878
+ */
879
+ declare function syntaxHighlighting(highlighter: Highlighter, options?: {
880
+ /**
881
+ When enabled, this marks the highlighter as a fallback, which
882
+ only takes effect if no other highlighters are registered.
883
+ */
884
+ fallback: boolean;
885
+ }): Extension;
886
+ /**
887
+ Returns the CSS classes (if any) that the highlighters active in
888
+ the state would assign to the given style
889
+ [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag) and
890
+ (optional) language
891
+ [scope](https://codemirror.net/6/docs/ref/#language.HighlightStyle^define^options.scope).
892
+ */
893
+ declare function highlightingFor(state: EditorState, tags: readonly Tag[], scope?: NodeType): string | null;
894
+ /**
895
+ The type of object used in
896
+ [`HighlightStyle.define`](https://codemirror.net/6/docs/ref/#language.HighlightStyle^define).
897
+ Assigns a style to one or more highlighting
898
+ [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag), which can either be a fixed class name
899
+ (which must be defined elsewhere), or a set of CSS properties, for
900
+ which the library will define an anonymous class.
901
+ */
902
+ interface TagStyle {
903
+ /**
904
+ The tag or tags to target.
905
+ */
906
+ tag: Tag | readonly Tag[];
907
+ /**
908
+ If given, this maps the tags to a fixed class name.
909
+ */
910
+ class?: string;
911
+ /**
912
+ Any further properties (if `class` isn't given) will be
913
+ interpreted as in style objects given to
914
+ [style-mod](https://github.com/marijnh/style-mod#documentation).
915
+ (The type here is `any` because of TypeScript limitations.)
916
+ */
917
+ [styleProperty: string]: any;
918
+ }
919
+ /**
920
+ A default highlight style (works well with light themes).
921
+ */
922
+ declare const defaultHighlightStyle: HighlightStyle;
923
+
924
+ interface Config {
925
+ /**
926
+ Whether the bracket matching should look at the character after
927
+ the cursor when matching (if the one before isn't a bracket).
928
+ Defaults to true.
929
+ */
930
+ afterCursor?: boolean;
931
+ /**
932
+ The bracket characters to match, as a string of pairs. Defaults
933
+ to `"()[]{}"`. Note that these are only used as fallback when
934
+ there is no [matching
935
+ information](https://lezer.codemirror.net/docs/ref/#common.NodeProp^closedBy)
936
+ in the syntax tree.
937
+ */
938
+ brackets?: string;
939
+ /**
940
+ The maximum distance to scan for matching brackets. This is only
941
+ relevant for brackets not encoded in the syntax tree. Defaults
942
+ to 10 000.
943
+ */
944
+ maxScanDistance?: number;
945
+ /**
946
+ Can be used to configure the way in which brackets are
947
+ decorated. The default behavior is to add the
948
+ `cm-matchingBracket` class for matching pairs, and
949
+ `cm-nonmatchingBracket` for mismatched pairs or single brackets.
950
+ */
951
+ renderMatch?: (match: MatchResult, state: EditorState) => readonly Range<Decoration>[];
952
+ }
953
+ /**
954
+ Create an extension that enables bracket matching. Whenever the
955
+ cursor is next to a bracket, that bracket and the one it matches
956
+ are highlighted. Or, when no matching bracket is found, another
957
+ highlighting style is used to indicate this.
958
+ */
959
+ declare function bracketMatching(config?: Config): Extension;
960
+ /**
961
+ When larger syntax nodes, such as HTML tags, are marked as
962
+ opening/closing, it can be a bit messy to treat the whole node as
963
+ a matchable bracket. This node prop allows you to define, for such
964
+ a node, a ‘handle’—the part of the node that is highlighted, and
965
+ that the cursor must be on to activate highlighting in the first
966
+ place.
967
+ */
968
+ declare const bracketMatchingHandle: NodeProp<(node: SyntaxNode) => SyntaxNode | null>;
969
+ /**
970
+ The result returned from `matchBrackets`.
971
+ */
972
+ interface MatchResult {
973
+ /**
974
+ The extent of the bracket token found.
975
+ */
976
+ start: {
977
+ from: number;
978
+ to: number;
979
+ };
980
+ /**
981
+ The extent of the matched token, if any was found.
982
+ */
983
+ end?: {
984
+ from: number;
985
+ to: number;
986
+ };
987
+ /**
988
+ Whether the tokens match. This can be false even when `end` has
989
+ a value, if that token doesn't match the opening token.
990
+ */
991
+ matched: boolean;
992
+ }
993
+ /**
994
+ Find the matching bracket for the token at `pos`, scanning
995
+ direction `dir`. Only the `brackets` and `maxScanDistance`
996
+ properties are used from `config`, if given. Returns null if no
997
+ bracket was found at `pos`, or a match result otherwise.
998
+ */
999
+ declare function matchBrackets(state: EditorState, pos: number, dir: -1 | 1, config?: Config): MatchResult | null;
1000
+
1001
+ /**
1002
+ Encapsulates a single line of input. Given to stream syntax code,
1003
+ which uses it to tokenize the content.
1004
+ */
1005
+ declare class StringStream {
1006
+ /**
1007
+ The line.
1008
+ */
1009
+ string: string;
1010
+ private tabSize;
1011
+ /**
1012
+ The current indent unit size.
1013
+ */
1014
+ indentUnit: number;
1015
+ private overrideIndent?;
1016
+ /**
1017
+ The current position on the line.
1018
+ */
1019
+ pos: number;
1020
+ /**
1021
+ The start position of the current token.
1022
+ */
1023
+ start: number;
1024
+ private lastColumnPos;
1025
+ private lastColumnValue;
1026
+ /**
1027
+ Create a stream.
1028
+ */
1029
+ constructor(
1030
+ /**
1031
+ The line.
1032
+ */
1033
+ string: string, tabSize: number,
1034
+ /**
1035
+ The current indent unit size.
1036
+ */
1037
+ indentUnit: number, overrideIndent?: number | undefined);
1038
+ /**
1039
+ True if we are at the end of the line.
1040
+ */
1041
+ eol(): boolean;
1042
+ /**
1043
+ True if we are at the start of the line.
1044
+ */
1045
+ sol(): boolean;
1046
+ /**
1047
+ Get the next code unit after the current position, or undefined
1048
+ if we're at the end of the line.
1049
+ */
1050
+ peek(): string | undefined;
1051
+ /**
1052
+ Read the next code unit and advance `this.pos`.
1053
+ */
1054
+ next(): string | void;
1055
+ /**
1056
+ Match the next character against the given string, regular
1057
+ expression, or predicate. Consume and return it if it matches.
1058
+ */
1059
+ eat(match: string | RegExp | ((ch: string) => boolean)): string | void;
1060
+ /**
1061
+ Continue matching characters that match the given string,
1062
+ regular expression, or predicate function. Return true if any
1063
+ characters were consumed.
1064
+ */
1065
+ eatWhile(match: string | RegExp | ((ch: string) => boolean)): boolean;
1066
+ /**
1067
+ Consume whitespace ahead of `this.pos`. Return true if any was
1068
+ found.
1069
+ */
1070
+ eatSpace(): boolean;
1071
+ /**
1072
+ Move to the end of the line.
1073
+ */
1074
+ skipToEnd(): void;
1075
+ /**
1076
+ Move to directly before the given character, if found on the
1077
+ current line.
1078
+ */
1079
+ skipTo(ch: string): boolean | void;
1080
+ /**
1081
+ Move back `n` characters.
1082
+ */
1083
+ backUp(n: number): void;
1084
+ /**
1085
+ Get the column position at `this.pos`.
1086
+ */
1087
+ column(): number;
1088
+ /**
1089
+ Get the indentation column of the current line.
1090
+ */
1091
+ indentation(): number;
1092
+ /**
1093
+ Match the input against the given string or regular expression
1094
+ (which should start with a `^`). Return true or the regexp match
1095
+ if it matches.
1096
+
1097
+ Unless `consume` is set to `false`, this will move `this.pos`
1098
+ past the matched text.
1099
+
1100
+ When matching a string `caseInsensitive` can be set to true to
1101
+ make the match case-insensitive.
1102
+ */
1103
+ match(pattern: string | RegExp, consume?: boolean, caseInsensitive?: boolean): boolean | RegExpMatchArray | null;
1104
+ /**
1105
+ Get the current token.
1106
+ */
1107
+ current(): string;
1108
+ }
1109
+
1110
+ /**
1111
+ A stream parser parses or tokenizes content from start to end,
1112
+ emitting tokens as it goes over it. It keeps a mutable (but
1113
+ copyable) object with state, in which it can store information
1114
+ about the current context.
1115
+ */
1116
+ interface StreamParser<State> {
1117
+ /**
1118
+ A name for this language.
1119
+ */
1120
+ name?: string;
1121
+ /**
1122
+ Produce a start state for the parser.
1123
+ */
1124
+ startState?(indentUnit: number): State;
1125
+ /**
1126
+ Read one token, advancing the stream past it, and returning a
1127
+ string indicating the token's style tag—either the name of one
1128
+ of the tags in
1129
+ [`tags`](https://lezer.codemirror.net/docs/ref#highlight.tags),
1130
+ or such a name suffixed by one or more tag
1131
+ [modifier](https://lezer.codemirror.net/docs/ref#highlight.Tag^defineModifier)
1132
+ names, separated by periods. For example `"keyword"` or
1133
+ "`variableName.constant"`.
1134
+
1135
+ It is okay to return a zero-length token, but only if that
1136
+ updates the state so that the next call will return a non-empty
1137
+ token again.
1138
+ */
1139
+ token(stream: StringStream, state: State): string | null;
1140
+ /**
1141
+ This notifies the parser of a blank line in the input. It can
1142
+ update its state here if it needs to.
1143
+ */
1144
+ blankLine?(state: State, indentUnit: number): void;
1145
+ /**
1146
+ Copy a given state. By default, a shallow object copy is done
1147
+ which also copies arrays held at the top level of the object.
1148
+ */
1149
+ copyState?(state: State): State;
1150
+ /**
1151
+ Compute automatic indentation for the line that starts with the
1152
+ given state and text.
1153
+ */
1154
+ indent?(state: State, textAfter: string, context: IndentContext): number | null;
1155
+ /**
1156
+ Default [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) to
1157
+ attach to this language.
1158
+ */
1159
+ languageData?: {
1160
+ [name: string]: any;
1161
+ };
1162
+ /**
1163
+ Extra tokens to use in this parser. When the tokenizer returns a
1164
+ token name that exists as a property in this object, the
1165
+ corresponding tag will be assigned to the token.
1166
+ */
1167
+ tokenTable?: {
1168
+ [name: string]: Tag;
1169
+ };
1170
+ }
1171
+ /**
1172
+ A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
1173
+ 5-style [streaming parser](https://codemirror.net/6/docs/ref/#language.StreamParser).
1174
+ */
1175
+ declare class StreamLanguage<State> extends Language {
1176
+ private constructor();
1177
+ /**
1178
+ Define a stream language.
1179
+ */
1180
+ static define<State>(spec: StreamParser<State>): StreamLanguage<State>;
1181
+ private getIndent;
1182
+ get allowsNesting(): boolean;
1183
+ }
1184
+
1185
+ export { Config, DocInput, HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, MatchResult, ParseContext, StreamLanguage, StreamParser, StringStream, Sublanguage, TagStyle, TreeIndentContext, bracketMatching, bracketMatchingHandle, 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, sublanguageProp, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, toggleFold, unfoldAll, unfoldCode, unfoldEffect };