parent
2d62d7da5f
commit
464adfcb0a
4 changed files with 23 additions and 8 deletions
|
@ -99,20 +99,21 @@ export default class TsserverService implements IServiceProvider {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public start(): Promise<void> {
|
public async start(): Promise<void> {
|
||||||
if (!this.enable) return
|
if (!this.enable) return
|
||||||
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
|
||||||
this._state = ServiceStat.Starting
|
this._state = ServiceStat.Starting
|
||||||
this.clientHost = new TypeScriptServiceClientHost(this.descriptions, this.pluginManager)
|
this.clientHost = new TypeScriptServiceClientHost(this.descriptions, this.pluginManager, tscPath)
|
||||||
let client = this.clientHost.serviceClient
|
let client = this.clientHost.serviceClient
|
||||||
return new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
client.onReady(() => {
|
client.onReady(() => {
|
||||||
this._onDidServiceReady.fire(void 0)
|
this._onDidServiceReady.fire(void 0)
|
||||||
resolve()
|
resolve(undefined)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,8 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly pluginManager: PluginManager,
|
public readonly pluginManager: PluginManager,
|
||||||
public readonly modeIds: string[]
|
public readonly modeIds: string[],
|
||||||
|
private readonly tscPathVim: string | undefined
|
||||||
) {
|
) {
|
||||||
this.pathSeparator = path.sep
|
this.pathSeparator = path.sep
|
||||||
this.lastStart = Date.now()
|
this.lastStart = Date.now()
|
||||||
|
@ -217,7 +218,10 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||||
private startService(resendModels = false): ForkedTsServerProcess | undefined {
|
private startService(resendModels = false): ForkedTsServerProcess | undefined {
|
||||||
const { ignoreLocalTsserver } = this.configuration
|
const { ignoreLocalTsserver } = this.configuration
|
||||||
let currentVersion: TypeScriptVersion
|
let currentVersion: TypeScriptVersion
|
||||||
if (!ignoreLocalTsserver) currentVersion = this.versionProvider.getLocalVersion()
|
console.log('===========')
|
||||||
|
console.log(this.tscPathVim)
|
||||||
|
if (this.tscPathVim) currentVersion = this.versionProvider.getVersionFromTscPath(this.tscPathVim)
|
||||||
|
if (!currentVersion && !ignoreLocalTsserver) currentVersion = this.versionProvider.getLocalVersion()
|
||||||
if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) {
|
if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) {
|
||||||
this.info('Local tsserver not found, using bundled tsserver with coc-tsserver.')
|
this.info('Local tsserver not found, using bundled tsserver with coc-tsserver.')
|
||||||
currentVersion = this.versionProvider.getDefaultVersion()
|
currentVersion = this.versionProvider.getDefaultVersion()
|
||||||
|
@ -232,6 +236,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||||
}
|
}
|
||||||
this._apiVersion = currentVersion.version
|
this._apiVersion = currentVersion.version
|
||||||
this._tscPath = currentVersion.tscPath
|
this._tscPath = currentVersion.tscPath
|
||||||
|
workspace.nvim.setVar('Tsserver_path', this._tscPath, true)
|
||||||
this.versionStatus.onDidChangeTypeScriptVersion(currentVersion)
|
this.versionStatus.onDidChangeTypeScriptVersion(currentVersion)
|
||||||
const tsServerForkArgs = this.getTsServerArgs(currentVersion)
|
const tsServerForkArgs = this.getTsServerArgs(currentVersion)
|
||||||
const options = { execArgv: this.getExecArgv() }
|
const options = { execArgv: this.getExecArgv() }
|
||||||
|
|
|
@ -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) {
|
constructor(descriptions: LanguageDescription[], pluginManager: PluginManager, tscPath: string | undefined) {
|
||||||
let timer: NodeJS.Timer
|
let timer: NodeJS.Timer
|
||||||
const handleProjectChange = () => {
|
const handleProjectChange = () => {
|
||||||
if (timer) clearTimeout(timer)
|
if (timer) clearTimeout(timer)
|
||||||
|
@ -57,7 +57,7 @@ export default class TypeScriptServiceClientHost implements Disposable {
|
||||||
packageFileWatcher.onDidChange(handleProjectChange, this, this.disposables)
|
packageFileWatcher.onDidChange(handleProjectChange, this, this.disposables)
|
||||||
|
|
||||||
const allModeIds = this.getAllModeIds(descriptions, pluginManager)
|
const allModeIds = this.getAllModeIds(descriptions, pluginManager)
|
||||||
this.client = new TypeScriptServiceClient(pluginManager, allModeIds)
|
this.client = new TypeScriptServiceClient(pluginManager, allModeIds, tscPath)
|
||||||
this.disposables.push(this.client)
|
this.disposables.push(this.client)
|
||||||
this.client.onDiagnosticsReceived(({ kind, resource, diagnostics }) => {
|
this.client.onDiagnosticsReceived(({ kind, resource, diagnostics }) => {
|
||||||
this.diagnosticsReceived(kind, resource, diagnostics).catch(e => {
|
this.diagnosticsReceived(kind, resource, diagnostics).catch(e => {
|
||||||
|
|
|
@ -106,6 +106,15 @@ export class TypeScriptVersionProvider {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getVersionFromTscPath(tscPath: string): TypeScriptVersion | undefined {
|
||||||
|
if (!tscPath || !fs.existsSync(tscPath)) return undefined
|
||||||
|
let libFolder = path.resolve(tscPath, '../../lib')
|
||||||
|
if (fs.existsSync(libFolder)) {
|
||||||
|
let version = new TypeScriptVersion(libFolder)
|
||||||
|
if (version.isValid) return version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public getLocalVersion(): TypeScriptVersion | undefined {
|
public getLocalVersion(): TypeScriptVersion | undefined {
|
||||||
let folders = workspace.workspaceFolders.map(f => Uri.parse(f.uri).fsPath)
|
let folders = workspace.workspaceFolders.map(f => Uri.parse(f.uri).fsPath)
|
||||||
for (let p of folders) {
|
for (let p of folders) {
|
||||||
|
|
Loading…
Reference in a new issue