@codemirror/lint 6.8.1 → 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,11 @@
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
+
1
9
  ## 6.8.1 (2024-06-19)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -236,10 +236,9 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
236
236
  this.set = false;
237
237
  let { state } = this.view, { sources } = state.facet(lintConfig);
238
238
  if (sources.length)
239
- Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
240
- let all = annotations.reduce((a, b) => a.concat(b));
239
+ batchResults(sources.map(s => Promise.resolve(s(this.view))), annotations => {
241
240
  if (this.view.state.doc == state.doc)
242
- this.view.dispatch(setDiagnostics(this.view.state, all));
241
+ this.view.dispatch(setDiagnostics(this.view.state, annotations.reduce((a, b) => a.concat(b))));
243
242
  }, error => { view.logException(this.view.state, error); });
244
243
  }
245
244
  }
@@ -264,6 +263,18 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
264
263
  clearTimeout(this.timeout);
265
264
  }
266
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
+ }
267
278
  const lintConfig = state.Facet.define({
268
279
  combine(input) {
269
280
  return Object.assign({ sources: input.map(i => i.source).filter(x => x != null) }, state.combineConfig(input.map(i => i.config), {
@@ -706,6 +717,13 @@ function markersForDiagnostics(doc, diagnostics) {
706
717
  const lintGutterExtension = view.gutter({
707
718
  class: "cm-gutter-lint",
708
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
+ }
709
727
  });
710
728
  const lintGutterMarkers = state.StateField.define({
711
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
 
@@ -234,10 +234,9 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
234
234
  this.set = false;
235
235
  let { state } = this.view, { sources } = state.facet(lintConfig);
236
236
  if (sources.length)
237
- Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
238
- let all = annotations.reduce((a, b) => a.concat(b));
237
+ batchResults(sources.map(s => Promise.resolve(s(this.view))), annotations => {
239
238
  if (this.view.state.doc == state.doc)
240
- this.view.dispatch(setDiagnostics(this.view.state, all));
239
+ this.view.dispatch(setDiagnostics(this.view.state, annotations.reduce((a, b) => a.concat(b))));
241
240
  }, error => { logException(this.view.state, error); });
242
241
  }
243
242
  }
@@ -262,6 +261,18 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
262
261
  clearTimeout(this.timeout);
263
262
  }
264
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
+ }
265
276
  const lintConfig = /*@__PURE__*/Facet.define({
266
277
  combine(input) {
267
278
  return Object.assign({ sources: input.map(i => i.source).filter(x => x != null) }, combineConfig(input.map(i => i.config), {
@@ -704,6 +715,13 @@ function markersForDiagnostics(doc, diagnostics) {
704
715
  const lintGutterExtension = /*@__PURE__*/gutter({
705
716
  class: "cm-gutter-lint",
706
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
+ }
707
725
  });
708
726
  const lintGutterMarkers = /*@__PURE__*/StateField.define({
709
727
  create() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/lint",
3
- "version": "6.8.1",
3
+ "version": "6.8.2",
4
4
  "description": "Linting support for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",