@codemirror/language 0.20.0 → 6.0.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 +18 -0
- package/dist/index.cjs +20 -11
- package/dist/index.d.ts +20 -1
- package/dist/index.js +20 -11
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 6.0.0 (2022-06-08)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
The `foldingChanged` option to `foldGutter` can now be used to trigger a recomputation of the fold markers.
|
|
6
|
+
|
|
7
|
+
## 0.20.2 (2022-05-20)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
List style-mod as a dependency.
|
|
12
|
+
|
|
13
|
+
## 0.20.1 (2022-05-18)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Make sure `all` styles in the CSS generated for a `HighlightStyle` have a lower precedence than the other rules defined for the style. Use a shorthand property
|
|
18
|
+
|
|
1
19
|
## 0.20.0 (2022-04-20)
|
|
2
20
|
|
|
3
21
|
### Breaking changes
|
package/dist/index.cjs
CHANGED
|
@@ -248,9 +248,6 @@ let currentContext = null;
|
|
|
248
248
|
A parse context provided to parsers working on the editor content.
|
|
249
249
|
*/
|
|
250
250
|
class ParseContext {
|
|
251
|
-
/**
|
|
252
|
-
@internal
|
|
253
|
-
*/
|
|
254
251
|
constructor(parser,
|
|
255
252
|
/**
|
|
256
253
|
The current editor state.
|
|
@@ -301,6 +298,12 @@ class ParseContext {
|
|
|
301
298
|
*/
|
|
302
299
|
this.tempSkipped = [];
|
|
303
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
@internal
|
|
303
|
+
*/
|
|
304
|
+
static create(parser, state, viewport) {
|
|
305
|
+
return new ParseContext(parser, state, [], common.Tree.empty, 0, viewport, [], null);
|
|
306
|
+
}
|
|
304
307
|
startParse() {
|
|
305
308
|
return this.parser.startParse(new DocInput(this.state.doc), this.fragments);
|
|
306
309
|
}
|
|
@@ -506,7 +509,7 @@ class LanguageState {
|
|
|
506
509
|
}
|
|
507
510
|
static init(state) {
|
|
508
511
|
let vpTo = Math.min(3000 /* InitViewport */, state.doc.length);
|
|
509
|
-
let parseState =
|
|
512
|
+
let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
|
|
510
513
|
if (!parseState.work(20 /* Apply */, vpTo))
|
|
511
514
|
parseState.takeTree();
|
|
512
515
|
return new LanguageState(parseState);
|
|
@@ -934,7 +937,7 @@ function indentFrom(node, pos, base) {
|
|
|
934
937
|
for (; node; node = node.parent) {
|
|
935
938
|
let strategy = indentStrategy(node);
|
|
936
939
|
if (strategy)
|
|
937
|
-
return strategy(
|
|
940
|
+
return strategy(TreeIndentContext.create(base, pos, node));
|
|
938
941
|
}
|
|
939
942
|
return null;
|
|
940
943
|
}
|
|
@@ -944,9 +947,6 @@ Objects of this type provide context information and helper
|
|
|
944
947
|
methods to indentation functions registered on syntax nodes.
|
|
945
948
|
*/
|
|
946
949
|
class TreeIndentContext extends IndentContext {
|
|
947
|
-
/**
|
|
948
|
-
@internal
|
|
949
|
-
*/
|
|
950
950
|
constructor(base,
|
|
951
951
|
/**
|
|
952
952
|
The position at which indentation is being computed.
|
|
@@ -963,6 +963,12 @@ class TreeIndentContext extends IndentContext {
|
|
|
963
963
|
this.node = node;
|
|
964
964
|
}
|
|
965
965
|
/**
|
|
966
|
+
@internal
|
|
967
|
+
*/
|
|
968
|
+
static create(base, pos, node) {
|
|
969
|
+
return new TreeIndentContext(base, pos, node);
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
966
972
|
Get the text directly after `this.pos`, either the entire line
|
|
967
973
|
or the next 100 characters, whichever is shorter.
|
|
968
974
|
*/
|
|
@@ -1374,6 +1380,7 @@ const foldGutterDefaults = {
|
|
|
1374
1380
|
closedText: "›",
|
|
1375
1381
|
markerDOM: null,
|
|
1376
1382
|
domEventHandlers: {},
|
|
1383
|
+
foldingChanged: () => false
|
|
1377
1384
|
};
|
|
1378
1385
|
class FoldMarker extends view.GutterMarker {
|
|
1379
1386
|
constructor(config, open) {
|
|
@@ -1408,7 +1415,8 @@ function foldGutter(config = {}) {
|
|
|
1408
1415
|
if (update.docChanged || update.viewportChanged ||
|
|
1409
1416
|
update.startState.facet(language) != update.state.facet(language) ||
|
|
1410
1417
|
update.startState.field(foldState, false) != update.state.field(foldState, false) ||
|
|
1411
|
-
syntaxTree(update.startState) != syntaxTree(update.state)
|
|
1418
|
+
syntaxTree(update.startState) != syntaxTree(update.state) ||
|
|
1419
|
+
fullConfig.foldingChanged(update))
|
|
1412
1420
|
this.markers = this.buildMarkers(update.view);
|
|
1413
1421
|
}
|
|
1414
1422
|
buildMarkers(view) {
|
|
@@ -1478,6 +1486,7 @@ class HighlightStyle {
|
|
|
1478
1486
|
(modSpec || (modSpec = Object.create(null)))["." + cls] = spec;
|
|
1479
1487
|
return cls;
|
|
1480
1488
|
}
|
|
1489
|
+
const all = typeof options.all == "string" ? options.all : options.all ? def(options.all) : undefined;
|
|
1481
1490
|
const scopeOpt = options.scope;
|
|
1482
1491
|
this.scope = scopeOpt instanceof Language ? (type) => type.prop(languageDataProp) == scopeOpt.data
|
|
1483
1492
|
: scopeOpt ? (type) => type == scopeOpt : undefined;
|
|
@@ -1485,7 +1494,7 @@ class HighlightStyle {
|
|
|
1485
1494
|
tag: style.tag,
|
|
1486
1495
|
class: style.class || def(Object.assign({}, style, { tag: null }))
|
|
1487
1496
|
})), {
|
|
1488
|
-
all
|
|
1497
|
+
all,
|
|
1489
1498
|
}).style;
|
|
1490
1499
|
this.module = modSpec ? new styleMod.StyleModule(modSpec) : null;
|
|
1491
1500
|
this.themeType = options.themeType;
|
|
@@ -1804,7 +1813,7 @@ which uses it to tokenize the content.
|
|
|
1804
1813
|
*/
|
|
1805
1814
|
class StringStream {
|
|
1806
1815
|
/**
|
|
1807
|
-
|
|
1816
|
+
Create a stream.
|
|
1808
1817
|
*/
|
|
1809
1818
|
constructor(
|
|
1810
1819
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { NodeProp, Parser, Tree, TreeFragment, SyntaxNode, NodeType } from '@lez
|
|
|
2
2
|
import { LRParser, ParserConfig } from '@lezer/lr';
|
|
3
3
|
import * as _codemirror_state from '@codemirror/state';
|
|
4
4
|
import { Facet, Extension, EditorState, Range } from '@codemirror/state';
|
|
5
|
-
import { EditorView, DecorationSet, Command, KeyBinding, BlockInfo, Decoration } from '@codemirror/view';
|
|
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';
|
|
8
8
|
|
|
@@ -187,6 +187,7 @@ declare class ParseContext {
|
|
|
187
187
|
to: number;
|
|
188
188
|
};
|
|
189
189
|
private parse;
|
|
190
|
+
private constructor();
|
|
190
191
|
private startParse;
|
|
191
192
|
private withContext;
|
|
192
193
|
private withoutTempSkipped;
|
|
@@ -487,6 +488,7 @@ declare class TreeIndentContext extends IndentContext {
|
|
|
487
488
|
applies.
|
|
488
489
|
*/
|
|
489
490
|
readonly node: SyntaxNode;
|
|
491
|
+
private constructor();
|
|
490
492
|
/**
|
|
491
493
|
Get the text directly after `this.pos`, either the entire line
|
|
492
494
|
or the next 100 characters, whichever is shorter.
|
|
@@ -696,6 +698,11 @@ interface FoldGutterConfig {
|
|
|
696
698
|
Supply event handlers for DOM events on this gutter.
|
|
697
699
|
*/
|
|
698
700
|
domEventHandlers?: Handlers;
|
|
701
|
+
/**
|
|
702
|
+
When given, if this returns true for a given view update,
|
|
703
|
+
recompute the fold markers.
|
|
704
|
+
*/
|
|
705
|
+
foldingChanged?: (update: ViewUpdate) => boolean;
|
|
699
706
|
}
|
|
700
707
|
/**
|
|
701
708
|
Create an extension that registers a fold gutter, which shows a
|
|
@@ -900,6 +907,18 @@ declare class StringStream {
|
|
|
900
907
|
private lastColumnPos;
|
|
901
908
|
private lastColumnValue;
|
|
902
909
|
/**
|
|
910
|
+
Create a stream.
|
|
911
|
+
*/
|
|
912
|
+
constructor(
|
|
913
|
+
/**
|
|
914
|
+
The line.
|
|
915
|
+
*/
|
|
916
|
+
string: string, tabSize: number,
|
|
917
|
+
/**
|
|
918
|
+
The current indent unit size.
|
|
919
|
+
*/
|
|
920
|
+
indentUnit: number);
|
|
921
|
+
/**
|
|
903
922
|
True if we are at the end of the line.
|
|
904
923
|
*/
|
|
905
924
|
eol(): boolean;
|
package/dist/index.js
CHANGED
|
@@ -244,9 +244,6 @@ let currentContext = null;
|
|
|
244
244
|
A parse context provided to parsers working on the editor content.
|
|
245
245
|
*/
|
|
246
246
|
class ParseContext {
|
|
247
|
-
/**
|
|
248
|
-
@internal
|
|
249
|
-
*/
|
|
250
247
|
constructor(parser,
|
|
251
248
|
/**
|
|
252
249
|
The current editor state.
|
|
@@ -297,6 +294,12 @@ class ParseContext {
|
|
|
297
294
|
*/
|
|
298
295
|
this.tempSkipped = [];
|
|
299
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
@internal
|
|
299
|
+
*/
|
|
300
|
+
static create(parser, state, viewport) {
|
|
301
|
+
return new ParseContext(parser, state, [], Tree.empty, 0, viewport, [], null);
|
|
302
|
+
}
|
|
300
303
|
startParse() {
|
|
301
304
|
return this.parser.startParse(new DocInput(this.state.doc), this.fragments);
|
|
302
305
|
}
|
|
@@ -502,7 +505,7 @@ class LanguageState {
|
|
|
502
505
|
}
|
|
503
506
|
static init(state) {
|
|
504
507
|
let vpTo = Math.min(3000 /* InitViewport */, state.doc.length);
|
|
505
|
-
let parseState =
|
|
508
|
+
let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
|
|
506
509
|
if (!parseState.work(20 /* Apply */, vpTo))
|
|
507
510
|
parseState.takeTree();
|
|
508
511
|
return new LanguageState(parseState);
|
|
@@ -930,7 +933,7 @@ function indentFrom(node, pos, base) {
|
|
|
930
933
|
for (; node; node = node.parent) {
|
|
931
934
|
let strategy = indentStrategy(node);
|
|
932
935
|
if (strategy)
|
|
933
|
-
return strategy(
|
|
936
|
+
return strategy(TreeIndentContext.create(base, pos, node));
|
|
934
937
|
}
|
|
935
938
|
return null;
|
|
936
939
|
}
|
|
@@ -940,9 +943,6 @@ Objects of this type provide context information and helper
|
|
|
940
943
|
methods to indentation functions registered on syntax nodes.
|
|
941
944
|
*/
|
|
942
945
|
class TreeIndentContext extends IndentContext {
|
|
943
|
-
/**
|
|
944
|
-
@internal
|
|
945
|
-
*/
|
|
946
946
|
constructor(base,
|
|
947
947
|
/**
|
|
948
948
|
The position at which indentation is being computed.
|
|
@@ -959,6 +959,12 @@ class TreeIndentContext extends IndentContext {
|
|
|
959
959
|
this.node = node;
|
|
960
960
|
}
|
|
961
961
|
/**
|
|
962
|
+
@internal
|
|
963
|
+
*/
|
|
964
|
+
static create(base, pos, node) {
|
|
965
|
+
return new TreeIndentContext(base, pos, node);
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
962
968
|
Get the text directly after `this.pos`, either the entire line
|
|
963
969
|
or the next 100 characters, whichever is shorter.
|
|
964
970
|
*/
|
|
@@ -1370,6 +1376,7 @@ const foldGutterDefaults = {
|
|
|
1370
1376
|
closedText: "›",
|
|
1371
1377
|
markerDOM: null,
|
|
1372
1378
|
domEventHandlers: {},
|
|
1379
|
+
foldingChanged: () => false
|
|
1373
1380
|
};
|
|
1374
1381
|
class FoldMarker extends GutterMarker {
|
|
1375
1382
|
constructor(config, open) {
|
|
@@ -1404,7 +1411,8 @@ function foldGutter(config = {}) {
|
|
|
1404
1411
|
if (update.docChanged || update.viewportChanged ||
|
|
1405
1412
|
update.startState.facet(language) != update.state.facet(language) ||
|
|
1406
1413
|
update.startState.field(foldState, false) != update.state.field(foldState, false) ||
|
|
1407
|
-
syntaxTree(update.startState) != syntaxTree(update.state)
|
|
1414
|
+
syntaxTree(update.startState) != syntaxTree(update.state) ||
|
|
1415
|
+
fullConfig.foldingChanged(update))
|
|
1408
1416
|
this.markers = this.buildMarkers(update.view);
|
|
1409
1417
|
}
|
|
1410
1418
|
buildMarkers(view) {
|
|
@@ -1474,6 +1482,7 @@ class HighlightStyle {
|
|
|
1474
1482
|
(modSpec || (modSpec = Object.create(null)))["." + cls] = spec;
|
|
1475
1483
|
return cls;
|
|
1476
1484
|
}
|
|
1485
|
+
const all = typeof options.all == "string" ? options.all : options.all ? def(options.all) : undefined;
|
|
1477
1486
|
const scopeOpt = options.scope;
|
|
1478
1487
|
this.scope = scopeOpt instanceof Language ? (type) => type.prop(languageDataProp) == scopeOpt.data
|
|
1479
1488
|
: scopeOpt ? (type) => type == scopeOpt : undefined;
|
|
@@ -1481,7 +1490,7 @@ class HighlightStyle {
|
|
|
1481
1490
|
tag: style.tag,
|
|
1482
1491
|
class: style.class || def(Object.assign({}, style, { tag: null }))
|
|
1483
1492
|
})), {
|
|
1484
|
-
all
|
|
1493
|
+
all,
|
|
1485
1494
|
}).style;
|
|
1486
1495
|
this.module = modSpec ? new StyleModule(modSpec) : null;
|
|
1487
1496
|
this.themeType = options.themeType;
|
|
@@ -1800,7 +1809,7 @@ which uses it to tokenize the content.
|
|
|
1800
1809
|
*/
|
|
1801
1810
|
class StringStream {
|
|
1802
1811
|
/**
|
|
1803
|
-
|
|
1812
|
+
Create a stream.
|
|
1804
1813
|
*/
|
|
1805
1814
|
constructor(
|
|
1806
1815
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemirror/language",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Language support infrastructure for the CodeMirror code editor",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "cm-runtests",
|
|
@@ -26,15 +26,16 @@
|
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@codemirror/state": "^0.
|
|
30
|
-
"@codemirror/view": "^0.
|
|
31
|
-
"@lezer/common": "^0.
|
|
32
|
-
"@lezer/highlight": "^0.
|
|
33
|
-
"@lezer/lr": "^0.
|
|
29
|
+
"@codemirror/state": "^6.0.0",
|
|
30
|
+
"@codemirror/view": "^6.0.0",
|
|
31
|
+
"@lezer/common": "^1.0.0",
|
|
32
|
+
"@lezer/highlight": "^1.0.0",
|
|
33
|
+
"@lezer/lr": "^1.0.0",
|
|
34
|
+
"style-mod": "^4.0.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@codemirror/buildhelper": "^0.1.5",
|
|
37
|
-
"@lezer/javascript": "^0.
|
|
38
|
+
"@lezer/javascript": "^1.0.0"
|
|
38
39
|
},
|
|
39
40
|
"repository": {
|
|
40
41
|
"type": "git",
|