monaco-editor
Version:
A browser based code editor
1,213 lines • 191 kB
JavaScript
define("vs/language/json/json.worker", ["../../initialize-BJOLaCxY", "../../main-Du7ctCk0", "../../main-CLp3wP3p", "../../index-CXwHBsfm"], (function(initialize, main$1, main, index) {
"use strict";
function equals(one, other) {
if (one === other) {
return true;
}
if (one === null || one === void 0 || other === null || other === void 0) {
return false;
}
if (typeof one !== typeof other) {
return false;
}
if (typeof one !== "object") {
return false;
}
if (Array.isArray(one) !== Array.isArray(other)) {
return false;
}
let i, key;
if (Array.isArray(one)) {
if (one.length !== other.length) {
return false;
}
for (i = 0; i < one.length; i++) {
if (!equals(one[i], other[i])) {
return false;
}
}
} else {
const oneKeys = [];
for (key in one) {
oneKeys.push(key);
}
oneKeys.sort();
const otherKeys = [];
for (key in other) {
otherKeys.push(key);
}
otherKeys.sort();
if (!equals(oneKeys, otherKeys)) {
return false;
}
for (i = 0; i < oneKeys.length; i++) {
if (!equals(one[oneKeys[i]], other[oneKeys[i]])) {
return false;
}
}
}
return true;
}
function isNumber(val) {
return typeof val === "number";
}
function isDefined(val) {
return typeof val !== "undefined";
}
function isBoolean(val) {
return typeof val === "boolean";
}
function isString(val) {
return typeof val === "string";
}
function isObject(val) {
return typeof val === "object" && val !== null && !Array.isArray(val);
}
function startsWith(haystack, needle) {
if (haystack.length < needle.length) {
return false;
}
for (let i = 0; i < needle.length; i++) {
if (haystack[i] !== needle[i]) {
return false;
}
}
return true;
}
function endsWith(haystack, needle) {
const diff = haystack.length - needle.length;
if (diff > 0) {
return haystack.lastIndexOf(needle) === diff;
} else if (diff === 0) {
return haystack === needle;
} else {
return false;
}
}
function extendedRegExp(pattern) {
let flags = "";
if (startsWith(pattern, "(?i)")) {
pattern = pattern.substring(4);
flags = "i";
}
try {
return new RegExp(pattern, flags + "u");
} catch (e) {
try {
return new RegExp(pattern, flags);
} catch (e2) {
return void 0;
}
}
}
function stringLength(str) {
let count = 0;
for (let i = 0; i < str.length; i++) {
count++;
const code = str.charCodeAt(i);
if (55296 <= code && code <= 56319) {
i++;
}
}
return count;
}
var ErrorCode;
(function(ErrorCode2) {
ErrorCode2[ErrorCode2["Undefined"] = 0] = "Undefined";
ErrorCode2[ErrorCode2["EnumValueMismatch"] = 1] = "EnumValueMismatch";
ErrorCode2[ErrorCode2["Deprecated"] = 2] = "Deprecated";
ErrorCode2[ErrorCode2["UnexpectedEndOfComment"] = 257] = "UnexpectedEndOfComment";
ErrorCode2[ErrorCode2["UnexpectedEndOfString"] = 258] = "UnexpectedEndOfString";
ErrorCode2[ErrorCode2["UnexpectedEndOfNumber"] = 259] = "UnexpectedEndOfNumber";
ErrorCode2[ErrorCode2["InvalidUnicode"] = 260] = "InvalidUnicode";
ErrorCode2[ErrorCode2["InvalidEscapeCharacter"] = 261] = "InvalidEscapeCharacter";
ErrorCode2[ErrorCode2["InvalidCharacter"] = 262] = "InvalidCharacter";
ErrorCode2[ErrorCode2["PropertyExpected"] = 513] = "PropertyExpected";
ErrorCode2[ErrorCode2["CommaExpected"] = 514] = "CommaExpected";
ErrorCode2[ErrorCode2["ColonExpected"] = 515] = "ColonExpected";
ErrorCode2[ErrorCode2["ValueExpected"] = 516] = "ValueExpected";
ErrorCode2[ErrorCode2["CommaOrCloseBacketExpected"] = 517] = "CommaOrCloseBacketExpected";
ErrorCode2[ErrorCode2["CommaOrCloseBraceExpected"] = 518] = "CommaOrCloseBraceExpected";
ErrorCode2[ErrorCode2["TrailingComma"] = 519] = "TrailingComma";
ErrorCode2[ErrorCode2["DuplicateKey"] = 520] = "DuplicateKey";
ErrorCode2[ErrorCode2["CommentNotPermitted"] = 521] = "CommentNotPermitted";
ErrorCode2[ErrorCode2["PropertyKeysMustBeDoublequoted"] = 528] = "PropertyKeysMustBeDoublequoted";
ErrorCode2[ErrorCode2["SchemaResolveError"] = 768] = "SchemaResolveError";
ErrorCode2[ErrorCode2["SchemaUnsupportedFeature"] = 769] = "SchemaUnsupportedFeature";
})(ErrorCode || (ErrorCode = {}));
var SchemaDraft;
(function(SchemaDraft2) {
SchemaDraft2[SchemaDraft2["v3"] = 3] = "v3";
SchemaDraft2[SchemaDraft2["v4"] = 4] = "v4";
SchemaDraft2[SchemaDraft2["v6"] = 6] = "v6";
SchemaDraft2[SchemaDraft2["v7"] = 7] = "v7";
SchemaDraft2[SchemaDraft2["v2019_09"] = 19] = "v2019_09";
SchemaDraft2[SchemaDraft2["v2020_12"] = 20] = "v2020_12";
})(SchemaDraft || (SchemaDraft = {}));
var ClientCapabilities;
(function(ClientCapabilities2) {
ClientCapabilities2.LATEST = {
textDocument: {
completion: {
completionItem: {
documentationFormat: [main.MarkupKind.Markdown, main.MarkupKind.PlainText],
commitCharactersSupport: true,
labelDetailsSupport: true
}
}
}
};
})(ClientCapabilities || (ClientCapabilities = {}));
const formats = {
"color-hex": { errorMessage: index.t("Invalid color format. Use #RGB, #RGBA, #RRGGBB or #RRGGBBAA."), pattern: /^#([0-9A-Fa-f]{3,4}|([0-9A-Fa-f]{2}){3,4})$/ },
"date-time": { errorMessage: index.t("String is not a RFC3339 date-time."), pattern: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/i },
"date": { errorMessage: index.t("String is not a RFC3339 date."), pattern: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/i },
"time": { errorMessage: index.t("String is not a RFC3339 time."), pattern: /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/i },
"email": { errorMessage: index.t("String is not an e-mail address."), pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}))$/ },
"hostname": { errorMessage: index.t("String is not a hostname."), pattern: /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i },
"ipv4": { errorMessage: index.t("String is not an IPv4 address."), pattern: /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/ },
"ipv6": { errorMessage: index.t("String is not an IPv6 address."), pattern: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i }
};
class ASTNodeImpl {
constructor(parent, offset, length = 0) {
this.offset = offset;
this.length = length;
this.parent = parent;
}
get children() {
return [];
}
toString() {
return "type: " + this.type + " (" + this.offset + "/" + this.length + ")" + (this.parent ? " parent: {" + this.parent.toString() + "}" : "");
}
}
class NullASTNodeImpl extends ASTNodeImpl {
constructor(parent, offset) {
super(parent, offset);
this.type = "null";
this.value = null;
}
}
class BooleanASTNodeImpl extends ASTNodeImpl {
constructor(parent, boolValue, offset) {
super(parent, offset);
this.type = "boolean";
this.value = boolValue;
}
}
class ArrayASTNodeImpl extends ASTNodeImpl {
constructor(parent, offset) {
super(parent, offset);
this.type = "array";
this.items = [];
}
get children() {
return this.items;
}
}
class NumberASTNodeImpl extends ASTNodeImpl {
constructor(parent, offset) {
super(parent, offset);
this.type = "number";
this.isInteger = true;
this.value = Number.NaN;
}
}
class StringASTNodeImpl extends ASTNodeImpl {
constructor(parent, offset, length) {
super(parent, offset, length);
this.type = "string";
this.value = "";
}
}
class PropertyASTNodeImpl extends ASTNodeImpl {
constructor(parent, offset, keyNode) {
super(parent, offset);
this.type = "property";
this.colonOffset = -1;
this.keyNode = keyNode;
}
get children() {
return this.valueNode ? [this.keyNode, this.valueNode] : [this.keyNode];
}
}
class ObjectASTNodeImpl extends ASTNodeImpl {
constructor(parent, offset) {
super(parent, offset);
this.type = "object";
this.properties = [];
}
get children() {
return this.properties;
}
}
function asSchema(schema) {
if (isBoolean(schema)) {
return schema ? {} : { "not": {} };
}
return schema;
}
var EnumMatch;
(function(EnumMatch2) {
EnumMatch2[EnumMatch2["Key"] = 0] = "Key";
EnumMatch2[EnumMatch2["Enum"] = 1] = "Enum";
})(EnumMatch || (EnumMatch = {}));
const schemaDraftFromId = {
"http://json-schema.org/draft-03/schema#": SchemaDraft.v3,
"http://json-schema.org/draft-04/schema#": SchemaDraft.v4,
"http://json-schema.org/draft-06/schema#": SchemaDraft.v6,
"http://json-schema.org/draft-07/schema#": SchemaDraft.v7,
"https://json-schema.org/draft/2019-09/schema": SchemaDraft.v2019_09,
"https://json-schema.org/draft/2020-12/schema": SchemaDraft.v2020_12
};
class EvaluationContext {
constructor(schemaDraft) {
this.schemaDraft = schemaDraft;
}
}
class SchemaCollector {
constructor(focusOffset = -1, exclude) {
this.focusOffset = focusOffset;
this.exclude = exclude;
this.schemas = [];
}
add(schema) {
this.schemas.push(schema);
}
merge(other) {
Array.prototype.push.apply(this.schemas, other.schemas);
}
include(node) {
return (this.focusOffset === -1 || contains(node, this.focusOffset)) && node !== this.exclude;
}
newSub() {
return new SchemaCollector(-1, this.exclude);
}
}
class NoOpSchemaCollector {
constructor() {
}
get schemas() {
return [];
}
add(_schema) {
}
merge(_other) {
}
include(_node) {
return true;
}
newSub() {
return this;
}
}
NoOpSchemaCollector.instance = new NoOpSchemaCollector();
class ValidationResult {
constructor() {
this.problems = [];
this.propertiesMatches = 0;
this.processedProperties = /* @__PURE__ */ new Set();
this.propertiesValueMatches = 0;
this.primaryValueMatches = 0;
this.enumValueMatch = false;
this.enumValues = void 0;
}
hasProblems() {
return !!this.problems.length;
}
merge(validationResult) {
this.problems = this.problems.concat(validationResult.problems);
this.propertiesMatches += validationResult.propertiesMatches;
this.propertiesValueMatches += validationResult.propertiesValueMatches;
this.mergeProcessedProperties(validationResult);
}
mergeEnumValues(validationResult) {
if (!this.enumValueMatch && !validationResult.enumValueMatch && this.enumValues && validationResult.enumValues) {
this.enumValues = this.enumValues.concat(validationResult.enumValues);
for (const error of this.problems) {
if (error.code === ErrorCode.EnumValueMismatch) {
error.message = index.t("Value is not accepted. Valid values: {0}.", this.enumValues.map((v) => JSON.stringify(v)).join(", "));
}
}
}
}
mergePropertyMatch(propertyValidationResult) {
this.problems = this.problems.concat(propertyValidationResult.problems);
this.propertiesMatches++;
if (propertyValidationResult.enumValueMatch || !propertyValidationResult.hasProblems() && propertyValidationResult.propertiesMatches) {
this.propertiesValueMatches++;
}
if (propertyValidationResult.enumValueMatch && propertyValidationResult.enumValues && propertyValidationResult.enumValues.length === 1) {
this.primaryValueMatches++;
}
}
mergeProcessedProperties(validationResult) {
validationResult.processedProperties.forEach((p) => this.processedProperties.add(p));
}
compare(other) {
const hasProblems = this.hasProblems();
if (hasProblems !== other.hasProblems()) {
return hasProblems ? -1 : 1;
}
if (this.enumValueMatch !== other.enumValueMatch) {
return other.enumValueMatch ? -1 : 1;
}
if (this.primaryValueMatches !== other.primaryValueMatches) {
return this.primaryValueMatches - other.primaryValueMatches;
}
if (this.propertiesValueMatches !== other.propertiesValueMatches) {
return this.propertiesValueMatches - other.propertiesValueMatches;
}
return this.propertiesMatches - other.propertiesMatches;
}
}
function newJSONDocument(root, diagnostics = []) {
return new JSONDocument(root, diagnostics, []);
}
function getNodeValue(node) {
return main$1.getNodeValue(node);
}
function getNodePath(node) {
return main$1.getNodePath(node);
}
function contains(node, offset, includeRightBound = false) {
return offset >= node.offset && offset < node.offset + node.length || includeRightBound && offset === node.offset + node.length;
}
class JSONDocument {
constructor(root, syntaxErrors = [], comments = []) {
this.root = root;
this.syntaxErrors = syntaxErrors;
this.comments = comments;
}
getNodeFromOffset(offset, includeRightBound = false) {
if (this.root) {
return main$1.findNodeAtOffset(this.root, offset, includeRightBound);
}
return void 0;
}
visit(visitor) {
if (this.root) {
const doVisit = (node) => {
let ctn = visitor(node);
const children = node.children;
if (Array.isArray(children)) {
for (let i = 0; i < children.length && ctn; i++) {
ctn = doVisit(children[i]);
}
}
return ctn;
};
doVisit(this.root);
}
}
validate(textDocument, schema, severity = main.DiagnosticSeverity.Warning, schemaDraft) {
if (this.root && schema) {
const validationResult = new ValidationResult();
validate(this.root, schema, validationResult, NoOpSchemaCollector.instance, new EvaluationContext(schemaDraft ?? getSchemaDraft(schema)));
return validationResult.problems.map((p) => {
const range = main.Range.create(textDocument.positionAt(p.location.offset), textDocument.positionAt(p.location.offset + p.location.length));
return main.Diagnostic.create(range, p.message, p.severity ?? severity, p.code);
});
}
return void 0;
}
getMatchingSchemas(schema, focusOffset = -1, exclude) {
if (this.root && schema) {
const matchingSchemas = new SchemaCollector(focusOffset, exclude);
const schemaDraft = getSchemaDraft(schema);
const context = new EvaluationContext(schemaDraft);
validate(this.root, schema, new ValidationResult(), matchingSchemas, context);
return matchingSchemas.schemas;
}
return [];
}
}
function getSchemaDraft(schema, fallBack = SchemaDraft.v2020_12) {
let schemaId = schema.$schema;
if (schemaId) {
return schemaDraftFromId[schemaId] ?? fallBack;
}
return fallBack;
}
function validate(n, schema, validationResult, matchingSchemas, context) {
if (!n || !matchingSchemas.include(n)) {
return;
}
if (n.type === "property") {
return validate(n.valueNode, schema, validationResult, matchingSchemas, context);
}
const node = n;
_validateNode();
switch (node.type) {
case "object":
_validateObjectNode(node);
break;
case "array":
_validateArrayNode(node);
break;
case "string":
_validateStringNode(node);
break;
case "number":
_validateNumberNode(node);
break;
}
matchingSchemas.add({ node, schema });
function _validateNode() {
function matchesType(type) {
return node.type === type || type === "integer" && node.type === "number" && node.isInteger;
}
if (Array.isArray(schema.type)) {
if (!schema.type.some(matchesType)) {
validationResult.problems.push({
location: { offset: node.offset, length: node.length },
message: schema.errorMessage || index.t("Incorrect type. Expected one of {0}.", schema.type.join(", "))
});
}
} else if (schema.type) {
if (!matchesType(schema.type)) {
validationResult.problems.push({
location: { offset: node.offset, length: node.length },
message: schema.errorMessage || index.t('Incorrect type. Expected "{0}".', schema.type)
});
}
}
if (Array.isArray(schema.allOf)) {
for (const subSchemaRef of schema.allOf) {
const subValidationResult = new ValidationResult();
const subMatchingSchemas = matchingSchemas.newSub();
validate(node, asSchema(subSchemaRef), subValidationResult, subMatchingSchemas, context);
validationResult.merge(subValidationResult);
matchingSchemas.merge(subMatchingSchemas);
}
}
const notSchema = asSchema(schema.not);
if (notSchema) {
const subValidationResult = new ValidationResult();
const subMatchingSchemas = matchingSchemas.newSub();
validate(node, notSchema, subValidationResult, subMatchingSchemas, context);
if (!subValidationResult.hasProblems()) {
validationResult.problems.push({
location: { offset: node.offset, length: node.length },
message: schema.errorMessage || index.t("Matches a schema that is not allowed.")
});
}
for (const ms of subMatchingSchemas.schemas) {
ms.inverted = !ms.inverted;
matchingSchemas.add(ms);
}
}
const testAlternatives = (alternatives, maxOneMatch) => {
const matches = [];
let bestMatch = void 0;
for (const subSchemaRef of alternatives) {
const subSchema = asSchema(subSchemaRef);
const subValidationResult = new ValidationResult();
const subMatchingSchemas = matchingSchemas.newSub();
validate(node, subSchema, subValidationResult, subMatchingSchemas, context);
if (!subValidationResult.hasProblems()) {
matches.push(subSchema);
}
if (!bestMatch) {
bestMatch = { schema: subSchema, validationResult: subValidationResult, matchingSchemas: subMatchingSchemas };
} else {
if (!maxOneMatch && !subValidationResult.hasProblems() && !bestMatch.validationResult.hasProblems()) {
bestMatch.matchingSchemas.merge(subMatchingSchemas);
bestMatch.validationResult.propertiesMatches += subValidationResult.propertiesMatches;
bestMatch.validationResult.propertiesValueMatches += subValidationResult.propertiesValueMatches;
bestMatch.validationResult.mergeProcessedProperties(subValidationResult);
} else {
const compareResult = subValidationResult.compare(bestMatch.validationResult);
if (compareResult > 0) {
bestMatch = { schema: subSchema, validationResult: subValidationResult, matchingSchemas: subMatchingSchemas };
} else if (compareResult === 0) {
bestMatch.matchingSchemas.merge(subMatchingSchemas);
bestMatch.validationResult.mergeEnumValues(subValidationResult);
}
}
}
}
if (matches.length > 1 && maxOneMatch) {
validationResult.problems.push({
location: { offset: node.offset, length: 1 },
message: index.t("Matches multiple schemas when only one must validate.")
});
}
if (bestMatch) {
validationResult.merge(bestMatch.validationResult);
matchingSchemas.merge(bestMatch.matchingSchemas);
}
return matches.length;
};
if (Array.isArray(schema.anyOf)) {
testAlternatives(schema.anyOf, false);
}
if (Array.isArray(schema.oneOf)) {
testAlternatives(schema.oneOf, true);
}
const testBranch = (schema2) => {
const subValidationResult = new ValidationResult();
const subMatchingSchemas = matchingSchemas.newSub();
validate(node, asSchema(schema2), subValidationResult, subMatchingSchemas, context);
validationResult.merge(subValidationResult);
matchingSchemas.merge(subMatchingSchemas);
};
const testCondition = (ifSchema2, thenSchema, elseSchema) => {
const subSchema = asSchema(ifSchema2);
const subValidationResult = new ValidationResult();
const subMatchingSchemas = matchingSchemas.newSub();
validate(node, subSchema, subValidationResult, subMatchingSchemas, context);
matchingSchemas.merge(subMatchingSchemas);
validationResult.mergeProcessedProperties(subValidationResult);
if (!subValidationResult.hasProblems()) {
if (thenSchema) {
testBranch(thenSchema);
}
} else if (elseSchema) {
testBranch(elseSchema);
}
};
const ifSchema = asSchema(schema.if);
if (ifSchema) {
testCondition(ifSchema, asSchema(schema.then), asSchema(schema.else));
}
if (Array.isArray(schema.enum)) {
const val = getNodeValue(node);
let enumValueMatch = false;
for (const e of schema.enum) {
if (equals(val, e)) {
enumValueMatch = true;
break;
}
}
validationResult.enumValues = schema.enum;
validationResult.enumValueMatch = enumValueMatch;
if (!enumValueMatch) {
validationResult.problems.push({
location: { offset: node.offset, length: node.length },
code: ErrorCode.EnumValueMismatch,
message: schema.errorMessage || index.t("Value is not accepted. Valid values: {0}.", schema.enum.map((v) => JSON.stringify(v)).join(", "))
});
}
}
if (isDefined(schema.const)) {
const val = getNodeValue(node);
if (!equals(val, schema.const)) {
validationResult.problems.push({
location: { offset: node.offset, length: node.length },
code: ErrorCode.EnumValueMismatch,
message: schema.errorMessage || index.t("Value must be {0}.", JSON.stringify(schema.const))
});
validationResult.enumValueMatch = false;
} else {
validationResult.enumValueMatch = true;
}
validationResult.enumValues = [schema.const];
}
let deprecationMessage = schema.deprecationMessage;
if (deprecationMessage || schema.deprecated) {
deprecationMessage = deprecationMessage || index.t("Value is deprecated");
let targetNode = node.parent?.type === "property" ? node.parent : node;
validationResult.problems.push({
location: { offset: targetNode.offset, length: targetNode.length },
severity: main.DiagnosticSeverity.Warning,
message: deprecationMessage,
code: ErrorCode.Deprecated
});
}
}
function _validateNumberNode(node2) {
const val = node2.value;
function normalizeFloats(float) {
const parts = /^(-?\d+)(?:\.(\d+))?(?:e([-+]\d+))?$/.exec(float.toString());
return parts && {
value: Number(parts[1] + (parts[2] || "")),
multiplier: (parts[2]?.length || 0) - (parseInt(parts[3]) || 0)
};
}
if (isNumber(schema.multipleOf)) {
let remainder = -1;
if (Number.isInteger(schema.multipleOf)) {
remainder = val % schema.multipleOf;
} else {
let normMultipleOf = normalizeFloats(schema.multipleOf);
let normValue = normalizeFloats(val);
if (normMultipleOf && normValue) {
const multiplier = 10 ** Math.abs(normValue.multiplier - normMultipleOf.multiplier);
if (normValue.multiplier < normMultipleOf.multiplier) {
normValue.value *= multiplier;
} else {
normMultipleOf.value *= multiplier;
}
remainder = normValue.value % normMultipleOf.value;
}
}
if (remainder !== 0) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Value is not divisible by {0}.", schema.multipleOf)
});
}
}
function getExclusiveLimit(limit, exclusive) {
if (isNumber(exclusive)) {
return exclusive;
}
if (isBoolean(exclusive) && exclusive) {
return limit;
}
return void 0;
}
function getLimit(limit, exclusive) {
if (!isBoolean(exclusive) || !exclusive) {
return limit;
}
return void 0;
}
const exclusiveMinimum = getExclusiveLimit(schema.minimum, schema.exclusiveMinimum);
if (isNumber(exclusiveMinimum) && val <= exclusiveMinimum) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Value is below the exclusive minimum of {0}.", exclusiveMinimum)
});
}
const exclusiveMaximum = getExclusiveLimit(schema.maximum, schema.exclusiveMaximum);
if (isNumber(exclusiveMaximum) && val >= exclusiveMaximum) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Value is above the exclusive maximum of {0}.", exclusiveMaximum)
});
}
const minimum = getLimit(schema.minimum, schema.exclusiveMinimum);
if (isNumber(minimum) && val < minimum) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Value is below the minimum of {0}.", minimum)
});
}
const maximum = getLimit(schema.maximum, schema.exclusiveMaximum);
if (isNumber(maximum) && val > maximum) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Value is above the maximum of {0}.", maximum)
});
}
}
function _validateStringNode(node2) {
if (isNumber(schema.minLength) && stringLength(node2.value) < schema.minLength) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("String is shorter than the minimum length of {0}.", schema.minLength)
});
}
if (isNumber(schema.maxLength) && stringLength(node2.value) > schema.maxLength) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("String is longer than the maximum length of {0}.", schema.maxLength)
});
}
if (isString(schema.pattern)) {
const regex = extendedRegExp(schema.pattern);
if (!regex?.test(node2.value)) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema.patternErrorMessage || schema.errorMessage || index.t('String does not match the pattern of "{0}".', schema.pattern)
});
}
}
if (schema.format) {
switch (schema.format) {
case "uri":
case "uri-reference":
{
let errorMessage;
if (!node2.value) {
errorMessage = index.t("URI expected.");
} else {
const match = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/.exec(node2.value);
if (!match) {
errorMessage = index.t("URI is expected.");
} else if (!match[2] && schema.format === "uri") {
errorMessage = index.t("URI with a scheme is expected.");
}
}
if (errorMessage) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema.patternErrorMessage || schema.errorMessage || index.t("String is not a URI: {0}", errorMessage)
});
}
}
break;
case "color-hex":
case "date-time":
case "date":
case "time":
case "email":
case "hostname":
case "ipv4":
case "ipv6":
const format2 = formats[schema.format];
if (!node2.value || !format2.pattern.exec(node2.value)) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema.patternErrorMessage || schema.errorMessage || format2.errorMessage
});
}
}
}
}
function _validateArrayNode(node2) {
let prefixItemsSchemas;
let additionalItemSchema;
if (context.schemaDraft >= SchemaDraft.v2020_12) {
prefixItemsSchemas = schema.prefixItems;
additionalItemSchema = !Array.isArray(schema.items) ? schema.items : void 0;
} else {
prefixItemsSchemas = Array.isArray(schema.items) ? schema.items : void 0;
additionalItemSchema = !Array.isArray(schema.items) ? schema.items : schema.additionalItems;
}
let index$1 = 0;
if (prefixItemsSchemas !== void 0) {
const max = Math.min(prefixItemsSchemas.length, node2.items.length);
for (; index$1 < max; index$1++) {
const subSchemaRef = prefixItemsSchemas[index$1];
const subSchema = asSchema(subSchemaRef);
const itemValidationResult = new ValidationResult();
const item = node2.items[index$1];
if (item) {
validate(item, subSchema, itemValidationResult, matchingSchemas, context);
validationResult.mergePropertyMatch(itemValidationResult);
}
validationResult.processedProperties.add(String(index$1));
}
}
if (additionalItemSchema !== void 0 && index$1 < node2.items.length) {
if (typeof additionalItemSchema === "boolean") {
if (additionalItemSchema === false) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Array has too many items according to schema. Expected {0} or fewer.", index$1)
});
}
for (; index$1 < node2.items.length; index$1++) {
validationResult.processedProperties.add(String(index$1));
validationResult.propertiesValueMatches++;
}
} else {
for (; index$1 < node2.items.length; index$1++) {
const itemValidationResult = new ValidationResult();
validate(node2.items[index$1], additionalItemSchema, itemValidationResult, matchingSchemas, context);
validationResult.mergePropertyMatch(itemValidationResult);
validationResult.processedProperties.add(String(index$1));
}
}
}
const containsSchema = asSchema(schema.contains);
if (containsSchema) {
let containsCount = 0;
for (let index2 = 0; index2 < node2.items.length; index2++) {
const item = node2.items[index2];
const itemValidationResult = new ValidationResult();
validate(item, containsSchema, itemValidationResult, NoOpSchemaCollector.instance, context);
if (!itemValidationResult.hasProblems()) {
containsCount++;
if (context.schemaDraft >= SchemaDraft.v2020_12) {
validationResult.processedProperties.add(String(index2));
}
}
}
if (containsCount === 0 && !isNumber(schema.minContains)) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema.errorMessage || index.t("Array does not contain required item.")
});
}
if (isNumber(schema.minContains) && containsCount < schema.minContains) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema.errorMessage || index.t("Array has too few items that match the contains contraint. Expected {0} or more.", schema.minContains)
});
}
if (isNumber(schema.maxContains) && containsCount > schema.maxContains) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema.errorMessage || index.t("Array has too many items that match the contains contraint. Expected {0} or less.", schema.maxContains)
});
}
}
const unevaluatedItems = schema.unevaluatedItems;
if (unevaluatedItems !== void 0) {
for (let i = 0; i < node2.items.length; i++) {
if (!validationResult.processedProperties.has(String(i))) {
if (unevaluatedItems === false) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Item does not match any validation rule from the array.")
});
} else {
const itemValidationResult = new ValidationResult();
validate(node2.items[i], schema.unevaluatedItems, itemValidationResult, matchingSchemas, context);
validationResult.mergePropertyMatch(itemValidationResult);
}
}
validationResult.processedProperties.add(String(i));
validationResult.propertiesValueMatches++;
}
}
if (isNumber(schema.minItems) && node2.items.length < schema.minItems) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Array has too few items. Expected {0} or more.", schema.minItems)
});
}
if (isNumber(schema.maxItems) && node2.items.length > schema.maxItems) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Array has too many items. Expected {0} or fewer.", schema.maxItems)
});
}
if (schema.uniqueItems === true) {
let hasDuplicates = function() {
for (let i = 0; i < values.length - 1; i++) {
const value = values[i];
for (let j = i + 1; j < values.length; j++) {
if (equals(value, values[j])) {
return true;
}
}
}
return false;
};
const values = getNodeValue(node2);
if (hasDuplicates()) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Array has duplicate items.")
});
}
}
}
function _validateObjectNode(node2) {
const seenKeys = /* @__PURE__ */ Object.create(null);
const unprocessedProperties = /* @__PURE__ */ new Set();
for (const propertyNode of node2.properties) {
const key = propertyNode.keyNode.value;
seenKeys[key] = propertyNode.valueNode;
unprocessedProperties.add(key);
}
if (Array.isArray(schema.required)) {
for (const propertyName of schema.required) {
if (!seenKeys[propertyName]) {
const keyNode = node2.parent && node2.parent.type === "property" && node2.parent.keyNode;
const location = keyNode ? { offset: keyNode.offset, length: keyNode.length } : { offset: node2.offset, length: 1 };
validationResult.problems.push({
location,
message: index.t('Missing property "{0}".', propertyName)
});
}
}
}
const propertyProcessed = (prop) => {
unprocessedProperties.delete(prop);
validationResult.processedProperties.add(prop);
};
if (schema.properties) {
for (const propertyName of Object.keys(schema.properties)) {
propertyProcessed(propertyName);
const propertySchema = schema.properties[propertyName];
const child = seenKeys[propertyName];
if (child) {
if (isBoolean(propertySchema)) {
if (!propertySchema) {
const propertyNode = child.parent;
validationResult.problems.push({
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
message: schema.errorMessage || index.t("Property {0} is not allowed.", propertyName)
});
} else {
validationResult.propertiesMatches++;
validationResult.propertiesValueMatches++;
}
} else {
const propertyValidationResult = new ValidationResult();
validate(child, propertySchema, propertyValidationResult, matchingSchemas, context);
validationResult.mergePropertyMatch(propertyValidationResult);
}
}
}
}
if (schema.patternProperties) {
for (const propertyPattern of Object.keys(schema.patternProperties)) {
const regex = extendedRegExp(propertyPattern);
if (regex) {
const processed = [];
for (const propertyName of unprocessedProperties) {
if (regex.test(propertyName)) {
processed.push(propertyName);
const child = seenKeys[propertyName];
if (child) {
const propertySchema = schema.patternProperties[propertyPattern];
if (isBoolean(propertySchema)) {
if (!propertySchema) {
const propertyNode = child.parent;
validationResult.problems.push({
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
message: schema.errorMessage || index.t("Property {0} is not allowed.", propertyName)
});
} else {
validationResult.propertiesMatches++;
validationResult.propertiesValueMatches++;
}
} else {
const propertyValidationResult = new ValidationResult();
validate(child, propertySchema, propertyValidationResult, matchingSchemas, context);
validationResult.mergePropertyMatch(propertyValidationResult);
}
}
}
}
processed.forEach(propertyProcessed);
}
}
}
const additionalProperties = schema.additionalProperties;
if (additionalProperties !== void 0) {
for (const propertyName of unprocessedProperties) {
propertyProcessed(propertyName);
const child = seenKeys[propertyName];
if (child) {
if (additionalProperties === false) {
const propertyNode = child.parent;
validationResult.problems.push({
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
message: schema.errorMessage || index.t("Property {0} is not allowed.", propertyName)
});
} else if (additionalProperties !== true) {
const propertyValidationResult = new ValidationResult();
validate(child, additionalProperties, propertyValidationResult, matchingSchemas, context);
validationResult.mergePropertyMatch(propertyValidationResult);
}
}
}
}
const unevaluatedProperties = schema.unevaluatedProperties;
if (unevaluatedProperties !== void 0) {
const processed = [];
for (const propertyName of unprocessedProperties) {
if (!validationResult.processedProperties.has(propertyName)) {
processed.push(propertyName);
const child = seenKeys[propertyName];
if (child) {
if (unevaluatedProperties === false) {
const propertyNode = child.parent;
validationResult.problems.push({
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
message: schema.errorMessage || index.t("Property {0} is not allowed.", propertyName)
});
} else if (unevaluatedProperties !== true) {
const propertyValidationResult = new ValidationResult();
validate(child, unevaluatedProperties, propertyValidationResult, matchingSchemas, context);
validationResult.mergePropertyMatch(propertyValidationResult);
}
}
}
}
processed.forEach(propertyProcessed);
}
if (isNumber(schema.maxProperties)) {
if (node2.properties.length > schema.maxProperties) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Object has more properties than limit of {0}.", schema.maxProperties)
});
}
}
if (isNumber(schema.minProperties)) {
if (node2.properties.length < schema.minProperties) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Object has fewer properties than the required number of {0}", schema.minProperties)
});
}
}
if (schema.dependentRequired) {
for (const key in schema.dependentRequired) {
const prop = seenKeys[key];
const propertyDeps = schema.dependentRequired[key];
if (prop && Array.isArray(propertyDeps)) {
_validatePropertyDependencies(key, propertyDeps);
}
}
}
if (schema.dependentSchemas) {
for (const key in schema.dependentSchemas) {
const prop = seenKeys[key];
const propertyDeps = schema.dependentSchemas[key];
if (prop && isObject(propertyDeps)) {
_validatePropertyDependencies(key, propertyDeps);
}
}
}
if (schema.dependencies) {
for (const key in schema.dependencies) {
const prop = seenKeys[key];
if (prop) {
_validatePropertyDependencies(key, schema.dependencies[key]);
}
}
}
const propertyNames = asSchema(schema.propertyNames);
if (propertyNames) {
for (const f2 of node2.properties) {
const key = f2.keyNode;
if (key) {
validate(key, propertyNames, validationResult, NoOpSchemaCollector.instance, context);
}
}
}
function _validatePropertyDependencies(key, propertyDep) {
if (Array.isArray(propertyDep)) {
for (const requiredProp of propertyDep) {
if (!seenKeys[requiredProp]) {
validationResult.problems.push({
location: { offset: node2.offset, length: node2.length },
message: index.t("Object is missing property {0} required by property {1}.", requiredProp, key)
});
} else {
validationResult.propertiesValueMatches++;
}
}
} else {
const propertySchema = asSchema(propertyDep);
if (propertySchema) {
const propertyValidationResult = new ValidationResult();
validate(node2, propertySchema, propertyValidationResult, matchingSchemas, context);
validationResult.mergePropertyMatch(propertyValidationResult);
}
}
}
}
}
function parse(textDocument, config) {
const problems = [];
let lastProblemOffset = -1;
const text = textDocument.getText();
const scanner = main$1.createScanner(text, false);
const commentRanges = config && config.collectComments ? [] : void 0;
function _scanNext() {
while (true) {
const token2 = scanner.scan();
_checkScanError();
switch (token2) {
case 12:
case 13:
if (Array.isArray(commentRanges)) {
commentRanges.push(main.Range.create(textDocument.positionAt(scanner.getTokenOffset()), textDocument.positionAt(scanner.getTokenOffset() + scanner.getTokenLength())));
}
break;
case 15:
case 14:
break;
default:
return token2;
}
}
}
function _errorAtRange(message, code, startOffset, endOffset, severity = main.DiagnosticSeverity.Error) {
if (problems.length === 0 || startOffset !== lastProblemOffset) {
const range = main.Range.create(textDocument.positionAt(startOffset), textDocument.positionAt(endOffset));
problems.push(main.Diagnostic.create(range, message, severity, code, textDocument.languageId));
lastProblemOffset = startOffset;
}
}
function _error(message, code, node = void 0, skipUntilAfter = [], skipUntil = []) {
let start = scanner.getTokenOffset();
let end = scanner.getTokenOffset() + scanner.getTokenLength();
if (start === end && start > 0) {
start--;
while (start > 0 && /\s/.test(text.charAt(start))) {
start--;
}
end = start + 1;
}
_errorAtRange(message, code, start, end);
if (node) {
_finalize(node, false);
}
if (skipUntilAfter.length + skipUntil.length > 0) {
let token2 = scanner.getToken();
while (token2 !== 17) {
if (skipUntilAfter.indexOf(token2) !== -1) {
_scanNext();
break;
} else if (skipUntil.indexOf(token2) !== -1) {
break;
}
token2 = _scanNext();
}
}
return node;
}
function _checkScanError() {
switch (scanner.getTokenError()) {
case 4:
_error(index.t("Invalid unicode sequence in string."), ErrorCode.InvalidUnicode);
return true;
case 5:
_error(index.t("Invalid escape character in string."), ErrorCode.InvalidEscapeCharacter);
return true;
case 3:
_error(index.t("Unexpected end of number."), ErrorCode.UnexpectedEndOfNumber);
return true;
case 1:
_error(index.t("Unexpected end of comment."), ErrorCode.UnexpectedEndOfComment);
return true;
case 2:
_error(index.t("Unexpected end of string."), ErrorCode.UnexpectedEndOfString);
return true;
case 6:
_error(index.t("Invalid characters in string. Control characters must be escaped."), ErrorCode.InvalidCharacter);
return true;
}
return false;
}
function _finalize(node, scanNext) {
node.length = scanner.getTokenOffset() + scanner.getTokenLength() - node.offset;
if (scanNext) {
_scanNext();
}
return node;
}
function _parseArray(parent) {
if (scanner.getToken() !== 3) {
return void 0;
}
const node = new ArrayASTNodeImpl(parent, scanner.getTokenOffset());
_scanNext();
let needsComma = false;
while (scanner.getToken() !== 4 && scanner.getToken() !== 17) {
if (scanner.getToken() === 5) {
if (!needsComma) {
_error(index.t("Value expected"), ErrorCode.ValueExpected);
}
const commaOffset = scanner.getTokenOffset();
_scanNext();
if (scanner.getToken() === 4) {
if (needsComma) {
_errorAtRange(index.t("Trailing comma"), ErrorCode.TrailingComma, commaOffset, commaOffset + 1);
}
continue;
}
} else if (needsComma) {
_error(index.t("Expected comma"), ErrorCode.CommaExpected);
}
const item = _parseValue(node);
if (!item) {
_error(index.t("Value expected"), ErrorCode.ValueExpected, void 0, [], [
4,
5
/* Json.SyntaxKind.CommaToken */
]);
} else {
node.items.push