fix possible start multiply tsserver

Closes #355
This commit is contained in:
Qiming Zhao 2022-02-22 18:11:13 +08:00
parent 67239f40b5
commit 2d4c8f0bb3
No known key found for this signature in database
GPG key ID: 9722CD0E8D4DCB8C
2 changed files with 5 additions and 5 deletions

View file

@ -100,14 +100,14 @@ export default class TsserverService implements IServiceProvider {
} }
public async start(): Promise<void> { public async start(): Promise<void> {
if (!this.enable) return if (!this.enable || this._state == ServiceStat.Starting) return
this._state = ServiceStat.Starting
if (this.clientHost) { if (this.clientHost) {
let client = this.clientHost.serviceClient let client = this.clientHost.serviceClient
client.restartTsServer() client.restartTsServer()
return return
} }
let tscPath = await workspace.nvim.getVar('Tsserver_path') as string let tscPath = await workspace.nvim.getVar('Tsserver_path') as string | null
this._state = ServiceStat.Starting
this.clientHost = new TypeScriptServiceClientHost(this.descriptions, this.pluginManager, tscPath) this.clientHost = new TypeScriptServiceClientHost(this.descriptions, this.pluginManager, tscPath)
let client = this.clientHost.serviceClient let client = this.clientHost.serviceClient
await new Promise(resolve => { await new Promise(resolve => {
@ -132,7 +132,7 @@ export default class TsserverService implements IServiceProvider {
if (!this.clientHost) return if (!this.clientHost) return
let client = this.clientHost.serviceClient let client = this.clientHost.serviceClient
await client.stop() await client.stop()
this.clientHost.dispose() this.clientHost?.dispose()
this.clientHost = null this.clientHost = null
this._state = ServiceStat.Stopped this._state = ServiceStat.Stopped
} }

View file

@ -38,7 +38,7 @@ export default class TypeScriptServiceClientHost implements Disposable {
private readonly fileConfigurationManager: FileConfigurationManager private readonly fileConfigurationManager: FileConfigurationManager
private reportStyleCheckAsWarnings = true private reportStyleCheckAsWarnings = true
constructor(descriptions: LanguageDescription[], pluginManager: PluginManager, tscPath: string | undefined) { constructor(descriptions: LanguageDescription[], pluginManager: PluginManager, tscPath: string | null) {
let timer: NodeJS.Timer let timer: NodeJS.Timer
const handleProjectChange = () => { const handleProjectChange = () => {
if (timer) clearTimeout(timer) if (timer) clearTimeout(timer)