@codemirror/lint 6.4.0 → 6.4.2
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 +12 -0
- package/dist/index.cjs +15 -20
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 6.4.2 (2023-09-14)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Make sure scrolling diagnostic into view in the panel works when the editor is scaled.
|
|
6
|
+
|
|
7
|
+
## 6.4.1 (2023-08-26)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Fix a crash that could occur when a view was reconfigured in a way that removed the lint extension.
|
|
12
|
+
|
|
1
13
|
## 6.4.0 (2023-07-03)
|
|
2
14
|
|
|
3
15
|
### 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;
|
|
@@ -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"),
|
|
@@ -473,10 +467,11 @@ class LintPanel {
|
|
|
473
467
|
key: this,
|
|
474
468
|
read: () => ({ sel: newSelectedItem.dom.getBoundingClientRect(), panel: this.list.getBoundingClientRect() }),
|
|
475
469
|
write: ({ sel, panel }) => {
|
|
470
|
+
let scaleY = panel.height / this.list.offsetHeight;
|
|
476
471
|
if (sel.top < panel.top)
|
|
477
|
-
this.list.scrollTop -= panel.top - sel.top;
|
|
472
|
+
this.list.scrollTop -= (panel.top - sel.top) / scaleY;
|
|
478
473
|
else if (sel.bottom > panel.bottom)
|
|
479
|
-
this.list.scrollTop += sel.bottom - panel.bottom;
|
|
474
|
+
this.list.scrollTop += (sel.bottom - panel.bottom) / scaleY;
|
|
480
475
|
}
|
|
481
476
|
});
|
|
482
477
|
}
|
|
@@ -642,8 +637,8 @@ class LintGutterMarker extends view.GutterMarker {
|
|
|
642
637
|
function trackHoverOn(view, marker) {
|
|
643
638
|
let mousemove = (event) => {
|
|
644
639
|
let rect = marker.getBoundingClientRect();
|
|
645
|
-
if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
|
|
646
|
-
event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
|
|
640
|
+
if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ &&
|
|
641
|
+
event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */)
|
|
647
642
|
return;
|
|
648
643
|
for (let target = event.target; target; target = target.parentNode) {
|
|
649
644
|
if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
|
|
@@ -764,7 +759,7 @@ const lintExtensions = [
|
|
|
764
759
|
const lintGutterConfig = state.Facet.define({
|
|
765
760
|
combine(configs) {
|
|
766
761
|
return state.combineConfig(configs, {
|
|
767
|
-
hoverTime: 300 /* Time */,
|
|
762
|
+
hoverTime: 300 /* Hover.Time */,
|
|
768
763
|
markerFilter: null,
|
|
769
764
|
tooltipFilter: null
|
|
770
765
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +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
|
-
|
|
5
|
+
type Severity = "hint" | "info" | "warning" | "error";
|
|
6
6
|
/**
|
|
7
7
|
Describes a problem or hint for a piece of code.
|
|
8
8
|
*/
|
|
@@ -62,7 +62,7 @@ interface Action {
|
|
|
62
62
|
*/
|
|
63
63
|
apply: (view: EditorView, from: number, to: number) => void;
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
type DiagnosticFilter = (diagnostics: readonly Diagnostic[]) => Diagnostic[];
|
|
66
66
|
interface LintConfig {
|
|
67
67
|
/**
|
|
68
68
|
Time to wait (in milliseconds) after a change before running
|
|
@@ -143,7 +143,7 @@ declare const lintKeymap: readonly KeyBinding[];
|
|
|
143
143
|
/**
|
|
144
144
|
The type of a function that produces diagnostics.
|
|
145
145
|
*/
|
|
146
|
-
|
|
146
|
+
type LintSource = (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>;
|
|
147
147
|
/**
|
|
148
148
|
Given a diagnostic source, this function returns an extension that
|
|
149
149
|
enables linting with that source. It will be called whenever the
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +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
|
-
|
|
5
|
+
type Severity = "hint" | "info" | "warning" | "error";
|
|
6
6
|
/**
|
|
7
7
|
Describes a problem or hint for a piece of code.
|
|
8
8
|
*/
|
|
@@ -62,7 +62,7 @@ interface Action {
|
|
|
62
62
|
*/
|
|
63
63
|
apply: (view: EditorView, from: number, to: number) => void;
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
type DiagnosticFilter = (diagnostics: readonly Diagnostic[]) => Diagnostic[];
|
|
66
66
|
interface LintConfig {
|
|
67
67
|
/**
|
|
68
68
|
Time to wait (in milliseconds) after a change before running
|
|
@@ -143,7 +143,7 @@ declare const lintKeymap: readonly KeyBinding[];
|
|
|
143
143
|
/**
|
|
144
144
|
The type of a function that produces diagnostics.
|
|
145
145
|
*/
|
|
146
|
-
|
|
146
|
+
type LintSource = (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>;
|
|
147
147
|
/**
|
|
148
148
|
Given a diagnostic source, this function returns an extension that
|
|
149
149
|
enables linting with that source. It will be called whenever the
|
package/dist/index.js
CHANGED
|
@@ -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;
|
|
@@ -465,10 +465,11 @@ class LintPanel {
|
|
|
465
465
|
key: this,
|
|
466
466
|
read: () => ({ sel: newSelectedItem.dom.getBoundingClientRect(), panel: this.list.getBoundingClientRect() }),
|
|
467
467
|
write: ({ sel, panel }) => {
|
|
468
|
+
let scaleY = panel.height / this.list.offsetHeight;
|
|
468
469
|
if (sel.top < panel.top)
|
|
469
|
-
this.list.scrollTop -= panel.top - sel.top;
|
|
470
|
+
this.list.scrollTop -= (panel.top - sel.top) / scaleY;
|
|
470
471
|
else if (sel.bottom > panel.bottom)
|
|
471
|
-
this.list.scrollTop += sel.bottom - panel.bottom;
|
|
472
|
+
this.list.scrollTop += (sel.bottom - panel.bottom) / scaleY;
|
|
472
473
|
}
|
|
473
474
|
});
|
|
474
475
|
}
|
|
@@ -634,8 +635,8 @@ class LintGutterMarker extends GutterMarker {
|
|
|
634
635
|
function trackHoverOn(view, marker) {
|
|
635
636
|
let mousemove = (event) => {
|
|
636
637
|
let rect = marker.getBoundingClientRect();
|
|
637
|
-
if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
|
|
638
|
-
event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
|
|
638
|
+
if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ &&
|
|
639
|
+
event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */)
|
|
639
640
|
return;
|
|
640
641
|
for (let target = event.target; target; target = target.parentNode) {
|
|
641
642
|
if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
|
|
@@ -756,7 +757,7 @@ const lintExtensions = [
|
|
|
756
757
|
const lintGutterConfig = /*@__PURE__*/Facet.define({
|
|
757
758
|
combine(configs) {
|
|
758
759
|
return combineConfig(configs, {
|
|
759
|
-
hoverTime: 300 /* Time */,
|
|
760
|
+
hoverTime: 300 /* Hover.Time */,
|
|
760
761
|
markerFilter: null,
|
|
761
762
|
tooltipFilter: null
|
|
762
763
|
});
|