@@ -56,7 +56,7 @@ import { getModuleDependencies } from './util/getModuleDependencies'
56
56
import assert from 'assert'
57
57
// import postcssLoadConfig from 'postcss-load-config'
58
58
import { bigSign } from '@tailwindcss/language-service/src/util/jit'
59
- import { getColor } from '@tailwindcss/language-service/src/util/color'
59
+ import { getColor , getColors } from '@tailwindcss/language-service/src/util/color'
60
60
import * as culori from 'culori'
61
61
import namedColors from 'color-name'
62
62
import tailwindPlugins from './lib/plugins'
@@ -84,7 +84,7 @@ const colorNames = Object.keys(namedColors)
84
84
85
85
function getConfigId ( configPath : string , configDependencies : string [ ] ) : string {
86
86
return JSON . stringify (
87
- [ configPath , ...configDependencies ] . map ( ( file ) => [ file , fs . statSync ( file ) . mtimeMs ] )
87
+ [ configPath , ...configDependencies ] . map ( ( file ) => [ file , fs . statSync ( file ) . mtimeMs ] ) ,
88
88
)
89
89
}
90
90
@@ -180,7 +180,7 @@ export async function createProjectService(
180
180
refreshDiagnostics : ( ) => void ,
181
181
watchPatterns : ( patterns : string [ ] ) => void ,
182
182
initialTailwindVersion : string ,
183
- getConfiguration : ( uri ?: string ) => Promise < Settings >
183
+ getConfiguration : ( uri ?: string ) => Promise < Settings > ,
184
184
) : Promise < ProjectService > {
185
185
let enabled = false
186
186
const folder = projectConfig . folder
@@ -228,11 +228,11 @@ export async function createProjectService(
228
228
return ( await isExcluded (
229
229
state ,
230
230
document ,
231
- path . join ( directory , dirent . name , isDirectory ? '/' : '' )
231
+ path . join ( directory , dirent . name , isDirectory ? '/' : '' ) ,
232
232
) )
233
233
? null
234
234
: [ dirent . name , { isDirectory } ]
235
- } )
235
+ } ) ,
236
236
)
237
237
return result . filter ( ( item ) => item !== null )
238
238
} catch {
@@ -255,7 +255,7 @@ export async function createProjectService(
255
255
256
256
function log ( ...args : string [ ] ) : void {
257
257
console . log (
258
- `[${ path . relative ( projectConfig . folder , projectConfig . configPath ) } ] ${ args . join ( ' ' ) } `
258
+ `[${ path . relative ( projectConfig . folder , projectConfig . configPath ) } ] ${ args . join ( ' ' ) } ` ,
259
259
)
260
260
}
261
261
@@ -280,12 +280,12 @@ export async function createProjectService(
280
280
) {
281
281
documentSelector = [
282
282
...documentSelector . filter (
283
- ( { priority } ) => priority !== DocumentSelectorPriority . CONTENT_FILE
283
+ ( { priority } ) => priority !== DocumentSelectorPriority . CONTENT_FILE ,
284
284
) ,
285
285
...getContentDocumentSelectorFromConfigFile (
286
286
projectConfig . configPath ,
287
287
initialTailwindVersion ,
288
- projectConfig . folder
288
+ projectConfig . folder ,
289
289
) ,
290
290
]
291
291
@@ -390,7 +390,7 @@ export async function createProjectService(
390
390
return findUp . stop
391
391
}
392
392
} ,
393
- { cwd : folder }
393
+ { cwd : folder } ,
394
394
)
395
395
396
396
if ( pnpPath ) {
@@ -498,10 +498,9 @@ export async function createProjectService(
498
498
resolveConfigFn = ( config ) => resolveConfig ( [ config , defaultConfig ] )
499
499
} catch ( _ ) {
500
500
try {
501
- const resolveConfig = require ( resolveFrom (
502
- tailwindDir ,
503
- './lib/util/mergeConfigWithDefaults.js'
504
- ) )
501
+ const resolveConfig = require (
502
+ resolveFrom ( tailwindDir , './lib/util/mergeConfigWithDefaults.js' ) ,
503
+ )
505
504
const defaultConfig = require ( resolveFrom ( tailwindDir , './defaultConfig.js' ) )
506
505
resolveConfigFn = ( config ) => resolveConfig . default ( config , defaultConfig ( ) )
507
506
} catch ( _ ) {
@@ -522,7 +521,7 @@ export async function createProjectService(
522
521
523
522
if ( semver . gte ( tailwindcssVersion , '1.99.0' ) ) {
524
523
applyComplexClasses = firstOptional ( ( ) =>
525
- require ( resolveFrom ( tailwindDir , './lib/lib/substituteClassApplyAtRules' ) )
524
+ require ( resolveFrom ( tailwindDir , './lib/lib/substituteClassApplyAtRules' ) ) ,
526
525
)
527
526
} else if ( semver . gte ( tailwindcssVersion , '1.7.0' ) ) {
528
527
applyComplexClasses = require ( resolveFrom ( tailwindDir , './lib/flagged/applyComplexClasses' ) )
@@ -541,43 +540,39 @@ export async function createProjectService(
541
540
try {
542
541
let createContext = first (
543
542
( ) => {
544
- let createContextFn = require ( resolveFrom (
545
- configDir ,
546
- 'tailwindcss/lib/lib/setupContextUtils'
547
- ) ) . createContext
543
+ let createContextFn = require (
544
+ resolveFrom ( configDir , 'tailwindcss/lib/lib/setupContextUtils' ) ,
545
+ ) . createContext
548
546
assert . strictEqual ( typeof createContextFn , 'function' )
549
547
return ( state ) => createContextFn ( state . config )
550
548
} ,
551
549
( ) => {
552
- let createContextFn = require ( resolveFrom (
553
- configDir ,
554
- 'tailwindcss/lib/jit/lib/setupContextUtils'
555
- ) ) . createContext
550
+ let createContextFn = require (
551
+ resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/setupContextUtils' ) ,
552
+ ) . createContext
556
553
assert . strictEqual ( typeof createContextFn , 'function' )
557
554
return ( state ) => createContextFn ( state . config )
558
555
} ,
559
556
// TODO: the next two are canary releases only so can probably be removed
560
557
( ) => {
561
- let setupTrackingContext = require ( resolveFrom (
562
- configDir ,
563
- 'tailwindcss/lib/jit/lib/setupTrackingContext'
564
- ) ) . default
558
+ let setupTrackingContext = require (
559
+ resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/setupTrackingContext' ) ,
560
+ ) . default
565
561
assert . strictEqual ( typeof setupTrackingContext , 'function' )
566
562
return ( state ) =>
567
563
setupTrackingContext (
568
564
state . configPath ,
569
565
tailwindDirectives ,
570
- registerDependency
566
+ registerDependency ,
571
567
) ( result , root )
572
568
} ,
573
569
( ) => {
574
- let setupContext = require ( resolveFrom (
575
- configDir ,
576
- 'tailwindcss/lib/jit/lib/setupContext'
577
- ) ) . default
570
+ let setupContext = require (
571
+ resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/setupContext' ) ,
572
+ ) . default
578
573
assert . strictEqual ( typeof setupContext , 'function' )
579
574
return ( state ) => setupContext ( state . configPath , tailwindDirectives ) ( result , root )
580
- }
575
+ } ,
581
576
)
582
577
583
578
jitModules = {
@@ -587,7 +582,7 @@ export async function createProjectService(
587
582
require ( resolveFrom ( configDir , 'tailwindcss/lib/lib/generateRules' ) ) . generateRules ,
588
583
( ) =>
589
584
require ( resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/generateRules' ) )
590
- . generateRules
585
+ . generateRules ,
591
586
) ,
592
587
} ,
593
588
createContext : {
@@ -599,14 +594,14 @@ export async function createProjectService(
599
594
require ( resolveFrom ( configDir , 'tailwindcss/lib/lib/expandApplyAtRules' ) ) . default ,
600
595
( ) =>
601
596
require ( resolveFrom ( configDir , 'tailwindcss/lib/jit/lib/expandApplyAtRules' ) )
602
- . default
597
+ . default ,
603
598
) ,
604
599
} ,
605
600
evaluateTailwindFunctions : {
606
601
module : firstOptional (
607
602
( ) =>
608
603
require ( resolveFrom ( configDir , 'tailwindcss/lib/lib/evaluateTailwindFunctions' ) )
609
- . default
604
+ . default ,
610
605
) ,
611
606
} ,
612
607
}
@@ -670,7 +665,7 @@ export async function createProjectService(
670
665
671
666
try {
672
667
state . corePlugins = Object . keys (
673
- require ( resolveFrom ( path . dirname ( state . configPath ) , 'tailwindcss/lib/plugins/index.js' ) )
668
+ require ( resolveFrom ( path . dirname ( state . configPath ) , 'tailwindcss/lib/plugins/index.js' ) ) ,
674
669
)
675
670
} catch ( _ ) { }
676
671
@@ -693,7 +688,7 @@ export async function createProjectService(
693
688
rule . before (
694
689
postcss . comment ( {
695
690
text : '__ORIGINAL_SELECTOR__:' + rule . selector ,
696
- } )
691
+ } ) ,
697
692
)
698
693
rule . selector = newSelector
699
694
}
@@ -738,7 +733,7 @@ export async function createProjectService(
738
733
let designSystem = await loadDesignSystem (
739
734
state . modules . tailwindcss . module ,
740
735
state . configPath ,
741
- css
736
+ css ,
742
737
)
743
738
744
739
state . designSystem = designSystem
@@ -851,13 +846,13 @@ export async function createProjectService(
851
846
if ( ! projectConfig . isUserConfigured ) {
852
847
documentSelector = [
853
848
...documentSelector . filter (
854
- ( { priority } ) => priority !== DocumentSelectorPriority . CONTENT_FILE
849
+ ( { priority } ) => priority !== DocumentSelectorPriority . CONTENT_FILE ,
855
850
) ,
856
851
...getContentDocumentSelectorFromConfigFile (
857
852
state . configPath ,
858
853
tailwindcss . version ,
859
854
projectConfig . folder ,
860
- originalConfig
855
+ originalConfig ,
861
856
) ,
862
857
]
863
858
}
@@ -873,15 +868,23 @@ export async function createProjectService(
873
868
delete state . config . blocklist
874
869
875
870
if ( state . v4 ) {
876
- state . classList = state . designSystem . getClassList ( ) . map ( ( className ) => {
877
- return [
878
- className [ 0 ] ,
879
- {
880
- ...className [ 1 ] ,
881
- color : getColor ( state , className [ 0 ] ) ,
882
- } ,
883
- ]
884
- } )
871
+ let classList = state . designSystem . getClassList ( )
872
+ let colors = await getColors (
873
+ state ,
874
+ classList . map ( ( entry ) => entry [ 0 ] ) ,
875
+ )
876
+
877
+ state . classList = await Promise . all (
878
+ classList . map ( ( className , idx ) => {
879
+ return [
880
+ className [ 0 ] ,
881
+ {
882
+ ...className [ 1 ] ,
883
+ color : colors [ idx ] ,
884
+ } ,
885
+ ]
886
+ } ) ,
887
+ )
885
888
} else if ( state . jit ) {
886
889
state . jitContext = state . modules . jit . createContext . module ( state )
887
890
state . jitContext . tailwindConfig . separator = state . config . separator
@@ -931,7 +934,7 @@ export async function createProjectService(
931
934
. join ( '\n' ) ,
932
935
{
933
936
from : undefined ,
934
- }
937
+ } ,
935
938
)
936
939
} catch ( error ) {
937
940
throw error
@@ -947,8 +950,8 @@ export async function createProjectService(
947
950
// chokidarWatcher?.add(state.dependencies)
948
951
watchPatterns (
949
952
( state . dependencies ?? [ ] ) . flatMap ( ( dep ) =>
950
- getWatchPatternsForFile ( dep , projectConfig . folder )
951
- )
953
+ getWatchPatternsForFile ( dep , projectConfig . folder ) ,
954
+ ) ,
952
955
)
953
956
954
957
state . configId = getConfigId ( state . configPath , state . dependencies )
@@ -1043,15 +1046,15 @@ export async function createProjectService(
1043
1046
let document = documentService . getDocument ( params . textDocument . uri )
1044
1047
if ( ! document ) return null
1045
1048
return getDocumentLinks ( state , document , ( linkPath ) =>
1046
- URI . file ( path . resolve ( path . dirname ( URI . parse ( document . uri ) . fsPath ) , linkPath ) ) . toString ( )
1049
+ URI . file ( path . resolve ( path . dirname ( URI . parse ( document . uri ) . fsPath ) , linkPath ) ) . toString ( ) ,
1047
1050
)
1048
1051
} ,
1049
1052
provideDiagnostics : debounce (
1050
1053
( document : TextDocument ) => {
1051
1054
if ( ! state . enabled ) return
1052
1055
provideDiagnostics ( state , document )
1053
1056
} ,
1054
- params . initializationOptions ?. testMode ? 0 : 500
1057
+ params . initializationOptions ?. testMode ? 0 : 500 ,
1055
1058
) ,
1056
1059
provideDiagnosticsForce : ( document : TextDocument ) => {
1057
1060
if ( ! state . enabled ) return
@@ -1071,7 +1074,7 @@ export async function createProjectService(
1071
1074
if ( ! document ) return [ ]
1072
1075
let className = document . getText ( params . range )
1073
1076
let match = className . match (
1074
- new RegExp ( `-\\[(${ colorNames . join ( '|' ) } |(?:(?:#|rgba?\\(|hsla?\\())[^\\]]+)\\]$` , 'i' )
1077
+ new RegExp ( `-\\[(${ colorNames . join ( '|' ) } |(?:(?:#|rgba?\\(|hsla?\\())[^\\]]+)\\]$` , 'i' ) ,
1075
1078
)
1076
1079
// let match = className.match(/-\[((?:#|rgba?\(|hsla?\()[^\]]+)\]$/i)
1077
1080
if ( match === null ) return [ ]
@@ -1193,7 +1196,7 @@ type Plugin = SimplePlugin | WrappedPlugin
1193
1196
function runPlugin (
1194
1197
plugin : Plugin ,
1195
1198
state : State ,
1196
- apiOverrides : Record < string , Function > = { }
1199
+ apiOverrides : Record < string , Function > = { } ,
1197
1200
) : void {
1198
1201
let config = state . config
1199
1202
let postcss = state . modules . postcss . module
@@ -1266,7 +1269,7 @@ function getVariants(state: State): Array<Variant> {
1266
1269
}
1267
1270
1268
1271
let fns = ( Array . isArray ( variantFnOrFns [ 0 ] ) ? variantFnOrFns : [ variantFnOrFns ] ) . map (
1269
- ( [ _sort , fn ] ) => fn
1272
+ ( [ _sort , fn ] ) => fn ,
1270
1273
)
1271
1274
1272
1275
let placeholder = '__variant_placeholder__'
@@ -1324,7 +1327,7 @@ function getVariants(state: State): Array<Variant> {
1324
1327
definition = `@${ rule . name } ${ rule . params } `
1325
1328
}
1326
1329
} ,
1327
- } )
1330
+ } ) ,
1328
1331
)
1329
1332
1330
1333
if ( ! definition ) {
@@ -1355,7 +1358,7 @@ function getVariants(state: State): Array<Variant> {
1355
1358
return definitions
1356
1359
} ,
1357
1360
} )
1358
- }
1361
+ } ,
1359
1362
)
1360
1363
1361
1364
return result
@@ -1454,7 +1457,7 @@ async function getPlugins(config: any) {
1454
1457
return {
1455
1458
name : fnName ,
1456
1459
}
1457
- } )
1460
+ } ) ,
1458
1461
)
1459
1462
}
1460
1463
@@ -1470,7 +1473,7 @@ function getPackageRoot(cwd: string, rootDir: string) {
1470
1473
return findUp . stop
1471
1474
}
1472
1475
} ,
1473
- { cwd }
1476
+ { cwd } ,
1474
1477
)
1475
1478
return pkgJsonPath ? path . dirname ( pkgJsonPath ) : rootDir
1476
1479
} catch {
@@ -1482,7 +1485,7 @@ function getContentDocumentSelectorFromConfigFile(
1482
1485
configPath : string ,
1483
1486
tailwindVersion : string ,
1484
1487
rootDir : string ,
1485
- actualConfig ?: any
1488
+ actualConfig ?: any ,
1486
1489
) : DocumentSelector [ ] {
1487
1490
let config = actualConfig ?? require ( configPath )
1488
1491
let contentConfig : unknown = config . content ?. files ?? config . content
@@ -1501,7 +1504,7 @@ function getContentDocumentSelectorFromConfigFile(
1501
1504
. map ( ( item ) =>
1502
1505
item . startsWith ( '!' )
1503
1506
? `!${ path . resolve ( contentBase , item . slice ( 1 ) ) } `
1504
- : path . resolve ( contentBase , item )
1507
+ : path . resolve ( contentBase , item ) ,
1505
1508
)
1506
1509
. map ( ( item ) => ( {
1507
1510
pattern : normalizePath ( item ) ,
0 commit comments