From 82dcf9835265cd0a45ec135587ae2a82673f1c8f Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 19 Oct 2017 19:52:02 -0700 Subject: [PATCH] Add support for localizing ts errors (#36451) * Pick up typescript 2.6.1-insiders.20171019 * Add support for localizing ts errors. Fixes #18634 --- extensions/npm-shrinkwrap.json | 6 +++--- extensions/package.json | 2 +- extensions/typescript/package.json | 9 +++++++++ extensions/typescript/package.nls.json | 3 ++- extensions/typescript/src/typescriptMain.ts | 4 +++- .../typescript/src/typescriptServiceClient.ts | 15 ++++++++++++++- extensions/typescript/src/utils/api.ts | 4 ++++ extensions/typescript/src/utils/configuration.ts | 9 ++++++++- 8 files changed, 44 insertions(+), 8 deletions(-) diff --git a/extensions/npm-shrinkwrap.json b/extensions/npm-shrinkwrap.json index 6241de07cd9..004d491bbe7 100644 --- a/extensions/npm-shrinkwrap.json +++ b/extensions/npm-shrinkwrap.json @@ -3,9 +3,9 @@ "version": "0.0.1", "dependencies": { "typescript": { - "version": "2.6.1-insiders.20171016", - "from": "typescript@2.6.1-insiders.20171016", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.6.1-insiders.20171016.tgz" + "version": "2.6.1-insiders.20171019", + "from": "typescript@2.6.1-insiders.20171019", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.6.1-insiders.20171019.tgz" } } } diff --git a/extensions/package.json b/extensions/package.json index bcf3e8b0dc8..1e3f4a31a5d 100644 --- a/extensions/package.json +++ b/extensions/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "Dependencies shared by all extensions", "dependencies": { - "typescript": "2.6.1-insiders.20171016" + "typescript": "^2.6.1-insiders.20171019" }, "scripts": { "postinstall": "node ./postinstall" diff --git a/extensions/typescript/package.json b/extensions/typescript/package.json index 3062949aad7..ea920c7f29f 100644 --- a/extensions/typescript/package.json +++ b/extensions/typescript/package.json @@ -399,6 +399,15 @@ "default": true, "description": "%typescript.quickSuggestionsForPaths%", "scope": "resource" + }, + "typescript.locale": { + "type": [ + "string", + "null" + ], + "default": null, + "description": "%typescript.locale%", + "scope": "window" } } }, diff --git a/extensions/typescript/package.nls.json b/extensions/typescript/package.nls.json index 39725205f50..284db837016 100644 --- a/extensions/typescript/package.nls.json +++ b/extensions/typescript/package.nls.json @@ -42,5 +42,6 @@ "typescript.tsc.autoDetect": "Controls auto detection of tsc tasks. 'off' disables this feature. 'build' only creates single run compile tasks. 'watch' only creates compile and watch tasks. 'on' creates both build and watch tasks. Default is 'on'.", "typescript.problemMatchers.tsc.label": "TypeScript problems", "typescript.problemMatchers.tscWatch.label": "TypeScript problems (watch mode)", - "typescript.quickSuggestionsForPaths": "Enable/disable quick suggestions when typing out an import path." + "typescript.quickSuggestionsForPaths": "Enable/disable quick suggestions when typing out an import path.", + "typescript.locale": "Sets the locale used to report TypeScript errors. Requires TypeScript >= 2.6.0. Default of 'null' uses VS Code's locale for TypeScript errors." } diff --git a/extensions/typescript/src/typescriptMain.ts b/extensions/typescript/src/typescriptMain.ts index b4bd55a6357..99e6f08e734 100644 --- a/extensions/typescript/src/typescriptMain.ts +++ b/extensions/typescript/src/typescriptMain.ts @@ -690,7 +690,9 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost { const converted = new Diagnostic(range, text); converted.severity = this.getDiagnosticSeverity(diagnostic); converted.source = diagnostic.source || source; - converted.code = '' + diagnostic.code; + if (diagnostic.code) { + converted.code = diagnostic.code; + } result.push(converted); } return result; diff --git a/extensions/typescript/src/typescriptServiceClient.ts b/extensions/typescript/src/typescriptServiceClient.ts index bd5936aa22c..8163808609d 100644 --- a/extensions/typescript/src/typescriptServiceClient.ts +++ b/extensions/typescript/src/typescriptServiceClient.ts @@ -11,7 +11,7 @@ import * as os from 'os'; import * as electron from './utils/electron'; import { Reader } from './utils/wireProtocol'; -import { workspace, window, Uri, CancellationToken, Disposable, Memento, MessageItem, EventEmitter, Event, commands } from 'vscode'; +import { workspace, window, Uri, CancellationToken, Disposable, Memento, MessageItem, EventEmitter, Event, commands, env } from 'vscode'; import * as Proto from './protocol'; import { ITypescriptServiceClient, ITypescriptServiceClientHost } from './typescriptService'; import { TypeScriptServerPlugin } from './utils/plugins'; @@ -381,6 +381,13 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient } } + if (this.apiVersion.has260Features()) { + const tsLocale = getTsLocale(this.configuration); + if (tsLocale) { + args.push('--locale', tsLocale); + } + } + electron.fork(currentVersion.tsServerPath, args, options, this.logger, (err: any, childProcess: cp.ChildProcess) => { if (err) { this.lastError = err; @@ -862,3 +869,9 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient this.logTelemetry(telemetryData.telemetryEventName, properties); } } + + +const getTsLocale = (configuration: TypeScriptServiceConfiguration): string | undefined => + (configuration.locale + ? configuration.locale + : env.language); \ No newline at end of file diff --git a/extensions/typescript/src/utils/api.ts b/extensions/typescript/src/utils/api.ts index 91888a52f58..69307cad289 100644 --- a/extensions/typescript/src/utils/api.ts +++ b/extensions/typescript/src/utils/api.ts @@ -69,4 +69,8 @@ export default class API { public has250Features(): boolean { return semver.gte(this.version, '2.5.0'); } + + public has260Features(): boolean { + return semver.gte(this.version, '2.6.0'); + } } \ No newline at end of file diff --git a/extensions/typescript/src/utils/configuration.ts b/extensions/typescript/src/utils/configuration.ts index 4a759024dd5..52792e4c73a 100644 --- a/extensions/typescript/src/utils/configuration.ts +++ b/extensions/typescript/src/utils/configuration.ts @@ -42,6 +42,7 @@ export namespace TsServerLogLevel { } export class TypeScriptServiceConfiguration { + public readonly locale: string | null; public readonly globalTsdk: string | null; public readonly localTsdk: string | null; public readonly npmLocation: string | null; @@ -56,6 +57,7 @@ export class TypeScriptServiceConfiguration { private constructor() { const configuration = workspace.getConfiguration(); + this.locale = TypeScriptServiceConfiguration.extractLocale(configuration); this.globalTsdk = TypeScriptServiceConfiguration.extractGlobalTsdk(configuration); this.localTsdk = TypeScriptServiceConfiguration.extractLocalTsdk(configuration); this.npmLocation = TypeScriptServiceConfiguration.readNpmLocation(configuration); @@ -65,7 +67,8 @@ export class TypeScriptServiceConfiguration { } public isEqualTo(other: TypeScriptServiceConfiguration): boolean { - return this.globalTsdk === other.globalTsdk + return this.locale === other.locale + && this.globalTsdk === other.globalTsdk && this.localTsdk === other.localTsdk && this.npmLocation === other.npmLocation && this.tsServerLogLevel === other.tsServerLogLevel @@ -105,4 +108,8 @@ export class TypeScriptServiceConfiguration { private static readDisableAutomaticTypeAcquisition(configuration: WorkspaceConfiguration): boolean { return configuration.get('typescript.disableAutomaticTypeAcquisition', false); } + + private static extractLocale(configuration: WorkspaceConfiguration): string | null { + return configuration.get('typescript.locale', null); + } } -- GitLab