@codemirror/lint 6.0.0 → 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.
- package/.github/workflows/dispatch.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/README.md +5 -5
- package/dist/index.cjs +19 -5
- package/dist/index.d.ts +9 -1
- package/dist/index.js +20 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @codemirror/lint [](https://www.npmjs.org/package/@codemirror/lint)
|
|
2
2
|
|
|
3
|
-
[ [**WEBSITE**](https://codemirror.net/
|
|
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
|
+
[CodeMirror](https://codemirror.net/) code editor.
|
|
7
7
|
|
|
8
|
-
The [project page](https://codemirror.net/
|
|
9
|
-
number of [examples](https://codemirror.net/
|
|
10
|
-
[documentation](https://codemirror.net/
|
|
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
|
|
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,
|
|
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
|
|
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 };
|