@codemirror/language 6.6.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.
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs +37 -22
- package/dist/index.d.cts +1185 -0
- package/dist/index.d.ts +29 -4
- package/dist/index.js +38 -24
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NodeProp, SyntaxNode, Parser, Tree, TreeFragment, NodeType } from '@lezer/common';
|
|
1
|
+
import { NodeProp, SyntaxNode, Parser, Tree, Input, TreeFragment, NodeType } from '@lezer/common';
|
|
2
2
|
import { LRParser, ParserConfig } from '@lezer/lr';
|
|
3
3
|
import * as _codemirror_state from '@codemirror/state';
|
|
4
|
-
import { Facet, EditorState, Extension, StateField, Range } from '@codemirror/state';
|
|
4
|
+
import { Facet, EditorState, Extension, Text, StateField, Range } from '@codemirror/state';
|
|
5
5
|
import { EditorView, DecorationSet, Command, KeyBinding, ViewUpdate, BlockInfo, Decoration } from '@codemirror/view';
|
|
6
6
|
import { Highlighter, Tag } from '@lezer/highlight';
|
|
7
7
|
import { StyleModule, StyleSpec } from 'style-mod';
|
|
@@ -64,7 +64,7 @@ interface Sublanguage {
|
|
|
64
64
|
}>;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
Syntax node prop used to register
|
|
67
|
+
Syntax node prop used to register sublanguages. Should be added to
|
|
68
68
|
the top level node type for the language.
|
|
69
69
|
*/
|
|
70
70
|
declare const sublanguageProp: NodeProp<Sublanguage[]>;
|
|
@@ -212,6 +212,26 @@ is no language parser enabled.
|
|
|
212
212
|
*/
|
|
213
213
|
declare function syntaxParserRunning(view: EditorView): boolean;
|
|
214
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
|
+
/**
|
|
215
235
|
A parse context provided to parsers working on the editor content.
|
|
216
236
|
*/
|
|
217
237
|
declare class ParseContext {
|
|
@@ -567,6 +587,11 @@ declare class TreeIndentContext extends IndentContext {
|
|
|
567
587
|
*/
|
|
568
588
|
get baseIndent(): number;
|
|
569
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
|
+
/**
|
|
570
595
|
Continue looking for indentations in the node's parent nodes,
|
|
571
596
|
and return the result of that.
|
|
572
597
|
*/
|
|
@@ -1157,4 +1182,4 @@ declare class StreamLanguage<State> extends Language {
|
|
|
1157
1182
|
get allowsNesting(): boolean;
|
|
1158
1183
|
}
|
|
1159
1184
|
|
|
1160
|
-
export { Config, 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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeProp,
|
|
1
|
+
import { NodeProp, Tree, IterMode, TreeFragment, Parser, NodeType, NodeSet } from '@lezer/common';
|
|
2
2
|
import { StateEffect, StateField, Facet, EditorState, countColumn, combineConfig, RangeSet, RangeSetBuilder, Prec } from '@codemirror/state';
|
|
3
3
|
import { ViewPlugin, logException, EditorView, Decoration, WidgetType, gutter, GutterMarker } from '@codemirror/view';
|
|
4
4
|
import { tags, tagHighlighter, highlightTree, styleTags } from '@lezer/highlight';
|
|
@@ -24,7 +24,7 @@ function defineLanguageFacet(baseData) {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
Syntax node prop used to register
|
|
27
|
+
Syntax node prop used to register sublanguages. Should be added to
|
|
28
28
|
the top level node type for the language.
|
|
29
29
|
*/
|
|
30
30
|
const sublanguageProp = /*@__PURE__*/new NodeProp();
|
|
@@ -240,8 +240,15 @@ function syntaxParserRunning(view) {
|
|
|
240
240
|
var _a;
|
|
241
241
|
return ((_a = view.plugin(parseWorker)) === null || _a === void 0 ? void 0 : _a.isWorking()) || false;
|
|
242
242
|
}
|
|
243
|
-
|
|
243
|
+
/**
|
|
244
|
+
Lezer-style
|
|
245
|
+
[`Input`](https://lezer.codemirror.net/docs/ref#common.Input)
|
|
246
|
+
object for a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) object.
|
|
247
|
+
*/
|
|
244
248
|
class DocInput {
|
|
249
|
+
/**
|
|
250
|
+
Create an input object for the given document.
|
|
251
|
+
*/
|
|
245
252
|
constructor(doc) {
|
|
246
253
|
this.doc = doc;
|
|
247
254
|
this.cursorPos = 0;
|
|
@@ -527,14 +534,14 @@ class LanguageState {
|
|
|
527
534
|
// state updates with parse work beyond the viewport.
|
|
528
535
|
let upto = this.context.treeLen == tr.startState.doc.length ? undefined
|
|
529
536
|
: Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
|
|
530
|
-
if (!newCx.work(20 /*
|
|
537
|
+
if (!newCx.work(20 /* Apply */, upto))
|
|
531
538
|
newCx.takeTree();
|
|
532
539
|
return new LanguageState(newCx);
|
|
533
540
|
}
|
|
534
541
|
static init(state) {
|
|
535
|
-
let vpTo = Math.min(3000 /*
|
|
542
|
+
let vpTo = Math.min(3000 /* InitViewport */, state.doc.length);
|
|
536
543
|
let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
|
|
537
|
-
if (!parseState.work(20 /*
|
|
544
|
+
if (!parseState.work(20 /* Apply */, vpTo))
|
|
538
545
|
parseState.takeTree();
|
|
539
546
|
return new LanguageState(parseState);
|
|
540
547
|
}
|
|
@@ -551,14 +558,14 @@ Language.state = /*@__PURE__*/StateField.define({
|
|
|
551
558
|
}
|
|
552
559
|
});
|
|
553
560
|
let requestIdle = (callback) => {
|
|
554
|
-
let timeout = setTimeout(() => callback(), 500 /*
|
|
561
|
+
let timeout = setTimeout(() => callback(), 500 /* MaxPause */);
|
|
555
562
|
return () => clearTimeout(timeout);
|
|
556
563
|
};
|
|
557
564
|
if (typeof requestIdleCallback != "undefined")
|
|
558
565
|
requestIdle = (callback) => {
|
|
559
566
|
let idle = -1, timeout = setTimeout(() => {
|
|
560
|
-
idle = requestIdleCallback(callback, { timeout: 500 /*
|
|
561
|
-
}, 100 /*
|
|
567
|
+
idle = requestIdleCallback(callback, { timeout: 500 /* MaxPause */ - 100 /* MinPause */ });
|
|
568
|
+
}, 100 /* MinPause */);
|
|
562
569
|
return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
|
|
563
570
|
};
|
|
564
571
|
const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending)
|
|
@@ -581,7 +588,7 @@ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
|
|
|
581
588
|
this.scheduleWork();
|
|
582
589
|
if (update.docChanged) {
|
|
583
590
|
if (this.view.hasFocus)
|
|
584
|
-
this.chunkBudget += 50 /*
|
|
591
|
+
this.chunkBudget += 50 /* ChangeBonus */;
|
|
585
592
|
this.scheduleWork();
|
|
586
593
|
}
|
|
587
594
|
this.checkAsyncSchedule(cx);
|
|
@@ -597,19 +604,19 @@ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
|
|
|
597
604
|
this.working = null;
|
|
598
605
|
let now = Date.now();
|
|
599
606
|
if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) { // Start a new chunk
|
|
600
|
-
this.chunkEnd = now + 30000 /*
|
|
601
|
-
this.chunkBudget = 3000 /*
|
|
607
|
+
this.chunkEnd = now + 30000 /* ChunkTime */;
|
|
608
|
+
this.chunkBudget = 3000 /* ChunkBudget */;
|
|
602
609
|
}
|
|
603
610
|
if (this.chunkBudget <= 0)
|
|
604
611
|
return; // No more budget
|
|
605
612
|
let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
|
|
606
|
-
if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /*
|
|
613
|
+
if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* MaxParseAhead */))
|
|
607
614
|
return;
|
|
608
|
-
let endTime = Date.now() + Math.min(this.chunkBudget, 100 /*
|
|
615
|
+
let endTime = Date.now() + Math.min(this.chunkBudget, 100 /* Slice */, deadline && !isInputPending ? Math.max(25 /* MinSlice */, deadline.timeRemaining() - 5) : 1e9);
|
|
609
616
|
let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1000;
|
|
610
617
|
let done = field.context.work(() => {
|
|
611
618
|
return isInputPending && isInputPending() || Date.now() > endTime;
|
|
612
|
-
}, vpTo + (viewportFirst ? 0 : 100000 /*
|
|
619
|
+
}, vpTo + (viewportFirst ? 0 : 100000 /* MaxParseAhead */));
|
|
613
620
|
this.chunkBudget -= Date.now() - now;
|
|
614
621
|
if (done || this.chunkBudget <= 0) {
|
|
615
622
|
field.context.takeTree();
|
|
@@ -1051,13 +1058,20 @@ class TreeIndentContext extends IndentContext {
|
|
|
1051
1058
|
on if it is covered by another such node.
|
|
1052
1059
|
*/
|
|
1053
1060
|
get baseIndent() {
|
|
1054
|
-
|
|
1061
|
+
return this.baseIndentFor(this.node);
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
Get the indentation for the reference line of the given node
|
|
1065
|
+
(see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
|
|
1066
|
+
*/
|
|
1067
|
+
baseIndentFor(node) {
|
|
1068
|
+
let line = this.state.doc.lineAt(node.from);
|
|
1055
1069
|
// Skip line starts that are covered by a sibling (or cousin, etc)
|
|
1056
1070
|
for (;;) {
|
|
1057
|
-
let atBreak =
|
|
1071
|
+
let atBreak = node.resolve(line.from);
|
|
1058
1072
|
while (atBreak.parent && atBreak.parent.from == atBreak.from)
|
|
1059
1073
|
atBreak = atBreak.parent;
|
|
1060
|
-
if (isParent(atBreak,
|
|
1074
|
+
if (isParent(atBreak, node))
|
|
1061
1075
|
break;
|
|
1062
1076
|
line = this.state.doc.lineAt(atBreak.from);
|
|
1063
1077
|
}
|
|
@@ -2189,7 +2203,7 @@ class StreamLanguage extends Language {
|
|
|
2189
2203
|
state = this.streamParser.startState(cx.unit);
|
|
2190
2204
|
statePos = 0;
|
|
2191
2205
|
}
|
|
2192
|
-
if (pos - statePos > 10000 /*
|
|
2206
|
+
if (pos - statePos > 10000 /* MaxIndentScanDist */)
|
|
2193
2207
|
return null;
|
|
2194
2208
|
while (statePos < pos) {
|
|
2195
2209
|
let line = cx.state.doc.lineAt(statePos), end = Math.min(pos, line.to);
|
|
@@ -2271,7 +2285,7 @@ class Parse {
|
|
|
2271
2285
|
this.chunks.push(tree.children[i]);
|
|
2272
2286
|
this.chunkPos.push(tree.positions[i]);
|
|
2273
2287
|
}
|
|
2274
|
-
if (context && this.parsedPos < context.viewport.from - 100000 /*
|
|
2288
|
+
if (context && this.parsedPos < context.viewport.from - 100000 /* MaxDistanceBeforeViewport */) {
|
|
2275
2289
|
this.state = this.lang.streamParser.startState(getIndentUnit(context.state));
|
|
2276
2290
|
context.skipUntilInView(this.parsedPos, context.viewport.from);
|
|
2277
2291
|
this.parsedPos = context.viewport.from;
|
|
@@ -2281,7 +2295,7 @@ class Parse {
|
|
|
2281
2295
|
advance() {
|
|
2282
2296
|
let context = ParseContext.get();
|
|
2283
2297
|
let parseEnd = this.stoppedAt == null ? this.to : Math.min(this.to, this.stoppedAt);
|
|
2284
|
-
let end = Math.min(parseEnd, this.chunkStart + 2048 /*
|
|
2298
|
+
let end = Math.min(parseEnd, this.chunkStart + 2048 /* ChunkSize */);
|
|
2285
2299
|
if (context)
|
|
2286
2300
|
end = Math.min(end, context.viewport.to);
|
|
2287
2301
|
while (this.parsedPos < end)
|
|
@@ -2365,7 +2379,7 @@ class Parse {
|
|
|
2365
2379
|
let token = readToken(streamParser.token, stream, this.state);
|
|
2366
2380
|
if (token)
|
|
2367
2381
|
offset = this.emitToken(this.lang.tokenTable.resolve(token), this.parsedPos + stream.start, this.parsedPos + stream.pos, 4, offset);
|
|
2368
|
-
if (stream.start > 10000 /*
|
|
2382
|
+
if (stream.start > 10000 /* MaxLineLength */)
|
|
2369
2383
|
break;
|
|
2370
2384
|
}
|
|
2371
2385
|
}
|
|
@@ -2381,7 +2395,7 @@ class Parse {
|
|
|
2381
2395
|
length: this.parsedPos - this.chunkStart,
|
|
2382
2396
|
nodeSet,
|
|
2383
2397
|
topID: 0,
|
|
2384
|
-
maxBufferLength: 2048 /*
|
|
2398
|
+
maxBufferLength: 2048 /* ChunkSize */,
|
|
2385
2399
|
reused: this.chunkReused
|
|
2386
2400
|
});
|
|
2387
2401
|
tree = new Tree(tree.type, tree.children, tree.positions, tree.length, [[this.lang.stateAfter, this.lang.streamParser.copyState(this.state)]]);
|
|
@@ -2476,4 +2490,4 @@ function docID(data) {
|
|
|
2476
2490
|
return type;
|
|
2477
2491
|
}
|
|
2478
2492
|
|
|
2479
|
-
export { HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, StreamLanguage, StringStream, 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 };
|
|
2493
|
+
export { DocInput, HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, StreamLanguage, StringStream, 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemirror/language",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0",
|
|
4
4
|
"description": "Language support infrastructure for the CodeMirror code editor",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "cm-runtests",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"style-mod": "^4.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@codemirror/buildhelper": "^0.
|
|
37
|
+
"@codemirror/buildhelper": "^1.0.0",
|
|
38
38
|
"@lezer/javascript": "^1.0.0"
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|