vscode-json-languageservice
Advanced tools
Comparing version 2.0.0-next.6 to 2.0.0-next.7
@@ -43,3 +43,4 @@ export interface JSONSchema { | ||
errorMessage?: string; | ||
deprecatedMessage?: string; | ||
deprecationMessage?: string; | ||
enumDescriptions?: string[]; | ||
} | ||
@@ -46,0 +47,0 @@ export interface JSONSchemaMap { |
@@ -22,2 +22,6 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var localize = nls.loadMessageBundle(); | ||
(function (ErrorCode) { | ||
ErrorCode[ErrorCode["EnumValueMismatch"] = 1] = "EnumValueMismatch"; | ||
})(exports.ErrorCode || (exports.ErrorCode = {})); | ||
var ErrorCode = exports.ErrorCode; | ||
var ASTNode = (function () { | ||
@@ -164,2 +168,3 @@ function ASTNode(parent, type, location, start, end) { | ||
bestMatch.matchingSchemas.push.apply(bestMatch.matchingSchemas, subMatchingSchemas); | ||
bestMatch.validationResult.mergeEnumValueMismatch(subValidationResult); | ||
} | ||
@@ -195,4 +200,6 @@ } | ||
location: { start: this.start, end: this.end }, | ||
message: schema.errorMessage || localize('enumWarning', 'Value is not an accepted value. Valid values: {0}', JSON.stringify(schema.enum)) | ||
code: ErrorCode.EnumValueMismatch, | ||
message: schema.errorMessage || localize('enumWarning', 'Value is not accepted. Valid values: {0}', JSON.stringify(schema.enum)) | ||
}); | ||
validationResult.mismatchedEnumValues = schema.enum; | ||
} | ||
@@ -203,6 +210,6 @@ else { | ||
} | ||
if (schema.deprecatedMessage) { | ||
if (schema.deprecationMessage) { | ||
validationResult.warnings.push({ | ||
location: { start: this.start, end: this.end }, | ||
message: schema.deprecatedMessage | ||
message: schema.deprecationMessage | ||
}); | ||
@@ -663,2 +670,3 @@ } | ||
this.enumValueMatch = false; | ||
this.mismatchedEnumValues = null; | ||
} | ||
@@ -678,2 +686,16 @@ ValidationResult.prototype.hasErrors = function () { | ||
}; | ||
ValidationResult.prototype.mergeEnumValueMismatch = function (validationResult) { | ||
if (this.mismatchedEnumValues && validationResult.mismatchedEnumValues) { | ||
this.mismatchedEnumValues = this.mismatchedEnumValues.concat(validationResult.mismatchedEnumValues); | ||
for (var _i = 0, _a = this.warnings; _i < _a.length; _i++) { | ||
var warning = _a[_i]; | ||
if (warning.code === ErrorCode.EnumValueMismatch) { | ||
warning.message = localize('enumWarning', 'Value is not accepted. Valid values: {0}', JSON.stringify(this.mismatchedEnumValues)); | ||
} | ||
} | ||
} | ||
else { | ||
this.mismatchedEnumValues = null; | ||
} | ||
}; | ||
ValidationResult.prototype.mergePropertyMatch = function (propertyValidationResult) { | ||
@@ -680,0 +702,0 @@ this.merge(propertyValidationResult); |
@@ -191,3 +191,5 @@ (function (factory) { | ||
var propertySchema = schemaProperties_1[key]; | ||
collector.add({ kind: 10 /* Property */, label: key, insertText: _this.getInsertTextForProperty(key, propertySchema, addValue, separatorAfter), filterText: _this.getFilterTextForValue(key), documentation: propertySchema.description || '' }); | ||
if (!propertySchema.deprecationMessage) { | ||
collector.add({ kind: 10 /* Property */, label: key, insertText: _this.getInsertTextForProperty(key, propertySchema, addValue, separatorAfter), filterText: _this.getFilterTextForValue(key), documentation: propertySchema.description || '' }); | ||
} | ||
}); | ||
@@ -409,5 +411,11 @@ } | ||
JSONCompletion.prototype.addEnumValueCompletions = function (schema, separatorAfter, collector) { | ||
var _this = this; | ||
if (Array.isArray(schema.enum)) { | ||
schema.enum.forEach(function (enm) { return collector.add({ kind: _this.getSuggestionKind(schema.type), label: _this.getLabelForValue(enm), insertText: _this.getInsertTextForValue(enm, separatorAfter), documentation: '' }); }); | ||
for (var i = 0, length = schema.enum.length; i < length; i++) { | ||
var enm = schema.enum[i]; | ||
var documentation = schema.description; | ||
if (schema.enumDescriptions && i < schema.enumDescriptions.length) { | ||
documentation = schema.enumDescriptions[i]; | ||
} | ||
collector.add({ kind: this.getSuggestionKind(schema.type), label: this.getLabelForValue(enm), insertText: this.getInsertTextForValue(enm, separatorAfter), documentation: documentation }); | ||
} | ||
} | ||
@@ -414,0 +422,0 @@ }; |
@@ -61,5 +61,10 @@ (function (factory) { | ||
var description_1 = null; | ||
var enumValueDescription_1 = null; | ||
matchingSchemas.every(function (s) { | ||
if (s.node === node && !s.inverted && s.schema) { | ||
description_1 = description_1 || s.schema.description; | ||
if (s.schema.enum && s.schema.enumDescriptions) { | ||
var idx = s.schema.enum.indexOf(node.getValue()); | ||
enumValueDescription_1 = s.schema.enumDescriptions[idx]; | ||
} | ||
} | ||
@@ -69,2 +74,5 @@ return true; | ||
if (description_1) { | ||
if (enumValueDescription_1) { | ||
description_1 = description_1 + '\n\n' + enumValueDescription_1; | ||
} | ||
return createHover([vscode_languageserver_types_1.MarkedString.fromPlainText(description_1)]); | ||
@@ -71,0 +79,0 @@ } |
@@ -270,3 +270,3 @@ (function (factory) { | ||
schemaContent = Json.parse(content, jsonErrors); | ||
var errors = jsonErrors.length ? [localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': {1}.', toDisplayString(url), jsonErrors[0])] : []; | ||
var errors = jsonErrors.length ? [localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': {1}.', toDisplayString(url), Json.getParseErrorMessage(jsonErrors[0]))] : []; | ||
return new UnresolvedSchema(schemaContent, errors); | ||
@@ -273,0 +273,0 @@ }, function (error) { |
{ | ||
"name": "vscode-json-languageservice", | ||
"version": "2.0.0-next.6", | ||
"version": "2.0.0-next.7", | ||
"description": "Language service for JSON", | ||
@@ -5,0 +5,0 @@ "main": "./lib/jsonLanguageService.js", |
154867
3037