@codemirror/lint 0.20.3 → 6.1.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.
@@ -11,6 +11,6 @@ jobs:
11
11
  with:
12
12
  # You should create a personal access token and store it in your repository
13
13
  token: ${{ secrets.DISPATCH_AUTH }}
14
- repo: codemirror.next
14
+ repo: dev
15
15
  owner: codemirror
16
16
  event_type: push
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 6.1.0 (2022-11-15)
2
+
3
+ ### New features
4
+
5
+ The new `forEachDiagnostic` function can be used to iterate over the diagnostics in an editor state.
6
+
7
+ ## 6.0.0 (2022-06-08)
8
+
9
+ ### Breaking changes
10
+
11
+ Update dependencies to 6.0.0
12
+
1
13
  ## 0.20.3 (2022-05-25)
2
14
 
3
15
  ### New features
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # @codemirror/lint [![NPM version](https://img.shields.io/npm/v/@codemirror/lint.svg)](https://www.npmjs.org/package/@codemirror/lint)
2
2
 
3
- [ [**WEBSITE**](https://codemirror.net/6/) | [**DOCS**](https://codemirror.net/6/docs/ref/#lint) | [**ISSUES**](https://github.com/codemirror/codemirror.next/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lint/blob/main/CHANGELOG.md) ]
3
+ [ [**WEBSITE**](https://codemirror.net/) | [**DOCS**](https://codemirror.net/docs/ref/#lint) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lint/blob/main/CHANGELOG.md) ]
4
4
 
5
5
  This package implements linting support for the
6
- [CodeMirror](https://codemirror.net/6/) code editor.
6
+ [CodeMirror](https://codemirror.net/) code editor.
7
7
 
8
- The [project page](https://codemirror.net/6/) has more information, a
9
- number of [examples](https://codemirror.net/6/examples/) and the
10
- [documentation](https://codemirror.net/6/docs/).
8
+ The [project page](https://codemirror.net/) has more information, a
9
+ number of [examples](https://codemirror.net/examples/) and the
10
+ [documentation](https://codemirror.net/docs/).
11
11
 
12
12
  This code is released under an
13
13
  [MIT license](https://github.com/codemirror/lint/tree/main/LICENSE).
package/dist/index.cjs CHANGED
@@ -197,7 +197,7 @@ A set of default key bindings for the lint functionality.
197
197
  - F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
198
198
  */
199
199
  const lintKeymap = [
200
- { key: "Mod-Shift-m", run: openLintPanel },
200
+ { key: "Mod-Shift-m", run: openLintPanel, preventDefault: true },
201
201
  { key: "F8", run: nextDiagnostic }
202
202
  ];
203
203
  const lintPlugin = view.ViewPlugin.fromClass(class {
@@ -611,8 +611,8 @@ class LintGutterMarker extends view.GutterMarker {
611
611
  function trackHoverOn(view, marker) {
612
612
  let mousemove = (event) => {
613
613
  let rect = marker.getBoundingClientRect();
614
- if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
615
- event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
614
+ if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ &&
615
+ event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */)
616
616
  return;
617
617
  for (let target = event.target; target; target = target.parentNode) {
618
618
  if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
@@ -715,14 +715,14 @@ const lintGutterTheme = view.EditorView.baseTheme({
715
715
  ".cm-lint-marker-warning": {
716
716
  content: svg(`<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>`),
717
717
  },
718
- ".cm-lint-marker-error:before": {
718
+ ".cm-lint-marker-error": {
719
719
  content: svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
720
720
  },
721
721
  });
722
722
  const lintGutterConfig = state.Facet.define({
723
723
  combine(configs) {
724
724
  return state.combineConfig(configs, {
725
- hoverTime: 300 /* Time */,
725
+ hoverTime: 300 /* Hover.Time */,
726
726
  markerFilter: null,
727
727
  tooltipFilter: null
728
728
  });
@@ -736,9 +736,23 @@ the diagnostics.
736
736
  function lintGutter(config = {}) {
737
737
  return [lintGutterConfig.of(config), lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
738
738
  }
739
+ /**
740
+ Iterate over the marked diagnostics for the given editor state,
741
+ calling `f` for each of them. Note that, if the document changed
742
+ since the diagnostics werecreated, the `Diagnostic` object will
743
+ hold the original outdated position, whereas the `to` and `from`
744
+ arguments hold the diagnostic's current position.
745
+ */
746
+ function forEachDiagnostic(state$1, f) {
747
+ let lState = state$1.field(lintState, false);
748
+ if (lState && lState.diagnostics.size)
749
+ for (let iter = state.RangeSet.iter([lState.diagnostics]); iter.value; iter.next())
750
+ f(iter.value.spec.diagnostic, iter.from, iter.to);
751
+ }
739
752
 
740
753
  exports.closeLintPanel = closeLintPanel;
741
754
  exports.diagnosticCount = diagnosticCount;
755
+ exports.forEachDiagnostic = forEachDiagnostic;
742
756
  exports.forceLinting = forceLinting;
743
757
  exports.lintGutter = lintGutter;
744
758
  exports.lintKeymap = lintKeymap;
package/dist/index.d.ts CHANGED
@@ -145,5 +145,13 @@ each line that has diagnostics, which can be hovered over to see
145
145
  the diagnostics.
146
146
  */
147
147
  declare function lintGutter(config?: LintGutterConfig): Extension;
148
+ /**
149
+ Iterate over the marked diagnostics for the given editor state,
150
+ calling `f` for each of them. Note that, if the document changed
151
+ since the diagnostics werecreated, the `Diagnostic` object will
152
+ hold the original outdated position, whereas the `to` and `from`
153
+ arguments hold the diagnostic's current position.
154
+ */
155
+ declare function forEachDiagnostic(state: EditorState, f: (d: Diagnostic, from: number, to: number) => void): void;
148
156
 
149
- export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
157
+ export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Decoration, showPanel, EditorView, ViewPlugin, hoverTooltip, logException, gutter, showTooltip, getPanel, WidgetType, GutterMarker } from '@codemirror/view';
1
+ import { Decoration, showPanel, EditorView, ViewPlugin, logException, gutter, showTooltip, getPanel, WidgetType, hoverTooltip, GutterMarker } from '@codemirror/view';
2
2
  import { StateEffect, StateField, Facet, combineConfig, RangeSet } from '@codemirror/state';
3
3
  import elt from 'crelt';
4
4
 
@@ -189,7 +189,7 @@ A set of default key bindings for the lint functionality.
189
189
  - F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
190
190
  */
191
191
  const lintKeymap = [
192
- { key: "Mod-Shift-m", run: openLintPanel },
192
+ { key: "Mod-Shift-m", run: openLintPanel, preventDefault: true },
193
193
  { key: "F8", run: nextDiagnostic }
194
194
  ];
195
195
  const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
@@ -603,8 +603,8 @@ class LintGutterMarker extends GutterMarker {
603
603
  function trackHoverOn(view, marker) {
604
604
  let mousemove = (event) => {
605
605
  let rect = marker.getBoundingClientRect();
606
- if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
607
- event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
606
+ if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ &&
607
+ event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */)
608
608
  return;
609
609
  for (let target = event.target; target; target = target.parentNode) {
610
610
  if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
@@ -707,14 +707,14 @@ const lintGutterTheme = /*@__PURE__*/EditorView.baseTheme({
707
707
  ".cm-lint-marker-warning": {
708
708
  content: /*@__PURE__*/svg(`<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>`),
709
709
  },
710
- ".cm-lint-marker-error:before": {
710
+ ".cm-lint-marker-error": {
711
711
  content: /*@__PURE__*/svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
712
712
  },
713
713
  });
714
714
  const lintGutterConfig = /*@__PURE__*/Facet.define({
715
715
  combine(configs) {
716
716
  return combineConfig(configs, {
717
- hoverTime: 300 /* Time */,
717
+ hoverTime: 300 /* Hover.Time */,
718
718
  markerFilter: null,
719
719
  tooltipFilter: null
720
720
  });
@@ -728,5 +728,18 @@ the diagnostics.
728
728
  function lintGutter(config = {}) {
729
729
  return [lintGutterConfig.of(config), lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
730
730
  }
731
+ /**
732
+ Iterate over the marked diagnostics for the given editor state,
733
+ calling `f` for each of them. Note that, if the document changed
734
+ since the diagnostics werecreated, the `Diagnostic` object will
735
+ hold the original outdated position, whereas the `to` and `from`
736
+ arguments hold the diagnostic's current position.
737
+ */
738
+ function forEachDiagnostic(state, f) {
739
+ let lState = state.field(lintState, false);
740
+ if (lState && lState.diagnostics.size)
741
+ for (let iter = RangeSet.iter([lState.diagnostics]); iter.value; iter.next())
742
+ f(iter.value.spec.diagnostic, iter.from, iter.to);
743
+ }
731
744
 
732
- export { closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
745
+ export { closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/lint",
3
- "version": "0.20.3",
3
+ "version": "6.1.0",
4
4
  "description": "Linting support for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -26,8 +26,8 @@
26
26
  "sideEffects": false,
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@codemirror/state": "^0.20.0",
30
- "@codemirror/view": "^0.20.2",
29
+ "@codemirror/state": "^6.0.0",
30
+ "@codemirror/view": "^6.0.0",
31
31
  "crelt": "^1.0.5"
32
32
  },
33
33
  "devDependencies": {