Converted json extension to new vscode-nls npm module

This commit is contained in:
Dirk Baeumer
2016-03-03 16:54:36 +01:00
parent 189321eb12
commit 5354309a24
12 changed files with 167 additions and 144 deletions
+2 -1
View File
@@ -10,7 +10,8 @@
"dependencies": {
"http-proxy-agent": "^0.2.6",
"https-proxy-agent": "^0.3.5",
"vscode-languageserver": "^1.3.0"
"vscode-languageserver": "^1.3.0",
"vscode-nls": "^1.0.4"
},
"devDependencies": {
"mocha": "^2.2.5",
+37 -36
View File
@@ -4,10 +4,11 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import nls = require('./utils/nls');
import {ISchemaContributions} from './jsonSchemaService';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export var schemaContributions: ISchemaContributions = {
schemaAssociations: {
@@ -15,7 +16,7 @@ export var schemaContributions: ISchemaContributions = {
schemas: {
// bundle the schema-schema to include (localized) descriptions
'http://json-schema.org/draft-04/schema#': {
'title': nls.localize('schema.json', 'Describes a JSON file using a schema. See json-schema.org for more info.'),
'title': localize('schema.json', 'Describes a JSON file using a schema. See json-schema.org for more info.'),
'$schema': 'http://json-schema.org/draft-04/schema#',
'definitions': {
'schemaArray': {
@@ -46,64 +47,64 @@ export var schemaContributions: ISchemaContributions = {
'id': {
'type': 'string',
'format': 'uri',
'description': nls.localize('schema.json.id', 'A unique identifier for the schema.')
'description': localize('schema.json.id', 'A unique identifier for the schema.')
},
'$schema': {
'type': 'string',
'format': 'uri',
'description': nls.localize('schema.json.$schema', 'The schema to verify this document against ')
'description': localize('schema.json.$schema', 'The schema to verify this document against ')
},
'title': {
'type': 'string',
'description': nls.localize('schema.json.title', 'A descriptive title of the element')
'description': localize('schema.json.title', 'A descriptive title of the element')
},
'description': {
'type': 'string',
'description': nls.localize('schema.json.description', 'A long description of the element. Used in hover menus and suggestions.')
'description': localize('schema.json.description', 'A long description of the element. Used in hover menus and suggestions.')
},
'default': {
'description': nls.localize('schema.json.default', 'A default value. Used by suggestions.')
'description': localize('schema.json.default', 'A default value. Used by suggestions.')
},
'multipleOf': {
'type': 'number',
'minimum': 0,
'exclusiveMinimum': true,
'description': nls.localize('schema.json.multipleOf', 'A number that should cleanly divide the current value (i.e. have no remainder)')
'description': localize('schema.json.multipleOf', 'A number that should cleanly divide the current value (i.e. have no remainder)')
},
'maximum': {
'type': 'number',
'description': nls.localize('schema.json.maximum', 'The maximum numerical value, inclusive by default.')
'description': localize('schema.json.maximum', 'The maximum numerical value, inclusive by default.')
},
'exclusiveMaximum': {
'type': 'boolean',
'default': false,
'description': nls.localize('schema.json.exclusiveMaximum', 'Makes the maximum property exclusive.')
'description': localize('schema.json.exclusiveMaximum', 'Makes the maximum property exclusive.')
},
'minimum': {
'type': 'number',
'description': nls.localize('schema.json.minimum', 'The minimum numerical value, inclusive by default.')
'description': localize('schema.json.minimum', 'The minimum numerical value, inclusive by default.')
},
'exclusiveMinimum': {
'type': 'boolean',
'default': false,
'description': nls.localize('schema.json.exclusiveMininum', 'Makes the minimum property exclusive.')
'description': localize('schema.json.exclusiveMininum', 'Makes the minimum property exclusive.')
},
'maxLength': {
'allOf': [
{ '$ref': '#/definitions/positiveInteger' }
],
'description': nls.localize('schema.json.maxLength', 'The maximum length of a string.')
'description': localize('schema.json.maxLength', 'The maximum length of a string.')
},
'minLength': {
'allOf': [
{ '$ref': '#/definitions/positiveIntegerDefault0' }
],
'description': nls.localize('schema.json.minLength', 'The minimum length of a string.')
'description': localize('schema.json.minLength', 'The minimum length of a string.')
},
'pattern': {
'type': 'string',
'format': 'regex',
'description': nls.localize('schema.json.pattern', 'A regular expression to match the string against. It is not implicitly anchored.')
'description': localize('schema.json.pattern', 'A regular expression to match the string against. It is not implicitly anchored.')
},
'additionalItems': {
'anyOf': [
@@ -111,7 +112,7 @@ export var schemaContributions: ISchemaContributions = {
{ '$ref': '#' }
],
'default': {},
'description': nls.localize('schema.json.additionalItems', 'For arrays, only when items is set as an array. If it is a schema, then this schema validates items after the ones specified by the items array. If it is false, then additional items will cause validation to fail.')
'description': localize('schema.json.additionalItems', 'For arrays, only when items is set as an array. If it is a schema, then this schema validates items after the ones specified by the items array. If it is false, then additional items will cause validation to fail.')
},
'items': {
'anyOf': [
@@ -119,42 +120,42 @@ export var schemaContributions: ISchemaContributions = {
{ '$ref': '#/definitions/schemaArray' }
],
'default': {},
'description': nls.localize('schema.json.items', 'For arrays. Can either be a schema to validate every element against or an array of schemas to validate each item against in order (the first schema will validate the first element, the second schema will validate the second element, and so on.')
'description': localize('schema.json.items', 'For arrays. Can either be a schema to validate every element against or an array of schemas to validate each item against in order (the first schema will validate the first element, the second schema will validate the second element, and so on.')
},
'maxItems': {
'allOf': [
{ '$ref': '#/definitions/positiveInteger' }
],
'description': nls.localize('schema.json.maxItems', 'The maximum number of items that can be inside an array. Inclusive.')
'description': localize('schema.json.maxItems', 'The maximum number of items that can be inside an array. Inclusive.')
},
'minItems': {
'allOf': [
{ '$ref': '#/definitions/positiveIntegerDefault0' }
],
'description': nls.localize('schema.json.minItems', 'The minimum number of items that can be inside an array. Inclusive.')
'description': localize('schema.json.minItems', 'The minimum number of items that can be inside an array. Inclusive.')
},
'uniqueItems': {
'type': 'boolean',
'default': false,
'description': nls.localize('schema.json.uniqueItems', 'If all of the items in the array must be unique. Defaults to false.')
'description': localize('schema.json.uniqueItems', 'If all of the items in the array must be unique. Defaults to false.')
},
'maxProperties': {
'allOf': [
{ '$ref': '#/definitions/positiveInteger' }
],
'description': nls.localize('schema.json.maxProperties', 'The maximum number of properties an object can have. Inclusive.')
'description': localize('schema.json.maxProperties', 'The maximum number of properties an object can have. Inclusive.')
},
'minProperties': {
'allOf': [
{ '$ref': '#/definitions/positiveIntegerDefault0' },
],
'description': nls.localize('schema.json.minProperties', 'The minimum number of properties an object can have. Inclusive.')
'description': localize('schema.json.minProperties', 'The minimum number of properties an object can have. Inclusive.')
},
'required': {
'allOf': [
{ '$ref': '#/definitions/stringArray' }
],
'description': nls.localize('schema.json.required', 'An array of strings that lists the names of all properties required on this object.')
'description': localize('schema.json.required', 'An array of strings that lists the names of all properties required on this object.')
},
'additionalProperties': {
'anyOf': [
@@ -162,25 +163,25 @@ export var schemaContributions: ISchemaContributions = {
{ '$ref': '#' }
],
'default': {},
'description': nls.localize('schema.json.additionalProperties', 'Either a schema or a boolean. If a schema, then used to validate all properties not matched by \'properties\' or \'patternProperties\'. If false, then any properties not matched by either will cause this schema to fail.')
'description': localize('schema.json.additionalProperties', 'Either a schema or a boolean. If a schema, then used to validate all properties not matched by \'properties\' or \'patternProperties\'. If false, then any properties not matched by either will cause this schema to fail.')
},
'definitions': {
'type': 'object',
'additionalProperties': { '$ref': '#' },
'default': {},
'description': nls.localize('schema.json.definitions', 'Not used for validation. Place subschemas here that you wish to reference inline with $ref')
'description': localize('schema.json.definitions', 'Not used for validation. Place subschemas here that you wish to reference inline with $ref')
},
'properties': {
'type': 'object',
'additionalProperties': { '$ref': '#' },
'default': {},
'description': nls.localize('schema.json.properties', 'A map of property names to schemas for each property.')
'description': localize('schema.json.properties', 'A map of property names to schemas for each property.')
},
'patternProperties': {
'type': 'object',
'additionalProperties': { '$ref': '#' },
'default': {},
'description': nls.localize('schema.json.patternProperties', 'A map of regular expressions on property names to schemas for matching properties.')
'description': localize('schema.json.patternProperties', 'A map of regular expressions on property names to schemas for matching properties.')
},
'dependencies': {
'type': 'object',
@@ -190,13 +191,13 @@ export var schemaContributions: ISchemaContributions = {
{ '$ref': '#/definitions/stringArray' }
]
},
'description': nls.localize('schema.json.dependencies', 'A map of property names to either an array of property names or a schema. An array of property names means the property named in the key depends on the properties in the array being present in the object in order to be valid. If the value is a schema, then the schema is only applied to the object if the property in the key exists on the object.')
'description': localize('schema.json.dependencies', 'A map of property names to either an array of property names or a schema. An array of property names means the property named in the key depends on the properties in the array being present in the object in order to be valid. If the value is a schema, then the schema is only applied to the object if the property in the key exists on the object.')
},
'enum': {
'type': 'array',
'minItems': 1,
'uniqueItems': true,
'description': nls.localize('schema.json.enum', 'The set of literal values that are valid')
'description': localize('schema.json.enum', 'The set of literal values that are valid')
},
'type': {
'anyOf': [
@@ -208,13 +209,13 @@ export var schemaContributions: ISchemaContributions = {
'uniqueItems': true
}
],
'description': nls.localize('schema.json.type', 'Either a string of one of the basic schema types (number, integer, null, array, object, boolean, string) or an array of strings specifying a subset of those types.')
'description': localize('schema.json.type', 'Either a string of one of the basic schema types (number, integer, null, array, object, boolean, string) or an array of strings specifying a subset of those types.')
},
'format': {
'anyOf': [
{
'type': 'string',
'description': nls.localize('schema.json.format', 'Describes the format expected for the value.'),
'description': localize('schema.json.format', 'Describes the format expected for the value.'),
'enum': ['date-time', 'uri', 'email', 'hostname', 'ipv4', 'ipv6', 'regex']
}, {
'type': 'string'
@@ -225,25 +226,25 @@ export var schemaContributions: ISchemaContributions = {
'allOf': [
{ '$ref': '#/definitions/schemaArray' }
],
'description': nls.localize('schema.json.allOf', 'An array of schemas, all of which must match.')
'description': localize('schema.json.allOf', 'An array of schemas, all of which must match.')
},
'anyOf': {
'allOf': [
{ '$ref': '#/definitions/schemaArray' }
],
'description': nls.localize('schema.json.anyOf', 'An array of schemas, where at least one must match.')
'description': localize('schema.json.anyOf', 'An array of schemas, where at least one must match.')
},
'oneOf': {
'allOf': [
{ '$ref': '#/definitions/schemaArray' }
],
'description': nls.localize('schema.json.oneOf', 'An array of schemas, exactly one of which must match.')
'description': localize('schema.json.oneOf', 'An array of schemas, exactly one of which must match.')
},
'not': {
'allOf': [
{ '$ref': '#' }
],
'description': nls.localize('schema.json.not', 'A schema which must not match.')
'description': localize('schema.json.not', 'A schema which must not match.')
}
},
'dependencies': {
+5 -3
View File
@@ -8,11 +8,13 @@
import Parser = require('./jsonParser');
import SchemaService = require('./jsonSchemaService');
import JsonSchema = require('./json-toolbox/jsonSchema');
import nls = require('./utils/nls');
import {IJSONWorkerContribution} from './jsonContributions';
import {CompletionItem, CompletionItemKind, CompletionList, ITextDocument, TextDocumentPosition, Range, TextEdit, RemoteConsole} from 'vscode-languageserver';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export interface ISuggestionsCollector {
add(suggestion: CompletionItem): void;
error(message:string): void;
@@ -31,7 +33,7 @@ export class JSONCompletion {
this.contributions = contributions;
this.console = console;
}
public doResolve(item: CompletionItem) : Thenable<CompletionItem> {
for (let i = this.contributions.length - 1; i >= 0; i--) {
if (this.contributions[i].resolveSuggestion) {
@@ -362,7 +364,7 @@ export class JSONCompletion {
kind: this.getSuggestionKind(schema.type),
label: this.getLabelForValue(schema.default),
insertText: this.getTextForValue(schema.default),
detail: nls.localize('json.suggest.default', 'Default value'),
detail: localize('json.suggest.default', 'Default value'),
});
}
if (Array.isArray(schema.defaultSnippets)) {
+43 -40
View File
@@ -4,11 +4,14 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import nls = require('./utils/nls');
import Json = require('./json-toolbox/json');
import JsonSchema = require('./json-toolbox/jsonSchema');
import {JSONLocation} from './jsonLocation';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export interface IRange {
start: number;
end: number;
@@ -103,7 +106,7 @@ export class ASTNode {
if ((<string[]>schema.type).indexOf(this.type) === -1) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('typeArrayMismatchWarning', 'Incorrect type. Expected one of {0}', (<string[]>schema.type).join(', '))
message: localize('typeArrayMismatchWarning', 'Incorrect type. Expected one of {0}', (<string[]>schema.type).join(', '))
});
}
}
@@ -111,7 +114,7 @@ export class ASTNode {
if (this.type !== schema.type) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('typeMismatchWarning', 'Incorrect type. Expected "{0}"', schema.type)
message: localize('typeMismatchWarning', 'Incorrect type. Expected "{0}"', schema.type)
});
}
}
@@ -127,7 +130,7 @@ export class ASTNode {
if (!subValidationResult.hasErrors()) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('notSchemaWarning', "Matches a schema that is not allowed.")
message: localize('notSchemaWarning', "Matches a schema that is not allowed.")
});
}
if (matchingSchemas) {
@@ -174,7 +177,7 @@ export class ASTNode {
if (matches.length > 1 && maxOneMatch) {
validationResult.warnings.push({
location: { start: this.start, end: this.start + 1 },
message: nls.localize('oneOfWarning', "Matches multiple schemas when only one must validate.")
message: localize('oneOfWarning', "Matches multiple schemas when only one must validate.")
});
}
if (bestMatch !== null) {
@@ -198,7 +201,7 @@ export class ASTNode {
if (schema.enum.indexOf(this.getValue()) === -1) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('enumWarning', 'Value is not an accepted value. Valid values: {0}', JSON.stringify(schema.enum))
message: localize('enumWarning', 'Value is not an accepted value. Valid values: {0}', JSON.stringify(schema.enum))
});
} else {
validationResult.enumValueMatch = true;
@@ -292,7 +295,7 @@ export class ArrayASTNode extends ASTNode {
if (schema.additionalItems === false && this.items.length > subSchemas.length) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('additionalItemsWarning', 'Array has too many items according to schema. Expected {0} or fewer', subSchemas.length)
message: localize('additionalItemsWarning', 'Array has too many items according to schema. Expected {0} or fewer', subSchemas.length)
});
} else if (this.items.length >= subSchemas.length) {
validationResult.propertiesValueMatches += (this.items.length - subSchemas.length);
@@ -309,14 +312,14 @@ export class ArrayASTNode extends ASTNode {
if (schema.minItems && this.items.length < schema.minItems) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('minItemsWarning', 'Array has too few items. Expected {0} or more', schema.minItems)
message: localize('minItemsWarning', 'Array has too few items. Expected {0} or more', schema.minItems)
});
}
if (schema.maxItems && this.items.length > schema.maxItems) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('maxItemsWarning', 'Array has too many items. Expected {0} or fewer', schema.minItems)
message: localize('maxItemsWarning', 'Array has too many items. Expected {0} or fewer', schema.minItems)
});
}
@@ -330,7 +333,7 @@ export class ArrayASTNode extends ASTNode {
if (duplicates) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('uniqueItemsWarning', 'Array has duplicate items')
message: localize('uniqueItemsWarning', 'Array has duplicate items')
});
}
}
@@ -374,7 +377,7 @@ export class NumberASTNode extends ASTNode {
if (val % schema.multipleOf !== 0) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('multipleOfWarning', 'Value is not divisible by {0}', schema.multipleOf)
message: localize('multipleOfWarning', 'Value is not divisible by {0}', schema.multipleOf)
});
}
}
@@ -383,13 +386,13 @@ export class NumberASTNode extends ASTNode {
if (schema.exclusiveMinimum && val <= schema.minimum) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('exclusiveMinimumWarning', 'Value is below the exclusive minimum of {0}', schema.minimum)
message: localize('exclusiveMinimumWarning', 'Value is below the exclusive minimum of {0}', schema.minimum)
});
}
if (!schema.exclusiveMinimum && val < schema.minimum) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('minimumWarning', 'Value is below the minimum of {0}', schema.minimum)
message: localize('minimumWarning', 'Value is below the minimum of {0}', schema.minimum)
});
}
}
@@ -398,13 +401,13 @@ export class NumberASTNode extends ASTNode {
if (schema.exclusiveMaximum && val >= schema.maximum) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('exclusiveMaximumWarning', 'Value is above the exclusive maximum of {0}', schema.maximum)
message: localize('exclusiveMaximumWarning', 'Value is above the exclusive maximum of {0}', schema.maximum)
});
}
if (!schema.exclusiveMaximum && val > schema.maximum) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('maximumWarning', 'Value is above the maximum of {0}', schema.maximum)
message: localize('maximumWarning', 'Value is above the maximum of {0}', schema.maximum)
});
}
}
@@ -435,14 +438,14 @@ export class StringASTNode extends ASTNode {
if (schema.minLength && this.value.length < schema.minLength) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('minLengthWarning', 'String is shorter than the minimum length of ', schema.minLength)
message: localize('minLengthWarning', 'String is shorter than the minimum length of ', schema.minLength)
});
}
if (schema.maxLength && this.value.length > schema.maxLength) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('maxLengthWarning', 'String is shorter than the maximum length of ', schema.maxLength)
message: localize('maxLengthWarning', 'String is shorter than the maximum length of ', schema.maxLength)
});
}
@@ -451,7 +454,7 @@ export class StringASTNode extends ASTNode {
if (!regex.test(this.value)) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: schema.errorMessage || nls.localize('patternWarning', 'String does not match the pattern of "{0}"', schema.pattern)
message: schema.errorMessage || localize('patternWarning', 'String does not match the pattern of "{0}"', schema.pattern)
});
}
}
@@ -569,7 +572,7 @@ export class ObjectASTNode extends ASTNode {
let location = key ? { start: key.start, end: key.end } : { start: this.start, end: this.start + 1 };
validationResult.warnings.push({
location: location,
message: nls.localize('MissingRequiredPropWarning', 'Missing property "{0}"', propertyName)
message: localize('MissingRequiredPropWarning', 'Missing property "{0}"', propertyName)
});
}
});
@@ -634,7 +637,7 @@ export class ObjectASTNode extends ASTNode {
validationResult.warnings.push({
location: { start: propertyNode.key.start, end: propertyNode.key.end },
message: nls.localize('DisallowedExtraPropWarning', 'Property {0} is not allowed', propertyName)
message: localize('DisallowedExtraPropWarning', 'Property {0} is not allowed', propertyName)
});
}
});
@@ -645,7 +648,7 @@ export class ObjectASTNode extends ASTNode {
if (this.properties.length > schema.maxProperties) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('MaxPropWarning', 'Object has more properties than limit of {0}', schema.maxProperties)
message: localize('MaxPropWarning', 'Object has more properties than limit of {0}', schema.maxProperties)
});
}
}
@@ -654,7 +657,7 @@ export class ObjectASTNode extends ASTNode {
if (this.properties.length < schema.minProperties) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('MinPropWarning', 'Object has fewer properties than the required number of {0}', schema.minProperties)
message: localize('MinPropWarning', 'Object has fewer properties than the required number of {0}', schema.minProperties)
});
}
}
@@ -669,7 +672,7 @@ export class ObjectASTNode extends ASTNode {
if (!seenKeys[requiredProp]) {
validationResult.warnings.push({
location: { start: this.start, end: this.end },
message: nls.localize('RequiredDependentPropWarning', 'Object is missing property {0} required by property {1}', requiredProp, key)
message: localize('RequiredDependentPropWarning', 'Object is missing property {0} required by property {1}', requiredProp, key)
});
} else {
validationResult.propertiesValueMatches++;
@@ -837,19 +840,19 @@ export function parse(text: string, config = new JSONDocumentConfig()): JSONDocu
function _checkScanError(): boolean {
switch (_scanner.getTokenError()) {
case Json.ScanError.InvalidUnicode:
_error(nls.localize('InvalidUnicode', 'Invalid unicode sequence in string'));
_error(localize('InvalidUnicode', 'Invalid unicode sequence in string'));
return true;
case Json.ScanError.InvalidEscapeCharacter:
_error(nls.localize('InvalidEscapeCharacter', 'Invalid escape character in string'));
_error(localize('InvalidEscapeCharacter', 'Invalid escape character in string'));
return true;
case Json.ScanError.UnexpectedEndOfNumber:
_error(nls.localize('UnexpectedEndOfNumber', 'Unexpected end of number'));
_error(localize('UnexpectedEndOfNumber', 'Unexpected end of number'));
return true;
case Json.ScanError.UnexpectedEndOfComment:
_error(nls.localize('UnexpectedEndOfComment', 'Unexpected end of comment'));
_error(localize('UnexpectedEndOfComment', 'Unexpected end of comment'));
return true;
case Json.ScanError.UnexpectedEndOfString:
_error(nls.localize('UnexpectedEndOfString', 'Unexpected end of string'));
_error(localize('UnexpectedEndOfString', 'Unexpected end of string'));
return true;
}
return false;
@@ -876,13 +879,13 @@ export function parse(text: string, config = new JSONDocumentConfig()): JSONDocu
if (node.addItem(_parseValue(node, '' + count++))) {
while (_accept(Json.SyntaxKind.CommaToken)) {
if (!node.addItem(_parseValue(node, '' + count++)) && !_doc.config.ignoreDanglingComma) {
_error(nls.localize('ValueExpected', 'Value expected'));
_error(localize('ValueExpected', 'Value expected'));
}
}
}
if (_scanner.getToken() !== Json.SyntaxKind.CloseBracketToken) {
return _error(nls.localize('ExpectedCloseBracket', 'Expected comma or closing bracket'), node);
return _error(localize('ExpectedCloseBracket', 'Expected comma or closing bracket'), node);
}
return _finalize(node, true);
@@ -896,7 +899,7 @@ export function parse(text: string, config = new JSONDocumentConfig()): JSONDocu
// give a more helpful error message
let value = _scanner.getTokenValue();
if (value.length > 0 && (value.charAt(0) === '\'' || Json.isLetter(value.charAt(0).charCodeAt(0)))) {
_error(nls.localize('DoubleQuotesExpected', 'Property keys must be doublequoted'));
_error(localize('DoubleQuotesExpected', 'Property keys must be doublequoted'));
}
}
return null;
@@ -904,20 +907,20 @@ export function parse(text: string, config = new JSONDocumentConfig()): JSONDocu
let node = new PropertyASTNode(parent, key);
if (keysSeen[key.value]) {
_doc.warnings.push({ location: { start: node.key.start, end: node.key.end }, message: nls.localize('DuplicateKeyWarning', "Duplicate object key") });
_doc.warnings.push({ location: { start: node.key.start, end: node.key.end }, message: localize('DuplicateKeyWarning', "Duplicate object key") });
}
keysSeen[key.value] = true;
if (_scanner.getToken() === Json.SyntaxKind.ColonToken) {
node.colonOffset = _scanner.getTokenOffset();
} else {
return _error(nls.localize('ColonExpected', 'Colon expected'), node, [], [Json.SyntaxKind.CloseBraceToken, Json.SyntaxKind.CommaToken]);
return _error(localize('ColonExpected', 'Colon expected'), node, [], [Json.SyntaxKind.CloseBraceToken, Json.SyntaxKind.CommaToken]);
}
_scanner.scan(); // consume ColonToken
if (!node.setValue(_parseValue(node, key.value))) {
return _error(nls.localize('ValueExpected', 'Value expected'), node, [], [Json.SyntaxKind.CloseBraceToken, Json.SyntaxKind.CommaToken]);
return _error(localize('ValueExpected', 'Value expected'), node, [], [Json.SyntaxKind.CloseBraceToken, Json.SyntaxKind.CommaToken]);
}
node.end = node.value.end;
return node;
@@ -934,13 +937,13 @@ export function parse(text: string, config = new JSONDocumentConfig()): JSONDocu
if (node.addProperty(_parseProperty(node, keysSeen))) {
while (_accept(Json.SyntaxKind.CommaToken)) {
if (!node.addProperty(_parseProperty(node, keysSeen)) && !_doc.config.ignoreDanglingComma) {
_error(nls.localize('PropertyExpected', 'Property expected'));
_error(localize('PropertyExpected', 'Property expected'));
}
}
}
if (_scanner.getToken() !== Json.SyntaxKind.CloseBraceToken) {
return _error(nls.localize('ExpectedCloseBrace', 'Expected comma or closing brace'), node);
return _error(localize('ExpectedCloseBrace', 'Expected comma or closing brace'), node);
}
return _finalize(node, true);
}
@@ -969,11 +972,11 @@ export function parse(text: string, config = new JSONDocumentConfig()): JSONDocu
try {
let numberValue = JSON.parse(tokenValue);
if (typeof numberValue !== 'number') {
return _error(nls.localize('InvalidNumberFormat', 'Invalid number format'), node);
return _error(localize('InvalidNumberFormat', 'Invalid number format'), node);
}
node.value = numberValue;
} catch (e) {
return _error(nls.localize('InvalidNumberFormat', 'Invalid number format'), node);
return _error(localize('InvalidNumberFormat', 'Invalid number format'), node);
}
node.isInteger = tokenValue.indexOf('.') === -1;
}
@@ -1006,9 +1009,9 @@ export function parse(text: string, config = new JSONDocumentConfig()): JSONDocu
_doc.root = _parseValue(null, null);
if (!_doc.root) {
_error(nls.localize('Invalid symbol', 'Expected a JSON object, array or literal'));
_error(localize('Invalid symbol', 'Expected a JSON object, array or literal'));
} else if (_scanner.getToken() !== Json.SyntaxKind.EOF) {
_error(nls.localize('End of file expected', 'End of file expected'));
_error(localize('End of file expected', 'End of file expected'));
}
return _doc;
}
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import nls = require('./utils/nls');
import Json = require('./json-toolbox/json');
import {IJSONSchema} from './json-toolbox/jsonSchema';
import {IXHROptions, IXHRResponse, getErrorStatusDescription} from './utils/httpRequest';
@@ -12,6 +11,9 @@ import URI from './utils/uri';
import Strings = require('./utils/strings');
import Parser = require('./jsonParser');
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export interface IJSONSchemaService {
/**
@@ -350,18 +352,18 @@ export class JSONSchemaService implements IJSONSchemaService {
request => {
let content = request.responseText;
if (!content) {
let errorMessage = nls.localize('json.schema.nocontent', 'Unable to load schema from \'{0}\': No content.', toDisplayString(url));
let errorMessage = localize('json.schema.nocontent', 'Unable to load schema from \'{0}\': No content.', toDisplayString(url));
return new UnresolvedSchema(<IJSONSchema>{}, [errorMessage]);
}
let schemaContent: IJSONSchema = {};
let jsonErrors = [];
schemaContent = Json.parse(content, jsonErrors);
let errors = jsonErrors.length ? [nls.localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': {1}.', toDisplayString(url), jsonErrors[0])] : [];
let errors = jsonErrors.length ? [localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': {1}.', toDisplayString(url), jsonErrors[0])] : [];
return new UnresolvedSchema(schemaContent, errors);
},
(error: IXHRResponse) => {
let errorMessage = nls.localize('json.schema.unabletoload', 'Unable to load schema from \'{0}\': {1}', toDisplayString(url), error.responseText || getErrorStatusDescription(error.status) || error.toString());
let errorMessage = localize('json.schema.unabletoload', 'Unable to load schema from \'{0}\': {1}', toDisplayString(url), error.responseText || getErrorStatusDescription(error.status) || error.toString());
return new UnresolvedSchema(<IJSONSchema>{}, [errorMessage]);
}
);
@@ -393,7 +395,7 @@ export class JSONSchemaService implements IJSONSchemaService {
}
}
} else {
resolveErrors.push(nls.localize('json.schema.invalidref', '$ref \'{0}\' in {1} can not be resolved.', linkPath, linkedSchema.id));
resolveErrors.push(localize('json.schema.invalidref', '$ref \'{0}\' in {1} can not be resolved.', linkPath, linkedSchema.id));
}
delete node.$ref;
};
@@ -402,7 +404,7 @@ export class JSONSchemaService implements IJSONSchemaService {
return this.getOrAddSchemaHandle(uri).getUnresolvedSchema().then(unresolvedSchema => {
if (unresolvedSchema.errors.length) {
let loc = linkPath ? uri + '#' + linkPath : uri;
resolveErrors.push(nls.localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
resolveErrors.push(localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
}
resolveLink(node, unresolvedSchema.schema, linkPath);
return resolveRefs(node, unresolvedSchema.schema);
@@ -6,11 +6,13 @@
import {MarkedString, CompletionItemKind} from 'vscode-languageserver';
import Strings = require('../utils/strings');
import nls = require('../utils/nls');
import {IJSONWorkerContribution, ISuggestionsCollector} from '../jsonContributions';
import {IRequestService} from '../jsonSchemaService';
import {JSONLocation} from '../jsonLocation';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export class BowerJSONContribution implements IJSONWorkerContribution {
private requestService : IRequestService;
@@ -41,7 +43,7 @@ export class BowerJSONContribution implements IJSONWorkerContribution {
'main': '{{pathToMain}}',
'dependencies': {}
};
result.add({ kind: CompletionItemKind.Class, label: nls.localize('json.bower.default', 'Default bower.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
result.add({ kind: CompletionItemKind.Class, label: localize('json.bower.default', 'Default bower.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
}
return null;
}
@@ -77,11 +79,11 @@ export class BowerJSONContribution implements IJSONWorkerContribution {
// ignore
}
} else {
result.error(nls.localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', success.responseText));
result.error(localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', success.responseText));
return 0;
}
}, (error) => {
result.error(nls.localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', error.responseText));
result.error(localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', error.responseText));
return 0;
});
} else {
@@ -110,7 +112,7 @@ export class BowerJSONContribution implements IJSONWorkerContribution {
if (this.isBowerFile(resource) && (location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
let pack = location.getSegments()[location.getSegments().length - 1];
let htmlContent : MarkedString[] = [];
htmlContent.push(nls.localize('json.bower.package.hover', '{0}', pack));
htmlContent.push(localize('json.bower.package.hover', '{0}', pack));
let queryUrl = 'https://bower.herokuapp.com/packages/' + encodeURIComponent(pack);
@@ -6,23 +6,25 @@
import {MarkedString, CompletionItemKind, CompletionItem} from 'vscode-languageserver';
import Strings = require('../utils/strings');
import nls = require('../utils/nls');
import {IJSONWorkerContribution, ISuggestionsCollector} from '../jsonContributions';
import {JSONLocation} from '../jsonLocation';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
let globProperties:CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: nls.localize('fileLabel', "Files by Extension"), insertText: '"**/*.{{extension}}": true', documentation: nls.localize('fileDescription', "Match all files of a specific file extension.")},
{ kind: CompletionItemKind.Value, label: nls.localize('filesLabel', "Files with Multiple Extensions"), insertText: '"**/*.{ext1,ext2,ext3}": true', documentation: nls.localize('filesDescription', "Match all files with any of the file extensions.")},
{ kind: CompletionItemKind.Value, label: nls.localize('derivedLabel', "Files with Siblings by Name"), insertText: '"**/*.{{source-extension}}": { "when": "$(basename).{{target-extension}}" }', documentation: nls.localize('derivedDescription', "Match files that have siblings with the same name but a different extension.")},
{ kind: CompletionItemKind.Value, label: nls.localize('topFolderLabel', "Folder by Name (Top Level)"), insertText: '"{{name}}": true', documentation: nls.localize('topFolderDescription', "Match a top level folder with a specific name.")},
{ kind: CompletionItemKind.Value, label: nls.localize('topFoldersLabel', "Folders with Multiple Names (Top Level)"), insertText: '"{folder1,folder2,folder3}": true', documentation: nls.localize('topFoldersDescription', "Match multiple top level folders.")},
{ kind: CompletionItemKind.Value, label: nls.localize('folderLabel', "Folder by Name (Any Location)"), insertText: '"**/{{name}}": true', documentation: nls.localize('folderDescription', "Match a folder with a specific name in any location.")},
{ kind: CompletionItemKind.Value, label: localize('fileLabel', "Files by Extension"), insertText: '"**/*.{{extension}}": true', documentation: localize('fileDescription', "Match all files of a specific file extension.")},
{ kind: CompletionItemKind.Value, label: localize('filesLabel', "Files with Multiple Extensions"), insertText: '"**/*.{ext1,ext2,ext3}": true', documentation: localize('filesDescription', "Match all files with any of the file extensions.")},
{ kind: CompletionItemKind.Value, label: localize('derivedLabel', "Files with Siblings by Name"), insertText: '"**/*.{{source-extension}}": { "when": "$(basename).{{target-extension}}" }', documentation: localize('derivedDescription', "Match files that have siblings with the same name but a different extension.")},
{ kind: CompletionItemKind.Value, label: localize('topFolderLabel', "Folder by Name (Top Level)"), insertText: '"{{name}}": true', documentation: localize('topFolderDescription', "Match a top level folder with a specific name.")},
{ kind: CompletionItemKind.Value, label: localize('topFoldersLabel', "Folders with Multiple Names (Top Level)"), insertText: '"{folder1,folder2,folder3}": true', documentation: localize('topFoldersDescription', "Match multiple top level folders.")},
{ kind: CompletionItemKind.Value, label: localize('folderLabel', "Folder by Name (Any Location)"), insertText: '"**/{{name}}": true', documentation: localize('folderDescription', "Match a folder with a specific name in any location.")},
];
let globValues:CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: nls.localize('trueLabel', "True"), insertText: 'true', documentation: nls.localize('trueDescription', "Enable the pattern.")},
{ kind: CompletionItemKind.Value, label: nls.localize('falseLabel', "False"), insertText: 'false', documentation: nls.localize('falseDescription', "Disable the pattern.")},
{ kind: CompletionItemKind.Value, label: nls.localize('derivedLabel', "Files with Siblings by Name"), insertText: '{ "when": "$(basename).{{extension}}" }', documentation: nls.localize('siblingsDescription', "Match files that have siblings with the same name but a different extension.")}
{ kind: CompletionItemKind.Value, label: localize('trueLabel', "True"), insertText: 'true', documentation: localize('trueDescription', "Enable the pattern.")},
{ kind: CompletionItemKind.Value, label: localize('falseLabel', "False"), insertText: 'false', documentation: localize('falseDescription', "Disable the pattern.")},
{ kind: CompletionItemKind.Value, label: localize('derivedLabel', "Files with Siblings by Name"), insertText: '{ "when": "$(basename).{{extension}}" }', documentation: localize('siblingsDescription', "Match files that have siblings with the same name but a different extension.")}
];
export class GlobPatternContribution implements IJSONWorkerContribution {
@@ -6,11 +6,13 @@
import {MarkedString, CompletionItemKind} from 'vscode-languageserver';
import Strings = require('../utils/strings');
import nls = require('../utils/nls');
import {IJSONWorkerContribution, ISuggestionsCollector} from '../jsonContributions';
import {IRequestService} from '../jsonSchemaService';
import {JSONLocation} from '../jsonLocation';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
let LIMIT = 40;
export class PackageJSONContribution implements IJSONWorkerContribution {
@@ -42,7 +44,7 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
'main': '{{pathToMain}}',
'dependencies': {}
};
result.add({ kind: CompletionItemKind.Module, label: nls.localize('json.package.default', 'Default package.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
result.add({ kind: CompletionItemKind.Module, label: localize('json.package.default', 'Default package.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
}
return null;
}
@@ -83,11 +85,11 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
// ignore
}
} else {
result.error(nls.localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
result.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
return 0;
}
}, (error) => {
result.error(nls.localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', error.responseText));
result.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', error.responseText));
return 0;
});
} else {
@@ -119,11 +121,11 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
if (obj && obj.version) {
let version = obj.version;
let name = JSON.stringify(version);
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: nls.localize('json.npm.latestversion', 'The currently latest version of the package') });
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: localize('json.npm.latestversion', 'The currently latest version of the package') });
name = JSON.stringify('^' + version);
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: nls.localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)') });
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)') });
name = JSON.stringify('~' + version);
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: nls.localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)') });
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)') });
}
} catch (e) {
// ignore
@@ -141,7 +143,7 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
let pack = location.getSegments()[location.getSegments().length - 1];
let htmlContent : MarkedString[] = [];
htmlContent.push(nls.localize('json.npm.package.hover', '{0}', pack));
htmlContent.push(localize('json.npm.package.hover', '{0}', pack));
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(pack) + '/latest';
@@ -155,7 +157,7 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
htmlContent.push(obj.description);
}
if (obj.version) {
htmlContent.push(nls.localize('json.npm.version.hover', 'Latest version: {0}', obj.version));
htmlContent.push(localize('json.npm.version.hover', 'Latest version: {0}', obj.version));
}
}
} catch (e) {
@@ -6,12 +6,15 @@
import {MarkedString, CompletionItemKind, CompletionItem} from 'vscode-languageserver';
import Strings = require('../utils/strings');
import nls = require('../utils/nls');
import {IXHRResponse, getErrorStatusDescription} from '../utils/httpRequest';
import {IJSONWorkerContribution, ISuggestionsCollector} from '../jsonContributions';
import {IRequestService} from '../jsonSchemaService';
import {JSONLocation} from '../jsonLocation';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
const FEED_INDEX_URL = 'https://api.nuget.org/v3/index.json';
const LIMIT = 30;
const RESOLVE_ID = 'ProjectJSONContribution-';
@@ -31,7 +34,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
private cachedProjects: { [id: string]: { version: string, description: string, time: number }} = {};
private cacheSize: number = 0;
private nugetIndexPromise: Thenable<NugetServices>;
public constructor(requestService: IRequestService) {
this.requestService = requestService;
}
@@ -39,7 +42,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
private isProjectJSONFile(resource: string): boolean {
return Strings.endsWith(resource, '/project.json');
}
private completeWithCache(id: string, item: CompletionItem) : boolean {
let entry = this.cachedProjects[id];
if (entry) {
@@ -61,7 +64,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
this.cacheSize++;
if (this.cacheSize > 50) {
let currentTime = new Date().getTime() ;
for (var id in this.cachedProjects) {
for (let id in this.cachedProjects) {
let entry = this.cachedProjects[id];
if (currentTime - entry.time > CACHE_EXPIRY) {
delete this.cachedProjects[id];
@@ -70,7 +73,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
}
}
}
private getNugetIndex() : Thenable<NugetServices> {
if (!this.nugetIndexPromise) {
this.nugetIndexPromise = this.makeJSONRequest<any>(FEED_INDEX_URL).then(indexContent => {
@@ -95,7 +98,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
return this.getNugetIndex().then(services => {
let serviceURL = services[serviceType];
if (!serviceURL) {
return Promise.reject<string>(nls.localize('json.nugget.error.missingservice', 'NuGet index document is missing service {0}', serviceType));
return Promise.reject<string>(localize('json.nugget.error.missingservice', 'NuGet index document is missing service {0}', serviceType));
}
return serviceURL;
});
@@ -111,7 +114,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
'dnxcore50': {}
}
};
result.add({ kind: CompletionItemKind.Class, label: nls.localize('json.project.default', 'Default project.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
result.add({ kind: CompletionItemKind.Class, label: localize('json.project.default', 'Default project.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
}
return null;
}
@@ -124,12 +127,12 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
try {
return <T> JSON.parse(success.responseText);
} catch (e) {
return Promise.reject<T>(nls.localize('json.nugget.error.invalidformat', '{0} is not a valid JSON document', url));
return Promise.reject<T>(localize('json.nugget.error.invalidformat', '{0} is not a valid JSON document', url));
}
}
return Promise.reject<T>(nls.localize('json.nugget.error.indexaccess', 'Request to {0} failed: {1}', url, success.responseText));
return Promise.reject<T>(localize('json.nugget.error.indexaccess', 'Request to {0} failed: {1}', url, success.responseText));
}, (error: IXHRResponse) => {
return Promise.reject<T>(nls.localize('json.nugget.error.access', 'Request to {0} failed: {1}', url, getErrorStatusDescription(error.status)));
return Promise.reject<T>(localize('json.nugget.error.access', 'Request to {0} failed: {1}', url, getErrorStatusDescription(error.status)));
});
}
@@ -211,7 +214,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
let queryUrl = service + '?q=' + encodeURIComponent(pack) +'&take=' + 5;
return this.makeJSONRequest<any>(queryUrl).then(resultObj => {
let htmlContent : MarkedString[] = [];
htmlContent.push(nls.localize('json.nugget.package.hover', '{0}', pack));
htmlContent.push(localize('json.nugget.package.hover', '{0}', pack));
if (Array.isArray(resultObj.data)) {
let results = <any[]> resultObj.data;
for (let i = 0; i < results.length; i++) {
@@ -222,7 +225,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
htmlContent.push(res.description);
}
if (res.version) {
htmlContent.push(nls.localize('json.nugget.version.hover', 'Latest version: {0}', res.version));
htmlContent.push(localize('json.nugget.version.hover', 'Latest version: {0}', res.version));
}
break;
}
@@ -238,7 +241,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
}
return null;
}
public resolveSuggestion(item: CompletionItem) : Thenable<CompletionItem> {
if (item.data && Strings.startsWith(item.data, RESOLVE_ID)) {
let pack = item.data.substring(RESOLVE_ID.length);
+3
View File
@@ -31,6 +31,9 @@ import {PackageJSONContribution} from './jsoncontributions/packageJSONContributi
import {ProjectJSONContribution} from './jsoncontributions/projectJSONContribution';
import {GlobPatternContribution} from './jsoncontributions/globPatternContribution';
import * as nls from 'vscode-nls';
nls.config(process.env['VSCODE_NLS_CONFIG']);
namespace TelemetryNotification {
export const type: NotificationType<{ key: string, data: any }> = { get method() { return 'telemetry'; } };
}
+22 -20
View File
@@ -9,7 +9,9 @@ import { parse as parseUrl } from 'url';
import { getProxyAgent } from './proxy';
import https = require('https');
import http = require('http');
import nls = require('./nls');
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export interface IXHROptions {
type?: string;
@@ -149,24 +151,24 @@ export function getErrorStatusDescription(status: number) : string {
return void 0;
}
switch (status) {
case 400: return nls.localize('status.400', 'Bad request. The request cannot be fulfilled due to bad syntax.');
case 401: return nls.localize('status.401', 'Unauthorized. The server is refusing to respond.');
case 403: return nls.localize('status.403', 'Forbidden. The server is refusing to respond.');
case 404: return nls.localize('status.404', 'Not Found. The requested location could not be found.');
case 405: return nls.localize('status.405', 'Method not allowed. A request was made using a request method not supported by that location.');
case 406: return nls.localize('status.406', 'Not Acceptable. The server can only generate a response that is not accepted by the client.');
case 407: return nls.localize('status.407', 'Proxy Authentication Required. The client must first authenticate itself with the proxy.');
case 408: return nls.localize('status.408', 'Request Timeout. The server timed out waiting for the request.');
case 409: return nls.localize('status.409', 'Conflict. The request could not be completed because of a conflict in the request.');
case 410: return nls.localize('status.410', 'Gone. The requested page is no longer available.');
case 411: return nls.localize('status.411', 'Length Required. The "Content-Length" is not defined.');
case 412: return nls.localize('status.412', 'Precondition Failed. The precondition given in the request evaluated to false by the server.');
case 413: return nls.localize('status.413', 'Request Entity Too Large. The server will not accept the request, because the request entity is too large.');
case 414: return nls.localize('status.414', 'Request-URI Too Long. The server will not accept the request, because the URL is too long.');
case 415: return nls.localize('status.415', 'Unsupported Media Type. The server will not accept the request, because the media type is not supported.');
case 500: return nls.localize('status.500', 'Internal Server Error.');
case 501: return nls.localize('status.501', 'Not Implemented. The server either does not recognize the request method, or it lacks the ability to fulfill the request.');
case 503: return nls.localize('status.503', 'Service Unavailable. The server is currently unavailable (overloaded or down).');
default: return nls.localize('status.416', 'HTTP status code {0}', status);
case 400: return localize('status.400', 'Bad request. The request cannot be fulfilled due to bad syntax.');
case 401: return localize('status.401', 'Unauthorized. The server is refusing to respond.');
case 403: return localize('status.403', 'Forbidden. The server is refusing to respond.');
case 404: return localize('status.404', 'Not Found. The requested location could not be found.');
case 405: return localize('status.405', 'Method not allowed. A request was made using a request method not supported by that location.');
case 406: return localize('status.406', 'Not Acceptable. The server can only generate a response that is not accepted by the client.');
case 407: return localize('status.407', 'Proxy Authentication Required. The client must first authenticate itself with the proxy.');
case 408: return localize('status.408', 'Request Timeout. The server timed out waiting for the request.');
case 409: return localize('status.409', 'Conflict. The request could not be completed because of a conflict in the request.');
case 410: return localize('status.410', 'Gone. The requested page is no longer available.');
case 411: return localize('status.411', 'Length Required. The "Content-Length" is not defined.');
case 412: return localize('status.412', 'Precondition Failed. The precondition given in the request evaluated to false by the server.');
case 413: return localize('status.413', 'Request Entity Too Large. The server will not accept the request, because the request entity is too large.');
case 414: return localize('status.414', 'Request-URI Too Long. The server will not accept the request, because the URL is too long.');
case 415: return localize('status.415', 'Unsupported Media Type. The server will not accept the request, because the media type is not supported.');
case 500: return localize('status.500', 'Internal Server Error.');
case 501: return localize('status.501', 'Not Implemented. The server either does not recognize the request method, or it lacks the ability to fulfill the request.');
case 503: return localize('status.503', 'Service Unavailable. The server is currently unavailable (overloaded or down).');
default: return localize('status.416', 'HTTP status code {0}', status);
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
export function localize(key: string, message: string, ...formatArgs: any[]) {
export function localize2(key: string, message: string, ...formatArgs: any[]) {
if (formatArgs.length > 0) {
return message.replace(/\{(\d+)\}/g, function(match, rest) {
var index = rest[0];