@@ -142,7 +142,35 @@ async function createProjectService(
142
142
params : InitializeParams ,
143
143
documentService : DocumentService
144
144
) : Promise < ProjectService > {
145
- const state : State = { enabled : false }
145
+ const state : State = {
146
+ enabled : false ,
147
+ editor : {
148
+ connection,
149
+ globalSettings : params . initializationOptions . configuration as Settings ,
150
+ userLanguages : { } ,
151
+ // TODO
152
+ capabilities : {
153
+ configuration : true ,
154
+ diagnosticRelatedInformation : true ,
155
+ } ,
156
+ documents : documentService . documents ,
157
+ getConfiguration : async ( uri ?: string ) => {
158
+ if ( documentSettingsCache . has ( uri ) ) {
159
+ return documentSettingsCache . get ( uri )
160
+ }
161
+ let config = await connection . workspace . getConfiguration ( {
162
+ section : 'tailwindCSS' ,
163
+ scopeUri : uri ,
164
+ } )
165
+ documentSettingsCache . set ( uri , config )
166
+ return config
167
+ } ,
168
+ getDocumentSymbols : ( uri : string ) => {
169
+ return connection . sendRequest ( '@/tailwindCSS/getDocumentSymbols' , { uri } )
170
+ } ,
171
+ } ,
172
+ }
173
+
146
174
const documentSettingsCache : Map < string , Settings > = new Map ( )
147
175
let registrations : Promise < BulkUnregistration >
148
176
@@ -255,33 +283,6 @@ async function createProjectService(
255
283
async function init ( ) {
256
284
clearRequireCache ( )
257
285
258
- // TODO
259
- state . editor = {
260
- connection,
261
- globalSettings : params . initializationOptions . configuration as Settings ,
262
- userLanguages : { } ,
263
- // TODO
264
- capabilities : {
265
- configuration : true ,
266
- diagnosticRelatedInformation : true ,
267
- } ,
268
- documents : documentService . documents ,
269
- getConfiguration : async ( uri ?: string ) => {
270
- if ( documentSettingsCache . has ( uri ) ) {
271
- return documentSettingsCache . get ( uri )
272
- }
273
- let config = await connection . workspace . getConfiguration ( {
274
- section : 'tailwindCSS' ,
275
- scopeUri : uri ,
276
- } )
277
- documentSettingsCache . set ( uri , config )
278
- return config
279
- } ,
280
- getDocumentSymbols : ( uri : string ) => {
281
- return connection . sendRequest ( '@/tailwindCSS/getDocumentSymbols' , { uri } )
282
- } ,
283
- }
284
-
285
286
let [ configPath ] = (
286
287
await glob ( [ `**/${ CONFIG_FILE_GLOB } ` ] , {
287
288
cwd : folder ,
@@ -325,6 +326,7 @@ async function createProjectService(
325
326
setPnpApi ( pnpApi )
326
327
}
327
328
329
+ const configModified = fs . statSync ( configPath ) . mtimeMs
328
330
const configDir = path . dirname ( configPath )
329
331
let tailwindcss : any
330
332
let postcss : any
@@ -356,6 +358,16 @@ async function createProjectService(
356
358
tailwindcssVersion = tailwindcssPkg . version
357
359
console . log ( `Loaded tailwindcss v${ tailwindcssVersion } : ${ tailwindDir } ` )
358
360
361
+ if (
362
+ state . enabled &&
363
+ postcssVersion === state . modules . postcss . version &&
364
+ tailwindcssVersion === state . modules . tailwindcss . version &&
365
+ configPath === state . configPath &&
366
+ configModified === state . configModified
367
+ ) {
368
+ return
369
+ }
370
+
359
371
try {
360
372
resolveConfigFn = __non_webpack_require__ ( resolveFrom ( tailwindDir , './resolveConfig.js' ) )
361
373
} catch ( _ ) {
@@ -432,6 +444,7 @@ async function createProjectService(
432
444
}
433
445
434
446
state . configPath = configPath
447
+ state . configModified = configModified
435
448
state . modules = {
436
449
tailwindcss : { version : tailwindcssVersion , module : tailwindcss } ,
437
450
postcss : { version : postcssVersion , module : postcss } ,
0 commit comments