@@ -19,7 +19,12 @@ import {
1919 RelativePattern ,
2020 ConfigurationScope ,
2121} 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'
2328import { DEFAULT_LANGUAGES } from './lib/languages'
2429import isObject from './util/isObject'
2530import { dedupe , equal } from 'tailwindcss-language-service/src/util/array'
@@ -76,8 +81,6 @@ function getUserLanguages(folder?: WorkspaceFolder): Record<string, string> {
7681 return isObject ( langs ) ? langs : { }
7782}
7883
79- let colorDecorationType : TextEditorDecorationType
80-
8184export function activate ( context : ExtensionContext ) {
8285 let module = context . asAbsolutePath ( path . join ( 'dist' , 'server' , 'index.js' ) )
8386 let outputChannel : OutputChannel = Window . createOutputChannel ( CLIENT_NAME )
@@ -132,6 +135,14 @@ export function activate(context: ExtensionContext) {
132135 return
133136 }
134137
138+ let colorDecorationType : TextEditorDecorationType
139+ function clearColors ( ) : void {
140+ if ( colorDecorationType ) {
141+ colorDecorationType . dispose ( )
142+ colorDecorationType = undefined
143+ }
144+ }
145+
135146 // placeholder so we don't boot another server before this one is ready
136147 clients . set ( folder . uri . toString ( ) , null )
137148
@@ -288,12 +299,7 @@ export function activate(context: ExtensionContext) {
288299 }
289300 } )
290301
291- client . onNotification ( '@/tailwindCSS/clearColors' , ( ) => {
292- if ( colorDecorationType ) {
293- colorDecorationType . dispose ( )
294- colorDecorationType = undefined
295- }
296- } )
302+ client . onNotification ( '@/tailwindCSS/clearColors' , ( ) => clearColors ( ) )
297303
298304 client . onRequest ( '@/tailwindCSS/getDocumentSymbols' , async ( { uri } ) => {
299305 return commands . executeCommand < SymbolInformation [ ] > (
@@ -303,6 +309,12 @@ export function activate(context: ExtensionContext) {
303309 } )
304310 } )
305311
312+ client . onDidChangeState ( ( { newState } ) => {
313+ if ( newState === LanguageClientState . Stopped ) {
314+ clearColors ( )
315+ }
316+ } )
317+
306318 client . start ( )
307319 clients . set ( folder . uri . toString ( ) , client )
308320 }
0 commit comments