@@ -19,7 +19,12 @@ import {
19
19
RelativePattern ,
20
20
ConfigurationScope ,
21
21
} from 'vscode'
22
- import { LanguageClient , LanguageClientOptions , TransportKind } from 'vscode-languageclient/node'
22
+ import {
23
+ LanguageClient ,
24
+ LanguageClientOptions ,
25
+ TransportKind ,
26
+ State as LanguageClientState ,
27
+ } from 'vscode-languageclient/node'
23
28
import { DEFAULT_LANGUAGES } from './lib/languages'
24
29
import isObject from './util/isObject'
25
30
import { dedupe , equal } from 'tailwindcss-language-service/src/util/array'
@@ -76,8 +81,6 @@ function getUserLanguages(folder?: WorkspaceFolder): Record<string, string> {
76
81
return isObject ( langs ) ? langs : { }
77
82
}
78
83
79
- let colorDecorationType : TextEditorDecorationType
80
-
81
84
export function activate ( context : ExtensionContext ) {
82
85
let module = context . asAbsolutePath ( path . join ( 'dist' , 'server' , 'index.js' ) )
83
86
let outputChannel : OutputChannel = Window . createOutputChannel ( CLIENT_NAME )
@@ -132,6 +135,14 @@ export function activate(context: ExtensionContext) {
132
135
return
133
136
}
134
137
138
+ let colorDecorationType : TextEditorDecorationType
139
+ function clearColors ( ) : void {
140
+ if ( colorDecorationType ) {
141
+ colorDecorationType . dispose ( )
142
+ colorDecorationType = undefined
143
+ }
144
+ }
145
+
135
146
// placeholder so we don't boot another server before this one is ready
136
147
clients . set ( folder . uri . toString ( ) , null )
137
148
@@ -288,12 +299,7 @@ export function activate(context: ExtensionContext) {
288
299
}
289
300
} )
290
301
291
- client . onNotification ( '@/tailwindCSS/clearColors' , ( ) => {
292
- if ( colorDecorationType ) {
293
- colorDecorationType . dispose ( )
294
- colorDecorationType = undefined
295
- }
296
- } )
302
+ client . onNotification ( '@/tailwindCSS/clearColors' , ( ) => clearColors ( ) )
297
303
298
304
client . onRequest ( '@/tailwindCSS/getDocumentSymbols' , async ( { uri } ) => {
299
305
return commands . executeCommand < SymbolInformation [ ] > (
@@ -303,6 +309,12 @@ export function activate(context: ExtensionContext) {
303
309
} )
304
310
} )
305
311
312
+ client . onDidChangeState ( ( { newState } ) => {
313
+ if ( newState === LanguageClientState . Stopped ) {
314
+ clearColors ( )
315
+ }
316
+ } )
317
+
306
318
client . start ( )
307
319
clients . set ( folder . uri . toString ( ) , client )
308
320
}
0 commit comments