Skip to content

Fix problem with too many ripgrep processes being spawned by VSCode #1287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 7, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup
  • Loading branch information
thecrypticace committed Apr 7, 2025
commit ac906bbe95b1ce0e61994f8ff22936bc12ddea2c
44 changes: 21 additions & 23 deletions packages/vscode-tailwindcss/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ export async function activate(context: ExtensionContext) {
let configWatcher = Workspace.createFileSystemWatcher(`**/${CONFIG_GLOB}`, false, true, true)

configWatcher.onDidCreate(async (uri) => {
if (currentClient) return
let folder = Workspace.getWorkspaceFolder(uri)
if (!folder || isExcluded(uri.fsPath, folder)) {
return
}
if (!folder || isExcluded(uri.fsPath, folder)) return

await bootWorkspaceClient()
})

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

async function bootClientIfCssFileMayBeTailwindRelated(uri: Uri) {
if (currentClient) return
let folder = Workspace.getWorkspaceFolder(uri)
if (!folder || isExcluded(uri.fsPath, folder)) {
return
}
if (await api.stylesheetNeedsLanguageServer(uri)) {
await bootWorkspaceClient()
}
if (!folder || isExcluded(uri.fsPath, folder)) return
if (!(await api.stylesheetNeedsLanguageServer(uri))) return

await bootWorkspaceClient()
}

cssWatcher.onDidCreate(bootClientIfCssFileMayBeTailwindRelated)
Expand Down Expand Up @@ -526,35 +525,34 @@ export async function activate(context: ExtensionContext) {
return client
}

async function bootClientIfNeeded(): Promise<void> {
if (currentClient) return

if (await api.workspaceNeedsLanguageServer()) {
await bootWorkspaceClient()
}
}

/**
* Note that this method can fire *many* times even for documents that are
* not in a visible editor. It's critical that this doesn't start any
* expensive operations more than is necessary.
*/
async function didOpenTextDocument(document: TextDocument): Promise<void> {
if (document.languageId === 'tailwindcss') {
servers.css.boot(context, outputChannel)
}

if (currentClient) return

// We are only interested in language mode text
if (document.uri.scheme !== 'file') {
return
}
if (document.uri.scheme !== 'file') return

let uri = document.uri
let folder = Workspace.getWorkspaceFolder(uri)
let folder = Workspace.getWorkspaceFolder(document.uri)

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

await bootClientIfNeeded()
if (!(await api.workspaceNeedsLanguageServer())) return

await bootWorkspaceClient()
}

context.subscriptions.push(Workspace.onDidOpenTextDocument(didOpenTextDocument))

Workspace.textDocuments.forEach(didOpenTextDocument)
context.subscriptions.push(
Workspace.onDidChangeWorkspaceFolders(async () => {
Expand Down