From 63e22e092cea9b6f5f0d3d83fba1f2f018c1049c Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 29 Aug 2022 18:21:23 +0800 Subject: [PATCH] fix configured tsserver.tsdk not used Use configured tsserver.tsdk when local tsserver not used. --- src/server/typescriptServiceClient.ts | 11 ++++++++++- src/server/utils/versionProvider.ts | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index 54a172e..605fefc 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -227,7 +227,16 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient if (this.tscPathVim) currentVersion = this.versionProvider.getVersionFromTscPath(this.tscPathVim) if (!currentVersion && !ignoreLocalTsserver) currentVersion = this.versionProvider.getLocalVersion() if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) { - this.info('Local tsserver not found, using bundled tsserver with coc-tsserver.') + if (ignoreLocalTsserver) { + this.info(`local tsserver is ignored, try global version`) + } else { + this.info(`local tsserver is not found, try global version`) + } + currentVersion = this.versionProvider.globalVersion + if (currentVersion) this.info('Local and global tsserver not found, using global tsserver from configuration') + } + if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) { + this.info('Local and global tsserver not found, using bundled tsserver with coc-tsserver.') currentVersion = this.versionProvider.getDefaultVersion() } if (!currentVersion || !currentVersion.isValid) { diff --git a/src/server/utils/versionProvider.ts b/src/server/utils/versionProvider.ts index b488bef..3fbd2db 100644 --- a/src/server/utils/versionProvider.ts +++ b/src/server/utils/versionProvider.ts @@ -102,7 +102,11 @@ export class TypeScriptVersionProvider { public get globalVersion(): TypeScriptVersion | undefined { let { globalTsdk } = this.configuration - if (globalTsdk) return new TypeScriptVersion(workspace.expand(globalTsdk)) + let folder = workspace.expand(globalTsdk) + if (!path.isAbsolute(folder)) { + folder = path.join(workspace.root, folder) + } + if (globalTsdk) return new TypeScriptVersion(folder) return undefined }