@@ -177,6 +177,7 @@ function firstOptional<T>(...options: Array<() => T>): T | undefined {
177
177
}
178
178
179
179
interface ProjectService {
180
+ projectConfig : ProjectConfig
180
181
enabled : ( ) => boolean
181
182
enable : ( ) => void
182
183
documentSelector : ( ) => Array < DocumentSelector >
@@ -361,6 +362,7 @@ function getWatchPatternsForFile(file: string): string[] {
361
362
}
362
363
363
364
async function createProjectService (
365
+ projectKey : string ,
364
366
projectConfig : ProjectConfig ,
365
367
connection : Connection ,
366
368
params : InitializeParams ,
@@ -1064,6 +1066,7 @@ async function createProjectService(
1064
1066
}
1065
1067
1066
1068
return {
1069
+ projectConfig,
1067
1070
enabled ( ) {
1068
1071
return enabled
1069
1072
} ,
@@ -1117,7 +1120,7 @@ async function createProjectService(
1117
1120
isIncomplete : result . isIncomplete ,
1118
1121
items : result . items . map ( ( item ) => ( {
1119
1122
...item ,
1120
- data : { projectKey : JSON . stringify ( projectConfig ) , originalData : item . data } ,
1123
+ data : { projectKey, originalData : item . data } ,
1121
1124
} ) ) ,
1122
1125
}
1123
1126
} , null )
@@ -1561,6 +1564,7 @@ class TW {
1561
1564
private lspHandlersAdded = false
1562
1565
private workspaces : Map < string , { name : string ; workspaceFsPath : string } >
1563
1566
private projects : Map < string , ProjectService >
1567
+ private projectCounter : number
1564
1568
private documentService : DocumentService
1565
1569
public initializeParams : InitializeParams
1566
1570
private registrations : Promise < BulkUnregistration >
@@ -1572,6 +1576,7 @@ class TW {
1572
1576
this . documentService = new DocumentService ( this . connection )
1573
1577
this . workspaces = new Map ( )
1574
1578
this . projects = new Map ( )
1579
+ this . projectCounter = 0
1575
1580
}
1576
1581
1577
1582
async init ( ) : Promise < void > {
@@ -1754,19 +1759,18 @@ class TW {
1754
1759
1755
1760
let isPackageFile = minimatch ( normalizedFilename , `**/${ PACKAGE_LOCK_GLOB } ` , { dot : true } )
1756
1761
if ( isPackageFile ) {
1757
- for ( let [ key ] of this . projects ) {
1758
- let projectConfig = JSON . parse ( key ) as ProjectConfig
1762
+ for ( let [ , project ] of this . projects ) {
1759
1763
let twVersion = require ( 'tailwindcss/package.json' ) . version
1760
1764
try {
1761
1765
let v = require ( resolveFrom (
1762
- path . dirname ( projectConfig . configPath ) ,
1766
+ path . dirname ( project . projectConfig . configPath ) ,
1763
1767
'tailwindcss/package.json'
1764
1768
) ) . version
1765
1769
if ( typeof v === 'string' ) {
1766
1770
twVersion = v
1767
1771
}
1768
1772
} catch { }
1769
- if ( configTailwindVersionMap . get ( projectConfig . configPath ) !== twVersion ) {
1773
+ if ( configTailwindVersionMap . get ( project . projectConfig . configPath ) !== twVersion ) {
1770
1774
needsRestart = true
1771
1775
break changeLoop
1772
1776
}
@@ -1798,11 +1802,10 @@ class TW {
1798
1802
break
1799
1803
}
1800
1804
1801
- for ( let [ key ] of this . projects ) {
1802
- let projectConfig = JSON . parse ( key ) as ProjectConfig
1805
+ for ( let [ , project ] of this . projects ) {
1803
1806
if (
1804
1807
change . type === FileChangeType . Deleted &&
1805
- changeAffectsFile ( normalizedFilename , [ projectConfig . configPath ] )
1808
+ changeAffectsFile ( normalizedFilename , [ project . projectConfig . configPath ] )
1806
1809
) {
1807
1810
needsRestart = true
1808
1811
break changeLoop
@@ -2017,31 +2020,29 @@ class TW {
2017
2020
watchPatterns : ( patterns : string [ ] ) => void ,
2018
2021
tailwindVersion : string
2019
2022
) : Promise < void > {
2020
- let key = JSON . stringify ( projectConfig )
2021
-
2022
- if ( ! this . projects . has ( key ) ) {
2023
- const project = await createProjectService (
2024
- projectConfig ,
2025
- this . connection ,
2026
- params ,
2027
- this . documentService ,
2028
- ( ) => this . updateCapabilities ( ) ,
2029
- ( ) => {
2030
- for ( let document of this . documentService . getAllDocuments ( ) ) {
2031
- let project = this . getProject ( document )
2032
- if ( project && ! project . enabled ( ) ) {
2033
- project . enable ( )
2034
- project . tryInit ( )
2035
- break
2036
- }
2023
+ let key = String ( this . projectCounter ++ )
2024
+ const project = await createProjectService (
2025
+ key ,
2026
+ projectConfig ,
2027
+ this . connection ,
2028
+ params ,
2029
+ this . documentService ,
2030
+ ( ) => this . updateCapabilities ( ) ,
2031
+ ( ) => {
2032
+ for ( let document of this . documentService . getAllDocuments ( ) ) {
2033
+ let project = this . getProject ( document )
2034
+ if ( project && ! project . enabled ( ) ) {
2035
+ project . enable ( )
2036
+ project . tryInit ( )
2037
+ break
2037
2038
}
2038
- } ,
2039
- ( ) => this . refreshDiagnostics ( ) ,
2040
- ( patterns : string [ ] ) => watchPatterns ( patterns ) ,
2041
- tailwindVersion
2042
- )
2043
- this . projects . set ( key , project )
2044
- }
2039
+ }
2040
+ } ,
2041
+ ( ) => this . refreshDiagnostics ( ) ,
2042
+ ( patterns : string [ ] ) => watchPatterns ( patterns ) ,
2043
+ tailwindVersion
2044
+ )
2045
+ this . projects . set ( key , project )
2045
2046
}
2046
2047
2047
2048
private refreshDiagnostics ( ) {
@@ -2104,9 +2105,8 @@ class TW {
2104
2105
let matchedProject : ProjectService
2105
2106
let matchedPriority : number = Infinity
2106
2107
2107
- for ( let [ key , project ] of this . projects ) {
2108
- let projectConfig = JSON . parse ( key ) as ProjectConfig
2109
- if ( projectConfig . configPath ) {
2108
+ for ( let [ , project ] of this . projects ) {
2109
+ if ( project . projectConfig . configPath ) {
2110
2110
let documentSelector = project
2111
2111
. documentSelector ( )
2112
2112
. concat ( )
0 commit comments