提交 775a1563 编写于 作者: D Dirk Baeumer

Fixes #57994: Narrow signature of localize function to string | number | boolean | undefined | null

上级 a957654d
......@@ -126,7 +126,7 @@ function zipLogs(
return new TPromise<string>((resolve, reject) => {
doZip(logsPath, outZip, tempDir, (err, stdout, stderr) => {
if (err) {
console.error(localize('zipError', 'Error zipping logs: {0}', err));
console.error(localize('zipError', 'Error zipping logs: {0}', err.message));
reject(err);
} else {
resolve(outZip);
......
......@@ -8,5 +8,5 @@ export interface ILocalizeInfo {
comment: string[];
}
export declare function localize(info: ILocalizeInfo, message: string, ...args: any[]): string;
export declare function localize(key: string, message: string, ...args: any[]): string;
export declare function localize(info: ILocalizeInfo, message: string, ...args: (string | number | boolean | undefined | null)[]): string;
export declare function localize(key: string, message: string, ...args: (string | number | boolean | undefined | null)[]): string;
......@@ -46,7 +46,15 @@ var NLSLoaderPlugin;
else {
result = message.replace(/\{(\d+)\}/g, function (match, rest) {
var index = rest[0];
return typeof args[index] !== 'undefined' ? args[index] : match;
var arg = args[index];
var result = match;
if (typeof arg === 'string') {
result = arg;
}
else if (typeof arg === 'number' || typeof arg === 'boolean' || arg === void 0 || arg === null) {
result = String(arg);
}
return result;
});
}
if (env.isPseudo) {
......
......@@ -213,7 +213,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
const versionNow = model.getVersionId();
const { tabSize, insertSpaces } = model.getOptions();
const timeout = this._configurationService.getValue('editor.formatOnSaveTimeout', { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() });
const timeout = this._configurationService.getValue<number>('editor.formatOnSaveTimeout', { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() });
return new Promise<ISingleEditOperation[]>((resolve, reject) => {
let source = new CancellationTokenSource();
......
......@@ -94,7 +94,7 @@ export class LanguageConfigurationFileHandler {
const errors: ParseError[] = [];
const configuration = <ILanguageConfiguration>parse(contents.value.toString(), errors);
if (errors.length) {
console.error(nls.localize('parseErrors', "Errors parsing {0}: {1}", configFileLocation, errors.join('\n')));
console.error(nls.localize('parseErrors', "Errors parsing {0}: {1}", configFileLocation.toString(), errors.join('\n')));
}
this._handleConfig(languageIdentifier, configuration);
}, (err) => {
......
......@@ -309,7 +309,7 @@ export class DebugService implements IDebugService {
}));
}
if (configOrName && !config) {
const message = !!launch ? nls.localize('configMissing', "Configuration '{0}' is missing in 'launch.json'.", configOrName) :
const message = !!launch ? nls.localize('configMissing', "Configuration '{0}' is missing in 'launch.json'.", typeof configOrName === 'string' ? configOrName : JSON.stringify(configOrName)) :
nls.localize('launchJsonDoesNotExist', "'launch.json' does not exist.");
return TPromise.wrapError(new Error(message));
}
......@@ -746,7 +746,7 @@ export class DebugService implements IDebugService {
if (!taskStarted) {
const errorMessage = typeof taskId === 'string'
? nls.localize('taskNotTrackedWithTaskId', "The specified task cannot be tracked.")
: nls.localize('taskNotTracked', "The task '{0}' cannot be tracked.", taskId);
: nls.localize('taskNotTracked', "The task '{0}' cannot be tracked.", JSON.stringify(taskId));
e({ severity: severity.Error, message: errorMessage });
}
}, 10000);
......
......@@ -202,7 +202,7 @@ class SnippetsService implements ISnippetsService {
extension.collector.warn(localize(
'badFile',
"The snippet file \"{0}\" could not be read.",
file.location
file.location.toString()
));
});
}
......
......@@ -361,7 +361,7 @@ export class ProcessTaskSystem implements ITaskSystem {
let makeVisible = false;
if (errorData.error && !errorData.terminated) {
let args: string = task.command.args ? task.command.args.join(' ') : '';
this.log(nls.localize('TaskRunnerSystem.childProcessError', 'Failed to launch external program {0} {1}.', task.command.name, args));
this.log(nls.localize('TaskRunnerSystem.childProcessError', 'Failed to launch external program {0} {1}.', JSON.stringify(task.command.name), args));
this.outputChannel.append(errorData.error.message);
makeVisible = true;
}
......
......@@ -890,7 +890,12 @@ namespace CommandConfiguration {
if (converted !== void 0) {
result.args.push(converted);
} else {
context.problemReporter.error(nls.localize('ConfigurationParser.inValidArg', 'Error: command argument must either be a string or a quoted string. Provided value is:\n{0}', context.problemReporter.error(nls.localize('ConfigurationParser.noargs', 'Error: command arguments must be an array of strings. Provided value is:\n{0}', arg ? JSON.stringify(arg, undefined, 4) : 'undefined'))));
context.problemReporter.error(
nls.localize(
'ConfigurationParser.inValidArg',
'Error: command argument must either be a string or a quoted string. Provided value is:\n{0}',
arg ? JSON.stringify(arg, undefined, 4) : 'undefined'
));
}
}
}
......
......@@ -61,7 +61,7 @@ export class JSONValidationExtensionPoint {
try {
const colorThemeLocation = resources.joinPath(extensionLocation, uri);
if (!resources.isEqualOrParent(colorThemeLocation, extensionLocation)) {
collector.warn(nls.localize('invalid.path.1', "Expected `contributes.{0}.url` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.", configurationExtPoint.name, location, extensionLocation.path));
collector.warn(nls.localize('invalid.path.1', "Expected `contributes.{0}.url` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.", configurationExtPoint.name, colorThemeLocation.toString(), extensionLocation.path));
}
} catch (e) {
collector.error(nls.localize('invalid.url.fileschema', "'configuration.jsonValidation.url' is an invalid relative URL: {0}", e.message));
......
......@@ -293,7 +293,7 @@ function _loadColorTheme(fileService: IFileService, themeLocation: URI, resultRu
let colors = contentValue.colors;
if (colors) {
if (typeof colors !== 'object') {
return TPromise.wrapError(new Error(nls.localize({ key: 'error.invalidformat.colors', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing color theme file: {0}. Property 'colors' is not of type 'object'.", themeLocation)));
return TPromise.wrapError(new Error(nls.localize({ key: 'error.invalidformat.colors', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing color theme file: {0}. Property 'colors' is not of type 'object'.", themeLocation.toString())));
}
// new JSON color themes format
for (let colorId in colors) {
......@@ -311,7 +311,7 @@ function _loadColorTheme(fileService: IFileService, themeLocation: URI, resultRu
} else if (typeof tokenColors === 'string') {
return _loadSyntaxTokens(fileService, resources.joinPath(resources.dirname(themeLocation), tokenColors), resultRules, {});
} else {
return TPromise.wrapError(new Error(nls.localize({ key: 'error.invalidformat.tokenColors', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing color theme file: {0}. Property 'tokenColors' should be either an array specifying colors or a path to a TextMate theme file", themeLocation)));
return TPromise.wrapError(new Error(nls.localize({ key: 'error.invalidformat.tokenColors', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing color theme file: {0}. Property 'tokenColors' should be either an array specifying colors or a path to a TextMate theme file", themeLocation.toString())));
}
}
return null;
......@@ -343,7 +343,7 @@ function _loadSyntaxTokens(fileService: IFileService, themeLocation: URI, result
}
});
}, error => {
return TPromise.wrapError(new Error(nls.localize('error.cannotload', "Problems loading tmTheme file {0}: {1}", themeLocation, error.message)));
return TPromise.wrapError(new Error(nls.localize('error.cannotload', "Problems loading tmTheme file {0}: {1}", themeLocation.toString(), error.message)));
});
}
......
......@@ -294,7 +294,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this.updateDynamicCSSRules(themeData);
return this.applyTheme(themeData, settingsTarget);
}, error => {
return TPromise.wrapError<IColorTheme>(new Error(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", themeData.location, error.message)));
return TPromise.wrapError<IColorTheme>(new Error(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", themeData.location.toString(), error.message)));
});
}
return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册