@codemirror/lint 6.8.0 → 6.8.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## 6.8.2 (2024-09-24)
2
+
3
+ ### Bug fixes
4
+
5
+ Show lint markers for code replaced by a block widget.
6
+
7
+ When multiple linters are installed, start displaying results from ones that return quickly even if others are slow to return.
8
+
9
+ ## 6.8.1 (2024-06-19)
10
+
11
+ ### Bug fixes
12
+
13
+ Make lint markers non-inclusive again, since having them that way causes more issues than it solves.
14
+
1
15
  ## 6.8.0 (2024-05-23)
2
16
 
3
17
  ### New features
package/dist/index.cjs CHANGED
@@ -32,8 +32,7 @@ class LintState {
32
32
  }).range(d.from)
33
33
  : view.Decoration.mark({
34
34
  attributes: { class: "cm-lintRange cm-lintRange-" + d.severity + (d.markClass ? " " + d.markClass : "") },
35
- diagnostic: d,
36
- inclusive: true
35
+ diagnostic: d
37
36
  }).range(d.from, d.to);
38
37
  }), true);
39
38
  return new LintState(ranges, panel, findDiagnostic(ranges));
@@ -116,7 +115,7 @@ function diagnosticCount(state) {
116
115
  let lint = state.field(lintState, false);
117
116
  return lint ? lint.diagnostics.size : 0;
118
117
  }
119
- const activeMark = view.Decoration.mark({ class: "cm-lintRange cm-lintRange-active", inclusive: true });
118
+ const activeMark = view.Decoration.mark({ class: "cm-lintRange cm-lintRange-active" });
120
119
  function lintTooltip(view, pos, side) {
121
120
  let { diagnostics } = view.state.field(lintState);
122
121
  let found = [], stackStart = 2e8, stackEnd = 0;
@@ -237,10 +236,9 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
237
236
  this.set = false;
238
237
  let { state } = this.view, { sources } = state.facet(lintConfig);
239
238
  if (sources.length)
240
- Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
241
- let all = annotations.reduce((a, b) => a.concat(b));
239
+ batchResults(sources.map(s => Promise.resolve(s(this.view))), annotations => {
242
240
  if (this.view.state.doc == state.doc)
243
- this.view.dispatch(setDiagnostics(this.view.state, all));
241
+ this.view.dispatch(setDiagnostics(this.view.state, annotations.reduce((a, b) => a.concat(b))));
244
242
  }, error => { view.logException(this.view.state, error); });
245
243
  }
246
244
  }
@@ -265,6 +263,18 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
265
263
  clearTimeout(this.timeout);
266
264
  }
267
265
  });
266
+ function batchResults(promises, sink, error) {
267
+ let collected = [], timeout = -1;
268
+ for (let p of promises)
269
+ p.then(value => {
270
+ collected.push(value);
271
+ clearTimeout(timeout);
272
+ if (collected.length == promises.length)
273
+ sink(collected);
274
+ else
275
+ setTimeout(() => sink(collected), 200);
276
+ }, error);
277
+ }
268
278
  const lintConfig = state.Facet.define({
269
279
  combine(input) {
270
280
  return Object.assign({ sources: input.map(i => i.source).filter(x => x != null) }, state.combineConfig(input.map(i => i.config), {
@@ -707,6 +717,13 @@ function markersForDiagnostics(doc, diagnostics) {
707
717
  const lintGutterExtension = view.gutter({
708
718
  class: "cm-gutter-lint",
709
719
  markers: view => view.state.field(lintGutterMarkers),
720
+ widgetMarker: (view, widget, block) => {
721
+ let diagnostics = [];
722
+ view.state.field(lintGutterMarkers).between(block.from, block.to, (from, to, value) => {
723
+ diagnostics.push(...value.diagnostics);
724
+ });
725
+ return diagnostics.length ? new LintGutterMarker(diagnostics) : null;
726
+ }
710
727
  });
711
728
  const lintGutterMarkers = state.StateField.define({
712
729
  create() {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Decoration, showPanel, EditorView, ViewPlugin, logException, gutter, showTooltip, hoverTooltip, getPanel, WidgetType, GutterMarker } from '@codemirror/view';
1
+ import { Decoration, showPanel, EditorView, ViewPlugin, gutter, showTooltip, hoverTooltip, getPanel, logException, WidgetType, GutterMarker } from '@codemirror/view';
2
2
  import { StateEffect, StateField, Facet, combineConfig, RangeSet } from '@codemirror/state';
3
3
  import elt from 'crelt';
4
4
 
@@ -30,8 +30,7 @@ class LintState {
30
30
  }).range(d.from)
31
31
  : Decoration.mark({
32
32
  attributes: { class: "cm-lintRange cm-lintRange-" + d.severity + (d.markClass ? " " + d.markClass : "") },
33
- diagnostic: d,
34
- inclusive: true
33
+ diagnostic: d
35
34
  }).range(d.from, d.to);
36
35
  }), true);
37
36
  return new LintState(ranges, panel, findDiagnostic(ranges));
@@ -114,7 +113,7 @@ function diagnosticCount(state) {
114
113
  let lint = state.field(lintState, false);
115
114
  return lint ? lint.diagnostics.size : 0;
116
115
  }
117
- const activeMark = /*@__PURE__*/Decoration.mark({ class: "cm-lintRange cm-lintRange-active", inclusive: true });
116
+ const activeMark = /*@__PURE__*/Decoration.mark({ class: "cm-lintRange cm-lintRange-active" });
118
117
  function lintTooltip(view, pos, side) {
119
118
  let { diagnostics } = view.state.field(lintState);
120
119
  let found = [], stackStart = 2e8, stackEnd = 0;
@@ -235,10 +234,9 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
235
234
  this.set = false;
236
235
  let { state } = this.view, { sources } = state.facet(lintConfig);
237
236
  if (sources.length)
238
- Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
239
- let all = annotations.reduce((a, b) => a.concat(b));
237
+ batchResults(sources.map(s => Promise.resolve(s(this.view))), annotations => {
240
238
  if (this.view.state.doc == state.doc)
241
- this.view.dispatch(setDiagnostics(this.view.state, all));
239
+ this.view.dispatch(setDiagnostics(this.view.state, annotations.reduce((a, b) => a.concat(b))));
242
240
  }, error => { logException(this.view.state, error); });
243
241
  }
244
242
  }
@@ -263,6 +261,18 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
263
261
  clearTimeout(this.timeout);
264
262
  }
265
263
  });
264
+ function batchResults(promises, sink, error) {
265
+ let collected = [], timeout = -1;
266
+ for (let p of promises)
267
+ p.then(value => {
268
+ collected.push(value);
269
+ clearTimeout(timeout);
270
+ if (collected.length == promises.length)
271
+ sink(collected);
272
+ else
273
+ setTimeout(() => sink(collected), 200);
274
+ }, error);
275
+ }
266
276
  const lintConfig = /*@__PURE__*/Facet.define({
267
277
  combine(input) {
268
278
  return Object.assign({ sources: input.map(i => i.source).filter(x => x != null) }, combineConfig(input.map(i => i.config), {
@@ -705,6 +715,13 @@ function markersForDiagnostics(doc, diagnostics) {
705
715
  const lintGutterExtension = /*@__PURE__*/gutter({
706
716
  class: "cm-gutter-lint",
707
717
  markers: view => view.state.field(lintGutterMarkers),
718
+ widgetMarker: (view, widget, block) => {
719
+ let diagnostics = [];
720
+ view.state.field(lintGutterMarkers).between(block.from, block.to, (from, to, value) => {
721
+ diagnostics.push(...value.diagnostics);
722
+ });
723
+ return diagnostics.length ? new LintGutterMarker(diagnostics) : null;
724
+ }
708
725
  });
709
726
  const lintGutterMarkers = /*@__PURE__*/StateField.define({
710
727
  create() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/lint",
3
- "version": "6.8.0",
3
+ "version": "6.8.2",
4
4
  "description": "Linting support for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",