diff --git a/Readme.md b/Readme.md index 49bea79..f1aa8c0 100644 --- a/Readme.md +++ b/Readme.md @@ -53,8 +53,9 @@ Almost the same as VSCode. - Rename imports on file rename. - Search for workspace symbols. -Tsserver module is resolved from your local workspace. If it's not found, the bundled tsserver -module will be used. +Tsserver module first resolved from your local workspace. If it's not found, +use tsserver from `tsserver.tsdk` configuration or use bundled tsserver with +this extension. ## Configuration options @@ -83,7 +84,7 @@ module will be used. - `typescript.suggestionActions.enabled`:Enable/disable suggestion diagnostics for TypeScript files in the editor. Requires using TypeScript 2.8 or newer in the workspace., default: `true` - `typescript.validate.enable`:Enable/disable TypeScript validation., default: `true` - `typescript.useBatchedBufferSync`: use batched buffer synchronize support. -- `typescript.showUnused`: show unused variable hint. +- `typescript.showUnused`: show unused variable hint, default: `true`. - `typescript.suggest.enabled` default: `true` - `typescript.suggest.paths`:Enable/disable suggest paths in import statement and require calls, default: `true` - `typescript.suggest.autoImports`:Enable/disable auto import suggests., default: `true` diff --git a/package.json b/package.json index 0547749..d5816d0 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,10 @@ "engines": { "coc": "^0.0.69" }, + "repository": { + "type": "git", + "url": "https://github.com/neoclide/coc-tsserver.git" + }, "keywords": [ "coc.nvim", "tsserver", @@ -125,6 +129,11 @@ "default": true, "description": "Use tsserver for javascript files" }, + "tsserver.ignoreLocalTsserver": { + "type": "boolean", + "default": false, + "description": "Always use tsserver module from tsserver.tsdk or tsserver extension." + }, "tsserver.tsdk": { "type": "string", "default": "", diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index a95d0f4..b7746fc 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -258,12 +258,18 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient } private async startService(resendModels = false): Promise { - let currentVersion = this.versionProvider.getLocalVersion() + const { ignoreLocalTsserver } = this.configuration + let currentVersion + if (!ignoreLocalTsserver) currentVersion = this.versionProvider.getLocalVersion() if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) { - currentVersion = await this.versionProvider.getDefaultVersion() + currentVersion = this.versionProvider.getDefaultVersion() } if (!currentVersion || !currentVersion.isValid) { - workspace.showMessage(`Can not find tsserver, run ':CocInstall coc-tsserver' to fix it!`, 'error') + if (this.configuration.globalTsdk) { + workspace.showMessage(`Can not find typescript module, in 'tsserver.tsdk': ${this.configuration.globalTsdk}`, 'error') + } else { + workspace.showMessage(`Can not find typescript module, run ':CocInstall coc-tsserver' to fix it!`, 'error') + } return } this._apiVersion = currentVersion.version diff --git a/src/server/utils/configuration.ts b/src/server/utils/configuration.ts index 8a0bc8c..cba937c 100644 --- a/src/server/utils/configuration.ts +++ b/src/server/utils/configuration.ts @@ -56,6 +56,10 @@ export class TypeScriptServiceConfiguration { return this._configuration.get('tsdk', null) } + public get ignoreLocalTsserver(): boolean { + return this._configuration.get('ignoreLocalTsserver', false) + } + public get tsServerLogLevel(): TsServerLogLevel { return TsServerLogLevel.fromString(this._configuration.get('log', null)) } diff --git a/src/server/utils/versionProvider.ts b/src/server/utils/versionProvider.ts index ba6b50a..df83b4f 100644 --- a/src/server/utils/versionProvider.ts +++ b/src/server/utils/versionProvider.ts @@ -90,7 +90,7 @@ export class TypeScriptVersionProvider { this.configuration = configuration } - public async getDefaultVersion(): Promise { + public getDefaultVersion(): TypeScriptVersion { // tsdk from configuration let { globalTsdk } = this.configuration if (globalTsdk) return new TypeScriptVersion(globalTsdk) @@ -108,7 +108,8 @@ export class TypeScriptVersionProvider { for (let p of folders) { if (fs.existsSync(path.join(p, 'node_modules/typescript/lib'))) { let lib = path.join(p, 'node_modules/typescript/lib') - return new TypeScriptVersion(lib) + let version = new TypeScriptVersion(lib) + if (version.isValid) return version } } return null