This repository was archived by the owner on Sep 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +29
-9
lines changed
Expand file tree Collapse file tree 1 file changed +29
-9
lines changed Original file line number Diff line number Diff line change 11import { type Diagnostic , linter } from "@codemirror/lint" ;
22import { tsFacet } from "../facet/tsFacet.js" ;
33import { 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";
1124export 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}
You can’t perform that action at this time.
0 commit comments