From 458f822a2747856c359f4bc520d004eada76a1c9 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 7 Jan 2025 12:40:06 -0500 Subject: [PATCH 1/2] Revert "Auto-switch CSS files to `tailwindcss` language in valid projects (#1087)" This reverts commit 3b4b5bae18dd42771d5aa7050a3c2e2ec04bf631. --- packages/vscode-tailwindcss/src/extension.ts | 40 +------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/packages/vscode-tailwindcss/src/extension.ts b/packages/vscode-tailwindcss/src/extension.ts index d717d5a5..d727f923 100755 --- a/packages/vscode-tailwindcss/src/extension.ts +++ b/packages/vscode-tailwindcss/src/extension.ts @@ -16,7 +16,6 @@ import { Position, Range, RelativePattern, - languages, } from 'vscode' import type { DocumentFilter, @@ -125,15 +124,11 @@ async function getActiveTextEditorProject(): Promise<{ version: string } | null> let editor = Window.activeTextEditor if (!editor) return null - return projectForDocument(editor.document) -} - -async function projectForDocument(document: TextDocument): Promise<{ version: string } | null> { // No server yet, no project if (!currentClient) return null // No workspace folder, no project - let uri = document.uri + let uri = editor.document.uri let folder = Workspace.getWorkspaceFolder(uri) if (!folder) return null @@ -165,41 +160,12 @@ async function activeTextEditorSupportsClassSorting(): Promise { return semver.gte(project.version, '3.0.0') } -const switchedDocuments = new Set() - -async function switchDocumentLanguageIfNeeded(document: TextDocument): Promise { - // Consider documents that are already in `tailwindcss` language mode as - // having been switched automatically. This ensures that a user can still - // manually switch this document to `css` and have it stay that way. - if (document.languageId === 'tailwindcss') { - switchedDocuments.add(document.uri.toString()) - return - } - - if (document.languageId !== 'css') return - - // When a document is manually switched back to the `css` language we do not - // want to switch it back to `tailwindcss` because the user has explicitly - // chosen to use the `css` language mode. - if (switchedDocuments.has(document.uri.toString())) return - - let project = await projectForDocument(document) - if (!project) return - - // CSS files in a known project should be switched to `tailwindcss` - // when they are opened - languages.setTextDocumentLanguage(document, 'tailwindcss') - switchedDocuments.add(document.uri.toString()) -} - async function updateActiveTextEditorContext(): Promise { commands.executeCommand( 'setContext', 'tailwindCSS.activeTextEditorSupportsClassSorting', await activeTextEditorSupportsClassSorting(), ) - - await Promise.all(Workspace.textDocuments.map(switchDocumentLanguageIfNeeded)) } function resetActiveTextEditorContext(): void { @@ -207,8 +173,6 @@ function resetActiveTextEditorContext(): void { } export async function activate(context: ExtensionContext) { - switchedDocuments.clear() - let outputChannel = Window.createOutputChannel(CLIENT_NAME) context.subscriptions.push(outputChannel) context.subscriptions.push( @@ -664,8 +628,6 @@ export async function activate(context: ExtensionContext) { } async function didOpenTextDocument(document: TextDocument): Promise { - await switchDocumentLanguageIfNeeded(document) - if (document.languageId === 'tailwindcss') { servers.css.boot(context, outputChannel) } From e498cb68d628b705506b3a5dbb20ca7d5b75d02b Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 7 Jan 2025 12:44:29 -0500 Subject: [PATCH 2/2] Update changelog --- packages/vscode-tailwindcss/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index cb17e7e3..e34a8d78 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -2,7 +2,7 @@ ## Prerelease -- Nothing yet! +- Stop auto-switching CSS files to the Tailwind CSS language mode ([#1116](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1116)) ## 0.12.17