add tsserver.ignoreLocalTsserver configuration

This commit is contained in:
chemzqm 2019-06-27 10:43:32 +08:00
parent 74bd823e4e
commit c10f34304c
5 changed files with 29 additions and 8 deletions

View file

@ -53,8 +53,9 @@ Almost the same as VSCode.
- Rename imports on file rename. - Rename imports on file rename.
- Search for workspace symbols. - Search for workspace symbols.
Tsserver module is resolved from your local workspace. If it's not found, the bundled tsserver Tsserver module first resolved from your local workspace. If it's not found,
module will be used. use tsserver from `tsserver.tsdk` configuration or use bundled tsserver with
this extension.
## Configuration options ## 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.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.validate.enable`:Enable/disable TypeScript validation., default: `true`
- `typescript.useBatchedBufferSync`: use batched buffer synchronize support. - `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.enabled` default: `true`
- `typescript.suggest.paths`:Enable/disable suggest paths in import statement and require calls, 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` - `typescript.suggest.autoImports`:Enable/disable auto import suggests., default: `true`

View file

@ -7,6 +7,10 @@
"engines": { "engines": {
"coc": "^0.0.69" "coc": "^0.0.69"
}, },
"repository": {
"type": "git",
"url": "https://github.com/neoclide/coc-tsserver.git"
},
"keywords": [ "keywords": [
"coc.nvim", "coc.nvim",
"tsserver", "tsserver",
@ -125,6 +129,11 @@
"default": true, "default": true,
"description": "Use tsserver for javascript files" "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": { "tsserver.tsdk": {
"type": "string", "type": "string",
"default": "", "default": "",

View file

@ -258,12 +258,18 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
} }
private async startService(resendModels = false): Promise<ForkedTsServerProcess> { private async startService(resendModels = false): Promise<ForkedTsServerProcess> {
let currentVersion = this.versionProvider.getLocalVersion() const { ignoreLocalTsserver } = this.configuration
let currentVersion
if (!ignoreLocalTsserver) currentVersion = this.versionProvider.getLocalVersion()
if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) { if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) {
currentVersion = await this.versionProvider.getDefaultVersion() currentVersion = this.versionProvider.getDefaultVersion()
} }
if (!currentVersion || !currentVersion.isValid) { 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 return
} }
this._apiVersion = currentVersion.version this._apiVersion = currentVersion.version

View file

@ -56,6 +56,10 @@ export class TypeScriptServiceConfiguration {
return this._configuration.get<string | null>('tsdk', null) return this._configuration.get<string | null>('tsdk', null)
} }
public get ignoreLocalTsserver(): boolean {
return this._configuration.get<boolean>('ignoreLocalTsserver', false)
}
public get tsServerLogLevel(): TsServerLogLevel { public get tsServerLogLevel(): TsServerLogLevel {
return TsServerLogLevel.fromString(this._configuration.get<string | null>('log', null)) return TsServerLogLevel.fromString(this._configuration.get<string | null>('log', null))
} }

View file

@ -90,7 +90,7 @@ export class TypeScriptVersionProvider {
this.configuration = configuration this.configuration = configuration
} }
public async getDefaultVersion(): Promise<TypeScriptVersion> { public getDefaultVersion(): TypeScriptVersion {
// tsdk from configuration // tsdk from configuration
let { globalTsdk } = this.configuration let { globalTsdk } = this.configuration
if (globalTsdk) return new TypeScriptVersion(globalTsdk) if (globalTsdk) return new TypeScriptVersion(globalTsdk)
@ -108,7 +108,8 @@ export class TypeScriptVersionProvider {
for (let p of folders) { for (let p of folders) {
if (fs.existsSync(path.join(p, 'node_modules/typescript/lib'))) { if (fs.existsSync(path.join(p, 'node_modules/typescript/lib'))) {
let lib = 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 return null