@codemirror/lint 6.2.1 → 6.2.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 +6 -0
- package/dist/index.cjs +5 -4
- package/dist/index.d.cts +163 -0
- package/dist/index.js +5 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -55,7 +55,8 @@ function findDiagnostic(diagnostics, diagnostic = null, after = 0) {
|
|
|
55
55
|
return found;
|
|
56
56
|
}
|
|
57
57
|
function hideTooltip(tr, tooltip) {
|
|
58
|
-
|
|
58
|
+
let line = tr.startState.doc.lineAt(tooltip.pos);
|
|
59
|
+
return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(line.from, line.to));
|
|
59
60
|
}
|
|
60
61
|
function maybeEnableLint(state$1, effects) {
|
|
61
62
|
return state$1.field(lintState, false) ? effects : effects.concat(state.StateEffect.appendConfig.of(lintExtensions));
|
|
@@ -612,8 +613,8 @@ class LintGutterMarker extends view.GutterMarker {
|
|
|
612
613
|
function trackHoverOn(view, marker) {
|
|
613
614
|
let mousemove = (event) => {
|
|
614
615
|
let rect = marker.getBoundingClientRect();
|
|
615
|
-
if (event.clientX > rect.left - 10 /*
|
|
616
|
-
event.clientY > rect.top - 10 /*
|
|
616
|
+
if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
|
|
617
|
+
event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
|
|
617
618
|
return;
|
|
618
619
|
for (let target = event.target; target; target = target.parentNode) {
|
|
619
620
|
if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
|
|
@@ -734,7 +735,7 @@ const lintExtensions = [
|
|
|
734
735
|
const lintGutterConfig = state.Facet.define({
|
|
735
736
|
combine(configs) {
|
|
736
737
|
return state.combineConfig(configs, {
|
|
737
|
-
hoverTime: 300 /*
|
|
738
|
+
hoverTime: 300 /* Time */,
|
|
738
739
|
markerFilter: null,
|
|
739
740
|
tooltipFilter: null
|
|
740
741
|
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as _codemirror_state from '@codemirror/state';
|
|
2
|
+
import { EditorState, TransactionSpec, Extension } from '@codemirror/state';
|
|
3
|
+
import { EditorView, Command, KeyBinding, ViewUpdate } from '@codemirror/view';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
Describes a problem or hint for a piece of code.
|
|
7
|
+
*/
|
|
8
|
+
interface Diagnostic {
|
|
9
|
+
/**
|
|
10
|
+
The start position of the relevant text.
|
|
11
|
+
*/
|
|
12
|
+
from: number;
|
|
13
|
+
/**
|
|
14
|
+
The end position. May be equal to `from`, though actually
|
|
15
|
+
covering text is preferable.
|
|
16
|
+
*/
|
|
17
|
+
to: number;
|
|
18
|
+
/**
|
|
19
|
+
The severity of the problem. This will influence how it is
|
|
20
|
+
displayed.
|
|
21
|
+
*/
|
|
22
|
+
severity: "info" | "warning" | "error";
|
|
23
|
+
/**
|
|
24
|
+
An optional source string indicating where the diagnostic is
|
|
25
|
+
coming from. You can put the name of your linter here, if
|
|
26
|
+
applicable.
|
|
27
|
+
*/
|
|
28
|
+
source?: string;
|
|
29
|
+
/**
|
|
30
|
+
The message associated with this diagnostic.
|
|
31
|
+
*/
|
|
32
|
+
message: string;
|
|
33
|
+
/**
|
|
34
|
+
An optional custom rendering function that displays the message
|
|
35
|
+
as a DOM node.
|
|
36
|
+
*/
|
|
37
|
+
renderMessage?: () => Node;
|
|
38
|
+
/**
|
|
39
|
+
An optional array of actions that can be taken on this
|
|
40
|
+
diagnostic.
|
|
41
|
+
*/
|
|
42
|
+
actions?: readonly Action[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
An action associated with a diagnostic.
|
|
46
|
+
*/
|
|
47
|
+
interface Action {
|
|
48
|
+
/**
|
|
49
|
+
The label to show to the user. Should be relatively short.
|
|
50
|
+
*/
|
|
51
|
+
name: string;
|
|
52
|
+
/**
|
|
53
|
+
The function to call when the user activates this action. Is
|
|
54
|
+
given the diagnostic's _current_ position, which may have
|
|
55
|
+
changed since the creation of the diagnostic, due to editing.
|
|
56
|
+
*/
|
|
57
|
+
apply: (view: EditorView, from: number, to: number) => void;
|
|
58
|
+
}
|
|
59
|
+
declare type DiagnosticFilter = (diagnostics: readonly Diagnostic[]) => Diagnostic[];
|
|
60
|
+
interface LintConfig {
|
|
61
|
+
/**
|
|
62
|
+
Time to wait (in milliseconds) after a change before running
|
|
63
|
+
the linter. Defaults to 750ms.
|
|
64
|
+
*/
|
|
65
|
+
delay?: number;
|
|
66
|
+
/**
|
|
67
|
+
Optional predicate that can be used to indicate when diagnostics
|
|
68
|
+
need to be recomputed. Linting is always re-done on document
|
|
69
|
+
changes.
|
|
70
|
+
*/
|
|
71
|
+
needsRefresh?: null | ((update: ViewUpdate) => boolean);
|
|
72
|
+
/**
|
|
73
|
+
Optional filter to determine which diagnostics produce markers
|
|
74
|
+
in the content.
|
|
75
|
+
*/
|
|
76
|
+
markerFilter?: null | DiagnosticFilter;
|
|
77
|
+
/**
|
|
78
|
+
Filter applied to a set of diagnostics shown in a tooltip. No
|
|
79
|
+
tooltip will appear if the empty set is returned.
|
|
80
|
+
*/
|
|
81
|
+
tooltipFilter?: null | DiagnosticFilter;
|
|
82
|
+
}
|
|
83
|
+
interface LintGutterConfig {
|
|
84
|
+
/**
|
|
85
|
+
The delay before showing a tooltip when hovering over a lint gutter marker.
|
|
86
|
+
*/
|
|
87
|
+
hoverTime?: number;
|
|
88
|
+
/**
|
|
89
|
+
Optional filter determining which diagnostics show a marker in
|
|
90
|
+
the gutter.
|
|
91
|
+
*/
|
|
92
|
+
markerFilter?: null | DiagnosticFilter;
|
|
93
|
+
/**
|
|
94
|
+
Optional filter for diagnostics displayed in a tooltip, which
|
|
95
|
+
can also be used to prevent a tooltip appearing.
|
|
96
|
+
*/
|
|
97
|
+
tooltipFilter?: null | DiagnosticFilter;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
Returns a transaction spec which updates the current set of
|
|
101
|
+
diagnostics, and enables the lint extension if if wasn't already
|
|
102
|
+
active.
|
|
103
|
+
*/
|
|
104
|
+
declare function setDiagnostics(state: EditorState, diagnostics: readonly Diagnostic[]): TransactionSpec;
|
|
105
|
+
/**
|
|
106
|
+
The state effect that updates the set of active diagnostics. Can
|
|
107
|
+
be useful when writing an extension that needs to track these.
|
|
108
|
+
*/
|
|
109
|
+
declare const setDiagnosticsEffect: _codemirror_state.StateEffectType<readonly Diagnostic[]>;
|
|
110
|
+
/**
|
|
111
|
+
Returns the number of active lint diagnostics in the given state.
|
|
112
|
+
*/
|
|
113
|
+
declare function diagnosticCount(state: EditorState): number;
|
|
114
|
+
/**
|
|
115
|
+
Command to open and focus the lint panel.
|
|
116
|
+
*/
|
|
117
|
+
declare const openLintPanel: Command;
|
|
118
|
+
/**
|
|
119
|
+
Command to close the lint panel, when open.
|
|
120
|
+
*/
|
|
121
|
+
declare const closeLintPanel: Command;
|
|
122
|
+
/**
|
|
123
|
+
Move the selection to the next diagnostic.
|
|
124
|
+
*/
|
|
125
|
+
declare const nextDiagnostic: Command;
|
|
126
|
+
/**
|
|
127
|
+
A set of default key bindings for the lint functionality.
|
|
128
|
+
|
|
129
|
+
- Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
|
|
130
|
+
- F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
|
|
131
|
+
*/
|
|
132
|
+
declare const lintKeymap: readonly KeyBinding[];
|
|
133
|
+
/**
|
|
134
|
+
The type of a function that produces diagnostics.
|
|
135
|
+
*/
|
|
136
|
+
declare type LintSource = (view: EditorView) => readonly Diagnostic[] | Promise<readonly Diagnostic[]>;
|
|
137
|
+
/**
|
|
138
|
+
Given a diagnostic source, this function returns an extension that
|
|
139
|
+
enables linting with that source. It will be called whenever the
|
|
140
|
+
editor is idle (after its content changed).
|
|
141
|
+
*/
|
|
142
|
+
declare function linter(source: LintSource, config?: LintConfig): Extension;
|
|
143
|
+
/**
|
|
144
|
+
Forces any linters [configured](https://codemirror.net/6/docs/ref/#lint.linter) to run when the
|
|
145
|
+
editor is idle to run right away.
|
|
146
|
+
*/
|
|
147
|
+
declare function forceLinting(view: EditorView): void;
|
|
148
|
+
/**
|
|
149
|
+
Returns an extension that installs a gutter showing markers for
|
|
150
|
+
each line that has diagnostics, which can be hovered over to see
|
|
151
|
+
the diagnostics.
|
|
152
|
+
*/
|
|
153
|
+
declare function lintGutter(config?: LintGutterConfig): Extension;
|
|
154
|
+
/**
|
|
155
|
+
Iterate over the marked diagnostics for the given editor state,
|
|
156
|
+
calling `f` for each of them. Note that, if the document changed
|
|
157
|
+
since the diagnostics were created, the `Diagnostic` object will
|
|
158
|
+
hold the original outdated position, whereas the `to` and `from`
|
|
159
|
+
arguments hold the diagnostic's current position.
|
|
160
|
+
*/
|
|
161
|
+
declare function forEachDiagnostic(state: EditorState, f: (d: Diagnostic, from: number, to: number) => void): void;
|
|
162
|
+
|
|
163
|
+
export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
|
package/dist/index.js
CHANGED
|
@@ -47,7 +47,8 @@ function findDiagnostic(diagnostics, diagnostic = null, after = 0) {
|
|
|
47
47
|
return found;
|
|
48
48
|
}
|
|
49
49
|
function hideTooltip(tr, tooltip) {
|
|
50
|
-
|
|
50
|
+
let line = tr.startState.doc.lineAt(tooltip.pos);
|
|
51
|
+
return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(line.from, line.to));
|
|
51
52
|
}
|
|
52
53
|
function maybeEnableLint(state, effects) {
|
|
53
54
|
return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of(lintExtensions));
|
|
@@ -604,8 +605,8 @@ class LintGutterMarker extends GutterMarker {
|
|
|
604
605
|
function trackHoverOn(view, marker) {
|
|
605
606
|
let mousemove = (event) => {
|
|
606
607
|
let rect = marker.getBoundingClientRect();
|
|
607
|
-
if (event.clientX > rect.left - 10 /*
|
|
608
|
-
event.clientY > rect.top - 10 /*
|
|
608
|
+
if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
|
|
609
|
+
event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
|
|
609
610
|
return;
|
|
610
611
|
for (let target = event.target; target; target = target.parentNode) {
|
|
611
612
|
if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
|
|
@@ -726,7 +727,7 @@ const lintExtensions = [
|
|
|
726
727
|
const lintGutterConfig = /*@__PURE__*/Facet.define({
|
|
727
728
|
combine(configs) {
|
|
728
729
|
return combineConfig(configs, {
|
|
729
|
-
hoverTime: 300 /*
|
|
730
|
+
hoverTime: 300 /* Time */,
|
|
730
731
|
markerFilter: null,
|
|
731
732
|
tooltipFilter: null
|
|
732
733
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemirror/lint",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.2",
|
|
4
4
|
"description": "Linting support for the CodeMirror code editor",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "cm-runtests",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"crelt": "^1.0.5"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@codemirror/buildhelper": "^
|
|
34
|
+
"@codemirror/buildhelper": "^1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|