@@ -16,7 +16,6 @@ import {
1616 Position ,
1717 Range ,
1818 RelativePattern ,
19- languages ,
2019} from 'vscode'
2120import 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-
195163async 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
205171function resetActiveTextEditorContext ( ) : void {
206172 commands . executeCommand ( 'setContext' , 'tailwindCSS.activeTextEditorSupportsClassSorting' , false )
207173}
208174
209175export 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