@codemirror/lint 6.1.0 → 6.2.0

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.2.0 (2023-02-27)
2
+
3
+ ### New features
4
+
5
+ The new `needsRefresh` option to `linter` makes it possible to cause linting to be recalculated for non-document state changes.
6
+
7
+ ## 6.1.1 (2023-02-15)
8
+
9
+ ### Bug fixes
10
+
11
+ Give lint action buttons a pointer cursor style.
12
+
13
+ Fix a bug that caused diagnostic action callbacks to be called twice when their button was clicked.
14
+
1
15
  ## 6.1.0 (2022-11-15)
2
16
 
3
17
  ### New features
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (C) 2018-2021 by Marijn Haverbeke <marijnh@gmail.com> and others
3
+ Copyright (C) 2018-2021 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.cjs CHANGED
@@ -227,7 +227,8 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
227
227
  }
228
228
  update(update) {
229
229
  let config = update.state.facet(lintConfig);
230
- if (update.docChanged || config != update.startState.facet(lintConfig)) {
230
+ if (update.docChanged || config != update.startState.facet(lintConfig) ||
231
+ config.needsRefresh && config.needsRefresh(update)) {
231
232
  this.lintTime = Date.now() + config.delay;
232
233
  if (!this.set) {
233
234
  this.set = true;
@@ -250,7 +251,10 @@ const lintConfig = state.Facet.define({
250
251
  return Object.assign({ sources: input.map(i => i.source) }, state.combineConfig(input.map(i => i.config), {
251
252
  delay: 750,
252
253
  markerFilter: null,
253
- tooltipFilter: null
254
+ tooltipFilter: null,
255
+ needsRefresh: null
256
+ }, {
257
+ needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
254
258
  }));
255
259
  },
256
260
  enables: lintPlugin
@@ -291,8 +295,11 @@ function renderDiagnostic(view, diagnostic, inPanel) {
291
295
  var _a;
292
296
  let keys = inPanel ? assignKeys(diagnostic.actions) : [];
293
297
  return elt__default["default"]("li", { class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity }, elt__default["default"]("span", { class: "cm-diagnosticText" }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
294
- let click = (e) => {
298
+ let fired = false, click = (e) => {
295
299
  e.preventDefault();
300
+ if (fired)
301
+ return;
302
+ fired = true;
296
303
  let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
297
304
  if (found)
298
305
  action.apply(view, found.from, found.to);
@@ -519,7 +526,8 @@ const baseTheme = view.EditorView.baseTheme({
519
526
  backgroundColor: "#444",
520
527
  color: "white",
521
528
  borderRadius: "3px",
522
- marginLeft: "8px"
529
+ marginLeft: "8px",
530
+ cursor: "pointer"
523
531
  },
524
532
  ".cm-diagnosticSource": {
525
533
  fontSize: "70%",
@@ -739,7 +747,7 @@ function lintGutter(config = {}) {
739
747
  /**
740
748
  Iterate over the marked diagnostics for the given editor state,
741
749
  calling `f` for each of them. Note that, if the document changed
742
- since the diagnostics werecreated, the `Diagnostic` object will
750
+ since the diagnostics were created, the `Diagnostic` object will
743
751
  hold the original outdated position, whereas the `to` and `from`
744
752
  arguments hold the diagnostic's current position.
745
753
  */
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
  */
@@ -148,7 +154,7 @@ declare function lintGutter(config?: LintGutterConfig): Extension;
148
154
  /**
149
155
  Iterate over the marked diagnostics for the given editor state,
150
156
  calling `f` for each of them. Note that, if the document changed
151
- since the diagnostics werecreated, the `Diagnostic` object will
157
+ since the diagnostics were created, the `Diagnostic` object will
152
158
  hold the original outdated position, whereas the `to` and `from`
153
159
  arguments hold the diagnostic's current position.
154
160
  */
package/dist/index.js CHANGED
@@ -219,7 +219,8 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
219
219
  }
220
220
  update(update) {
221
221
  let config = update.state.facet(lintConfig);
222
- if (update.docChanged || config != update.startState.facet(lintConfig)) {
222
+ if (update.docChanged || config != update.startState.facet(lintConfig) ||
223
+ config.needsRefresh && config.needsRefresh(update)) {
223
224
  this.lintTime = Date.now() + config.delay;
224
225
  if (!this.set) {
225
226
  this.set = true;
@@ -242,7 +243,10 @@ const lintConfig = /*@__PURE__*/Facet.define({
242
243
  return Object.assign({ sources: input.map(i => i.source) }, combineConfig(input.map(i => i.config), {
243
244
  delay: 750,
244
245
  markerFilter: null,
245
- tooltipFilter: null
246
+ tooltipFilter: null,
247
+ needsRefresh: null
248
+ }, {
249
+ needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
246
250
  }));
247
251
  },
248
252
  enables: lintPlugin
@@ -283,8 +287,11 @@ function renderDiagnostic(view, diagnostic, inPanel) {
283
287
  var _a;
284
288
  let keys = inPanel ? assignKeys(diagnostic.actions) : [];
285
289
  return elt("li", { class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity }, elt("span", { class: "cm-diagnosticText" }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
286
- let click = (e) => {
290
+ let fired = false, click = (e) => {
287
291
  e.preventDefault();
292
+ if (fired)
293
+ return;
294
+ fired = true;
288
295
  let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
289
296
  if (found)
290
297
  action.apply(view, found.from, found.to);
@@ -511,7 +518,8 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
511
518
  backgroundColor: "#444",
512
519
  color: "white",
513
520
  borderRadius: "3px",
514
- marginLeft: "8px"
521
+ marginLeft: "8px",
522
+ cursor: "pointer"
515
523
  },
516
524
  ".cm-diagnosticSource": {
517
525
  fontSize: "70%",
@@ -731,7 +739,7 @@ function lintGutter(config = {}) {
731
739
  /**
732
740
  Iterate over the marked diagnostics for the given editor state,
733
741
  calling `f` for each of them. Note that, if the document changed
734
- since the diagnostics werecreated, the `Diagnostic` object will
742
+ since the diagnostics were created, the `Diagnostic` object will
735
743
  hold the original outdated position, whereas the `to` and `from`
736
744
  arguments hold the diagnostic's current position.
737
745
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/lint",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "Linting support for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "author": {
14
14
  "name": "Marijn Haverbeke",
15
- "email": "marijnh@gmail.com",
15
+ "email": "marijn@haverbeke.berlin",
16
16
  "url": "http://marijnhaverbeke.nl"
17
17
  },
18
18
  "type": "module",