@@ -226,38 +226,42 @@ export function activate(context: ExtensionContext) {
226226 provider ,
227227 ...triggerCharacters ) ) ;
228228
229- const glob = "**/*.css" ;
230- const folders = workspace . workspaceFolders ?. map ( folder => `${ folder . uri . fsPath } /${ glob } ` ) ;
231-
232- if ( folders ) {
233- const ignored = config . get < string [ ] > ( "ignoredFolders" , [ "**/node_modules/**" ] ) ;
234-
235- const watcher = watch ( folders , {
236- ignored,
237- ignoreInitial : false ,
238- ignorePermissionErrors : true ,
239- useFsEvents : true ,
240- followSymlinks : false
241- } )
242- . on ( "add" , key => provider . files . add ( key ) )
243- . on ( "unlink" , key => provider . files . delete ( key ) )
244- . on ( "change" , key => provider . cache . delete ( key ) ) ;
245-
246- const changes = workspace . onDidChangeWorkspaceFolders ( e => {
247- e . removed . forEach ( folder => {
248- watcher . unwatch ( `${ folder . uri . fsPath } /${ glob } ` ) ;
249-
250- for ( const key of provider . files ) {
251- if ( key . startsWith ( folder . uri . fsPath ) ) {
252- provider . files . delete ( key ) ;
229+ const watcherEnabled = config . get < boolean > ( "watcherEnabled" , true ) ;
230+
231+ if ( watcherEnabled ) {
232+ const glob = "**/*.css" ;
233+ const folders = workspace . workspaceFolders ?. map ( folder => `${ folder . uri . fsPath } /${ glob } ` ) ;
234+
235+ if ( folders ) {
236+ const ignored = config . get < string [ ] > ( "ignoredFolders" , [ "**/node_modules/**" ] ) ;
237+
238+ const watcher = watch ( folders , {
239+ ignored,
240+ ignoreInitial : false ,
241+ ignorePermissionErrors : true ,
242+ useFsEvents : true ,
243+ followSymlinks : false
244+ } )
245+ . on ( "add" , key => provider . files . add ( key ) )
246+ . on ( "unlink" , key => provider . files . delete ( key ) )
247+ . on ( "change" , key => provider . cache . delete ( key ) ) ;
248+
249+ const changes = workspace . onDidChangeWorkspaceFolders ( e => {
250+ e . removed . forEach ( folder => {
251+ watcher . unwatch ( `${ folder . uri . fsPath } /${ glob } ` ) ;
252+
253+ for ( const key of provider . files ) {
254+ if ( key . startsWith ( folder . uri . fsPath ) ) {
255+ provider . files . delete ( key ) ;
256+ }
253257 }
254- }
255- } ) ;
258+ } ) ;
256259
257- e . added . forEach ( folder => watcher . add ( `${ folder . uri . fsPath } /${ glob } ` ) ) ;
258- } ) ;
260+ e . added . forEach ( folder => watcher . add ( `${ folder . uri . fsPath } /${ glob } ` ) ) ;
261+ } ) ;
259262
260- context . subscriptions . push ( changes , { dispose : watcher . close } ) ;
263+ context . subscriptions . push ( changes , { dispose : watcher . close } ) ;
264+ }
261265 }
262266}
263267
0 commit comments