From a5a049400318ad69be72f35f5244d07f0fc81eb9 Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Tue, 4 May 2021 12:57:10 +0100 Subject: [PATCH] clear color decorators when restarting language client --- src/extension.ts | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 17b1a72..ae4407b 100755 --- a/src/extension.ts +++ b/src/extension.ts @@ -19,7 +19,12 @@ import { RelativePattern, ConfigurationScope, } from 'vscode' -import { LanguageClient, LanguageClientOptions, TransportKind } from 'vscode-languageclient/node' +import { + LanguageClient, + LanguageClientOptions, + TransportKind, + State as LanguageClientState, +} from 'vscode-languageclient/node' import { DEFAULT_LANGUAGES } from './lib/languages' import isObject from './util/isObject' import { dedupe, equal } from 'tailwindcss-language-service/src/util/array' @@ -76,8 +81,6 @@ function getUserLanguages(folder?: WorkspaceFolder): Record { return isObject(langs) ? langs : {} } -let colorDecorationType: TextEditorDecorationType - export function activate(context: ExtensionContext) { let module = context.asAbsolutePath(path.join('dist', 'server', 'index.js')) let outputChannel: OutputChannel = Window.createOutputChannel(CLIENT_NAME) @@ -132,6 +135,14 @@ export function activate(context: ExtensionContext) { return } + let colorDecorationType: TextEditorDecorationType + function clearColors(): void { + if (colorDecorationType) { + colorDecorationType.dispose() + colorDecorationType = undefined + } + } + // placeholder so we don't boot another server before this one is ready clients.set(folder.uri.toString(), null) @@ -288,12 +299,7 @@ export function activate(context: ExtensionContext) { } }) - client.onNotification('@/tailwindCSS/clearColors', () => { - if (colorDecorationType) { - colorDecorationType.dispose() - colorDecorationType = undefined - } - }) + client.onNotification('@/tailwindCSS/clearColors', () => clearColors()) client.onRequest('@/tailwindCSS/getDocumentSymbols', async ({ uri }) => { return commands.executeCommand( @@ -303,6 +309,12 @@ export function activate(context: ExtensionContext) { }) }) + client.onDidChangeState(({ newState }) => { + if (newState === LanguageClientState.Stopped) { + clearColors() + } + }) + client.start() clients.set(folder.uri.toString(), client) }