From 50d6c6241a3e3c45a659a1237b5827d06291b284 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 13 Jul 2020 19:56:13 +0800 Subject: [PATCH] use tsserver.pluginPaths replace tsserver.pluginRoot --- Readme.md | 2 +- package.json | 6 +++--- src/server/typescriptServiceClient.ts | 21 ++++++++++++++++----- src/server/utils/configuration.ts | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Readme.md b/Readme.md index fb34d1a..ab38a3a 100644 --- a/Readme.md +++ b/Readme.md @@ -104,7 +104,7 @@ Checkout [using the configuration file](https://github.com/neoclide/coc.nvim/wik - `tsserver.npm`:Executable path of npm for download typings, default: `""` - `tsserver.log`:Log level of tsserver, default: `"off"` - `tsserver.trace.server`:Trace level of tsserver, default: `"off"` -- `tsserver.pluginRoot`:Folder contains tsserver plugins, default: `[]` +- `tsserver.pluginPaths`:Folders contains tsserver plugins, default: `[]` - `tsserver.debugPort`:Debug port number of tsserver - `tsserver.watchOptions`:Configure which watching strategies should be used to keep track of files and directories. Requires using TypeScript 3.8+ in the workspace, default: undefined. - `tsserver.reportStyleChecksAsWarnings` default: `true` diff --git a/package.json b/package.json index 6c405b4..5ac815a 100644 --- a/package.json +++ b/package.json @@ -211,13 +211,13 @@ ], "description": "Trace level of tsserver" }, - "tsserver.pluginRoot": { - "type": "string", + "tsserver.pluginPaths": { + "type": "array", "default": [], "items": { "type": "string" }, - "description": "Folder contains tsserver plugins" + "description": "Folders contains tsserver plugins" }, "tsserver.debugPort": { "type": "number", diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index d3b86ae..cefa995 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -281,7 +281,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient this._tscPath = currentVersion.tscPath this.versionStatus.onDidChangeTypeScriptVersion(currentVersion) this.lastError = null - const tsServerForkArgs = await this.getTsServerArgs() + const tsServerForkArgs = await this.getTsServerArgs(currentVersion) const debugPort = this._configuration.debugPort const maxTsServerMemory = this._configuration.maxTsServerMemory const options = { @@ -766,7 +766,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient } } - private async getTsServerArgs(): Promise { + private async getTsServerArgs(currentVersion: TypeScriptVersion): Promise { const args: string[] = [] args.push('--allowLocalPluginLoads') @@ -809,13 +809,24 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient if (this.apiVersion.gte(API.v230)) { const pluginNames = this.pluginManager.plugins.map(x => x.name) - const pluginRoot = this._configuration.tsServerPluginRoot - const pluginPaths = pluginRoot ? [pluginRoot] : [] + let pluginPaths = this._configuration.tsServerPluginPaths + pluginPaths = pluginPaths.reduce((p, c) => { + if (path.isAbsolute(c)) { + p.push(c) + } else { + let roots = workspace.workspaceFolders.map(o => Uri.parse(o.uri).fsPath) + p.push(...roots.map(r => path.join(r, c))) + } + return p + }, []) if (pluginNames.length) { + const isUsingBundledTypeScriptVersion = currentVersion.path == this.versionProvider.bundledVersion.path args.push('--globalPlugins', pluginNames.join(',')) for (const plugin of this.pluginManager.plugins) { - pluginPaths.push(plugin.path) + if (isUsingBundledTypeScriptVersion || plugin.enableForWorkspaceTypeScriptVersions) { + pluginPaths.push(plugin.path) + } } } diff --git a/src/server/utils/configuration.ts b/src/server/utils/configuration.ts index b9ef8a5..36e3112 100644 --- a/src/server/utils/configuration.ts +++ b/src/server/utils/configuration.ts @@ -73,8 +73,8 @@ export class TypeScriptServiceConfiguration { return this._configuration.get('typingsCacheLocation', '') } - public get tsServerPluginRoot(): string | null { - return this._configuration.get('tsServerPluginRoot', null) + public get tsServerPluginPaths(): string[] { + return this._configuration.get('pluginPaths', []) } public get checkJs(): boolean {