Skip to content
This repository was archived by the owner on Sep 19, 2025. It is now read-only.

Commit ba3fa40

Browse files
committed
Add way to manually trigger lint
1 parent a242315 commit ba3fa40

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/lint/tsLinter.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import { type Diagnostic, linter } from "@codemirror/lint";
22
import { tsFacet } from "../facet/tsFacet.js";
33
import { getLints } from "./getLints.js";
4+
import { Annotation } from "@codemirror/state";
5+
6+
/**
7+
* An annotation that you can send to CodeMirror to cause the code
8+
* to be re-linted. This could be because you've updated stuff
9+
* out-of-band in the TypeScript environment.
10+
*
11+
* @example
12+
* view.dispatch({
13+
* annotations: [triggerLint.of(true)],
14+
* });
15+
*/
16+
export const triggerLint = Annotation.define<boolean>();
417

518
/**
619
* Binds the TypeScript `lint()` method with TypeScript's
@@ -11,13 +24,20 @@ import { getLints } from "./getLints.js";
1124
export function tsLinter({
1225
diagnosticCodesToIgnore,
1326
}: { diagnosticCodesToIgnore?: number[] } = {}) {
14-
return linter(async (view): Promise<readonly Diagnostic[]> => {
15-
const config = view.state.facet(tsFacet);
16-
return config
17-
? getLints({
18-
...config,
19-
diagnosticCodesToIgnore: diagnosticCodesToIgnore || [],
20-
})
21-
: [];
22-
});
27+
return linter(
28+
async (view): Promise<readonly Diagnostic[]> => {
29+
const config = view.state.facet(tsFacet);
30+
return config
31+
? getLints({
32+
...config,
33+
diagnosticCodesToIgnore: diagnosticCodesToIgnore || [],
34+
})
35+
: [];
36+
},
37+
{
38+
needsRefresh: (update) => {
39+
return update.transactions.some((tr) => tr.annotation(triggerLint));
40+
},
41+
},
42+
);
2343
}

0 commit comments

Comments
 (0)