@@ -214,10 +214,10 @@ export async function activate(context: ExtensionContext) {
214
214
let configWatcher = Workspace . createFileSystemWatcher ( `**/${ CONFIG_GLOB } ` , false , true , true )
215
215
216
216
configWatcher . onDidCreate ( async ( uri ) => {
217
+ if ( currentClient ) return
217
218
let folder = Workspace . getWorkspaceFolder ( uri )
218
- if ( ! folder || isExcluded ( uri . fsPath , folder ) ) {
219
- return
220
- }
219
+ if ( ! folder || isExcluded ( uri . fsPath , folder ) ) return
220
+
221
221
await bootWorkspaceClient ( )
222
222
} )
223
223
@@ -226,13 +226,12 @@ export async function activate(context: ExtensionContext) {
226
226
let cssWatcher = Workspace . createFileSystemWatcher ( `**/${ CSS_GLOB } ` , false , false , true )
227
227
228
228
async function bootClientIfCssFileMayBeTailwindRelated ( uri : Uri ) {
229
+ if ( currentClient ) return
229
230
let folder = Workspace . getWorkspaceFolder ( uri )
230
- if ( ! folder || isExcluded ( uri . fsPath , folder ) ) {
231
- return
232
- }
233
- if ( await api . stylesheetNeedsLanguageServer ( uri ) ) {
234
- await bootWorkspaceClient ( )
235
- }
231
+ if ( ! folder || isExcluded ( uri . fsPath , folder ) ) return
232
+ if ( ! ( await api . stylesheetNeedsLanguageServer ( uri ) ) ) return
233
+
234
+ await bootWorkspaceClient ( )
236
235
}
237
236
238
237
cssWatcher . onDidCreate ( bootClientIfCssFileMayBeTailwindRelated )
@@ -526,35 +525,34 @@ export async function activate(context: ExtensionContext) {
526
525
return client
527
526
}
528
527
529
- async function bootClientIfNeeded ( ) : Promise < void > {
530
- if ( currentClient ) return
531
-
532
- if ( await api . workspaceNeedsLanguageServer ( ) ) {
533
- await bootWorkspaceClient ( )
534
- }
535
- }
536
-
528
+ /**
529
+ * Note that this method can fire *many* times even for documents that are
530
+ * not in a visible editor. It's critical that this doesn't start any
531
+ * expensive operations more than is necessary.
532
+ */
537
533
async function didOpenTextDocument ( document : TextDocument ) : Promise < void > {
538
534
if ( document . languageId === 'tailwindcss' ) {
539
535
servers . css . boot ( context , outputChannel )
540
536
}
541
537
538
+ if ( currentClient ) return
539
+
542
540
// We are only interested in language mode text
543
- if ( document . uri . scheme !== 'file' ) {
544
- return
545
- }
541
+ if ( document . uri . scheme !== 'file' ) return
546
542
547
- let uri = document . uri
548
- let folder = Workspace . getWorkspaceFolder ( uri )
543
+ let folder = Workspace . getWorkspaceFolder ( document . uri )
549
544
550
545
// Files outside a folder can't be handled. This might depend on the language.
551
546
// Single file languages like JSON might handle files outside the workspace folders.
552
547
if ( ! folder ) return
553
548
554
- await bootClientIfNeeded ( )
549
+ if ( ! ( await api . workspaceNeedsLanguageServer ( ) ) ) return
550
+
551
+ await bootWorkspaceClient ( )
555
552
}
556
553
557
554
context . subscriptions . push ( Workspace . onDidOpenTextDocument ( didOpenTextDocument ) )
555
+
558
556
Workspace . textDocuments . forEach ( didOpenTextDocument )
559
557
context . subscriptions . push (
560
558
Workspace . onDidChangeWorkspaceFolders ( async ( ) => {
0 commit comments