Add support for localizing ts errors (#36451)

* Pick up typescript 2.6.1-insiders.20171019

* Add support for localizing ts errors. Fixes #18634
This commit is contained in:
Matt Bierner
2017-10-19 19:52:02 -07:00
committed by GitHub
parent d6e8af6c0c
commit 82dcf98352
8 changed files with 44 additions and 8 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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');
}
}

View File

@@ -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<boolean>('typescript.disableAutomaticTypeAcquisition', false);
}
private static extractLocale(configuration: WorkspaceConfiguration): string | null {
return configuration.get<string | null>('typescript.locale', null);
}
}