@codemirror/lint 6.1.1 → 6.2.1
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 +24 -16
- package/dist/index.d.ts +7 -1
- package/dist/index.js +25 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 6.2.1 (2023-04-13)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
The `linter` function now eagerly includes all lint-related extensions, rather than appending them to the configuration as-needed, so that turning off linting by clearing the compartment that contains it works properly.
|
|
6
|
+
|
|
7
|
+
## 6.2.0 (2023-02-27)
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
The new `needsRefresh` option to `linter` makes it possible to cause linting to be recalculated for non-document state changes.
|
|
12
|
+
|
|
1
13
|
## 6.1.1 (2023-02-15)
|
|
2
14
|
|
|
3
15
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -58,17 +58,7 @@ function hideTooltip(tr, tooltip) {
|
|
|
58
58
|
return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
|
|
59
59
|
}
|
|
60
60
|
function maybeEnableLint(state$1, effects) {
|
|
61
|
-
return state$1.field(lintState, false) ? effects : effects.concat(state.StateEffect.appendConfig.of(
|
|
62
|
-
lintState,
|
|
63
|
-
view.EditorView.decorations.compute([lintState], state => {
|
|
64
|
-
let { selected, panel } = state.field(lintState);
|
|
65
|
-
return !selected || !panel || selected.from == selected.to ? view.Decoration.none : view.Decoration.set([
|
|
66
|
-
activeMark.range(selected.from, selected.to)
|
|
67
|
-
]);
|
|
68
|
-
}),
|
|
69
|
-
view.hoverTooltip(lintTooltip, { hideOn: hideTooltip }),
|
|
70
|
-
baseTheme
|
|
71
|
-
]));
|
|
61
|
+
return state$1.field(lintState, false) ? effects : effects.concat(state.StateEffect.appendConfig.of(lintExtensions));
|
|
72
62
|
}
|
|
73
63
|
/**
|
|
74
64
|
Returns a transaction spec which updates the current set of
|
|
@@ -227,7 +217,8 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
|
|
|
227
217
|
}
|
|
228
218
|
update(update) {
|
|
229
219
|
let config = update.state.facet(lintConfig);
|
|
230
|
-
if (update.docChanged || config != update.startState.facet(lintConfig)
|
|
220
|
+
if (update.docChanged || config != update.startState.facet(lintConfig) ||
|
|
221
|
+
config.needsRefresh && config.needsRefresh(update)) {
|
|
231
222
|
this.lintTime = Date.now() + config.delay;
|
|
232
223
|
if (!this.set) {
|
|
233
224
|
this.set = true;
|
|
@@ -250,10 +241,12 @@ const lintConfig = state.Facet.define({
|
|
|
250
241
|
return Object.assign({ sources: input.map(i => i.source) }, state.combineConfig(input.map(i => i.config), {
|
|
251
242
|
delay: 750,
|
|
252
243
|
markerFilter: null,
|
|
253
|
-
tooltipFilter: null
|
|
244
|
+
tooltipFilter: null,
|
|
245
|
+
needsRefresh: null
|
|
246
|
+
}, {
|
|
247
|
+
needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
|
|
254
248
|
}));
|
|
255
|
-
}
|
|
256
|
-
enables: lintPlugin
|
|
249
|
+
}
|
|
257
250
|
});
|
|
258
251
|
/**
|
|
259
252
|
Given a diagnostic source, this function returns an extension that
|
|
@@ -261,7 +254,11 @@ enables linting with that source. It will be called whenever the
|
|
|
261
254
|
editor is idle (after its content changed).
|
|
262
255
|
*/
|
|
263
256
|
function linter(source, config = {}) {
|
|
264
|
-
return
|
|
257
|
+
return [
|
|
258
|
+
lintConfig.of({ source, config }),
|
|
259
|
+
lintPlugin,
|
|
260
|
+
lintExtensions
|
|
261
|
+
];
|
|
265
262
|
}
|
|
266
263
|
/**
|
|
267
264
|
Forces any linters [configured](https://codemirror.net/6/docs/ref/#lint.linter) to run when the
|
|
@@ -723,6 +720,17 @@ const lintGutterTheme = view.EditorView.baseTheme({
|
|
|
723
720
|
content: svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
|
|
724
721
|
},
|
|
725
722
|
});
|
|
723
|
+
const lintExtensions = [
|
|
724
|
+
lintState,
|
|
725
|
+
view.EditorView.decorations.compute([lintState], state => {
|
|
726
|
+
let { selected, panel } = state.field(lintState);
|
|
727
|
+
return !selected || !panel || selected.from == selected.to ? view.Decoration.none : view.Decoration.set([
|
|
728
|
+
activeMark.range(selected.from, selected.to)
|
|
729
|
+
]);
|
|
730
|
+
}),
|
|
731
|
+
view.hoverTooltip(lintTooltip, { hideOn: hideTooltip }),
|
|
732
|
+
baseTheme
|
|
733
|
+
];
|
|
726
734
|
const lintGutterConfig = state.Facet.define({
|
|
727
735
|
combine(configs) {
|
|
728
736
|
return state.combineConfig(configs, {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _codemirror_state from '@codemirror/state';
|
|
2
2
|
import { EditorState, TransactionSpec, Extension } from '@codemirror/state';
|
|
3
|
-
import { EditorView, Command, KeyBinding } from '@codemirror/view';
|
|
3
|
+
import { EditorView, Command, KeyBinding, ViewUpdate } from '@codemirror/view';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
Describes a problem or hint for a piece of code.
|
|
@@ -64,6 +64,12 @@ interface LintConfig {
|
|
|
64
64
|
*/
|
|
65
65
|
delay?: number;
|
|
66
66
|
/**
|
|
67
|
+
Optional predicate that can be used to indicate when diagnostics
|
|
68
|
+
need to be recomputed. Linting is always re-done on document
|
|
69
|
+
changes.
|
|
70
|
+
*/
|
|
71
|
+
needsRefresh?: null | ((update: ViewUpdate) => boolean);
|
|
72
|
+
/**
|
|
67
73
|
Optional filter to determine which diagnostics produce markers
|
|
68
74
|
in the content.
|
|
69
75
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Decoration, showPanel, EditorView, ViewPlugin, logException, gutter, showTooltip, getPanel, WidgetType,
|
|
1
|
+
import { Decoration, showPanel, EditorView, ViewPlugin, logException, gutter, showTooltip, hoverTooltip, getPanel, WidgetType, GutterMarker } from '@codemirror/view';
|
|
2
2
|
import { StateEffect, StateField, Facet, combineConfig, RangeSet } from '@codemirror/state';
|
|
3
3
|
import elt from 'crelt';
|
|
4
4
|
|
|
@@ -50,17 +50,7 @@ function hideTooltip(tr, tooltip) {
|
|
|
50
50
|
return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
|
|
51
51
|
}
|
|
52
52
|
function maybeEnableLint(state, effects) {
|
|
53
|
-
return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of(
|
|
54
|
-
lintState,
|
|
55
|
-
EditorView.decorations.compute([lintState], state => {
|
|
56
|
-
let { selected, panel } = state.field(lintState);
|
|
57
|
-
return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([
|
|
58
|
-
activeMark.range(selected.from, selected.to)
|
|
59
|
-
]);
|
|
60
|
-
}),
|
|
61
|
-
hoverTooltip(lintTooltip, { hideOn: hideTooltip }),
|
|
62
|
-
baseTheme
|
|
63
|
-
]));
|
|
53
|
+
return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of(lintExtensions));
|
|
64
54
|
}
|
|
65
55
|
/**
|
|
66
56
|
Returns a transaction spec which updates the current set of
|
|
@@ -219,7 +209,8 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
219
209
|
}
|
|
220
210
|
update(update) {
|
|
221
211
|
let config = update.state.facet(lintConfig);
|
|
222
|
-
if (update.docChanged || config != update.startState.facet(lintConfig)
|
|
212
|
+
if (update.docChanged || config != update.startState.facet(lintConfig) ||
|
|
213
|
+
config.needsRefresh && config.needsRefresh(update)) {
|
|
223
214
|
this.lintTime = Date.now() + config.delay;
|
|
224
215
|
if (!this.set) {
|
|
225
216
|
this.set = true;
|
|
@@ -242,10 +233,12 @@ const lintConfig = /*@__PURE__*/Facet.define({
|
|
|
242
233
|
return Object.assign({ sources: input.map(i => i.source) }, combineConfig(input.map(i => i.config), {
|
|
243
234
|
delay: 750,
|
|
244
235
|
markerFilter: null,
|
|
245
|
-
tooltipFilter: null
|
|
236
|
+
tooltipFilter: null,
|
|
237
|
+
needsRefresh: null
|
|
238
|
+
}, {
|
|
239
|
+
needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
|
|
246
240
|
}));
|
|
247
|
-
}
|
|
248
|
-
enables: lintPlugin
|
|
241
|
+
}
|
|
249
242
|
});
|
|
250
243
|
/**
|
|
251
244
|
Given a diagnostic source, this function returns an extension that
|
|
@@ -253,7 +246,11 @@ enables linting with that source. It will be called whenever the
|
|
|
253
246
|
editor is idle (after its content changed).
|
|
254
247
|
*/
|
|
255
248
|
function linter(source, config = {}) {
|
|
256
|
-
return
|
|
249
|
+
return [
|
|
250
|
+
lintConfig.of({ source, config }),
|
|
251
|
+
lintPlugin,
|
|
252
|
+
lintExtensions
|
|
253
|
+
];
|
|
257
254
|
}
|
|
258
255
|
/**
|
|
259
256
|
Forces any linters [configured](https://codemirror.net/6/docs/ref/#lint.linter) to run when the
|
|
@@ -715,6 +712,17 @@ const lintGutterTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
715
712
|
content: /*@__PURE__*/svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
|
|
716
713
|
},
|
|
717
714
|
});
|
|
715
|
+
const lintExtensions = [
|
|
716
|
+
lintState,
|
|
717
|
+
/*@__PURE__*/EditorView.decorations.compute([lintState], state => {
|
|
718
|
+
let { selected, panel } = state.field(lintState);
|
|
719
|
+
return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([
|
|
720
|
+
activeMark.range(selected.from, selected.to)
|
|
721
|
+
]);
|
|
722
|
+
}),
|
|
723
|
+
/*@__PURE__*/hoverTooltip(lintTooltip, { hideOn: hideTooltip }),
|
|
724
|
+
baseTheme
|
|
725
|
+
];
|
|
718
726
|
const lintGutterConfig = /*@__PURE__*/Facet.define({
|
|
719
727
|
combine(configs) {
|
|
720
728
|
return combineConfig(configs, {
|