@codemirror/lint 6.3.0 → 6.4.1
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 +22 -23
- package/dist/index.d.cts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +14 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 6.4.1 (2023-08-26)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a crash that could occur when a view was reconfigured in a way that removed the lint extension.
|
|
6
|
+
|
|
7
|
+
## 6.4.0 (2023-07-03)
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
Diagnostics can now use `"hint"` as a severity level.
|
|
12
|
+
|
|
13
|
+
Diagnostics can now set a `markClass` property to add an additional CSS class to the text marked by the diagnostic.
|
|
14
|
+
|
|
1
15
|
## 6.3.0 (2023-06-23)
|
|
2
16
|
|
|
3
17
|
### New features
|
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var view = require('@codemirror/view');
|
|
6
4
|
var state = require('@codemirror/state');
|
|
7
5
|
var elt = require('crelt');
|
|
8
6
|
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var elt__default = /*#__PURE__*/_interopDefaultLegacy(elt);
|
|
12
|
-
|
|
13
7
|
class SelectedDiagnostic {
|
|
14
8
|
constructor(from, to, diagnostic) {
|
|
15
9
|
this.from = from;
|
|
@@ -37,7 +31,7 @@ class LintState {
|
|
|
37
31
|
diagnostic: d
|
|
38
32
|
}).range(d.from)
|
|
39
33
|
: view.Decoration.mark({
|
|
40
|
-
attributes: { class: "cm-lintRange cm-lintRange-" + d.severity },
|
|
34
|
+
attributes: { class: "cm-lintRange cm-lintRange-" + d.severity + (d.markClass ? " " + d.markClass : "") },
|
|
41
35
|
diagnostic: d
|
|
42
36
|
}).range(d.from, d.to);
|
|
43
37
|
}), true);
|
|
@@ -141,7 +135,7 @@ function lintTooltip(view, pos, side) {
|
|
|
141
135
|
};
|
|
142
136
|
}
|
|
143
137
|
function diagnosticsTooltip(view, diagnostics) {
|
|
144
|
-
return
|
|
138
|
+
return elt("ul", { class: "cm-tooltip-lint" }, diagnostics.map(d => renderDiagnostic(view, d, false)));
|
|
145
139
|
}
|
|
146
140
|
/**
|
|
147
141
|
Command to open and focus the lint panel.
|
|
@@ -228,7 +222,7 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
|
|
|
228
222
|
run() {
|
|
229
223
|
let now = Date.now();
|
|
230
224
|
if (now < this.lintTime - 10) {
|
|
231
|
-
setTimeout(this.run, this.lintTime - now);
|
|
225
|
+
this.timeout = setTimeout(this.run, this.lintTime - now);
|
|
232
226
|
}
|
|
233
227
|
else {
|
|
234
228
|
this.set = false;
|
|
@@ -312,7 +306,7 @@ function assignKeys(actions) {
|
|
|
312
306
|
function renderDiagnostic(view, diagnostic, inPanel) {
|
|
313
307
|
var _a;
|
|
314
308
|
let keys = inPanel ? assignKeys(diagnostic.actions) : [];
|
|
315
|
-
return
|
|
309
|
+
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) => {
|
|
316
310
|
let fired = false, click = (e) => {
|
|
317
311
|
e.preventDefault();
|
|
318
312
|
if (fired)
|
|
@@ -324,16 +318,16 @@ function renderDiagnostic(view, diagnostic, inPanel) {
|
|
|
324
318
|
};
|
|
325
319
|
let { name } = action, keyIndex = keys[i] ? name.indexOf(keys[i]) : -1;
|
|
326
320
|
let nameElt = keyIndex < 0 ? name : [name.slice(0, keyIndex),
|
|
327
|
-
|
|
321
|
+
elt("u", name.slice(keyIndex, keyIndex + 1)),
|
|
328
322
|
name.slice(keyIndex + 1)];
|
|
329
|
-
return
|
|
323
|
+
return elt("button", {
|
|
330
324
|
type: "button",
|
|
331
325
|
class: "cm-diagnosticAction",
|
|
332
326
|
onclick: click,
|
|
333
327
|
onmousedown: click,
|
|
334
328
|
"aria-label": ` Action: ${name}${keyIndex < 0 ? "" : ` (access key "${keys[i]})"`}.`
|
|
335
329
|
}, nameElt);
|
|
336
|
-
}), diagnostic.source &&
|
|
330
|
+
}), diagnostic.source && elt("div", { class: "cm-diagnosticSource" }, diagnostic.source));
|
|
337
331
|
}
|
|
338
332
|
class DiagnosticWidget extends view.WidgetType {
|
|
339
333
|
constructor(diagnostic) {
|
|
@@ -342,7 +336,7 @@ class DiagnosticWidget extends view.WidgetType {
|
|
|
342
336
|
}
|
|
343
337
|
eq(other) { return other.diagnostic == this.diagnostic; }
|
|
344
338
|
toDOM() {
|
|
345
|
-
return
|
|
339
|
+
return elt("span", { class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity });
|
|
346
340
|
}
|
|
347
341
|
}
|
|
348
342
|
class PanelItem {
|
|
@@ -398,14 +392,14 @@ class LintPanel {
|
|
|
398
392
|
this.moveSelection(i);
|
|
399
393
|
}
|
|
400
394
|
};
|
|
401
|
-
this.list =
|
|
395
|
+
this.list = elt("ul", {
|
|
402
396
|
tabIndex: 0,
|
|
403
397
|
role: "listbox",
|
|
404
398
|
"aria-label": this.view.state.phrase("Diagnostics"),
|
|
405
399
|
onkeydown,
|
|
406
400
|
onclick
|
|
407
401
|
});
|
|
408
|
-
this.dom =
|
|
402
|
+
this.dom = elt("div", { class: "cm-panel-lint" }, this.list, elt("button", {
|
|
409
403
|
type: "button",
|
|
410
404
|
name: "close",
|
|
411
405
|
"aria-label": this.view.state.phrase("close"),
|
|
@@ -537,6 +531,7 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
537
531
|
".cm-diagnostic-error": { borderLeft: "5px solid #d11" },
|
|
538
532
|
".cm-diagnostic-warning": { borderLeft: "5px solid orange" },
|
|
539
533
|
".cm-diagnostic-info": { borderLeft: "5px solid #999" },
|
|
534
|
+
".cm-diagnostic-hint": { borderLeft: "5px solid #66d" },
|
|
540
535
|
".cm-diagnosticAction": {
|
|
541
536
|
font: "inherit",
|
|
542
537
|
border: "none",
|
|
@@ -559,6 +554,7 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
559
554
|
".cm-lintRange-error": { backgroundImage: underline("#d11") },
|
|
560
555
|
".cm-lintRange-warning": { backgroundImage: underline("orange") },
|
|
561
556
|
".cm-lintRange-info": { backgroundImage: underline("#999") },
|
|
557
|
+
".cm-lintRange-hint": { backgroundImage: underline("#66d") },
|
|
562
558
|
".cm-lintRange-active": { backgroundColor: "#ffdd9980" },
|
|
563
559
|
".cm-tooltip-lint": {
|
|
564
560
|
padding: 0,
|
|
@@ -582,6 +578,9 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
582
578
|
".cm-lintPoint-info": {
|
|
583
579
|
"&:after": { borderBottomColor: "#999" }
|
|
584
580
|
},
|
|
581
|
+
".cm-lintPoint-hint": {
|
|
582
|
+
"&:after": { borderBottomColor: "#66d" }
|
|
583
|
+
},
|
|
585
584
|
".cm-panel.cm-panel-lint": {
|
|
586
585
|
position: "relative",
|
|
587
586
|
"& ul": {
|
|
@@ -613,14 +612,14 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
613
612
|
}
|
|
614
613
|
}
|
|
615
614
|
});
|
|
615
|
+
function severityWeight(sev) {
|
|
616
|
+
return sev == "error" ? 4 : sev == "warning" ? 3 : sev == "info" ? 2 : 1;
|
|
617
|
+
}
|
|
616
618
|
class LintGutterMarker extends view.GutterMarker {
|
|
617
619
|
constructor(diagnostics) {
|
|
618
620
|
super();
|
|
619
621
|
this.diagnostics = diagnostics;
|
|
620
|
-
this.severity = diagnostics.reduce((max, d) =>
|
|
621
|
-
let s = d.severity;
|
|
622
|
-
return s == "error" || s == "warning" && max == "info" ? s : max;
|
|
623
|
-
}, "info");
|
|
622
|
+
this.severity = diagnostics.reduce((max, d) => severityWeight(max) < severityWeight(d.severity) ? d.severity : max, "hint");
|
|
624
623
|
}
|
|
625
624
|
toDOM(view) {
|
|
626
625
|
let elt = document.createElement("div");
|
|
@@ -637,8 +636,8 @@ class LintGutterMarker extends view.GutterMarker {
|
|
|
637
636
|
function trackHoverOn(view, marker) {
|
|
638
637
|
let mousemove = (event) => {
|
|
639
638
|
let rect = marker.getBoundingClientRect();
|
|
640
|
-
if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
|
|
641
|
-
event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
|
|
639
|
+
if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ &&
|
|
640
|
+
event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */)
|
|
642
641
|
return;
|
|
643
642
|
for (let target = event.target; target; target = target.parentNode) {
|
|
644
643
|
if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
|
|
@@ -759,7 +758,7 @@ const lintExtensions = [
|
|
|
759
758
|
const lintGutterConfig = state.Facet.define({
|
|
760
759
|
combine(configs) {
|
|
761
760
|
return state.combineConfig(configs, {
|
|
762
|
-
hoverTime: 300 /* Time */,
|
|
761
|
+
hoverTime: 300 /* Hover.Time */,
|
|
763
762
|
markerFilter: null,
|
|
764
763
|
tooltipFilter: null
|
|
765
764
|
});
|
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
|
+
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
|
|
@@ -56,7 +62,7 @@ interface Action {
|
|
|
56
62
|
*/
|
|
57
63
|
apply: (view: EditorView, from: number, to: number) => void;
|
|
58
64
|
}
|
|
59
|
-
|
|
65
|
+
type DiagnosticFilter = (diagnostics: readonly Diagnostic[]) => Diagnostic[];
|
|
60
66
|
interface LintConfig {
|
|
61
67
|
/**
|
|
62
68
|
Time to wait (in milliseconds) after a change before running
|
|
@@ -137,7 +143,7 @@ declare const lintKeymap: readonly KeyBinding[];
|
|
|
137
143
|
/**
|
|
138
144
|
The type of a function that produces diagnostics.
|
|
139
145
|
*/
|
|
140
|
-
|
|
146
|
+
type LintSource = (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>;
|
|
141
147
|
/**
|
|
142
148
|
Given a diagnostic source, this function returns an extension that
|
|
143
149
|
enables linting with that source. It will be called whenever the
|
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
|
+
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
|
|
@@ -56,7 +62,7 @@ interface Action {
|
|
|
56
62
|
*/
|
|
57
63
|
apply: (view: EditorView, from: number, to: number) => void;
|
|
58
64
|
}
|
|
59
|
-
|
|
65
|
+
type DiagnosticFilter = (diagnostics: readonly Diagnostic[]) => Diagnostic[];
|
|
60
66
|
interface LintConfig {
|
|
61
67
|
/**
|
|
62
68
|
Time to wait (in milliseconds) after a change before running
|
|
@@ -137,7 +143,7 @@ declare const lintKeymap: readonly KeyBinding[];
|
|
|
137
143
|
/**
|
|
138
144
|
The type of a function that produces diagnostics.
|
|
139
145
|
*/
|
|
140
|
-
|
|
146
|
+
type LintSource = (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>;
|
|
141
147
|
/**
|
|
142
148
|
Given a diagnostic source, this function returns an extension that
|
|
143
149
|
enables linting with that source. It will be called whenever the
|
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);
|
|
@@ -220,7 +220,7 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
220
220
|
run() {
|
|
221
221
|
let now = Date.now();
|
|
222
222
|
if (now < this.lintTime - 10) {
|
|
223
|
-
setTimeout(this.run, this.lintTime - now);
|
|
223
|
+
this.timeout = setTimeout(this.run, this.lintTime - now);
|
|
224
224
|
}
|
|
225
225
|
else {
|
|
226
226
|
this.set = false;
|
|
@@ -529,6 +529,7 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
529
529
|
".cm-diagnostic-error": { borderLeft: "5px solid #d11" },
|
|
530
530
|
".cm-diagnostic-warning": { borderLeft: "5px solid orange" },
|
|
531
531
|
".cm-diagnostic-info": { borderLeft: "5px solid #999" },
|
|
532
|
+
".cm-diagnostic-hint": { borderLeft: "5px solid #66d" },
|
|
532
533
|
".cm-diagnosticAction": {
|
|
533
534
|
font: "inherit",
|
|
534
535
|
border: "none",
|
|
@@ -551,6 +552,7 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
551
552
|
".cm-lintRange-error": { backgroundImage: /*@__PURE__*/underline("#d11") },
|
|
552
553
|
".cm-lintRange-warning": { backgroundImage: /*@__PURE__*/underline("orange") },
|
|
553
554
|
".cm-lintRange-info": { backgroundImage: /*@__PURE__*/underline("#999") },
|
|
555
|
+
".cm-lintRange-hint": { backgroundImage: /*@__PURE__*/underline("#66d") },
|
|
554
556
|
".cm-lintRange-active": { backgroundColor: "#ffdd9980" },
|
|
555
557
|
".cm-tooltip-lint": {
|
|
556
558
|
padding: 0,
|
|
@@ -574,6 +576,9 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
574
576
|
".cm-lintPoint-info": {
|
|
575
577
|
"&:after": { borderBottomColor: "#999" }
|
|
576
578
|
},
|
|
579
|
+
".cm-lintPoint-hint": {
|
|
580
|
+
"&:after": { borderBottomColor: "#66d" }
|
|
581
|
+
},
|
|
577
582
|
".cm-panel.cm-panel-lint": {
|
|
578
583
|
position: "relative",
|
|
579
584
|
"& ul": {
|
|
@@ -605,14 +610,14 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
605
610
|
}
|
|
606
611
|
}
|
|
607
612
|
});
|
|
613
|
+
function severityWeight(sev) {
|
|
614
|
+
return sev == "error" ? 4 : sev == "warning" ? 3 : sev == "info" ? 2 : 1;
|
|
615
|
+
}
|
|
608
616
|
class LintGutterMarker extends GutterMarker {
|
|
609
617
|
constructor(diagnostics) {
|
|
610
618
|
super();
|
|
611
619
|
this.diagnostics = diagnostics;
|
|
612
|
-
this.severity = diagnostics.reduce((max, d) =>
|
|
613
|
-
let s = d.severity;
|
|
614
|
-
return s == "error" || s == "warning" && max == "info" ? s : max;
|
|
615
|
-
}, "info");
|
|
620
|
+
this.severity = diagnostics.reduce((max, d) => severityWeight(max) < severityWeight(d.severity) ? d.severity : max, "hint");
|
|
616
621
|
}
|
|
617
622
|
toDOM(view) {
|
|
618
623
|
let elt = document.createElement("div");
|
|
@@ -629,8 +634,8 @@ class LintGutterMarker extends GutterMarker {
|
|
|
629
634
|
function trackHoverOn(view, marker) {
|
|
630
635
|
let mousemove = (event) => {
|
|
631
636
|
let rect = marker.getBoundingClientRect();
|
|
632
|
-
if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
|
|
633
|
-
event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
|
|
637
|
+
if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ &&
|
|
638
|
+
event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */)
|
|
634
639
|
return;
|
|
635
640
|
for (let target = event.target; target; target = target.parentNode) {
|
|
636
641
|
if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
|
|
@@ -751,7 +756,7 @@ const lintExtensions = [
|
|
|
751
756
|
const lintGutterConfig = /*@__PURE__*/Facet.define({
|
|
752
757
|
combine(configs) {
|
|
753
758
|
return combineConfig(configs, {
|
|
754
|
-
hoverTime: 300 /* Time */,
|
|
759
|
+
hoverTime: 300 /* Hover.Time */,
|
|
755
760
|
markerFilter: null,
|
|
756
761
|
tooltipFilter: null
|
|
757
762
|
});
|