From 2d4c8f0bb37b043aeddfae3b69cc99520f8ea53e Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Tue, 22 Feb 2022 18:11:13 +0800 Subject: [PATCH] fix possible start multiply tsserver Closes #355 --- src/server/index.ts | 8 ++++---- src/server/typescriptServiceClientHost.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/index.ts b/src/server/index.ts index 160bce2..6744848 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -100,14 +100,14 @@ export default class TsserverService implements IServiceProvider { } public async start(): Promise { - if (!this.enable) return + if (!this.enable || this._state == ServiceStat.Starting) return + this._state = ServiceStat.Starting if (this.clientHost) { let client = this.clientHost.serviceClient client.restartTsServer() return } - let tscPath = await workspace.nvim.getVar('Tsserver_path') as string - this._state = ServiceStat.Starting + let tscPath = await workspace.nvim.getVar('Tsserver_path') as string | null this.clientHost = new TypeScriptServiceClientHost(this.descriptions, this.pluginManager, tscPath) let client = this.clientHost.serviceClient await new Promise(resolve => { @@ -132,7 +132,7 @@ export default class TsserverService implements IServiceProvider { if (!this.clientHost) return let client = this.clientHost.serviceClient await client.stop() - this.clientHost.dispose() + this.clientHost?.dispose() this.clientHost = null this._state = ServiceStat.Stopped } diff --git a/src/server/typescriptServiceClientHost.ts b/src/server/typescriptServiceClientHost.ts index 4113e09..dd44d49 100644 --- a/src/server/typescriptServiceClientHost.ts +++ b/src/server/typescriptServiceClientHost.ts @@ -38,7 +38,7 @@ export default class TypeScriptServiceClientHost implements Disposable { private readonly fileConfigurationManager: FileConfigurationManager private reportStyleCheckAsWarnings = true - constructor(descriptions: LanguageDescription[], pluginManager: PluginManager, tscPath: string | undefined) { + constructor(descriptions: LanguageDescription[], pluginManager: PluginManager, tscPath: string | null) { let timer: NodeJS.Timer const handleProjectChange = () => { if (timer) clearTimeout(timer)