@codemirror/language 0.19.4 → 0.19.5
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 +8 -0
- package/dist/index.cjs +35 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +35 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.19.5 (2021-11-17)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
The new function `syntaxTreeAvailable` can be used to check if a fully-parsed syntax tree is available up to a given document position.
|
|
6
|
+
|
|
7
|
+
The module now exports `syntaxParserRunning`, which tells you whether the background parser is still planning to do more work for a given editor view.
|
|
8
|
+
|
|
1
9
|
## 0.19.4 (2021-11-13)
|
|
2
10
|
|
|
3
11
|
### New features
|
package/dist/index.cjs
CHANGED
|
@@ -181,6 +181,30 @@ function ensureSyntaxTree(state, upto, timeout = 50) {
|
|
|
181
181
|
let parse = (_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context;
|
|
182
182
|
return !parse ? null : parse.treeLen >= upto || parse.work(timeout, upto) ? parse.tree : null;
|
|
183
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
Queries whether there is a full syntax tree available up to the
|
|
186
|
+
given document position. If there isn't, the background parse
|
|
187
|
+
process _might_ still be working and update the tree further, but
|
|
188
|
+
there is no guarantee of that—the parser will [stop
|
|
189
|
+
working](https://codemirror.net/6/docs/ref/#language.syntaxParserStopped) when it has spent a
|
|
190
|
+
certain amount of time or has moved beyond the visible viewport.
|
|
191
|
+
Always returns false if no language has been enabled.
|
|
192
|
+
*/
|
|
193
|
+
function syntaxTreeAvailable(state, upto = state.doc.length) {
|
|
194
|
+
var _a;
|
|
195
|
+
return ((_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context.isDone(upto)) || false;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
Tells you whether the language parser is planning to do more
|
|
199
|
+
parsing work (in a `requestIdleCallback` pseudo-thread) or has
|
|
200
|
+
stopped running, either because it parsed the entire document,
|
|
201
|
+
because it spent too much time and was cut off, or because there
|
|
202
|
+
is no language parser enabled.
|
|
203
|
+
*/
|
|
204
|
+
function syntaxParserRunning(view) {
|
|
205
|
+
var _a;
|
|
206
|
+
return ((_a = view.plugin(parseWorker)) === null || _a === void 0 ? void 0 : _a.isWorking()) || false;
|
|
207
|
+
}
|
|
184
208
|
// Lezer-style Input object for a Text document.
|
|
185
209
|
class DocInput {
|
|
186
210
|
constructor(doc, length = doc.length) {
|
|
@@ -491,6 +515,7 @@ const parseWorker = view.ViewPlugin.fromClass(class ParseWorker {
|
|
|
491
515
|
constructor(view) {
|
|
492
516
|
this.view = view;
|
|
493
517
|
this.working = -1;
|
|
518
|
+
this.workScheduled = 0;
|
|
494
519
|
// End of the current time chunk
|
|
495
520
|
this.chunkEnd = -1;
|
|
496
521
|
// Milliseconds of budget left for this chunk
|
|
@@ -541,7 +566,11 @@ const parseWorker = view.ViewPlugin.fromClass(class ParseWorker {
|
|
|
541
566
|
}
|
|
542
567
|
checkAsyncSchedule(cx) {
|
|
543
568
|
if (cx.scheduleOn) {
|
|
544
|
-
|
|
569
|
+
this.workScheduled++;
|
|
570
|
+
cx.scheduleOn
|
|
571
|
+
.then(() => this.scheduleWork())
|
|
572
|
+
.catch(err => view.logException(this.view.state, err))
|
|
573
|
+
.then(() => this.workScheduled--);
|
|
545
574
|
cx.scheduleOn = null;
|
|
546
575
|
}
|
|
547
576
|
}
|
|
@@ -549,6 +578,9 @@ const parseWorker = view.ViewPlugin.fromClass(class ParseWorker {
|
|
|
549
578
|
if (this.working >= 0)
|
|
550
579
|
cancelIdle(this.working);
|
|
551
580
|
}
|
|
581
|
+
isWorking() {
|
|
582
|
+
return this.working >= 0 || this.workScheduled > 0;
|
|
583
|
+
}
|
|
552
584
|
}, {
|
|
553
585
|
eventHandlers: { focus() { this.scheduleWork(); } }
|
|
554
586
|
});
|
|
@@ -1133,4 +1165,6 @@ exports.indentString = indentString;
|
|
|
1133
1165
|
exports.indentUnit = indentUnit;
|
|
1134
1166
|
exports.language = language;
|
|
1135
1167
|
exports.languageDataProp = languageDataProp;
|
|
1168
|
+
exports.syntaxParserRunning = syntaxParserRunning;
|
|
1136
1169
|
exports.syntaxTree = syntaxTree;
|
|
1170
|
+
exports.syntaxTreeAvailable = syntaxTreeAvailable;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NodeProp, NodeType, Parser, Tree, TreeFragment, Input, PartialParse, SyntaxNode } from '@lezer/common';
|
|
2
2
|
import { LRParser, ParserConfig } from '@lezer/lr';
|
|
3
3
|
import { Facet, Extension, EditorState } from '@codemirror/state';
|
|
4
|
+
import { EditorView } from '@codemirror/view';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
Node prop stored in a grammar's top syntax node to provide the
|
|
@@ -139,6 +140,24 @@ up to that point if the tree isn't already available.
|
|
|
139
140
|
*/
|
|
140
141
|
declare function ensureSyntaxTree(state: EditorState, upto: number, timeout?: number): Tree | null;
|
|
141
142
|
/**
|
|
143
|
+
Queries whether there is a full syntax tree available up to the
|
|
144
|
+
given document position. If there isn't, the background parse
|
|
145
|
+
process _might_ still be working and update the tree further, but
|
|
146
|
+
there is no guarantee of that—the parser will [stop
|
|
147
|
+
working](https://codemirror.net/6/docs/ref/#language.syntaxParserStopped) when it has spent a
|
|
148
|
+
certain amount of time or has moved beyond the visible viewport.
|
|
149
|
+
Always returns false if no language has been enabled.
|
|
150
|
+
*/
|
|
151
|
+
declare function syntaxTreeAvailable(state: EditorState, upto?: number): boolean;
|
|
152
|
+
/**
|
|
153
|
+
Tells you whether the language parser is planning to do more
|
|
154
|
+
parsing work (in a `requestIdleCallback` pseudo-thread) or has
|
|
155
|
+
stopped running, either because it parsed the entire document,
|
|
156
|
+
because it spent too much time and was cut off, or because there
|
|
157
|
+
is no language parser enabled.
|
|
158
|
+
*/
|
|
159
|
+
declare function syntaxParserRunning(view: EditorView): boolean;
|
|
160
|
+
/**
|
|
142
161
|
A parse context provided to parsers working on the editor content.
|
|
143
162
|
*/
|
|
144
163
|
declare class ParseContext {
|
|
@@ -590,4 +609,4 @@ declare function foldable(state: EditorState, lineStart: number, lineEnd: number
|
|
|
590
609
|
to: number;
|
|
591
610
|
} | null;
|
|
592
611
|
|
|
593
|
-
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, syntaxTree };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeProp, Tree, TreeFragment, Parser, NodeType } from '@lezer/common';
|
|
2
2
|
import { StateEffect, StateField, Facet, EditorState } from '@codemirror/state';
|
|
3
|
-
import { ViewPlugin } from '@codemirror/view';
|
|
3
|
+
import { ViewPlugin, logException } from '@codemirror/view';
|
|
4
4
|
import { countColumn } from '@codemirror/text';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -177,6 +177,30 @@ function ensureSyntaxTree(state, upto, timeout = 50) {
|
|
|
177
177
|
let parse = (_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context;
|
|
178
178
|
return !parse ? null : parse.treeLen >= upto || parse.work(timeout, upto) ? parse.tree : null;
|
|
179
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
Queries whether there is a full syntax tree available up to the
|
|
182
|
+
given document position. If there isn't, the background parse
|
|
183
|
+
process _might_ still be working and update the tree further, but
|
|
184
|
+
there is no guarantee of that—the parser will [stop
|
|
185
|
+
working](https://codemirror.net/6/docs/ref/#language.syntaxParserStopped) when it has spent a
|
|
186
|
+
certain amount of time or has moved beyond the visible viewport.
|
|
187
|
+
Always returns false if no language has been enabled.
|
|
188
|
+
*/
|
|
189
|
+
function syntaxTreeAvailable(state, upto = state.doc.length) {
|
|
190
|
+
var _a;
|
|
191
|
+
return ((_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context.isDone(upto)) || false;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
Tells you whether the language parser is planning to do more
|
|
195
|
+
parsing work (in a `requestIdleCallback` pseudo-thread) or has
|
|
196
|
+
stopped running, either because it parsed the entire document,
|
|
197
|
+
because it spent too much time and was cut off, or because there
|
|
198
|
+
is no language parser enabled.
|
|
199
|
+
*/
|
|
200
|
+
function syntaxParserRunning(view) {
|
|
201
|
+
var _a;
|
|
202
|
+
return ((_a = view.plugin(parseWorker)) === null || _a === void 0 ? void 0 : _a.isWorking()) || false;
|
|
203
|
+
}
|
|
180
204
|
// Lezer-style Input object for a Text document.
|
|
181
205
|
class DocInput {
|
|
182
206
|
constructor(doc, length = doc.length) {
|
|
@@ -487,6 +511,7 @@ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
|
|
|
487
511
|
constructor(view) {
|
|
488
512
|
this.view = view;
|
|
489
513
|
this.working = -1;
|
|
514
|
+
this.workScheduled = 0;
|
|
490
515
|
// End of the current time chunk
|
|
491
516
|
this.chunkEnd = -1;
|
|
492
517
|
// Milliseconds of budget left for this chunk
|
|
@@ -537,7 +562,11 @@ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
|
|
|
537
562
|
}
|
|
538
563
|
checkAsyncSchedule(cx) {
|
|
539
564
|
if (cx.scheduleOn) {
|
|
540
|
-
|
|
565
|
+
this.workScheduled++;
|
|
566
|
+
cx.scheduleOn
|
|
567
|
+
.then(() => this.scheduleWork())
|
|
568
|
+
.catch(err => logException(this.view.state, err))
|
|
569
|
+
.then(() => this.workScheduled--);
|
|
541
570
|
cx.scheduleOn = null;
|
|
542
571
|
}
|
|
543
572
|
}
|
|
@@ -545,6 +574,9 @@ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
|
|
|
545
574
|
if (this.working >= 0)
|
|
546
575
|
cancelIdle(this.working);
|
|
547
576
|
}
|
|
577
|
+
isWorking() {
|
|
578
|
+
return this.working >= 0 || this.workScheduled > 0;
|
|
579
|
+
}
|
|
548
580
|
}, {
|
|
549
581
|
eventHandlers: { focus() { this.scheduleWork(); } }
|
|
550
582
|
});
|
|
@@ -1104,4 +1136,4 @@ function foldable(state, lineStart, lineEnd) {
|
|
|
1104
1136
|
return syntaxFolding(state, lineStart, lineEnd);
|
|
1105
1137
|
}
|
|
1106
1138
|
|
|
1107
|
-
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, syntaxTree };
|
|
1139
|
+
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 };
|