UNPKG

monaco-editor

Version:
1,656 lines (1,648 loc) • 266 kB
/*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f) * Released under the MIT license * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt *-----------------------------------------------------------------------------*/ // src/language/json/json.worker.ts import * as worker from "../../editor/editor.worker.js"; // node_modules/jsonc-parser/lib/esm/impl/scanner.js function createScanner(text, ignoreTrivia) { if (ignoreTrivia === void 0) { ignoreTrivia = false; } var len = text.length; var pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0; function scanHexDigits(count, exact) { var digits = 0; var value2 = 0; while (digits < count || !exact) { var ch = text.charCodeAt(pos); if (ch >= 48 && ch <= 57) { value2 = value2 * 16 + ch - 48; } else if (ch >= 65 && ch <= 70) { value2 = value2 * 16 + ch - 65 + 10; } else if (ch >= 97 && ch <= 102) { value2 = value2 * 16 + ch - 97 + 10; } else { break; } pos++; digits++; } if (digits < count) { value2 = -1; } return value2; } function setPosition(newPosition) { pos = newPosition; value = ""; tokenOffset = 0; token = 16; scanError = 0; } function scanNumber() { var start = pos; if (text.charCodeAt(pos) === 48) { pos++; } else { pos++; while (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; } } if (pos < text.length && text.charCodeAt(pos) === 46) { pos++; if (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; while (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; } } else { scanError = 3; return text.substring(start, pos); } } var end = pos; if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) { pos++; if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) { pos++; } if (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; while (pos < text.length && isDigit(text.charCodeAt(pos))) { pos++; } end = pos; } else { scanError = 3; } } return text.substring(start, end); } function scanString() { var result = "", start = pos; while (true) { if (pos >= len) { result += text.substring(start, pos); scanError = 2; break; } var ch = text.charCodeAt(pos); if (ch === 34) { result += text.substring(start, pos); pos++; break; } if (ch === 92) { result += text.substring(start, pos); pos++; if (pos >= len) { scanError = 2; break; } var ch2 = text.charCodeAt(pos++); switch (ch2) { case 34: result += '"'; break; case 92: result += "\\"; break; case 47: result += "/"; break; case 98: result += "\b"; break; case 102: result += "\f"; break; case 110: result += "\n"; break; case 114: result += "\r"; break; case 116: result += " "; break; case 117: var ch3 = scanHexDigits(4, true); if (ch3 >= 0) { result += String.fromCharCode(ch3); } else { scanError = 4; } break; default: scanError = 5; } start = pos; continue; } if (ch >= 0 && ch <= 31) { if (isLineBreak(ch)) { result += text.substring(start, pos); scanError = 2; break; } else { scanError = 6; } } pos++; } return result; } function scanNext() { value = ""; scanError = 0; tokenOffset = pos; lineStartOffset = lineNumber; prevTokenLineStartOffset = tokenLineStartOffset; if (pos >= len) { tokenOffset = len; return token = 17; } var code = text.charCodeAt(pos); if (isWhiteSpace(code)) { do { pos++; value += String.fromCharCode(code); code = text.charCodeAt(pos); } while (isWhiteSpace(code)); return token = 15; } if (isLineBreak(code)) { pos++; value += String.fromCharCode(code); if (code === 13 && text.charCodeAt(pos) === 10) { pos++; value += "\n"; } lineNumber++; tokenLineStartOffset = pos; return token = 14; } switch (code) { case 123: pos++; return token = 1; case 125: pos++; return token = 2; case 91: pos++; return token = 3; case 93: pos++; return token = 4; case 58: pos++; return token = 6; case 44: pos++; return token = 5; case 34: pos++; value = scanString(); return token = 10; case 47: var start = pos - 1; if (text.charCodeAt(pos + 1) === 47) { pos += 2; while (pos < len) { if (isLineBreak(text.charCodeAt(pos))) { break; } pos++; } value = text.substring(start, pos); return token = 12; } if (text.charCodeAt(pos + 1) === 42) { pos += 2; var safeLength = len - 1; var commentClosed = false; while (pos < safeLength) { var ch = text.charCodeAt(pos); if (ch === 42 && text.charCodeAt(pos + 1) === 47) { pos += 2; commentClosed = true; break; } pos++; if (isLineBreak(ch)) { if (ch === 13 && text.charCodeAt(pos) === 10) { pos++; } lineNumber++; tokenLineStartOffset = pos; } } if (!commentClosed) { pos++; scanError = 1; } value = text.substring(start, pos); return token = 13; } value += String.fromCharCode(code); pos++; return token = 16; case 45: value += String.fromCharCode(code); pos++; if (pos === len || !isDigit(text.charCodeAt(pos))) { return token = 16; } case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: value += scanNumber(); return token = 11; default: while (pos < len && isUnknownContentCharacter(code)) { pos++; code = text.charCodeAt(pos); } if (tokenOffset !== pos) { value = text.substring(tokenOffset, pos); switch (value) { case "true": return token = 8; case "false": return token = 9; case "null": return token = 7; } return token = 16; } value += String.fromCharCode(code); pos++; return token = 16; } } function isUnknownContentCharacter(code) { if (isWhiteSpace(code) || isLineBreak(code)) { return false; } switch (code) { case 125: case 93: case 123: case 91: case 34: case 58: case 44: case 47: return false; } return true; } function scanNextNonTrivia() { var result; do { result = scanNext(); } while (result >= 12 && result <= 15); return result; } return { setPosition, getPosition: function() { return pos; }, scan: ignoreTrivia ? scanNextNonTrivia : scanNext, getToken: function() { return token; }, getTokenValue: function() { return value; }, getTokenOffset: function() { return tokenOffset; }, getTokenLength: function() { return pos - tokenOffset; }, getTokenStartLine: function() { return lineStartOffset; }, getTokenStartCharacter: function() { return tokenOffset - prevTokenLineStartOffset; }, getTokenError: function() { return scanError; } }; } function isWhiteSpace(ch) { return ch === 32 || ch === 9 || ch === 11 || ch === 12 || ch === 160 || ch === 5760 || ch >= 8192 && ch <= 8203 || ch === 8239 || ch === 8287 || ch === 12288 || ch === 65279; } function isLineBreak(ch) { return ch === 10 || ch === 13 || ch === 8232 || ch === 8233; } function isDigit(ch) { return ch >= 48 && ch <= 57; } // node_modules/jsonc-parser/lib/esm/impl/format.js function format(documentText, range, options) { var initialIndentLevel; var formatText; var formatTextStart; var rangeStart; var rangeEnd; if (range) { rangeStart = range.offset; rangeEnd = rangeStart + range.length; formatTextStart = rangeStart; while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) { formatTextStart--; } var endOffset = rangeEnd; while (endOffset < documentText.length && !isEOL(documentText, endOffset)) { endOffset++; } formatText = documentText.substring(formatTextStart, endOffset); initialIndentLevel = computeIndentLevel(formatText, options); } else { formatText = documentText; initialIndentLevel = 0; formatTextStart = 0; rangeStart = 0; rangeEnd = documentText.length; } var eol = getEOL(options, documentText); var lineBreak = false; var indentLevel = 0; var indentValue; if (options.insertSpaces) { indentValue = repeat(" ", options.tabSize || 4); } else { indentValue = " "; } var scanner = createScanner(formatText, false); var hasError = false; function newLineAndIndent() { return eol + repeat(indentValue, initialIndentLevel + indentLevel); } function scanNext() { var token = scanner.scan(); lineBreak = false; while (token === 15 || token === 14) { lineBreak = lineBreak || token === 14; token = scanner.scan(); } hasError = token === 16 || scanner.getTokenError() !== 0; return token; } var editOperations = []; function addEdit(text, startOffset, endOffset2) { if (!hasError && (!range || startOffset < rangeEnd && endOffset2 > rangeStart) && documentText.substring(startOffset, endOffset2) !== text) { editOperations.push({ offset: startOffset, length: endOffset2 - startOffset, content: text }); } } var firstToken = scanNext(); if (firstToken !== 17) { var firstTokenStart = scanner.getTokenOffset() + formatTextStart; var initialIndent = repeat(indentValue, initialIndentLevel); addEdit(initialIndent, formatTextStart, firstTokenStart); } while (firstToken !== 17) { var firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart; var secondToken = scanNext(); var replaceContent = ""; var needsLineBreak = false; while (!lineBreak && (secondToken === 12 || secondToken === 13)) { var commentTokenStart = scanner.getTokenOffset() + formatTextStart; addEdit(" ", firstTokenEnd, commentTokenStart); firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart; needsLineBreak = secondToken === 12; replaceContent = needsLineBreak ? newLineAndIndent() : ""; secondToken = scanNext(); } if (secondToken === 2) { if (firstToken !== 1) { indentLevel--; replaceContent = newLineAndIndent(); } } else if (secondToken === 4) { if (firstToken !== 3) { indentLevel--; replaceContent = newLineAndIndent(); } } else { switch (firstToken) { case 3: case 1: indentLevel++; replaceContent = newLineAndIndent(); break; case 5: case 12: replaceContent = newLineAndIndent(); break; case 13: if (lineBreak) { replaceContent = newLineAndIndent(); } else if (!needsLineBreak) { replaceContent = " "; } break; case 6: if (!needsLineBreak) { replaceContent = " "; } break; case 10: if (secondToken === 6) { if (!needsLineBreak) { replaceContent = ""; } break; } case 7: case 8: case 9: case 11: case 2: case 4: if (secondToken === 12 || secondToken === 13) { if (!needsLineBreak) { replaceContent = " "; } } else if (secondToken !== 5 && secondToken !== 17) { hasError = true; } break; case 16: hasError = true; break; } if (lineBreak && (secondToken === 12 || secondToken === 13)) { replaceContent = newLineAndIndent(); } } if (secondToken === 17) { replaceContent = options.insertFinalNewline ? eol : ""; } var secondTokenStart = scanner.getTokenOffset() + formatTextStart; addEdit(replaceContent, firstTokenEnd, secondTokenStart); firstToken = secondToken; } return editOperations; } function repeat(s, count) { var result = ""; for (var i = 0; i < count; i++) { result += s; } return result; } function computeIndentLevel(content, options) { var i = 0; var nChars = 0; var tabSize = options.tabSize || 4; while (i < content.length) { var ch = content.charAt(i); if (ch === " ") { nChars++; } else if (ch === " ") { nChars += tabSize; } else { break; } i++; } return Math.floor(nChars / tabSize); } function getEOL(options, text) { for (var i = 0; i < text.length; i++) { var ch = text.charAt(i); if (ch === "\r") { if (i + 1 < text.length && text.charAt(i + 1) === "\n") { return "\r\n"; } return "\r"; } else if (ch === "\n") { return "\n"; } } return options && options.eol || "\n"; } function isEOL(text, offset) { return "\r\n".indexOf(text.charAt(offset)) !== -1; } // node_modules/jsonc-parser/lib/esm/impl/parser.js var ParseOptions; (function(ParseOptions2) { ParseOptions2.DEFAULT = { allowTrailingComma: false }; })(ParseOptions || (ParseOptions = {})); function parse(text, errors, options) { if (errors === void 0) { errors = []; } if (options === void 0) { options = ParseOptions.DEFAULT; } var currentProperty = null; var currentParent = []; var previousParents = []; function onValue(value) { if (Array.isArray(currentParent)) { currentParent.push(value); } else if (currentProperty !== null) { currentParent[currentProperty] = value; } } var visitor = { onObjectBegin: function() { var object = {}; onValue(object); previousParents.push(currentParent); currentParent = object; currentProperty = null; }, onObjectProperty: function(name) { currentProperty = name; }, onObjectEnd: function() { currentParent = previousParents.pop(); }, onArrayBegin: function() { var array = []; onValue(array); previousParents.push(currentParent); currentParent = array; currentProperty = null; }, onArrayEnd: function() { currentParent = previousParents.pop(); }, onLiteralValue: onValue, onError: function(error, offset, length) { errors.push({ error, offset, length }); } }; visit(text, visitor, options); return currentParent[0]; } function getNodePath(node) { if (!node.parent || !node.parent.children) { return []; } var path = getNodePath(node.parent); if (node.parent.type === "property") { var key = node.parent.children[0].value; path.push(key); } else if (node.parent.type === "array") { var index = node.parent.children.indexOf(node); if (index !== -1) { path.push(index); } } return path; } function getNodeValue(node) { switch (node.type) { case "array": return node.children.map(getNodeValue); case "object": var obj = /* @__PURE__ */ Object.create(null); for (var _i = 0, _a = node.children; _i < _a.length; _i++) { var prop = _a[_i]; var valueNode = prop.children[1]; if (valueNode) { obj[prop.children[0].value] = getNodeValue(valueNode); } } return obj; case "null": case "string": case "number": case "boolean": return node.value; default: return void 0; } } 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; } function findNodeAtOffset(node, offset, includeRightBound) { if (includeRightBound === void 0) { includeRightBound = false; } if (contains(node, offset, includeRightBound)) { var children = node.children; if (Array.isArray(children)) { for (var i = 0; i < children.length && children[i].offset <= offset; i++) { var item = findNodeAtOffset(children[i], offset, includeRightBound); if (item) { return item; } } } return node; } return void 0; } function visit(text, visitor, options) { if (options === void 0) { options = ParseOptions.DEFAULT; } var _scanner = createScanner(text, false); function toNoArgVisit(visitFunction) { return visitFunction ? function() { return visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()); } : function() { return true; }; } function toOneArgVisit(visitFunction) { return visitFunction ? function(arg) { return visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()); } : function() { return true; }; } var onObjectBegin = toNoArgVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisit(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisit(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisit(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError); var disallowComments = options && options.disallowComments; var allowTrailingComma = options && options.allowTrailingComma; function scanNext() { while (true) { var token = _scanner.scan(); switch (_scanner.getTokenError()) { case 4: handleError(14); break; case 5: handleError(15); break; case 3: handleError(13); break; case 1: if (!disallowComments) { handleError(11); } break; case 2: handleError(12); break; case 6: handleError(16); break; } switch (token) { case 12: case 13: if (disallowComments) { handleError(10); } else { onComment(); } break; case 16: handleError(1); break; case 15: case 14: break; default: return token; } } } function handleError(error, skipUntilAfter, skipUntil) { if (skipUntilAfter === void 0) { skipUntilAfter = []; } if (skipUntil === void 0) { skipUntil = []; } onError(error); if (skipUntilAfter.length + skipUntil.length > 0) { var token = _scanner.getToken(); while (token !== 17) { if (skipUntilAfter.indexOf(token) !== -1) { scanNext(); break; } else if (skipUntil.indexOf(token) !== -1) { break; } token = scanNext(); } } } function parseString(isValue) { var value = _scanner.getTokenValue(); if (isValue) { onLiteralValue(value); } else { onObjectProperty(value); } scanNext(); return true; } function parseLiteral() { switch (_scanner.getToken()) { case 11: var tokenValue = _scanner.getTokenValue(); var value = Number(tokenValue); if (isNaN(value)) { handleError(2); value = 0; } onLiteralValue(value); break; case 7: onLiteralValue(null); break; case 8: onLiteralValue(true); break; case 9: onLiteralValue(false); break; default: return false; } scanNext(); return true; } function parseProperty() { if (_scanner.getToken() !== 10) { handleError(3, [], [2, 5]); return false; } parseString(false); if (_scanner.getToken() === 6) { onSeparator(":"); scanNext(); if (!parseValue()) { handleError(4, [], [2, 5]); } } else { handleError(5, [], [2, 5]); } return true; } function parseObject() { onObjectBegin(); scanNext(); var needsComma = false; while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) { if (_scanner.getToken() === 5) { if (!needsComma) { handleError(4, [], []); } onSeparator(","); scanNext(); if (_scanner.getToken() === 2 && allowTrailingComma) { break; } } else if (needsComma) { handleError(6, [], []); } if (!parseProperty()) { handleError(4, [], [2, 5]); } needsComma = true; } onObjectEnd(); if (_scanner.getToken() !== 2) { handleError(7, [2], []); } else { scanNext(); } return true; } function parseArray() { onArrayBegin(); scanNext(); var needsComma = false; while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) { if (_scanner.getToken() === 5) { if (!needsComma) { handleError(4, [], []); } onSeparator(","); scanNext(); if (_scanner.getToken() === 4 && allowTrailingComma) { break; } } else if (needsComma) { handleError(6, [], []); } if (!parseValue()) { handleError(4, [], [4, 5]); } needsComma = true; } onArrayEnd(); if (_scanner.getToken() !== 4) { handleError(8, [4], []); } else { scanNext(); } return true; } function parseValue() { switch (_scanner.getToken()) { case 3: return parseArray(); case 1: return parseObject(); case 10: return parseString(true); default: return parseLiteral(); } } scanNext(); if (_scanner.getToken() === 17) { if (options.allowEmptyContent) { return true; } handleError(4, [], []); return false; } if (!parseValue()) { handleError(4, [], []); return false; } if (_scanner.getToken() !== 17) { handleError(9, [], []); } return true; } // node_modules/jsonc-parser/lib/esm/main.js var createScanner2 = createScanner; var parse2 = parse; var findNodeAtOffset2 = findNodeAtOffset; var getNodePath2 = getNodePath; var getNodeValue2 = getNodeValue; function format2(documentText, range, options) { return format(documentText, range, options); } // 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/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) { var 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; } } } // node_modules/vscode-languageserver-types/lib/esm/main.js var integer; (function(integer2) { integer2.MIN_VALUE = -2147483648; integer2.MAX_VALUE = 2147483647; })(integer || (integer = {})); var uinteger; (function(uinteger2) { uinteger2.MIN_VALUE = 0; uinteger2.MAX_VALUE = 2147483647; })(uinteger || (uinteger = {})); var Position; (function(Position2) { function create(line, character) { if (line === Number.MAX_VALUE) { line = uinteger.MAX_VALUE; } if (character === Number.MAX_VALUE) { character = uinteger.MAX_VALUE; } return { line, character }; } Position2.create = create; function is(value) { var candidate = value; return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character); } Position2.is = is; })(Position || (Position = {})); var Range; (function(Range2) { function create(one, two, three, four) { if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) { return { start: Position.create(one, two), end: Position.create(three, four) }; } else if (Position.is(one) && Position.is(two)) { return { start: one, end: two }; } else { throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]"); } } Range2.create = create; function is(value) { var candidate = value; return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end); } Range2.is = is; })(Range || (Range = {})); var Location; (function(Location2) { function create(uri, range) { return { uri, range }; } Location2.create = create; function is(value) { var candidate = value; return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri)); } Location2.is = is; })(Location || (Location = {})); var LocationLink; (function(LocationLink2) { function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) { return { targetUri, targetRange, targetSelectionRange, originSelectionRange }; } LocationLink2.create = create; function is(value) { var candidate = value; return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri) && (Range.is(candidate.targetSelectionRange) || Is.undefined(candidate.targetSelectionRange)) && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange)); } LocationLink2.is = is; })(LocationLink || (LocationLink = {})); var Color; (function(Color2) { function create(red, green, blue, alpha) { return { red, green, blue, alpha }; } Color2.create = create; function is(value) { var candidate = value; return Is.numberRange(candidate.red, 0, 1) && Is.numberRange(candidate.green, 0, 1) && Is.numberRange(candidate.blue, 0, 1) && Is.numberRange(candidate.alpha, 0, 1); } Color2.is = is; })(Color || (Color = {})); var ColorInformation; (function(ColorInformation2) { function create(range, color) { return { range, color }; } ColorInformation2.create = create; function is(value) { var candidate = value; return Range.is(candidate.range) && Color.is(candidate.color); } ColorInformation2.is = is; })(ColorInformation || (ColorInformation = {})); var ColorPresentation; (function(ColorPresentation2) { function create(label, textEdit, additionalTextEdits) { return { label, textEdit, additionalTextEdits }; } ColorPresentation2.create = create; function is(value) { var candidate = value; return Is.string(candidate.label) && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate)) && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is)); } ColorPresentation2.is = is; })(ColorPresentation || (ColorPresentation = {})); var FoldingRangeKind; (function(FoldingRangeKind2) { FoldingRangeKind2["Comment"] = "comment"; FoldingRangeKind2["Imports"] = "imports"; FoldingRangeKind2["Region"] = "region"; })(FoldingRangeKind || (FoldingRangeKind = {})); var FoldingRange; (function(FoldingRange2) { function create(startLine, endLine, startCharacter, endCharacter, kind) { var result = { startLine, endLine }; if (Is.defined(startCharacter)) { result.startCharacter = startCharacter; } if (Is.defined(endCharacter)) { result.endCharacter = endCharacter; } if (Is.defined(kind)) { result.kind = kind; } return result; } FoldingRange2.create = create; function is(value) { var candidate = value; return Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine) && (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter)) && (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter)) && (Is.undefined(candidate.kind) || Is.string(candidate.kind)); } FoldingRange2.is = is; })(FoldingRange || (FoldingRange = {})); var DiagnosticRelatedInformation; (function(DiagnosticRelatedInformation2) { function create(location, message) { return { location, message }; } DiagnosticRelatedInformation2.create = create; function is(value) { var candidate = value; return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message); } DiagnosticRelatedInformation2.is = is; })(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {})); var DiagnosticSeverity; (function(DiagnosticSeverity2) { DiagnosticSeverity2.Error = 1; DiagnosticSeverity2.Warning = 2; DiagnosticSeverity2.Information = 3; DiagnosticSeverity2.Hint = 4; })(DiagnosticSeverity || (DiagnosticSeverity = {})); var DiagnosticTag; (function(DiagnosticTag2) { DiagnosticTag2.Unnecessary = 1; DiagnosticTag2.Deprecated = 2; })(DiagnosticTag || (DiagnosticTag = {})); var CodeDescription; (function(CodeDescription2) { function is(value) { var candidate = value; return candidate !== void 0 && candidate !== null && Is.string(candidate.href); } CodeDescription2.is = is; })(CodeDescription || (CodeDescription = {})); var Diagnostic; (function(Diagnostic2) { function create(range, message, severity, code, source, relatedInformation) { var result = { range, message }; if (Is.defined(severity)) { result.severity = severity; } if (Is.defined(code)) { result.code = code; } if (Is.defined(source)) { result.source = source; } if (Is.defined(relatedInformation)) { result.relatedInformation = relatedInformation; } return result; } Diagnostic2.create = create; function is(value) { var _a; var candidate = value; return Is.defined(candidate) && Range.is(candidate.range) && Is.string(candidate.message) && (Is.number(candidate.severity) || Is.undefined(candidate.severity)) && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code)) && (Is.undefined(candidate.codeDescription) || Is.string((_a = candidate.codeDescription) === null || _a === void 0 ? void 0 : _a.href)) && (Is.string(candidate.source) || Is.undefined(candidate.source)) && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is)); } Diagnostic2.is = is; })(Diagnostic || (Diagnostic = {})); var Command; (function(Command2) { function create(title, command) { var args = []; for (var _i = 2; _i < arguments.length; _i++) { args[_i - 2] = arguments[_i]; } var result = { title, command }; if (Is.defined(args) && args.length > 0) { result.arguments = args; } return result; } Command2.create = create; function is(value) { var candidate = value; return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command); } Command2.is = is; })(Command || (Command = {})); var TextEdit; (function(TextEdit2) { function replace(range, newText) { return { range, newText }; } TextEdit2.replace = replace; function insert(position, newText) { return { range: { start: position, end: position }, newText }; } TextEdit2.insert = insert; function del(range) { return { range, newText: "" }; } TextEdit2.del = del; function is(value) { var candidate = value; return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range.is(candidate.range); } TextEdit2.is = is; })(TextEdit || (TextEdit = {})); var ChangeAnnotation; (function(ChangeAnnotation2) { function create(label, needsConfirmation, description) { var result = { label }; if (needsConfirmation !== void 0) { result.needsConfirmation = needsConfirmation; } if (description !== void 0) { result.description = description; } return result; } ChangeAnnotation2.create = create; function is(value) { var candidate = value; return candidate !== void 0 && Is.objectLiteral(candidate) && Is.string(candidate.label) && (Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === void 0) && (Is.string(candidate.description) || candidate.description === void 0); } ChangeAnnotation2.is = is; })(ChangeAnnotation || (ChangeAnnotation = {})); var ChangeAnnotationIdentifier; (function(ChangeAnnotationIdentifier2) { function is(value) { var candidate = value; return typeof candidate === "string"; } ChangeAnnotationIdentifier2.is = is; })(ChangeAnnotationIdentifier || (ChangeAnnotationIdentifier = {})); var AnnotatedTextEdit; (function(AnnotatedTextEdit2) { function replace(range, newText, annotation) { return { range, newText, annotationId: annotation }; } AnnotatedTextEdit2.replace = replace; function insert(position, newText, annotation) { return { range: { start: position, end: position }, newText, annotationId: annotation }; } AnnotatedTextEdit2.insert = insert; function del(range, annotation) { return { range, newText: "", annotationId: annotation }; } AnnotatedTextEdit2.del = del; function is(value) { var candidate = value; return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId)); } AnnotatedTextEdit2.is = is; })(AnnotatedTextEdit || (AnnotatedTextEdit = {})); var TextDocumentEdit; (function(TextDocumentEdit2) { function create(textDocument, edits) { return { textDocument, edits }; } TextDocumentEdit2.create = create; function is(value) { var candidate = value; return Is.defined(candidate) && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument) && Array.isArray(candidate.edits); } TextDocumentEdit2.is = is; })(TextDocumentEdit || (TextDocumentEdit = {})); var CreateFile; (function(CreateFile2) { function create(uri, options, annotation) { var result = { kind: "create", uri }; if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) { result.options = options; } if (annotation !== void 0) { result.annotationId = annotation; } return result; } CreateFile2.create = create; function is(value) { var candidate = value; return candidate && candidate.kind === "create" && Is.string(candidate.uri) && (candidate.options === void 0 || (candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId)); } CreateFile2.is = is; })(CreateFile || (CreateFile = {})); var RenameFile; (function(RenameFile2) { function create(oldUri, newUri, options, annotation) { var result = { kind: "rename", oldUri, newUri }; if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) { result.options = options; } if (annotation !== void 0) { result.annotationId = annotation; } return result; } RenameFile2.create = create; function is(value) { var candidate = value; return candidate && candidate.kind === "rename" && Is.string(candidate.oldUri) && Is.string(candidate.newUri) && (candidate.options === void 0 || (candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId)); } RenameFile2.is = is; })(RenameFile || (RenameFile = {})); var DeleteFile; (function(DeleteFile2) { function create(uri, options, annotation) { var result = { kind: "delete", uri }; if (options !== void 0 && (options.recursive !== void 0 || options.ignoreIfNotExists !== void 0)) { result.options = options; } if (annotation !== void 0) { result.annotationId = annotation; } return result; } DeleteFile2.create = create; function is(value) { var candidate = value; return candidate && candidate.kind === "delete" && Is.string(candidate.uri) && (candidate.options === void 0 || (candidate.options.recursive === void 0 || Is.boolean(candidate.options.recursive)) && (candidate.options.ignoreIfNotExists === void 0 || Is.boolean(candidate.options.ignoreIfNotExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId)); } DeleteFile2.is = is; })(DeleteFile || (DeleteFile = {})); var WorkspaceEdit; (function(WorkspaceEdit2) { function is(value) { var candidate = value; return candidate && (candidate.changes !== void 0 || candidate.documentChanges !== void 0) && (candidate.documentChanges === void 0 || candidate.documentChanges.every(function(change) { if (Is.string(change.kind)) { return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change); } else { return TextDocumentEdit.is(change); } })); } WorkspaceEdit2.is = is; })(WorkspaceEdit || (WorkspaceEdit = {})); var TextEditChangeImpl = function() { function TextEditChangeImpl2(edits, changeAnnotations) { this.edits = edits; this.changeAnnotations = changeAnnotations; } TextEditChangeImpl2.prototype.insert = function(position, newText, annotation) { var edit; var id; if (annotation === void 0) { edit = TextEdit.insert(position, newText); } else if (ChangeAnnotationIdentifier.is(annotation)) { id = annotation; edit = AnnotatedTextEdit.insert(position, newText, annotation); } else { this.assertChangeAnnotations(this.changeAnnotations); id = this.changeAnnotations.manage(annotation); edit = AnnotatedTextEdit.insert(position, newText, id); } this.edits.push(edit); if (id !== void 0) { return id; } }; TextEditChangeImpl2.prototype.replace = function(range, newText, annotation) { var edit; var id; if (annotation === void 0) { edit = TextEdit.replace(range, newText); } else if (ChangeAnnotationIdentifier.is(annotation)) { id = annotation; edit = AnnotatedTextEdit.replace(range, newText, annotation); } else { this.assertChangeAnnotations(this.changeAnnotations); id = this.changeAnnotations.manage(annotation); edit = AnnotatedTextEdit.replace(range, newText, id); } this.edits.push(edit); if (id !== void 0) { return id; } }; TextEditChangeImpl2.prototype.delete = function(range, annotation) { var edit; var id; if (annotation === void 0) { edit = TextEdit.del(range); } else if (ChangeAnnotationIdentifier.is(annotation)) { id = annotation; edit = AnnotatedTextEdit.del(range, annotation); } else { this.assertChangeAnnotations(this.changeAnnotations); id = this.changeAnnotations.manage(annotation); edit = AnnotatedTextEdit.del(range, id); } this.edits.push(edit); if (id !== void 0) { return id; } }; TextEditChangeImpl2.prototype.add = function(edit) { this.edits.push(edit); }; TextEditChangeImpl2.prototype.all = function() { return this.edits; }; TextEditChangeImpl2.prototype.clear = function() { this.edits.splice(0, this.edits.length); }; TextEditChangeImpl2.prototype.assertChangeAnnotations = function(value) { if (value === void 0) { throw new Error("Text edit change is not configured to manage change annotations."); } }; return TextEditChangeImpl2; }(); var ChangeAnnotations = function() { function ChangeAnnotations2(annotations) { this._annotations = annotations === void 0 ? /* @__PURE__ */ Object.create(null) : annotations; this._counter = 0; this._size = 0; } ChangeAnnotations2.prototype.all = function() { return this._annotations; }; Object.defineProperty(ChangeAnnotations2.prototype, "size", { get: function() { return this._size; }, enumerable: false, configurable: true }); ChangeAnnotations2.prototype.manage = function(idOrAnnotation, annotation) { var id; if (ChangeAnnotationIdentifier.is(idOrAnnotation)) { id = idOrAnnotation; } else { id = this.nextId(); annotation = idOrAnnotation; } if (this._annotations[id] !== void 0) { throw new Error("Id " + id + " is already in use."); } if (annotation === void 0) { throw new Error("No annotation provided for id " + id); } this._annotations[id] = annotation; this._size++; return id; }; ChangeAnnotations2.prototype.nextId = function() { this._counter++; return this._counter.toString(); }; return ChangeAnnotations2; }(); var WorkspaceChange = function() { function WorkspaceChange2(workspaceEdit) { var _this = this; this._textEditChanges = /* @__PURE__ */ Object.create(null); if (workspaceEdit !== void 0) { this._workspaceEdit = workspaceEdit; if (workspaceEdit.documentChanges) { this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations); workspaceEdit.changeAnnotations = this._changeAnnotations.all(); workspaceEdit.documentChanges.forEach(function(change) { if (TextDocumentEdit.is(change)) { var textEditChange = new TextEditChangeImpl(change.edits, _this._changeAnnotations); _this._textEditChanges[change.textDocument.uri] = textEditChange; } }); } else if (workspaceEdit.changes) { Object.keys(workspaceEdit.changes).forEach(function(key) { var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]); _this._textEditChanges[key] = textEditChange; }); } } else { this._workspaceEdit = {}; } } Object.defineProperty(WorkspaceChange2.prototype, "edit", { get: function() { this.initDocumentChanges(); if (this._changeAnnotations !== void 0) { if (this._changeAnnotations.size === 0) { this._workspaceEdit.changeAnnotations = void 0; } else { this._workspaceEdit.changeAnnotations = this._changeAnnotations.all(); } } return this._workspaceEdit; }, enumerable: false, configurable: true }); WorkspaceChange2.prototype.getTextEditChange = function(key) { if (OptionalVersionedTextDocumentIdentifier.is(key)) { this.initDocumentChanges(); if (this._workspaceEdit.documentChanges === void 0) { throw new Error("Workspace edit is not configured for document changes."); } var textDocument = { uri: key.uri, version: key.version }; var result = this._textEditChanges[textDocument.uri]; if (!result) { var edits = []; var textDocumentEdit = { textDocument, edits }; this._workspaceEdit.documentChanges.push(textDocumentEdit); result = new TextEditChangeImpl(edits, this._changeAnnotations); this._textEditChanges[textDocument.uri] = result; } return result; } else { this.initChanges(); if (this._workspaceEdit.changes === void 0) { throw new Error("Workspace edit is not configured for normal text edit changes."); } var result = this._textEditChanges[key]; if (!result) { var edits = []; this._workspaceEdit.changes[key] = edits; result = new TextEditChangeImpl(edits); this._textEditChanges[key] = result; } return result; } }; WorkspaceChange2.prototype.initDocumentChanges = function() { if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) { this._changeAnnotations = new ChangeAnnotations(); this._workspaceEdit.documentChanges = []; this._workspaceEdit.changeAnnotations = this._changeAnnotations.all(); } }; WorkspaceChange2.prototype.initChanges = function() { if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) { this._workspaceEdit.changes = /* @__PURE__ */ Object.create(null); } }; WorkspaceChange2.prototype.createFile = function(uri, optionsOrAnnotation, options) { this.initDocumentChanges(); if (this._workspaceEdit.documentChanges === void 0) { throw new Error("Workspace edit is not configured for document changes."); } var annotation; if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) { annotation = optionsOrAnnotation; } else { options = optionsOrAnnotation; } var operation; var id; if (annotation === void 0) { operation = CreateFile.create(uri, options); } else { id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation); operation = CreateFile.create(uri, options, id); } this._workspaceEdit.documentChanges.push(operation); if (id !== void 0) { return id; } }; WorkspaceChange2.prototype.renameFile = function(oldUri, newUri, optionsOrAnnotation, options) { this.initDocumentChanges(); if (this._workspaceEdit.documentChanges === void 0) { throw new Error("Workspace edit is not configured for document changes."); } var annotation; if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) { annotation = optionsOrAnnotation; } else { options = optionsOrAnnotation; } var operation; var id; if (annotation === void 0) { operation = RenameFile.create(oldUri, newUri, options); } else { id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation); operation = RenameFile.create(oldUri, newUri, options, id); } this._workspaceEdit.documentChanges.push(operation); if (id !== void 0) { return id; } }; WorkspaceChange2.prototype.deleteFile = function(uri, optionsOrAnnotation, options) { this.initDocumentChanges(); if (this._workspaceEdit.documentChanges === void 0) { throw new Error("Workspace edit is not configured for document changes."); } var annotation; if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIde