提交 82dcf983 编写于 作者: M Matt Bierner 提交者: GitHub

Add support for localizing ts errors (#36451)

* Pick up typescript 2.6.1-insiders.20171019

* Add support for localizing ts errors. Fixes #18634
上级 d6e8af6c
......@@ -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"
}
}
}
......@@ -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"
......
......@@ -399,6 +399,15 @@
"default": true,
"description": "%typescript.quickSuggestionsForPaths%",
"scope": "resource"
},
"typescript.locale": {
"type": [
"string",
"null"
],
"default": null,
"description": "%typescript.locale%",
"scope": "window"
}
}
},
......
......@@ -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."
}
......@@ -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;
......
......@@ -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
......@@ -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
......@@ -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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册