@@ -32,27 +32,7 @@ async function openAllDocuments(
32
32
) {
33
33
const offset = workspaceUri . fsPath . length + 1 ;
34
34
// We support a very limited subset of glob patterns: You can only have ** at the end or the start
35
- const ignored : Array < ( path : string ) => boolean > = filePathsToIgnore . map ( ( i ) => {
36
- if ( i . endsWith ( '**' ) ) i = i . slice ( 0 , - 2 ) ;
37
-
38
- if ( i . startsWith ( '**' ) ) {
39
- i = i . slice ( 2 ) ;
40
-
41
- if ( i . includes ( '*' ) )
42
- throw new Error (
43
- 'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported'
44
- ) ;
45
-
46
- return ( path ) => path . includes ( i ) ;
47
- }
48
-
49
- if ( i . includes ( '*' ) )
50
- throw new Error (
51
- 'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported'
52
- ) ;
53
-
54
- return ( path ) => path . startsWith ( i ) ;
55
- } ) ;
35
+ const ignored = createIgnored ( filePathsToIgnore ) ;
56
36
const isIgnored = ( path : string ) => {
57
37
path = path . slice ( offset ) ;
58
38
for ( const i of ignored ) {
@@ -84,6 +64,30 @@ async function openAllDocuments(
84
64
}
85
65
}
86
66
67
+ function createIgnored ( filePathsToIgnore : string [ ] ) : Array < ( path : string ) => boolean > {
68
+ return filePathsToIgnore . map ( ( i ) => {
69
+ if ( i . endsWith ( '**' ) ) i = i . slice ( 0 , - 2 ) ;
70
+
71
+ if ( i . startsWith ( '**' ) ) {
72
+ i = i . slice ( 2 ) ;
73
+
74
+ if ( i . includes ( '*' ) )
75
+ throw new Error (
76
+ 'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported'
77
+ ) ;
78
+
79
+ return ( path ) => path . includes ( i ) ;
80
+ }
81
+
82
+ if ( i . includes ( '*' ) )
83
+ throw new Error (
84
+ 'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported'
85
+ ) ;
86
+
87
+ return ( path ) => path . startsWith ( i ) ;
88
+ } ) ;
89
+ }
90
+
87
91
async function getDiagnostics (
88
92
workspaceUri : URI ,
89
93
writer : Writer ,
@@ -149,10 +153,32 @@ class DiagnosticsWatcher {
149
153
filePathsToIgnore : string [ ] ,
150
154
ignoreInitialAdd : boolean
151
155
) {
152
- watch ( `${ workspaceUri . fsPath } /**/*.{svelte,d.ts,ts,js,jsx,tsx,mjs,cjs,mts,cts}` , {
153
- ignored : [ 'node_modules' , 'vite.config.{js,ts}.timestamp-*' ]
154
- . concat ( filePathsToIgnore )
155
- . map ( ( ignore ) => path . join ( workspaceUri . fsPath , ignore ) ) ,
156
+ const fileEnding = / \. ( s v e l t e | d \. t s | t s | j s | j s x | t s x | m j s | c j s | m t s | c t s ) $ / ;
157
+ const viteConfigRegex = / v i t e \. c o n f i g \. ( j s | t s ) \. t i m e s t a m p - / ;
158
+ const userIgnored = createIgnored ( filePathsToIgnore ) ;
159
+ const offset = workspaceUri . fsPath . length + 1 ;
160
+
161
+ watch ( workspaceUri . fsPath , {
162
+ ignored : ( path , stats ) => {
163
+ if (
164
+ path . includes ( 'node_modules' ) ||
165
+ path . includes ( '.git' ) ||
166
+ ( stats ?. isFile ( ) && ( ! fileEnding . test ( path ) || viteConfigRegex . test ( path ) ) )
167
+ ) {
168
+ return true ;
169
+ }
170
+
171
+ if ( userIgnored . length !== 0 ) {
172
+ path = path . slice ( offset ) ;
173
+ for ( const i of userIgnored ) {
174
+ if ( i ( path ) ) {
175
+ return true ;
176
+ }
177
+ }
178
+ }
179
+
180
+ return false ;
181
+ } ,
156
182
ignoreInitial : ignoreInitialAdd
157
183
} )
158
184
. on ( 'add' , ( path ) => this . updateDocument ( path , true ) )
0 commit comments