@codemirror/lint 6.2.2 → 6.4.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 +14 -0
- package/dist/index.cjs +35 -5
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +35 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 6.4.0 (2023-07-03)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
Diagnostics can now use `"hint"` as a severity level.
|
|
6
|
+
|
|
7
|
+
Diagnostics can now set a `markClass` property to add an additional CSS class to the text marked by the diagnostic.
|
|
8
|
+
|
|
9
|
+
## 6.3.0 (2023-06-23)
|
|
10
|
+
|
|
11
|
+
### New features
|
|
12
|
+
|
|
13
|
+
A new `previousDiagnostic` command can be used to move back through the active diagnostics.
|
|
14
|
+
|
|
1
15
|
## 6.2.2 (2023-06-05)
|
|
2
16
|
|
|
3
17
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -37,7 +37,7 @@ class LintState {
|
|
|
37
37
|
diagnostic: d
|
|
38
38
|
}).range(d.from)
|
|
39
39
|
: view.Decoration.mark({
|
|
40
|
-
attributes: { class: "cm-lintRange cm-lintRange-" + d.severity },
|
|
40
|
+
attributes: { class: "cm-lintRange cm-lintRange-" + d.severity + (d.markClass ? " " + d.markClass : "") },
|
|
41
41
|
diagnostic: d
|
|
42
42
|
}).range(d.from, d.to);
|
|
43
43
|
}), true);
|
|
@@ -182,6 +182,30 @@ const nextDiagnostic = (view) => {
|
|
|
182
182
|
return true;
|
|
183
183
|
};
|
|
184
184
|
/**
|
|
185
|
+
Move the selection to the previous diagnostic.
|
|
186
|
+
*/
|
|
187
|
+
const previousDiagnostic = (view) => {
|
|
188
|
+
let { state } = view, field = state.field(lintState, false);
|
|
189
|
+
if (!field)
|
|
190
|
+
return false;
|
|
191
|
+
let sel = state.selection.main;
|
|
192
|
+
let prevFrom, prevTo, lastFrom, lastTo;
|
|
193
|
+
field.diagnostics.between(0, state.doc.length, (from, to) => {
|
|
194
|
+
if (to < sel.to && (prevFrom == null || prevFrom < from)) {
|
|
195
|
+
prevFrom = from;
|
|
196
|
+
prevTo = to;
|
|
197
|
+
}
|
|
198
|
+
if (lastFrom == null || from > lastFrom) {
|
|
199
|
+
lastFrom = from;
|
|
200
|
+
lastTo = to;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (lastFrom == null || prevFrom == null && lastFrom == sel.from)
|
|
204
|
+
return false;
|
|
205
|
+
view.dispatch({ selection: { anchor: prevFrom !== null && prevFrom !== void 0 ? prevFrom : lastFrom, head: prevTo !== null && prevTo !== void 0 ? prevTo : lastTo }, scrollIntoView: true });
|
|
206
|
+
return true;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
185
209
|
A set of default key bindings for the lint functionality.
|
|
186
210
|
|
|
187
211
|
- Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
|
|
@@ -513,6 +537,7 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
513
537
|
".cm-diagnostic-error": { borderLeft: "5px solid #d11" },
|
|
514
538
|
".cm-diagnostic-warning": { borderLeft: "5px solid orange" },
|
|
515
539
|
".cm-diagnostic-info": { borderLeft: "5px solid #999" },
|
|
540
|
+
".cm-diagnostic-hint": { borderLeft: "5px solid #66d" },
|
|
516
541
|
".cm-diagnosticAction": {
|
|
517
542
|
font: "inherit",
|
|
518
543
|
border: "none",
|
|
@@ -535,6 +560,7 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
535
560
|
".cm-lintRange-error": { backgroundImage: underline("#d11") },
|
|
536
561
|
".cm-lintRange-warning": { backgroundImage: underline("orange") },
|
|
537
562
|
".cm-lintRange-info": { backgroundImage: underline("#999") },
|
|
563
|
+
".cm-lintRange-hint": { backgroundImage: underline("#66d") },
|
|
538
564
|
".cm-lintRange-active": { backgroundColor: "#ffdd9980" },
|
|
539
565
|
".cm-tooltip-lint": {
|
|
540
566
|
padding: 0,
|
|
@@ -558,6 +584,9 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
558
584
|
".cm-lintPoint-info": {
|
|
559
585
|
"&:after": { borderBottomColor: "#999" }
|
|
560
586
|
},
|
|
587
|
+
".cm-lintPoint-hint": {
|
|
588
|
+
"&:after": { borderBottomColor: "#66d" }
|
|
589
|
+
},
|
|
561
590
|
".cm-panel.cm-panel-lint": {
|
|
562
591
|
position: "relative",
|
|
563
592
|
"& ul": {
|
|
@@ -589,14 +618,14 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
589
618
|
}
|
|
590
619
|
}
|
|
591
620
|
});
|
|
621
|
+
function severityWeight(sev) {
|
|
622
|
+
return sev == "error" ? 4 : sev == "warning" ? 3 : sev == "info" ? 2 : 1;
|
|
623
|
+
}
|
|
592
624
|
class LintGutterMarker extends view.GutterMarker {
|
|
593
625
|
constructor(diagnostics) {
|
|
594
626
|
super();
|
|
595
627
|
this.diagnostics = diagnostics;
|
|
596
|
-
this.severity = diagnostics.reduce((max, d) =>
|
|
597
|
-
let s = d.severity;
|
|
598
|
-
return s == "error" || s == "warning" && max == "info" ? s : max;
|
|
599
|
-
}, "info");
|
|
628
|
+
this.severity = diagnostics.reduce((max, d) => severityWeight(max) < severityWeight(d.severity) ? d.severity : max, "hint");
|
|
600
629
|
}
|
|
601
630
|
toDOM(view) {
|
|
602
631
|
let elt = document.createElement("div");
|
|
@@ -772,5 +801,6 @@ exports.lintKeymap = lintKeymap;
|
|
|
772
801
|
exports.linter = linter;
|
|
773
802
|
exports.nextDiagnostic = nextDiagnostic;
|
|
774
803
|
exports.openLintPanel = openLintPanel;
|
|
804
|
+
exports.previousDiagnostic = previousDiagnostic;
|
|
775
805
|
exports.setDiagnostics = setDiagnostics;
|
|
776
806
|
exports.setDiagnosticsEffect = setDiagnosticsEffect;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import * as _codemirror_state from '@codemirror/state';
|
|
|
2
2
|
import { EditorState, TransactionSpec, Extension } from '@codemirror/state';
|
|
3
3
|
import { EditorView, Command, KeyBinding, ViewUpdate } from '@codemirror/view';
|
|
4
4
|
|
|
5
|
+
declare type Severity = "hint" | "info" | "warning" | "error";
|
|
5
6
|
/**
|
|
6
7
|
Describes a problem or hint for a piece of code.
|
|
7
8
|
*/
|
|
@@ -19,7 +20,12 @@ interface Diagnostic {
|
|
|
19
20
|
The severity of the problem. This will influence how it is
|
|
20
21
|
displayed.
|
|
21
22
|
*/
|
|
22
|
-
severity:
|
|
23
|
+
severity: Severity;
|
|
24
|
+
/**
|
|
25
|
+
When given, add an extra CSS class to parts of the code that
|
|
26
|
+
this diagnostic applies to.
|
|
27
|
+
*/
|
|
28
|
+
markClass?: string;
|
|
23
29
|
/**
|
|
24
30
|
An optional source string indicating where the diagnostic is
|
|
25
31
|
coming from. You can put the name of your linter here, if
|
|
@@ -124,6 +130,10 @@ Move the selection to the next diagnostic.
|
|
|
124
130
|
*/
|
|
125
131
|
declare const nextDiagnostic: Command;
|
|
126
132
|
/**
|
|
133
|
+
Move the selection to the previous diagnostic.
|
|
134
|
+
*/
|
|
135
|
+
declare const previousDiagnostic: Command;
|
|
136
|
+
/**
|
|
127
137
|
A set of default key bindings for the lint functionality.
|
|
128
138
|
|
|
129
139
|
- Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
|
|
@@ -160,4 +170,4 @@ arguments hold the diagnostic's current position.
|
|
|
160
170
|
*/
|
|
161
171
|
declare function forEachDiagnostic(state: EditorState, f: (d: Diagnostic, from: number, to: number) => void): void;
|
|
162
172
|
|
|
163
|
-
export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
|
|
173
|
+
export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, previousDiagnostic, setDiagnostics, setDiagnosticsEffect };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as _codemirror_state from '@codemirror/state';
|
|
|
2
2
|
import { EditorState, TransactionSpec, Extension } from '@codemirror/state';
|
|
3
3
|
import { EditorView, Command, KeyBinding, ViewUpdate } from '@codemirror/view';
|
|
4
4
|
|
|
5
|
+
declare type Severity = "hint" | "info" | "warning" | "error";
|
|
5
6
|
/**
|
|
6
7
|
Describes a problem or hint for a piece of code.
|
|
7
8
|
*/
|
|
@@ -19,7 +20,12 @@ interface Diagnostic {
|
|
|
19
20
|
The severity of the problem. This will influence how it is
|
|
20
21
|
displayed.
|
|
21
22
|
*/
|
|
22
|
-
severity:
|
|
23
|
+
severity: Severity;
|
|
24
|
+
/**
|
|
25
|
+
When given, add an extra CSS class to parts of the code that
|
|
26
|
+
this diagnostic applies to.
|
|
27
|
+
*/
|
|
28
|
+
markClass?: string;
|
|
23
29
|
/**
|
|
24
30
|
An optional source string indicating where the diagnostic is
|
|
25
31
|
coming from. You can put the name of your linter here, if
|
|
@@ -124,6 +130,10 @@ Move the selection to the next diagnostic.
|
|
|
124
130
|
*/
|
|
125
131
|
declare const nextDiagnostic: Command;
|
|
126
132
|
/**
|
|
133
|
+
Move the selection to the previous diagnostic.
|
|
134
|
+
*/
|
|
135
|
+
declare const previousDiagnostic: Command;
|
|
136
|
+
/**
|
|
127
137
|
A set of default key bindings for the lint functionality.
|
|
128
138
|
|
|
129
139
|
- Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
|
|
@@ -160,4 +170,4 @@ arguments hold the diagnostic's current position.
|
|
|
160
170
|
*/
|
|
161
171
|
declare function forEachDiagnostic(state: EditorState, f: (d: Diagnostic, from: number, to: number) => void): void;
|
|
162
172
|
|
|
163
|
-
export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
|
|
173
|
+
export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, previousDiagnostic, setDiagnostics, setDiagnosticsEffect };
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ class LintState {
|
|
|
29
29
|
diagnostic: d
|
|
30
30
|
}).range(d.from)
|
|
31
31
|
: Decoration.mark({
|
|
32
|
-
attributes: { class: "cm-lintRange cm-lintRange-" + d.severity },
|
|
32
|
+
attributes: { class: "cm-lintRange cm-lintRange-" + d.severity + (d.markClass ? " " + d.markClass : "") },
|
|
33
33
|
diagnostic: d
|
|
34
34
|
}).range(d.from, d.to);
|
|
35
35
|
}), true);
|
|
@@ -174,6 +174,30 @@ const nextDiagnostic = (view) => {
|
|
|
174
174
|
return true;
|
|
175
175
|
};
|
|
176
176
|
/**
|
|
177
|
+
Move the selection to the previous diagnostic.
|
|
178
|
+
*/
|
|
179
|
+
const previousDiagnostic = (view) => {
|
|
180
|
+
let { state } = view, field = state.field(lintState, false);
|
|
181
|
+
if (!field)
|
|
182
|
+
return false;
|
|
183
|
+
let sel = state.selection.main;
|
|
184
|
+
let prevFrom, prevTo, lastFrom, lastTo;
|
|
185
|
+
field.diagnostics.between(0, state.doc.length, (from, to) => {
|
|
186
|
+
if (to < sel.to && (prevFrom == null || prevFrom < from)) {
|
|
187
|
+
prevFrom = from;
|
|
188
|
+
prevTo = to;
|
|
189
|
+
}
|
|
190
|
+
if (lastFrom == null || from > lastFrom) {
|
|
191
|
+
lastFrom = from;
|
|
192
|
+
lastTo = to;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
if (lastFrom == null || prevFrom == null && lastFrom == sel.from)
|
|
196
|
+
return false;
|
|
197
|
+
view.dispatch({ selection: { anchor: prevFrom !== null && prevFrom !== void 0 ? prevFrom : lastFrom, head: prevTo !== null && prevTo !== void 0 ? prevTo : lastTo }, scrollIntoView: true });
|
|
198
|
+
return true;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
177
201
|
A set of default key bindings for the lint functionality.
|
|
178
202
|
|
|
179
203
|
- Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
|
|
@@ -505,6 +529,7 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
505
529
|
".cm-diagnostic-error": { borderLeft: "5px solid #d11" },
|
|
506
530
|
".cm-diagnostic-warning": { borderLeft: "5px solid orange" },
|
|
507
531
|
".cm-diagnostic-info": { borderLeft: "5px solid #999" },
|
|
532
|
+
".cm-diagnostic-hint": { borderLeft: "5px solid #66d" },
|
|
508
533
|
".cm-diagnosticAction": {
|
|
509
534
|
font: "inherit",
|
|
510
535
|
border: "none",
|
|
@@ -527,6 +552,7 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
527
552
|
".cm-lintRange-error": { backgroundImage: /*@__PURE__*/underline("#d11") },
|
|
528
553
|
".cm-lintRange-warning": { backgroundImage: /*@__PURE__*/underline("orange") },
|
|
529
554
|
".cm-lintRange-info": { backgroundImage: /*@__PURE__*/underline("#999") },
|
|
555
|
+
".cm-lintRange-hint": { backgroundImage: /*@__PURE__*/underline("#66d") },
|
|
530
556
|
".cm-lintRange-active": { backgroundColor: "#ffdd9980" },
|
|
531
557
|
".cm-tooltip-lint": {
|
|
532
558
|
padding: 0,
|
|
@@ -550,6 +576,9 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
550
576
|
".cm-lintPoint-info": {
|
|
551
577
|
"&:after": { borderBottomColor: "#999" }
|
|
552
578
|
},
|
|
579
|
+
".cm-lintPoint-hint": {
|
|
580
|
+
"&:after": { borderBottomColor: "#66d" }
|
|
581
|
+
},
|
|
553
582
|
".cm-panel.cm-panel-lint": {
|
|
554
583
|
position: "relative",
|
|
555
584
|
"& ul": {
|
|
@@ -581,14 +610,14 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
581
610
|
}
|
|
582
611
|
}
|
|
583
612
|
});
|
|
613
|
+
function severityWeight(sev) {
|
|
614
|
+
return sev == "error" ? 4 : sev == "warning" ? 3 : sev == "info" ? 2 : 1;
|
|
615
|
+
}
|
|
584
616
|
class LintGutterMarker extends GutterMarker {
|
|
585
617
|
constructor(diagnostics) {
|
|
586
618
|
super();
|
|
587
619
|
this.diagnostics = diagnostics;
|
|
588
|
-
this.severity = diagnostics.reduce((max, d) =>
|
|
589
|
-
let s = d.severity;
|
|
590
|
-
return s == "error" || s == "warning" && max == "info" ? s : max;
|
|
591
|
-
}, "info");
|
|
620
|
+
this.severity = diagnostics.reduce((max, d) => severityWeight(max) < severityWeight(d.severity) ? d.severity : max, "hint");
|
|
592
621
|
}
|
|
593
622
|
toDOM(view) {
|
|
594
623
|
let elt = document.createElement("div");
|
|
@@ -755,4 +784,4 @@ function forEachDiagnostic(state, f) {
|
|
|
755
784
|
f(iter.value.spec.diagnostic, iter.from, iter.to);
|
|
756
785
|
}
|
|
757
786
|
|
|
758
|
-
export { closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
|
|
787
|
+
export { closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, previousDiagnostic, setDiagnostics, setDiagnosticsEffect };
|