@@ -177,7 +177,7 @@ export class TW {
177
177
isDefaultVersion : false ,
178
178
} ,
179
179
}
180
- } ,
180
+ }
181
181
)
182
182
} else {
183
183
console . log ( "Searching for Tailwind CSS projects in the workspace's folders." )
@@ -224,9 +224,10 @@ export class TW {
224
224
console . log ( `[Global] Creating projects: ${ JSON . stringify ( workspaceDescription ) } ` )
225
225
226
226
const onDidChangeWatchedFiles = async (
227
- changes : Array < { file : string ; type : FileChangeType } > ,
227
+ changes : Array < { file : string ; type : FileChangeType } >
228
228
) : Promise < void > => {
229
229
let needsRestart = false
230
+ let needsSoftRestart = false
230
231
231
232
changeLoop: for ( let change of changes ) {
232
233
let normalizedFilename = normalizePath ( change . file )
@@ -242,12 +243,10 @@ export class TW {
242
243
for ( let [ , project ] of this . projects ) {
243
244
let twVersion = require ( 'tailwindcss/package.json' ) . version
244
245
try {
245
- let v = require (
246
- resolveFrom (
247
- path . dirname ( project . projectConfig . configPath ) ,
248
- 'tailwindcss/package.json' ,
249
- ) ,
250
- ) . version
246
+ let v = require ( resolveFrom (
247
+ path . dirname ( project . projectConfig . configPath ) ,
248
+ 'tailwindcss/package.json'
249
+ ) ) . version
251
250
if ( typeof v === 'string' ) {
252
251
twVersion = v
253
252
}
@@ -259,6 +258,20 @@ export class TW {
259
258
}
260
259
}
261
260
261
+ for ( let [ , project ] of this . projects ) {
262
+ if ( ! project . state . v4 ) continue
263
+
264
+ let reloadableFiles = [
265
+ project . projectConfig . configPath ,
266
+ ...project . projectConfig . config . entries . map ( ( entry ) => entry . path ) ,
267
+ ]
268
+
269
+ if ( ! changeAffectsFile ( normalizedFilename , reloadableFiles ) ) continue
270
+
271
+ needsSoftRestart = true
272
+ break changeLoop
273
+ }
274
+
262
275
let isCssFile = minimatch ( normalizedFilename , `**/${ CSS_GLOB } ` , {
263
276
dot : true ,
264
277
} )
@@ -300,6 +313,15 @@ export class TW {
300
313
return
301
314
}
302
315
316
+ if ( needsSoftRestart ) {
317
+ try {
318
+ await this . softRestart ( )
319
+ } catch {
320
+ this . restart ( )
321
+ }
322
+ return
323
+ }
324
+
303
325
for ( let [ , project ] of this . projects ) {
304
326
project . onFileEvents ( changes )
305
327
}
@@ -316,11 +338,11 @@ export class TW {
316
338
. filter (
317
339
( change , changeIndex , changes ) =>
318
340
changes . findIndex ( ( c ) => c . file === change . file && c . type === change . type ) ===
319
- changeIndex ,
341
+ changeIndex
320
342
)
321
343
322
344
await onDidChangeWatchedFiles ( normalizedChanges )
323
- } ) ,
345
+ } )
324
346
)
325
347
326
348
let disposable = await this . connection . client . register (
@@ -331,7 +353,7 @@ export class TW {
331
353
{ globPattern : `**/${ PACKAGE_LOCK_GLOB } ` } ,
332
354
{ globPattern : `**/${ CSS_GLOB } ` } ,
333
355
] ,
334
- } ,
356
+ }
335
357
)
336
358
337
359
this . disposables . push ( disposable )
@@ -360,14 +382,14 @@ export class TW {
360
382
base ,
361
383
( err , events ) => {
362
384
onDidChangeWatchedFiles (
363
- events . map ( ( event ) => ( { file : event . path , type : typeMap [ event . type ] } ) ) ,
385
+ events . map ( ( event ) => ( { file : event . path , type : typeMap [ event . type ] } ) )
364
386
)
365
387
} ,
366
388
{
367
389
ignore : ignore . map ( ( ignorePattern ) =>
368
- path . resolve ( base , ignorePattern . replace ( / ^ [ * / ] + / , '' ) . replace ( / [ * / ] + $ / , '' ) ) ,
390
+ path . resolve ( base , ignorePattern . replace ( / ^ [ * / ] + / , '' ) . replace ( / [ * / ] + $ / , '' ) )
369
391
) ,
370
- } ,
392
+ }
371
393
)
372
394
373
395
this . disposables . push ( {
@@ -388,7 +410,7 @@ export class TW {
388
410
stabilityThreshold : 100 ,
389
411
pollInterval : 20 ,
390
412
} ,
391
- } ,
413
+ }
392
414
)
393
415
394
416
await new Promise < void > ( ( resolve ) => {
@@ -399,17 +421,17 @@ export class TW {
399
421
. on ( 'add' , ( file ) =>
400
422
onDidChangeWatchedFiles ( [
401
423
{ file : path . resolve ( base , file ) , type : FileChangeType . Created } ,
402
- ] ) ,
424
+ ] )
403
425
)
404
426
. on ( 'change' , ( file ) =>
405
427
onDidChangeWatchedFiles ( [
406
428
{ file : path . resolve ( base , file ) , type : FileChangeType . Changed } ,
407
- ] ) ,
429
+ ] )
408
430
)
409
431
. on ( 'unlink' , ( file ) =>
410
432
onDidChangeWatchedFiles ( [
411
433
{ file : path . resolve ( base , file ) , type : FileChangeType . Deleted } ,
412
- ] ) ,
434
+ ] )
413
435
)
414
436
415
437
this . disposables . push ( {
@@ -433,9 +455,9 @@ export class TW {
433
455
projectConfig ,
434
456
this . initializeParams ,
435
457
this . watchPatterns ,
436
- configTailwindVersionMap . get ( projectConfig . configPath ) ,
437
- ) ,
438
- ) ,
458
+ configTailwindVersionMap . get ( projectConfig . configPath )
459
+ )
460
+ )
439
461
)
440
462
441
463
// init projects for documents that are _already_ open
@@ -465,19 +487,19 @@ export class TW {
465
487
for ( let [ , project ] of this . projects ) {
466
488
project . onUpdateSettings ( settings )
467
489
}
468
- } ) ,
490
+ } )
469
491
)
470
492
471
493
this . disposables . push (
472
494
this . connection . onShutdown ( ( ) => {
473
495
this . dispose ( )
474
- } ) ,
496
+ } )
475
497
)
476
498
477
499
this . disposables . push (
478
500
this . documentService . onDidChangeContent ( ( change ) => {
479
501
this . getProject ( change . document ) ?. provideDiagnostics ( change . document )
480
- } ) ,
502
+ } )
481
503
)
482
504
483
505
this . disposables . push (
@@ -487,7 +509,7 @@ export class TW {
487
509
project . enable ( )
488
510
project . tryInit ( )
489
511
}
490
- } ) ,
512
+ } )
491
513
)
492
514
}
493
515
@@ -501,7 +523,7 @@ export class TW {
501
523
projectConfig : ProjectConfig ,
502
524
params : InitializeParams ,
503
525
watchPatterns : ( patterns : string [ ] ) => void ,
504
- tailwindVersion : string ,
526
+ tailwindVersion : string
505
527
) : Promise < void > {
506
528
let key = String ( this . projectCounter ++ )
507
529
const project = await createProjectService (
@@ -524,7 +546,7 @@ export class TW {
524
546
( ) => this . refreshDiagnostics ( ) ,
525
547
( patterns : string [ ] ) => watchPatterns ( patterns ) ,
526
548
tailwindVersion ,
527
- this . settingsCache . get ,
549
+ this . settingsCache . get
528
550
)
529
551
this . projects . set ( key , project )
530
552
@@ -571,11 +593,11 @@ export class TW {
571
593
572
594
private onRequest (
573
595
method : '@/tailwindCSS/sortSelection' ,
574
- params : { uri : string ; classLists : string [ ] } ,
596
+ params : { uri : string ; classLists : string [ ] }
575
597
) : { error : string } | { classLists : string [ ] }
576
598
private onRequest (
577
599
method : '@/tailwindCSS/getProject' ,
578
- params : { uri : string } ,
600
+ params : { uri : string }
579
601
) : { version : string } | null
580
602
private onRequest ( method : string , params : any ) : any {
581
603
if ( method === '@/tailwindCSS/sortSelection' ) {
@@ -776,6 +798,18 @@ export class TW {
776
798
this . initPromise = undefined
777
799
this . init ( )
778
800
}
801
+
802
+ async softRestart ( ) : Promise < void > {
803
+ // Tell each v4 project to reload it's design system
804
+ for ( let [ , project ] of this . projects ) {
805
+ if ( ! project . state . v4 ) continue
806
+
807
+ // "soft"-reload the project
808
+ try {
809
+ await project . reload ( )
810
+ } catch { }
811
+ }
812
+ }
779
813
}
780
814
781
815
function supportsDynamicRegistration ( params : InitializeParams ) : boolean {
0 commit comments