Skip to content

Commit ac906bb

Browse files
committed
Cleanup
1 parent 8d02006 commit ac906bb

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

packages/vscode-tailwindcss/src/extension.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ export async function activate(context: ExtensionContext) {
214214
let configWatcher = Workspace.createFileSystemWatcher(`**/${CONFIG_GLOB}`, false, true, true)
215215

216216
configWatcher.onDidCreate(async (uri) => {
217+
if (currentClient) return
217218
let folder = Workspace.getWorkspaceFolder(uri)
218-
if (!folder || isExcluded(uri.fsPath, folder)) {
219-
return
220-
}
219+
if (!folder || isExcluded(uri.fsPath, folder)) return
220+
221221
await bootWorkspaceClient()
222222
})
223223

@@ -226,13 +226,12 @@ export async function activate(context: ExtensionContext) {
226226
let cssWatcher = Workspace.createFileSystemWatcher(`**/${CSS_GLOB}`, false, false, true)
227227

228228
async function bootClientIfCssFileMayBeTailwindRelated(uri: Uri) {
229+
if (currentClient) return
229230
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()
236235
}
237236

238237
cssWatcher.onDidCreate(bootClientIfCssFileMayBeTailwindRelated)
@@ -526,35 +525,34 @@ export async function activate(context: ExtensionContext) {
526525
return client
527526
}
528527

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+
*/
537533
async function didOpenTextDocument(document: TextDocument): Promise<void> {
538534
if (document.languageId === 'tailwindcss') {
539535
servers.css.boot(context, outputChannel)
540536
}
541537

538+
if (currentClient) return
539+
542540
// We are only interested in language mode text
543-
if (document.uri.scheme !== 'file') {
544-
return
545-
}
541+
if (document.uri.scheme !== 'file') return
546542

547-
let uri = document.uri
548-
let folder = Workspace.getWorkspaceFolder(uri)
543+
let folder = Workspace.getWorkspaceFolder(document.uri)
549544

550545
// Files outside a folder can't be handled. This might depend on the language.
551546
// Single file languages like JSON might handle files outside the workspace folders.
552547
if (!folder) return
553548

554-
await bootClientIfNeeded()
549+
if (!(await api.workspaceNeedsLanguageServer())) return
550+
551+
await bootWorkspaceClient()
555552
}
556553

557554
context.subscriptions.push(Workspace.onDidOpenTextDocument(didOpenTextDocument))
555+
558556
Workspace.textDocuments.forEach(didOpenTextDocument)
559557
context.subscriptions.push(
560558
Workspace.onDidChangeWorkspaceFolders(async () => {

0 commit comments

Comments
 (0)