@@ -8,44 +8,48 @@ const SEVERITY = ['error', 'warning', 'info'] as const;
88
99export const lint : Extension = linter (
1010 view => {
11- const schema = getSchema ( view . state ) ;
12- if ( ! schema ) {
13- return [ ] ;
14- }
15- const results = getDiagnostics ( view . state . doc . toString ( ) , schema ) ;
11+ try {
12+ const schema = getSchema ( view . state ) ;
13+ if ( ! schema ) {
14+ return [ ] ;
15+ }
16+ const results = getDiagnostics ( view . state . doc . toString ( ) , schema ) ;
1617
17- return results
18- . map ( ( item ) : Diagnostic | null => {
19- if ( ! item . severity || ! item . source ) {
20- return null ;
21- }
18+ return results
19+ . map ( ( item ) : Diagnostic | null => {
20+ if ( ! item . severity || ! item . source ) {
21+ return null ;
22+ }
2223
23- const calculatedFrom = posToOffset (
24- view . state . doc ,
25- new Position ( item . range . start . line , item . range . start . character ) ,
26- ) ;
27- const from = Math . max (
28- 0 ,
29- Math . min ( calculatedFrom , view . state . doc . length ) ,
30- ) ;
31- const calculatedRo = posToOffset (
32- view . state . doc ,
33- new Position ( item . range . end . line , item . range . end . character - 1 ) ,
34- ) ;
35- const to = Math . min (
36- Math . max ( from + 1 , calculatedRo ) ,
37- view . state . doc . length ,
38- ) ;
39- return {
40- from,
41- to : from === to ? to + 1 : to ,
42- severity : SEVERITY [ item . severity - 1 ] ,
43- // source: item.source, // TODO:
44- message : item . message ,
45- actions : [ ] , // TODO:
46- } ;
47- } )
48- . filter ( ( _ ) : _ is Diagnostic => Boolean ( _ ) ) ;
24+ const calculatedFrom = posToOffset (
25+ view . state . doc ,
26+ new Position ( item . range . start . line , item . range . start . character ) ,
27+ ) ;
28+ const from = Math . max (
29+ 0 ,
30+ Math . min ( calculatedFrom , view . state . doc . length ) ,
31+ ) ;
32+ const calculatedRo = posToOffset (
33+ view . state . doc ,
34+ new Position ( item . range . end . line , item . range . end . character - 1 ) ,
35+ ) ;
36+ const to = Math . min (
37+ Math . max ( from + 1 , calculatedRo ) ,
38+ view . state . doc . length ,
39+ ) ;
40+ return {
41+ from,
42+ to : from === to ? to + 1 : to ,
43+ severity : SEVERITY [ item . severity - 1 ] ,
44+ // source: item.source, // TODO:
45+ message : item . message ,
46+ actions : [ ] , // TODO:
47+ } ;
48+ } )
49+ . filter ( ( _ ) : _ is Diagnostic => Boolean ( _ ) ) ;
50+ } catch {
51+ return [ ] ;
52+ }
4953 } ,
5054 {
5155 needsRefresh ( vu ) {
0 commit comments