@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.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +27 -20
- package/dist/index.d.cts +1185 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +28 -21
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -587,6 +587,11 @@ declare class TreeIndentContext extends IndentContext {
|
|
|
587
587
|
*/
|
|
588
588
|
get baseIndent(): number;
|
|
589
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
|
+
/**
|
|
590
595
|
Continue looking for indentations in the node's parent nodes,
|
|
591
596
|
and return the result of that.
|
|
592
597
|
*/
|
|
@@ -684,7 +689,7 @@ declare function foldable(state: EditorState, lineStart: number, lineEnd: number
|
|
|
684
689
|
from: number;
|
|
685
690
|
to: number;
|
|
686
691
|
} | null;
|
|
687
|
-
type DocRange = {
|
|
692
|
+
declare type DocRange = {
|
|
688
693
|
from: number;
|
|
689
694
|
to: number;
|
|
690
695
|
};
|
|
@@ -772,7 +777,7 @@ interface FoldConfig {
|
|
|
772
777
|
Create an extension that configures code folding.
|
|
773
778
|
*/
|
|
774
779
|
declare function codeFolding(config?: FoldConfig): Extension;
|
|
775
|
-
type Handlers = {
|
|
780
|
+
declare type Handlers = {
|
|
776
781
|
[event: string]: (view: EditorView, line: BlockInfo, event: Event) => boolean;
|
|
777
782
|
};
|
|
778
783
|
interface FoldGutterConfig {
|
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';
|
|
@@ -534,14 +534,14 @@ class LanguageState {
|
|
|
534
534
|
// state updates with parse work beyond the viewport.
|
|
535
535
|
let upto = this.context.treeLen == tr.startState.doc.length ? undefined
|
|
536
536
|
: Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
|
|
537
|
-
if (!newCx.work(20 /*
|
|
537
|
+
if (!newCx.work(20 /* Apply */, upto))
|
|
538
538
|
newCx.takeTree();
|
|
539
539
|
return new LanguageState(newCx);
|
|
540
540
|
}
|
|
541
541
|
static init(state) {
|
|
542
|
-
let vpTo = Math.min(3000 /*
|
|
542
|
+
let vpTo = Math.min(3000 /* InitViewport */, state.doc.length);
|
|
543
543
|
let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
|
|
544
|
-
if (!parseState.work(20 /*
|
|
544
|
+
if (!parseState.work(20 /* Apply */, vpTo))
|
|
545
545
|
parseState.takeTree();
|
|
546
546
|
return new LanguageState(parseState);
|
|
547
547
|
}
|
|
@@ -558,14 +558,14 @@ Language.state = /*@__PURE__*/StateField.define({
|
|
|
558
558
|
}
|
|
559
559
|
});
|
|
560
560
|
let requestIdle = (callback) => {
|
|
561
|
-
let timeout = setTimeout(() => callback(), 500 /*
|
|
561
|
+
let timeout = setTimeout(() => callback(), 500 /* MaxPause */);
|
|
562
562
|
return () => clearTimeout(timeout);
|
|
563
563
|
};
|
|
564
564
|
if (typeof requestIdleCallback != "undefined")
|
|
565
565
|
requestIdle = (callback) => {
|
|
566
566
|
let idle = -1, timeout = setTimeout(() => {
|
|
567
|
-
idle = requestIdleCallback(callback, { timeout: 500 /*
|
|
568
|
-
}, 100 /*
|
|
567
|
+
idle = requestIdleCallback(callback, { timeout: 500 /* MaxPause */ - 100 /* MinPause */ });
|
|
568
|
+
}, 100 /* MinPause */);
|
|
569
569
|
return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
|
|
570
570
|
};
|
|
571
571
|
const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending)
|
|
@@ -588,7 +588,7 @@ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
|
|
|
588
588
|
this.scheduleWork();
|
|
589
589
|
if (update.docChanged) {
|
|
590
590
|
if (this.view.hasFocus)
|
|
591
|
-
this.chunkBudget += 50 /*
|
|
591
|
+
this.chunkBudget += 50 /* ChangeBonus */;
|
|
592
592
|
this.scheduleWork();
|
|
593
593
|
}
|
|
594
594
|
this.checkAsyncSchedule(cx);
|
|
@@ -604,19 +604,19 @@ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
|
|
|
604
604
|
this.working = null;
|
|
605
605
|
let now = Date.now();
|
|
606
606
|
if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) { // Start a new chunk
|
|
607
|
-
this.chunkEnd = now + 30000 /*
|
|
608
|
-
this.chunkBudget = 3000 /*
|
|
607
|
+
this.chunkEnd = now + 30000 /* ChunkTime */;
|
|
608
|
+
this.chunkBudget = 3000 /* ChunkBudget */;
|
|
609
609
|
}
|
|
610
610
|
if (this.chunkBudget <= 0)
|
|
611
611
|
return; // No more budget
|
|
612
612
|
let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
|
|
613
|
-
if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /*
|
|
613
|
+
if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* MaxParseAhead */))
|
|
614
614
|
return;
|
|
615
|
-
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);
|
|
616
616
|
let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1000;
|
|
617
617
|
let done = field.context.work(() => {
|
|
618
618
|
return isInputPending && isInputPending() || Date.now() > endTime;
|
|
619
|
-
}, vpTo + (viewportFirst ? 0 : 100000 /*
|
|
619
|
+
}, vpTo + (viewportFirst ? 0 : 100000 /* MaxParseAhead */));
|
|
620
620
|
this.chunkBudget -= Date.now() - now;
|
|
621
621
|
if (done || this.chunkBudget <= 0) {
|
|
622
622
|
field.context.takeTree();
|
|
@@ -1058,13 +1058,20 @@ class TreeIndentContext extends IndentContext {
|
|
|
1058
1058
|
on if it is covered by another such node.
|
|
1059
1059
|
*/
|
|
1060
1060
|
get baseIndent() {
|
|
1061
|
-
|
|
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);
|
|
1062
1069
|
// Skip line starts that are covered by a sibling (or cousin, etc)
|
|
1063
1070
|
for (;;) {
|
|
1064
|
-
let atBreak =
|
|
1071
|
+
let atBreak = node.resolve(line.from);
|
|
1065
1072
|
while (atBreak.parent && atBreak.parent.from == atBreak.from)
|
|
1066
1073
|
atBreak = atBreak.parent;
|
|
1067
|
-
if (isParent(atBreak,
|
|
1074
|
+
if (isParent(atBreak, node))
|
|
1068
1075
|
break;
|
|
1069
1076
|
line = this.state.doc.lineAt(atBreak.from);
|
|
1070
1077
|
}
|
|
@@ -2196,7 +2203,7 @@ class StreamLanguage extends Language {
|
|
|
2196
2203
|
state = this.streamParser.startState(cx.unit);
|
|
2197
2204
|
statePos = 0;
|
|
2198
2205
|
}
|
|
2199
|
-
if (pos - statePos > 10000 /*
|
|
2206
|
+
if (pos - statePos > 10000 /* MaxIndentScanDist */)
|
|
2200
2207
|
return null;
|
|
2201
2208
|
while (statePos < pos) {
|
|
2202
2209
|
let line = cx.state.doc.lineAt(statePos), end = Math.min(pos, line.to);
|
|
@@ -2278,7 +2285,7 @@ class Parse {
|
|
|
2278
2285
|
this.chunks.push(tree.children[i]);
|
|
2279
2286
|
this.chunkPos.push(tree.positions[i]);
|
|
2280
2287
|
}
|
|
2281
|
-
if (context && this.parsedPos < context.viewport.from - 100000 /*
|
|
2288
|
+
if (context && this.parsedPos < context.viewport.from - 100000 /* MaxDistanceBeforeViewport */) {
|
|
2282
2289
|
this.state = this.lang.streamParser.startState(getIndentUnit(context.state));
|
|
2283
2290
|
context.skipUntilInView(this.parsedPos, context.viewport.from);
|
|
2284
2291
|
this.parsedPos = context.viewport.from;
|
|
@@ -2288,7 +2295,7 @@ class Parse {
|
|
|
2288
2295
|
advance() {
|
|
2289
2296
|
let context = ParseContext.get();
|
|
2290
2297
|
let parseEnd = this.stoppedAt == null ? this.to : Math.min(this.to, this.stoppedAt);
|
|
2291
|
-
let end = Math.min(parseEnd, this.chunkStart + 2048 /*
|
|
2298
|
+
let end = Math.min(parseEnd, this.chunkStart + 2048 /* ChunkSize */);
|
|
2292
2299
|
if (context)
|
|
2293
2300
|
end = Math.min(end, context.viewport.to);
|
|
2294
2301
|
while (this.parsedPos < end)
|
|
@@ -2372,7 +2379,7 @@ class Parse {
|
|
|
2372
2379
|
let token = readToken(streamParser.token, stream, this.state);
|
|
2373
2380
|
if (token)
|
|
2374
2381
|
offset = this.emitToken(this.lang.tokenTable.resolve(token), this.parsedPos + stream.start, this.parsedPos + stream.pos, 4, offset);
|
|
2375
|
-
if (stream.start > 10000 /*
|
|
2382
|
+
if (stream.start > 10000 /* MaxLineLength */)
|
|
2376
2383
|
break;
|
|
2377
2384
|
}
|
|
2378
2385
|
}
|
|
@@ -2388,7 +2395,7 @@ class Parse {
|
|
|
2388
2395
|
length: this.parsedPos - this.chunkStart,
|
|
2389
2396
|
nodeSet,
|
|
2390
2397
|
topID: 0,
|
|
2391
|
-
maxBufferLength: 2048 /*
|
|
2398
|
+
maxBufferLength: 2048 /* ChunkSize */,
|
|
2392
2399
|
reused: this.chunkReused
|
|
2393
2400
|
});
|
|
2394
2401
|
tree = new Tree(tree.type, tree.children, tree.positions, tree.length, [[this.lang.stateAfter, this.lang.streamParser.copyState(this.state)]]);
|
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": {
|