@@ -246,6 +246,15 @@ export async function activate(context: ExtensionContext) {
246246 // e.g. "plaintext" already exists but you change it from "html" to "css"
247247 context . subscriptions . push (
248248 Workspace . onDidChangeConfiguration ( ( event ) => {
249+ let toReboot = new Set < WorkspaceFolder > ( )
250+
251+ Workspace . textDocuments . forEach ( ( document ) => {
252+ let folder = Workspace . getWorkspaceFolder ( document . uri )
253+ if ( ! folder ) return
254+ if ( event . affectsConfiguration ( 'tailwindCSS.experimental.configFile' , folder ) ) {
255+ toReboot . add ( folder )
256+ }
257+ } )
249258 ; [ ...clients ] . forEach ( ( [ key , client ] ) => {
250259 const folder = Workspace . getWorkspaceFolder ( Uri . parse ( key ) )
251260 let reboot = false
@@ -267,11 +276,15 @@ export async function activate(context: ExtensionContext) {
267276 }
268277
269278 if ( reboot && client ) {
270- clients . delete ( folder . uri . toString ( ) )
271- client . stop ( )
272- bootWorkspaceClient ( folder )
279+ toReboot . add ( folder )
273280 }
274281 } )
282+
283+ for ( let folder of toReboot ) {
284+ clients . get ( folder . uri . toString ( ) ) ?. stop ( )
285+ clients . delete ( folder . uri . toString ( ) )
286+ bootClientForFolderIfNeeded ( folder )
287+ }
275288 } )
276289 )
277290
@@ -568,6 +581,8 @@ export async function activate(context: ExtensionContext) {
568581 } ,
569582 initializationOptions : {
570583 userLanguages : getUserLanguages ( folder ) ,
584+ workspaceFile :
585+ Workspace . workspaceFile ?. scheme === 'file' ? Workspace . workspaceFile . fsPath : undefined ,
571586 } ,
572587 synchronize : {
573588 configurationSection : [ 'files' , 'editor' , 'tailwindCSS' ] ,
@@ -602,29 +617,12 @@ export async function activate(context: ExtensionContext) {
602617 clients . set ( folder . uri . toString ( ) , client )
603618 }
604619
605- async function didOpenTextDocument ( document : TextDocument ) : Promise < void > {
606- if ( document . languageId === 'tailwindcss' ) {
607- bootCssServer ( )
608- }
609-
610- // We are only interested in language mode text
611- if ( document . uri . scheme !== 'file' ) {
612- return
613- }
614-
615- let uri = document . uri
616- let folder = Workspace . getWorkspaceFolder ( uri )
617- // Files outside a folder can't be handled. This might depend on the language.
618- // Single file languages like JSON might handle files outside the workspace folders.
619- if ( ! folder ) {
620+ async function bootClientForFolderIfNeeded ( folder : WorkspaceFolder ) : Promise < void > {
621+ let settings = Workspace . getConfiguration ( 'tailwindCSS' , folder )
622+ if ( settings . get ( 'experimental.configFile' ) !== null ) {
623+ bootWorkspaceClient ( folder )
620624 return
621625 }
622- // If we have nested workspace folders we only start a server on the outer most workspace folder.
623- folder = getOuterMostWorkspaceFolder ( folder )
624-
625- if ( searchedFolders . has ( folder . uri . toString ( ) ) ) return
626-
627- searchedFolders . add ( folder . uri . toString ( ) )
628626
629627 let [ configFile ] = await Workspace . findFiles (
630628 new RelativePattern ( folder , `**/${ CONFIG_GLOB } ` ) ,
@@ -650,6 +648,35 @@ export async function activate(context: ExtensionContext) {
650648 }
651649 }
652650
651+ async function didOpenTextDocument ( document : TextDocument ) : Promise < void > {
652+ if ( document . languageId === 'tailwindcss' ) {
653+ bootCssServer ( )
654+ }
655+
656+ // We are only interested in language mode text
657+ if ( document . uri . scheme !== 'file' ) {
658+ return
659+ }
660+
661+ let uri = document . uri
662+ let folder = Workspace . getWorkspaceFolder ( uri )
663+ // Files outside a folder can't be handled. This might depend on the language.
664+ // Single file languages like JSON might handle files outside the workspace folders.
665+ if ( ! folder ) {
666+ return
667+ }
668+ // If we have nested workspace folders we only start a server on the outer most workspace folder.
669+ folder = getOuterMostWorkspaceFolder ( folder )
670+
671+ if ( searchedFolders . has ( folder . uri . toString ( ) ) ) {
672+ return
673+ }
674+
675+ searchedFolders . add ( folder . uri . toString ( ) )
676+
677+ await bootClientForFolderIfNeeded ( folder )
678+ }
679+
653680 context . subscriptions . push ( Workspace . onDidOpenTextDocument ( didOpenTextDocument ) )
654681 Workspace . textDocuments . forEach ( didOpenTextDocument )
655682 context . subscriptions . push (
0 commit comments