monaco-yaml
Version:
YAML plugin for the Monaco Editor
1,322 lines (1,311 loc) • 380 kB
JavaScript
var __getOwnPropNames = Object.getOwnPropertyNames;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
// fillers/json-schema.json
var require_json_schema = __commonJS({
"fillers/json-schema.json"(exports, module) {
module.exports = {};
}
});
// src/yaml.worker.ts
import { initialize } from "monaco-worker-manager/worker";
import { TextDocument } from "vscode-languageserver-textdocument";
// node_modules/vscode-json-languageservice/lib/esm/services/jsonSchemaService.js
import * as Json2 from "jsonc-parser";
import { URI } from "vscode-uri";
// node_modules/vscode-json-languageservice/lib/esm/utils/strings.js
function startsWith(haystack, needle) {
if (haystack.length < needle.length) {
return false;
}
for (var i = 0; i < needle.length; i++) {
if (haystack[i] !== needle[i]) {
return false;
}
}
return true;
}
function endsWith(haystack, needle) {
var 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) {
if (startsWith(pattern, "(?i)")) {
return new RegExp(pattern.substring(4), "i");
} else {
return new RegExp(pattern);
}
}
// node_modules/vscode-json-languageservice/lib/esm/parser/jsonParser.js
import * as Json from "jsonc-parser";
// node_modules/vscode-json-languageservice/lib/esm/utils/objects.js
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;
}
var 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 {
var oneKeys = [];
for (key in one) {
oneKeys.push(key);
}
oneKeys.sort();
var 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";
}
// node_modules/vscode-json-languageservice/lib/esm/jsonLanguageTypes.js
import { Range, Position, MarkupContent, MarkupKind, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind } from "vscode-languageserver-types";
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["SchemaResolveError"] = 768] = "SchemaResolveError";
})(ErrorCode || (ErrorCode = {}));
var ClientCapabilities;
(function(ClientCapabilities2) {
ClientCapabilities2.LATEST = {
textDocument: {
completion: {
completionItem: {
documentationFormat: [MarkupKind.Markdown, MarkupKind.PlainText],
commitCharactersSupport: true
}
}
}
};
})(ClientCapabilities || (ClientCapabilities = {}));
// fillers/vscode-nls.ts
var localize = (key, message, ...args) => args.length === 0 ? message : message.replaceAll(
/{(\d+)}/g,
(match, [index]) => index in args ? String(args[index]) : match
);
function loadMessageBundle() {
return localize;
}
// node_modules/vscode-json-languageservice/lib/esm/parser/jsonParser.js
var __extends = /* @__PURE__ */ (function() {
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
d2.__proto__ = b2;
} || function(d2, b2) {
for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
};
return extendStatics(d, b);
};
return function(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var localize2 = loadMessageBundle();
var formats = {
"color-hex": { errorMessage: localize2("colorHexFormatWarning", "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: localize2("dateTimeFormatWarning", "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: localize2("dateFormatWarning", "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: localize2("timeFormatWarning", "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: localize2("emailFormatWarning", "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-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ }
};
var ASTNodeImpl = (
/** @class */
(function() {
function ASTNodeImpl3(parent, offset, length) {
if (length === void 0) {
length = 0;
}
this.offset = offset;
this.length = length;
this.parent = parent;
}
Object.defineProperty(ASTNodeImpl3.prototype, "children", {
get: function() {
return [];
},
enumerable: false,
configurable: true
});
ASTNodeImpl3.prototype.toString = function() {
return "type: " + this.type + " (" + this.offset + "/" + this.length + ")" + (this.parent ? " parent: {" + this.parent.toString() + "}" : "");
};
return ASTNodeImpl3;
})()
);
var NullASTNodeImpl = (
/** @class */
(function(_super) {
__extends(NullASTNodeImpl3, _super);
function NullASTNodeImpl3(parent, offset) {
var _this = _super.call(this, parent, offset) || this;
_this.type = "null";
_this.value = null;
return _this;
}
return NullASTNodeImpl3;
})(ASTNodeImpl)
);
var BooleanASTNodeImpl = (
/** @class */
(function(_super) {
__extends(BooleanASTNodeImpl3, _super);
function BooleanASTNodeImpl3(parent, boolValue, offset) {
var _this = _super.call(this, parent, offset) || this;
_this.type = "boolean";
_this.value = boolValue;
return _this;
}
return BooleanASTNodeImpl3;
})(ASTNodeImpl)
);
var ArrayASTNodeImpl = (
/** @class */
(function(_super) {
__extends(ArrayASTNodeImpl3, _super);
function ArrayASTNodeImpl3(parent, offset) {
var _this = _super.call(this, parent, offset) || this;
_this.type = "array";
_this.items = [];
return _this;
}
Object.defineProperty(ArrayASTNodeImpl3.prototype, "children", {
get: function() {
return this.items;
},
enumerable: false,
configurable: true
});
return ArrayASTNodeImpl3;
})(ASTNodeImpl)
);
var NumberASTNodeImpl = (
/** @class */
(function(_super) {
__extends(NumberASTNodeImpl3, _super);
function NumberASTNodeImpl3(parent, offset) {
var _this = _super.call(this, parent, offset) || this;
_this.type = "number";
_this.isInteger = true;
_this.value = Number.NaN;
return _this;
}
return NumberASTNodeImpl3;
})(ASTNodeImpl)
);
var StringASTNodeImpl = (
/** @class */
(function(_super) {
__extends(StringASTNodeImpl3, _super);
function StringASTNodeImpl3(parent, offset, length) {
var _this = _super.call(this, parent, offset, length) || this;
_this.type = "string";
_this.value = "";
return _this;
}
return StringASTNodeImpl3;
})(ASTNodeImpl)
);
var PropertyASTNodeImpl = (
/** @class */
(function(_super) {
__extends(PropertyASTNodeImpl3, _super);
function PropertyASTNodeImpl3(parent, offset, keyNode) {
var _this = _super.call(this, parent, offset) || this;
_this.type = "property";
_this.colonOffset = -1;
_this.keyNode = keyNode;
return _this;
}
Object.defineProperty(PropertyASTNodeImpl3.prototype, "children", {
get: function() {
return this.valueNode ? [this.keyNode, this.valueNode] : [this.keyNode];
},
enumerable: false,
configurable: true
});
return PropertyASTNodeImpl3;
})(ASTNodeImpl)
);
var ObjectASTNodeImpl = (
/** @class */
(function(_super) {
__extends(ObjectASTNodeImpl3, _super);
function ObjectASTNodeImpl3(parent, offset) {
var _this = _super.call(this, parent, offset) || this;
_this.type = "object";
_this.properties = [];
return _this;
}
Object.defineProperty(ObjectASTNodeImpl3.prototype, "children", {
get: function() {
return this.properties;
},
enumerable: false,
configurable: true
});
return ObjectASTNodeImpl3;
})(ASTNodeImpl)
);
function asSchema(schema) {
if (isBoolean(schema)) {
return schema ? {} : { "not": {} };
}
return schema;
}
var EnumMatch;
(function(EnumMatch3) {
EnumMatch3[EnumMatch3["Key"] = 0] = "Key";
EnumMatch3[EnumMatch3["Enum"] = 1] = "Enum";
})(EnumMatch || (EnumMatch = {}));
var SchemaCollector = (
/** @class */
(function() {
function SchemaCollector3(focusOffset, exclude) {
if (focusOffset === void 0) {
focusOffset = -1;
}
this.focusOffset = focusOffset;
this.exclude = exclude;
this.schemas = [];
}
SchemaCollector3.prototype.add = function(schema) {
this.schemas.push(schema);
};
SchemaCollector3.prototype.merge = function(other) {
Array.prototype.push.apply(this.schemas, other.schemas);
};
SchemaCollector3.prototype.include = function(node) {
return (this.focusOffset === -1 || contains(node, this.focusOffset)) && node !== this.exclude;
};
SchemaCollector3.prototype.newSub = function() {
return new SchemaCollector3(-1, this.exclude);
};
return SchemaCollector3;
})()
);
var NoOpSchemaCollector = (
/** @class */
(function() {
function NoOpSchemaCollector3() {
}
Object.defineProperty(NoOpSchemaCollector3.prototype, "schemas", {
get: function() {
return [];
},
enumerable: false,
configurable: true
});
NoOpSchemaCollector3.prototype.add = function(schema) {
};
NoOpSchemaCollector3.prototype.merge = function(other) {
};
NoOpSchemaCollector3.prototype.include = function(node) {
return true;
};
NoOpSchemaCollector3.prototype.newSub = function() {
return this;
};
NoOpSchemaCollector3.instance = new NoOpSchemaCollector3();
return NoOpSchemaCollector3;
})()
);
var ValidationResult = (
/** @class */
(function() {
function ValidationResult3() {
this.problems = [];
this.propertiesMatches = 0;
this.propertiesValueMatches = 0;
this.primaryValueMatches = 0;
this.enumValueMatch = false;
this.enumValues = void 0;
}
ValidationResult3.prototype.hasProblems = function() {
return !!this.problems.length;
};
ValidationResult3.prototype.mergeAll = function(validationResults) {
for (var _i = 0, validationResults_1 = validationResults; _i < validationResults_1.length; _i++) {
var validationResult = validationResults_1[_i];
this.merge(validationResult);
}
};
ValidationResult3.prototype.merge = function(validationResult) {
this.problems = this.problems.concat(validationResult.problems);
};
ValidationResult3.prototype.mergeEnumValues = function(validationResult) {
if (!this.enumValueMatch && !validationResult.enumValueMatch && this.enumValues && validationResult.enumValues) {
this.enumValues = this.enumValues.concat(validationResult.enumValues);
for (var _i = 0, _a = this.problems; _i < _a.length; _i++) {
var error = _a[_i];
if (error.code === ErrorCode.EnumValueMismatch) {
error.message = localize2("enumWarning", "Value is not accepted. Valid values: {0}.", this.enumValues.map(function(v) {
return JSON.stringify(v);
}).join(", "));
}
}
}
};
ValidationResult3.prototype.mergePropertyMatch = function(propertyValidationResult) {
this.merge(propertyValidationResult);
this.propertiesMatches++;
if (propertyValidationResult.enumValueMatch || !propertyValidationResult.hasProblems() && propertyValidationResult.propertiesMatches) {
this.propertiesValueMatches++;
}
if (propertyValidationResult.enumValueMatch && propertyValidationResult.enumValues && propertyValidationResult.enumValues.length === 1) {
this.primaryValueMatches++;
}
};
ValidationResult3.prototype.compare = function(other) {
var 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;
};
return ValidationResult3;
})()
);
function getNodeValue2(node) {
return Json.getNodeValue(node);
}
function contains(node, offset, includeRightBound) {
if (includeRightBound === void 0) {
includeRightBound = false;
}
return offset >= node.offset && offset < node.offset + node.length || includeRightBound && offset === node.offset + node.length;
}
var JSONDocument = (
/** @class */
(function() {
function JSONDocument3(root, syntaxErrors, comments) {
if (syntaxErrors === void 0) {
syntaxErrors = [];
}
if (comments === void 0) {
comments = [];
}
this.root = root;
this.syntaxErrors = syntaxErrors;
this.comments = comments;
}
JSONDocument3.prototype.getNodeFromOffset = function(offset, includeRightBound) {
if (includeRightBound === void 0) {
includeRightBound = false;
}
if (this.root) {
return Json.findNodeAtOffset(this.root, offset, includeRightBound);
}
return void 0;
};
JSONDocument3.prototype.visit = function(visitor) {
if (this.root) {
var doVisit_1 = function(node) {
var ctn = visitor(node);
var children = node.children;
if (Array.isArray(children)) {
for (var i = 0; i < children.length && ctn; i++) {
ctn = doVisit_1(children[i]);
}
}
return ctn;
};
doVisit_1(this.root);
}
};
JSONDocument3.prototype.validate = function(textDocument, schema, severity) {
if (severity === void 0) {
severity = DiagnosticSeverity.Warning;
}
if (this.root && schema) {
var validationResult = new ValidationResult();
validate(this.root, schema, validationResult, NoOpSchemaCollector.instance);
return validationResult.problems.map(function(p) {
var _a;
var range = Range.create(textDocument.positionAt(p.location.offset), textDocument.positionAt(p.location.offset + p.location.length));
return Diagnostic.create(range, p.message, (_a = p.severity) !== null && _a !== void 0 ? _a : severity, p.code);
});
}
return void 0;
};
JSONDocument3.prototype.getMatchingSchemas = function(schema, focusOffset, exclude) {
if (focusOffset === void 0) {
focusOffset = -1;
}
var matchingSchemas = new SchemaCollector(focusOffset, exclude);
if (this.root && schema) {
validate(this.root, schema, new ValidationResult(), matchingSchemas);
}
return matchingSchemas.schemas;
};
return JSONDocument3;
})()
);
function validate(n, schema, validationResult, matchingSchemas) {
if (!n || !matchingSchemas.include(n)) {
return;
}
var node = n;
switch (node.type) {
case "object":
_validateObjectNode(node, schema, validationResult, matchingSchemas);
break;
case "array":
_validateArrayNode(node, schema, validationResult, matchingSchemas);
break;
case "string":
_validateStringNode(node, schema, validationResult, matchingSchemas);
break;
case "number":
_validateNumberNode(node, schema, validationResult, matchingSchemas);
break;
case "property":
return validate(node.valueNode, schema, validationResult, matchingSchemas);
}
_validateNode();
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 || localize2("typeArrayMismatchWarning", "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 || localize2("typeMismatchWarning", 'Incorrect type. Expected "{0}".', schema.type)
});
}
}
if (Array.isArray(schema.allOf)) {
for (var _i = 0, _a = schema.allOf; _i < _a.length; _i++) {
var subSchemaRef = _a[_i];
validate(node, asSchema(subSchemaRef), validationResult, matchingSchemas);
}
}
var notSchema = asSchema(schema.not);
if (notSchema) {
var subValidationResult = new ValidationResult();
var subMatchingSchemas = matchingSchemas.newSub();
validate(node, notSchema, subValidationResult, subMatchingSchemas);
if (!subValidationResult.hasProblems()) {
validationResult.problems.push({
location: { offset: node.offset, length: node.length },
message: localize2("notSchemaWarning", "Matches a schema that is not allowed.")
});
}
for (var _b = 0, _c = subMatchingSchemas.schemas; _b < _c.length; _b++) {
var ms = _c[_b];
ms.inverted = !ms.inverted;
matchingSchemas.add(ms);
}
}
var testAlternatives = function(alternatives, maxOneMatch) {
var matches = [];
var bestMatch = void 0;
for (var _i2 = 0, alternatives_1 = alternatives; _i2 < alternatives_1.length; _i2++) {
var subSchemaRef2 = alternatives_1[_i2];
var subSchema = asSchema(subSchemaRef2);
var subValidationResult2 = new ValidationResult();
var subMatchingSchemas2 = matchingSchemas.newSub();
validate(node, subSchema, subValidationResult2, subMatchingSchemas2);
if (!subValidationResult2.hasProblems()) {
matches.push(subSchema);
}
if (!bestMatch) {
bestMatch = { schema: subSchema, validationResult: subValidationResult2, matchingSchemas: subMatchingSchemas2 };
} else {
if (!maxOneMatch && !subValidationResult2.hasProblems() && !bestMatch.validationResult.hasProblems()) {
bestMatch.matchingSchemas.merge(subMatchingSchemas2);
bestMatch.validationResult.propertiesMatches += subValidationResult2.propertiesMatches;
bestMatch.validationResult.propertiesValueMatches += subValidationResult2.propertiesValueMatches;
} else {
var compareResult = subValidationResult2.compare(bestMatch.validationResult);
if (compareResult > 0) {
bestMatch = { schema: subSchema, validationResult: subValidationResult2, matchingSchemas: subMatchingSchemas2 };
} else if (compareResult === 0) {
bestMatch.matchingSchemas.merge(subMatchingSchemas2);
bestMatch.validationResult.mergeEnumValues(subValidationResult2);
}
}
}
}
if (matches.length > 1 && maxOneMatch) {
validationResult.problems.push({
location: { offset: node.offset, length: 1 },
message: localize2("oneOfWarning", "Matches multiple schemas when only one must validate.")
});
}
if (bestMatch) {
validationResult.merge(bestMatch.validationResult);
validationResult.propertiesMatches += bestMatch.validationResult.propertiesMatches;
validationResult.propertiesValueMatches += bestMatch.validationResult.propertiesValueMatches;
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);
}
var testBranch = function(schema2) {
var subValidationResult2 = new ValidationResult();
var subMatchingSchemas2 = matchingSchemas.newSub();
validate(node, asSchema(schema2), subValidationResult2, subMatchingSchemas2);
validationResult.merge(subValidationResult2);
validationResult.propertiesMatches += subValidationResult2.propertiesMatches;
validationResult.propertiesValueMatches += subValidationResult2.propertiesValueMatches;
matchingSchemas.merge(subMatchingSchemas2);
};
var testCondition = function(ifSchema2, thenSchema, elseSchema) {
var subSchema = asSchema(ifSchema2);
var subValidationResult2 = new ValidationResult();
var subMatchingSchemas2 = matchingSchemas.newSub();
validate(node, subSchema, subValidationResult2, subMatchingSchemas2);
matchingSchemas.merge(subMatchingSchemas2);
if (!subValidationResult2.hasProblems()) {
if (thenSchema) {
testBranch(thenSchema);
}
} else if (elseSchema) {
testBranch(elseSchema);
}
};
var ifSchema = asSchema(schema.if);
if (ifSchema) {
testCondition(ifSchema, asSchema(schema.then), asSchema(schema.else));
}
if (Array.isArray(schema.enum)) {
var val = getNodeValue2(node);
var enumValueMatch = false;
for (var _d = 0, _e = schema.enum; _d < _e.length; _d++) {
var e = _e[_d];
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 || localize2("enumWarning", "Value is not accepted. Valid values: {0}.", schema.enum.map(function(v) {
return JSON.stringify(v);
}).join(", "))
});
}
}
if (isDefined(schema.const)) {
var val = getNodeValue2(node);
if (!equals(val, schema.const)) {
validationResult.problems.push({
location: { offset: node.offset, length: node.length },
code: ErrorCode.EnumValueMismatch,
message: schema.errorMessage || localize2("constWarning", "Value must be {0}.", JSON.stringify(schema.const))
});
validationResult.enumValueMatch = false;
} else {
validationResult.enumValueMatch = true;
}
validationResult.enumValues = [schema.const];
}
if (schema.deprecationMessage && node.parent) {
validationResult.problems.push({
location: { offset: node.parent.offset, length: node.parent.length },
severity: DiagnosticSeverity.Warning,
message: schema.deprecationMessage,
code: ErrorCode.Deprecated
});
}
}
function _validateNumberNode(node2, schema2, validationResult2, matchingSchemas2) {
var val = node2.value;
function normalizeFloats(float) {
var _a;
var parts = /^(-?\d+)(?:\.(\d+))?(?:e([-+]\d+))?$/.exec(float.toString());
return parts && {
value: Number(parts[1] + (parts[2] || "")),
multiplier: (((_a = parts[2]) === null || _a === void 0 ? void 0 : _a.length) || 0) - (parseInt(parts[3]) || 0)
};
}
;
if (isNumber(schema2.multipleOf)) {
var remainder = -1;
if (Number.isInteger(schema2.multipleOf)) {
remainder = val % schema2.multipleOf;
} else {
var normMultipleOf = normalizeFloats(schema2.multipleOf);
var normValue = normalizeFloats(val);
if (normMultipleOf && normValue) {
var multiplier = Math.pow(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) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("multipleOfWarning", "Value is not divisible by {0}.", schema2.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;
}
var exclusiveMinimum = getExclusiveLimit(schema2.minimum, schema2.exclusiveMinimum);
if (isNumber(exclusiveMinimum) && val <= exclusiveMinimum) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("exclusiveMinimumWarning", "Value is below the exclusive minimum of {0}.", exclusiveMinimum)
});
}
var exclusiveMaximum = getExclusiveLimit(schema2.maximum, schema2.exclusiveMaximum);
if (isNumber(exclusiveMaximum) && val >= exclusiveMaximum) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("exclusiveMaximumWarning", "Value is above the exclusive maximum of {0}.", exclusiveMaximum)
});
}
var minimum = getLimit(schema2.minimum, schema2.exclusiveMinimum);
if (isNumber(minimum) && val < minimum) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("minimumWarning", "Value is below the minimum of {0}.", minimum)
});
}
var maximum = getLimit(schema2.maximum, schema2.exclusiveMaximum);
if (isNumber(maximum) && val > maximum) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("maximumWarning", "Value is above the maximum of {0}.", maximum)
});
}
}
function _validateStringNode(node2, schema2, validationResult2, matchingSchemas2) {
if (isNumber(schema2.minLength) && node2.value.length < schema2.minLength) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("minLengthWarning", "String is shorter than the minimum length of {0}.", schema2.minLength)
});
}
if (isNumber(schema2.maxLength) && node2.value.length > schema2.maxLength) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("maxLengthWarning", "String is longer than the maximum length of {0}.", schema2.maxLength)
});
}
if (isString(schema2.pattern)) {
var regex = extendedRegExp(schema2.pattern);
if (!regex.test(node2.value)) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema2.patternErrorMessage || schema2.errorMessage || localize2("patternWarning", 'String does not match the pattern of "{0}".', schema2.pattern)
});
}
}
if (schema2.format) {
switch (schema2.format) {
case "uri":
case "uri-reference":
{
var errorMessage = void 0;
if (!node2.value) {
errorMessage = localize2("uriEmpty", "URI expected.");
} else {
var match = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/.exec(node2.value);
if (!match) {
errorMessage = localize2("uriMissing", "URI is expected.");
} else if (!match[2] && schema2.format === "uri") {
errorMessage = localize2("uriSchemeMissing", "URI with a scheme is expected.");
}
}
if (errorMessage) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema2.patternErrorMessage || schema2.errorMessage || localize2("uriFormatWarning", "String is not a URI: {0}", errorMessage)
});
}
}
break;
case "color-hex":
case "date-time":
case "date":
case "time":
case "email":
var format2 = formats[schema2.format];
if (!node2.value || !format2.pattern.exec(node2.value)) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema2.patternErrorMessage || schema2.errorMessage || format2.errorMessage
});
}
default:
}
}
}
function _validateArrayNode(node2, schema2, validationResult2, matchingSchemas2) {
if (Array.isArray(schema2.items)) {
var subSchemas = schema2.items;
for (var index = 0; index < subSchemas.length; index++) {
var subSchemaRef = subSchemas[index];
var subSchema = asSchema(subSchemaRef);
var itemValidationResult = new ValidationResult();
var item = node2.items[index];
if (item) {
validate(item, subSchema, itemValidationResult, matchingSchemas2);
validationResult2.mergePropertyMatch(itemValidationResult);
} else if (node2.items.length >= subSchemas.length) {
validationResult2.propertiesValueMatches++;
}
}
if (node2.items.length > subSchemas.length) {
if (typeof schema2.additionalItems === "object") {
for (var i = subSchemas.length; i < node2.items.length; i++) {
var itemValidationResult = new ValidationResult();
validate(node2.items[i], schema2.additionalItems, itemValidationResult, matchingSchemas2);
validationResult2.mergePropertyMatch(itemValidationResult);
}
} else if (schema2.additionalItems === false) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("additionalItemsWarning", "Array has too many items according to schema. Expected {0} or fewer.", subSchemas.length)
});
}
}
} else {
var itemSchema = asSchema(schema2.items);
if (itemSchema) {
for (var _i = 0, _a = node2.items; _i < _a.length; _i++) {
var item = _a[_i];
var itemValidationResult = new ValidationResult();
validate(item, itemSchema, itemValidationResult, matchingSchemas2);
validationResult2.mergePropertyMatch(itemValidationResult);
}
}
}
var containsSchema = asSchema(schema2.contains);
if (containsSchema) {
var doesContain = node2.items.some(function(item2) {
var itemValidationResult2 = new ValidationResult();
validate(item2, containsSchema, itemValidationResult2, NoOpSchemaCollector.instance);
return !itemValidationResult2.hasProblems();
});
if (!doesContain) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: schema2.errorMessage || localize2("requiredItemMissingWarning", "Array does not contain required item.")
});
}
}
if (isNumber(schema2.minItems) && node2.items.length < schema2.minItems) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("minItemsWarning", "Array has too few items. Expected {0} or more.", schema2.minItems)
});
}
if (isNumber(schema2.maxItems) && node2.items.length > schema2.maxItems) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("maxItemsWarning", "Array has too many items. Expected {0} or fewer.", schema2.maxItems)
});
}
if (schema2.uniqueItems === true) {
var values_1 = getNodeValue2(node2);
var duplicates = values_1.some(function(value, index2) {
return index2 !== values_1.lastIndexOf(value);
});
if (duplicates) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("uniqueItemsWarning", "Array has duplicate items.")
});
}
}
}
function _validateObjectNode(node2, schema2, validationResult2, matchingSchemas2) {
var seenKeys = /* @__PURE__ */ Object.create(null);
var unprocessedProperties = [];
for (var _i = 0, _a = node2.properties; _i < _a.length; _i++) {
var propertyNode = _a[_i];
var key = propertyNode.keyNode.value;
seenKeys[key] = propertyNode.valueNode;
unprocessedProperties.push(key);
}
if (Array.isArray(schema2.required)) {
for (var _b = 0, _c = schema2.required; _b < _c.length; _b++) {
var propertyName = _c[_b];
if (!seenKeys[propertyName]) {
var keyNode = node2.parent && node2.parent.type === "property" && node2.parent.keyNode;
var location = keyNode ? { offset: keyNode.offset, length: keyNode.length } : { offset: node2.offset, length: 1 };
validationResult2.problems.push({
location,
message: localize2("MissingRequiredPropWarning", 'Missing property "{0}".', propertyName)
});
}
}
}
var propertyProcessed = function(prop2) {
var index = unprocessedProperties.indexOf(prop2);
while (index >= 0) {
unprocessedProperties.splice(index, 1);
index = unprocessedProperties.indexOf(prop2);
}
};
if (schema2.properties) {
for (var _d = 0, _e = Object.keys(schema2.properties); _d < _e.length; _d++) {
var propertyName = _e[_d];
propertyProcessed(propertyName);
var propertySchema = schema2.properties[propertyName];
var child = seenKeys[propertyName];
if (child) {
if (isBoolean(propertySchema)) {
if (!propertySchema) {
var propertyNode = child.parent;
validationResult2.problems.push({
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
message: schema2.errorMessage || localize2("DisallowedExtraPropWarning", "Property {0} is not allowed.", propertyName)
});
} else {
validationResult2.propertiesMatches++;
validationResult2.propertiesValueMatches++;
}
} else {
var propertyValidationResult = new ValidationResult();
validate(child, propertySchema, propertyValidationResult, matchingSchemas2);
validationResult2.mergePropertyMatch(propertyValidationResult);
}
}
}
}
if (schema2.patternProperties) {
for (var _f = 0, _g = Object.keys(schema2.patternProperties); _f < _g.length; _f++) {
var propertyPattern = _g[_f];
var regex = extendedRegExp(propertyPattern);
for (var _h = 0, _j = unprocessedProperties.slice(0); _h < _j.length; _h++) {
var propertyName = _j[_h];
if (regex.test(propertyName)) {
propertyProcessed(propertyName);
var child = seenKeys[propertyName];
if (child) {
var propertySchema = schema2.patternProperties[propertyPattern];
if (isBoolean(propertySchema)) {
if (!propertySchema) {
var propertyNode = child.parent;
validationResult2.problems.push({
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
message: schema2.errorMessage || localize2("DisallowedExtraPropWarning", "Property {0} is not allowed.", propertyName)
});
} else {
validationResult2.propertiesMatches++;
validationResult2.propertiesValueMatches++;
}
} else {
var propertyValidationResult = new ValidationResult();
validate(child, propertySchema, propertyValidationResult, matchingSchemas2);
validationResult2.mergePropertyMatch(propertyValidationResult);
}
}
}
}
}
}
if (typeof schema2.additionalProperties === "object") {
for (var _k = 0, unprocessedProperties_1 = unprocessedProperties; _k < unprocessedProperties_1.length; _k++) {
var propertyName = unprocessedProperties_1[_k];
var child = seenKeys[propertyName];
if (child) {
var propertyValidationResult = new ValidationResult();
validate(child, schema2.additionalProperties, propertyValidationResult, matchingSchemas2);
validationResult2.mergePropertyMatch(propertyValidationResult);
}
}
} else if (schema2.additionalProperties === false) {
if (unprocessedProperties.length > 0) {
for (var _l = 0, unprocessedProperties_2 = unprocessedProperties; _l < unprocessedProperties_2.length; _l++) {
var propertyName = unprocessedProperties_2[_l];
var child = seenKeys[propertyName];
if (child) {
var propertyNode = child.parent;
validationResult2.problems.push({
location: { offset: propertyNode.keyNode.offset, length: propertyNode.keyNode.length },
message: schema2.errorMessage || localize2("DisallowedExtraPropWarning", "Property {0} is not allowed.", propertyName)
});
}
}
}
}
if (isNumber(schema2.maxProperties)) {
if (node2.properties.length > schema2.maxProperties) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("MaxPropWarning", "Object has more properties than limit of {0}.", schema2.maxProperties)
});
}
}
if (isNumber(schema2.minProperties)) {
if (node2.properties.length < schema2.minProperties) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("MinPropWarning", "Object has fewer properties than the required number of {0}", schema2.minProperties)
});
}
}
if (schema2.dependencies) {
for (var _m = 0, _o = Object.keys(schema2.dependencies); _m < _o.length; _m++) {
var key = _o[_m];
var prop = seenKeys[key];
if (prop) {
var propertyDep = schema2.dependencies[key];
if (Array.isArray(propertyDep)) {
for (var _p = 0, propertyDep_1 = propertyDep; _p < propertyDep_1.length; _p++) {
var requiredProp = propertyDep_1[_p];
if (!seenKeys[requiredProp]) {
validationResult2.problems.push({
location: { offset: node2.offset, length: node2.length },
message: localize2("RequiredDependentPropWarning", "Object is missing property {0} required by property {1}.", requiredProp, key)
});
} else {
validationResult2.propertiesValueMatches++;
}
}
} else {
var propertySchema = asSchema(propertyDep);
if (propertySchema) {
var propertyValidationResult = new ValidationResult();
validate(node2, propertySchema, propertyValidationResult, matchingSchemas2);
validationResult2.mergePropertyMatch(propertyValidationResult);
}
}
}
}
}
var propertyNames = asSchema(schema2.propertyNames);
if (propertyNames) {
for (var _q = 0, _r = node2.properties; _q < _r.length; _q++) {
var f2 = _r[_q];
var key = f2.keyNode;
if (key) {
validate(key, propertyNames, validationResult2, NoOpSchemaCollector.instance);
}
}
}
}
}
// node_modules/vscode-json-languageservice/lib/esm/utils/glob.js
function createRegex(glob, opts) {
if (typeof glob !== "string") {
throw new TypeError("Expected a string");
}
var str = String(glob);
var reStr = "";
var extended = opts ? !!opts.extended : false;
var globstar = opts ? !!opts.globstar : false;
var inGroup = false;
var flags = opts && typeof opts.flags === "string" ? opts.flags : "";
var c;
for (var i = 0, len = str.length; i < len; i++) {
c = str[i];
switch (c) {
case "/":
case "$":
case "^":
case "+":
case ".":
case "(":
case ")":
case "=":
case "!":
case "|":
reStr += "\\" + c;
break;
case "?":
if (extended) {
reStr += ".";
break;
}
case "[":
case "]":
if (extended) {
reStr += c;
break;
}
case "{":
if (extended) {
inGroup = true;
reStr += "(";
break;
}
case "}":
if (extended) {
inGroup = false;
reStr += ")";
break;
}
case ",":
if (inGroup) {
reStr += "|";
break;
}
reStr += "\\" + c;
break;
case "*":
var prevChar = str[i - 1];
var starCount = 1;
while (str[i + 1] === "*") {
starCount++;
i++;
}
var nextChar = str[i + 1];
if (!globstar) {
reStr += ".*";
} else {
var isGlobstar = starCount > 1 && (prevChar === "/" || prevChar === void 0 || prevChar === "{" || prevChar === ",") && (nextChar === "/" || nextChar === void 0 || nextChar === "," || nextChar === "}");
if (isGlobstar) {
if (nextChar === "/") {
i++;
} else if (prevChar === "/" && reStr.endsWith("\\/")) {
reStr = reStr.substr(0, reStr.length - 2);
}
reStr += "((?:[^/]*(?:/|$))*)";
} else {
reStr += "([^/]*)";
}
}
break;
default:
reStr += c;
}
}
if (!flags || !~flags.indexOf("g")) {
reStr = "^" + reStr + "$";
}
return new RegExp(reStr, flags);
}
// node_modules/vscode-json-languageservice/lib/esm/services/jsonSchemaService.js
var localize3 = loadMessageBundle();
var BANG = "!";
var PATH_SEP = "/";
var FilePatternAssociation = (
/** @class */
(function() {
function FilePatternAssociation3(pattern, uris) {
this.globWrappers = [];
try {
for (var _i = 0, pattern_1 = pattern; _i < pattern_1.length; _i++) {
var patternString = pattern_1[_i];
var include = patternString[0] !== BANG;
if (!include) {
patternString = patternString.substring(1);
}
if (patternString.length > 0) {
if (patternString[0] === PATH_SEP) {
patternString = patternString.substring(1);
}
this.globWrappers.push({
regexp: createRegex("**/" + patternString, { extended: true, globstar: true }),
include
});
}
}
;
this.uris = uris;
} catch (e) {
this.globWrappers.length = 0;
this.uris = [];
}
}
FilePatternAssociation3.prototype.matchesPattern = function(fileName) {
var match = false;
for (var _i = 0, _a = this.globWrappers; _i < _a.length; _i++) {
var _b = _a[_i], regexp = _b.regexp, include = _b.include;
if (regexp.test(fileName)) {
match = include;
}
}
return match;
};
FilePatternAssociation3.prototype.getURIs = function() {
return this.uris;
};
return FilePatternAssociation3;
})()
);
var SchemaHandle = (
/** @class */
(function() {
function SchemaHandle2(service, url, unresolvedSchemaContent) {
this.service = service;
this.url = url;
this.dependencies = {};
if (unresolvedSchemaContent) {
this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
}
}
SchemaHandle2.prototype.getUnresolvedSchema = function() {
if (!this.unresolvedSchema) {
this.unresolvedSchema = this.service.loadSchema(this.url);
}
return this.unresolvedSchema;
};
SchemaHandle2.prototype.getResolvedSchema = function() {
var _this = this;
if (!this.resolvedSchema) {
this.resolvedSchema = this.getUnresolvedSchema().then(function(unresolved) {
return _this.service.resolveSchemaContent(unresolved, _this.url, _this.dependencies);
});
}
return this.resolvedSchema;
};
SchemaHandle2.prototype.clearSchema = function() {
this.resolvedSchema = void 0;
this.unresolvedSchema = void 0;
this.dependencies = {};
};
return SchemaHandle2;
})()
);
var UnresolvedSchema = (
/** @class */
/* @__PURE__ */ (function() {
function UnresolvedSchema2(schema, errors) {
if (errors === void 0) {
errors = [];
}
this.schema = schema;
this.errors = errors;
}
return UnresolvedSchema2;
})()
);
var ResolvedSchema = (
/** @class */
(function() {
function ResolvedSchema2(schema, errors) {
if (errors === void 0) {
errors = [];
}
this.schema = schema;
this.errors = errors;
}
ResolvedSchema2.prototype.getSection = function(path5) {
var schemaRef = this.getSectionRecursive(path5, this.schema);
if (schemaRef) {
return asSchema(schemaRef);
}
return void 0;
};
ResolvedSchema2.prototype.getSectionRecursive = function(path5, schema) {
if (!schema || typeof schema === "boolean" || path5.length === 0) {
return schema;
}
var next = path5.shift();
if (schema.properties && typeof schema.properties[next]) {
return this.getSectionRecursive(path5, schema.properties[next]);
} else if (schema.patternProperties) {
for (var _i = 0, _a = Object.keys(schema.patternProperties); _i < _a.length; _i++) {
var pattern = _a[