Skip to content

Commit 001791a

Browse files
Stop auto-switching CSS files to the Tailwind CSS language mode (#1116)
There's some issues with the approach and it's unexpected behavior for some users. Rolling this back until we have a better solution. Potentially one that's configurable. Fixes #1111
1 parent 1c24aa5 commit 001791a

File tree

2 files changed

+2
-40
lines changed

2 files changed

+2
-40
lines changed

packages/vscode-tailwindcss/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Prerelease
44

5-
- Nothing yet!
5+
- Stop auto-switching CSS files to the Tailwind CSS language mode ([#1116](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1116))
66

77
## 0.12.17
88

packages/vscode-tailwindcss/src/extension.ts

+1-39
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
Position,
1717
Range,
1818
RelativePattern,
19-
languages,
2019
} from 'vscode'
2120
import type {
2221
DocumentFilter,
@@ -125,15 +124,11 @@ async function getActiveTextEditorProject(): Promise<{ version: string } | null>
125124
let editor = Window.activeTextEditor
126125
if (!editor) return null
127126

128-
return projectForDocument(editor.document)
129-
}
130-
131-
async function projectForDocument(document: TextDocument): Promise<{ version: string } | null> {
132127
// No server yet, no project
133128
if (!currentClient) return null
134129

135130
// No workspace folder, no project
136-
let uri = document.uri
131+
let uri = editor.document.uri
137132
let folder = Workspace.getWorkspaceFolder(uri)
138133
if (!folder) return null
139134

@@ -165,50 +160,19 @@ async function activeTextEditorSupportsClassSorting(): Promise<boolean> {
165160
return semver.gte(project.version, '3.0.0')
166161
}
167162

168-
const switchedDocuments = new Set<string>()
169-
170-
async function switchDocumentLanguageIfNeeded(document: TextDocument): Promise<void> {
171-
// Consider documents that are already in `tailwindcss` language mode as
172-
// having been switched automatically. This ensures that a user can still
173-
// manually switch this document to `css` and have it stay that way.
174-
if (document.languageId === 'tailwindcss') {
175-
switchedDocuments.add(document.uri.toString())
176-
return
177-
}
178-
179-
if (document.languageId !== 'css') return
180-
181-
// When a document is manually switched back to the `css` language we do not
182-
// want to switch it back to `tailwindcss` because the user has explicitly
183-
// chosen to use the `css` language mode.
184-
if (switchedDocuments.has(document.uri.toString())) return
185-
186-
let project = await projectForDocument(document)
187-
if (!project) return
188-
189-
// CSS files in a known project should be switched to `tailwindcss`
190-
// when they are opened
191-
languages.setTextDocumentLanguage(document, 'tailwindcss')
192-
switchedDocuments.add(document.uri.toString())
193-
}
194-
195163
async function updateActiveTextEditorContext(): Promise<void> {
196164
commands.executeCommand(
197165
'setContext',
198166
'tailwindCSS.activeTextEditorSupportsClassSorting',
199167
await activeTextEditorSupportsClassSorting(),
200168
)
201-
202-
await Promise.all(Workspace.textDocuments.map(switchDocumentLanguageIfNeeded))
203169
}
204170

205171
function resetActiveTextEditorContext(): void {
206172
commands.executeCommand('setContext', 'tailwindCSS.activeTextEditorSupportsClassSorting', false)
207173
}
208174

209175
export async function activate(context: ExtensionContext) {
210-
switchedDocuments.clear()
211-
212176
let outputChannel = Window.createOutputChannel(CLIENT_NAME)
213177
context.subscriptions.push(outputChannel)
214178
context.subscriptions.push(
@@ -664,8 +628,6 @@ export async function activate(context: ExtensionContext) {
664628
}
665629

666630
async function didOpenTextDocument(document: TextDocument): Promise<void> {
667-
await switchDocumentLanguageIfNeeded(document)
668-
669631
if (document.languageId === 'tailwindcss') {
670632
servers.css.boot(context, outputChannel)
671633
}

0 commit comments

Comments
 (0)