@@ -16,7 +16,6 @@ import {
16
16
Position ,
17
17
Range ,
18
18
RelativePattern ,
19
- languages ,
20
19
} from 'vscode'
21
20
import type {
22
21
DocumentFilter ,
@@ -125,15 +124,11 @@ async function getActiveTextEditorProject(): Promise<{ version: string } | null>
125
124
let editor = Window . activeTextEditor
126
125
if ( ! editor ) return null
127
126
128
- return projectForDocument ( editor . document )
129
- }
130
-
131
- async function projectForDocument ( document : TextDocument ) : Promise < { version : string } | null > {
132
127
// No server yet, no project
133
128
if ( ! currentClient ) return null
134
129
135
130
// No workspace folder, no project
136
- let uri = document . uri
131
+ let uri = editor . document . uri
137
132
let folder = Workspace . getWorkspaceFolder ( uri )
138
133
if ( ! folder ) return null
139
134
@@ -165,50 +160,19 @@ async function activeTextEditorSupportsClassSorting(): Promise<boolean> {
165
160
return semver . gte ( project . version , '3.0.0' )
166
161
}
167
162
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
-
195
163
async function updateActiveTextEditorContext ( ) : Promise < void > {
196
164
commands . executeCommand (
197
165
'setContext' ,
198
166
'tailwindCSS.activeTextEditorSupportsClassSorting' ,
199
167
await activeTextEditorSupportsClassSorting ( ) ,
200
168
)
201
-
202
- await Promise . all ( Workspace . textDocuments . map ( switchDocumentLanguageIfNeeded ) )
203
169
}
204
170
205
171
function resetActiveTextEditorContext ( ) : void {
206
172
commands . executeCommand ( 'setContext' , 'tailwindCSS.activeTextEditorSupportsClassSorting' , false )
207
173
}
208
174
209
175
export async function activate ( context : ExtensionContext ) {
210
- switchedDocuments . clear ( )
211
-
212
176
let outputChannel = Window . createOutputChannel ( CLIENT_NAME )
213
177
context . subscriptions . push ( outputChannel )
214
178
context . subscriptions . push (
@@ -664,8 +628,6 @@ export async function activate(context: ExtensionContext) {
664
628
}
665
629
666
630
async function didOpenTextDocument ( document : TextDocument ) : Promise < void > {
667
- await switchDocumentLanguageIfNeeded ( document )
668
-
669
631
if ( document . languageId === 'tailwindcss' ) {
670
632
servers . css . boot ( context , outputChannel )
671
633
}
0 commit comments