@codemirror/lint 0.19.6 → 0.20.2
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 +20 -0
- package/dist/index.cjs +54 -32
- package/dist/index.d.ts +34 -9
- package/dist/index.js +44 -22
- package/package.json +3 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## 0.20.2 (2022-05-02)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
The package now exports the `LintSource` function type.
|
|
6
|
+
|
|
7
|
+
The new `markerFilter` and `tooltipFilter` options to `linter` and `lintGutter` allow more control over which diagnostics are visible and which have tooltips.
|
|
8
|
+
|
|
9
|
+
## 0.20.1 (2022-04-22)
|
|
10
|
+
|
|
11
|
+
### Bug fixes
|
|
12
|
+
|
|
13
|
+
Hide lint tooltips when the document is changed.
|
|
14
|
+
|
|
15
|
+
## 0.20.0 (2022-04-20)
|
|
16
|
+
|
|
17
|
+
### Breaking changes
|
|
18
|
+
|
|
19
|
+
Update dependencies to 0.20.0
|
|
20
|
+
|
|
1
21
|
## 0.19.6 (2022-03-04)
|
|
2
22
|
|
|
3
23
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -4,10 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var view = require('@codemirror/view');
|
|
6
6
|
var state = require('@codemirror/state');
|
|
7
|
-
var tooltip = require('@codemirror/tooltip');
|
|
8
|
-
var panel = require('@codemirror/panel');
|
|
9
|
-
var gutter = require('@codemirror/gutter');
|
|
10
|
-
var rangeset = require('@codemirror/rangeset');
|
|
11
7
|
var elt = require('crelt');
|
|
12
8
|
|
|
13
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -28,7 +24,12 @@ class LintState {
|
|
|
28
24
|
this.selected = selected;
|
|
29
25
|
}
|
|
30
26
|
static init(diagnostics, panel, state) {
|
|
31
|
-
|
|
27
|
+
// Filter the list of diagnostics for which to create markers
|
|
28
|
+
let markedDiagnostics = diagnostics;
|
|
29
|
+
let diagnosticFilter = state.facet(lintConfig).markerFilter;
|
|
30
|
+
if (diagnosticFilter)
|
|
31
|
+
markedDiagnostics = diagnosticFilter(markedDiagnostics);
|
|
32
|
+
let ranges = view.Decoration.set(markedDiagnostics.map((d) => {
|
|
32
33
|
// For zero-length ranges or ranges covering only a line break, create a widget
|
|
33
34
|
return d.from == d.to || (d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from)
|
|
34
35
|
? view.Decoration.widget({
|
|
@@ -53,6 +54,9 @@ function findDiagnostic(diagnostics, diagnostic = null, after = 0) {
|
|
|
53
54
|
});
|
|
54
55
|
return found;
|
|
55
56
|
}
|
|
57
|
+
function hideTooltip(tr, tooltip) {
|
|
58
|
+
return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
|
|
59
|
+
}
|
|
56
60
|
function maybeEnableLint(state$1, effects) {
|
|
57
61
|
return state$1.field(lintState, false) ? effects : effects.concat(state.StateEffect.appendConfig.of([
|
|
58
62
|
lintState,
|
|
@@ -62,7 +66,7 @@ function maybeEnableLint(state$1, effects) {
|
|
|
62
66
|
activeMark.range(selected.from, selected.to)
|
|
63
67
|
]);
|
|
64
68
|
}),
|
|
65
|
-
|
|
69
|
+
view.hoverTooltip(lintTooltip, { hideOn: hideTooltip }),
|
|
66
70
|
baseTheme
|
|
67
71
|
]));
|
|
68
72
|
}
|
|
@@ -109,7 +113,7 @@ const lintState = state.StateField.define({
|
|
|
109
113
|
}
|
|
110
114
|
return value;
|
|
111
115
|
},
|
|
112
|
-
provide: f => [
|
|
116
|
+
provide: f => [view.showPanel.from(f, val => val.panel),
|
|
113
117
|
view.EditorView.decorations.from(f, s => s.diagnostics)]
|
|
114
118
|
});
|
|
115
119
|
/**
|
|
@@ -131,6 +135,9 @@ function lintTooltip(view, pos, side) {
|
|
|
131
135
|
stackEnd = Math.max(to, stackEnd);
|
|
132
136
|
}
|
|
133
137
|
});
|
|
138
|
+
let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
|
|
139
|
+
if (diagnosticFilter)
|
|
140
|
+
found = diagnosticFilter(found);
|
|
134
141
|
if (!found.length)
|
|
135
142
|
return null;
|
|
136
143
|
return {
|
|
@@ -148,13 +155,13 @@ function diagnosticsTooltip(view, diagnostics) {
|
|
|
148
155
|
/**
|
|
149
156
|
Command to open and focus the lint panel.
|
|
150
157
|
*/
|
|
151
|
-
const openLintPanel = (view) => {
|
|
152
|
-
let field = view.state.field(lintState, false);
|
|
158
|
+
const openLintPanel = (view$1) => {
|
|
159
|
+
let field = view$1.state.field(lintState, false);
|
|
153
160
|
if (!field || !field.panel)
|
|
154
|
-
view.dispatch({ effects: maybeEnableLint(view.state, [togglePanel.of(true)]) });
|
|
155
|
-
let panel
|
|
156
|
-
if (panel
|
|
157
|
-
panel
|
|
161
|
+
view$1.dispatch({ effects: maybeEnableLint(view$1.state, [togglePanel.of(true)]) });
|
|
162
|
+
let panel = view.getPanel(view$1, LintPanel.open);
|
|
163
|
+
if (panel)
|
|
164
|
+
panel.dom.querySelector(".cm-panel-lint ul").focus();
|
|
158
165
|
return true;
|
|
159
166
|
};
|
|
160
167
|
/**
|
|
@@ -198,7 +205,7 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
|
|
|
198
205
|
this.view = view;
|
|
199
206
|
this.timeout = -1;
|
|
200
207
|
this.set = true;
|
|
201
|
-
let { delay } = view.state.facet(
|
|
208
|
+
let { delay } = view.state.facet(lintConfig);
|
|
202
209
|
this.lintTime = Date.now() + delay;
|
|
203
210
|
this.run = this.run.bind(this);
|
|
204
211
|
this.timeout = setTimeout(this.run, delay);
|
|
@@ -210,7 +217,7 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
|
|
|
210
217
|
}
|
|
211
218
|
else {
|
|
212
219
|
this.set = false;
|
|
213
|
-
let { state } = this.view, { sources } = state.facet(
|
|
220
|
+
let { state } = this.view, { sources } = state.facet(lintConfig);
|
|
214
221
|
Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
|
|
215
222
|
let all = annotations.reduce((a, b) => a.concat(b));
|
|
216
223
|
if (this.view.state.doc == state.doc)
|
|
@@ -219,12 +226,12 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
|
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
228
|
update(update) {
|
|
222
|
-
let
|
|
223
|
-
if (update.docChanged ||
|
|
224
|
-
this.lintTime = Date.now() +
|
|
229
|
+
let config = update.state.facet(lintConfig);
|
|
230
|
+
if (update.docChanged || config != update.startState.facet(lintConfig)) {
|
|
231
|
+
this.lintTime = Date.now() + config.delay;
|
|
225
232
|
if (!this.set) {
|
|
226
233
|
this.set = true;
|
|
227
|
-
this.timeout = setTimeout(this.run,
|
|
234
|
+
this.timeout = setTimeout(this.run, config.delay);
|
|
228
235
|
}
|
|
229
236
|
}
|
|
230
237
|
}
|
|
@@ -238,9 +245,13 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
|
|
|
238
245
|
clearTimeout(this.timeout);
|
|
239
246
|
}
|
|
240
247
|
});
|
|
241
|
-
const
|
|
248
|
+
const lintConfig = state.Facet.define({
|
|
242
249
|
combine(input) {
|
|
243
|
-
return { sources: input.map(i => i.source),
|
|
250
|
+
return Object.assign({ sources: input.map(i => i.source) }, state.combineConfig(input.map(i => i.config), {
|
|
251
|
+
delay: 750,
|
|
252
|
+
markerFilter: null,
|
|
253
|
+
tooltipFilter: null
|
|
254
|
+
}));
|
|
244
255
|
},
|
|
245
256
|
enables: lintPlugin
|
|
246
257
|
});
|
|
@@ -250,8 +261,7 @@ enables linting with that source. It will be called whenever the
|
|
|
250
261
|
editor is idle (after its content changed).
|
|
251
262
|
*/
|
|
252
263
|
function linter(source, config = {}) {
|
|
253
|
-
|
|
254
|
-
return lintSource.of({ source, delay: (_a = config.delay) !== null && _a !== void 0 ? _a : 750 });
|
|
264
|
+
return lintConfig.of({ source, config });
|
|
255
265
|
}
|
|
256
266
|
/**
|
|
257
267
|
Forces any linters [configured](https://codemirror.net/6/docs/ref/#lint.linter) to run when the
|
|
@@ -577,7 +587,7 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
577
587
|
}
|
|
578
588
|
}
|
|
579
589
|
});
|
|
580
|
-
class LintGutterMarker extends
|
|
590
|
+
class LintGutterMarker extends view.GutterMarker {
|
|
581
591
|
constructor(diagnostics) {
|
|
582
592
|
super();
|
|
583
593
|
this.diagnostics = diagnostics;
|
|
@@ -589,7 +599,12 @@ class LintGutterMarker extends gutter.GutterMarker {
|
|
|
589
599
|
toDOM(view) {
|
|
590
600
|
let elt = document.createElement("div");
|
|
591
601
|
elt.className = "cm-lint-marker cm-lint-marker-" + this.severity;
|
|
592
|
-
|
|
602
|
+
let diagnostics = this.diagnostics;
|
|
603
|
+
let diagnosticsFilter = view.state.facet(lintGutterConfig).tooltipFilter;
|
|
604
|
+
if (diagnosticsFilter)
|
|
605
|
+
diagnostics = diagnosticsFilter(diagnostics);
|
|
606
|
+
if (diagnostics.length)
|
|
607
|
+
elt.onmouseover = () => gutterMarkerMouseOver(view, elt, diagnostics);
|
|
593
608
|
return elt;
|
|
594
609
|
}
|
|
595
610
|
}
|
|
@@ -649,22 +664,27 @@ function markersForDiagnostics(doc, diagnostics) {
|
|
|
649
664
|
for (let line in byLine) {
|
|
650
665
|
markers.push(new LintGutterMarker(byLine[line]).range(+line));
|
|
651
666
|
}
|
|
652
|
-
return
|
|
667
|
+
return state.RangeSet.of(markers, true);
|
|
653
668
|
}
|
|
654
|
-
const lintGutterExtension =
|
|
669
|
+
const lintGutterExtension = view.gutter({
|
|
655
670
|
class: "cm-gutter-lint",
|
|
656
671
|
markers: view => view.state.field(lintGutterMarkers),
|
|
657
672
|
});
|
|
658
673
|
const lintGutterMarkers = state.StateField.define({
|
|
659
674
|
create() {
|
|
660
|
-
return
|
|
675
|
+
return state.RangeSet.empty;
|
|
661
676
|
},
|
|
662
677
|
update(markers, tr) {
|
|
663
678
|
markers = markers.map(tr.changes);
|
|
664
|
-
|
|
679
|
+
let diagnosticFilter = tr.state.facet(lintGutterConfig).markerFilter;
|
|
680
|
+
for (let effect of tr.effects) {
|
|
665
681
|
if (effect.is(setDiagnosticsEffect)) {
|
|
666
|
-
|
|
682
|
+
let diagnostics = effect.value;
|
|
683
|
+
if (diagnosticFilter)
|
|
684
|
+
diagnostics = diagnosticFilter(diagnostics || []);
|
|
685
|
+
markers = markersForDiagnostics(tr.state.doc, diagnostics.slice(0));
|
|
667
686
|
}
|
|
687
|
+
}
|
|
668
688
|
return markers;
|
|
669
689
|
}
|
|
670
690
|
});
|
|
@@ -673,10 +693,10 @@ const lintGutterTooltip = state.StateField.define({
|
|
|
673
693
|
create() { return null; },
|
|
674
694
|
update(tooltip, tr) {
|
|
675
695
|
if (tooltip && tr.docChanged)
|
|
676
|
-
tooltip = Object.assign(Object.assign({}, tooltip), { pos: tr.changes.mapPos(tooltip.pos) });
|
|
696
|
+
tooltip = hideTooltip(tr, tooltip) ? null : Object.assign(Object.assign({}, tooltip), { pos: tr.changes.mapPos(tooltip.pos) });
|
|
677
697
|
return tr.effects.reduce((t, e) => e.is(setLintGutterTooltip) ? e.value : t, tooltip);
|
|
678
698
|
},
|
|
679
|
-
provide: field =>
|
|
699
|
+
provide: field => view.showTooltip.from(field)
|
|
680
700
|
});
|
|
681
701
|
const lintGutterTheme = view.EditorView.baseTheme({
|
|
682
702
|
".cm-gutter-lint": {
|
|
@@ -703,6 +723,8 @@ const lintGutterConfig = state.Facet.define({
|
|
|
703
723
|
combine(configs) {
|
|
704
724
|
return state.combineConfig(configs, {
|
|
705
725
|
hoverTime: 300 /* Time */,
|
|
726
|
+
markerFilter: null,
|
|
727
|
+
tooltipFilter: null
|
|
706
728
|
});
|
|
707
729
|
}
|
|
708
730
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -47,15 +47,43 @@ interface Action {
|
|
|
47
47
|
/**
|
|
48
48
|
The function to call when the user activates this action. Is
|
|
49
49
|
given the diagnostic's _current_ position, which may have
|
|
50
|
-
changed since the creation of the diagnostic due to editing.
|
|
50
|
+
changed since the creation of the diagnostic, due to editing.
|
|
51
51
|
*/
|
|
52
52
|
apply: (view: EditorView, from: number, to: number) => void;
|
|
53
53
|
}
|
|
54
|
+
declare type DiagnosticFilter = (diagnostics: readonly Diagnostic[]) => Diagnostic[];
|
|
55
|
+
interface LintConfig {
|
|
56
|
+
/**
|
|
57
|
+
Time to wait (in milliseconds) after a change before running
|
|
58
|
+
the linter. Defaults to 750ms.
|
|
59
|
+
*/
|
|
60
|
+
delay?: number;
|
|
61
|
+
/**
|
|
62
|
+
Optional filter to determine which diagnostics produce markers
|
|
63
|
+
in the content.
|
|
64
|
+
*/
|
|
65
|
+
markerFilter?: null | DiagnosticFilter;
|
|
66
|
+
/**
|
|
67
|
+
Filter applied to a set of diagnostics shown in a tooltip. No
|
|
68
|
+
tooltip will appear if the empty set is returned.
|
|
69
|
+
*/
|
|
70
|
+
tooltipFilter?: null | DiagnosticFilter;
|
|
71
|
+
}
|
|
54
72
|
interface LintGutterConfig {
|
|
55
73
|
/**
|
|
56
74
|
The delay before showing a tooltip when hovering over a lint gutter marker.
|
|
57
75
|
*/
|
|
58
76
|
hoverTime?: number;
|
|
77
|
+
/**
|
|
78
|
+
Optional filter determining which diagnostics show a marker in
|
|
79
|
+
the gutter.
|
|
80
|
+
*/
|
|
81
|
+
markerFilter?: null | DiagnosticFilter;
|
|
82
|
+
/**
|
|
83
|
+
Optional filter for diagnostics displayed in a tooltip, which
|
|
84
|
+
can also be used to prevent a tooltip appearing.
|
|
85
|
+
*/
|
|
86
|
+
tooltipFilter?: null | DiagnosticFilter;
|
|
59
87
|
}
|
|
60
88
|
/**
|
|
61
89
|
Returns a transaction spec which updates the current set of
|
|
@@ -91,19 +119,16 @@ A set of default key bindings for the lint functionality.
|
|
|
91
119
|
- F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
|
|
92
120
|
*/
|
|
93
121
|
declare const lintKeymap: readonly KeyBinding[];
|
|
122
|
+
/**
|
|
123
|
+
The type of a function that produces diagnostics.
|
|
124
|
+
*/
|
|
94
125
|
declare type LintSource = (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>;
|
|
95
126
|
/**
|
|
96
127
|
Given a diagnostic source, this function returns an extension that
|
|
97
128
|
enables linting with that source. It will be called whenever the
|
|
98
129
|
editor is idle (after its content changed).
|
|
99
130
|
*/
|
|
100
|
-
declare function linter(source: LintSource, config?:
|
|
101
|
-
/**
|
|
102
|
-
Time to wait (in milliseconds) after a change before running
|
|
103
|
-
the linter. Defaults to 750ms.
|
|
104
|
-
*/
|
|
105
|
-
delay?: number;
|
|
106
|
-
}): Extension;
|
|
131
|
+
declare function linter(source: LintSource, config?: LintConfig): Extension;
|
|
107
132
|
/**
|
|
108
133
|
Forces any linters [configured](https://codemirror.net/6/docs/ref/#lint.linter) to run when the
|
|
109
134
|
editor is idle to run right away.
|
|
@@ -116,4 +141,4 @@ the diagnostics.
|
|
|
116
141
|
*/
|
|
117
142
|
declare function lintGutter(config?: LintGutterConfig): Extension;
|
|
118
143
|
|
|
119
|
-
export { Action, Diagnostic, closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
|
|
144
|
+
export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { Decoration, EditorView, ViewPlugin, logException, WidgetType } from '@codemirror/view';
|
|
2
|
-
import { StateEffect, StateField, Facet, combineConfig } from '@codemirror/state';
|
|
3
|
-
import { hoverTooltip, showTooltip } from '@codemirror/tooltip';
|
|
4
|
-
import { showPanel, getPanel } from '@codemirror/panel';
|
|
5
|
-
import { gutter, GutterMarker } from '@codemirror/gutter';
|
|
6
|
-
import { RangeSet } from '@codemirror/rangeset';
|
|
1
|
+
import { Decoration, showPanel, EditorView, ViewPlugin, hoverTooltip, logException, gutter, showTooltip, getPanel, WidgetType, GutterMarker } from '@codemirror/view';
|
|
2
|
+
import { StateEffect, StateField, Facet, combineConfig, RangeSet } from '@codemirror/state';
|
|
7
3
|
import elt from 'crelt';
|
|
8
4
|
|
|
9
5
|
class SelectedDiagnostic {
|
|
@@ -20,7 +16,12 @@ class LintState {
|
|
|
20
16
|
this.selected = selected;
|
|
21
17
|
}
|
|
22
18
|
static init(diagnostics, panel, state) {
|
|
23
|
-
|
|
19
|
+
// Filter the list of diagnostics for which to create markers
|
|
20
|
+
let markedDiagnostics = diagnostics;
|
|
21
|
+
let diagnosticFilter = state.facet(lintConfig).markerFilter;
|
|
22
|
+
if (diagnosticFilter)
|
|
23
|
+
markedDiagnostics = diagnosticFilter(markedDiagnostics);
|
|
24
|
+
let ranges = Decoration.set(markedDiagnostics.map((d) => {
|
|
24
25
|
// For zero-length ranges or ranges covering only a line break, create a widget
|
|
25
26
|
return d.from == d.to || (d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from)
|
|
26
27
|
? Decoration.widget({
|
|
@@ -45,6 +46,9 @@ function findDiagnostic(diagnostics, diagnostic = null, after = 0) {
|
|
|
45
46
|
});
|
|
46
47
|
return found;
|
|
47
48
|
}
|
|
49
|
+
function hideTooltip(tr, tooltip) {
|
|
50
|
+
return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
|
|
51
|
+
}
|
|
48
52
|
function maybeEnableLint(state, effects) {
|
|
49
53
|
return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of([
|
|
50
54
|
lintState,
|
|
@@ -54,7 +58,7 @@ function maybeEnableLint(state, effects) {
|
|
|
54
58
|
activeMark.range(selected.from, selected.to)
|
|
55
59
|
]);
|
|
56
60
|
}),
|
|
57
|
-
hoverTooltip(lintTooltip),
|
|
61
|
+
hoverTooltip(lintTooltip, { hideOn: hideTooltip }),
|
|
58
62
|
baseTheme
|
|
59
63
|
]));
|
|
60
64
|
}
|
|
@@ -123,6 +127,9 @@ function lintTooltip(view, pos, side) {
|
|
|
123
127
|
stackEnd = Math.max(to, stackEnd);
|
|
124
128
|
}
|
|
125
129
|
});
|
|
130
|
+
let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
|
|
131
|
+
if (diagnosticFilter)
|
|
132
|
+
found = diagnosticFilter(found);
|
|
126
133
|
if (!found.length)
|
|
127
134
|
return null;
|
|
128
135
|
return {
|
|
@@ -190,7 +197,7 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
190
197
|
this.view = view;
|
|
191
198
|
this.timeout = -1;
|
|
192
199
|
this.set = true;
|
|
193
|
-
let { delay } = view.state.facet(
|
|
200
|
+
let { delay } = view.state.facet(lintConfig);
|
|
194
201
|
this.lintTime = Date.now() + delay;
|
|
195
202
|
this.run = this.run.bind(this);
|
|
196
203
|
this.timeout = setTimeout(this.run, delay);
|
|
@@ -202,7 +209,7 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
202
209
|
}
|
|
203
210
|
else {
|
|
204
211
|
this.set = false;
|
|
205
|
-
let { state } = this.view, { sources } = state.facet(
|
|
212
|
+
let { state } = this.view, { sources } = state.facet(lintConfig);
|
|
206
213
|
Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
|
|
207
214
|
let all = annotations.reduce((a, b) => a.concat(b));
|
|
208
215
|
if (this.view.state.doc == state.doc)
|
|
@@ -211,12 +218,12 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
211
218
|
}
|
|
212
219
|
}
|
|
213
220
|
update(update) {
|
|
214
|
-
let
|
|
215
|
-
if (update.docChanged ||
|
|
216
|
-
this.lintTime = Date.now() +
|
|
221
|
+
let config = update.state.facet(lintConfig);
|
|
222
|
+
if (update.docChanged || config != update.startState.facet(lintConfig)) {
|
|
223
|
+
this.lintTime = Date.now() + config.delay;
|
|
217
224
|
if (!this.set) {
|
|
218
225
|
this.set = true;
|
|
219
|
-
this.timeout = setTimeout(this.run,
|
|
226
|
+
this.timeout = setTimeout(this.run, config.delay);
|
|
220
227
|
}
|
|
221
228
|
}
|
|
222
229
|
}
|
|
@@ -230,9 +237,13 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
230
237
|
clearTimeout(this.timeout);
|
|
231
238
|
}
|
|
232
239
|
});
|
|
233
|
-
const
|
|
240
|
+
const lintConfig = /*@__PURE__*/Facet.define({
|
|
234
241
|
combine(input) {
|
|
235
|
-
return { sources: input.map(i => i.source),
|
|
242
|
+
return Object.assign({ sources: input.map(i => i.source) }, combineConfig(input.map(i => i.config), {
|
|
243
|
+
delay: 750,
|
|
244
|
+
markerFilter: null,
|
|
245
|
+
tooltipFilter: null
|
|
246
|
+
}));
|
|
236
247
|
},
|
|
237
248
|
enables: lintPlugin
|
|
238
249
|
});
|
|
@@ -242,8 +253,7 @@ enables linting with that source. It will be called whenever the
|
|
|
242
253
|
editor is idle (after its content changed).
|
|
243
254
|
*/
|
|
244
255
|
function linter(source, config = {}) {
|
|
245
|
-
|
|
246
|
-
return lintSource.of({ source, delay: (_a = config.delay) !== null && _a !== void 0 ? _a : 750 });
|
|
256
|
+
return lintConfig.of({ source, config });
|
|
247
257
|
}
|
|
248
258
|
/**
|
|
249
259
|
Forces any linters [configured](https://codemirror.net/6/docs/ref/#lint.linter) to run when the
|
|
@@ -581,7 +591,12 @@ class LintGutterMarker extends GutterMarker {
|
|
|
581
591
|
toDOM(view) {
|
|
582
592
|
let elt = document.createElement("div");
|
|
583
593
|
elt.className = "cm-lint-marker cm-lint-marker-" + this.severity;
|
|
584
|
-
|
|
594
|
+
let diagnostics = this.diagnostics;
|
|
595
|
+
let diagnosticsFilter = view.state.facet(lintGutterConfig).tooltipFilter;
|
|
596
|
+
if (diagnosticsFilter)
|
|
597
|
+
diagnostics = diagnosticsFilter(diagnostics);
|
|
598
|
+
if (diagnostics.length)
|
|
599
|
+
elt.onmouseover = () => gutterMarkerMouseOver(view, elt, diagnostics);
|
|
585
600
|
return elt;
|
|
586
601
|
}
|
|
587
602
|
}
|
|
@@ -653,10 +668,15 @@ const lintGutterMarkers = /*@__PURE__*/StateField.define({
|
|
|
653
668
|
},
|
|
654
669
|
update(markers, tr) {
|
|
655
670
|
markers = markers.map(tr.changes);
|
|
656
|
-
|
|
671
|
+
let diagnosticFilter = tr.state.facet(lintGutterConfig).markerFilter;
|
|
672
|
+
for (let effect of tr.effects) {
|
|
657
673
|
if (effect.is(setDiagnosticsEffect)) {
|
|
658
|
-
|
|
674
|
+
let diagnostics = effect.value;
|
|
675
|
+
if (diagnosticFilter)
|
|
676
|
+
diagnostics = diagnosticFilter(diagnostics || []);
|
|
677
|
+
markers = markersForDiagnostics(tr.state.doc, diagnostics.slice(0));
|
|
659
678
|
}
|
|
679
|
+
}
|
|
660
680
|
return markers;
|
|
661
681
|
}
|
|
662
682
|
});
|
|
@@ -665,7 +685,7 @@ const lintGutterTooltip = /*@__PURE__*/StateField.define({
|
|
|
665
685
|
create() { return null; },
|
|
666
686
|
update(tooltip, tr) {
|
|
667
687
|
if (tooltip && tr.docChanged)
|
|
668
|
-
tooltip = Object.assign(Object.assign({}, tooltip), { pos: tr.changes.mapPos(tooltip.pos) });
|
|
688
|
+
tooltip = hideTooltip(tr, tooltip) ? null : Object.assign(Object.assign({}, tooltip), { pos: tr.changes.mapPos(tooltip.pos) });
|
|
669
689
|
return tr.effects.reduce((t, e) => e.is(setLintGutterTooltip) ? e.value : t, tooltip);
|
|
670
690
|
},
|
|
671
691
|
provide: field => showTooltip.from(field)
|
|
@@ -695,6 +715,8 @@ const lintGutterConfig = /*@__PURE__*/Facet.define({
|
|
|
695
715
|
combine(configs) {
|
|
696
716
|
return combineConfig(configs, {
|
|
697
717
|
hoverTime: 300 /* Time */,
|
|
718
|
+
markerFilter: null,
|
|
719
|
+
tooltipFilter: null
|
|
698
720
|
});
|
|
699
721
|
}
|
|
700
722
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemirror/lint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.2",
|
|
4
4
|
"description": "Linting support for the CodeMirror code editor",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "cm-runtests",
|
|
@@ -26,12 +26,8 @@
|
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@codemirror/
|
|
30
|
-
"@codemirror/
|
|
31
|
-
"@codemirror/rangeset": "^0.19.1",
|
|
32
|
-
"@codemirror/state": "^0.19.4",
|
|
33
|
-
"@codemirror/tooltip": "^0.19.16",
|
|
34
|
-
"@codemirror/view": "^0.19.22",
|
|
29
|
+
"@codemirror/state": "^0.20.0",
|
|
30
|
+
"@codemirror/view": "^0.20.2",
|
|
35
31
|
"crelt": "^1.0.5"
|
|
36
32
|
},
|
|
37
33
|
"devDependencies": {
|