clear color decorators when restarting language client

master
Brad Cornes 2021-05-04 12:57:10 +01:00
parent c4a2c254d8
commit a5a0494003
1 changed files with 21 additions and 9 deletions

View File

@ -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<string, string> {
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<SymbolInformation[]>(
@ -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)
}