/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function _format$1(message, args) { let result; if (args.length === 0) { result = message; } else { result = message.replace(/\{(\d+)\}/g, function (match, rest) { const index = rest[0]; return typeof args[index] !== 'undefined' ? args[index] : match; }); } return result; } function localize(data, message, ...args) { return _format$1(message, args); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var _a$d; const LANGUAGE_DEFAULT = 'en'; let _isWindows = false; let _isMacintosh = false; let _isLinux = false; let _isNative = false; let _isWeb = false; let _isIOS = false; let _locale = undefined; let _language = LANGUAGE_DEFAULT; let _translationsConfigFile = undefined; let _userAgent = undefined; const globals = (typeof self === 'object' ? self : typeof global === 'object' ? global : {}); let nodeProcess = undefined; if (typeof globals.vscode !== 'undefined' && typeof globals.vscode.process !== 'undefined') { // Native environment (sandboxed) nodeProcess = globals.vscode.process; } else if (typeof process !== 'undefined') { // Native environment (non-sandboxed) nodeProcess = process; } const isElectronProcess = typeof ((_a$d = nodeProcess === null || nodeProcess === void 0 ? void 0 : nodeProcess.versions) === null || _a$d === void 0 ? void 0 : _a$d.electron) === 'string'; const isElectronRenderer = isElectronProcess && (nodeProcess === null || nodeProcess === void 0 ? void 0 : nodeProcess.type) === 'renderer'; // Web environment if (typeof navigator === 'object' && !isElectronRenderer) { _userAgent = navigator.userAgent; _isWindows = _userAgent.indexOf('Windows') >= 0; _isMacintosh = _userAgent.indexOf('Macintosh') >= 0; _isIOS = (_userAgent.indexOf('Macintosh') >= 0 || _userAgent.indexOf('iPad') >= 0 || _userAgent.indexOf('iPhone') >= 0) && !!navigator.maxTouchPoints && navigator.maxTouchPoints > 0; _isLinux = _userAgent.indexOf('Linux') >= 0; _isWeb = true; _locale = navigator.language; _language = _locale; } // Native environment else if (typeof nodeProcess === 'object') { _isWindows = (nodeProcess.platform === 'win32'); _isMacintosh = (nodeProcess.platform === 'darwin'); _isLinux = (nodeProcess.platform === 'linux'); _isLinux && !!nodeProcess.env['SNAP'] && !!nodeProcess.env['SNAP_REVISION']; _locale = LANGUAGE_DEFAULT; _language = LANGUAGE_DEFAULT; const rawNlsConfig = nodeProcess.env['VSCODE_NLS_CONFIG']; if (rawNlsConfig) { try { const nlsConfig = JSON.parse(rawNlsConfig); const resolved = nlsConfig.availableLanguages['*']; _locale = nlsConfig.locale; // VSCode's default language is 'en' _language = resolved ? resolved : LANGUAGE_DEFAULT; _translationsConfigFile = nlsConfig._translationsConfigFile; } catch (e) { } } _isNative = true; } // Unknown environment else { console.error('Unable to resolve platform.'); } const isWindows = _isWindows; const isMacintosh = _isMacintosh; const isLinux = _isLinux; const isNative = _isNative; const isWeb = _isWeb; const isIOS = _isIOS; const userAgent$1 = _userAgent; /** * The language used for the user interface. The format of * the string is all lower case (e.g. zh-tw for Traditional * Chinese) */ const language$1c = _language; /** * See https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#:~:text=than%204%2C%20then-,set%20timeout%20to%204,-. * * Works similarly to `setTimeout(0)` but doesn't suffer from the 4ms artificial delay * that browsers set when the nesting level is > 5. */ const setTimeout0 = (() => { if (typeof globals.postMessage === 'function' && !globals.importScripts) { let pending = []; globals.addEventListener('message', (e) => { if (e.data && e.data.vscodeScheduleAsyncWork) { for (let i = 0, len = pending.length; i < len; i++) { const candidate = pending[i]; if (candidate.id === e.data.vscodeScheduleAsyncWork) { pending.splice(i, 1); candidate.callback(); return; } } } }); let lastId = 0; return (callback) => { const myId = ++lastId; pending.push({ id: myId, callback: callback }); globals.postMessage({ vscodeScheduleAsyncWork: myId }, '*'); }; } return (callback) => setTimeout(callback); })(); const OS = (_isMacintosh || _isIOS ? 2 /* Macintosh */ : (_isWindows ? 1 /* Windows */ : 3 /* Linux */)); let _isLittleEndian = true; let _isLittleEndianComputed = false; function isLittleEndian() { if (!_isLittleEndianComputed) { _isLittleEndianComputed = true; const test = new Uint8Array(2); test[0] = 1; test[1] = 2; const view = new Uint16Array(test.buffer); _isLittleEndian = (view[0] === (2 << 8) + 1); } return _isLittleEndian; } const isChrome$1 = !!(userAgent$1 && userAgent$1.indexOf('Chrome') >= 0); const isFirefox$1 = !!(userAgent$1 && userAgent$1.indexOf('Firefox') >= 0); const isSafari$1 = !!(!isChrome$1 && (userAgent$1 && userAgent$1.indexOf('Safari') >= 0)); const isEdge = !!(userAgent$1 && userAgent$1.indexOf('Edg/') >= 0); !!(userAgent$1 && userAgent$1.indexOf('Android') >= 0); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const USUAL_WORD_SEPARATORS = '`~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?'; /** * Create a word definition regular expression based on default word separators. * Optionally provide allowed separators that should be included in words. * * The default would look like this: * /(-?\d*\.\d\w*)|([^\`\~\!\@\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g */ function createWordRegExp(allowInWords = '') { let source = '(-?\\d*\\.\\d\\w*)|([^'; for (const sep of USUAL_WORD_SEPARATORS) { if (allowInWords.indexOf(sep) >= 0) { continue; } source += '\\' + sep; } source += '\\s]+)'; return new RegExp(source, 'g'); } // catches numbers (including floating numbers) in the first group, and alphanum in the second const DEFAULT_WORD_REGEXP = createWordRegExp(); function ensureValidWordDefinition(wordDefinition) { let result = DEFAULT_WORD_REGEXP; if (wordDefinition && (wordDefinition instanceof RegExp)) { if (!wordDefinition.global) { let flags = 'g'; if (wordDefinition.ignoreCase) { flags += 'i'; } if (wordDefinition.multiline) { flags += 'm'; } if (wordDefinition.unicode) { flags += 'u'; } result = new RegExp(wordDefinition.source, flags); } else { result = wordDefinition; } } result.lastIndex = 0; return result; } const _defaultConfig = { maxLen: 1000, windowSize: 15, timeBudget: 150 }; function getWordAtText(column, wordDefinition, text, textOffset, config = _defaultConfig) { if (text.length > config.maxLen) { // don't throw strings that long at the regexp // but use a sub-string in which a word must occur let start = column - config.maxLen / 2; if (start < 0) { start = 0; } else { textOffset += start; } text = text.substring(start, column + config.maxLen / 2); return getWordAtText(column, wordDefinition, text, textOffset, config); } const t1 = Date.now(); const pos = column - 1 - textOffset; let prevRegexIndex = -1; let match = null; for (let i = 1;; i++) { // check time budget if (Date.now() - t1 >= config.timeBudget) { break; } // reset the index at which the regexp should start matching, also know where it // should stop so that subsequent search don't repeat previous searches const regexIndex = pos - config.windowSize * i; wordDefinition.lastIndex = Math.max(0, regexIndex); const thisMatch = _findRegexMatchEnclosingPosition(wordDefinition, text, pos, prevRegexIndex); if (!thisMatch && match) { // stop: we have something break; } match = thisMatch; // stop: searched at start if (regexIndex <= 0) { break; } prevRegexIndex = regexIndex; } if (match) { const result = { word: match[0], startColumn: textOffset + 1 + match.index, endColumn: textOffset + 1 + match.index + match[0].length }; wordDefinition.lastIndex = 0; return result; } return null; } function _findRegexMatchEnclosingPosition(wordDefinition, text, pos, stopPos) { let match; while (match = wordDefinition.exec(text)) { const matchIndex = match.index || 0; if (matchIndex <= pos && wordDefinition.lastIndex >= pos) { return match; } else if (stopPos > 0 && matchIndex > stopPos) { return null; } } return null; } /** * Returns the last element of an array. * @param array The array. * @param n Which element from the end (default is zero). */ function tail(array, n = 0) { return array[array.length - (1 + n)]; } function tail2(arr) { if (arr.length === 0) { throw new Error('Invalid tail call'); } return [arr.slice(0, arr.length - 1), arr[arr.length - 1]]; } function equals$1(one, other, itemEquals = (a, b) => a === b) { if (one === other) { return true; } if (!one || !other) { return false; } if (one.length !== other.length) { return false; } for (let i = 0, len = one.length; i < len; i++) { if (!itemEquals(one[i], other[i])) { return false; } } return true; } function binarySearch(array, key, comparator) { let low = 0, high = array.length - 1; while (low <= high) { const mid = ((low + high) / 2) | 0; const comp = comparator(array[mid], key); if (comp < 0) { low = mid + 1; } else if (comp > 0) { high = mid - 1; } else { return mid; } } return -(low + 1); } /** * Takes a sorted array and a function p. The array is sorted in such a way that all elements where p(x) is false * are located before all elements where p(x) is true. * @returns the least x for which p(x) is true or array.length if no element fullfills the given function. */ function findFirstInSorted(array, p) { let low = 0, high = array.length; if (high === 0) { return 0; // no children } while (low < high) { const mid = Math.floor((low + high) / 2); if (p(array[mid])) { high = mid; } else { low = mid + 1; } } return low; } function quickSelect(nth, data, compare) { nth = nth | 0; if (nth >= data.length) { throw new TypeError('invalid index'); } let pivotValue = data[Math.floor(data.length * Math.random())]; let lower = []; let higher = []; let pivots = []; for (let value of data) { const val = compare(value, pivotValue); if (val < 0) { lower.push(value); } else if (val > 0) { higher.push(value); } else { pivots.push(value); } } if (nth < lower.length) { return quickSelect(nth, lower, compare); } else if (nth < lower.length + pivots.length) { return pivots[0]; } else { return quickSelect(nth - (lower.length + pivots.length), higher, compare); } } function groupBy(data, compare) { const result = []; let currentGroup = undefined; for (const element of data.slice(0).sort(compare)) { if (!currentGroup || compare(currentGroup[0], element) !== 0) { currentGroup = [element]; result.push(currentGroup); } else { currentGroup.push(element); } } return result; } /** * @returns New array with all falsy values removed. The original array IS NOT modified. */ function coalesce(array) { return array.filter(e => !!e); } /** * @returns false if the provided object is an array and not empty. */ function isFalsyOrEmpty(obj) { return !Array.isArray(obj) || obj.length === 0; } function isNonEmptyArray(obj) { return Array.isArray(obj) && obj.length > 0; } /** * Removes duplicates from the given array. The optional keyFn allows to specify * how elements are checked for equality by returning an alternate value for each. */ function distinct(array, keyFn = value => value) { const seen = new Set(); return array.filter(element => { const key = keyFn(element); if (seen.has(key)) { return false; } seen.add(key); return true; }); } function findLast(arr, predicate) { const idx = lastIndex(arr, predicate); if (idx === -1) { return undefined; } return arr[idx]; } function lastIndex(array, fn) { for (let i = array.length - 1; i >= 0; i--) { const element = array[i]; if (fn(element)) { return i; } } return -1; } function firstOrDefault(array, notFoundValue) { return array.length > 0 ? array[0] : notFoundValue; } function flatten(arr) { return [].concat(...arr); } function range(arg, to) { let from = typeof to === 'number' ? arg : 0; if (typeof to === 'number') { from = arg; } else { from = 0; to = arg; } const result = []; if (from <= to) { for (let i = from; i < to; i++) { result.push(i); } } else { for (let i = from; i > to; i--) { result.push(i); } } return result; } /** * Insert `insertArr` inside `target` at `insertIndex`. * Please don't touch unless you understand https://jsperf.com/inserting-an-array-within-an-array */ function arrayInsert(target, insertIndex, insertArr) { const before = target.slice(0, insertIndex); const after = target.slice(insertIndex); return before.concat(insertArr, after); } /** * Pushes an element to the start of the array, if found. */ function pushToStart(arr, value) { const index = arr.indexOf(value); if (index > -1) { arr.splice(index, 1); arr.unshift(value); } } /** * Pushes an element to the end of the array, if found. */ function pushToEnd(arr, value) { const index = arr.indexOf(value); if (index > -1) { arr.splice(index, 1); arr.push(value); } } function asArray(x) { return Array.isArray(x) ? x : [x]; } /** * Insert the new items in the array. * @param array The original array. * @param start The zero-based location in the array from which to start inserting elements. * @param newItems The items to be inserted */ function insertInto(array, start, newItems) { const startIdx = getActualStartIndex(array, start); const originalLength = array.length; const newItemsLength = newItems.length; array.length = originalLength + newItemsLength; // Move the items after the start index, start from the end so that we don't overwrite any value. for (let i = originalLength - 1; i >= startIdx; i--) { array[i + newItemsLength] = array[i]; } for (let i = 0; i < newItemsLength; i++) { array[i + startIdx] = newItems[i]; } } /** * Removes elements from an array and inserts new elements in their place, returning the deleted elements. Alternative to the native Array.splice method, it * can only support limited number of items due to the maximum call stack size limit. * @param array The original array. * @param start The zero-based location in the array from which to start removing elements. * @param deleteCount The number of elements to remove. * @returns An array containing the elements that were deleted. */ function splice$1(array, start, deleteCount, newItems) { const index = getActualStartIndex(array, start); const result = array.splice(index, deleteCount); insertInto(array, index, newItems); return result; } /** * Determine the actual start index (same logic as the native splice() or slice()) * If greater than the length of the array, start will be set to the length of the array. In this case, no element will be deleted but the method will behave as an adding function, adding as many element as item[n*] provided. * If negative, it will begin that many elements from the end of the array. (In this case, the origin -1, meaning -n is the index of the nth last element, and is therefore equivalent to the index of array.length - n.) If array.length + start is less than 0, it will begin from index 0. * @param array The target array. * @param start The operation index. */ function getActualStartIndex(array, start) { return start < 0 ? Math.max(start + array.length, 0) : Math.min(start, array.length); } function compareBy(selector, comparator) { return (a, b) => comparator(selector(a), selector(b)); } /** * The natural order on numbers. */ const numberComparator = (a, b) => a - b; /** * Returns the first item that is equal to or greater than every other item. */ function findMaxBy(items, comparator) { if (items.length === 0) { return undefined; } let max = items[0]; for (let i = 1; i < items.length; i++) { const item = items[i]; if (comparator(item, max) > 0) { max = item; } } return max; } /** * Returns the last item that is equal to or greater than every other item. */ function findLastMaxBy(items, comparator) { if (items.length === 0) { return undefined; } let max = items[0]; for (let i = 1; i < items.length; i++) { const item = items[i]; if (comparator(item, max) >= 0) { max = item; } } return max; } /** * Returns the first item that is equal to or less than every other item. */ function findMinBy(items, comparator) { return findMaxBy(items, (a, b) => -comparator(a, b)); } class ArrayQueue { /** * Constructs a queue that is backed by the given array. Runtime is O(1). */ constructor(items) { this.items = items; this.firstIdx = 0; this.lastIdx = this.items.length - 1; } /** * Consumes elements from the beginning of the queue as long as the predicate returns true. * If no elements were consumed, `null` is returned. Has a runtime of O(result.length). */ takeWhile(predicate) { // P(k) := k <= this.lastIdx && predicate(this.items[k]) // Find s := min { k | k >= this.firstIdx && !P(k) } and return this.data[this.firstIdx...s) let startIdx = this.firstIdx; while (startIdx < this.items.length && predicate(this.items[startIdx])) { startIdx++; } const result = startIdx === this.firstIdx ? null : this.items.slice(this.firstIdx, startIdx); this.firstIdx = startIdx; return result; } /** * Consumes elements from the end of the queue as long as the predicate returns true. * If no elements were consumed, `null` is returned. * The result has the same order as the underlying array! */ takeFromEndWhile(predicate) { // P(k) := this.firstIdx >= k && predicate(this.items[k]) // Find s := max { k | k <= this.lastIdx && !P(k) } and return this.data(s...this.lastIdx] let endIdx = this.lastIdx; while (endIdx >= 0 && predicate(this.items[endIdx])) { endIdx--; } const result = endIdx === this.lastIdx ? null : this.items.slice(endIdx + 1, this.lastIdx + 1); this.lastIdx = endIdx; return result; } peek() { return this.items[this.firstIdx]; } dequeue() { const result = this.items[this.firstIdx]; this.firstIdx++; return result; } takeCount(count) { const result = this.items.slice(this.firstIdx, this.firstIdx + count); this.firstIdx += count; return result; } } /** * @returns whether the provided parameter is a JavaScript Array or not. */ function isArray(array) { return Array.isArray(array); } /** * @returns whether the provided parameter is a JavaScript String or not. */ function isString$1(str) { return (typeof str === 'string'); } /** * * @returns whether the provided parameter is of type `object` but **not** * `null`, an `array`, a `regexp`, nor a `date`. */ function isObject(obj) { // The method can't do a type cast since there are type (like strings) which // are subclasses of any put not positvely matched by the function. Hence type // narrowing results in wrong results. return typeof obj === 'object' && obj !== null && !Array.isArray(obj) && !(obj instanceof RegExp) && !(obj instanceof Date); } /** * In **contrast** to just checking `typeof` this will return `false` for `NaN`. * @returns whether the provided parameter is a JavaScript Number or not. */ function isNumber$1(obj) { return (typeof obj === 'number' && !isNaN(obj)); } /** * @returns whether the provided parameter is a JavaScript Boolean or not. */ function isBoolean(obj) { return (obj === true || obj === false); } /** * @returns whether the provided parameter is undefined. */ function isUndefined(obj) { return (typeof obj === 'undefined'); } /** * @returns whether the provided parameter is defined. */ function isDefined(arg) { return !isUndefinedOrNull(arg); } /** * @returns whether the provided parameter is undefined or null. */ function isUndefinedOrNull(obj) { return (isUndefined(obj) || obj === null); } function assertType(condition, type) { if (!condition) { throw new Error(type ? `Unexpected type, expected '${type}'` : 'Unexpected type'); } } /** * Asserts that the argument passed in is neither undefined nor null. */ function assertIsDefined(arg) { if (isUndefinedOrNull(arg)) { throw new Error('Assertion Failed: argument is undefined or null'); } return arg; } /** * @returns whether the provided parameter is a JavaScript Function or not. */ function isFunction(obj) { return (typeof obj === 'function'); } function validateConstraints(args, constraints) { const len = Math.min(args.length, constraints.length); for (let i = 0; i < len; i++) { validateConstraint(args[i], constraints[i]); } } function validateConstraint(arg, constraint) { if (isString$1(constraint)) { if (typeof arg !== constraint) { throw new Error(`argument does not match constraint: typeof ${constraint}`); } } else if (isFunction(constraint)) { try { if (arg instanceof constraint) { return; } } catch (_a) { // ignore } if (!isUndefinedOrNull(arg) && arg.constructor === constraint) { return; } if (constraint.length === 1 && constraint.call(undefined, arg) === true) { return; } throw new Error(`argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true`); } } function getAllPropertyNames(obj) { let res = []; let proto = Object.getPrototypeOf(obj); while (Object.prototype !== proto) { res = res.concat(Object.getOwnPropertyNames(proto)); proto = Object.getPrototypeOf(proto); } return res; } function getAllMethodNames(obj) { const methods = []; for (const prop of getAllPropertyNames(obj)) { if (typeof obj[prop] === 'function') { methods.push(prop); } } return methods; } function createProxyObject$1(methodNames, invoke) { const createProxyMethod = (method) => { return function () { const args = Array.prototype.slice.call(arguments, 0); return invoke(method, args); }; }; let result = {}; for (const methodName of methodNames) { result[methodName] = createProxyMethod(methodName); } return result; } /** * Converts null to undefined, passes all other values through. */ function withNullAsUndefined(x) { return x === null ? undefined : x; } function assertNever(value, message = 'Unreachable') { throw new Error(message); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function deepClone(obj) { if (!obj || typeof obj !== 'object') { return obj; } if (obj instanceof RegExp) { // See https://github.com/microsoft/TypeScript/issues/10990 return obj; } const result = Array.isArray(obj) ? [] : {}; Object.keys(obj).forEach((key) => { if (obj[key] && typeof obj[key] === 'object') { result[key] = deepClone(obj[key]); } else { result[key] = obj[key]; } }); return result; } function deepFreeze(obj) { if (!obj || typeof obj !== 'object') { return obj; } const stack = [obj]; while (stack.length > 0) { const obj = stack.shift(); Object.freeze(obj); for (const key in obj) { if (_hasOwnProperty.call(obj, key)) { const prop = obj[key]; if (typeof prop === 'object' && !Object.isFrozen(prop)) { stack.push(prop); } } } } return obj; } const _hasOwnProperty = Object.prototype.hasOwnProperty; function cloneAndChange(obj, changer) { return _cloneAndChange(obj, changer, new Set()); } function _cloneAndChange(obj, changer, seen) { if (isUndefinedOrNull(obj)) { return obj; } const changed = changer(obj); if (typeof changed !== 'undefined') { return changed; } if (isArray(obj)) { const r1 = []; for (const e of obj) { r1.push(_cloneAndChange(e, changer, seen)); } return r1; } if (isObject(obj)) { if (seen.has(obj)) { throw new Error('Cannot clone recursive data-structure'); } seen.add(obj); const r2 = {}; for (let i2 in obj) { if (_hasOwnProperty.call(obj, i2)) { r2[i2] = _cloneAndChange(obj[i2], changer, seen); } } seen.delete(obj); return r2; } return obj; } /** * Copies all properties of source into destination. The optional parameter "overwrite" allows to control * if existing properties on the destination should be overwritten or not. Defaults to true (overwrite). */ function mixin(destination, source, overwrite = true) { if (!isObject(destination)) { return source; } if (isObject(source)) { Object.keys(source).forEach(key => { if (key in destination) { if (overwrite) { if (isObject(destination[key]) && isObject(source[key])) { mixin(destination[key], source[key], overwrite); } else { destination[key] = source[key]; } } } else { destination[key] = source[key]; } }); } return destination; } function equals(one, other) { if (one === other) { return true; } if (one === null || one === undefined || other === null || other === undefined) { 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; let 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 getOrDefault(obj, fn, defaultValue) { const result = fn(obj); return typeof result === 'undefined' ? defaultValue : result; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const EDITOR_MODEL_DEFAULTS = { tabSize: 4, indentSize: 4, insertSpaces: true, detectIndentation: true, trimAutoWhitespace: true, largeFileOptimizations: true, bracketPairColorizationOptions: { enabled: false } }; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * @internal * The width of the minimap gutter, in pixels. */ const MINIMAP_GUTTER_WIDTH = 8; //#endregion /** * An event describing that the configuration of the editor has changed. */ class ConfigurationChangedEvent { /** * @internal */ constructor(values) { this._values = values; } hasChanged(id) { return this._values[id]; } } /** * @internal */ class ComputeOptionsMemory { constructor() { this.stableMinimapLayoutInput = null; this.stableFitMaxMinimapScale = 0; this.stableFitRemainingWidth = 0; } } /** * @internal */ class BaseEditorOption { constructor(id, name, defaultValue, schema) { this.id = id; this.name = name; this.defaultValue = defaultValue; this.schema = schema; } applyUpdate(value, update) { return applyUpdate(value, update); } compute(env, options, value) { return value; } } class ApplyUpdateResult { constructor(newValue, didChange) { this.newValue = newValue; this.didChange = didChange; } } function applyUpdate(value, update) { if (typeof value !== 'object' || typeof update !== 'object' || !value || !update) { return new ApplyUpdateResult(update, value !== update); } if (Array.isArray(value) || Array.isArray(update)) { const arrayEquals = Array.isArray(value) && Array.isArray(update) && equals$1(value, update); return new ApplyUpdateResult(update, arrayEquals); } let didChange = false; for (const key in update) { if (update.hasOwnProperty(key)) { const result = applyUpdate(value[key], update[key]); if (result.didChange) { value[key] = result.newValue; didChange = true; } } } return new ApplyUpdateResult(value, didChange); } /** * @internal */ class ComputedEditorOption { constructor(id) { this.schema = undefined; this.id = id; this.name = '_never_'; this.defaultValue = undefined; } applyUpdate(value, update) { return applyUpdate(value, update); } validate(input) { return this.defaultValue; } } class SimpleEditorOption { constructor(id, name, defaultValue, schema) { this.id = id; this.name = name; this.defaultValue = defaultValue; this.schema = schema; } applyUpdate(value, update) { return applyUpdate(value, update); } validate(input) { if (typeof input === 'undefined') { return this.defaultValue; } return input; } compute(env, options, value) { return value; } } /** * @internal */ function boolean(value, defaultValue) { if (typeof value === 'undefined') { return defaultValue; } if (value === 'false') { // treat the string 'false' as false return false; } return Boolean(value); } class EditorBooleanOption extends SimpleEditorOption { constructor(id, name, defaultValue, schema = undefined) { if (typeof schema !== 'undefined') { schema.type = 'boolean'; schema.default = defaultValue; } super(id, name, defaultValue, schema); } validate(input) { return boolean(input, this.defaultValue); } } /** * @internal */ function clampedInt(value, defaultValue, minimum, maximum) { if (typeof value === 'undefined') { return defaultValue; } let r = parseInt(value, 10); if (isNaN(r)) { return defaultValue; } r = Math.max(minimum, r); r = Math.min(maximum, r); return r | 0; } class EditorIntOption extends SimpleEditorOption { constructor(id, name, defaultValue, minimum, maximum, schema = undefined) { if (typeof schema !== 'undefined') { schema.type = 'integer'; schema.default = defaultValue; schema.minimum = minimum; schema.maximum = maximum; } super(id, name, defaultValue, schema); this.minimum = minimum; this.maximum = maximum; } static clampedInt(value, defaultValue, minimum, maximum) { return clampedInt(value, defaultValue, minimum, maximum); } validate(input) { return EditorIntOption.clampedInt(input, this.defaultValue, this.minimum, this.maximum); } } class EditorFloatOption extends SimpleEditorOption { constructor(id, name, defaultValue, validationFn, schema) { if (typeof schema !== 'undefined') { schema.type = 'number'; schema.default = defaultValue; } super(id, name, defaultValue, schema); this.validationFn = validationFn; } static clamp(n, min, max) { if (n < min) { return min; } if (n > max) { return max; } return n; } static float(value, defaultValue) { if (typeof value === 'number') { return value; } if (typeof value === 'undefined') { return defaultValue; } const r = parseFloat(value); return (isNaN(r) ? defaultValue : r); } validate(input) { return this.validationFn(EditorFloatOption.float(input, this.defaultValue)); } } class EditorStringOption extends SimpleEditorOption { static string(value, defaultValue) { if (typeof value !== 'string') { return defaultValue; } return value; } constructor(id, name, defaultValue, schema = undefined) { if (typeof schema !== 'undefined') { schema.type = 'string'; schema.default = defaultValue; } super(id, name, defaultValue, schema); } validate(input) { return EditorStringOption.string(input, this.defaultValue); } } /** * @internal */ function stringSet(value, defaultValue, allowedValues) { if (typeof value !== 'string') { return defaultValue; } if (allowedValues.indexOf(value) === -1) { return defaultValue; } return value; } class EditorStringEnumOption extends SimpleEditorOption { constructor(id, name, defaultValue, allowedValues, schema = undefined) { if (typeof schema !== 'undefined') { schema.type = 'string'; schema.enum = allowedValues; schema.default = defaultValue; } super(id, name, defaultValue, schema); this._allowedValues = allowedValues; } validate(input) { return stringSet(input, this.defaultValue, this._allowedValues); } } class EditorEnumOption extends BaseEditorOption { constructor(id, name, defaultValue, defaultStringValue, allowedValues, convert, schema = undefined) { if (typeof schema !== 'undefined') { schema.type = 'string'; schema.enum = allowedValues; schema.default = defaultStringValue; } super(id, name, defaultValue, schema); this._allowedValues = allowedValues; this._convert = convert; } validate(input) { if (typeof input !== 'string') { return this.defaultValue; } if (this._allowedValues.indexOf(input) === -1) { return this.defaultValue; } return this._convert(input); } } //#endregion //#region autoIndent function _autoIndentFromString(autoIndent) { switch (autoIndent) { case 'none': return 0 /* None */; case 'keep': return 1 /* Keep */; case 'brackets': return 2 /* Brackets */; case 'advanced': return 3 /* Advanced */; case 'full': return 4 /* Full */; } } //#endregion //#region accessibilitySupport class EditorAccessibilitySupport extends BaseEditorOption { constructor() { super(2 /* accessibilitySupport */, 'accessibilitySupport', 0 /* Unknown */, { type: 'string', enum: ['auto', 'on', 'off'], enumDescriptions: [ localize('accessibilitySupport.auto', "The editor will use platform APIs to detect when a Screen Reader is attached."), localize('accessibilitySupport.on', "The editor will be permanently optimized for usage with a Screen Reader. Word wrapping will be disabled."), localize('accessibilitySupport.off', "The editor will never be optimized for usage with a Screen Reader."), ], default: 'auto', description: localize('accessibilitySupport', "Controls whether the editor should run in a mode where it is optimized for screen readers. Setting to on will disable word wrapping.") }); } validate(input) { switch (input) { case 'auto': return 0 /* Unknown */; case 'off': return 1 /* Disabled */; case 'on': return 2 /* Enabled */; } return this.defaultValue; } compute(env, options, value) { if (value === 0 /* Unknown */) { // The editor reads the `accessibilitySupport` from the environment return env.accessibilitySupport; } return value; } } class EditorComments extends BaseEditorOption { constructor() { const defaults = { insertSpace: true, ignoreEmptyLines: true, }; super(19 /* comments */, 'comments', defaults, { 'editor.comments.insertSpace': { type: 'boolean', default: defaults.insertSpace, description: localize('comments.insertSpace', "Controls whether a space character is inserted when commenting.") }, 'editor.comments.ignoreEmptyLines': { type: 'boolean', default: defaults.ignoreEmptyLines, description: localize('comments.ignoreEmptyLines', 'Controls if empty lines should be ignored with toggle, add or remove actions for line comments.') }, }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { insertSpace: boolean(input.insertSpace, this.defaultValue.insertSpace), ignoreEmptyLines: boolean(input.ignoreEmptyLines, this.defaultValue.ignoreEmptyLines), }; } } function _cursorBlinkingStyleFromString(cursorBlinkingStyle) { switch (cursorBlinkingStyle) { case 'blink': return 1 /* Blink */; case 'smooth': return 2 /* Smooth */; case 'phase': return 3 /* Phase */; case 'expand': return 4 /* Expand */; case 'solid': return 5 /* Solid */; } } //#endregion //#region cursorStyle /** * The style in which the editor's cursor should be rendered. */ var TextEditorCursorStyle$1; (function (TextEditorCursorStyle) { /** * As a vertical line (sitting between two characters). */ TextEditorCursorStyle[TextEditorCursorStyle["Line"] = 1] = "Line"; /** * As a block (sitting on top of a character). */ TextEditorCursorStyle[TextEditorCursorStyle["Block"] = 2] = "Block"; /** * As a horizontal line (sitting under a character). */ TextEditorCursorStyle[TextEditorCursorStyle["Underline"] = 3] = "Underline"; /** * As a thin vertical line (sitting between two characters). */ TextEditorCursorStyle[TextEditorCursorStyle["LineThin"] = 4] = "LineThin"; /** * As an outlined block (sitting on top of a character). */ TextEditorCursorStyle[TextEditorCursorStyle["BlockOutline"] = 5] = "BlockOutline"; /** * As a thin horizontal line (sitting under a character). */ TextEditorCursorStyle[TextEditorCursorStyle["UnderlineThin"] = 6] = "UnderlineThin"; })(TextEditorCursorStyle$1 || (TextEditorCursorStyle$1 = {})); function _cursorStyleFromString(cursorStyle) { switch (cursorStyle) { case 'line': return TextEditorCursorStyle$1.Line; case 'block': return TextEditorCursorStyle$1.Block; case 'underline': return TextEditorCursorStyle$1.Underline; case 'line-thin': return TextEditorCursorStyle$1.LineThin; case 'block-outline': return TextEditorCursorStyle$1.BlockOutline; case 'underline-thin': return TextEditorCursorStyle$1.UnderlineThin; } } //#endregion //#region editorClassName class EditorClassName extends ComputedEditorOption { constructor() { super(128 /* editorClassName */); } compute(env, options, _) { const classNames = ['monaco-editor']; if (options.get(33 /* extraEditorClassName */)) { classNames.push(options.get(33 /* extraEditorClassName */)); } if (env.extraEditorClassName) { classNames.push(env.extraEditorClassName); } if (options.get(66 /* mouseStyle */) === 'default') { classNames.push('mouse-default'); } else if (options.get(66 /* mouseStyle */) === 'copy') { classNames.push('mouse-copy'); } if (options.get(100 /* showUnused */)) { classNames.push('showUnused'); } if (options.get(126 /* showDeprecated */)) { classNames.push('showDeprecated'); } return classNames.join(' '); } } //#endregion //#region emptySelectionClipboard class EditorEmptySelectionClipboard extends EditorBooleanOption { constructor() { super(32 /* emptySelectionClipboard */, 'emptySelectionClipboard', true, { description: localize('emptySelectionClipboard', "Controls whether copying without a selection copies the current line.") }); } compute(env, options, value) { return value && env.emptySelectionClipboard; } } class EditorFind extends BaseEditorOption { constructor() { const defaults = { cursorMoveOnType: true, seedSearchStringFromSelection: 'always', autoFindInSelection: 'never', globalFindClipboard: false, addExtraSpaceOnTop: true, loop: true }; super(35 /* find */, 'find', defaults, { 'editor.find.cursorMoveOnType': { type: 'boolean', default: defaults.cursorMoveOnType, description: localize('find.cursorMoveOnType', "Controls whether the cursor should jump to find matches while typing.") }, 'editor.find.seedSearchStringFromSelection': { type: 'string', enum: ['never', 'always', 'selection'], default: defaults.seedSearchStringFromSelection, enumDescriptions: [ localize('editor.find.seedSearchStringFromSelection.never', 'Never seed search string from the editor selection.'), localize('editor.find.seedSearchStringFromSelection.always', 'Always seed search string from the editor selection, including word at cursor position.'), localize('editor.find.seedSearchStringFromSelection.selection', 'Only seed search string from the editor selection.') ], description: localize('find.seedSearchStringFromSelection', "Controls whether the search string in the Find Widget is seeded from the editor selection.") }, 'editor.find.autoFindInSelection': { type: 'string', enum: ['never', 'always', 'multiline'], default: defaults.autoFindInSelection, enumDescriptions: [ localize('editor.find.autoFindInSelection.never', 'Never turn on Find in Selection automatically (default).'), localize('editor.find.autoFindInSelection.always', 'Always turn on Find in Selection automatically.'), localize('editor.find.autoFindInSelection.multiline', 'Turn on Find in Selection automatically when multiple lines of content are selected.') ], description: localize('find.autoFindInSelection', "Controls the condition for turning on Find in Selection automatically.") }, 'editor.find.globalFindClipboard': { type: 'boolean', default: defaults.globalFindClipboard, description: localize('find.globalFindClipboard', "Controls whether the Find Widget should read or modify the shared find clipboard on macOS."), included: isMacintosh }, 'editor.find.addExtraSpaceOnTop': { type: 'boolean', default: defaults.addExtraSpaceOnTop, description: localize('find.addExtraSpaceOnTop', "Controls whether the Find Widget should add extra lines on top of the editor. When true, you can scroll beyond the first line when the Find Widget is visible.") }, 'editor.find.loop': { type: 'boolean', default: defaults.loop, description: localize('find.loop', "Controls whether the search automatically restarts from the beginning (or the end) when no further matches can be found.") }, }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { cursorMoveOnType: boolean(input.cursorMoveOnType, this.defaultValue.cursorMoveOnType), seedSearchStringFromSelection: typeof _input.seedSearchStringFromSelection === 'boolean' ? (_input.seedSearchStringFromSelection ? 'always' : 'never') : stringSet(input.seedSearchStringFromSelection, this.defaultValue.seedSearchStringFromSelection, ['never', 'always', 'selection']), autoFindInSelection: typeof _input.autoFindInSelection === 'boolean' ? (_input.autoFindInSelection ? 'always' : 'never') : stringSet(input.autoFindInSelection, this.defaultValue.autoFindInSelection, ['never', 'always', 'multiline']), globalFindClipboard: boolean(input.globalFindClipboard, this.defaultValue.globalFindClipboard), addExtraSpaceOnTop: boolean(input.addExtraSpaceOnTop, this.defaultValue.addExtraSpaceOnTop), loop: boolean(input.loop, this.defaultValue.loop), }; } } //#endregion //#region fontLigatures /** * @internal */ class EditorFontLigatures extends BaseEditorOption { constructor() { super(45 /* fontLigatures */, 'fontLigatures', EditorFontLigatures.OFF, { anyOf: [ { type: 'boolean', description: localize('fontLigatures', "Enables/Disables font ligatures ('calt' and 'liga' font features). Change this to a string for fine-grained control of the 'font-feature-settings' CSS property."), }, { type: 'string', description: localize('fontFeatureSettings', "Explicit 'font-feature-settings' CSS property. A boolean can be passed instead if one only needs to turn on/off ligatures.") } ], description: localize('fontLigaturesGeneral', "Configures font ligatures or font features. Can be either a boolean to enable/disable ligatures or a string for the value of the CSS 'font-feature-settings' property."), default: false }); } validate(input) { if (typeof input === 'undefined') { return this.defaultValue; } if (typeof input === 'string') { if (input === 'false') { return EditorFontLigatures.OFF; } if (input === 'true') { return EditorFontLigatures.ON; } return input; } if (Boolean(input)) { return EditorFontLigatures.ON; } return EditorFontLigatures.OFF; } } EditorFontLigatures.OFF = '"liga" off, "calt" off'; EditorFontLigatures.ON = '"liga" on, "calt" on'; //#endregion //#region fontInfo class EditorFontInfo extends ComputedEditorOption { constructor() { super(44 /* fontInfo */); } compute(env, options, _) { return env.fontInfo; } } //#endregion //#region fontSize class EditorFontSize extends SimpleEditorOption { constructor() { super(46 /* fontSize */, 'fontSize', EDITOR_FONT_DEFAULTS.fontSize, { type: 'number', minimum: 6, maximum: 100, default: EDITOR_FONT_DEFAULTS.fontSize, description: localize('fontSize', "Controls the font size in pixels.") }); } validate(input) { const r = EditorFloatOption.float(input, this.defaultValue); if (r === 0) { return EDITOR_FONT_DEFAULTS.fontSize; } return EditorFloatOption.clamp(r, 6, 100); } compute(env, options, value) { // The final fontSize respects the editor zoom level. // So take the result from env.fontInfo return env.fontInfo.fontSize; } } //#endregion //#region fontWeight class EditorFontWeight extends BaseEditorOption { constructor() { super(47 /* fontWeight */, 'fontWeight', EDITOR_FONT_DEFAULTS.fontWeight, { anyOf: [ { type: 'number', minimum: EditorFontWeight.MINIMUM_VALUE, maximum: EditorFontWeight.MAXIMUM_VALUE, errorMessage: localize('fontWeightErrorMessage', "Only \"normal\" and \"bold\" keywords or numbers between 1 and 1000 are allowed.") }, { type: 'string', pattern: '^(normal|bold|1000|[1-9][0-9]{0,2})$' }, { enum: EditorFontWeight.SUGGESTION_VALUES } ], default: EDITOR_FONT_DEFAULTS.fontWeight, description: localize('fontWeight', "Controls the font weight. Accepts \"normal\" and \"bold\" keywords or numbers between 1 and 1000.") }); } validate(input) { if (input === 'normal' || input === 'bold') { return input; } return String(EditorIntOption.clampedInt(input, EDITOR_FONT_DEFAULTS.fontWeight, EditorFontWeight.MINIMUM_VALUE, EditorFontWeight.MAXIMUM_VALUE)); } } EditorFontWeight.SUGGESTION_VALUES = ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900']; EditorFontWeight.MINIMUM_VALUE = 1; EditorFontWeight.MAXIMUM_VALUE = 1000; class EditorGoToLocation extends BaseEditorOption { constructor() { const defaults = { multiple: 'peek', multipleDefinitions: 'peek', multipleTypeDefinitions: 'peek', multipleDeclarations: 'peek', multipleImplementations: 'peek', multipleReferences: 'peek', alternativeDefinitionCommand: 'editor.action.goToReferences', alternativeTypeDefinitionCommand: 'editor.action.goToReferences', alternativeDeclarationCommand: 'editor.action.goToReferences', alternativeImplementationCommand: '', alternativeReferenceCommand: '', }; const jsonSubset = { type: 'string', enum: ['peek', 'gotoAndPeek', 'goto'], default: defaults.multiple, enumDescriptions: [ localize('editor.gotoLocation.multiple.peek', 'Show peek view of the results (default)'), localize('editor.gotoLocation.multiple.gotoAndPeek', 'Go to the primary result and show a peek view'), localize('editor.gotoLocation.multiple.goto', 'Go to the primary result and enable peek-less navigation to others') ] }; const alternativeCommandOptions = ['', 'editor.action.referenceSearch.trigger', 'editor.action.goToReferences', 'editor.action.peekImplementation', 'editor.action.goToImplementation', 'editor.action.peekTypeDefinition', 'editor.action.goToTypeDefinition', 'editor.action.peekDeclaration', 'editor.action.revealDeclaration', 'editor.action.peekDefinition', 'editor.action.revealDefinitionAside', 'editor.action.revealDefinition']; super(51 /* gotoLocation */, 'gotoLocation', defaults, { 'editor.gotoLocation.multiple': { deprecationMessage: localize('editor.gotoLocation.multiple.deprecated', "This setting is deprecated, please use separate settings like 'editor.editor.gotoLocation.multipleDefinitions' or 'editor.editor.gotoLocation.multipleImplementations' instead."), }, 'editor.gotoLocation.multipleDefinitions': Object.assign({ description: localize('editor.editor.gotoLocation.multipleDefinitions', "Controls the behavior the 'Go to Definition'-command when multiple target locations exist.") }, jsonSubset), 'editor.gotoLocation.multipleTypeDefinitions': Object.assign({ description: localize('editor.editor.gotoLocation.multipleTypeDefinitions', "Controls the behavior the 'Go to Type Definition'-command when multiple target locations exist.") }, jsonSubset), 'editor.gotoLocation.multipleDeclarations': Object.assign({ description: localize('editor.editor.gotoLocation.multipleDeclarations', "Controls the behavior the 'Go to Declaration'-command when multiple target locations exist.") }, jsonSubset), 'editor.gotoLocation.multipleImplementations': Object.assign({ description: localize('editor.editor.gotoLocation.multipleImplemenattions', "Controls the behavior the 'Go to Implementations'-command when multiple target locations exist.") }, jsonSubset), 'editor.gotoLocation.multipleReferences': Object.assign({ description: localize('editor.editor.gotoLocation.multipleReferences', "Controls the behavior the 'Go to References'-command when multiple target locations exist.") }, jsonSubset), 'editor.gotoLocation.alternativeDefinitionCommand': { type: 'string', default: defaults.alternativeDefinitionCommand, enum: alternativeCommandOptions, description: localize('alternativeDefinitionCommand', "Alternative command id that is being executed when the result of 'Go to Definition' is the current location.") }, 'editor.gotoLocation.alternativeTypeDefinitionCommand': { type: 'string', default: defaults.alternativeTypeDefinitionCommand, enum: alternativeCommandOptions, description: localize('alternativeTypeDefinitionCommand', "Alternative command id that is being executed when the result of 'Go to Type Definition' is the current location.") }, 'editor.gotoLocation.alternativeDeclarationCommand': { type: 'string', default: defaults.alternativeDeclarationCommand, enum: alternativeCommandOptions, description: localize('alternativeDeclarationCommand', "Alternative command id that is being executed when the result of 'Go to Declaration' is the current location.") }, 'editor.gotoLocation.alternativeImplementationCommand': { type: 'string', default: defaults.alternativeImplementationCommand, enum: alternativeCommandOptions, description: localize('alternativeImplementationCommand', "Alternative command id that is being executed when the result of 'Go to Implementation' is the current location.") }, 'editor.gotoLocation.alternativeReferenceCommand': { type: 'string', default: defaults.alternativeReferenceCommand, enum: alternativeCommandOptions, description: localize('alternativeReferenceCommand', "Alternative command id that is being executed when the result of 'Go to Reference' is the current location.") }, }); } validate(_input) { var _a, _b, _c, _d, _e; if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { multiple: stringSet(input.multiple, this.defaultValue.multiple, ['peek', 'gotoAndPeek', 'goto']), multipleDefinitions: (_a = input.multipleDefinitions) !== null && _a !== void 0 ? _a : stringSet(input.multipleDefinitions, 'peek', ['peek', 'gotoAndPeek', 'goto']), multipleTypeDefinitions: (_b = input.multipleTypeDefinitions) !== null && _b !== void 0 ? _b : stringSet(input.multipleTypeDefinitions, 'peek', ['peek', 'gotoAndPeek', 'goto']), multipleDeclarations: (_c = input.multipleDeclarations) !== null && _c !== void 0 ? _c : stringSet(input.multipleDeclarations, 'peek', ['peek', 'gotoAndPeek', 'goto']), multipleImplementations: (_d = input.multipleImplementations) !== null && _d !== void 0 ? _d : stringSet(input.multipleImplementations, 'peek', ['peek', 'gotoAndPeek', 'goto']), multipleReferences: (_e = input.multipleReferences) !== null && _e !== void 0 ? _e : stringSet(input.multipleReferences, 'peek', ['peek', 'gotoAndPeek', 'goto']), alternativeDefinitionCommand: EditorStringOption.string(input.alternativeDefinitionCommand, this.defaultValue.alternativeDefinitionCommand), alternativeTypeDefinitionCommand: EditorStringOption.string(input.alternativeTypeDefinitionCommand, this.defaultValue.alternativeTypeDefinitionCommand), alternativeDeclarationCommand: EditorStringOption.string(input.alternativeDeclarationCommand, this.defaultValue.alternativeDeclarationCommand), alternativeImplementationCommand: EditorStringOption.string(input.alternativeImplementationCommand, this.defaultValue.alternativeImplementationCommand), alternativeReferenceCommand: EditorStringOption.string(input.alternativeReferenceCommand, this.defaultValue.alternativeReferenceCommand), }; } } class EditorHover extends BaseEditorOption { constructor() { const defaults = { enabled: true, delay: 300, sticky: true, above: true, }; super(53 /* hover */, 'hover', defaults, { 'editor.hover.enabled': { type: 'boolean', default: defaults.enabled, description: localize('hover.enabled', "Controls whether the hover is shown.") }, 'editor.hover.delay': { type: 'number', default: defaults.delay, minimum: 0, maximum: 10000, description: localize('hover.delay', "Controls the delay in milliseconds after which the hover is shown.") }, 'editor.hover.sticky': { type: 'boolean', default: defaults.sticky, description: localize('hover.sticky', "Controls whether the hover should remain visible when mouse is moved over it.") }, 'editor.hover.above': { type: 'boolean', default: defaults.above, description: localize('hover.above', "Prefer showing hovers above the line, if there's space.") }, }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { enabled: boolean(input.enabled, this.defaultValue.enabled), delay: EditorIntOption.clampedInt(input.delay, this.defaultValue.delay, 0, 10000), sticky: boolean(input.sticky, this.defaultValue.sticky), above: boolean(input.above, this.defaultValue.above), }; } } /** * @internal */ class EditorLayoutInfoComputer extends ComputedEditorOption { constructor() { super(131 /* layoutInfo */); } compute(env, options, _) { return EditorLayoutInfoComputer.computeLayout(options, { memory: env.memory, outerWidth: env.outerWidth, outerHeight: env.outerHeight, isDominatedByLongLines: env.isDominatedByLongLines, lineHeight: env.fontInfo.lineHeight, viewLineCount: env.viewLineCount, lineNumbersDigitCount: env.lineNumbersDigitCount, typicalHalfwidthCharacterWidth: env.fontInfo.typicalHalfwidthCharacterWidth, maxDigitWidth: env.fontInfo.maxDigitWidth, pixelRatio: env.pixelRatio }); } static computeContainedMinimapLineCount(input) { const typicalViewportLineCount = input.height / input.lineHeight; const extraLinesBeyondLastLine = input.scrollBeyondLastLine ? (typicalViewportLineCount - 1) : 0; const desiredRatio = (input.viewLineCount + extraLinesBeyondLastLine) / (input.pixelRatio * input.height); const minimapLineCount = Math.floor(input.viewLineCount / desiredRatio); return { typicalViewportLineCount, extraLinesBeyondLastLine, desiredRatio, minimapLineCount }; } static _computeMinimapLayout(input, memory) { const outerWidth = input.outerWidth; const outerHeight = input.outerHeight; const pixelRatio = input.pixelRatio; if (!input.minimap.enabled) { return { renderMinimap: 0 /* None */, minimapLeft: 0, minimapWidth: 0, minimapHeightIsEditorHeight: false, minimapIsSampling: false, minimapScale: 1, minimapLineHeight: 1, minimapCanvasInnerWidth: 0, minimapCanvasInnerHeight: Math.floor(pixelRatio * outerHeight), minimapCanvasOuterWidth: 0, minimapCanvasOuterHeight: outerHeight, }; } // Can use memory if only the `viewLineCount` and `remainingWidth` have changed const stableMinimapLayoutInput = memory.stableMinimapLayoutInput; const couldUseMemory = (stableMinimapLayoutInput // && input.outerWidth === lastMinimapLayoutInput.outerWidth !!! INTENTIONAL OMITTED && input.outerHeight === stableMinimapLayoutInput.outerHeight && input.lineHeight === stableMinimapLayoutInput.lineHeight && input.typicalHalfwidthCharacterWidth === stableMinimapLayoutInput.typicalHalfwidthCharacterWidth && input.pixelRatio === stableMinimapLayoutInput.pixelRatio && input.scrollBeyondLastLine === stableMinimapLayoutInput.scrollBeyondLastLine && input.minimap.enabled === stableMinimapLayoutInput.minimap.enabled && input.minimap.side === stableMinimapLayoutInput.minimap.side && input.minimap.size === stableMinimapLayoutInput.minimap.size && input.minimap.showSlider === stableMinimapLayoutInput.minimap.showSlider && input.minimap.renderCharacters === stableMinimapLayoutInput.minimap.renderCharacters && input.minimap.maxColumn === stableMinimapLayoutInput.minimap.maxColumn && input.minimap.scale === stableMinimapLayoutInput.minimap.scale && input.verticalScrollbarWidth === stableMinimapLayoutInput.verticalScrollbarWidth // && input.viewLineCount === lastMinimapLayoutInput.viewLineCount !!! INTENTIONAL OMITTED // && input.remainingWidth === lastMinimapLayoutInput.remainingWidth !!! INTENTIONAL OMITTED && input.isViewportWrapping === stableMinimapLayoutInput.isViewportWrapping); const lineHeight = input.lineHeight; const typicalHalfwidthCharacterWidth = input.typicalHalfwidthCharacterWidth; const scrollBeyondLastLine = input.scrollBeyondLastLine; const minimapRenderCharacters = input.minimap.renderCharacters; let minimapScale = (pixelRatio >= 2 ? Math.round(input.minimap.scale * 2) : input.minimap.scale); const minimapMaxColumn = input.minimap.maxColumn; const minimapSize = input.minimap.size; const minimapSide = input.minimap.side; const verticalScrollbarWidth = input.verticalScrollbarWidth; const viewLineCount = input.viewLineCount; const remainingWidth = input.remainingWidth; const isViewportWrapping = input.isViewportWrapping; const baseCharHeight = minimapRenderCharacters ? 2 : 3; let minimapCanvasInnerHeight = Math.floor(pixelRatio * outerHeight); const minimapCanvasOuterHeight = minimapCanvasInnerHeight / pixelRatio; let minimapHeightIsEditorHeight = false; let minimapIsSampling = false; let minimapLineHeight = baseCharHeight * minimapScale; let minimapCharWidth = minimapScale / pixelRatio; let minimapWidthMultiplier = 1; if (minimapSize === 'fill' || minimapSize === 'fit') { const { typicalViewportLineCount, extraLinesBeyondLastLine, desiredRatio, minimapLineCount } = EditorLayoutInfoComputer.computeContainedMinimapLineCount({ viewLineCount: viewLineCount, scrollBeyondLastLine: scrollBeyondLastLine, height: outerHeight, lineHeight: lineHeight, pixelRatio: pixelRatio }); // ratio is intentionally not part of the layout to avoid the layout changing all the time // when doing sampling const ratio = viewLineCount / minimapLineCount; if (ratio > 1) { minimapHeightIsEditorHeight = true; minimapIsSampling = true; minimapScale = 1; minimapLineHeight = 1; minimapCharWidth = minimapScale / pixelRatio; } else { let fitBecomesFill = false; let maxMinimapScale = minimapScale + 1; if (minimapSize === 'fit') { const effectiveMinimapHeight = Math.ceil((viewLineCount + extraLinesBeyondLastLine) * minimapLineHeight); if (isViewportWrapping && couldUseMemory && remainingWidth <= memory.stableFitRemainingWidth) { // There is a loop when using `fit` and viewport wrapping: // - view line count impacts minimap layout // - minimap layout impacts viewport width // - viewport width impacts view line count // To break the loop, once we go to a smaller minimap scale, we try to stick with it. fitBecomesFill = true; maxMinimapScale = memory.stableFitMaxMinimapScale; } else { fitBecomesFill = (effectiveMinimapHeight > minimapCanvasInnerHeight); } } if (minimapSize === 'fill' || fitBecomesFill) { minimapHeightIsEditorHeight = true; const configuredMinimapScale = minimapScale; minimapLineHeight = Math.min(lineHeight * pixelRatio, Math.max(1, Math.floor(1 / desiredRatio))); if (isViewportWrapping && couldUseMemory && remainingWidth <= memory.stableFitRemainingWidth) { // There is a loop when using `fill` and viewport wrapping: // - view line count impacts minimap layout // - minimap layout impacts viewport width // - viewport width impacts view line count // To break the loop, once we go to a smaller minimap scale, we try to stick with it. maxMinimapScale = memory.stableFitMaxMinimapScale; } minimapScale = Math.min(maxMinimapScale, Math.max(1, Math.floor(minimapLineHeight / baseCharHeight))); if (minimapScale > configuredMinimapScale) { minimapWidthMultiplier = Math.min(2, minimapScale / configuredMinimapScale); } minimapCharWidth = minimapScale / pixelRatio / minimapWidthMultiplier; minimapCanvasInnerHeight = Math.ceil((Math.max(typicalViewportLineCount, viewLineCount + extraLinesBeyondLastLine)) * minimapLineHeight); if (isViewportWrapping) { // remember for next time memory.stableMinimapLayoutInput = input; memory.stableFitRemainingWidth = remainingWidth; memory.stableFitMaxMinimapScale = minimapScale; } else { memory.stableMinimapLayoutInput = null; memory.stableFitRemainingWidth = 0; } } } } // Given: // (leaving 2px for the cursor to have space after the last character) // viewportColumn = (contentWidth - verticalScrollbarWidth - 2) / typicalHalfwidthCharacterWidth // minimapWidth = viewportColumn * minimapCharWidth // contentWidth = remainingWidth - minimapWidth // What are good values for contentWidth and minimapWidth ? // minimapWidth = ((contentWidth - verticalScrollbarWidth - 2) / typicalHalfwidthCharacterWidth) * minimapCharWidth // typicalHalfwidthCharacterWidth * minimapWidth = (contentWidth - verticalScrollbarWidth - 2) * minimapCharWidth // typicalHalfwidthCharacterWidth * minimapWidth = (remainingWidth - minimapWidth - verticalScrollbarWidth - 2) * minimapCharWidth // (typicalHalfwidthCharacterWidth + minimapCharWidth) * minimapWidth = (remainingWidth - verticalScrollbarWidth - 2) * minimapCharWidth // minimapWidth = ((remainingWidth - verticalScrollbarWidth - 2) * minimapCharWidth) / (typicalHalfwidthCharacterWidth + minimapCharWidth) const minimapMaxWidth = Math.floor(minimapMaxColumn * minimapCharWidth); const minimapWidth = Math.min(minimapMaxWidth, Math.max(0, Math.floor(((remainingWidth - verticalScrollbarWidth - 2) * minimapCharWidth) / (typicalHalfwidthCharacterWidth + minimapCharWidth))) + MINIMAP_GUTTER_WIDTH); let minimapCanvasInnerWidth = Math.floor(pixelRatio * minimapWidth); const minimapCanvasOuterWidth = minimapCanvasInnerWidth / pixelRatio; minimapCanvasInnerWidth = Math.floor(minimapCanvasInnerWidth * minimapWidthMultiplier); const renderMinimap = (minimapRenderCharacters ? 1 /* Text */ : 2 /* Blocks */); const minimapLeft = (minimapSide === 'left' ? 0 : (outerWidth - minimapWidth - verticalScrollbarWidth)); return { renderMinimap, minimapLeft, minimapWidth, minimapHeightIsEditorHeight, minimapIsSampling, minimapScale, minimapLineHeight, minimapCanvasInnerWidth, minimapCanvasInnerHeight, minimapCanvasOuterWidth, minimapCanvasOuterHeight, }; } static computeLayout(options, env) { const outerWidth = env.outerWidth | 0; const outerHeight = env.outerHeight | 0; const lineHeight = env.lineHeight | 0; const lineNumbersDigitCount = env.lineNumbersDigitCount | 0; const typicalHalfwidthCharacterWidth = env.typicalHalfwidthCharacterWidth; const maxDigitWidth = env.maxDigitWidth; const pixelRatio = env.pixelRatio; const viewLineCount = env.viewLineCount; const wordWrapOverride2 = options.get(123 /* wordWrapOverride2 */); const wordWrapOverride1 = (wordWrapOverride2 === 'inherit' ? options.get(122 /* wordWrapOverride1 */) : wordWrapOverride2); const wordWrap = (wordWrapOverride1 === 'inherit' ? options.get(118 /* wordWrap */) : wordWrapOverride1); const wordWrapColumn = options.get(121 /* wordWrapColumn */); const accessibilitySupport = options.get(2 /* accessibilitySupport */); const isDominatedByLongLines = env.isDominatedByLongLines; const showGlyphMargin = options.get(50 /* glyphMargin */); const showLineNumbers = (options.get(60 /* lineNumbers */).renderType !== 0 /* Off */); const lineNumbersMinChars = options.get(61 /* lineNumbersMinChars */); const scrollBeyondLastLine = options.get(94 /* scrollBeyondLastLine */); const minimap = options.get(65 /* minimap */); const scrollbar = options.get(92 /* scrollbar */); const verticalScrollbarWidth = scrollbar.verticalScrollbarSize; const verticalScrollbarHasArrows = scrollbar.verticalHasArrows; const scrollbarArrowSize = scrollbar.arrowSize; const horizontalScrollbarHeight = scrollbar.horizontalScrollbarSize; const rawLineDecorationsWidth = options.get(58 /* lineDecorationsWidth */); const folding = options.get(37 /* folding */); let lineDecorationsWidth; if (typeof rawLineDecorationsWidth === 'string' && /^\d+(\.\d+)?ch$/.test(rawLineDecorationsWidth)) { const multiple = parseFloat(rawLineDecorationsWidth.substr(0, rawLineDecorationsWidth.length - 2)); lineDecorationsWidth = EditorIntOption.clampedInt(multiple * typicalHalfwidthCharacterWidth, 0, 0, 1000); } else { lineDecorationsWidth = EditorIntOption.clampedInt(rawLineDecorationsWidth, 0, 0, 1000); } if (folding) { lineDecorationsWidth += 16; } let lineNumbersWidth = 0; if (showLineNumbers) { const digitCount = Math.max(lineNumbersDigitCount, lineNumbersMinChars); lineNumbersWidth = Math.round(digitCount * maxDigitWidth); } let glyphMarginWidth = 0; if (showGlyphMargin) { glyphMarginWidth = lineHeight; } let glyphMarginLeft = 0; let lineNumbersLeft = glyphMarginLeft + glyphMarginWidth; let decorationsLeft = lineNumbersLeft + lineNumbersWidth; let contentLeft = decorationsLeft + lineDecorationsWidth; const remainingWidth = outerWidth - glyphMarginWidth - lineNumbersWidth - lineDecorationsWidth; let isWordWrapMinified = false; let isViewportWrapping = false; let wrappingColumn = -1; if (accessibilitySupport !== 2 /* Enabled */) { // See https://github.com/microsoft/vscode/issues/27766 // Never enable wrapping when a screen reader is attached // because arrow down etc. will not move the cursor in the way // a screen reader expects. if (wordWrapOverride1 === 'inherit' && isDominatedByLongLines) { // Force viewport width wrapping if model is dominated by long lines isWordWrapMinified = true; isViewportWrapping = true; } else if (wordWrap === 'on' || wordWrap === 'bounded') { isViewportWrapping = true; } else if (wordWrap === 'wordWrapColumn') { wrappingColumn = wordWrapColumn; } } const minimapLayout = EditorLayoutInfoComputer._computeMinimapLayout({ outerWidth: outerWidth, outerHeight: outerHeight, lineHeight: lineHeight, typicalHalfwidthCharacterWidth: typicalHalfwidthCharacterWidth, pixelRatio: pixelRatio, scrollBeyondLastLine: scrollBeyondLastLine, minimap: minimap, verticalScrollbarWidth: verticalScrollbarWidth, viewLineCount: viewLineCount, remainingWidth: remainingWidth, isViewportWrapping: isViewportWrapping, }, env.memory || new ComputeOptionsMemory()); if (minimapLayout.renderMinimap !== 0 /* None */ && minimapLayout.minimapLeft === 0) { // the minimap is rendered to the left, so move everything to the right glyphMarginLeft += minimapLayout.minimapWidth; lineNumbersLeft += minimapLayout.minimapWidth; decorationsLeft += minimapLayout.minimapWidth; contentLeft += minimapLayout.minimapWidth; } const contentWidth = remainingWidth - minimapLayout.minimapWidth; // (leaving 2px for the cursor to have space after the last character) const viewportColumn = Math.max(1, Math.floor((contentWidth - verticalScrollbarWidth - 2) / typicalHalfwidthCharacterWidth)); const verticalArrowSize = (verticalScrollbarHasArrows ? scrollbarArrowSize : 0); if (isViewportWrapping) { // compute the actual wrappingColumn wrappingColumn = Math.max(1, viewportColumn); if (wordWrap === 'bounded') { wrappingColumn = Math.min(wrappingColumn, wordWrapColumn); } } return { width: outerWidth, height: outerHeight, glyphMarginLeft: glyphMarginLeft, glyphMarginWidth: glyphMarginWidth, lineNumbersLeft: lineNumbersLeft, lineNumbersWidth: lineNumbersWidth, decorationsLeft: decorationsLeft, decorationsWidth: lineDecorationsWidth, contentLeft: contentLeft, contentWidth: contentWidth, minimap: minimapLayout, viewportColumn: viewportColumn, isWordWrapMinified: isWordWrapMinified, isViewportWrapping: isViewportWrapping, wrappingColumn: wrappingColumn, verticalScrollbarWidth: verticalScrollbarWidth, horizontalScrollbarHeight: horizontalScrollbarHeight, overviewRuler: { top: verticalArrowSize, width: verticalScrollbarWidth, height: (outerHeight - 2 * verticalArrowSize), right: 0 } }; } } class EditorLightbulb extends BaseEditorOption { constructor() { const defaults = { enabled: true }; super(57 /* lightbulb */, 'lightbulb', defaults, { 'editor.lightbulb.enabled': { type: 'boolean', default: defaults.enabled, description: localize('codeActions', "Enables the code action lightbulb in the editor.") }, }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { enabled: boolean(input.enabled, this.defaultValue.enabled) }; } } class EditorInlayHints extends BaseEditorOption { constructor() { const defaults = { enabled: true, fontSize: 0, fontFamily: '' }; super(127 /* inlayHints */, 'inlayHints', defaults, { 'editor.inlayHints.enabled': { type: 'boolean', default: defaults.enabled, description: localize('inlayHints.enable', "Enables the inlay hints in the editor.") }, 'editor.inlayHints.fontSize': { type: 'number', default: defaults.fontSize, markdownDescription: localize('inlayHints.fontSize', "Controls font size of inlay hints in the editor. A default of 90% of `#editor.fontSize#` is used when the configured value is less than `5` or greater than the editor font size.") }, 'editor.inlayHints.fontFamily': { type: 'string', default: defaults.fontFamily, markdownDescription: localize('inlayHints.fontFamily', "Controls font family of inlay hints in the editor. When set to empty, the `#editor.fontFamily#` is used.") }, }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { enabled: boolean(input.enabled, this.defaultValue.enabled), fontSize: EditorIntOption.clampedInt(input.fontSize, this.defaultValue.fontSize, 0, 100), fontFamily: EditorStringOption.string(input.fontFamily, this.defaultValue.fontFamily) }; } } //#endregion //#region lineHeight class EditorLineHeight extends EditorFloatOption { constructor() { super(59 /* lineHeight */, 'lineHeight', EDITOR_FONT_DEFAULTS.lineHeight, x => EditorFloatOption.clamp(x, 0, 150), { markdownDescription: localize('lineHeight', "Controls the line height. \n - Use 0 to automatically compute the line height from the font size.\n - Values between 0 and 8 will be used as a multiplier with the font size.\n - Values greater than or equal to 8 will be used as effective values.") }); } compute(env, options, value) { // The lineHeight is computed from the fontSize if it is 0. // Moreover, the final lineHeight respects the editor zoom level. // So take the result from env.fontInfo return env.fontInfo.lineHeight; } } class EditorMinimap extends BaseEditorOption { constructor() { const defaults = { enabled: true, size: 'proportional', side: 'right', showSlider: 'mouseover', renderCharacters: true, maxColumn: 120, scale: 1, }; super(65 /* minimap */, 'minimap', defaults, { 'editor.minimap.enabled': { type: 'boolean', default: defaults.enabled, description: localize('minimap.enabled', "Controls whether the minimap is shown.") }, 'editor.minimap.size': { type: 'string', enum: ['proportional', 'fill', 'fit'], enumDescriptions: [ localize('minimap.size.proportional', "The minimap has the same size as the editor contents (and might scroll)."), localize('minimap.size.fill', "The minimap will stretch or shrink as necessary to fill the height of the editor (no scrolling)."), localize('minimap.size.fit', "The minimap will shrink as necessary to never be larger than the editor (no scrolling)."), ], default: defaults.size, description: localize('minimap.size', "Controls the size of the minimap.") }, 'editor.minimap.side': { type: 'string', enum: ['left', 'right'], default: defaults.side, description: localize('minimap.side', "Controls the side where to render the minimap.") }, 'editor.minimap.showSlider': { type: 'string', enum: ['always', 'mouseover'], default: defaults.showSlider, description: localize('minimap.showSlider', "Controls when the minimap slider is shown.") }, 'editor.minimap.scale': { type: 'number', default: defaults.scale, minimum: 1, maximum: 3, enum: [1, 2, 3], description: localize('minimap.scale', "Scale of content drawn in the minimap: 1, 2 or 3.") }, 'editor.minimap.renderCharacters': { type: 'boolean', default: defaults.renderCharacters, description: localize('minimap.renderCharacters', "Render the actual characters on a line as opposed to color blocks.") }, 'editor.minimap.maxColumn': { type: 'number', default: defaults.maxColumn, description: localize('minimap.maxColumn', "Limit the width of the minimap to render at most a certain number of columns.") } }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { enabled: boolean(input.enabled, this.defaultValue.enabled), size: stringSet(input.size, this.defaultValue.size, ['proportional', 'fill', 'fit']), side: stringSet(input.side, this.defaultValue.side, ['right', 'left']), showSlider: stringSet(input.showSlider, this.defaultValue.showSlider, ['always', 'mouseover']), renderCharacters: boolean(input.renderCharacters, this.defaultValue.renderCharacters), scale: EditorIntOption.clampedInt(input.scale, 1, 1, 3), maxColumn: EditorIntOption.clampedInt(input.maxColumn, this.defaultValue.maxColumn, 1, 10000), }; } } //#endregion //#region multiCursorModifier function _multiCursorModifierFromString(multiCursorModifier) { if (multiCursorModifier === 'ctrlCmd') { return (isMacintosh ? 'metaKey' : 'ctrlKey'); } return 'altKey'; } class EditorPadding extends BaseEditorOption { constructor() { super(75 /* padding */, 'padding', { top: 0, bottom: 0 }, { 'editor.padding.top': { type: 'number', default: 0, minimum: 0, maximum: 1000, description: localize('padding.top', "Controls the amount of space between the top edge of the editor and the first line.") }, 'editor.padding.bottom': { type: 'number', default: 0, minimum: 0, maximum: 1000, description: localize('padding.bottom', "Controls the amount of space between the bottom edge of the editor and the last line.") } }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { top: EditorIntOption.clampedInt(input.top, 0, 0, 1000), bottom: EditorIntOption.clampedInt(input.bottom, 0, 0, 1000) }; } } class EditorParameterHints extends BaseEditorOption { constructor() { const defaults = { enabled: true, cycle: false }; super(76 /* parameterHints */, 'parameterHints', defaults, { 'editor.parameterHints.enabled': { type: 'boolean', default: defaults.enabled, description: localize('parameterHints.enabled', "Enables a pop-up that shows parameter documentation and type information as you type.") }, 'editor.parameterHints.cycle': { type: 'boolean', default: defaults.cycle, description: localize('parameterHints.cycle', "Controls whether the parameter hints menu cycles or closes when reaching the end of the list.") }, }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { enabled: boolean(input.enabled, this.defaultValue.enabled), cycle: boolean(input.cycle, this.defaultValue.cycle) }; } } //#endregion //#region pixelRatio class EditorPixelRatio extends ComputedEditorOption { constructor() { super(129 /* pixelRatio */); } compute(env, options, _) { return env.pixelRatio; } } class EditorQuickSuggestions extends BaseEditorOption { constructor() { const defaults = { other: true, comments: false, strings: false }; super(79 /* quickSuggestions */, 'quickSuggestions', defaults, { anyOf: [ { type: 'boolean', }, { type: 'object', properties: { strings: { type: 'boolean', default: defaults.strings, description: localize('quickSuggestions.strings', "Enable quick suggestions inside strings.") }, comments: { type: 'boolean', default: defaults.comments, description: localize('quickSuggestions.comments', "Enable quick suggestions inside comments.") }, other: { type: 'boolean', default: defaults.other, description: localize('quickSuggestions.other', "Enable quick suggestions outside of strings and comments.") }, } } ], default: defaults, description: localize('quickSuggestions', "Controls whether suggestions should automatically show up while typing.") }); this.defaultValue = defaults; } validate(_input) { if (typeof _input === 'boolean') { return _input; } if (_input && typeof _input === 'object') { const input = _input; const opts = { other: boolean(input.other, this.defaultValue.other), comments: boolean(input.comments, this.defaultValue.comments), strings: boolean(input.strings, this.defaultValue.strings), }; if (opts.other && opts.comments && opts.strings) { return true; // all on } else if (!opts.other && !opts.comments && !opts.strings) { return false; // all off } else { return opts; } } return this.defaultValue; } } class EditorRenderLineNumbersOption extends BaseEditorOption { constructor() { super(60 /* lineNumbers */, 'lineNumbers', { renderType: 1 /* On */, renderFn: null }, { type: 'string', enum: ['off', 'on', 'relative', 'interval'], enumDescriptions: [ localize('lineNumbers.off', "Line numbers are not rendered."), localize('lineNumbers.on', "Line numbers are rendered as absolute number."), localize('lineNumbers.relative', "Line numbers are rendered as distance in lines to cursor position."), localize('lineNumbers.interval', "Line numbers are rendered every 10 lines.") ], default: 'on', description: localize('lineNumbers', "Controls the display of line numbers.") }); } validate(lineNumbers) { let renderType = this.defaultValue.renderType; let renderFn = this.defaultValue.renderFn; if (typeof lineNumbers !== 'undefined') { if (typeof lineNumbers === 'function') { renderType = 4 /* Custom */; renderFn = lineNumbers; } else if (lineNumbers === 'interval') { renderType = 3 /* Interval */; } else if (lineNumbers === 'relative') { renderType = 2 /* Relative */; } else if (lineNumbers === 'on') { renderType = 1 /* On */; } else { renderType = 0 /* Off */; } } return { renderType, renderFn }; } } //#endregion //#region renderValidationDecorations /** * @internal */ function filterValidationDecorations(options) { const renderValidationDecorations = options.get(87 /* renderValidationDecorations */); if (renderValidationDecorations === 'editable') { return options.get(81 /* readOnly */); } return renderValidationDecorations === 'on' ? false : true; } class EditorRulers extends BaseEditorOption { constructor() { const defaults = []; const columnSchema = { type: 'number', description: localize('rulers.size', "Number of monospace characters at which this editor ruler will render.") }; super(91 /* rulers */, 'rulers', defaults, { type: 'array', items: { anyOf: [ columnSchema, { type: [ 'object' ], properties: { column: columnSchema, color: { type: 'string', description: localize('rulers.color', "Color of this editor ruler."), format: 'color-hex' } } } ] }, default: defaults, description: localize('rulers', "Render vertical rulers after a certain number of monospace characters. Use multiple values for multiple rulers. No rulers are drawn if array is empty.") }); } validate(input) { if (Array.isArray(input)) { const rulers = []; for (let _element of input) { if (typeof _element === 'number') { rulers.push({ column: EditorIntOption.clampedInt(_element, 0, 0, 10000), color: null }); } else if (_element && typeof _element === 'object') { const element = _element; rulers.push({ column: EditorIntOption.clampedInt(element.column, 0, 0, 10000), color: element.color }); } } rulers.sort((a, b) => a.column - b.column); return rulers; } return this.defaultValue; } } function _scrollbarVisibilityFromString(visibility, defaultValue) { if (typeof visibility !== 'string') { return defaultValue; } switch (visibility) { case 'hidden': return 2 /* Hidden */; case 'visible': return 3 /* Visible */; default: return 1 /* Auto */; } } class EditorScrollbar$1 extends BaseEditorOption { constructor() { const defaults = { vertical: 1 /* Auto */, horizontal: 1 /* Auto */, arrowSize: 11, useShadows: true, verticalHasArrows: false, horizontalHasArrows: false, horizontalScrollbarSize: 12, horizontalSliderSize: 12, verticalScrollbarSize: 14, verticalSliderSize: 14, handleMouseWheel: true, alwaysConsumeMouseWheel: true, scrollByPage: false }; super(92 /* scrollbar */, 'scrollbar', defaults, { 'editor.scrollbar.vertical': { type: 'string', enum: ['auto', 'visible', 'hidden'], enumDescriptions: [ localize('scrollbar.vertical.auto', "The vertical scrollbar will be visible only when necessary."), localize('scrollbar.vertical.visible', "The vertical scrollbar will always be visible."), localize('scrollbar.vertical.fit', "The vertical scrollbar will always be hidden."), ], default: 'auto', description: localize('scrollbar.vertical', "Controls the visibility of the vertical scrollbar.") }, 'editor.scrollbar.horizontal': { type: 'string', enum: ['auto', 'visible', 'hidden'], enumDescriptions: [ localize('scrollbar.horizontal.auto', "The horizontal scrollbar will be visible only when necessary."), localize('scrollbar.horizontal.visible', "The horizontal scrollbar will always be visible."), localize('scrollbar.horizontal.fit', "The horizontal scrollbar will always be hidden."), ], default: 'auto', description: localize('scrollbar.horizontal', "Controls the visibility of the horizontal scrollbar.") }, 'editor.scrollbar.verticalScrollbarSize': { type: 'number', default: defaults.verticalScrollbarSize, description: localize('scrollbar.verticalScrollbarSize', "The width of the vertical scrollbar.") }, 'editor.scrollbar.horizontalScrollbarSize': { type: 'number', default: defaults.horizontalScrollbarSize, description: localize('scrollbar.horizontalScrollbarSize', "The height of the horizontal scrollbar.") }, 'editor.scrollbar.scrollByPage': { type: 'boolean', default: defaults.scrollByPage, description: localize('scrollbar.scrollByPage', "Controls whether clicks scroll by page or jump to click position.") } }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; const horizontalScrollbarSize = EditorIntOption.clampedInt(input.horizontalScrollbarSize, this.defaultValue.horizontalScrollbarSize, 0, 1000); const verticalScrollbarSize = EditorIntOption.clampedInt(input.verticalScrollbarSize, this.defaultValue.verticalScrollbarSize, 0, 1000); return { arrowSize: EditorIntOption.clampedInt(input.arrowSize, this.defaultValue.arrowSize, 0, 1000), vertical: _scrollbarVisibilityFromString(input.vertical, this.defaultValue.vertical), horizontal: _scrollbarVisibilityFromString(input.horizontal, this.defaultValue.horizontal), useShadows: boolean(input.useShadows, this.defaultValue.useShadows), verticalHasArrows: boolean(input.verticalHasArrows, this.defaultValue.verticalHasArrows), horizontalHasArrows: boolean(input.horizontalHasArrows, this.defaultValue.horizontalHasArrows), handleMouseWheel: boolean(input.handleMouseWheel, this.defaultValue.handleMouseWheel), alwaysConsumeMouseWheel: boolean(input.alwaysConsumeMouseWheel, this.defaultValue.alwaysConsumeMouseWheel), horizontalScrollbarSize: horizontalScrollbarSize, horizontalSliderSize: EditorIntOption.clampedInt(input.horizontalSliderSize, horizontalScrollbarSize, 0, 1000), verticalScrollbarSize: verticalScrollbarSize, verticalSliderSize: EditorIntOption.clampedInt(input.verticalSliderSize, verticalScrollbarSize, 0, 1000), scrollByPage: boolean(input.scrollByPage, this.defaultValue.scrollByPage), }; } } /** * @internal */ const inUntrustedWorkspace = 'inUntrustedWorkspace'; /** * @internal */ const unicodeHighlightConfigKeys = { allowedCharacters: 'editor.unicodeHighlight.allowedCharacters', invisibleCharacters: 'editor.unicodeHighlight.invisibleCharacters', nonBasicASCII: 'editor.unicodeHighlight.nonBasicASCII', ambiguousCharacters: 'editor.unicodeHighlight.ambiguousCharacters', includeComments: 'editor.unicodeHighlight.includeComments', includeStrings: 'editor.unicodeHighlight.includeStrings', allowedLocales: 'editor.unicodeHighlight.allowedLocales', }; class UnicodeHighlight extends BaseEditorOption { constructor() { const defaults = { nonBasicASCII: inUntrustedWorkspace, invisibleCharacters: true, ambiguousCharacters: true, includeComments: inUntrustedWorkspace, includeStrings: true, allowedCharacters: {}, allowedLocales: { _os: true, _vscode: true }, }; super(113 /* unicodeHighlighting */, 'unicodeHighlight', defaults, { [unicodeHighlightConfigKeys.nonBasicASCII]: { restricted: true, type: ['boolean', 'string'], enum: [true, false, inUntrustedWorkspace], default: defaults.nonBasicASCII, description: localize('unicodeHighlight.nonBasicASCII', "Controls whether all non-basic ASCII characters are highlighted. Only characters between U+0020 and U+007E, tab, line-feed and carriage-return are considered basic ASCII.") }, [unicodeHighlightConfigKeys.invisibleCharacters]: { restricted: true, type: 'boolean', default: defaults.invisibleCharacters, description: localize('unicodeHighlight.invisibleCharacters', "Controls whether characters that just reserve space or have no width at all are highlighted.") }, [unicodeHighlightConfigKeys.ambiguousCharacters]: { restricted: true, type: 'boolean', default: defaults.ambiguousCharacters, description: localize('unicodeHighlight.ambiguousCharacters', "Controls whether characters are highlighted that can be confused with basic ASCII characters, except those that are common in the current user locale.") }, [unicodeHighlightConfigKeys.includeComments]: { restricted: true, type: ['boolean', 'string'], enum: [true, false, inUntrustedWorkspace], default: defaults.includeComments, description: localize('unicodeHighlight.includeComments', "Controls whether characters in comments should also be subject to unicode highlighting.") }, [unicodeHighlightConfigKeys.includeStrings]: { restricted: true, type: ['boolean', 'string'], enum: [true, false, inUntrustedWorkspace], default: defaults.includeStrings, description: localize('unicodeHighlight.includeStrings', "Controls whether characters in strings should also be subject to unicode highlighting.") }, [unicodeHighlightConfigKeys.allowedCharacters]: { restricted: true, type: 'object', default: defaults.allowedCharacters, description: localize('unicodeHighlight.allowedCharacters', "Defines allowed characters that are not being highlighted."), additionalProperties: { type: 'boolean' } }, [unicodeHighlightConfigKeys.allowedLocales]: { restricted: true, type: 'object', additionalProperties: { type: 'boolean' }, default: defaults.allowedLocales, description: localize('unicodeHighlight.allowedLocales', "Unicode characters that are common in allowed locales are not being highlighted.") }, }); } applyUpdate(value, update) { let didChange = false; if (update.allowedCharacters) { // Treat allowedCharacters atomically if (!equals(value.allowedCharacters, update.allowedCharacters)) { value = Object.assign(Object.assign({}, value), { allowedCharacters: update.allowedCharacters }); didChange = true; } } if (update.allowedLocales) { // Treat allowedLocales atomically if (!equals(value.allowedLocales, update.allowedLocales)) { value = Object.assign(Object.assign({}, value), { allowedLocales: update.allowedLocales }); didChange = true; } } const result = super.applyUpdate(value, update); if (didChange) { return new ApplyUpdateResult(result.newValue, true); } return result; } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { nonBasicASCII: primitiveSet(input.nonBasicASCII, inUntrustedWorkspace, [true, false, inUntrustedWorkspace]), invisibleCharacters: boolean(input.invisibleCharacters, this.defaultValue.invisibleCharacters), ambiguousCharacters: boolean(input.ambiguousCharacters, this.defaultValue.ambiguousCharacters), includeComments: primitiveSet(input.includeComments, inUntrustedWorkspace, [true, false, inUntrustedWorkspace]), includeStrings: primitiveSet(input.includeStrings, inUntrustedWorkspace, [true, false, inUntrustedWorkspace]), allowedCharacters: this.validateBooleanMap(_input.allowedCharacters, this.defaultValue.allowedCharacters), allowedLocales: this.validateBooleanMap(_input.allowedLocales, this.defaultValue.allowedLocales), }; } validateBooleanMap(map, defaultValue) { if ((typeof map !== 'object') || !map) { return defaultValue; } const result = {}; for (const [key, value] of Object.entries(map)) { if (value === true) { result[key] = true; } } return result; } } /** * Configuration options for inline suggestions */ class InlineEditorSuggest extends BaseEditorOption { constructor() { const defaults = { enabled: true, mode: 'subwordSmart' }; super(55 /* inlineSuggest */, 'inlineSuggest', defaults, { 'editor.inlineSuggest.enabled': { type: 'boolean', default: defaults.enabled, description: localize('inlineSuggest.enabled', "Controls whether to automatically show inline suggestions in the editor.") } }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { enabled: boolean(input.enabled, this.defaultValue.enabled), mode: stringSet(input.mode, this.defaultValue.mode, ['prefix', 'subword', 'subwordSmart']), }; } } /** * Configuration options for inline suggestions */ class BracketPairColorization extends BaseEditorOption { constructor() { const defaults = { enabled: EDITOR_MODEL_DEFAULTS.bracketPairColorizationOptions.enabled }; super(12 /* bracketPairColorization */, 'bracketPairColorization', defaults, { 'editor.bracketPairColorization.enabled': { type: 'boolean', default: defaults.enabled, description: localize('bracketPairColorization.enabled', "Controls whether bracket pair colorization is enabled or not. Use 'workbench.colorCustomizations' to override the bracket highlight colors.") } }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { enabled: boolean(input.enabled, this.defaultValue.enabled) }; } } /** * Configuration options for inline suggestions */ class GuideOptions extends BaseEditorOption { constructor() { const defaults = { bracketPairs: false, bracketPairsHorizontal: 'active', highlightActiveBracketPair: true, indentation: true, highlightActiveIndentation: true }; super(13 /* guides */, 'guides', defaults, { 'editor.guides.bracketPairs': { type: ['boolean', 'string'], enum: [true, 'active', false], enumDescriptions: [ localize('editor.guides.bracketPairs.true', "Enables bracket pair guides."), localize('editor.guides.bracketPairs.active', "Enables bracket pair guides only for the active bracket pair."), localize('editor.guides.bracketPairs.false', "Disables bracket pair guides."), ], default: defaults.bracketPairs, description: localize('editor.guides.bracketPairs', "Controls whether bracket pair guides are enabled or not.") }, 'editor.guides.bracketPairsHorizontal': { type: ['boolean', 'string'], enum: [true, 'active', false], enumDescriptions: [ localize('editor.guides.bracketPairsHorizontal.true', "Enables horizontal guides as addition to vertical bracket pair guides."), localize('editor.guides.bracketPairsHorizontal.active', "Enables horizontal guides only for the active bracket pair."), localize('editor.guides.bracketPairsHorizontal.false', "Disables horizontal bracket pair guides."), ], default: defaults.bracketPairsHorizontal, description: localize('editor.guides.bracketPairsHorizontal', "Controls whether horizontal bracket pair guides are enabled or not.") }, 'editor.guides.highlightActiveBracketPair': { type: 'boolean', default: defaults.highlightActiveBracketPair, description: localize('editor.guides.highlightActiveBracketPair', "Controls whether bracket pair guides are enabled or not.") }, 'editor.guides.indentation': { type: 'boolean', default: defaults.indentation, description: localize('editor.guides.indentation', "Controls whether the editor should render indent guides.") }, 'editor.guides.highlightActiveIndentation': { type: 'boolean', default: defaults.highlightActiveIndentation, description: localize('editor.guides.highlightActiveIndentation', "Controls whether the editor should highlight the active indent guide.") } }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { bracketPairs: primitiveSet(input.bracketPairs, this.defaultValue.bracketPairs, [true, false, 'active']), bracketPairsHorizontal: primitiveSet(input.bracketPairsHorizontal, this.defaultValue.bracketPairsHorizontal, [true, false, 'active']), highlightActiveBracketPair: boolean(input.highlightActiveBracketPair, this.defaultValue.highlightActiveBracketPair), indentation: boolean(input.indentation, this.defaultValue.indentation), highlightActiveIndentation: boolean(input.highlightActiveIndentation, this.defaultValue.highlightActiveIndentation), }; } } function primitiveSet(value, defaultValue, allowedValues) { const idx = allowedValues.indexOf(value); if (idx === -1) { return defaultValue; } return allowedValues[idx]; } class EditorSuggest extends BaseEditorOption { constructor() { const defaults = { insertMode: 'insert', filterGraceful: true, snippetsPreventQuickSuggestions: true, localityBonus: false, shareSuggestSelections: false, showIcons: true, showStatusBar: false, preview: false, previewMode: 'subwordSmart', showInlineDetails: true, showMethods: true, showFunctions: true, showConstructors: true, showDeprecated: true, showFields: true, showVariables: true, showClasses: true, showStructs: true, showInterfaces: true, showModules: true, showProperties: true, showEvents: true, showOperators: true, showUnits: true, showValues: true, showConstants: true, showEnums: true, showEnumMembers: true, showKeywords: true, showWords: true, showColors: true, showFiles: true, showReferences: true, showFolders: true, showTypeParameters: true, showSnippets: true, showUsers: true, showIssues: true, }; super(106 /* suggest */, 'suggest', defaults, { 'editor.suggest.insertMode': { type: 'string', enum: ['insert', 'replace'], enumDescriptions: [ localize('suggest.insertMode.insert', "Insert suggestion without overwriting text right of the cursor."), localize('suggest.insertMode.replace', "Insert suggestion and overwrite text right of the cursor."), ], default: defaults.insertMode, description: localize('suggest.insertMode', "Controls whether words are overwritten when accepting completions. Note that this depends on extensions opting into this feature.") }, 'editor.suggest.filterGraceful': { type: 'boolean', default: defaults.filterGraceful, description: localize('suggest.filterGraceful', "Controls whether filtering and sorting suggestions accounts for small typos.") }, 'editor.suggest.localityBonus': { type: 'boolean', default: defaults.localityBonus, description: localize('suggest.localityBonus', "Controls whether sorting favors words that appear close to the cursor.") }, 'editor.suggest.shareSuggestSelections': { type: 'boolean', default: defaults.shareSuggestSelections, markdownDescription: localize('suggest.shareSuggestSelections', "Controls whether remembered suggestion selections are shared between multiple workspaces and windows (needs `#editor.suggestSelection#`).") }, 'editor.suggest.snippetsPreventQuickSuggestions': { type: 'boolean', default: defaults.snippetsPreventQuickSuggestions, description: localize('suggest.snippetsPreventQuickSuggestions', "Controls whether an active snippet prevents quick suggestions.") }, 'editor.suggest.showIcons': { type: 'boolean', default: defaults.showIcons, description: localize('suggest.showIcons', "Controls whether to show or hide icons in suggestions.") }, 'editor.suggest.showStatusBar': { type: 'boolean', default: defaults.showStatusBar, description: localize('suggest.showStatusBar', "Controls the visibility of the status bar at the bottom of the suggest widget.") }, 'editor.suggest.preview': { type: 'boolean', default: defaults.preview, description: localize('suggest.preview', "Controls whether to preview the suggestion outcome in the editor.") }, 'editor.suggest.showInlineDetails': { type: 'boolean', default: defaults.showInlineDetails, description: localize('suggest.showInlineDetails', "Controls whether suggest details show inline with the label or only in the details widget") }, 'editor.suggest.maxVisibleSuggestions': { type: 'number', deprecationMessage: localize('suggest.maxVisibleSuggestions.dep', "This setting is deprecated. The suggest widget can now be resized."), }, 'editor.suggest.filteredTypes': { type: 'object', deprecationMessage: localize('deprecated', "This setting is deprecated, please use separate settings like 'editor.suggest.showKeywords' or 'editor.suggest.showSnippets' instead.") }, 'editor.suggest.showMethods': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showMethods', "When enabled IntelliSense shows `method`-suggestions.") }, 'editor.suggest.showFunctions': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showFunctions', "When enabled IntelliSense shows `function`-suggestions.") }, 'editor.suggest.showConstructors': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showConstructors', "When enabled IntelliSense shows `constructor`-suggestions.") }, 'editor.suggest.showDeprecated': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showDeprecated', "When enabled IntelliSense shows `deprecated`-suggestions.") }, 'editor.suggest.showFields': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showFields', "When enabled IntelliSense shows `field`-suggestions.") }, 'editor.suggest.showVariables': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showVariables', "When enabled IntelliSense shows `variable`-suggestions.") }, 'editor.suggest.showClasses': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showClasss', "When enabled IntelliSense shows `class`-suggestions.") }, 'editor.suggest.showStructs': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showStructs', "When enabled IntelliSense shows `struct`-suggestions.") }, 'editor.suggest.showInterfaces': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showInterfaces', "When enabled IntelliSense shows `interface`-suggestions.") }, 'editor.suggest.showModules': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showModules', "When enabled IntelliSense shows `module`-suggestions.") }, 'editor.suggest.showProperties': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showPropertys', "When enabled IntelliSense shows `property`-suggestions.") }, 'editor.suggest.showEvents': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showEvents', "When enabled IntelliSense shows `event`-suggestions.") }, 'editor.suggest.showOperators': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showOperators', "When enabled IntelliSense shows `operator`-suggestions.") }, 'editor.suggest.showUnits': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showUnits', "When enabled IntelliSense shows `unit`-suggestions.") }, 'editor.suggest.showValues': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showValues', "When enabled IntelliSense shows `value`-suggestions.") }, 'editor.suggest.showConstants': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showConstants', "When enabled IntelliSense shows `constant`-suggestions.") }, 'editor.suggest.showEnums': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showEnums', "When enabled IntelliSense shows `enum`-suggestions.") }, 'editor.suggest.showEnumMembers': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showEnumMembers', "When enabled IntelliSense shows `enumMember`-suggestions.") }, 'editor.suggest.showKeywords': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showKeywords', "When enabled IntelliSense shows `keyword`-suggestions.") }, 'editor.suggest.showWords': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showTexts', "When enabled IntelliSense shows `text`-suggestions.") }, 'editor.suggest.showColors': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showColors', "When enabled IntelliSense shows `color`-suggestions.") }, 'editor.suggest.showFiles': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showFiles', "When enabled IntelliSense shows `file`-suggestions.") }, 'editor.suggest.showReferences': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showReferences', "When enabled IntelliSense shows `reference`-suggestions.") }, 'editor.suggest.showCustomcolors': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showCustomcolors', "When enabled IntelliSense shows `customcolor`-suggestions.") }, 'editor.suggest.showFolders': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showFolders', "When enabled IntelliSense shows `folder`-suggestions.") }, 'editor.suggest.showTypeParameters': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showTypeParameters', "When enabled IntelliSense shows `typeParameter`-suggestions.") }, 'editor.suggest.showSnippets': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showSnippets', "When enabled IntelliSense shows `snippet`-suggestions.") }, 'editor.suggest.showUsers': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showUsers', "When enabled IntelliSense shows `user`-suggestions.") }, 'editor.suggest.showIssues': { type: 'boolean', default: true, markdownDescription: localize('editor.suggest.showIssues', "When enabled IntelliSense shows `issues`-suggestions.") } }); } validate(_input) { if (!_input || typeof _input !== 'object') { return this.defaultValue; } const input = _input; return { insertMode: stringSet(input.insertMode, this.defaultValue.insertMode, ['insert', 'replace']), filterGraceful: boolean(input.filterGraceful, this.defaultValue.filterGraceful), snippetsPreventQuickSuggestions: boolean(input.snippetsPreventQuickSuggestions, this.defaultValue.filterGraceful), localityBonus: boolean(input.localityBonus, this.defaultValue.localityBonus), shareSuggestSelections: boolean(input.shareSuggestSelections, this.defaultValue.shareSuggestSelections), showIcons: boolean(input.showIcons, this.defaultValue.showIcons), showStatusBar: boolean(input.showStatusBar, this.defaultValue.showStatusBar), preview: boolean(input.preview, this.defaultValue.preview), previewMode: stringSet(input.previewMode, this.defaultValue.previewMode, ['prefix', 'subword', 'subwordSmart']), showInlineDetails: boolean(input.showInlineDetails, this.defaultValue.showInlineDetails), showMethods: boolean(input.showMethods, this.defaultValue.showMethods), showFunctions: boolean(input.showFunctions, this.defaultValue.showFunctions), showConstructors: boolean(input.showConstructors, this.defaultValue.showConstructors), showDeprecated: boolean(input.showDeprecated, this.defaultValue.showDeprecated), showFields: boolean(input.showFields, this.defaultValue.showFields), showVariables: boolean(input.showVariables, this.defaultValue.showVariables), showClasses: boolean(input.showClasses, this.defaultValue.showClasses), showStructs: boolean(input.showStructs, this.defaultValue.showStructs), showInterfaces: boolean(input.showInterfaces, this.defaultValue.showInterfaces), showModules: boolean(input.showModules, this.defaultValue.showModules), showProperties: boolean(input.showProperties, this.defaultValue.showProperties), showEvents: boolean(input.showEvents, this.defaultValue.showEvents), showOperators: boolean(input.showOperators, this.defaultValue.showOperators), showUnits: boolean(input.showUnits, this.defaultValue.showUnits), showValues: boolean(input.showValues, this.defaultValue.showValues), showConstants: boolean(input.showConstants, this.defaultValue.showConstants), showEnums: boolean(input.showEnums, this.defaultValue.showEnums), showEnumMembers: boolean(input.showEnumMembers, this.defaultValue.showEnumMembers), showKeywords: boolean(input.showKeywords, this.defaultValue.showKeywords), showWords: boolean(input.showWords, this.defaultValue.showWords), showColors: boolean(input.showColors, this.defaultValue.showColors), showFiles: boolean(input.showFiles, this.defaultValue.showFiles), showReferences: boolean(input.showReferences, this.defaultValue.showReferences), showFolders: boolean(input.showFolders, this.defaultValue.showFolders), showTypeParameters: boolean(input.showTypeParameters, this.defaultValue.showTypeParameters), showSnippets: boolean(input.showSnippets, this.defaultValue.showSnippets), showUsers: boolean(input.showUsers, this.defaultValue.showUsers), showIssues: boolean(input.showIssues, this.defaultValue.showIssues), }; } } class SmartSelect extends BaseEditorOption { constructor() { super(102 /* smartSelect */, 'smartSelect', { selectLeadingAndTrailingWhitespace: true }, { 'editor.smartSelect.selectLeadingAndTrailingWhitespace': { description: localize('selectLeadingAndTrailingWhitespace', "Whether leading and trailing whitespace should always be selected."), default: true, type: 'boolean' } }); } validate(input) { if (!input || typeof input !== 'object') { return this.defaultValue; } return { selectLeadingAndTrailingWhitespace: boolean(input.selectLeadingAndTrailingWhitespace, this.defaultValue.selectLeadingAndTrailingWhitespace) }; } } //#endregion //#region tabFocusMode class EditorTabFocusMode extends ComputedEditorOption { constructor() { super(130 /* tabFocusMode */); } compute(env, options, _) { const readOnly = options.get(81 /* readOnly */); return (readOnly ? true : env.tabFocusMode); } } function _wrappingIndentFromString(wrappingIndent) { switch (wrappingIndent) { case 'none': return 0 /* None */; case 'same': return 1 /* Same */; case 'indent': return 2 /* Indent */; case 'deepIndent': return 3 /* DeepIndent */; } } class EditorWrappingInfoComputer extends ComputedEditorOption { constructor() { super(132 /* wrappingInfo */); } compute(env, options, _) { const layoutInfo = options.get(131 /* layoutInfo */); return { isDominatedByLongLines: env.isDominatedByLongLines, isWordWrapMinified: layoutInfo.isWordWrapMinified, isViewportWrapping: layoutInfo.isViewportWrapping, wrappingColumn: layoutInfo.wrappingColumn, }; } } //#endregion const DEFAULT_WINDOWS_FONT_FAMILY = 'Consolas, \'Courier New\', monospace'; const DEFAULT_MAC_FONT_FAMILY = 'Menlo, Monaco, \'Courier New\', monospace'; const DEFAULT_LINUX_FONT_FAMILY = '\'Droid Sans Mono\', \'monospace\', monospace'; /** * @internal */ const EDITOR_FONT_DEFAULTS = { fontFamily: (isMacintosh ? DEFAULT_MAC_FONT_FAMILY : (isLinux ? DEFAULT_LINUX_FONT_FAMILY : DEFAULT_WINDOWS_FONT_FAMILY)), fontWeight: 'normal', fontSize: (isMacintosh ? 12 : 14), lineHeight: 0, letterSpacing: 0, }; /** * @internal */ const editorOptionsRegistry = []; function register$1(option) { editorOptionsRegistry[option.id] = option; return option; } const EditorOptions = { acceptSuggestionOnCommitCharacter: register$1(new EditorBooleanOption(0 /* acceptSuggestionOnCommitCharacter */, 'acceptSuggestionOnCommitCharacter', true, { markdownDescription: localize('acceptSuggestionOnCommitCharacter', "Controls whether suggestions should be accepted on commit characters. For example, in JavaScript, the semi-colon (`;`) can be a commit character that accepts a suggestion and types that character.") })), acceptSuggestionOnEnter: register$1(new EditorStringEnumOption(1 /* acceptSuggestionOnEnter */, 'acceptSuggestionOnEnter', 'on', ['on', 'smart', 'off'], { markdownEnumDescriptions: [ '', localize('acceptSuggestionOnEnterSmart', "Only accept a suggestion with `Enter` when it makes a textual change."), '' ], markdownDescription: localize('acceptSuggestionOnEnter', "Controls whether suggestions should be accepted on `Enter`, in addition to `Tab`. Helps to avoid ambiguity between inserting new lines or accepting suggestions.") })), accessibilitySupport: register$1(new EditorAccessibilitySupport()), accessibilityPageSize: register$1(new EditorIntOption(3 /* accessibilityPageSize */, 'accessibilityPageSize', 10, 1, 1073741824 /* MAX_SAFE_SMALL_INTEGER */, { description: localize('accessibilityPageSize', "Controls the number of lines in the editor that can be read out by a screen reader at once. When we detect a screen reader we automatically set the default to be 500. Warning: this has a performance implication for numbers larger than the default.") })), ariaLabel: register$1(new EditorStringOption(4 /* ariaLabel */, 'ariaLabel', localize('editorViewAccessibleLabel', "Editor content"))), autoClosingBrackets: register$1(new EditorStringEnumOption(5 /* autoClosingBrackets */, 'autoClosingBrackets', 'languageDefined', ['always', 'languageDefined', 'beforeWhitespace', 'never'], { enumDescriptions: [ '', localize('editor.autoClosingBrackets.languageDefined', "Use language configurations to determine when to autoclose brackets."), localize('editor.autoClosingBrackets.beforeWhitespace', "Autoclose brackets only when the cursor is to the left of whitespace."), '', ], description: localize('autoClosingBrackets', "Controls whether the editor should automatically close brackets after the user adds an opening bracket.") })), autoClosingDelete: register$1(new EditorStringEnumOption(6 /* autoClosingDelete */, 'autoClosingDelete', 'auto', ['always', 'auto', 'never'], { enumDescriptions: [ '', localize('editor.autoClosingDelete.auto', "Remove adjacent closing quotes or brackets only if they were automatically inserted."), '', ], description: localize('autoClosingDelete', "Controls whether the editor should remove adjacent closing quotes or brackets when deleting.") })), autoClosingOvertype: register$1(new EditorStringEnumOption(7 /* autoClosingOvertype */, 'autoClosingOvertype', 'auto', ['always', 'auto', 'never'], { enumDescriptions: [ '', localize('editor.autoClosingOvertype.auto', "Type over closing quotes or brackets only if they were automatically inserted."), '', ], description: localize('autoClosingOvertype', "Controls whether the editor should type over closing quotes or brackets.") })), autoClosingQuotes: register$1(new EditorStringEnumOption(8 /* autoClosingQuotes */, 'autoClosingQuotes', 'languageDefined', ['always', 'languageDefined', 'beforeWhitespace', 'never'], { enumDescriptions: [ '', localize('editor.autoClosingQuotes.languageDefined', "Use language configurations to determine when to autoclose quotes."), localize('editor.autoClosingQuotes.beforeWhitespace', "Autoclose quotes only when the cursor is to the left of whitespace."), '', ], description: localize('autoClosingQuotes', "Controls whether the editor should automatically close quotes after the user adds an opening quote.") })), autoIndent: register$1(new EditorEnumOption(9 /* autoIndent */, 'autoIndent', 4 /* Full */, 'full', ['none', 'keep', 'brackets', 'advanced', 'full'], _autoIndentFromString, { enumDescriptions: [ localize('editor.autoIndent.none', "The editor will not insert indentation automatically."), localize('editor.autoIndent.keep', "The editor will keep the current line's indentation."), localize('editor.autoIndent.brackets', "The editor will keep the current line's indentation and honor language defined brackets."), localize('editor.autoIndent.advanced', "The editor will keep the current line's indentation, honor language defined brackets and invoke special onEnterRules defined by languages."), localize('editor.autoIndent.full', "The editor will keep the current line's indentation, honor language defined brackets, invoke special onEnterRules defined by languages, and honor indentationRules defined by languages."), ], description: localize('autoIndent', "Controls whether the editor should automatically adjust the indentation when users type, paste, move or indent lines.") })), automaticLayout: register$1(new EditorBooleanOption(10 /* automaticLayout */, 'automaticLayout', false)), autoSurround: register$1(new EditorStringEnumOption(11 /* autoSurround */, 'autoSurround', 'languageDefined', ['languageDefined', 'quotes', 'brackets', 'never'], { enumDescriptions: [ localize('editor.autoSurround.languageDefined', "Use language configurations to determine when to automatically surround selections."), localize('editor.autoSurround.quotes', "Surround with quotes but not brackets."), localize('editor.autoSurround.brackets', "Surround with brackets but not quotes."), '' ], description: localize('autoSurround', "Controls whether the editor should automatically surround selections when typing quotes or brackets.") })), bracketPairColorization: register$1(new BracketPairColorization()), bracketPairGuides: register$1(new GuideOptions()), stickyTabStops: register$1(new EditorBooleanOption(104 /* stickyTabStops */, 'stickyTabStops', false, { description: localize('stickyTabStops', "Emulate selection behavior of tab characters when using spaces for indentation. Selection will stick to tab stops.") })), codeLens: register$1(new EditorBooleanOption(14 /* codeLens */, 'codeLens', true, { description: localize('codeLens', "Controls whether the editor shows CodeLens.") })), codeLensFontFamily: register$1(new EditorStringOption(15 /* codeLensFontFamily */, 'codeLensFontFamily', '', { description: localize('codeLensFontFamily', "Controls the font family for CodeLens.") })), codeLensFontSize: register$1(new EditorIntOption(16 /* codeLensFontSize */, 'codeLensFontSize', 0, 0, 100, { type: 'number', default: 0, minimum: 0, maximum: 100, markdownDescription: localize('codeLensFontSize', "Controls the font size in pixels for CodeLens. When set to `0`, 90% of `#editor.fontSize#` is used.") })), colorDecorators: register$1(new EditorBooleanOption(17 /* colorDecorators */, 'colorDecorators', true, { description: localize('colorDecorators', "Controls whether the editor should render the inline color decorators and color picker.") })), columnSelection: register$1(new EditorBooleanOption(18 /* columnSelection */, 'columnSelection', false, { description: localize('columnSelection', "Enable that the selection with the mouse and keys is doing column selection.") })), comments: register$1(new EditorComments()), contextmenu: register$1(new EditorBooleanOption(20 /* contextmenu */, 'contextmenu', true)), copyWithSyntaxHighlighting: register$1(new EditorBooleanOption(21 /* copyWithSyntaxHighlighting */, 'copyWithSyntaxHighlighting', true, { description: localize('copyWithSyntaxHighlighting', "Controls whether syntax highlighting should be copied into the clipboard.") })), cursorBlinking: register$1(new EditorEnumOption(22 /* cursorBlinking */, 'cursorBlinking', 1 /* Blink */, 'blink', ['blink', 'smooth', 'phase', 'expand', 'solid'], _cursorBlinkingStyleFromString, { description: localize('cursorBlinking', "Control the cursor animation style.") })), cursorSmoothCaretAnimation: register$1(new EditorBooleanOption(23 /* cursorSmoothCaretAnimation */, 'cursorSmoothCaretAnimation', false, { description: localize('cursorSmoothCaretAnimation', "Controls whether the smooth caret animation should be enabled.") })), cursorStyle: register$1(new EditorEnumOption(24 /* cursorStyle */, 'cursorStyle', TextEditorCursorStyle$1.Line, 'line', ['line', 'block', 'underline', 'line-thin', 'block-outline', 'underline-thin'], _cursorStyleFromString, { description: localize('cursorStyle', "Controls the cursor style.") })), cursorSurroundingLines: register$1(new EditorIntOption(25 /* cursorSurroundingLines */, 'cursorSurroundingLines', 0, 0, 1073741824 /* MAX_SAFE_SMALL_INTEGER */, { description: localize('cursorSurroundingLines', "Controls the minimal number of visible leading and trailing lines surrounding the cursor. Known as 'scrollOff' or 'scrollOffset' in some other editors.") })), cursorSurroundingLinesStyle: register$1(new EditorStringEnumOption(26 /* cursorSurroundingLinesStyle */, 'cursorSurroundingLinesStyle', 'default', ['default', 'all'], { enumDescriptions: [ localize('cursorSurroundingLinesStyle.default', "`cursorSurroundingLines` is enforced only when triggered via the keyboard or API."), localize('cursorSurroundingLinesStyle.all', "`cursorSurroundingLines` is enforced always.") ], description: localize('cursorSurroundingLinesStyle', "Controls when `cursorSurroundingLines` should be enforced.") })), cursorWidth: register$1(new EditorIntOption(27 /* cursorWidth */, 'cursorWidth', 0, 0, 1073741824 /* MAX_SAFE_SMALL_INTEGER */, { markdownDescription: localize('cursorWidth', "Controls the width of the cursor when `#editor.cursorStyle#` is set to `line`.") })), disableLayerHinting: register$1(new EditorBooleanOption(28 /* disableLayerHinting */, 'disableLayerHinting', false)), disableMonospaceOptimizations: register$1(new EditorBooleanOption(29 /* disableMonospaceOptimizations */, 'disableMonospaceOptimizations', false)), domReadOnly: register$1(new EditorBooleanOption(30 /* domReadOnly */, 'domReadOnly', false)), dragAndDrop: register$1(new EditorBooleanOption(31 /* dragAndDrop */, 'dragAndDrop', true, { description: localize('dragAndDrop', "Controls whether the editor should allow moving selections via drag and drop.") })), emptySelectionClipboard: register$1(new EditorEmptySelectionClipboard()), extraEditorClassName: register$1(new EditorStringOption(33 /* extraEditorClassName */, 'extraEditorClassName', '')), fastScrollSensitivity: register$1(new EditorFloatOption(34 /* fastScrollSensitivity */, 'fastScrollSensitivity', 5, x => (x <= 0 ? 5 : x), { markdownDescription: localize('fastScrollSensitivity', "Scrolling speed multiplier when pressing `Alt`.") })), find: register$1(new EditorFind()), fixedOverflowWidgets: register$1(new EditorBooleanOption(36 /* fixedOverflowWidgets */, 'fixedOverflowWidgets', false)), folding: register$1(new EditorBooleanOption(37 /* folding */, 'folding', true, { description: localize('folding', "Controls whether the editor has code folding enabled.") })), foldingStrategy: register$1(new EditorStringEnumOption(38 /* foldingStrategy */, 'foldingStrategy', 'auto', ['auto', 'indentation'], { enumDescriptions: [ localize('foldingStrategy.auto', "Use a language-specific folding strategy if available, else the indentation-based one."), localize('foldingStrategy.indentation', "Use the indentation-based folding strategy."), ], description: localize('foldingStrategy', "Controls the strategy for computing folding ranges.") })), foldingHighlight: register$1(new EditorBooleanOption(39 /* foldingHighlight */, 'foldingHighlight', true, { description: localize('foldingHighlight', "Controls whether the editor should highlight folded ranges.") })), foldingImportsByDefault: register$1(new EditorBooleanOption(40 /* foldingImportsByDefault */, 'foldingImportsByDefault', false, { description: localize('foldingImportsByDefault', "Controls whether the editor automatically collapses import ranges.") })), foldingMaximumRegions: register$1(new EditorIntOption(41 /* foldingMaximumRegions */, 'foldingMaximumRegions', 5000, 10, 65000, // limit must be less than foldingRanges MAX_FOLDING_REGIONS { description: localize('foldingMaximumRegions', "The maximum number of foldable regions. Increasing this value may result in the editor becoming less responsive when the current source has a large number of foldable regions.") })), unfoldOnClickAfterEndOfLine: register$1(new EditorBooleanOption(42 /* unfoldOnClickAfterEndOfLine */, 'unfoldOnClickAfterEndOfLine', false, { description: localize('unfoldOnClickAfterEndOfLine', "Controls whether clicking on the empty content after a folded line will unfold the line.") })), fontFamily: register$1(new EditorStringOption(43 /* fontFamily */, 'fontFamily', EDITOR_FONT_DEFAULTS.fontFamily, { description: localize('fontFamily', "Controls the font family.") })), fontInfo: register$1(new EditorFontInfo()), fontLigatures2: register$1(new EditorFontLigatures()), fontSize: register$1(new EditorFontSize()), fontWeight: register$1(new EditorFontWeight()), formatOnPaste: register$1(new EditorBooleanOption(48 /* formatOnPaste */, 'formatOnPaste', false, { description: localize('formatOnPaste', "Controls whether the editor should automatically format the pasted content. A formatter must be available and the formatter should be able to format a range in a document.") })), formatOnType: register$1(new EditorBooleanOption(49 /* formatOnType */, 'formatOnType', false, { description: localize('formatOnType', "Controls whether the editor should automatically format the line after typing.") })), glyphMargin: register$1(new EditorBooleanOption(50 /* glyphMargin */, 'glyphMargin', true, { description: localize('glyphMargin', "Controls whether the editor should render the vertical glyph margin. Glyph margin is mostly used for debugging.") })), gotoLocation: register$1(new EditorGoToLocation()), hideCursorInOverviewRuler: register$1(new EditorBooleanOption(52 /* hideCursorInOverviewRuler */, 'hideCursorInOverviewRuler', false, { description: localize('hideCursorInOverviewRuler', "Controls whether the cursor should be hidden in the overview ruler.") })), hover: register$1(new EditorHover()), inDiffEditor: register$1(new EditorBooleanOption(54 /* inDiffEditor */, 'inDiffEditor', false)), letterSpacing: register$1(new EditorFloatOption(56 /* letterSpacing */, 'letterSpacing', EDITOR_FONT_DEFAULTS.letterSpacing, x => EditorFloatOption.clamp(x, -5, 20), { description: localize('letterSpacing', "Controls the letter spacing in pixels.") })), lightbulb: register$1(new EditorLightbulb()), lineDecorationsWidth: register$1(new SimpleEditorOption(58 /* lineDecorationsWidth */, 'lineDecorationsWidth', 10)), lineHeight: register$1(new EditorLineHeight()), lineNumbers: register$1(new EditorRenderLineNumbersOption()), lineNumbersMinChars: register$1(new EditorIntOption(61 /* lineNumbersMinChars */, 'lineNumbersMinChars', 5, 1, 300)), linkedEditing: register$1(new EditorBooleanOption(62 /* linkedEditing */, 'linkedEditing', false, { description: localize('linkedEditing', "Controls whether the editor has linked editing enabled. Depending on the language, related symbols, e.g. HTML tags, are updated while editing.") })), links: register$1(new EditorBooleanOption(63 /* links */, 'links', true, { description: localize('links', "Controls whether the editor should detect links and make them clickable.") })), matchBrackets: register$1(new EditorStringEnumOption(64 /* matchBrackets */, 'matchBrackets', 'always', ['always', 'near', 'never'], { description: localize('matchBrackets', "Highlight matching brackets.") })), minimap: register$1(new EditorMinimap()), mouseStyle: register$1(new EditorStringEnumOption(66 /* mouseStyle */, 'mouseStyle', 'text', ['text', 'default', 'copy'])), mouseWheelScrollSensitivity: register$1(new EditorFloatOption(67 /* mouseWheelScrollSensitivity */, 'mouseWheelScrollSensitivity', 1, x => (x === 0 ? 1 : x), { markdownDescription: localize('mouseWheelScrollSensitivity', "A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events.") })), mouseWheelZoom: register$1(new EditorBooleanOption(68 /* mouseWheelZoom */, 'mouseWheelZoom', false, { markdownDescription: localize('mouseWheelZoom', "Zoom the font of the editor when using mouse wheel and holding `Ctrl`.") })), multiCursorMergeOverlapping: register$1(new EditorBooleanOption(69 /* multiCursorMergeOverlapping */, 'multiCursorMergeOverlapping', true, { description: localize('multiCursorMergeOverlapping', "Merge multiple cursors when they are overlapping.") })), multiCursorModifier: register$1(new EditorEnumOption(70 /* multiCursorModifier */, 'multiCursorModifier', 'altKey', 'alt', ['ctrlCmd', 'alt'], _multiCursorModifierFromString, { markdownEnumDescriptions: [ localize('multiCursorModifier.ctrlCmd', "Maps to `Control` on Windows and Linux and to `Command` on macOS."), localize('multiCursorModifier.alt', "Maps to `Alt` on Windows and Linux and to `Option` on macOS.") ], markdownDescription: localize({ key: 'multiCursorModifier', comment: [ '- `ctrlCmd` refers to a value the setting can take and should not be localized.', '- `Control` and `Command` refer to the modifier keys Ctrl or Cmd on the keyboard and can be localized.' ] }, "The modifier to be used to add multiple cursors with the mouse. The Go to Definition and Open Link mouse gestures will adapt such that they do not conflict with the multicursor modifier. [Read more](https://code.visualstudio.com/docs/editor/codebasics#_multicursor-modifier).") })), multiCursorPaste: register$1(new EditorStringEnumOption(71 /* multiCursorPaste */, 'multiCursorPaste', 'spread', ['spread', 'full'], { markdownEnumDescriptions: [ localize('multiCursorPaste.spread', "Each cursor pastes a single line of the text."), localize('multiCursorPaste.full', "Each cursor pastes the full text.") ], markdownDescription: localize('multiCursorPaste', "Controls pasting when the line count of the pasted text matches the cursor count.") })), occurrencesHighlight: register$1(new EditorBooleanOption(72 /* occurrencesHighlight */, 'occurrencesHighlight', true, { description: localize('occurrencesHighlight', "Controls whether the editor should highlight semantic symbol occurrences.") })), overviewRulerBorder: register$1(new EditorBooleanOption(73 /* overviewRulerBorder */, 'overviewRulerBorder', true, { description: localize('overviewRulerBorder', "Controls whether a border should be drawn around the overview ruler.") })), overviewRulerLanes: register$1(new EditorIntOption(74 /* overviewRulerLanes */, 'overviewRulerLanes', 3, 0, 3)), padding: register$1(new EditorPadding()), parameterHints: register$1(new EditorParameterHints()), peekWidgetDefaultFocus: register$1(new EditorStringEnumOption(77 /* peekWidgetDefaultFocus */, 'peekWidgetDefaultFocus', 'tree', ['tree', 'editor'], { enumDescriptions: [ localize('peekWidgetDefaultFocus.tree', "Focus the tree when opening peek"), localize('peekWidgetDefaultFocus.editor', "Focus the editor when opening peek") ], description: localize('peekWidgetDefaultFocus', "Controls whether to focus the inline editor or the tree in the peek widget.") })), definitionLinkOpensInPeek: register$1(new EditorBooleanOption(78 /* definitionLinkOpensInPeek */, 'definitionLinkOpensInPeek', false, { description: localize('definitionLinkOpensInPeek', "Controls whether the Go to Definition mouse gesture always opens the peek widget.") })), quickSuggestions: register$1(new EditorQuickSuggestions()), quickSuggestionsDelay: register$1(new EditorIntOption(80 /* quickSuggestionsDelay */, 'quickSuggestionsDelay', 10, 0, 1073741824 /* MAX_SAFE_SMALL_INTEGER */, { description: localize('quickSuggestionsDelay', "Controls the delay in milliseconds after which quick suggestions will show up.") })), readOnly: register$1(new EditorBooleanOption(81 /* readOnly */, 'readOnly', false)), renameOnType: register$1(new EditorBooleanOption(82 /* renameOnType */, 'renameOnType', false, { description: localize('renameOnType', "Controls whether the editor auto renames on type."), markdownDeprecationMessage: localize('renameOnTypeDeprecate', "Deprecated, use `editor.linkedEditing` instead.") })), renderControlCharacters: register$1(new EditorBooleanOption(83 /* renderControlCharacters */, 'renderControlCharacters', true, { description: localize('renderControlCharacters', "Controls whether the editor should render control characters."), restricted: true })), renderFinalNewline: register$1(new EditorBooleanOption(84 /* renderFinalNewline */, 'renderFinalNewline', true, { description: localize('renderFinalNewline', "Render last line number when the file ends with a newline.") })), renderLineHighlight: register$1(new EditorStringEnumOption(85 /* renderLineHighlight */, 'renderLineHighlight', 'line', ['none', 'gutter', 'line', 'all'], { enumDescriptions: [ '', '', '', localize('renderLineHighlight.all', "Highlights both the gutter and the current line."), ], description: localize('renderLineHighlight', "Controls how the editor should render the current line highlight.") })), renderLineHighlightOnlyWhenFocus: register$1(new EditorBooleanOption(86 /* renderLineHighlightOnlyWhenFocus */, 'renderLineHighlightOnlyWhenFocus', false, { description: localize('renderLineHighlightOnlyWhenFocus', "Controls if the editor should render the current line highlight only when the editor is focused.") })), renderValidationDecorations: register$1(new EditorStringEnumOption(87 /* renderValidationDecorations */, 'renderValidationDecorations', 'editable', ['editable', 'on', 'off'])), renderWhitespace: register$1(new EditorStringEnumOption(88 /* renderWhitespace */, 'renderWhitespace', 'selection', ['none', 'boundary', 'selection', 'trailing', 'all'], { enumDescriptions: [ '', localize('renderWhitespace.boundary', "Render whitespace characters except for single spaces between words."), localize('renderWhitespace.selection', "Render whitespace characters only on selected text."), localize('renderWhitespace.trailing', "Render only trailing whitespace characters."), '' ], description: localize('renderWhitespace', "Controls how the editor should render whitespace characters.") })), revealHorizontalRightPadding: register$1(new EditorIntOption(89 /* revealHorizontalRightPadding */, 'revealHorizontalRightPadding', 30, 0, 1000)), roundedSelection: register$1(new EditorBooleanOption(90 /* roundedSelection */, 'roundedSelection', true, { description: localize('roundedSelection', "Controls whether selections should have rounded corners.") })), rulers: register$1(new EditorRulers()), scrollbar: register$1(new EditorScrollbar$1()), scrollBeyondLastColumn: register$1(new EditorIntOption(93 /* scrollBeyondLastColumn */, 'scrollBeyondLastColumn', 5, 0, 1073741824 /* MAX_SAFE_SMALL_INTEGER */, { description: localize('scrollBeyondLastColumn', "Controls the number of extra characters beyond which the editor will scroll horizontally.") })), scrollBeyondLastLine: register$1(new EditorBooleanOption(94 /* scrollBeyondLastLine */, 'scrollBeyondLastLine', true, { description: localize('scrollBeyondLastLine', "Controls whether the editor will scroll beyond the last line.") })), scrollPredominantAxis: register$1(new EditorBooleanOption(95 /* scrollPredominantAxis */, 'scrollPredominantAxis', true, { description: localize('scrollPredominantAxis', "Scroll only along the predominant axis when scrolling both vertically and horizontally at the same time. Prevents horizontal drift when scrolling vertically on a trackpad.") })), selectionClipboard: register$1(new EditorBooleanOption(96 /* selectionClipboard */, 'selectionClipboard', true, { description: localize('selectionClipboard', "Controls whether the Linux primary clipboard should be supported."), included: isLinux })), selectionHighlight: register$1(new EditorBooleanOption(97 /* selectionHighlight */, 'selectionHighlight', true, { description: localize('selectionHighlight', "Controls whether the editor should highlight matches similar to the selection.") })), selectOnLineNumbers: register$1(new EditorBooleanOption(98 /* selectOnLineNumbers */, 'selectOnLineNumbers', true)), showFoldingControls: register$1(new EditorStringEnumOption(99 /* showFoldingControls */, 'showFoldingControls', 'mouseover', ['always', 'mouseover'], { enumDescriptions: [ localize('showFoldingControls.always', "Always show the folding controls."), localize('showFoldingControls.mouseover', "Only show the folding controls when the mouse is over the gutter."), ], description: localize('showFoldingControls', "Controls when the folding controls on the gutter are shown.") })), showUnused: register$1(new EditorBooleanOption(100 /* showUnused */, 'showUnused', true, { description: localize('showUnused', "Controls fading out of unused code.") })), showDeprecated: register$1(new EditorBooleanOption(126 /* showDeprecated */, 'showDeprecated', true, { description: localize('showDeprecated', "Controls strikethrough deprecated variables.") })), inlayHints: register$1(new EditorInlayHints()), snippetSuggestions: register$1(new EditorStringEnumOption(101 /* snippetSuggestions */, 'snippetSuggestions', 'inline', ['top', 'bottom', 'inline', 'none'], { enumDescriptions: [ localize('snippetSuggestions.top', "Show snippet suggestions on top of other suggestions."), localize('snippetSuggestions.bottom', "Show snippet suggestions below other suggestions."), localize('snippetSuggestions.inline', "Show snippets suggestions with other suggestions."), localize('snippetSuggestions.none', "Do not show snippet suggestions."), ], description: localize('snippetSuggestions', "Controls whether snippets are shown with other suggestions and how they are sorted.") })), smartSelect: register$1(new SmartSelect()), smoothScrolling: register$1(new EditorBooleanOption(103 /* smoothScrolling */, 'smoothScrolling', false, { description: localize('smoothScrolling', "Controls whether the editor will scroll using an animation.") })), stopRenderingLineAfter: register$1(new EditorIntOption(105 /* stopRenderingLineAfter */, 'stopRenderingLineAfter', 10000, -1, 1073741824 /* MAX_SAFE_SMALL_INTEGER */)), suggest: register$1(new EditorSuggest()), inlineSuggest: register$1(new InlineEditorSuggest()), suggestFontSize: register$1(new EditorIntOption(107 /* suggestFontSize */, 'suggestFontSize', 0, 0, 1000, { markdownDescription: localize('suggestFontSize', "Font size for the suggest widget. When set to `0`, the value of `#editor.fontSize#` is used.") })), suggestLineHeight: register$1(new EditorIntOption(108 /* suggestLineHeight */, 'suggestLineHeight', 0, 0, 1000, { markdownDescription: localize('suggestLineHeight', "Line height for the suggest widget. When set to `0`, the value of `#editor.lineHeight#` is used. The minimum value is 8.") })), suggestOnTriggerCharacters: register$1(new EditorBooleanOption(109 /* suggestOnTriggerCharacters */, 'suggestOnTriggerCharacters', true, { description: localize('suggestOnTriggerCharacters', "Controls whether suggestions should automatically show up when typing trigger characters.") })), suggestSelection: register$1(new EditorStringEnumOption(110 /* suggestSelection */, 'suggestSelection', 'first', ['first', 'recentlyUsed', 'recentlyUsedByPrefix'], { markdownEnumDescriptions: [ localize('suggestSelection.first', "Always select the first suggestion."), localize('suggestSelection.recentlyUsed', "Select recent suggestions unless further typing selects one, e.g. `console.| -> console.log` because `log` has been completed recently."), localize('suggestSelection.recentlyUsedByPrefix', "Select suggestions based on previous prefixes that have completed those suggestions, e.g. `co -> console` and `con -> const`."), ], description: localize('suggestSelection', "Controls how suggestions are pre-selected when showing the suggest list.") })), tabCompletion: register$1(new EditorStringEnumOption(111 /* tabCompletion */, 'tabCompletion', 'off', ['on', 'off', 'onlySnippets'], { enumDescriptions: [ localize('tabCompletion.on', "Tab complete will insert the best matching suggestion when pressing tab."), localize('tabCompletion.off', "Disable tab completions."), localize('tabCompletion.onlySnippets', "Tab complete snippets when their prefix match. Works best when 'quickSuggestions' aren't enabled."), ], description: localize('tabCompletion', "Enables tab completions.") })), tabIndex: register$1(new EditorIntOption(112 /* tabIndex */, 'tabIndex', 0, -1, 1073741824 /* MAX_SAFE_SMALL_INTEGER */)), unicodeHighlight: register$1(new UnicodeHighlight()), unusualLineTerminators: register$1(new EditorStringEnumOption(114 /* unusualLineTerminators */, 'unusualLineTerminators', 'prompt', ['auto', 'off', 'prompt'], { enumDescriptions: [ localize('unusualLineTerminators.auto', "Unusual line terminators are automatically removed."), localize('unusualLineTerminators.off', "Unusual line terminators are ignored."), localize('unusualLineTerminators.prompt', "Unusual line terminators prompt to be removed."), ], description: localize('unusualLineTerminators', "Remove unusual line terminators that might cause problems.") })), useShadowDOM: register$1(new EditorBooleanOption(115 /* useShadowDOM */, 'useShadowDOM', true)), useTabStops: register$1(new EditorBooleanOption(116 /* useTabStops */, 'useTabStops', true, { description: localize('useTabStops', "Inserting and deleting whitespace follows tab stops.") })), wordSeparators: register$1(new EditorStringOption(117 /* wordSeparators */, 'wordSeparators', USUAL_WORD_SEPARATORS, { description: localize('wordSeparators', "Characters that will be used as word separators when doing word related navigations or operations.") })), wordWrap: register$1(new EditorStringEnumOption(118 /* wordWrap */, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], { markdownEnumDescriptions: [ localize('wordWrap.off', "Lines will never wrap."), localize('wordWrap.on', "Lines will wrap at the viewport width."), localize({ key: 'wordWrap.wordWrapColumn', comment: [ '- `editor.wordWrapColumn` refers to a different setting and should not be localized.' ] }, "Lines will wrap at `#editor.wordWrapColumn#`."), localize({ key: 'wordWrap.bounded', comment: [ '- viewport means the edge of the visible window size.', '- `editor.wordWrapColumn` refers to a different setting and should not be localized.' ] }, "Lines will wrap at the minimum of viewport and `#editor.wordWrapColumn#`."), ], description: localize({ key: 'wordWrap', comment: [ '- \'off\', \'on\', \'wordWrapColumn\' and \'bounded\' refer to values the setting can take and should not be localized.', '- `editor.wordWrapColumn` refers to a different setting and should not be localized.' ] }, "Controls how lines should wrap.") })), wordWrapBreakAfterCharacters: register$1(new EditorStringOption(119 /* wordWrapBreakAfterCharacters */, 'wordWrapBreakAfterCharacters', // allow-any-unicode-next-line ' \t})]?|/&.,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), wordWrapBreakBeforeCharacters: register$1(new EditorStringOption(120 /* wordWrapBreakBeforeCharacters */, 'wordWrapBreakBeforeCharacters', // allow-any-unicode-next-line '([{‘“〈《「『【〔([{「£¥$£¥++')), wordWrapColumn: register$1(new EditorIntOption(121 /* wordWrapColumn */, 'wordWrapColumn', 80, 1, 1073741824 /* MAX_SAFE_SMALL_INTEGER */, { markdownDescription: localize({ key: 'wordWrapColumn', comment: [ '- `editor.wordWrap` refers to a different setting and should not be localized.', '- \'wordWrapColumn\' and \'bounded\' refer to values the different setting can take and should not be localized.' ] }, "Controls the wrapping column of the editor when `#editor.wordWrap#` is `wordWrapColumn` or `bounded`.") })), wordWrapOverride1: register$1(new EditorStringEnumOption(122 /* wordWrapOverride1 */, 'wordWrapOverride1', 'inherit', ['off', 'on', 'inherit'])), wordWrapOverride2: register$1(new EditorStringEnumOption(123 /* wordWrapOverride2 */, 'wordWrapOverride2', 'inherit', ['off', 'on', 'inherit'])), wrappingIndent: register$1(new EditorEnumOption(124 /* wrappingIndent */, 'wrappingIndent', 1 /* Same */, 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString, { enumDescriptions: [ localize('wrappingIndent.none', "No indentation. Wrapped lines begin at column 1."), localize('wrappingIndent.same', "Wrapped lines get the same indentation as the parent."), localize('wrappingIndent.indent', "Wrapped lines get +1 indentation toward the parent."), localize('wrappingIndent.deepIndent', "Wrapped lines get +2 indentation toward the parent."), ], description: localize('wrappingIndent', "Controls the indentation of wrapped lines."), })), wrappingStrategy: register$1(new EditorStringEnumOption(125 /* wrappingStrategy */, 'wrappingStrategy', 'simple', ['simple', 'advanced'], { enumDescriptions: [ localize('wrappingStrategy.simple', "Assumes that all characters are of the same width. This is a fast algorithm that works correctly for monospace fonts and certain scripts (like Latin characters) where glyphs are of equal width."), localize('wrappingStrategy.advanced', "Delegates wrapping points computation to the browser. This is a slow algorithm, that might cause freezes for large files, but it works correctly in all cases.") ], description: localize('wrappingStrategy', "Controls the algorithm that computes wrapping points.") })), // Leave these at the end (because they have dependencies!) editorClassName: register$1(new EditorClassName()), pixelRatio: register$1(new EditorPixelRatio()), tabFocusMode: register$1(new EditorTabFocusMode()), layoutInfo: register$1(new EditorLayoutInfoComputer()), wrappingInfo: register$1(new EditorWrappingInfoComputer()) }; // Avoid circular dependency on EventEmitter by implementing a subset of the interface. class ErrorHandler { constructor() { this.listeners = []; this.unexpectedErrorHandler = function (e) { setTimeout(() => { if (e.stack) { throw new Error(e.message + '\n\n' + e.stack); } throw e; }, 0); }; } emit(e) { this.listeners.forEach((listener) => { listener(e); }); } onUnexpectedError(e) { this.unexpectedErrorHandler(e); this.emit(e); } // For external errors, we don't want the listeners to be called onUnexpectedExternalError(e) { this.unexpectedErrorHandler(e); } } const errorHandler = new ErrorHandler(); function onUnexpectedError(e) { // ignore errors from cancelled promises if (!isCancellationError(e)) { errorHandler.onUnexpectedError(e); } return undefined; } function onUnexpectedExternalError(e) { // ignore errors from cancelled promises if (!isCancellationError(e)) { errorHandler.onUnexpectedExternalError(e); } return undefined; } function transformErrorForSerialization(error) { if (error instanceof Error) { let { name, message } = error; const stack = error.stacktrace || error.stack; return { $isError: true, name, message, stack }; } // return as is return error; } const canceledName = 'Canceled'; /** * Checks if the given error is a promise in canceled state */ function isCancellationError(error) { if (error instanceof CancellationError) { return true; } return error instanceof Error && error.name === canceledName && error.message === canceledName; } // !!!IMPORTANT!!! // Do NOT change this class because it is also used as an API-type. class CancellationError extends Error { constructor() { super(canceledName); this.name = this.message; } } /** * @deprecated uses {@link CancellationError} */ function canceled() { const error = new Error(canceledName); error.name = error.message; return error; } function illegalArgument(name) { if (name) { return new Error(`Illegal argument: ${name}`); } else { return new Error('Illegal argument'); } } function illegalState(name) { if (name) { return new Error(`Illegal state: ${name}`); } else { return new Error('Illegal state'); } } class NotSupportedError extends Error { constructor(message) { super('NotSupported'); if (message) { this.message = message; } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function once$1(fn) { const _this = this; let didCall = false; let result; return function () { if (didCall) { return result; } didCall = true; result = fn.apply(_this, arguments); return result; }; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var Iterable; (function (Iterable) { function is(thing) { return thing && typeof thing === 'object' && typeof thing[Symbol.iterator] === 'function'; } Iterable.is = is; const _empty = Object.freeze([]); function empty() { return _empty; } Iterable.empty = empty; function* single(element) { yield element; } Iterable.single = single; function from(iterable) { return iterable || _empty; } Iterable.from = from; function isEmpty(iterable) { return !iterable || iterable[Symbol.iterator]().next().done === true; } Iterable.isEmpty = isEmpty; function first(iterable) { return iterable[Symbol.iterator]().next().value; } Iterable.first = first; function some(iterable, predicate) { for (const element of iterable) { if (predicate(element)) { return true; } } return false; } Iterable.some = some; function find(iterable, predicate) { for (const element of iterable) { if (predicate(element)) { return element; } } return undefined; } Iterable.find = find; function* filter(iterable, predicate) { for (const element of iterable) { if (predicate(element)) { yield element; } } } Iterable.filter = filter; function* map(iterable, fn) { let index = 0; for (const element of iterable) { yield fn(element, index++); } } Iterable.map = map; function* concat(...iterables) { for (const iterable of iterables) { for (const element of iterable) { yield element; } } } Iterable.concat = concat; function* concatNested(iterables) { for (const iterable of iterables) { for (const element of iterable) { yield element; } } } Iterable.concatNested = concatNested; function reduce(iterable, reducer, initialValue) { let value = initialValue; for (const element of iterable) { value = reducer(value, element); } return value; } Iterable.reduce = reduce; /** * Returns an iterable slice of the array, with the same semantics as `array.slice()`. */ function* slice(arr, from, to = arr.length) { if (from < 0) { from += arr.length; } if (to < 0) { to += arr.length; } else if (to > arr.length) { to = arr.length; } for (; from < to; from++) { yield arr[from]; } } Iterable.slice = slice; /** * Consumes `atMost` elements from iterable and returns the consumed elements, * and an iterable for the rest of the elements. */ function consume(iterable, atMost = Number.POSITIVE_INFINITY) { const consumed = []; if (atMost === 0) { return [consumed, iterable]; } const iterator = iterable[Symbol.iterator](); for (let i = 0; i < atMost; i++) { const next = iterator.next(); if (next.done) { return [consumed, Iterable.empty()]; } consumed.push(next.value); } return [consumed, { [Symbol.iterator]() { return iterator; } }]; } Iterable.consume = consume; /** * Returns whether the iterables are the same length and all items are * equal using the comparator function. */ function equals(a, b, comparator = (at, bt) => at === bt) { const ai = a[Symbol.iterator](); const bi = b[Symbol.iterator](); while (true) { const an = ai.next(); const bn = bi.next(); if (an.done !== bn.done) { return false; } else if (an.done) { return true; } else if (!comparator(an.value, bn.value)) { return false; } } } Iterable.equals = equals; })(Iterable || (Iterable = {})); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function trackDisposable(x) { return x; } function setParentOfDisposable(child, parent) { } /** * Indicates that the given object is a singleton which does not need to be disposed. */ function markAsSingleton(singleton) { return singleton; } class MultiDisposeError extends Error { constructor(errors) { super(`Encountered errors while disposing of store. Errors: [${errors.join(', ')}]`); this.errors = errors; } } function isDisposable(thing) { return typeof thing.dispose === 'function' && thing.dispose.length === 0; } function dispose(arg) { if (Iterable.is(arg)) { let errors = []; for (const d of arg) { if (d) { try { d.dispose(); } catch (e) { errors.push(e); } } } if (errors.length === 1) { throw errors[0]; } else if (errors.length > 1) { throw new MultiDisposeError(errors); } return Array.isArray(arg) ? [] : arg; } else if (arg) { arg.dispose(); return arg; } } function combinedDisposable(...disposables) { const parent = toDisposable(() => dispose(disposables)); return parent; } function toDisposable(fn) { const self = trackDisposable({ dispose: once$1(() => { fn(); }) }); return self; } class DisposableStore { constructor() { this._toDispose = new Set(); this._isDisposed = false; } /** * Dispose of all registered disposables and mark this object as disposed. * * Any future disposables added to this object will be disposed of on `add`. */ dispose() { if (this._isDisposed) { return; } this._isDisposed = true; this.clear(); } /** * Returns `true` if this object has been disposed */ get isDisposed() { return this._isDisposed; } /** * Dispose of all registered disposables but do not mark this object as disposed. */ clear() { try { dispose(this._toDispose.values()); } finally { this._toDispose.clear(); } } add(o) { if (!o) { return o; } if (o === this) { throw new Error('Cannot register a disposable on itself!'); } if (this._isDisposed) { if (!DisposableStore.DISABLE_DISPOSED_WARNING) { console.warn(new Error('Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!').stack); } } else { this._toDispose.add(o); } return o; } } DisposableStore.DISABLE_DISPOSED_WARNING = false; class Disposable { constructor() { this._store = new DisposableStore(); setParentOfDisposable(this._store); } dispose() { this._store.dispose(); } _register(o) { if (o === this) { throw new Error('Cannot register a disposable on itself!'); } return this._store.add(o); } } Disposable.None = Object.freeze({ dispose() { } }); /** * Manages the lifecycle of a disposable value that may be changed. * * This ensures that when the disposable value is changed, the previously held disposable is disposed of. You can * also register a `MutableDisposable` on a `Disposable` to ensure it is automatically cleaned up. */ class MutableDisposable { constructor() { this._isDisposed = false; } get value() { return this._isDisposed ? undefined : this._value; } set value(value) { var _a; if (this._isDisposed || value === this._value) { return; } (_a = this._value) === null || _a === void 0 ? void 0 : _a.dispose(); this._value = value; } clear() { this.value = undefined; } dispose() { var _a; this._isDisposed = true; (_a = this._value) === null || _a === void 0 ? void 0 : _a.dispose(); this._value = undefined; } /** * Clears the value, but does not dispose it. * The old value is returned. */ clearAndLeak() { const oldValue = this._value; this._value = undefined; return oldValue; } } class ImmortalReference { constructor(object) { this.object = object; } dispose() { } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class Node$2 { constructor(element) { this.element = element; this.next = Node$2.Undefined; this.prev = Node$2.Undefined; } } Node$2.Undefined = new Node$2(undefined); class LinkedList { constructor() { this._first = Node$2.Undefined; this._last = Node$2.Undefined; this._size = 0; } get size() { return this._size; } isEmpty() { return this._first === Node$2.Undefined; } clear() { let node = this._first; while (node !== Node$2.Undefined) { const next = node.next; node.prev = Node$2.Undefined; node.next = Node$2.Undefined; node = next; } this._first = Node$2.Undefined; this._last = Node$2.Undefined; this._size = 0; } unshift(element) { return this._insert(element, false); } push(element) { return this._insert(element, true); } _insert(element, atTheEnd) { const newNode = new Node$2(element); if (this._first === Node$2.Undefined) { this._first = newNode; this._last = newNode; } else if (atTheEnd) { // push const oldLast = this._last; this._last = newNode; newNode.prev = oldLast; oldLast.next = newNode; } else { // unshift const oldFirst = this._first; this._first = newNode; newNode.next = oldFirst; oldFirst.prev = newNode; } this._size += 1; let didRemove = false; return () => { if (!didRemove) { didRemove = true; this._remove(newNode); } }; } shift() { if (this._first === Node$2.Undefined) { return undefined; } else { const res = this._first.element; this._remove(this._first); return res; } } pop() { if (this._last === Node$2.Undefined) { return undefined; } else { const res = this._last.element; this._remove(this._last); return res; } } _remove(node) { if (node.prev !== Node$2.Undefined && node.next !== Node$2.Undefined) { // middle const anchor = node.prev; anchor.next = node.next; node.next.prev = anchor; } else if (node.prev === Node$2.Undefined && node.next === Node$2.Undefined) { // only node this._first = Node$2.Undefined; this._last = Node$2.Undefined; } else if (node.next === Node$2.Undefined) { // last this._last = this._last.prev; this._last.next = Node$2.Undefined; } else if (node.prev === Node$2.Undefined) { // first this._first = this._first.next; this._first.prev = Node$2.Undefined; } // done this._size -= 1; } *[Symbol.iterator]() { let node = this._first; while (node !== Node$2.Undefined) { yield node.element; node = node.next; } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const hasPerformanceNow = (globals.performance && typeof globals.performance.now === 'function'); class StopWatch { constructor(highResolution) { this._highResolution = hasPerformanceNow && highResolution; this._startTime = this._now(); this._stopTime = -1; } static create(highResolution = true) { return new StopWatch(highResolution); } stop() { this._stopTime = this._now(); } elapsed() { if (this._stopTime !== -1) { return this._stopTime - this._startTime; } return this._now() - this._startTime; } _now() { return this._highResolution ? globals.performance.now() : Date.now(); } } var Event; (function (Event) { Event.None = () => Disposable.None; /** * Given an event, returns another event which only fires once. */ function once(event) { return (listener, thisArgs = null, disposables) => { // we need this, in case the event fires during the listener call let didFire = false; let result; result = event(e => { if (didFire) { return; } else if (result) { result.dispose(); } else { didFire = true; } return listener.call(thisArgs, e); }, null, disposables); if (didFire) { result.dispose(); } return result; }; } Event.once = once; /** * @deprecated DO NOT use, this leaks memory */ function map(event, map) { return snapshot((listener, thisArgs = null, disposables) => event(i => listener.call(thisArgs, map(i)), null, disposables)); } Event.map = map; /** * @deprecated DO NOT use, this leaks memory */ function forEach(event, each) { return snapshot((listener, thisArgs = null, disposables) => event(i => { each(i); listener.call(thisArgs, i); }, null, disposables)); } Event.forEach = forEach; function filter(event, filter) { return snapshot((listener, thisArgs = null, disposables) => event(e => filter(e) && listener.call(thisArgs, e), null, disposables)); } Event.filter = filter; /** * Given an event, returns the same event but typed as `Event`. */ function signal(event) { return event; } Event.signal = signal; function any(...events) { return (listener, thisArgs = null, disposables) => combinedDisposable(...events.map(event => event(e => listener.call(thisArgs, e), null, disposables))); } Event.any = any; /** * @deprecated DO NOT use, this leaks memory */ function reduce(event, merge, initial) { let output = initial; return map(event, e => { output = merge(output, e); return output; }); } Event.reduce = reduce; /** * @deprecated DO NOT use, this leaks memory */ function snapshot(event) { let listener; const emitter = new Emitter$1({ onFirstListenerAdd() { listener = event(emitter.fire, emitter); }, onLastListenerRemove() { listener.dispose(); } }); return emitter.event; } function debouncedListener(event, listener, merge, delay = 100, leading = false) { let output = undefined; let handle = undefined; let numDebouncedCalls = 0; return event(cur => { numDebouncedCalls++; output = merge(output, cur); if (leading && !handle) { listener(output); output = undefined; } clearTimeout(handle); handle = setTimeout(() => { const _output = output; output = undefined; handle = undefined; if (!leading || numDebouncedCalls > 1) { listener(_output); } numDebouncedCalls = 0; }, delay); }); } Event.debouncedListener = debouncedListener; /** * @deprecated this leaks memory, {@link debouncedListener} or {@link DebounceEmitter} instead */ function debounce(event, merge, delay = 100, leading = false, leakWarningThreshold) { let subscription; let output = undefined; let handle = undefined; let numDebouncedCalls = 0; const emitter = new Emitter$1({ leakWarningThreshold, onFirstListenerAdd() { subscription = event(cur => { numDebouncedCalls++; output = merge(output, cur); if (leading && !handle) { emitter.fire(output); output = undefined; } clearTimeout(handle); handle = setTimeout(() => { const _output = output; output = undefined; handle = undefined; if (!leading || numDebouncedCalls > 1) { emitter.fire(_output); } numDebouncedCalls = 0; }, delay); }); }, onLastListenerRemove() { subscription.dispose(); } }); return emitter.event; } Event.debounce = debounce; /** * @deprecated DO NOT use, this leaks memory */ function latch(event, equals = (a, b) => a === b) { let firstCall = true; let cache; return filter(event, value => { const shouldEmit = firstCall || !equals(value, cache); firstCall = false; cache = value; return shouldEmit; }); } Event.latch = latch; /** * @deprecated DO NOT use, this leaks memory */ function split(event, isT) { return [ Event.filter(event, isT), Event.filter(event, e => !isT(e)), ]; } Event.split = split; /** * @deprecated DO NOT use, this leaks memory */ function buffer(event, flushAfterTimeout = false, _buffer = []) { let buffer = _buffer.slice(); let listener = event(e => { if (buffer) { buffer.push(e); } else { emitter.fire(e); } }); const flush = () => { if (buffer) { buffer.forEach(e => emitter.fire(e)); } buffer = null; }; const emitter = new Emitter$1({ onFirstListenerAdd() { if (!listener) { listener = event(e => emitter.fire(e)); } }, onFirstListenerDidAdd() { if (buffer) { if (flushAfterTimeout) { setTimeout(flush); } else { flush(); } } }, onLastListenerRemove() { if (listener) { listener.dispose(); } listener = null; } }); return emitter.event; } Event.buffer = buffer; class ChainableEvent { constructor(event) { this.event = event; } map(fn) { return new ChainableEvent(map(this.event, fn)); } forEach(fn) { return new ChainableEvent(forEach(this.event, fn)); } filter(fn) { return new ChainableEvent(filter(this.event, fn)); } reduce(merge, initial) { return new ChainableEvent(reduce(this.event, merge, initial)); } latch() { return new ChainableEvent(latch(this.event)); } debounce(merge, delay = 100, leading = false, leakWarningThreshold) { return new ChainableEvent(debounce(this.event, merge, delay, leading, leakWarningThreshold)); } on(listener, thisArgs, disposables) { return this.event(listener, thisArgs, disposables); } once(listener, thisArgs, disposables) { return once(this.event)(listener, thisArgs, disposables); } } /** * @deprecated DO NOT use, this leaks memory */ function chain(event) { return new ChainableEvent(event); } Event.chain = chain; function fromNodeEventEmitter(emitter, eventName, map = id => id) { const fn = (...args) => result.fire(map(...args)); const onFirstListenerAdd = () => emitter.on(eventName, fn); const onLastListenerRemove = () => emitter.removeListener(eventName, fn); const result = new Emitter$1({ onFirstListenerAdd, onLastListenerRemove }); return result.event; } Event.fromNodeEventEmitter = fromNodeEventEmitter; function fromDOMEventEmitter(emitter, eventName, map = id => id) { const fn = (...args) => result.fire(map(...args)); const onFirstListenerAdd = () => emitter.addEventListener(eventName, fn); const onLastListenerRemove = () => emitter.removeEventListener(eventName, fn); const result = new Emitter$1({ onFirstListenerAdd, onLastListenerRemove }); return result.event; } Event.fromDOMEventEmitter = fromDOMEventEmitter; function toPromise(event) { return new Promise(resolve => once(event)(resolve)); } Event.toPromise = toPromise; function runAndSubscribe(event, handler) { handler(undefined); return event(e => handler(e)); } Event.runAndSubscribe = runAndSubscribe; function runAndSubscribeWithStore(event, handler) { let store = null; function run(e) { store === null || store === void 0 ? void 0 : store.dispose(); store = new DisposableStore(); handler(e, store); } run(undefined); const disposable = event(e => run(e)); return toDisposable(() => { disposable.dispose(); store === null || store === void 0 ? void 0 : store.dispose(); }); } Event.runAndSubscribeWithStore = runAndSubscribeWithStore; })(Event || (Event = {})); class EventProfiling { constructor(name) { this._listenerCount = 0; this._invocationCount = 0; this._elapsedOverall = 0; this._name = `${name}_${EventProfiling._idPool++}`; } start(listenerCount) { this._stopWatch = new StopWatch(true); this._listenerCount = listenerCount; } stop() { if (this._stopWatch) { const elapsed = this._stopWatch.elapsed(); this._elapsedOverall += elapsed; this._invocationCount += 1; console.info(`did FIRE ${this._name}: elapsed_ms: ${elapsed.toFixed(5)}, listener: ${this._listenerCount} (elapsed_overall: ${this._elapsedOverall.toFixed(2)}, invocations: ${this._invocationCount})`); this._stopWatch = undefined; } } } EventProfiling._idPool = 0; /** * The Emitter can be used to expose an Event to the public * to fire it from the insides. * Sample: class Document { private readonly _onDidChange = new Emitter<(value:string)=>any>(); public onDidChange = this._onDidChange.event; // getter-style // get onDidChange(): Event<(value:string)=>any> { // return this._onDidChange.event; // } private _doIt() { //... this._onDidChange.fire(value); } } */ class Emitter$1 { constructor(options) { var _a; this._disposed = false; this._options = options; this._leakageMon = undefined; this._perfMon = ((_a = this._options) === null || _a === void 0 ? void 0 : _a._profName) ? new EventProfiling(this._options._profName) : undefined; } /** * For the public to allow to subscribe * to events from this Emitter */ get event() { if (!this._event) { this._event = (listener, thisArgs, disposables) => { var _a; if (!this._listeners) { this._listeners = new LinkedList(); } const firstListener = this._listeners.isEmpty(); if (firstListener && this._options && this._options.onFirstListenerAdd) { this._options.onFirstListenerAdd(this); } const remove = this._listeners.push(!thisArgs ? listener : [listener, thisArgs]); if (firstListener && this._options && this._options.onFirstListenerDidAdd) { this._options.onFirstListenerDidAdd(this); } if (this._options && this._options.onListenerDidAdd) { this._options.onListenerDidAdd(this, listener, thisArgs); } // check and record this emitter for potential leakage const removeMonitor = (_a = this._leakageMon) === null || _a === void 0 ? void 0 : _a.check(this._listeners.size); const result = toDisposable(() => { if (removeMonitor) { removeMonitor(); } if (!this._disposed) { remove(); if (this._options && this._options.onLastListenerRemove) { const hasListeners = (this._listeners && !this._listeners.isEmpty()); if (!hasListeners) { this._options.onLastListenerRemove(this); } } } }); if (disposables instanceof DisposableStore) { disposables.add(result); } else if (Array.isArray(disposables)) { disposables.push(result); } return result; }; } return this._event; } /** * To be kept private to fire an event to * subscribers */ fire(event) { var _a, _b; if (this._listeners) { // put all [listener,event]-pairs into delivery queue // then emit all event. an inner/nested event might be // the driver of this if (!this._deliveryQueue) { this._deliveryQueue = new LinkedList(); } for (let listener of this._listeners) { this._deliveryQueue.push([listener, event]); } // start/stop performance insight collection (_a = this._perfMon) === null || _a === void 0 ? void 0 : _a.start(this._deliveryQueue.size); while (this._deliveryQueue.size > 0) { const [listener, event] = this._deliveryQueue.shift(); try { if (typeof listener === 'function') { listener.call(undefined, event); } else { listener[0].call(listener[1], event); } } catch (e) { onUnexpectedError(e); } } (_b = this._perfMon) === null || _b === void 0 ? void 0 : _b.stop(); } } dispose() { var _a, _b, _c, _d, _e; if (!this._disposed) { this._disposed = true; (_a = this._listeners) === null || _a === void 0 ? void 0 : _a.clear(); (_b = this._deliveryQueue) === null || _b === void 0 ? void 0 : _b.clear(); (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.onLastListenerRemove) === null || _d === void 0 ? void 0 : _d.call(_c); (_e = this._leakageMon) === null || _e === void 0 ? void 0 : _e.dispose(); } } } class PauseableEmitter extends Emitter$1 { constructor(options) { super(options); this._isPaused = 0; this._eventQueue = new LinkedList(); this._mergeFn = options === null || options === void 0 ? void 0 : options.merge; } pause() { this._isPaused++; } resume() { if (this._isPaused !== 0 && --this._isPaused === 0) { if (this._mergeFn) { // use the merge function to create a single composite // event. make a copy in case firing pauses this emitter const events = Array.from(this._eventQueue); this._eventQueue.clear(); super.fire(this._mergeFn(events)); } else { // no merging, fire each event individually and test // that this emitter isn't paused halfway through while (!this._isPaused && this._eventQueue.size !== 0) { super.fire(this._eventQueue.shift()); } } } } fire(event) { if (this._listeners) { if (this._isPaused !== 0) { this._eventQueue.push(event); } else { super.fire(event); } } } } class DebounceEmitter extends PauseableEmitter { constructor(options) { var _a; super(options); this._delay = (_a = options.delay) !== null && _a !== void 0 ? _a : 100; } fire(event) { if (!this._handle) { this.pause(); this._handle = setTimeout(() => { this._handle = undefined; this.resume(); }, this._delay); } super.fire(event); } } /** * The EventBufferer is useful in situations in which you want * to delay firing your events during some code. * You can wrap that code and be sure that the event will not * be fired during that wrap. * * ``` * const emitter: Emitter; * const delayer = new EventDelayer(); * const delayedEvent = delayer.wrapEvent(emitter.event); * * delayedEvent(console.log); * * delayer.bufferEvents(() => { * emitter.fire(); // event will not be fired yet * }); * * // event will only be fired at this point * ``` */ class EventBufferer { constructor() { this.buffers = []; } wrapEvent(event) { return (listener, thisArgs, disposables) => { return event(i => { const buffer = this.buffers[this.buffers.length - 1]; if (buffer) { buffer.push(() => listener.call(thisArgs, i)); } else { listener.call(thisArgs, i); } }, undefined, disposables); }; } bufferEvents(fn) { const buffer = []; this.buffers.push(buffer); const r = fn(); this.buffers.pop(); buffer.forEach(flush => flush()); return r; } } /** * A Relay is an event forwarder which functions as a replugabble event pipe. * Once created, you can connect an input event to it and it will simply forward * events from that input event through its own `event` property. The `input` * can be changed at any point in time. */ class Relay { constructor() { this.listening = false; this.inputEvent = Event.None; this.inputEventListener = Disposable.None; this.emitter = new Emitter$1({ onFirstListenerDidAdd: () => { this.listening = true; this.inputEventListener = this.inputEvent(this.emitter.fire, this.emitter); }, onLastListenerRemove: () => { this.listening = false; this.inputEventListener.dispose(); } }); this.event = this.emitter.event; } set input(event) { this.inputEvent = event; if (this.listening) { this.inputEventListener.dispose(); this.inputEventListener = event(this.emitter.fire, this.emitter); } } dispose() { this.inputEventListener.dispose(); this.emitter.dispose(); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const shortcutEvent = Object.freeze(function (callback, context) { const handle = setTimeout(callback.bind(context), 0); return { dispose() { clearTimeout(handle); } }; }); var CancellationToken; (function (CancellationToken) { function isCancellationToken(thing) { if (thing === CancellationToken.None || thing === CancellationToken.Cancelled) { return true; } if (thing instanceof MutableToken) { return true; } if (!thing || typeof thing !== 'object') { return false; } return typeof thing.isCancellationRequested === 'boolean' && typeof thing.onCancellationRequested === 'function'; } CancellationToken.isCancellationToken = isCancellationToken; CancellationToken.None = Object.freeze({ isCancellationRequested: false, onCancellationRequested: Event.None }); CancellationToken.Cancelled = Object.freeze({ isCancellationRequested: true, onCancellationRequested: shortcutEvent }); })(CancellationToken || (CancellationToken = {})); class MutableToken { constructor() { this._isCancelled = false; this._emitter = null; } cancel() { if (!this._isCancelled) { this._isCancelled = true; if (this._emitter) { this._emitter.fire(undefined); this.dispose(); } } } get isCancellationRequested() { return this._isCancelled; } get onCancellationRequested() { if (this._isCancelled) { return shortcutEvent; } if (!this._emitter) { this._emitter = new Emitter$1(); } return this._emitter.event; } dispose() { if (this._emitter) { this._emitter.dispose(); this._emitter = null; } } } class CancellationTokenSource$1 { constructor(parent) { this._token = undefined; this._parentListener = undefined; this._parentListener = parent && parent.onCancellationRequested(this.cancel, this); } get token() { if (!this._token) { // be lazy and create the token only when // actually needed this._token = new MutableToken(); } return this._token; } cancel() { if (!this._token) { // save an object by returning the default // cancelled token when cancellation happens // before someone asks for the token this._token = CancellationToken.Cancelled; } else if (this._token instanceof MutableToken) { // actually cancel this._token.cancel(); } } dispose(cancel = false) { if (cancel) { this.cancel(); } if (this._parentListener) { this._parentListener.dispose(); } if (!this._token) { // ensure to initialize with an empty token if we had none this._token = CancellationToken.None; } else if (this._token instanceof MutableToken) { // actually dispose this._token.dispose(); } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class KeyCodeStrMap { constructor() { this._keyCodeToStr = []; this._strToKeyCode = Object.create(null); } define(keyCode, str) { this._keyCodeToStr[keyCode] = str; this._strToKeyCode[str.toLowerCase()] = keyCode; } keyCodeToStr(keyCode) { return this._keyCodeToStr[keyCode]; } strToKeyCode(str) { return this._strToKeyCode[str.toLowerCase()] || 0 /* Unknown */; } } const uiMap = new KeyCodeStrMap(); const userSettingsUSMap = new KeyCodeStrMap(); const userSettingsGeneralMap = new KeyCodeStrMap(); const EVENT_KEY_CODE_MAP = new Array(230); const scanCodeStrToInt = Object.create(null); const scanCodeLowerCaseStrToInt = Object.create(null); /** * -1 if a ScanCode => KeyCode mapping depends on kb layout. */ const IMMUTABLE_CODE_TO_KEY_CODE = []; for (let i = 0; i <= 193 /* MAX_VALUE */; i++) { IMMUTABLE_CODE_TO_KEY_CODE[i] = -1 /* DependsOnKbLayout */; } (function () { // See https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx // See https://github.com/microsoft/node-native-keymap/blob/master/deps/chromium/keyboard_codes_win.h const empty = ''; const mappings = [ // keyCodeOrd, immutable, scanCode, scanCodeStr, keyCode, keyCodeStr, eventKeyCode, vkey, usUserSettingsLabel, generalUserSettingsLabel [0, 1, 0 /* None */, 'None', 0 /* Unknown */, 'unknown', 0, 'VK_UNKNOWN', empty, empty], [0, 1, 1 /* Hyper */, 'Hyper', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 2 /* Super */, 'Super', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 3 /* Fn */, 'Fn', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 4 /* FnLock */, 'FnLock', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 5 /* Suspend */, 'Suspend', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 6 /* Resume */, 'Resume', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 7 /* Turbo */, 'Turbo', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 8 /* Sleep */, 'Sleep', 0 /* Unknown */, empty, 0, 'VK_SLEEP', empty, empty], [0, 1, 9 /* WakeUp */, 'WakeUp', 0 /* Unknown */, empty, 0, empty, empty, empty], [31, 0, 10 /* KeyA */, 'KeyA', 31 /* KeyA */, 'A', 65, 'VK_A', empty, empty], [32, 0, 11 /* KeyB */, 'KeyB', 32 /* KeyB */, 'B', 66, 'VK_B', empty, empty], [33, 0, 12 /* KeyC */, 'KeyC', 33 /* KeyC */, 'C', 67, 'VK_C', empty, empty], [34, 0, 13 /* KeyD */, 'KeyD', 34 /* KeyD */, 'D', 68, 'VK_D', empty, empty], [35, 0, 14 /* KeyE */, 'KeyE', 35 /* KeyE */, 'E', 69, 'VK_E', empty, empty], [36, 0, 15 /* KeyF */, 'KeyF', 36 /* KeyF */, 'F', 70, 'VK_F', empty, empty], [37, 0, 16 /* KeyG */, 'KeyG', 37 /* KeyG */, 'G', 71, 'VK_G', empty, empty], [38, 0, 17 /* KeyH */, 'KeyH', 38 /* KeyH */, 'H', 72, 'VK_H', empty, empty], [39, 0, 18 /* KeyI */, 'KeyI', 39 /* KeyI */, 'I', 73, 'VK_I', empty, empty], [40, 0, 19 /* KeyJ */, 'KeyJ', 40 /* KeyJ */, 'J', 74, 'VK_J', empty, empty], [41, 0, 20 /* KeyK */, 'KeyK', 41 /* KeyK */, 'K', 75, 'VK_K', empty, empty], [42, 0, 21 /* KeyL */, 'KeyL', 42 /* KeyL */, 'L', 76, 'VK_L', empty, empty], [43, 0, 22 /* KeyM */, 'KeyM', 43 /* KeyM */, 'M', 77, 'VK_M', empty, empty], [44, 0, 23 /* KeyN */, 'KeyN', 44 /* KeyN */, 'N', 78, 'VK_N', empty, empty], [45, 0, 24 /* KeyO */, 'KeyO', 45 /* KeyO */, 'O', 79, 'VK_O', empty, empty], [46, 0, 25 /* KeyP */, 'KeyP', 46 /* KeyP */, 'P', 80, 'VK_P', empty, empty], [47, 0, 26 /* KeyQ */, 'KeyQ', 47 /* KeyQ */, 'Q', 81, 'VK_Q', empty, empty], [48, 0, 27 /* KeyR */, 'KeyR', 48 /* KeyR */, 'R', 82, 'VK_R', empty, empty], [49, 0, 28 /* KeyS */, 'KeyS', 49 /* KeyS */, 'S', 83, 'VK_S', empty, empty], [50, 0, 29 /* KeyT */, 'KeyT', 50 /* KeyT */, 'T', 84, 'VK_T', empty, empty], [51, 0, 30 /* KeyU */, 'KeyU', 51 /* KeyU */, 'U', 85, 'VK_U', empty, empty], [52, 0, 31 /* KeyV */, 'KeyV', 52 /* KeyV */, 'V', 86, 'VK_V', empty, empty], [53, 0, 32 /* KeyW */, 'KeyW', 53 /* KeyW */, 'W', 87, 'VK_W', empty, empty], [54, 0, 33 /* KeyX */, 'KeyX', 54 /* KeyX */, 'X', 88, 'VK_X', empty, empty], [55, 0, 34 /* KeyY */, 'KeyY', 55 /* KeyY */, 'Y', 89, 'VK_Y', empty, empty], [56, 0, 35 /* KeyZ */, 'KeyZ', 56 /* KeyZ */, 'Z', 90, 'VK_Z', empty, empty], [22, 0, 36 /* Digit1 */, 'Digit1', 22 /* Digit1 */, '1', 49, 'VK_1', empty, empty], [23, 0, 37 /* Digit2 */, 'Digit2', 23 /* Digit2 */, '2', 50, 'VK_2', empty, empty], [24, 0, 38 /* Digit3 */, 'Digit3', 24 /* Digit3 */, '3', 51, 'VK_3', empty, empty], [25, 0, 39 /* Digit4 */, 'Digit4', 25 /* Digit4 */, '4', 52, 'VK_4', empty, empty], [26, 0, 40 /* Digit5 */, 'Digit5', 26 /* Digit5 */, '5', 53, 'VK_5', empty, empty], [27, 0, 41 /* Digit6 */, 'Digit6', 27 /* Digit6 */, '6', 54, 'VK_6', empty, empty], [28, 0, 42 /* Digit7 */, 'Digit7', 28 /* Digit7 */, '7', 55, 'VK_7', empty, empty], [29, 0, 43 /* Digit8 */, 'Digit8', 29 /* Digit8 */, '8', 56, 'VK_8', empty, empty], [30, 0, 44 /* Digit9 */, 'Digit9', 30 /* Digit9 */, '9', 57, 'VK_9', empty, empty], [21, 0, 45 /* Digit0 */, 'Digit0', 21 /* Digit0 */, '0', 48, 'VK_0', empty, empty], [3, 1, 46 /* Enter */, 'Enter', 3 /* Enter */, 'Enter', 13, 'VK_RETURN', empty, empty], [9, 1, 47 /* Escape */, 'Escape', 9 /* Escape */, 'Escape', 27, 'VK_ESCAPE', empty, empty], [1, 1, 48 /* Backspace */, 'Backspace', 1 /* Backspace */, 'Backspace', 8, 'VK_BACK', empty, empty], [2, 1, 49 /* Tab */, 'Tab', 2 /* Tab */, 'Tab', 9, 'VK_TAB', empty, empty], [10, 1, 50 /* Space */, 'Space', 10 /* Space */, 'Space', 32, 'VK_SPACE', empty, empty], [83, 0, 51 /* Minus */, 'Minus', 83 /* Minus */, '-', 189, 'VK_OEM_MINUS', '-', 'OEM_MINUS'], [81, 0, 52 /* Equal */, 'Equal', 81 /* Equal */, '=', 187, 'VK_OEM_PLUS', '=', 'OEM_PLUS'], [87, 0, 53 /* BracketLeft */, 'BracketLeft', 87 /* BracketLeft */, '[', 219, 'VK_OEM_4', '[', 'OEM_4'], [89, 0, 54 /* BracketRight */, 'BracketRight', 89 /* BracketRight */, ']', 221, 'VK_OEM_6', ']', 'OEM_6'], [88, 0, 55 /* Backslash */, 'Backslash', 88 /* Backslash */, '\\', 220, 'VK_OEM_5', '\\', 'OEM_5'], [0, 0, 56 /* IntlHash */, 'IntlHash', 0 /* Unknown */, empty, 0, empty, empty, empty], [80, 0, 57 /* Semicolon */, 'Semicolon', 80 /* Semicolon */, ';', 186, 'VK_OEM_1', ';', 'OEM_1'], [90, 0, 58 /* Quote */, 'Quote', 90 /* Quote */, '\'', 222, 'VK_OEM_7', '\'', 'OEM_7'], [86, 0, 59 /* Backquote */, 'Backquote', 86 /* Backquote */, '`', 192, 'VK_OEM_3', '`', 'OEM_3'], [82, 0, 60 /* Comma */, 'Comma', 82 /* Comma */, ',', 188, 'VK_OEM_COMMA', ',', 'OEM_COMMA'], [84, 0, 61 /* Period */, 'Period', 84 /* Period */, '.', 190, 'VK_OEM_PERIOD', '.', 'OEM_PERIOD'], [85, 0, 62 /* Slash */, 'Slash', 85 /* Slash */, '/', 191, 'VK_OEM_2', '/', 'OEM_2'], [8, 1, 63 /* CapsLock */, 'CapsLock', 8 /* CapsLock */, 'CapsLock', 20, 'VK_CAPITAL', empty, empty], [59, 1, 64 /* F1 */, 'F1', 59 /* F1 */, 'F1', 112, 'VK_F1', empty, empty], [60, 1, 65 /* F2 */, 'F2', 60 /* F2 */, 'F2', 113, 'VK_F2', empty, empty], [61, 1, 66 /* F3 */, 'F3', 61 /* F3 */, 'F3', 114, 'VK_F3', empty, empty], [62, 1, 67 /* F4 */, 'F4', 62 /* F4 */, 'F4', 115, 'VK_F4', empty, empty], [63, 1, 68 /* F5 */, 'F5', 63 /* F5 */, 'F5', 116, 'VK_F5', empty, empty], [64, 1, 69 /* F6 */, 'F6', 64 /* F6 */, 'F6', 117, 'VK_F6', empty, empty], [65, 1, 70 /* F7 */, 'F7', 65 /* F7 */, 'F7', 118, 'VK_F7', empty, empty], [66, 1, 71 /* F8 */, 'F8', 66 /* F8 */, 'F8', 119, 'VK_F8', empty, empty], [67, 1, 72 /* F9 */, 'F9', 67 /* F9 */, 'F9', 120, 'VK_F9', empty, empty], [68, 1, 73 /* F10 */, 'F10', 68 /* F10 */, 'F10', 121, 'VK_F10', empty, empty], [69, 1, 74 /* F11 */, 'F11', 69 /* F11 */, 'F11', 122, 'VK_F11', empty, empty], [70, 1, 75 /* F12 */, 'F12', 70 /* F12 */, 'F12', 123, 'VK_F12', empty, empty], [0, 1, 76 /* PrintScreen */, 'PrintScreen', 0 /* Unknown */, empty, 0, empty, empty, empty], [79, 1, 77 /* ScrollLock */, 'ScrollLock', 79 /* ScrollLock */, 'ScrollLock', 145, 'VK_SCROLL', empty, empty], [7, 1, 78 /* Pause */, 'Pause', 7 /* PauseBreak */, 'PauseBreak', 19, 'VK_PAUSE', empty, empty], [19, 1, 79 /* Insert */, 'Insert', 19 /* Insert */, 'Insert', 45, 'VK_INSERT', empty, empty], [14, 1, 80 /* Home */, 'Home', 14 /* Home */, 'Home', 36, 'VK_HOME', empty, empty], [11, 1, 81 /* PageUp */, 'PageUp', 11 /* PageUp */, 'PageUp', 33, 'VK_PRIOR', empty, empty], [20, 1, 82 /* Delete */, 'Delete', 20 /* Delete */, 'Delete', 46, 'VK_DELETE', empty, empty], [13, 1, 83 /* End */, 'End', 13 /* End */, 'End', 35, 'VK_END', empty, empty], [12, 1, 84 /* PageDown */, 'PageDown', 12 /* PageDown */, 'PageDown', 34, 'VK_NEXT', empty, empty], [17, 1, 85 /* ArrowRight */, 'ArrowRight', 17 /* RightArrow */, 'RightArrow', 39, 'VK_RIGHT', 'Right', empty], [15, 1, 86 /* ArrowLeft */, 'ArrowLeft', 15 /* LeftArrow */, 'LeftArrow', 37, 'VK_LEFT', 'Left', empty], [18, 1, 87 /* ArrowDown */, 'ArrowDown', 18 /* DownArrow */, 'DownArrow', 40, 'VK_DOWN', 'Down', empty], [16, 1, 88 /* ArrowUp */, 'ArrowUp', 16 /* UpArrow */, 'UpArrow', 38, 'VK_UP', 'Up', empty], [78, 1, 89 /* NumLock */, 'NumLock', 78 /* NumLock */, 'NumLock', 144, 'VK_NUMLOCK', empty, empty], [108, 1, 90 /* NumpadDivide */, 'NumpadDivide', 108 /* NumpadDivide */, 'NumPad_Divide', 111, 'VK_DIVIDE', empty, empty], [103, 1, 91 /* NumpadMultiply */, 'NumpadMultiply', 103 /* NumpadMultiply */, 'NumPad_Multiply', 106, 'VK_MULTIPLY', empty, empty], [106, 1, 92 /* NumpadSubtract */, 'NumpadSubtract', 106 /* NumpadSubtract */, 'NumPad_Subtract', 109, 'VK_SUBTRACT', empty, empty], [104, 1, 93 /* NumpadAdd */, 'NumpadAdd', 104 /* NumpadAdd */, 'NumPad_Add', 107, 'VK_ADD', empty, empty], [3, 1, 94 /* NumpadEnter */, 'NumpadEnter', 3 /* Enter */, empty, 0, empty, empty, empty], [94, 1, 95 /* Numpad1 */, 'Numpad1', 94 /* Numpad1 */, 'NumPad1', 97, 'VK_NUMPAD1', empty, empty], [95, 1, 96 /* Numpad2 */, 'Numpad2', 95 /* Numpad2 */, 'NumPad2', 98, 'VK_NUMPAD2', empty, empty], [96, 1, 97 /* Numpad3 */, 'Numpad3', 96 /* Numpad3 */, 'NumPad3', 99, 'VK_NUMPAD3', empty, empty], [97, 1, 98 /* Numpad4 */, 'Numpad4', 97 /* Numpad4 */, 'NumPad4', 100, 'VK_NUMPAD4', empty, empty], [98, 1, 99 /* Numpad5 */, 'Numpad5', 98 /* Numpad5 */, 'NumPad5', 101, 'VK_NUMPAD5', empty, empty], [99, 1, 100 /* Numpad6 */, 'Numpad6', 99 /* Numpad6 */, 'NumPad6', 102, 'VK_NUMPAD6', empty, empty], [100, 1, 101 /* Numpad7 */, 'Numpad7', 100 /* Numpad7 */, 'NumPad7', 103, 'VK_NUMPAD7', empty, empty], [101, 1, 102 /* Numpad8 */, 'Numpad8', 101 /* Numpad8 */, 'NumPad8', 104, 'VK_NUMPAD8', empty, empty], [102, 1, 103 /* Numpad9 */, 'Numpad9', 102 /* Numpad9 */, 'NumPad9', 105, 'VK_NUMPAD9', empty, empty], [93, 1, 104 /* Numpad0 */, 'Numpad0', 93 /* Numpad0 */, 'NumPad0', 96, 'VK_NUMPAD0', empty, empty], [107, 1, 105 /* NumpadDecimal */, 'NumpadDecimal', 107 /* NumpadDecimal */, 'NumPad_Decimal', 110, 'VK_DECIMAL', empty, empty], [92, 0, 106 /* IntlBackslash */, 'IntlBackslash', 92 /* IntlBackslash */, 'OEM_102', 226, 'VK_OEM_102', empty, empty], [58, 1, 107 /* ContextMenu */, 'ContextMenu', 58 /* ContextMenu */, 'ContextMenu', 93, empty, empty, empty], [0, 1, 108 /* Power */, 'Power', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 109 /* NumpadEqual */, 'NumpadEqual', 0 /* Unknown */, empty, 0, empty, empty, empty], [71, 1, 110 /* F13 */, 'F13', 71 /* F13 */, 'F13', 124, 'VK_F13', empty, empty], [72, 1, 111 /* F14 */, 'F14', 72 /* F14 */, 'F14', 125, 'VK_F14', empty, empty], [73, 1, 112 /* F15 */, 'F15', 73 /* F15 */, 'F15', 126, 'VK_F15', empty, empty], [74, 1, 113 /* F16 */, 'F16', 74 /* F16 */, 'F16', 127, 'VK_F16', empty, empty], [75, 1, 114 /* F17 */, 'F17', 75 /* F17 */, 'F17', 128, 'VK_F17', empty, empty], [76, 1, 115 /* F18 */, 'F18', 76 /* F18 */, 'F18', 129, 'VK_F18', empty, empty], [77, 1, 116 /* F19 */, 'F19', 77 /* F19 */, 'F19', 130, 'VK_F19', empty, empty], [0, 1, 117 /* F20 */, 'F20', 0 /* Unknown */, empty, 0, 'VK_F20', empty, empty], [0, 1, 118 /* F21 */, 'F21', 0 /* Unknown */, empty, 0, 'VK_F21', empty, empty], [0, 1, 119 /* F22 */, 'F22', 0 /* Unknown */, empty, 0, 'VK_F22', empty, empty], [0, 1, 120 /* F23 */, 'F23', 0 /* Unknown */, empty, 0, 'VK_F23', empty, empty], [0, 1, 121 /* F24 */, 'F24', 0 /* Unknown */, empty, 0, 'VK_F24', empty, empty], [0, 1, 122 /* Open */, 'Open', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 123 /* Help */, 'Help', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 124 /* Select */, 'Select', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 125 /* Again */, 'Again', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 126 /* Undo */, 'Undo', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 127 /* Cut */, 'Cut', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 128 /* Copy */, 'Copy', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 129 /* Paste */, 'Paste', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 130 /* Find */, 'Find', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 131 /* AudioVolumeMute */, 'AudioVolumeMute', 112 /* AudioVolumeMute */, 'AudioVolumeMute', 173, 'VK_VOLUME_MUTE', empty, empty], [0, 1, 132 /* AudioVolumeUp */, 'AudioVolumeUp', 113 /* AudioVolumeUp */, 'AudioVolumeUp', 175, 'VK_VOLUME_UP', empty, empty], [0, 1, 133 /* AudioVolumeDown */, 'AudioVolumeDown', 114 /* AudioVolumeDown */, 'AudioVolumeDown', 174, 'VK_VOLUME_DOWN', empty, empty], [105, 1, 134 /* NumpadComma */, 'NumpadComma', 105 /* NUMPAD_SEPARATOR */, 'NumPad_Separator', 108, 'VK_SEPARATOR', empty, empty], [110, 0, 135 /* IntlRo */, 'IntlRo', 110 /* ABNT_C1 */, 'ABNT_C1', 193, 'VK_ABNT_C1', empty, empty], [0, 1, 136 /* KanaMode */, 'KanaMode', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 0, 137 /* IntlYen */, 'IntlYen', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 138 /* Convert */, 'Convert', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 139 /* NonConvert */, 'NonConvert', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 140 /* Lang1 */, 'Lang1', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 141 /* Lang2 */, 'Lang2', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 142 /* Lang3 */, 'Lang3', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 143 /* Lang4 */, 'Lang4', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 144 /* Lang5 */, 'Lang5', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 145 /* Abort */, 'Abort', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 146 /* Props */, 'Props', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 147 /* NumpadParenLeft */, 'NumpadParenLeft', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 148 /* NumpadParenRight */, 'NumpadParenRight', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 149 /* NumpadBackspace */, 'NumpadBackspace', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 150 /* NumpadMemoryStore */, 'NumpadMemoryStore', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 151 /* NumpadMemoryRecall */, 'NumpadMemoryRecall', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 152 /* NumpadMemoryClear */, 'NumpadMemoryClear', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 153 /* NumpadMemoryAdd */, 'NumpadMemoryAdd', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 154 /* NumpadMemorySubtract */, 'NumpadMemorySubtract', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 155 /* NumpadClear */, 'NumpadClear', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 156 /* NumpadClearEntry */, 'NumpadClearEntry', 0 /* Unknown */, empty, 0, empty, empty, empty], [5, 1, 0 /* None */, empty, 5 /* Ctrl */, 'Ctrl', 17, 'VK_CONTROL', empty, empty], [4, 1, 0 /* None */, empty, 4 /* Shift */, 'Shift', 16, 'VK_SHIFT', empty, empty], [6, 1, 0 /* None */, empty, 6 /* Alt */, 'Alt', 18, 'VK_MENU', empty, empty], [57, 1, 0 /* None */, empty, 57 /* Meta */, 'Meta', 0, 'VK_COMMAND', empty, empty], [5, 1, 157 /* ControlLeft */, 'ControlLeft', 5 /* Ctrl */, empty, 0, 'VK_LCONTROL', empty, empty], [4, 1, 158 /* ShiftLeft */, 'ShiftLeft', 4 /* Shift */, empty, 0, 'VK_LSHIFT', empty, empty], [6, 1, 159 /* AltLeft */, 'AltLeft', 6 /* Alt */, empty, 0, 'VK_LMENU', empty, empty], [57, 1, 160 /* MetaLeft */, 'MetaLeft', 57 /* Meta */, empty, 0, 'VK_LWIN', empty, empty], [5, 1, 161 /* ControlRight */, 'ControlRight', 5 /* Ctrl */, empty, 0, 'VK_RCONTROL', empty, empty], [4, 1, 162 /* ShiftRight */, 'ShiftRight', 4 /* Shift */, empty, 0, 'VK_RSHIFT', empty, empty], [6, 1, 163 /* AltRight */, 'AltRight', 6 /* Alt */, empty, 0, 'VK_RMENU', empty, empty], [57, 1, 164 /* MetaRight */, 'MetaRight', 57 /* Meta */, empty, 0, 'VK_RWIN', empty, empty], [0, 1, 165 /* BrightnessUp */, 'BrightnessUp', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 166 /* BrightnessDown */, 'BrightnessDown', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 167 /* MediaPlay */, 'MediaPlay', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 168 /* MediaRecord */, 'MediaRecord', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 169 /* MediaFastForward */, 'MediaFastForward', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 170 /* MediaRewind */, 'MediaRewind', 0 /* Unknown */, empty, 0, empty, empty, empty], [114, 1, 171 /* MediaTrackNext */, 'MediaTrackNext', 119 /* MediaTrackNext */, 'MediaTrackNext', 176, 'VK_MEDIA_NEXT_TRACK', empty, empty], [115, 1, 172 /* MediaTrackPrevious */, 'MediaTrackPrevious', 120 /* MediaTrackPrevious */, 'MediaTrackPrevious', 177, 'VK_MEDIA_PREV_TRACK', empty, empty], [116, 1, 173 /* MediaStop */, 'MediaStop', 121 /* MediaStop */, 'MediaStop', 178, 'VK_MEDIA_STOP', empty, empty], [0, 1, 174 /* Eject */, 'Eject', 0 /* Unknown */, empty, 0, empty, empty, empty], [117, 1, 175 /* MediaPlayPause */, 'MediaPlayPause', 122 /* MediaPlayPause */, 'MediaPlayPause', 179, 'VK_MEDIA_PLAY_PAUSE', empty, empty], [0, 1, 176 /* MediaSelect */, 'MediaSelect', 123 /* LaunchMediaPlayer */, 'LaunchMediaPlayer', 181, 'VK_MEDIA_LAUNCH_MEDIA_SELECT', empty, empty], [0, 1, 177 /* LaunchMail */, 'LaunchMail', 124 /* LaunchMail */, 'LaunchMail', 180, 'VK_MEDIA_LAUNCH_MAIL', empty, empty], [0, 1, 178 /* LaunchApp2 */, 'LaunchApp2', 125 /* LaunchApp2 */, 'LaunchApp2', 183, 'VK_MEDIA_LAUNCH_APP2', empty, empty], [0, 1, 179 /* LaunchApp1 */, 'LaunchApp1', 0 /* Unknown */, empty, 0, 'VK_MEDIA_LAUNCH_APP1', empty, empty], [0, 1, 180 /* SelectTask */, 'SelectTask', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 181 /* LaunchScreenSaver */, 'LaunchScreenSaver', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 182 /* BrowserSearch */, 'BrowserSearch', 115 /* BrowserSearch */, 'BrowserSearch', 170, 'VK_BROWSER_SEARCH', empty, empty], [0, 1, 183 /* BrowserHome */, 'BrowserHome', 116 /* BrowserHome */, 'BrowserHome', 172, 'VK_BROWSER_HOME', empty, empty], [112, 1, 184 /* BrowserBack */, 'BrowserBack', 117 /* BrowserBack */, 'BrowserBack', 166, 'VK_BROWSER_BACK', empty, empty], [113, 1, 185 /* BrowserForward */, 'BrowserForward', 118 /* BrowserForward */, 'BrowserForward', 167, 'VK_BROWSER_FORWARD', empty, empty], [0, 1, 186 /* BrowserStop */, 'BrowserStop', 0 /* Unknown */, empty, 0, 'VK_BROWSER_STOP', empty, empty], [0, 1, 187 /* BrowserRefresh */, 'BrowserRefresh', 0 /* Unknown */, empty, 0, 'VK_BROWSER_REFRESH', empty, empty], [0, 1, 188 /* BrowserFavorites */, 'BrowserFavorites', 0 /* Unknown */, empty, 0, 'VK_BROWSER_FAVORITES', empty, empty], [0, 1, 189 /* ZoomToggle */, 'ZoomToggle', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 190 /* MailReply */, 'MailReply', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 191 /* MailForward */, 'MailForward', 0 /* Unknown */, empty, 0, empty, empty, empty], [0, 1, 192 /* MailSend */, 'MailSend', 0 /* Unknown */, empty, 0, empty, empty, empty], // See https://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html // If an Input Method Editor is processing key input and the event is keydown, return 229. [109, 1, 0 /* None */, empty, 109 /* KEY_IN_COMPOSITION */, 'KeyInComposition', 229, empty, empty, empty], [111, 1, 0 /* None */, empty, 111 /* ABNT_C2 */, 'ABNT_C2', 194, 'VK_ABNT_C2', empty, empty], [91, 1, 0 /* None */, empty, 91 /* OEM_8 */, 'OEM_8', 223, 'VK_OEM_8', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_CLEAR', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_KANA', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_HANGUL', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_JUNJA', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_FINAL', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_HANJA', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_KANJI', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_CONVERT', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_NONCONVERT', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_ACCEPT', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_MODECHANGE', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_SELECT', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_PRINT', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_EXECUTE', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_SNAPSHOT', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_HELP', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_APPS', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_PROCESSKEY', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_PACKET', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_DBE_SBCSCHAR', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_DBE_DBCSCHAR', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_ATTN', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_CRSEL', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_EXSEL', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_EREOF', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_PLAY', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_ZOOM', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_NONAME', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_PA1', empty, empty], [0, 1, 0 /* None */, empty, 0 /* Unknown */, empty, 0, 'VK_OEM_CLEAR', empty, empty], ]; let seenKeyCode = []; let seenScanCode = []; for (const mapping of mappings) { const [_keyCodeOrd, immutable, scanCode, scanCodeStr, keyCode, keyCodeStr, eventKeyCode, vkey, usUserSettingsLabel, generalUserSettingsLabel] = mapping; if (!seenScanCode[scanCode]) { seenScanCode[scanCode] = true; scanCodeStrToInt[scanCodeStr] = scanCode; scanCodeLowerCaseStrToInt[scanCodeStr.toLowerCase()] = scanCode; if (immutable) { IMMUTABLE_CODE_TO_KEY_CODE[scanCode] = keyCode; } } if (!seenKeyCode[keyCode]) { seenKeyCode[keyCode] = true; if (!keyCodeStr) { throw new Error(`String representation missing for key code ${keyCode} around scan code ${scanCodeStr}`); } uiMap.define(keyCode, keyCodeStr); userSettingsUSMap.define(keyCode, usUserSettingsLabel || keyCodeStr); userSettingsGeneralMap.define(keyCode, generalUserSettingsLabel || usUserSettingsLabel || keyCodeStr); } if (eventKeyCode) { EVENT_KEY_CODE_MAP[eventKeyCode] = keyCode; } } })(); var KeyCodeUtils; (function (KeyCodeUtils) { function toString(keyCode) { return uiMap.keyCodeToStr(keyCode); } KeyCodeUtils.toString = toString; function fromString(key) { return uiMap.strToKeyCode(key); } KeyCodeUtils.fromString = fromString; function toUserSettingsUS(keyCode) { return userSettingsUSMap.keyCodeToStr(keyCode); } KeyCodeUtils.toUserSettingsUS = toUserSettingsUS; function toUserSettingsGeneral(keyCode) { return userSettingsGeneralMap.keyCodeToStr(keyCode); } KeyCodeUtils.toUserSettingsGeneral = toUserSettingsGeneral; function fromUserSettings(key) { return userSettingsUSMap.strToKeyCode(key) || userSettingsGeneralMap.strToKeyCode(key); } KeyCodeUtils.fromUserSettings = fromUserSettings; function toElectronAccelerator(keyCode) { if (keyCode >= 93 /* Numpad0 */ && keyCode <= 108 /* NumpadDivide */) { // [Electron Accelerators] Electron is able to parse numpad keys, but unfortunately it // renders them just as regular keys in menus. For example, num0 is rendered as "0", // numdiv is rendered as "/", numsub is rendered as "-". // // This can lead to incredible confusion, as it makes numpad based keybindings indistinguishable // from keybindings based on regular keys. // // We therefore need to fall back to custom rendering for numpad keys. return null; } switch (keyCode) { case 16 /* UpArrow */: return 'Up'; case 18 /* DownArrow */: return 'Down'; case 15 /* LeftArrow */: return 'Left'; case 17 /* RightArrow */: return 'Right'; } return uiMap.keyCodeToStr(keyCode); } KeyCodeUtils.toElectronAccelerator = toElectronAccelerator; })(KeyCodeUtils || (KeyCodeUtils = {})); function KeyChord(firstPart, secondPart) { const chordPart = ((secondPart & 0x0000FFFF) << 16) >>> 0; return (firstPart | chordPart) >>> 0; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ let safeProcess; // Native sandbox environment if (typeof globals.vscode !== 'undefined' && typeof globals.vscode.process !== 'undefined') { const sandboxProcess = globals.vscode.process; safeProcess = { get platform() { return sandboxProcess.platform; }, get arch() { return sandboxProcess.arch; }, get env() { return sandboxProcess.env; }, cwd() { return sandboxProcess.cwd(); } }; } // Native node.js environment else if (typeof process !== 'undefined') { safeProcess = { get platform() { return process.platform; }, get arch() { return process.arch; }, get env() { return process.env; }, cwd() { return process.env['VSCODE_CWD'] || process.cwd(); } }; } // Web environment else { safeProcess = { // Supported get platform() { return isWindows ? 'win32' : isMacintosh ? 'darwin' : 'linux'; }, get arch() { return undefined; /* arch is undefined in web */ }, // Unsupported get env() { return {}; }, cwd() { return '/'; } }; } /** * Provides safe access to the `cwd` property in node.js, sandboxed or web * environments. * * Note: in web, this property is hardcoded to be `/`. */ const cwd = safeProcess.cwd; /** * Provides safe access to the `env` property in node.js, sandboxed or web * environments. * * Note: in web, this property is hardcoded to be `{}`. */ const env = safeProcess.env; /** * Provides safe access to the `platform` property in node.js, sandboxed or web * environments. */ const platform = safeProcess.platform; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const CHAR_UPPERCASE_A = 65; /* A */ const CHAR_LOWERCASE_A = 97; /* a */ const CHAR_UPPERCASE_Z = 90; /* Z */ const CHAR_LOWERCASE_Z = 122; /* z */ const CHAR_DOT = 46; /* . */ const CHAR_FORWARD_SLASH = 47; /* / */ const CHAR_BACKWARD_SLASH = 92; /* \ */ const CHAR_COLON = 58; /* : */ const CHAR_QUESTION_MARK = 63; /* ? */ class ErrorInvalidArgType extends Error { constructor(name, expected, actual) { // determiner: 'must be' or 'must not be' let determiner; if (typeof expected === 'string' && expected.indexOf('not ') === 0) { determiner = 'must not be'; expected = expected.replace(/^not /, ''); } else { determiner = 'must be'; } const type = name.indexOf('.') !== -1 ? 'property' : 'argument'; let msg = `The "${name}" ${type} ${determiner} of type ${expected}`; msg += `. Received type ${typeof actual}`; super(msg); this.code = 'ERR_INVALID_ARG_TYPE'; } } function validateString(value, name) { if (typeof value !== 'string') { throw new ErrorInvalidArgType(name, 'string', value); } } function isPathSeparator$1(code) { return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH; } function isPosixPathSeparator(code) { return code === CHAR_FORWARD_SLASH; } function isWindowsDeviceRoot(code) { return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) || (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z); } // Resolves . and .. elements in a path with directory names function normalizeString(path, allowAboveRoot, separator, isPathSeparator) { let res = ''; let lastSegmentLength = 0; let lastSlash = -1; let dots = 0; let code = 0; for (let i = 0; i <= path.length; ++i) { if (i < path.length) { code = path.charCodeAt(i); } else if (isPathSeparator(code)) { break; } else { code = CHAR_FORWARD_SLASH; } if (isPathSeparator(code)) { if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) { if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) { if (res.length > 2) { const lastSlashIndex = res.lastIndexOf(separator); if (lastSlashIndex === -1) { res = ''; lastSegmentLength = 0; } else { res = res.slice(0, lastSlashIndex); lastSegmentLength = res.length - 1 - res.lastIndexOf(separator); } lastSlash = i; dots = 0; continue; } else if (res.length !== 0) { res = ''; lastSegmentLength = 0; lastSlash = i; dots = 0; continue; } } if (allowAboveRoot) { res += res.length > 0 ? `${separator}..` : '..'; lastSegmentLength = 2; } } else { if (res.length > 0) { res += `${separator}${path.slice(lastSlash + 1, i)}`; } else { res = path.slice(lastSlash + 1, i); } lastSegmentLength = i - lastSlash - 1; } lastSlash = i; dots = 0; } else if (code === CHAR_DOT && dots !== -1) { ++dots; } else { dots = -1; } } return res; } function _format(sep, pathObject) { if (pathObject === null || typeof pathObject !== 'object') { throw new ErrorInvalidArgType('pathObject', 'Object', pathObject); } const dir = pathObject.dir || pathObject.root; const base = pathObject.base || `${pathObject.name || ''}${pathObject.ext || ''}`; if (!dir) { return base; } return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`; } const win32 = { // path.resolve([from ...], to) resolve(...pathSegments) { let resolvedDevice = ''; let resolvedTail = ''; let resolvedAbsolute = false; for (let i = pathSegments.length - 1; i >= -1; i--) { let path; if (i >= 0) { path = pathSegments[i]; validateString(path, 'path'); // Skip empty entries if (path.length === 0) { continue; } } else if (resolvedDevice.length === 0) { path = cwd(); } else { // Windows has the concept of drive-specific current working // directories. If we've resolved a drive letter but not yet an // absolute path, get cwd for that drive, or the process cwd if // the drive cwd is not available. We're sure the device is not // a UNC path at this points, because UNC paths are always absolute. path = env[`=${resolvedDevice}`] || cwd(); // Verify that a cwd was found and that it actually points // to our drive. If not, default to the drive's root. if (path === undefined || (path.slice(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() && path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) { path = `${resolvedDevice}\\`; } } const len = path.length; let rootEnd = 0; let device = ''; let isAbsolute = false; const code = path.charCodeAt(0); // Try to match a root if (len === 1) { if (isPathSeparator$1(code)) { // `path` contains just a path separator rootEnd = 1; isAbsolute = true; } } else if (isPathSeparator$1(code)) { // Possible UNC root // If we started with a separator, we know we at least have an // absolute path of some kind (UNC or otherwise) isAbsolute = true; if (isPathSeparator$1(path.charCodeAt(1))) { // Matched double path separator at beginning let j = 2; let last = j; // Match 1 or more non-path separators while (j < len && !isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j < len && j !== last) { const firstPart = path.slice(last, j); // Matched! last = j; // Match 1 or more path separators while (j < len && isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j < len && j !== last) { // Matched! last = j; // Match 1 or more non-path separators while (j < len && !isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j === len || j !== last) { // We matched a UNC root device = `\\\\${firstPart}\\${path.slice(last, j)}`; rootEnd = j; } } } } else { rootEnd = 1; } } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) { // Possible device root device = path.slice(0, 2); rootEnd = 2; if (len > 2 && isPathSeparator$1(path.charCodeAt(2))) { // Treat separator following drive name as an absolute path // indicator isAbsolute = true; rootEnd = 3; } } if (device.length > 0) { if (resolvedDevice.length > 0) { if (device.toLowerCase() !== resolvedDevice.toLowerCase()) { // This path points to another device so it is not applicable continue; } } else { resolvedDevice = device; } } if (resolvedAbsolute) { if (resolvedDevice.length > 0) { break; } } else { resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`; resolvedAbsolute = isAbsolute; if (isAbsolute && resolvedDevice.length > 0) { break; } } } // At this point the path should be resolved to a full absolute path, // but handle relative paths to be safe (might happen when process.cwd() // fails) // Normalize the tail path resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparator$1); return resolvedAbsolute ? `${resolvedDevice}\\${resolvedTail}` : `${resolvedDevice}${resolvedTail}` || '.'; }, normalize(path) { validateString(path, 'path'); const len = path.length; if (len === 0) { return '.'; } let rootEnd = 0; let device; let isAbsolute = false; const code = path.charCodeAt(0); // Try to match a root if (len === 1) { // `path` contains just a single char, exit early to avoid // unnecessary work return isPosixPathSeparator(code) ? '\\' : path; } if (isPathSeparator$1(code)) { // Possible UNC root // If we started with a separator, we know we at least have an absolute // path of some kind (UNC or otherwise) isAbsolute = true; if (isPathSeparator$1(path.charCodeAt(1))) { // Matched double path separator at beginning let j = 2; let last = j; // Match 1 or more non-path separators while (j < len && !isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j < len && j !== last) { const firstPart = path.slice(last, j); // Matched! last = j; // Match 1 or more path separators while (j < len && isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j < len && j !== last) { // Matched! last = j; // Match 1 or more non-path separators while (j < len && !isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j === len) { // We matched a UNC root only // Return the normalized version of the UNC root since there // is nothing left to process return `\\\\${firstPart}\\${path.slice(last)}\\`; } if (j !== last) { // We matched a UNC root with leftovers device = `\\\\${firstPart}\\${path.slice(last, j)}`; rootEnd = j; } } } } else { rootEnd = 1; } } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) { // Possible device root device = path.slice(0, 2); rootEnd = 2; if (len > 2 && isPathSeparator$1(path.charCodeAt(2))) { // Treat separator following drive name as an absolute path // indicator isAbsolute = true; rootEnd = 3; } } let tail = rootEnd < len ? normalizeString(path.slice(rootEnd), !isAbsolute, '\\', isPathSeparator$1) : ''; if (tail.length === 0 && !isAbsolute) { tail = '.'; } if (tail.length > 0 && isPathSeparator$1(path.charCodeAt(len - 1))) { tail += '\\'; } if (device === undefined) { return isAbsolute ? `\\${tail}` : tail; } return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`; }, isAbsolute(path) { validateString(path, 'path'); const len = path.length; if (len === 0) { return false; } const code = path.charCodeAt(0); return isPathSeparator$1(code) || // Possible device root (len > 2 && isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON && isPathSeparator$1(path.charCodeAt(2))); }, join(...paths) { if (paths.length === 0) { return '.'; } let joined; let firstPart; for (let i = 0; i < paths.length; ++i) { const arg = paths[i]; validateString(arg, 'path'); if (arg.length > 0) { if (joined === undefined) { joined = firstPart = arg; } else { joined += `\\${arg}`; } } } if (joined === undefined) { return '.'; } // Make sure that the joined path doesn't start with two slashes, because // normalize() will mistake it for a UNC path then. // // This step is skipped when it is very clear that the user actually // intended to point at a UNC path. This is assumed when the first // non-empty string arguments starts with exactly two slashes followed by // at least one more non-slash character. // // Note that for normalize() to treat a path as a UNC path it needs to // have at least 2 components, so we don't filter for that here. // This means that the user can use join to construct UNC paths from // a server name and a share name; for example: // path.join('//server', 'share') -> '\\\\server\\share\\') let needsReplace = true; let slashCount = 0; if (typeof firstPart === 'string' && isPathSeparator$1(firstPart.charCodeAt(0))) { ++slashCount; const firstLen = firstPart.length; if (firstLen > 1 && isPathSeparator$1(firstPart.charCodeAt(1))) { ++slashCount; if (firstLen > 2) { if (isPathSeparator$1(firstPart.charCodeAt(2))) { ++slashCount; } else { // We matched a UNC path in the first part needsReplace = false; } } } } if (needsReplace) { // Find any more consecutive slashes we need to replace while (slashCount < joined.length && isPathSeparator$1(joined.charCodeAt(slashCount))) { slashCount++; } // Replace the slashes if needed if (slashCount >= 2) { joined = `\\${joined.slice(slashCount)}`; } } return win32.normalize(joined); }, // It will solve the relative path from `from` to `to`, for instance: // from = 'C:\\orandea\\test\\aaa' // to = 'C:\\orandea\\impl\\bbb' // The output of the function should be: '..\\..\\impl\\bbb' relative(from, to) { validateString(from, 'from'); validateString(to, 'to'); if (from === to) { return ''; } const fromOrig = win32.resolve(from); const toOrig = win32.resolve(to); if (fromOrig === toOrig) { return ''; } from = fromOrig.toLowerCase(); to = toOrig.toLowerCase(); if (from === to) { return ''; } // Trim any leading backslashes let fromStart = 0; while (fromStart < from.length && from.charCodeAt(fromStart) === CHAR_BACKWARD_SLASH) { fromStart++; } // Trim trailing backslashes (applicable to UNC paths only) let fromEnd = from.length; while (fromEnd - 1 > fromStart && from.charCodeAt(fromEnd - 1) === CHAR_BACKWARD_SLASH) { fromEnd--; } const fromLen = fromEnd - fromStart; // Trim any leading backslashes let toStart = 0; while (toStart < to.length && to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) { toStart++; } // Trim trailing backslashes (applicable to UNC paths only) let toEnd = to.length; while (toEnd - 1 > toStart && to.charCodeAt(toEnd - 1) === CHAR_BACKWARD_SLASH) { toEnd--; } const toLen = toEnd - toStart; // Compare paths to find the longest common path from root const length = fromLen < toLen ? fromLen : toLen; let lastCommonSep = -1; let i = 0; for (; i < length; i++) { const fromCode = from.charCodeAt(fromStart + i); if (fromCode !== to.charCodeAt(toStart + i)) { break; } else if (fromCode === CHAR_BACKWARD_SLASH) { lastCommonSep = i; } } // We found a mismatch before the first common path separator was seen, so // return the original `to`. if (i !== length) { if (lastCommonSep === -1) { return toOrig; } } else { if (toLen > length) { if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) { // We get here if `from` is the exact base path for `to`. // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz' return toOrig.slice(toStart + i + 1); } if (i === 2) { // We get here if `from` is the device root. // For example: from='C:\\'; to='C:\\foo' return toOrig.slice(toStart + i); } } if (fromLen > length) { if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) { // We get here if `to` is the exact base path for `from`. // For example: from='C:\\foo\\bar'; to='C:\\foo' lastCommonSep = i; } else if (i === 2) { // We get here if `to` is the device root. // For example: from='C:\\foo\\bar'; to='C:\\' lastCommonSep = 3; } } if (lastCommonSep === -1) { lastCommonSep = 0; } } let out = ''; // Generate the relative path based on the path difference between `to` and // `from` for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) { out += out.length === 0 ? '..' : '\\..'; } } toStart += lastCommonSep; // Lastly, append the rest of the destination (`to`) path that comes after // the common path parts if (out.length > 0) { return `${out}${toOrig.slice(toStart, toEnd)}`; } if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) { ++toStart; } return toOrig.slice(toStart, toEnd); }, toNamespacedPath(path) { // Note: this will *probably* throw somewhere. if (typeof path !== 'string') { return path; } if (path.length === 0) { return ''; } const resolvedPath = win32.resolve(path); if (resolvedPath.length <= 2) { return path; } if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) { // Possible UNC root if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) { const code = resolvedPath.charCodeAt(2); if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) { // Matched non-long UNC root, convert the path to a long UNC path return `\\\\?\\UNC\\${resolvedPath.slice(2)}`; } } } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) && resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) { // Matched device root, convert the path to a long UNC path return `\\\\?\\${resolvedPath}`; } return path; }, dirname(path) { validateString(path, 'path'); const len = path.length; if (len === 0) { return '.'; } let rootEnd = -1; let offset = 0; const code = path.charCodeAt(0); if (len === 1) { // `path` contains just a path separator, exit early to avoid // unnecessary work or a dot. return isPathSeparator$1(code) ? path : '.'; } // Try to match a root if (isPathSeparator$1(code)) { // Possible UNC root rootEnd = offset = 1; if (isPathSeparator$1(path.charCodeAt(1))) { // Matched double path separator at beginning let j = 2; let last = j; // Match 1 or more non-path separators while (j < len && !isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j < len && j !== last) { // Matched! last = j; // Match 1 or more path separators while (j < len && isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j < len && j !== last) { // Matched! last = j; // Match 1 or more non-path separators while (j < len && !isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j === len) { // We matched a UNC root only return path; } if (j !== last) { // We matched a UNC root with leftovers // Offset by 1 to include the separator after the UNC root to // treat it as a "normal root" on top of a (UNC) root rootEnd = offset = j + 1; } } } } // Possible device root } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) { rootEnd = len > 2 && isPathSeparator$1(path.charCodeAt(2)) ? 3 : 2; offset = rootEnd; } let end = -1; let matchedSlash = true; for (let i = len - 1; i >= offset; --i) { if (isPathSeparator$1(path.charCodeAt(i))) { if (!matchedSlash) { end = i; break; } } else { // We saw the first non-path separator matchedSlash = false; } } if (end === -1) { if (rootEnd === -1) { return '.'; } end = rootEnd; } return path.slice(0, end); }, basename(path, ext) { if (ext !== undefined) { validateString(ext, 'ext'); } validateString(path, 'path'); let start = 0; let end = -1; let matchedSlash = true; let i; // Check for a drive letter prefix so as not to mistake the following // path separator as an extra separator at the end of the path that can be // disregarded if (path.length >= 2 && isWindowsDeviceRoot(path.charCodeAt(0)) && path.charCodeAt(1) === CHAR_COLON) { start = 2; } if (ext !== undefined && ext.length > 0 && ext.length <= path.length) { if (ext === path) { return ''; } let extIdx = ext.length - 1; let firstNonSlashEnd = -1; for (i = path.length - 1; i >= start; --i) { const code = path.charCodeAt(i); if (isPathSeparator$1(code)) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { start = i + 1; break; } } else { if (firstNonSlashEnd === -1) { // We saw the first non-path separator, remember this index in case // we need it if the extension ends up not matching matchedSlash = false; firstNonSlashEnd = i + 1; } if (extIdx >= 0) { // Try to match the explicit extension if (code === ext.charCodeAt(extIdx)) { if (--extIdx === -1) { // We matched the extension, so mark this as the end of our path // component end = i; } } else { // Extension does not match, so our result is the entire path // component extIdx = -1; end = firstNonSlashEnd; } } } } if (start === end) { end = firstNonSlashEnd; } else if (end === -1) { end = path.length; } return path.slice(start, end); } for (i = path.length - 1; i >= start; --i) { if (isPathSeparator$1(path.charCodeAt(i))) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { start = i + 1; break; } } else if (end === -1) { // We saw the first non-path separator, mark this as the end of our // path component matchedSlash = false; end = i + 1; } } if (end === -1) { return ''; } return path.slice(start, end); }, extname(path) { validateString(path, 'path'); let start = 0; let startDot = -1; let startPart = 0; let end = -1; let matchedSlash = true; // Track the state of characters (if any) we see before our first dot and // after any path separator we find let preDotState = 0; // Check for a drive letter prefix so as not to mistake the following // path separator as an extra separator at the end of the path that can be // disregarded if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) { start = startPart = 2; } for (let i = path.length - 1; i >= start; --i) { const code = path.charCodeAt(i); if (isPathSeparator$1(code)) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { startPart = i + 1; break; } continue; } if (end === -1) { // We saw the first non-path separator, mark this as the end of our // extension matchedSlash = false; end = i + 1; } if (code === CHAR_DOT) { // If this is our first dot, mark it as the start of our extension if (startDot === -1) { startDot = i; } else if (preDotState !== 1) { preDotState = 1; } } else if (startDot !== -1) { // We saw a non-dot and non-path separator before our dot, so we should // have a good chance at having a non-empty extension preDotState = -1; } } if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot preDotState === 0 || // The (right-most) trimmed path component is exactly '..' (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) { return ''; } return path.slice(startDot, end); }, format: _format.bind(null, '\\'), parse(path) { validateString(path, 'path'); const ret = { root: '', dir: '', base: '', ext: '', name: '' }; if (path.length === 0) { return ret; } const len = path.length; let rootEnd = 0; let code = path.charCodeAt(0); if (len === 1) { if (isPathSeparator$1(code)) { // `path` contains just a path separator, exit early to avoid // unnecessary work ret.root = ret.dir = path; return ret; } ret.base = ret.name = path; return ret; } // Try to match a root if (isPathSeparator$1(code)) { // Possible UNC root rootEnd = 1; if (isPathSeparator$1(path.charCodeAt(1))) { // Matched double path separator at beginning let j = 2; let last = j; // Match 1 or more non-path separators while (j < len && !isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j < len && j !== last) { // Matched! last = j; // Match 1 or more path separators while (j < len && isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j < len && j !== last) { // Matched! last = j; // Match 1 or more non-path separators while (j < len && !isPathSeparator$1(path.charCodeAt(j))) { j++; } if (j === len) { // We matched a UNC root only rootEnd = j; } else if (j !== last) { // We matched a UNC root with leftovers rootEnd = j + 1; } } } } } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) { // Possible device root if (len <= 2) { // `path` contains just a drive root, exit early to avoid // unnecessary work ret.root = ret.dir = path; return ret; } rootEnd = 2; if (isPathSeparator$1(path.charCodeAt(2))) { if (len === 3) { // `path` contains just a drive root, exit early to avoid // unnecessary work ret.root = ret.dir = path; return ret; } rootEnd = 3; } } if (rootEnd > 0) { ret.root = path.slice(0, rootEnd); } let startDot = -1; let startPart = rootEnd; let end = -1; let matchedSlash = true; let i = path.length - 1; // Track the state of characters (if any) we see before our first dot and // after any path separator we find let preDotState = 0; // Get non-dir info for (; i >= rootEnd; --i) { code = path.charCodeAt(i); if (isPathSeparator$1(code)) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { startPart = i + 1; break; } continue; } if (end === -1) { // We saw the first non-path separator, mark this as the end of our // extension matchedSlash = false; end = i + 1; } if (code === CHAR_DOT) { // If this is our first dot, mark it as the start of our extension if (startDot === -1) { startDot = i; } else if (preDotState !== 1) { preDotState = 1; } } else if (startDot !== -1) { // We saw a non-dot and non-path separator before our dot, so we should // have a good chance at having a non-empty extension preDotState = -1; } } if (end !== -1) { if (startDot === -1 || // We saw a non-dot character immediately before the dot preDotState === 0 || // The (right-most) trimmed path component is exactly '..' (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) { ret.base = ret.name = path.slice(startPart, end); } else { ret.name = path.slice(startPart, startDot); ret.base = path.slice(startPart, end); ret.ext = path.slice(startDot, end); } } // If the directory is the root, use the entire root as the `dir` including // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the // trailing slash (`C:\abc\def` -> `C:\abc`). if (startPart > 0 && startPart !== rootEnd) { ret.dir = path.slice(0, startPart - 1); } else { ret.dir = ret.root; } return ret; }, sep: '\\', delimiter: ';', win32: null, posix: null }; const posix = { // path.resolve([from ...], to) resolve(...pathSegments) { let resolvedPath = ''; let resolvedAbsolute = false; for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) { const path = i >= 0 ? pathSegments[i] : cwd(); validateString(path, 'path'); // Skip empty entries if (path.length === 0) { continue; } resolvedPath = `${path}/${resolvedPath}`; resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH; } // At this point the path should be resolved to a full absolute path, but // handle relative paths to be safe (might happen when process.cwd() fails) // Normalize the path resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator); if (resolvedAbsolute) { return `/${resolvedPath}`; } return resolvedPath.length > 0 ? resolvedPath : '.'; }, normalize(path) { validateString(path, 'path'); if (path.length === 0) { return '.'; } const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH; const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH; // Normalize the path path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator); if (path.length === 0) { if (isAbsolute) { return '/'; } return trailingSeparator ? './' : '.'; } if (trailingSeparator) { path += '/'; } return isAbsolute ? `/${path}` : path; }, isAbsolute(path) { validateString(path, 'path'); return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH; }, join(...paths) { if (paths.length === 0) { return '.'; } let joined; for (let i = 0; i < paths.length; ++i) { const arg = paths[i]; validateString(arg, 'path'); if (arg.length > 0) { if (joined === undefined) { joined = arg; } else { joined += `/${arg}`; } } } if (joined === undefined) { return '.'; } return posix.normalize(joined); }, relative(from, to) { validateString(from, 'from'); validateString(to, 'to'); if (from === to) { return ''; } // Trim leading forward slashes. from = posix.resolve(from); to = posix.resolve(to); if (from === to) { return ''; } const fromStart = 1; const fromEnd = from.length; const fromLen = fromEnd - fromStart; const toStart = 1; const toLen = to.length - toStart; // Compare paths to find the longest common path from root const length = (fromLen < toLen ? fromLen : toLen); let lastCommonSep = -1; let i = 0; for (; i < length; i++) { const fromCode = from.charCodeAt(fromStart + i); if (fromCode !== to.charCodeAt(toStart + i)) { break; } else if (fromCode === CHAR_FORWARD_SLASH) { lastCommonSep = i; } } if (i === length) { if (toLen > length) { if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) { // We get here if `from` is the exact base path for `to`. // For example: from='/foo/bar'; to='/foo/bar/baz' return to.slice(toStart + i + 1); } if (i === 0) { // We get here if `from` is the root // For example: from='/'; to='/foo' return to.slice(toStart + i); } } else if (fromLen > length) { if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) { // We get here if `to` is the exact base path for `from`. // For example: from='/foo/bar/baz'; to='/foo/bar' lastCommonSep = i; } else if (i === 0) { // We get here if `to` is the root. // For example: from='/foo/bar'; to='/' lastCommonSep = 0; } } } let out = ''; // Generate the relative path based on the path difference between `to` // and `from`. for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) { out += out.length === 0 ? '..' : '/..'; } } // Lastly, append the rest of the destination (`to`) path that comes after // the common path parts. return `${out}${to.slice(toStart + lastCommonSep)}`; }, toNamespacedPath(path) { // Non-op on posix systems return path; }, dirname(path) { validateString(path, 'path'); if (path.length === 0) { return '.'; } const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH; let end = -1; let matchedSlash = true; for (let i = path.length - 1; i >= 1; --i) { if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) { if (!matchedSlash) { end = i; break; } } else { // We saw the first non-path separator matchedSlash = false; } } if (end === -1) { return hasRoot ? '/' : '.'; } if (hasRoot && end === 1) { return '//'; } return path.slice(0, end); }, basename(path, ext) { if (ext !== undefined) { validateString(ext, 'ext'); } validateString(path, 'path'); let start = 0; let end = -1; let matchedSlash = true; let i; if (ext !== undefined && ext.length > 0 && ext.length <= path.length) { if (ext === path) { return ''; } let extIdx = ext.length - 1; let firstNonSlashEnd = -1; for (i = path.length - 1; i >= 0; --i) { const code = path.charCodeAt(i); if (code === CHAR_FORWARD_SLASH) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { start = i + 1; break; } } else { if (firstNonSlashEnd === -1) { // We saw the first non-path separator, remember this index in case // we need it if the extension ends up not matching matchedSlash = false; firstNonSlashEnd = i + 1; } if (extIdx >= 0) { // Try to match the explicit extension if (code === ext.charCodeAt(extIdx)) { if (--extIdx === -1) { // We matched the extension, so mark this as the end of our path // component end = i; } } else { // Extension does not match, so our result is the entire path // component extIdx = -1; end = firstNonSlashEnd; } } } } if (start === end) { end = firstNonSlashEnd; } else if (end === -1) { end = path.length; } return path.slice(start, end); } for (i = path.length - 1; i >= 0; --i) { if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { start = i + 1; break; } } else if (end === -1) { // We saw the first non-path separator, mark this as the end of our // path component matchedSlash = false; end = i + 1; } } if (end === -1) { return ''; } return path.slice(start, end); }, extname(path) { validateString(path, 'path'); let startDot = -1; let startPart = 0; let end = -1; let matchedSlash = true; // Track the state of characters (if any) we see before our first dot and // after any path separator we find let preDotState = 0; for (let i = path.length - 1; i >= 0; --i) { const code = path.charCodeAt(i); if (code === CHAR_FORWARD_SLASH) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { startPart = i + 1; break; } continue; } if (end === -1) { // We saw the first non-path separator, mark this as the end of our // extension matchedSlash = false; end = i + 1; } if (code === CHAR_DOT) { // If this is our first dot, mark it as the start of our extension if (startDot === -1) { startDot = i; } else if (preDotState !== 1) { preDotState = 1; } } else if (startDot !== -1) { // We saw a non-dot and non-path separator before our dot, so we should // have a good chance at having a non-empty extension preDotState = -1; } } if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot preDotState === 0 || // The (right-most) trimmed path component is exactly '..' (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) { return ''; } return path.slice(startDot, end); }, format: _format.bind(null, '/'), parse(path) { validateString(path, 'path'); const ret = { root: '', dir: '', base: '', ext: '', name: '' }; if (path.length === 0) { return ret; } const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH; let start; if (isAbsolute) { ret.root = '/'; start = 1; } else { start = 0; } let startDot = -1; let startPart = 0; let end = -1; let matchedSlash = true; let i = path.length - 1; // Track the state of characters (if any) we see before our first dot and // after any path separator we find let preDotState = 0; // Get non-dir info for (; i >= start; --i) { const code = path.charCodeAt(i); if (code === CHAR_FORWARD_SLASH) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { startPart = i + 1; break; } continue; } if (end === -1) { // We saw the first non-path separator, mark this as the end of our // extension matchedSlash = false; end = i + 1; } if (code === CHAR_DOT) { // If this is our first dot, mark it as the start of our extension if (startDot === -1) { startDot = i; } else if (preDotState !== 1) { preDotState = 1; } } else if (startDot !== -1) { // We saw a non-dot and non-path separator before our dot, so we should // have a good chance at having a non-empty extension preDotState = -1; } } if (end !== -1) { const start = startPart === 0 && isAbsolute ? 1 : startPart; if (startDot === -1 || // We saw a non-dot character immediately before the dot preDotState === 0 || // The (right-most) trimmed path component is exactly '..' (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) { ret.base = ret.name = path.slice(start, end); } else { ret.name = path.slice(start, startDot); ret.base = path.slice(start, end); ret.ext = path.slice(startDot, end); } } if (startPart > 0) { ret.dir = path.slice(0, startPart - 1); } else if (isAbsolute) { ret.dir = '/'; } return ret; }, sep: '/', delimiter: ':', win32: null, posix: null }; posix.win32 = win32.win32 = win32; posix.posix = win32.posix = posix; const normalize = (platform === 'win32' ? win32.normalize : posix.normalize); const resolve = (platform === 'win32' ? win32.resolve : posix.resolve); const relative = (platform === 'win32' ? win32.relative : posix.relative); const dirname$1 = (platform === 'win32' ? win32.dirname : posix.dirname); const basename$1 = (platform === 'win32' ? win32.basename : posix.basename); const extname$1 = (platform === 'win32' ? win32.extname : posix.extname); const sep = (platform === 'win32' ? win32.sep : posix.sep); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const _schemePattern = /^\w[\w\d+.-]*$/; const _singleSlashStart = /^\//; const _doubleSlashStart = /^\/\//; function _validateUri(ret, _strict) { // scheme, must be set if (!ret.scheme && _strict) { throw new Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`); } // scheme, https://tools.ietf.org/html/rfc3986#section-3.1 // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) if (ret.scheme && !_schemePattern.test(ret.scheme)) { throw new Error('[UriError]: Scheme contains illegal characters.'); } // path, http://tools.ietf.org/html/rfc3986#section-3.3 // If a URI contains an authority component, then the path component // must either be empty or begin with a slash ("/") character. If a URI // does not contain an authority component, then the path cannot begin // with two slash characters ("//"). if (ret.path) { if (ret.authority) { if (!_singleSlashStart.test(ret.path)) { throw new Error('[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character'); } } else { if (_doubleSlashStart.test(ret.path)) { throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")'); } } } } // for a while we allowed uris *without* schemes and this is the migration // for them, e.g. an uri without scheme and without strict-mode warns and falls // back to the file-scheme. that should cause the least carnage and still be a // clear warning function _schemeFix(scheme, _strict) { if (!scheme && !_strict) { return 'file'; } return scheme; } // implements a bit of https://tools.ietf.org/html/rfc3986#section-5 function _referenceResolution(scheme, path) { // the slash-character is our 'default base' as we don't // support constructing URIs relative to other URIs. This // also means that we alter and potentially break paths. // see https://tools.ietf.org/html/rfc3986#section-5.1.4 switch (scheme) { case 'https': case 'http': case 'file': if (!path) { path = _slash; } else if (path[0] !== _slash) { path = _slash + path; } break; } return path; } const _empty = ''; const _slash = '/'; const _regexp = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/; /** * Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986. * This class is a simple parser which creates the basic component parts * (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation * and encoding. * * ```txt * foo://example.com:8042/over/there?name=ferret#nose * \_/ \______________/\_________/ \_________/ \__/ * | | | | | * scheme authority path query fragment * | _____________________|__ * / \ / \ * urn:example:animal:ferret:nose * ``` */ class URI { /** * @internal */ constructor(schemeOrData, authority, path, query, fragment, _strict = false) { if (typeof schemeOrData === 'object') { this.scheme = schemeOrData.scheme || _empty; this.authority = schemeOrData.authority || _empty; this.path = schemeOrData.path || _empty; this.query = schemeOrData.query || _empty; this.fragment = schemeOrData.fragment || _empty; // no validation because it's this URI // that creates uri components. // _validateUri(this); } else { this.scheme = _schemeFix(schemeOrData, _strict); this.authority = authority || _empty; this.path = _referenceResolution(this.scheme, path || _empty); this.query = query || _empty; this.fragment = fragment || _empty; _validateUri(this, _strict); } } static isUri(thing) { if (thing instanceof URI) { return true; } if (!thing) { return false; } return typeof thing.authority === 'string' && typeof thing.fragment === 'string' && typeof thing.path === 'string' && typeof thing.query === 'string' && typeof thing.scheme === 'string' && typeof thing.fsPath === 'string' && typeof thing.with === 'function' && typeof thing.toString === 'function'; } // ---- filesystem path ----------------------- /** * Returns a string representing the corresponding file system path of this URI. * Will handle UNC paths, normalizes windows drive letters to lower-case, and uses the * platform specific path separator. * * * Will *not* validate the path for invalid characters and semantics. * * Will *not* look at the scheme of this URI. * * The result shall *not* be used for display purposes but for accessing a file on disk. * * * The *difference* to `URI#path` is the use of the platform specific separator and the handling * of UNC paths. See the below sample of a file-uri with an authority (UNC path). * * ```ts const u = URI.parse('file://server/c$/folder/file.txt') u.authority === 'server' u.path === '/shares/c$/file.txt' u.fsPath === '\\server\c$\folder\file.txt' ``` * * Using `URI#path` to read a file (using fs-apis) would not be enough because parts of the path, * namely the server name, would be missing. Therefore `URI#fsPath` exists - it's sugar to ease working * with URIs that represent files on disk (`file` scheme). */ get fsPath() { // if (this.scheme !== 'file') { // console.warn(`[UriError] calling fsPath with scheme ${this.scheme}`); // } return uriToFsPath(this, false); } // ---- modify to new ------------------------- with(change) { if (!change) { return this; } let { scheme, authority, path, query, fragment } = change; if (scheme === undefined) { scheme = this.scheme; } else if (scheme === null) { scheme = _empty; } if (authority === undefined) { authority = this.authority; } else if (authority === null) { authority = _empty; } if (path === undefined) { path = this.path; } else if (path === null) { path = _empty; } if (query === undefined) { query = this.query; } else if (query === null) { query = _empty; } if (fragment === undefined) { fragment = this.fragment; } else if (fragment === null) { fragment = _empty; } if (scheme === this.scheme && authority === this.authority && path === this.path && query === this.query && fragment === this.fragment) { return this; } return new Uri$1(scheme, authority, path, query, fragment); } // ---- parse & validate ------------------------ /** * Creates a new URI from a string, e.g. `http://www.example.com/some/path`, * `file:///usr/home`, or `scheme:with/path`. * * @param value A string which represents an URI (see `URI#toString`). */ static parse(value, _strict = false) { const match = _regexp.exec(value); if (!match) { return new Uri$1(_empty, _empty, _empty, _empty, _empty); } return new Uri$1(match[2] || _empty, percentDecode(match[4] || _empty), percentDecode(match[5] || _empty), percentDecode(match[7] || _empty), percentDecode(match[9] || _empty), _strict); } /** * Creates a new URI from a file system path, e.g. `c:\my\files`, * `/usr/home`, or `\\server\share\some\path`. * * The *difference* between `URI#parse` and `URI#file` is that the latter treats the argument * as path, not as stringified-uri. E.g. `URI.file(path)` is **not the same as** * `URI.parse('file://' + path)` because the path might contain characters that are * interpreted (# and ?). See the following sample: * ```ts const good = URI.file('/coding/c#/project1'); good.scheme === 'file'; good.path === '/coding/c#/project1'; good.fragment === ''; const bad = URI.parse('file://' + '/coding/c#/project1'); bad.scheme === 'file'; bad.path === '/coding/c'; // path is now broken bad.fragment === '/project1'; ``` * * @param path A file system path (see `URI#fsPath`) */ static file(path) { let authority = _empty; // normalize to fwd-slashes on windows, // on other systems bwd-slashes are valid // filename character, eg /f\oo/ba\r.txt if (isWindows) { path = path.replace(/\\/g, _slash); } // check for authority as used in UNC shares // or use the path as given if (path[0] === _slash && path[1] === _slash) { const idx = path.indexOf(_slash, 2); if (idx === -1) { authority = path.substring(2); path = _slash; } else { authority = path.substring(2, idx); path = path.substring(idx) || _slash; } } return new Uri$1('file', authority, path, _empty, _empty); } static from(components) { const result = new Uri$1(components.scheme, components.authority, components.path, components.query, components.fragment); _validateUri(result, true); return result; } /** * Join a URI path with path fragments and normalizes the resulting path. * * @param uri The input URI. * @param pathFragment The path fragment to add to the URI path. * @returns The resulting URI. */ static joinPath(uri, ...pathFragment) { if (!uri.path) { throw new Error(`[UriError]: cannot call joinPath on URI without path`); } let newPath; if (isWindows && uri.scheme === 'file') { newPath = URI.file(win32.join(uriToFsPath(uri, true), ...pathFragment)).path; } else { newPath = posix.join(uri.path, ...pathFragment); } return uri.with({ path: newPath }); } // ---- printing/externalize --------------------------- /** * Creates a string representation for this URI. It's guaranteed that calling * `URI.parse` with the result of this function creates an URI which is equal * to this URI. * * * The result shall *not* be used for display purposes but for externalization or transport. * * The result will be encoded using the percentage encoding and encoding happens mostly * ignore the scheme-specific encoding rules. * * @param skipEncoding Do not encode the result, default is `false` */ toString(skipEncoding = false) { return _asFormatted(this, skipEncoding); } toJSON() { return this; } static revive(data) { if (!data) { return data; } else if (data instanceof URI) { return data; } else { const result = new Uri$1(data); result._formatted = data.external; result._fsPath = data._sep === _pathSepMarker ? data.fsPath : null; return result; } } } const _pathSepMarker = isWindows ? 1 : undefined; // This class exists so that URI is compatible with vscode.Uri (API). class Uri$1 extends URI { constructor() { super(...arguments); this._formatted = null; this._fsPath = null; } get fsPath() { if (!this._fsPath) { this._fsPath = uriToFsPath(this, false); } return this._fsPath; } toString(skipEncoding = false) { if (!skipEncoding) { if (!this._formatted) { this._formatted = _asFormatted(this, false); } return this._formatted; } else { // we don't cache that return _asFormatted(this, true); } } toJSON() { const res = { $mid: 1 /* Uri */ }; // cached state if (this._fsPath) { res.fsPath = this._fsPath; res._sep = _pathSepMarker; } if (this._formatted) { res.external = this._formatted; } // uri components if (this.path) { res.path = this.path; } if (this.scheme) { res.scheme = this.scheme; } if (this.authority) { res.authority = this.authority; } if (this.query) { res.query = this.query; } if (this.fragment) { res.fragment = this.fragment; } return res; } } // reserved characters: https://tools.ietf.org/html/rfc3986#section-2.2 const encodeTable = { [58 /* Colon */]: '%3A', [47 /* Slash */]: '%2F', [63 /* QuestionMark */]: '%3F', [35 /* Hash */]: '%23', [91 /* OpenSquareBracket */]: '%5B', [93 /* CloseSquareBracket */]: '%5D', [64 /* AtSign */]: '%40', [33 /* ExclamationMark */]: '%21', [36 /* DollarSign */]: '%24', [38 /* Ampersand */]: '%26', [39 /* SingleQuote */]: '%27', [40 /* OpenParen */]: '%28', [41 /* CloseParen */]: '%29', [42 /* Asterisk */]: '%2A', [43 /* Plus */]: '%2B', [44 /* Comma */]: '%2C', [59 /* Semicolon */]: '%3B', [61 /* Equals */]: '%3D', [32 /* Space */]: '%20', }; function encodeURIComponentFast(uriComponent, allowSlash) { let res = undefined; let nativeEncodePos = -1; for (let pos = 0; pos < uriComponent.length; pos++) { const code = uriComponent.charCodeAt(pos); // unreserved characters: https://tools.ietf.org/html/rfc3986#section-2.3 if ((code >= 97 /* a */ && code <= 122 /* z */) || (code >= 65 /* A */ && code <= 90 /* Z */) || (code >= 48 /* Digit0 */ && code <= 57 /* Digit9 */) || code === 45 /* Dash */ || code === 46 /* Period */ || code === 95 /* Underline */ || code === 126 /* Tilde */ || (allowSlash && code === 47 /* Slash */)) { // check if we are delaying native encode if (nativeEncodePos !== -1) { res += encodeURIComponent(uriComponent.substring(nativeEncodePos, pos)); nativeEncodePos = -1; } // check if we write into a new string (by default we try to return the param) if (res !== undefined) { res += uriComponent.charAt(pos); } } else { // encoding needed, we need to allocate a new string if (res === undefined) { res = uriComponent.substr(0, pos); } // check with default table first const escaped = encodeTable[code]; if (escaped !== undefined) { // check if we are delaying native encode if (nativeEncodePos !== -1) { res += encodeURIComponent(uriComponent.substring(nativeEncodePos, pos)); nativeEncodePos = -1; } // append escaped variant to result res += escaped; } else if (nativeEncodePos === -1) { // use native encode only when needed nativeEncodePos = pos; } } } if (nativeEncodePos !== -1) { res += encodeURIComponent(uriComponent.substring(nativeEncodePos)); } return res !== undefined ? res : uriComponent; } function encodeURIComponentMinimal(path) { let res = undefined; for (let pos = 0; pos < path.length; pos++) { const code = path.charCodeAt(pos); if (code === 35 /* Hash */ || code === 63 /* QuestionMark */) { if (res === undefined) { res = path.substr(0, pos); } res += encodeTable[code]; } else { if (res !== undefined) { res += path[pos]; } } } return res !== undefined ? res : path; } /** * Compute `fsPath` for the given uri */ function uriToFsPath(uri, keepDriveLetterCasing) { let value; if (uri.authority && uri.path.length > 1 && uri.scheme === 'file') { // unc path: file://shares/c$/far/boo value = `//${uri.authority}${uri.path}`; } else if (uri.path.charCodeAt(0) === 47 /* Slash */ && (uri.path.charCodeAt(1) >= 65 /* A */ && uri.path.charCodeAt(1) <= 90 /* Z */ || uri.path.charCodeAt(1) >= 97 /* a */ && uri.path.charCodeAt(1) <= 122 /* z */) && uri.path.charCodeAt(2) === 58 /* Colon */) { if (!keepDriveLetterCasing) { // windows drive letter: file:///c:/far/boo value = uri.path[1].toLowerCase() + uri.path.substr(2); } else { value = uri.path.substr(1); } } else { // other path value = uri.path; } if (isWindows) { value = value.replace(/\//g, '\\'); } return value; } /** * Create the external version of a uri */ function _asFormatted(uri, skipEncoding) { const encoder = !skipEncoding ? encodeURIComponentFast : encodeURIComponentMinimal; let res = ''; let { scheme, authority, path, query, fragment } = uri; if (scheme) { res += scheme; res += ':'; } if (authority || scheme === 'file') { res += _slash; res += _slash; } if (authority) { let idx = authority.indexOf('@'); if (idx !== -1) { // @ const userinfo = authority.substr(0, idx); authority = authority.substr(idx + 1); idx = userinfo.indexOf(':'); if (idx === -1) { res += encoder(userinfo, false); } else { // :@ res += encoder(userinfo.substr(0, idx), false); res += ':'; res += encoder(userinfo.substr(idx + 1), false); } res += '@'; } authority = authority.toLowerCase(); idx = authority.indexOf(':'); if (idx === -1) { res += encoder(authority, false); } else { // : res += encoder(authority.substr(0, idx), false); res += authority.substr(idx); } } if (path) { // lower-case windows drive letters in /C:/fff or C:/fff if (path.length >= 3 && path.charCodeAt(0) === 47 /* Slash */ && path.charCodeAt(2) === 58 /* Colon */) { const code = path.charCodeAt(1); if (code >= 65 /* A */ && code <= 90 /* Z */) { path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3 } } else if (path.length >= 2 && path.charCodeAt(1) === 58 /* Colon */) { const code = path.charCodeAt(0); if (code >= 65 /* A */ && code <= 90 /* Z */) { path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3 } } // encode the rest of the path res += encoder(path, true); } if (query) { res += '?'; res += encoder(query, false); } if (fragment) { res += '#'; res += !skipEncoding ? encodeURIComponentFast(fragment, false) : fragment; } return res; } // --- decode function decodeURIComponentGraceful(str) { try { return decodeURIComponent(str); } catch (_a) { if (str.length > 3) { return str.substr(0, 3) + decodeURIComponentGraceful(str.substr(3)); } else { return str; } } } const _rEncodedAsHex = /(%[0-9A-Za-z][0-9A-Za-z])+/g; function percentDecode(str) { if (!str.match(_rEncodedAsHex)) { return str; } return str.replace(_rEncodedAsHex, (match) => decodeURIComponentGraceful(match)); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * A position in the editor. */ class Position$4 { constructor(lineNumber, column) { this.lineNumber = lineNumber; this.column = column; } /** * Create a new position from this position. * * @param newLineNumber new line number * @param newColumn new column */ with(newLineNumber = this.lineNumber, newColumn = this.column) { if (newLineNumber === this.lineNumber && newColumn === this.column) { return this; } else { return new Position$4(newLineNumber, newColumn); } } /** * Derive a new position from this position. * * @param deltaLineNumber line number delta * @param deltaColumn column delta */ delta(deltaLineNumber = 0, deltaColumn = 0) { return this.with(this.lineNumber + deltaLineNumber, this.column + deltaColumn); } /** * Test if this position equals other position */ equals(other) { return Position$4.equals(this, other); } /** * Test if position `a` equals position `b` */ static equals(a, b) { if (!a && !b) { return true; } return (!!a && !!b && a.lineNumber === b.lineNumber && a.column === b.column); } /** * Test if this position is before other position. * If the two positions are equal, the result will be false. */ isBefore(other) { return Position$4.isBefore(this, other); } /** * Test if position `a` is before position `b`. * If the two positions are equal, the result will be false. */ static isBefore(a, b) { if (a.lineNumber < b.lineNumber) { return true; } if (b.lineNumber < a.lineNumber) { return false; } return a.column < b.column; } /** * Test if this position is before other position. * If the two positions are equal, the result will be true. */ isBeforeOrEqual(other) { return Position$4.isBeforeOrEqual(this, other); } /** * Test if position `a` is before position `b`. * If the two positions are equal, the result will be true. */ static isBeforeOrEqual(a, b) { if (a.lineNumber < b.lineNumber) { return true; } if (b.lineNumber < a.lineNumber) { return false; } return a.column <= b.column; } /** * A function that compares positions, useful for sorting */ static compare(a, b) { const aLineNumber = a.lineNumber | 0; const bLineNumber = b.lineNumber | 0; if (aLineNumber === bLineNumber) { const aColumn = a.column | 0; const bColumn = b.column | 0; return aColumn - bColumn; } return aLineNumber - bLineNumber; } /** * Clone this position. */ clone() { return new Position$4(this.lineNumber, this.column); } /** * Convert to a human-readable representation. */ toString() { return '(' + this.lineNumber + ',' + this.column + ')'; } // --- /** * Create a `Position` from an `IPosition`. */ static lift(pos) { return new Position$4(pos.lineNumber, pos.column); } /** * Test if `obj` is an `IPosition`. */ static isIPosition(obj) { return (obj && (typeof obj.lineNumber === 'number') && (typeof obj.column === 'number')); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * A range in the editor. (startLineNumber,startColumn) is <= (endLineNumber,endColumn) */ class Range$5 { constructor(startLineNumber, startColumn, endLineNumber, endColumn) { if ((startLineNumber > endLineNumber) || (startLineNumber === endLineNumber && startColumn > endColumn)) { this.startLineNumber = endLineNumber; this.startColumn = endColumn; this.endLineNumber = startLineNumber; this.endColumn = startColumn; } else { this.startLineNumber = startLineNumber; this.startColumn = startColumn; this.endLineNumber = endLineNumber; this.endColumn = endColumn; } } /** * Test if this range is empty. */ isEmpty() { return Range$5.isEmpty(this); } /** * Test if `range` is empty. */ static isEmpty(range) { return (range.startLineNumber === range.endLineNumber && range.startColumn === range.endColumn); } /** * Test if position is in this range. If the position is at the edges, will return true. */ containsPosition(position) { return Range$5.containsPosition(this, position); } /** * Test if `position` is in `range`. If the position is at the edges, will return true. */ static containsPosition(range, position) { if (position.lineNumber < range.startLineNumber || position.lineNumber > range.endLineNumber) { return false; } if (position.lineNumber === range.startLineNumber && position.column < range.startColumn) { return false; } if (position.lineNumber === range.endLineNumber && position.column > range.endColumn) { return false; } return true; } /** * Test if `position` is in `range`. If the position is at the edges, will return false. * @internal */ static strictContainsPosition(range, position) { if (position.lineNumber < range.startLineNumber || position.lineNumber > range.endLineNumber) { return false; } if (position.lineNumber === range.startLineNumber && position.column <= range.startColumn) { return false; } if (position.lineNumber === range.endLineNumber && position.column >= range.endColumn) { return false; } return true; } /** * Test if range is in this range. If the range is equal to this range, will return true. */ containsRange(range) { return Range$5.containsRange(this, range); } /** * Test if `otherRange` is in `range`. If the ranges are equal, will return true. */ static containsRange(range, otherRange) { if (otherRange.startLineNumber < range.startLineNumber || otherRange.endLineNumber < range.startLineNumber) { return false; } if (otherRange.startLineNumber > range.endLineNumber || otherRange.endLineNumber > range.endLineNumber) { return false; } if (otherRange.startLineNumber === range.startLineNumber && otherRange.startColumn < range.startColumn) { return false; } if (otherRange.endLineNumber === range.endLineNumber && otherRange.endColumn > range.endColumn) { return false; } return true; } /** * Test if `range` is strictly in this range. `range` must start after and end before this range for the result to be true. */ strictContainsRange(range) { return Range$5.strictContainsRange(this, range); } /** * Test if `otherRange` is strictly in `range` (must start after, and end before). If the ranges are equal, will return false. */ static strictContainsRange(range, otherRange) { if (otherRange.startLineNumber < range.startLineNumber || otherRange.endLineNumber < range.startLineNumber) { return false; } if (otherRange.startLineNumber > range.endLineNumber || otherRange.endLineNumber > range.endLineNumber) { return false; } if (otherRange.startLineNumber === range.startLineNumber && otherRange.startColumn <= range.startColumn) { return false; } if (otherRange.endLineNumber === range.endLineNumber && otherRange.endColumn >= range.endColumn) { return false; } return true; } /** * A reunion of the two ranges. * The smallest position will be used as the start point, and the largest one as the end point. */ plusRange(range) { return Range$5.plusRange(this, range); } /** * A reunion of the two ranges. * The smallest position will be used as the start point, and the largest one as the end point. */ static plusRange(a, b) { let startLineNumber; let startColumn; let endLineNumber; let endColumn; if (b.startLineNumber < a.startLineNumber) { startLineNumber = b.startLineNumber; startColumn = b.startColumn; } else if (b.startLineNumber === a.startLineNumber) { startLineNumber = b.startLineNumber; startColumn = Math.min(b.startColumn, a.startColumn); } else { startLineNumber = a.startLineNumber; startColumn = a.startColumn; } if (b.endLineNumber > a.endLineNumber) { endLineNumber = b.endLineNumber; endColumn = b.endColumn; } else if (b.endLineNumber === a.endLineNumber) { endLineNumber = b.endLineNumber; endColumn = Math.max(b.endColumn, a.endColumn); } else { endLineNumber = a.endLineNumber; endColumn = a.endColumn; } return new Range$5(startLineNumber, startColumn, endLineNumber, endColumn); } /** * A intersection of the two ranges. */ intersectRanges(range) { return Range$5.intersectRanges(this, range); } /** * A intersection of the two ranges. */ static intersectRanges(a, b) { let resultStartLineNumber = a.startLineNumber; let resultStartColumn = a.startColumn; let resultEndLineNumber = a.endLineNumber; let resultEndColumn = a.endColumn; let otherStartLineNumber = b.startLineNumber; let otherStartColumn = b.startColumn; let otherEndLineNumber = b.endLineNumber; let otherEndColumn = b.endColumn; if (resultStartLineNumber < otherStartLineNumber) { resultStartLineNumber = otherStartLineNumber; resultStartColumn = otherStartColumn; } else if (resultStartLineNumber === otherStartLineNumber) { resultStartColumn = Math.max(resultStartColumn, otherStartColumn); } if (resultEndLineNumber > otherEndLineNumber) { resultEndLineNumber = otherEndLineNumber; resultEndColumn = otherEndColumn; } else if (resultEndLineNumber === otherEndLineNumber) { resultEndColumn = Math.min(resultEndColumn, otherEndColumn); } // Check if selection is now empty if (resultStartLineNumber > resultEndLineNumber) { return null; } if (resultStartLineNumber === resultEndLineNumber && resultStartColumn > resultEndColumn) { return null; } return new Range$5(resultStartLineNumber, resultStartColumn, resultEndLineNumber, resultEndColumn); } /** * Test if this range equals other. */ equalsRange(other) { return Range$5.equalsRange(this, other); } /** * Test if range `a` equals `b`. */ static equalsRange(a, b) { return (!!a && !!b && a.startLineNumber === b.startLineNumber && a.startColumn === b.startColumn && a.endLineNumber === b.endLineNumber && a.endColumn === b.endColumn); } /** * Return the end position (which will be after or equal to the start position) */ getEndPosition() { return Range$5.getEndPosition(this); } /** * Return the end position (which will be after or equal to the start position) */ static getEndPosition(range) { return new Position$4(range.endLineNumber, range.endColumn); } /** * Return the start position (which will be before or equal to the end position) */ getStartPosition() { return Range$5.getStartPosition(this); } /** * Return the start position (which will be before or equal to the end position) */ static getStartPosition(range) { return new Position$4(range.startLineNumber, range.startColumn); } /** * Transform to a user presentable string representation. */ toString() { return '[' + this.startLineNumber + ',' + this.startColumn + ' -> ' + this.endLineNumber + ',' + this.endColumn + ']'; } /** * Create a new range using this range's start position, and using endLineNumber and endColumn as the end position. */ setEndPosition(endLineNumber, endColumn) { return new Range$5(this.startLineNumber, this.startColumn, endLineNumber, endColumn); } /** * Create a new range using this range's end position, and using startLineNumber and startColumn as the start position. */ setStartPosition(startLineNumber, startColumn) { return new Range$5(startLineNumber, startColumn, this.endLineNumber, this.endColumn); } /** * Create a new empty range using this range's start position. */ collapseToStart() { return Range$5.collapseToStart(this); } /** * Create a new empty range using this range's start position. */ static collapseToStart(range) { return new Range$5(range.startLineNumber, range.startColumn, range.startLineNumber, range.startColumn); } // --- static fromPositions(start, end = start) { return new Range$5(start.lineNumber, start.column, end.lineNumber, end.column); } static lift(range) { if (!range) { return null; } return new Range$5(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn); } /** * Test if `obj` is an `IRange`. */ static isIRange(obj) { return (obj && (typeof obj.startLineNumber === 'number') && (typeof obj.startColumn === 'number') && (typeof obj.endLineNumber === 'number') && (typeof obj.endColumn === 'number')); } /** * Test if the two ranges are touching in any way. */ static areIntersectingOrTouching(a, b) { // Check if `a` is before `b` if (a.endLineNumber < b.startLineNumber || (a.endLineNumber === b.startLineNumber && a.endColumn < b.startColumn)) { return false; } // Check if `b` is before `a` if (b.endLineNumber < a.startLineNumber || (b.endLineNumber === a.startLineNumber && b.endColumn < a.startColumn)) { return false; } // These ranges must intersect return true; } /** * Test if the two ranges are intersecting. If the ranges are touching it returns true. */ static areIntersecting(a, b) { // Check if `a` is before `b` if (a.endLineNumber < b.startLineNumber || (a.endLineNumber === b.startLineNumber && a.endColumn <= b.startColumn)) { return false; } // Check if `b` is before `a` if (b.endLineNumber < a.startLineNumber || (b.endLineNumber === a.startLineNumber && b.endColumn <= a.startColumn)) { return false; } // These ranges must intersect return true; } /** * A function that compares ranges, useful for sorting ranges * It will first compare ranges on the startPosition and then on the endPosition */ static compareRangesUsingStarts(a, b) { if (a && b) { const aStartLineNumber = a.startLineNumber | 0; const bStartLineNumber = b.startLineNumber | 0; if (aStartLineNumber === bStartLineNumber) { const aStartColumn = a.startColumn | 0; const bStartColumn = b.startColumn | 0; if (aStartColumn === bStartColumn) { const aEndLineNumber = a.endLineNumber | 0; const bEndLineNumber = b.endLineNumber | 0; if (aEndLineNumber === bEndLineNumber) { const aEndColumn = a.endColumn | 0; const bEndColumn = b.endColumn | 0; return aEndColumn - bEndColumn; } return aEndLineNumber - bEndLineNumber; } return aStartColumn - bStartColumn; } return aStartLineNumber - bStartLineNumber; } const aExists = (a ? 1 : 0); const bExists = (b ? 1 : 0); return aExists - bExists; } /** * A function that compares ranges, useful for sorting ranges * It will first compare ranges on the endPosition and then on the startPosition */ static compareRangesUsingEnds(a, b) { if (a.endLineNumber === b.endLineNumber) { if (a.endColumn === b.endColumn) { if (a.startLineNumber === b.startLineNumber) { return a.startColumn - b.startColumn; } return a.startLineNumber - b.startLineNumber; } return a.endColumn - b.endColumn; } return a.endLineNumber - b.endLineNumber; } /** * Test if the range spans multiple lines. */ static spansMultipleLines(range) { return range.endLineNumber > range.startLineNumber; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * A selection in the editor. * The selection is a range that has an orientation. */ class Selection$1 extends Range$5 { constructor(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn) { super(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn); this.selectionStartLineNumber = selectionStartLineNumber; this.selectionStartColumn = selectionStartColumn; this.positionLineNumber = positionLineNumber; this.positionColumn = positionColumn; } /** * Transform to a human-readable representation. */ toString() { return '[' + this.selectionStartLineNumber + ',' + this.selectionStartColumn + ' -> ' + this.positionLineNumber + ',' + this.positionColumn + ']'; } /** * Test if equals other selection. */ equalsSelection(other) { return (Selection$1.selectionsEqual(this, other)); } /** * Test if the two selections are equal. */ static selectionsEqual(a, b) { return (a.selectionStartLineNumber === b.selectionStartLineNumber && a.selectionStartColumn === b.selectionStartColumn && a.positionLineNumber === b.positionLineNumber && a.positionColumn === b.positionColumn); } /** * Get directions (LTR or RTL). */ getDirection() { if (this.selectionStartLineNumber === this.startLineNumber && this.selectionStartColumn === this.startColumn) { return 0 /* LTR */; } return 1 /* RTL */; } /** * Create a new selection with a different `positionLineNumber` and `positionColumn`. */ setEndPosition(endLineNumber, endColumn) { if (this.getDirection() === 0 /* LTR */) { return new Selection$1(this.startLineNumber, this.startColumn, endLineNumber, endColumn); } return new Selection$1(endLineNumber, endColumn, this.startLineNumber, this.startColumn); } /** * Get the position at `positionLineNumber` and `positionColumn`. */ getPosition() { return new Position$4(this.positionLineNumber, this.positionColumn); } /** * Get the position at the start of the selection. */ getSelectionStart() { return new Position$4(this.selectionStartLineNumber, this.selectionStartColumn); } /** * Create a new selection with a different `selectionStartLineNumber` and `selectionStartColumn`. */ setStartPosition(startLineNumber, startColumn) { if (this.getDirection() === 0 /* LTR */) { return new Selection$1(startLineNumber, startColumn, this.endLineNumber, this.endColumn); } return new Selection$1(this.endLineNumber, this.endColumn, startLineNumber, startColumn); } // ---- /** * Create a `Selection` from one or two positions */ static fromPositions(start, end = start) { return new Selection$1(start.lineNumber, start.column, end.lineNumber, end.column); } /** * Creates a `Selection` from a range, given a direction. */ static fromRange(range, direction) { if (direction === 0 /* LTR */) { return new Selection$1(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn); } else { return new Selection$1(range.endLineNumber, range.endColumn, range.startLineNumber, range.startColumn); } } /** * Create a `Selection` from an `ISelection`. */ static liftSelection(sel) { return new Selection$1(sel.selectionStartLineNumber, sel.selectionStartColumn, sel.positionLineNumber, sel.positionColumn); } /** * `a` equals `b`. */ static selectionsArrEqual(a, b) { if (a && !b || !a && b) { return false; } if (!a && !b) { return true; } if (a.length !== b.length) { return false; } for (let i = 0, len = a.length; i < len; i++) { if (!this.selectionsEqual(a[i], b[i])) { return false; } } return true; } /** * Test if `obj` is an `ISelection`. */ static isISelection(obj) { return (obj && (typeof obj.selectionStartLineNumber === 'number') && (typeof obj.selectionStartColumn === 'number') && (typeof obj.positionLineNumber === 'number') && (typeof obj.positionColumn === 'number')); } /** * Create with a direction. */ static createWithDirection(startLineNumber, startColumn, endLineNumber, endColumn, direction) { if (direction === 0 /* LTR */) { return new Selection$1(startLineNumber, startColumn, endLineNumber, endColumn); } return new Selection$1(endLineNumber, endColumn, startLineNumber, startColumn); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Vertical Lane in the overview ruler of the editor. */ var OverviewRulerLane$1; (function (OverviewRulerLane) { OverviewRulerLane[OverviewRulerLane["Left"] = 1] = "Left"; OverviewRulerLane[OverviewRulerLane["Center"] = 2] = "Center"; OverviewRulerLane[OverviewRulerLane["Right"] = 4] = "Right"; OverviewRulerLane[OverviewRulerLane["Full"] = 7] = "Full"; })(OverviewRulerLane$1 || (OverviewRulerLane$1 = {})); /** * Position in the minimap to render the decoration. */ var MinimapPosition$1; (function (MinimapPosition) { MinimapPosition[MinimapPosition["Inline"] = 1] = "Inline"; MinimapPosition[MinimapPosition["Gutter"] = 2] = "Gutter"; })(MinimapPosition$1 || (MinimapPosition$1 = {})); var InjectedTextCursorStops$1; (function (InjectedTextCursorStops) { InjectedTextCursorStops[InjectedTextCursorStops["Both"] = 0] = "Both"; InjectedTextCursorStops[InjectedTextCursorStops["Right"] = 1] = "Right"; InjectedTextCursorStops[InjectedTextCursorStops["Left"] = 2] = "Left"; InjectedTextCursorStops[InjectedTextCursorStops["None"] = 3] = "None"; })(InjectedTextCursorStops$1 || (InjectedTextCursorStops$1 = {})); class TextModelResolvedOptions { /** * @internal */ constructor(src) { this._textModelResolvedOptionsBrand = undefined; this.tabSize = Math.max(1, src.tabSize | 0); this.indentSize = src.tabSize | 0; this.insertSpaces = Boolean(src.insertSpaces); this.defaultEOL = src.defaultEOL | 0; this.trimAutoWhitespace = Boolean(src.trimAutoWhitespace); this.bracketPairColorizationOptions = src.bracketPairColorizationOptions; } /** * @internal */ equals(other) { return (this.tabSize === other.tabSize && this.indentSize === other.indentSize && this.insertSpaces === other.insertSpaces && this.defaultEOL === other.defaultEOL && this.trimAutoWhitespace === other.trimAutoWhitespace && equals(this.bracketPairColorizationOptions, other.bracketPairColorizationOptions)); } /** * @internal */ createChangeEvent(newOpts) { return { tabSize: this.tabSize !== newOpts.tabSize, indentSize: this.indentSize !== newOpts.indentSize, insertSpaces: this.insertSpaces !== newOpts.insertSpaces, trimAutoWhitespace: this.trimAutoWhitespace !== newOpts.trimAutoWhitespace, }; } } class FindMatch { /** * @internal */ constructor(range, matches) { this._findMatchBrand = undefined; this.range = range; this.matches = matches; } } /** * @internal */ class ValidAnnotatedEditOperation { constructor(identifier, range, text, forceMoveMarkers, isAutoWhitespaceEdit, _isTracked) { this.identifier = identifier; this.range = range; this.text = text; this.forceMoveMarkers = forceMoveMarkers; this.isAutoWhitespaceEdit = isAutoWhitespaceEdit; this._isTracked = _isTracked; } } /** * @internal */ class SearchData { constructor(regex, wordSeparators, simpleSearch) { this.regex = regex; this.wordSeparators = wordSeparators; this.simpleSearch = simpleSearch; } } /** * @internal */ class ApplyEditsResult { constructor(reverseEdits, changes, trimAutoWhitespaceLineNumbers) { this.reverseEdits = reverseEdits; this.changes = changes; this.trimAutoWhitespaceLineNumbers = trimAutoWhitespaceLineNumbers; } } /** * @internal */ function shouldSynchronizeModel(model) { return (!model.isTooLargeForSyncing() && !model.isForSimpleWidget); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __awaiter$19 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __asyncValues$2 = (undefined && undefined.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function isThenable$1(obj) { return !!obj && typeof obj.then === 'function'; } function createCancelablePromise(callback) { const source = new CancellationTokenSource$1(); const thenable = callback(source.token); const promise = new Promise((resolve, reject) => { const subscription = source.token.onCancellationRequested(() => { subscription.dispose(); source.dispose(); reject(new CancellationError()); }); Promise.resolve(thenable).then(value => { subscription.dispose(); source.dispose(); resolve(value); }, err => { subscription.dispose(); source.dispose(); reject(err); }); }); return new class { cancel() { source.cancel(); } then(resolve, reject) { return promise.then(resolve, reject); } catch(reject) { return this.then(undefined, reject); } finally(onfinally) { return promise.finally(onfinally); } }; } function raceCancellation(promise, token, defaultValue) { return new Promise((resolve, reject) => { const ref = token.onCancellationRequested(() => { ref.dispose(); resolve(defaultValue); }); promise.then(resolve, reject).finally(() => ref.dispose()); }); } /** * A helper to prevent accumulation of sequential async tasks. * * Imagine a mail man with the sole task of delivering letters. As soon as * a letter submitted for delivery, he drives to the destination, delivers it * and returns to his base. Imagine that during the trip, N more letters were submitted. * When the mail man returns, he picks those N letters and delivers them all in a * single trip. Even though N+1 submissions occurred, only 2 deliveries were made. * * The throttler implements this via the queue() method, by providing it a task * factory. Following the example: * * const throttler = new Throttler(); * const letters = []; * * function deliver() { * const lettersToDeliver = letters; * letters = []; * return makeTheTrip(lettersToDeliver); * } * * function onLetterReceived(l) { * letters.push(l); * throttler.queue(deliver); * } */ class Throttler { constructor() { this.activePromise = null; this.queuedPromise = null; this.queuedPromiseFactory = null; } queue(promiseFactory) { if (this.activePromise) { this.queuedPromiseFactory = promiseFactory; if (!this.queuedPromise) { const onComplete = () => { this.queuedPromise = null; const result = this.queue(this.queuedPromiseFactory); this.queuedPromiseFactory = null; return result; }; this.queuedPromise = new Promise(resolve => { this.activePromise.then(onComplete, onComplete).then(resolve); }); } return new Promise((resolve, reject) => { this.queuedPromise.then(resolve, reject); }); } this.activePromise = promiseFactory(); return new Promise((resolve, reject) => { this.activePromise.then((result) => { this.activePromise = null; resolve(result); }, (err) => { this.activePromise = null; reject(err); }); }); } } const timeoutDeferred = (timeout, fn) => { let scheduled = true; const handle = setTimeout(() => { scheduled = false; fn(); }, timeout); return { isTriggered: () => scheduled, dispose: () => { clearTimeout(handle); scheduled = false; }, }; }; const microtaskDeferred = (fn) => { let scheduled = true; queueMicrotask(() => { if (scheduled) { scheduled = false; fn(); } }); return { isTriggered: () => scheduled, dispose: () => { scheduled = false; }, }; }; /** Can be passed into the Delayed to defer using a microtask */ const MicrotaskDelay = Symbol('MicrotaskDelay'); /** * A helper to delay (debounce) execution of a task that is being requested often. * * Following the throttler, now imagine the mail man wants to optimize the number of * trips proactively. The trip itself can be long, so he decides not to make the trip * as soon as a letter is submitted. Instead he waits a while, in case more * letters are submitted. After said waiting period, if no letters were submitted, he * decides to make the trip. Imagine that N more letters were submitted after the first * one, all within a short period of time between each other. Even though N+1 * submissions occurred, only 1 delivery was made. * * The delayer offers this behavior via the trigger() method, into which both the task * to be executed and the waiting period (delay) must be passed in as arguments. Following * the example: * * const delayer = new Delayer(WAITING_PERIOD); * const letters = []; * * function letterReceived(l) { * letters.push(l); * delayer.trigger(() => { return makeTheTrip(); }); * } */ class Delayer { constructor(defaultDelay) { this.defaultDelay = defaultDelay; this.deferred = null; this.completionPromise = null; this.doResolve = null; this.doReject = null; this.task = null; } trigger(task, delay = this.defaultDelay) { this.task = task; this.cancelTimeout(); if (!this.completionPromise) { this.completionPromise = new Promise((resolve, reject) => { this.doResolve = resolve; this.doReject = reject; }).then(() => { this.completionPromise = null; this.doResolve = null; if (this.task) { const task = this.task; this.task = null; return task(); } return undefined; }); } const fn = () => { var _a; this.deferred = null; (_a = this.doResolve) === null || _a === void 0 ? void 0 : _a.call(this, null); }; this.deferred = delay === MicrotaskDelay ? microtaskDeferred(fn) : timeoutDeferred(delay, fn); return this.completionPromise; } isTriggered() { var _a; return !!((_a = this.deferred) === null || _a === void 0 ? void 0 : _a.isTriggered()); } cancel() { this.cancelTimeout(); if (this.completionPromise) { if (this.doReject) { this.doReject(new CancellationError()); } this.completionPromise = null; } } cancelTimeout() { var _a; (_a = this.deferred) === null || _a === void 0 ? void 0 : _a.dispose(); this.deferred = null; } dispose() { this.cancel(); } } /** * A helper to delay execution of a task that is being requested often, while * preventing accumulation of consecutive executions, while the task runs. * * The mail man is clever and waits for a certain amount of time, before going * out to deliver letters. While the mail man is going out, more letters arrive * and can only be delivered once he is back. Once he is back the mail man will * do one more trip to deliver the letters that have accumulated while he was out. */ class ThrottledDelayer { constructor(defaultDelay) { this.delayer = new Delayer(defaultDelay); this.throttler = new Throttler(); } trigger(promiseFactory, delay) { return this.delayer.trigger(() => this.throttler.queue(promiseFactory), delay); } dispose() { this.delayer.dispose(); } } function timeout(millis, token) { if (!token) { return createCancelablePromise(token => timeout(millis, token)); } return new Promise((resolve, reject) => { const handle = setTimeout(() => { disposable.dispose(); resolve(); }, millis); const disposable = token.onCancellationRequested(() => { clearTimeout(handle); disposable.dispose(); reject(new CancellationError()); }); }); } function disposableTimeout(handler, timeout = 0) { const timer = setTimeout(handler, timeout); return toDisposable(() => clearTimeout(timer)); } function first(promiseFactories, shouldStop = t => !!t, defaultValue = null) { let index = 0; const len = promiseFactories.length; const loop = () => { if (index >= len) { return Promise.resolve(defaultValue); } const factory = promiseFactories[index++]; const promise = Promise.resolve(factory()); return promise.then(result => { if (shouldStop(result)) { return Promise.resolve(result); } return loop(); }); }; return loop(); } class TimeoutTimer { constructor(runner, timeout) { this._token = -1; if (typeof runner === 'function' && typeof timeout === 'number') { this.setIfNotSet(runner, timeout); } } dispose() { this.cancel(); } cancel() { if (this._token !== -1) { clearTimeout(this._token); this._token = -1; } } cancelAndSet(runner, timeout) { this.cancel(); this._token = setTimeout(() => { this._token = -1; runner(); }, timeout); } setIfNotSet(runner, timeout) { if (this._token !== -1) { // timer is already set return; } this._token = setTimeout(() => { this._token = -1; runner(); }, timeout); } } class IntervalTimer { constructor() { this._token = -1; } dispose() { this.cancel(); } cancel() { if (this._token !== -1) { clearInterval(this._token); this._token = -1; } } cancelAndSet(runner, interval) { this.cancel(); this._token = setInterval(() => { runner(); }, interval); } } class RunOnceScheduler { constructor(runner, delay) { this.timeoutToken = -1; this.runner = runner; this.timeout = delay; this.timeoutHandler = this.onTimeout.bind(this); } /** * Dispose RunOnceScheduler */ dispose() { this.cancel(); this.runner = null; } /** * Cancel current scheduled runner (if any). */ cancel() { if (this.isScheduled()) { clearTimeout(this.timeoutToken); this.timeoutToken = -1; } } /** * Cancel previous runner (if any) & schedule a new runner. */ schedule(delay = this.timeout) { this.cancel(); this.timeoutToken = setTimeout(this.timeoutHandler, delay); } get delay() { return this.timeout; } set delay(value) { this.timeout = value; } /** * Returns true if scheduled. */ isScheduled() { return this.timeoutToken !== -1; } onTimeout() { this.timeoutToken = -1; if (this.runner) { this.doRun(); } } doRun() { if (this.runner) { this.runner(); } } } /** * Execute the callback the next time the browser is idle */ let runWhenIdle; (function () { if (typeof requestIdleCallback !== 'function' || typeof cancelIdleCallback !== 'function') { runWhenIdle = (runner) => { setTimeout0(() => { if (disposed) { return; } const end = Date.now() + 15; // one frame at 64fps runner(Object.freeze({ didTimeout: true, timeRemaining() { return Math.max(0, end - Date.now()); } })); }); let disposed = false; return { dispose() { if (disposed) { return; } disposed = true; } }; }; } else { runWhenIdle = (runner, timeout) => { const handle = requestIdleCallback(runner, typeof timeout === 'number' ? { timeout } : undefined); let disposed = false; return { dispose() { if (disposed) { return; } disposed = true; cancelIdleCallback(handle); } }; }; } })(); /** * An implementation of the "idle-until-urgent"-strategy as introduced * here: https://philipwalton.com/articles/idle-until-urgent/ */ class IdleValue { constructor(executor) { this._didRun = false; this._executor = () => { try { this._value = executor(); } catch (err) { this._error = err; } finally { this._didRun = true; } }; this._handle = runWhenIdle(() => this._executor()); } dispose() { this._handle.dispose(); } get value() { if (!this._didRun) { this._handle.dispose(); this._executor(); } if (this._error) { throw this._error; } return this._value; } get isInitialized() { return this._didRun; } } /** * Creates a promise whose resolution or rejection can be controlled imperatively. */ class DeferredPromise { constructor() { this.rejected = false; this.resolved = false; this.p = new Promise((c, e) => { this.completeCallback = c; this.errorCallback = e; }); } get isRejected() { return this.rejected; } get isSettled() { return this.rejected || this.resolved; } complete(value) { return new Promise(resolve => { this.completeCallback(value); this.resolved = true; resolve(); }); } cancel() { new Promise(resolve => { this.errorCallback(new CancellationError()); this.rejected = true; resolve(); }); } } //#endregion //#region Promises var Promises; (function (Promises) { /** * A drop-in replacement for `Promise.all` with the only difference * that the method awaits every promise to either fulfill or reject. * * Similar to `Promise.all`, only the first error will be returned * if any. */ function settled(promises) { return __awaiter$19(this, void 0, void 0, function* () { let firstError = undefined; const result = yield Promise.all(promises.map(promise => promise.then(value => value, error => { if (!firstError) { firstError = error; } return undefined; // do not rethrow so that other promises can settle }))); if (typeof firstError !== 'undefined') { throw firstError; } return result; // cast is needed and protected by the `throw` above }); } Promises.settled = settled; /** * A helper to create a new `Promise` with a body that is a promise * itself. By default, an error that raises from the async body will * end up as a unhandled rejection, so this utility properly awaits the * body and rejects the promise as a normal promise does without async * body. * * This method should only be used in rare cases where otherwise `async` * cannot be used (e.g. when callbacks are involved that require this). */ function withAsyncBody(bodyFn) { // eslint-disable-next-line no-async-promise-executor return new Promise((resolve, reject) => __awaiter$19(this, void 0, void 0, function* () { try { yield bodyFn(resolve, reject); } catch (error) { reject(error); } })); } Promises.withAsyncBody = withAsyncBody; })(Promises || (Promises = {})); /** * A rich implementation for an `AsyncIterable`. */ class AsyncIterableObject { constructor(executor) { this._state = 0 /* Initial */; this._results = []; this._error = null; this._onStateChanged = new Emitter$1(); queueMicrotask(() => __awaiter$19(this, void 0, void 0, function* () { const writer = { emitOne: (item) => this.emitOne(item), emitMany: (items) => this.emitMany(items), reject: (error) => this.reject(error) }; try { yield Promise.resolve(executor(writer)); this.resolve(); } catch (err) { this.reject(err); } finally { writer.emitOne = undefined; writer.emitMany = undefined; writer.reject = undefined; } })); } static fromArray(items) { return new AsyncIterableObject((writer) => { writer.emitMany(items); }); } static fromPromise(promise) { return new AsyncIterableObject((emitter) => __awaiter$19(this, void 0, void 0, function* () { emitter.emitMany(yield promise); })); } static fromPromises(promises) { return new AsyncIterableObject((emitter) => __awaiter$19(this, void 0, void 0, function* () { yield Promise.all(promises.map((p) => __awaiter$19(this, void 0, void 0, function* () { return emitter.emitOne(yield p); }))); })); } static merge(iterables) { return new AsyncIterableObject((emitter) => __awaiter$19(this, void 0, void 0, function* () { yield Promise.all(iterables.map((iterable) => { var iterable_1, iterable_1_1; return __awaiter$19(this, void 0, void 0, function* () { var e_1, _a; try { for (iterable_1 = __asyncValues$2(iterable); iterable_1_1 = yield iterable_1.next(), !iterable_1_1.done;) { const item = iterable_1_1.value; emitter.emitOne(item); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) yield _a.call(iterable_1); } finally { if (e_1) throw e_1.error; } } }); })); })); } [Symbol.asyncIterator]() { let i = 0; return { next: () => __awaiter$19(this, void 0, void 0, function* () { do { if (this._state === 2 /* DoneError */) { throw this._error; } if (i < this._results.length) { return { done: false, value: this._results[i++] }; } if (this._state === 1 /* DoneOK */) { return { done: true, value: undefined }; } yield Event.toPromise(this._onStateChanged.event); } while (true); }) }; } static map(iterable, mapFn) { return new AsyncIterableObject((emitter) => __awaiter$19(this, void 0, void 0, function* () { var e_2, _a; try { for (var iterable_2 = __asyncValues$2(iterable), iterable_2_1; iterable_2_1 = yield iterable_2.next(), !iterable_2_1.done;) { const item = iterable_2_1.value; emitter.emitOne(mapFn(item)); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (iterable_2_1 && !iterable_2_1.done && (_a = iterable_2.return)) yield _a.call(iterable_2); } finally { if (e_2) throw e_2.error; } } })); } map(mapFn) { return AsyncIterableObject.map(this, mapFn); } static filter(iterable, filterFn) { return new AsyncIterableObject((emitter) => __awaiter$19(this, void 0, void 0, function* () { var e_3, _a; try { for (var iterable_3 = __asyncValues$2(iterable), iterable_3_1; iterable_3_1 = yield iterable_3.next(), !iterable_3_1.done;) { const item = iterable_3_1.value; if (filterFn(item)) { emitter.emitOne(item); } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (iterable_3_1 && !iterable_3_1.done && (_a = iterable_3.return)) yield _a.call(iterable_3); } finally { if (e_3) throw e_3.error; } } })); } filter(filterFn) { return AsyncIterableObject.filter(this, filterFn); } static coalesce(iterable) { return AsyncIterableObject.filter(iterable, item => !!item); } coalesce() { return AsyncIterableObject.coalesce(this); } static toPromise(iterable) { var iterable_4, iterable_4_1; var e_4, _a; return __awaiter$19(this, void 0, void 0, function* () { const result = []; try { for (iterable_4 = __asyncValues$2(iterable); iterable_4_1 = yield iterable_4.next(), !iterable_4_1.done;) { const item = iterable_4_1.value; result.push(item); } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (iterable_4_1 && !iterable_4_1.done && (_a = iterable_4.return)) yield _a.call(iterable_4); } finally { if (e_4) throw e_4.error; } } return result; }); } toPromise() { return AsyncIterableObject.toPromise(this); } /** * The value will be appended at the end. * * **NOTE** If `resolve()` or `reject()` have already been called, this method has no effect. */ emitOne(value) { if (this._state !== 0 /* Initial */) { return; } // it is important to add new values at the end, // as we may have iterators already running on the array this._results.push(value); this._onStateChanged.fire(); } /** * The values will be appended at the end. * * **NOTE** If `resolve()` or `reject()` have already been called, this method has no effect. */ emitMany(values) { if (this._state !== 0 /* Initial */) { return; } // it is important to add new values at the end, // as we may have iterators already running on the array this._results = this._results.concat(values); this._onStateChanged.fire(); } /** * Calling `resolve()` will mark the result array as complete. * * **NOTE** `resolve()` must be called, otherwise all consumers of this iterable will hang indefinitely, similar to a non-resolved promise. * **NOTE** If `resolve()` or `reject()` have already been called, this method has no effect. */ resolve() { if (this._state !== 0 /* Initial */) { return; } this._state = 1 /* DoneOK */; this._onStateChanged.fire(); } /** * Writing an error will permanently invalidate this iterable. * The current users will receive an error thrown, as will all future users. * * **NOTE** If `resolve()` or `reject()` have already been called, this method has no effect. */ reject(error) { if (this._state !== 0 /* Initial */) { return; } this._state = 2 /* DoneError */; this._error = error; this._onStateChanged.fire(); } } AsyncIterableObject.EMPTY = AsyncIterableObject.fromArray([]); class CancelableAsyncIterableObject extends AsyncIterableObject { constructor(_source, executor) { super(executor); this._source = _source; } cancel() { this._source.cancel(); } } function createCancelableAsyncIterable(callback) { const source = new CancellationTokenSource$1(); const innerIterable = callback(source.token); return new CancelableAsyncIterableObject(source, (emitter) => __awaiter$19(this, void 0, void 0, function* () { var e_5, _a; const subscription = source.token.onCancellationRequested(() => { subscription.dispose(); source.dispose(); emitter.reject(new CancellationError()); }); try { try { for (var innerIterable_1 = __asyncValues$2(innerIterable), innerIterable_1_1; innerIterable_1_1 = yield innerIterable_1.next(), !innerIterable_1_1.done;) { const item = innerIterable_1_1.value; if (source.token.isCancellationRequested) { // canceled in the meantime return; } emitter.emitOne(item); } } catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (innerIterable_1_1 && !innerIterable_1_1.done && (_a = innerIterable_1.return)) yield _a.call(innerIterable_1); } finally { if (e_5) throw e_5.error; } } subscription.dispose(); source.dispose(); } catch (err) { subscription.dispose(); source.dispose(); emitter.reject(err); } })); } //#endregion /** * Uses a LRU cache to make a given parametrized function cached. * Caches just the last value. * The key must be JSON serializable. */ class LRUCachedComputed { constructor(computeFn) { this.computeFn = computeFn; this.lastCache = undefined; this.lastArgKey = undefined; } get(arg) { const key = JSON.stringify(arg); if (this.lastArgKey !== key) { this.lastArgKey = key; this.lastCache = this.computeFn(arg); } return this.lastCache; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class Lazy { constructor(executor) { this.executor = executor; this._didRun = false; } /** * Get the wrapped value. * * This will force evaluation of the lazy value if it has not been resolved yet. Lazy values are only * resolved once. `getValue` will re-throw exceptions that are hit while resolving the value */ getValue() { if (!this._didRun) { try { this._value = this.executor(); } catch (err) { this._error = err; } finally { this._didRun = true; } } if (this._error) { throw this._error; } return this._value; } /** * Get the wrapped value without forcing evaluation. */ get rawValue() { return this._value; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var _a$c; function isFalsyOrWhitespace(str) { if (!str || typeof str !== 'string') { return true; } return str.trim().length === 0; } const _formatRegexp = /{(\d+)}/g; /** * Helper to produce a string with a variable number of arguments. Insert variable segments * into the string using the {n} notation where N is the index of the argument following the string. * @param value string to which formatting is applied * @param args replacements for {n}-entries */ function format(value, ...args) { if (args.length === 0) { return value; } return value.replace(_formatRegexp, function (match, group) { const idx = parseInt(group, 10); return isNaN(idx) || idx < 0 || idx >= args.length ? match : args[idx]; }); } /** * Converts HTML characters inside the string to use entities instead. Makes the string safe from * being used e.g. in HTMLElement.innerHTML. */ function escape(html) { return html.replace(/[<>&]/g, function (match) { switch (match) { case '<': return '<'; case '>': return '>'; case '&': return '&'; default: return match; } }); } /** * Escapes regular expression characters in a given string */ function escapeRegExpCharacters(value) { return value.replace(/[\\\{\}\*\+\?\|\^\$\.\[\]\(\)]/g, '\\$&'); } /** * Removes all occurrences of needle from the beginning and end of haystack. * @param haystack string to trim * @param needle the thing to trim (default is a blank) */ function trim(haystack, needle = ' ') { const trimmed = ltrim(haystack, needle); return rtrim(trimmed, needle); } /** * Removes all occurrences of needle from the beginning of haystack. * @param haystack string to trim * @param needle the thing to trim */ function ltrim(haystack, needle) { if (!haystack || !needle) { return haystack; } const needleLen = needle.length; if (needleLen === 0 || haystack.length === 0) { return haystack; } let offset = 0; while (haystack.indexOf(needle, offset) === offset) { offset = offset + needleLen; } return haystack.substring(offset); } /** * Removes all occurrences of needle from the end of haystack. * @param haystack string to trim * @param needle the thing to trim */ function rtrim(haystack, needle) { if (!haystack || !needle) { return haystack; } const needleLen = needle.length, haystackLen = haystack.length; if (needleLen === 0 || haystackLen === 0) { return haystack; } let offset = haystackLen, idx = -1; while (true) { idx = haystack.lastIndexOf(needle, offset - 1); if (idx === -1 || idx + needleLen !== offset) { break; } if (idx === 0) { return ''; } offset = idx; } return haystack.substring(0, offset); } function convertSimple2RegExpPattern(pattern) { return pattern.replace(/[\-\\\{\}\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&').replace(/[\*]/g, '.*'); } function stripWildcards(pattern) { return pattern.replace(/\*/g, ''); } function createRegExp(searchString, isRegex, options = {}) { if (!searchString) { throw new Error('Cannot create regex from empty string'); } if (!isRegex) { searchString = escapeRegExpCharacters(searchString); } if (options.wholeWord) { if (!/\B/.test(searchString.charAt(0))) { searchString = '\\b' + searchString; } if (!/\B/.test(searchString.charAt(searchString.length - 1))) { searchString = searchString + '\\b'; } } let modifiers = ''; if (options.global) { modifiers += 'g'; } if (!options.matchCase) { modifiers += 'i'; } if (options.multiline) { modifiers += 'm'; } if (options.unicode) { modifiers += 'u'; } return new RegExp(searchString, modifiers); } function regExpLeadsToEndlessLoop(regexp) { // Exit early if it's one of these special cases which are meant to match // against an empty string if (regexp.source === '^' || regexp.source === '^$' || regexp.source === '$' || regexp.source === '^\\s*$') { return false; } // We check against an empty string. If the regular expression doesn't advance // (e.g. ends in an endless loop) it will match an empty string. const match = regexp.exec(''); return !!(match && regexp.lastIndex === 0); } function regExpFlags(regexp) { return (regexp.global ? 'g' : '') + (regexp.ignoreCase ? 'i' : '') + (regexp.multiline ? 'm' : '') + (regexp /* standalone editor compilation */.unicode ? 'u' : ''); } function splitLines(str) { return str.split(/\r\n|\r|\n/); } /** * Returns first index of the string that is not whitespace. * If string is empty or contains only whitespaces, returns -1 */ function firstNonWhitespaceIndex(str) { for (let i = 0, len = str.length; i < len; i++) { const chCode = str.charCodeAt(i); if (chCode !== 32 /* Space */ && chCode !== 9 /* Tab */) { return i; } } return -1; } /** * Returns the leading whitespace of the string. * If the string contains only whitespaces, returns entire string */ function getLeadingWhitespace(str, start = 0, end = str.length) { for (let i = start; i < end; i++) { const chCode = str.charCodeAt(i); if (chCode !== 32 /* Space */ && chCode !== 9 /* Tab */) { return str.substring(start, i); } } return str.substring(start, end); } /** * Returns last index of the string that is not whitespace. * If string is empty or contains only whitespaces, returns -1 */ function lastNonWhitespaceIndex(str, startIndex = str.length - 1) { for (let i = startIndex; i >= 0; i--) { const chCode = str.charCodeAt(i); if (chCode !== 32 /* Space */ && chCode !== 9 /* Tab */) { return i; } } return -1; } function compare(a, b) { if (a < b) { return -1; } else if (a > b) { return 1; } else { return 0; } } function compareSubstring(a, b, aStart = 0, aEnd = a.length, bStart = 0, bEnd = b.length) { for (; aStart < aEnd && bStart < bEnd; aStart++, bStart++) { let codeA = a.charCodeAt(aStart); let codeB = b.charCodeAt(bStart); if (codeA < codeB) { return -1; } else if (codeA > codeB) { return 1; } } const aLen = aEnd - aStart; const bLen = bEnd - bStart; if (aLen < bLen) { return -1; } else if (aLen > bLen) { return 1; } return 0; } function compareIgnoreCase(a, b) { return compareSubstringIgnoreCase(a, b, 0, a.length, 0, b.length); } function compareSubstringIgnoreCase(a, b, aStart = 0, aEnd = a.length, bStart = 0, bEnd = b.length) { for (; aStart < aEnd && bStart < bEnd; aStart++, bStart++) { let codeA = a.charCodeAt(aStart); let codeB = b.charCodeAt(bStart); if (codeA === codeB) { // equal continue; } if (codeA >= 128 || codeB >= 128) { // not ASCII letters -> fallback to lower-casing strings return compareSubstring(a.toLowerCase(), b.toLowerCase(), aStart, aEnd, bStart, bEnd); } // mapper lower-case ascii letter onto upper-case varinats // [97-122] (lower ascii) --> [65-90] (upper ascii) if (isLowerAsciiLetter(codeA)) { codeA -= 32; } if (isLowerAsciiLetter(codeB)) { codeB -= 32; } // compare both code points const diff = codeA - codeB; if (diff === 0) { continue; } return diff; } const aLen = aEnd - aStart; const bLen = bEnd - bStart; if (aLen < bLen) { return -1; } else if (aLen > bLen) { return 1; } return 0; } function isLowerAsciiLetter(code) { return code >= 97 /* a */ && code <= 122 /* z */; } function isUpperAsciiLetter(code) { return code >= 65 /* A */ && code <= 90 /* Z */; } function equalsIgnoreCase(a, b) { return a.length === b.length && compareSubstringIgnoreCase(a, b) === 0; } function startsWithIgnoreCase(str, candidate) { const candidateLength = candidate.length; if (candidate.length > str.length) { return false; } return compareSubstringIgnoreCase(str, candidate, 0, candidateLength) === 0; } /** * @returns the length of the common prefix of the two strings. */ function commonPrefixLength(a, b) { let i, len = Math.min(a.length, b.length); for (i = 0; i < len; i++) { if (a.charCodeAt(i) !== b.charCodeAt(i)) { return i; } } return len; } /** * @returns the length of the common suffix of the two strings. */ function commonSuffixLength(a, b) { let i, len = Math.min(a.length, b.length); const aLastIndex = a.length - 1; const bLastIndex = b.length - 1; for (i = 0; i < len; i++) { if (a.charCodeAt(aLastIndex - i) !== b.charCodeAt(bLastIndex - i)) { return i; } } return len; } /** * See http://en.wikipedia.org/wiki/Surrogate_pair */ function isHighSurrogate(charCode) { return (0xD800 <= charCode && charCode <= 0xDBFF); } /** * See http://en.wikipedia.org/wiki/Surrogate_pair */ function isLowSurrogate(charCode) { return (0xDC00 <= charCode && charCode <= 0xDFFF); } /** * See http://en.wikipedia.org/wiki/Surrogate_pair */ function computeCodePoint(highSurrogate, lowSurrogate) { return ((highSurrogate - 0xD800) << 10) + (lowSurrogate - 0xDC00) + 0x10000; } /** * get the code point that begins at offset `offset` */ function getNextCodePoint(str, len, offset) { const charCode = str.charCodeAt(offset); if (isHighSurrogate(charCode) && offset + 1 < len) { const nextCharCode = str.charCodeAt(offset + 1); if (isLowSurrogate(nextCharCode)) { return computeCodePoint(charCode, nextCharCode); } } return charCode; } /** * get the code point that ends right before offset `offset` */ function getPrevCodePoint(str, offset) { const charCode = str.charCodeAt(offset - 1); if (isLowSurrogate(charCode) && offset > 1) { const prevCharCode = str.charCodeAt(offset - 2); if (isHighSurrogate(prevCharCode)) { return computeCodePoint(prevCharCode, charCode); } } return charCode; } class CodePointIterator { constructor(str, offset = 0) { this._str = str; this._len = str.length; this._offset = offset; } get offset() { return this._offset; } setOffset(offset) { this._offset = offset; } prevCodePoint() { const codePoint = getPrevCodePoint(this._str, this._offset); this._offset -= (codePoint >= 65536 /* UNICODE_SUPPLEMENTARY_PLANE_BEGIN */ ? 2 : 1); return codePoint; } nextCodePoint() { const codePoint = getNextCodePoint(this._str, this._len, this._offset); this._offset += (codePoint >= 65536 /* UNICODE_SUPPLEMENTARY_PLANE_BEGIN */ ? 2 : 1); return codePoint; } eol() { return (this._offset >= this._len); } } class GraphemeIterator { constructor(str, offset = 0) { this._iterator = new CodePointIterator(str, offset); } get offset() { return this._iterator.offset; } nextGraphemeLength() { const graphemeBreakTree = GraphemeBreakTree.getInstance(); const iterator = this._iterator; const initialOffset = iterator.offset; let graphemeBreakType = graphemeBreakTree.getGraphemeBreakType(iterator.nextCodePoint()); while (!iterator.eol()) { const offset = iterator.offset; const nextGraphemeBreakType = graphemeBreakTree.getGraphemeBreakType(iterator.nextCodePoint()); if (breakBetweenGraphemeBreakType(graphemeBreakType, nextGraphemeBreakType)) { // move iterator back iterator.setOffset(offset); break; } graphemeBreakType = nextGraphemeBreakType; } return (iterator.offset - initialOffset); } prevGraphemeLength() { const graphemeBreakTree = GraphemeBreakTree.getInstance(); const iterator = this._iterator; const initialOffset = iterator.offset; let graphemeBreakType = graphemeBreakTree.getGraphemeBreakType(iterator.prevCodePoint()); while (iterator.offset > 0) { const offset = iterator.offset; const prevGraphemeBreakType = graphemeBreakTree.getGraphemeBreakType(iterator.prevCodePoint()); if (breakBetweenGraphemeBreakType(prevGraphemeBreakType, graphemeBreakType)) { // move iterator back iterator.setOffset(offset); break; } graphemeBreakType = prevGraphemeBreakType; } return (initialOffset - iterator.offset); } eol() { return this._iterator.eol(); } } function nextCharLength(str, initialOffset) { const iterator = new GraphemeIterator(str, initialOffset); return iterator.nextGraphemeLength(); } function prevCharLength(str, initialOffset) { const iterator = new GraphemeIterator(str, initialOffset); return iterator.prevGraphemeLength(); } function getCharContainingOffset(str, offset) { if (offset > 0 && isLowSurrogate(str.charCodeAt(offset))) { offset--; } const endOffset = offset + nextCharLength(str, offset); const startOffset = endOffset - prevCharLength(str, endOffset); return [startOffset, endOffset]; } /** * Generated using https://github.com/alexdima/unicode-utils/blob/main/rtl-test.js */ const CONTAINS_RTL = /(?:[\u05BE\u05C0\u05C3\u05C6\u05D0-\u05F4\u0608\u060B\u060D\u061B-\u064A\u066D-\u066F\u0671-\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u0710\u0712-\u072F\u074D-\u07A5\u07B1-\u07EA\u07F4\u07F5\u07FA\u07FE-\u0815\u081A\u0824\u0828\u0830-\u0858\u085E-\u088E\u08A0-\u08C9\u200F\uFB1D\uFB1F-\uFB28\uFB2A-\uFD3D\uFD50-\uFDC7\uFDF0-\uFDFC\uFE70-\uFEFC]|\uD802[\uDC00-\uDD1B\uDD20-\uDE00\uDE10-\uDE35\uDE40-\uDEE4\uDEEB-\uDF35\uDF40-\uDFFF]|\uD803[\uDC00-\uDD23\uDE80-\uDEA9\uDEAD-\uDF45\uDF51-\uDF81\uDF86-\uDFF6]|\uD83A[\uDC00-\uDCCF\uDD00-\uDD43\uDD4B-\uDFFF]|\uD83B[\uDC00-\uDEBB])/; /** * Returns true if `str` contains any Unicode character that is classified as "R" or "AL". */ function containsRTL(str) { return CONTAINS_RTL.test(str); } const IS_BASIC_ASCII = /^[\t\n\r\x20-\x7E]*$/; /** * Returns true if `str` contains only basic ASCII characters in the range 32 - 126 (including 32 and 126) or \n, \r, \t */ function isBasicASCII(str) { return IS_BASIC_ASCII.test(str); } const UNUSUAL_LINE_TERMINATORS = /[\u2028\u2029]/; // LINE SEPARATOR (LS) or PARAGRAPH SEPARATOR (PS) /** * Returns true if `str` contains unusual line terminators, like LS or PS */ function containsUnusualLineTerminators(str) { return UNUSUAL_LINE_TERMINATORS.test(str); } function isFullWidthCharacter(charCode) { // Do a cheap trick to better support wrapping of wide characters, treat them as 2 columns // http://jrgraphix.net/research/unicode_blocks.php // 2E80 - 2EFF CJK Radicals Supplement // 2F00 - 2FDF Kangxi Radicals // 2FF0 - 2FFF Ideographic Description Characters // 3000 - 303F CJK Symbols and Punctuation // 3040 - 309F Hiragana // 30A0 - 30FF Katakana // 3100 - 312F Bopomofo // 3130 - 318F Hangul Compatibility Jamo // 3190 - 319F Kanbun // 31A0 - 31BF Bopomofo Extended // 31F0 - 31FF Katakana Phonetic Extensions // 3200 - 32FF Enclosed CJK Letters and Months // 3300 - 33FF CJK Compatibility // 3400 - 4DBF CJK Unified Ideographs Extension A // 4DC0 - 4DFF Yijing Hexagram Symbols // 4E00 - 9FFF CJK Unified Ideographs // A000 - A48F Yi Syllables // A490 - A4CF Yi Radicals // AC00 - D7AF Hangul Syllables // [IGNORE] D800 - DB7F High Surrogates // [IGNORE] DB80 - DBFF High Private Use Surrogates // [IGNORE] DC00 - DFFF Low Surrogates // [IGNORE] E000 - F8FF Private Use Area // F900 - FAFF CJK Compatibility Ideographs // [IGNORE] FB00 - FB4F Alphabetic Presentation Forms // [IGNORE] FB50 - FDFF Arabic Presentation Forms-A // [IGNORE] FE00 - FE0F Variation Selectors // [IGNORE] FE20 - FE2F Combining Half Marks // [IGNORE] FE30 - FE4F CJK Compatibility Forms // [IGNORE] FE50 - FE6F Small Form Variants // [IGNORE] FE70 - FEFF Arabic Presentation Forms-B // FF00 - FFEF Halfwidth and Fullwidth Forms // [https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms] // of which FF01 - FF5E fullwidth ASCII of 21 to 7E // [IGNORE] and FF65 - FFDC halfwidth of Katakana and Hangul // [IGNORE] FFF0 - FFFF Specials return ((charCode >= 0x2E80 && charCode <= 0xD7AF) || (charCode >= 0xF900 && charCode <= 0xFAFF) || (charCode >= 0xFF01 && charCode <= 0xFF5E)); } /** * A fast function (therefore imprecise) to check if code points are emojis. * Generated using https://github.com/alexdima/unicode-utils/blob/main/emoji-test.js */ function isEmojiImprecise(x) { return ((x >= 0x1F1E6 && x <= 0x1F1FF) || (x === 8986) || (x === 8987) || (x === 9200) || (x === 9203) || (x >= 9728 && x <= 10175) || (x === 11088) || (x === 11093) || (x >= 127744 && x <= 128591) || (x >= 128640 && x <= 128764) || (x >= 128992 && x <= 129008) || (x >= 129280 && x <= 129535) || (x >= 129648 && x <= 129782)); } // -- UTF-8 BOM const UTF8_BOM_CHARACTER = String.fromCharCode(65279 /* UTF8_BOM */); function startsWithUTF8BOM(str) { return !!(str && str.length > 0 && str.charCodeAt(0) === 65279 /* UTF8_BOM */); } function containsUppercaseCharacter(target, ignoreEscapedChars = false) { if (!target) { return false; } if (ignoreEscapedChars) { target = target.replace(/\\./g, ''); } return target.toLowerCase() !== target; } /** * Produces 'a'-'z', followed by 'A'-'Z'... followed by 'a'-'z', etc. */ function singleLetterHash(n) { const LETTERS_CNT = (90 /* Z */ - 65 /* A */ + 1); n = n % (2 * LETTERS_CNT); if (n < LETTERS_CNT) { return String.fromCharCode(97 /* a */ + n); } return String.fromCharCode(65 /* A */ + n - LETTERS_CNT); } function breakBetweenGraphemeBreakType(breakTypeA, breakTypeB) { // http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules // !!! Let's make the common case a bit faster if (breakTypeA === 0 /* Other */) { // see https://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakTest-13.0.0d10.html#table return (breakTypeB !== 5 /* Extend */ && breakTypeB !== 7 /* SpacingMark */); } // Do not break between a CR and LF. Otherwise, break before and after controls. // GB3 CR × LF // GB4 (Control | CR | LF) ÷ // GB5 ÷ (Control | CR | LF) if (breakTypeA === 2 /* CR */) { if (breakTypeB === 3 /* LF */) { return false; // GB3 } } if (breakTypeA === 4 /* Control */ || breakTypeA === 2 /* CR */ || breakTypeA === 3 /* LF */) { return true; // GB4 } if (breakTypeB === 4 /* Control */ || breakTypeB === 2 /* CR */ || breakTypeB === 3 /* LF */) { return true; // GB5 } // Do not break Hangul syllable sequences. // GB6 L × (L | V | LV | LVT) // GB7 (LV | V) × (V | T) // GB8 (LVT | T) × T if (breakTypeA === 8 /* L */) { if (breakTypeB === 8 /* L */ || breakTypeB === 9 /* V */ || breakTypeB === 11 /* LV */ || breakTypeB === 12 /* LVT */) { return false; // GB6 } } if (breakTypeA === 11 /* LV */ || breakTypeA === 9 /* V */) { if (breakTypeB === 9 /* V */ || breakTypeB === 10 /* T */) { return false; // GB7 } } if (breakTypeA === 12 /* LVT */ || breakTypeA === 10 /* T */) { if (breakTypeB === 10 /* T */) { return false; // GB8 } } // Do not break before extending characters or ZWJ. // GB9 × (Extend | ZWJ) if (breakTypeB === 5 /* Extend */ || breakTypeB === 13 /* ZWJ */) { return false; // GB9 } // The GB9a and GB9b rules only apply to extended grapheme clusters: // Do not break before SpacingMarks, or after Prepend characters. // GB9a × SpacingMark // GB9b Prepend × if (breakTypeB === 7 /* SpacingMark */) { return false; // GB9a } if (breakTypeA === 1 /* Prepend */) { return false; // GB9b } // Do not break within emoji modifier sequences or emoji zwj sequences. // GB11 \p{Extended_Pictographic} Extend* ZWJ × \p{Extended_Pictographic} if (breakTypeA === 13 /* ZWJ */ && breakTypeB === 14 /* Extended_Pictographic */) { // Note: we are not implementing the rule entirely here to avoid introducing states return false; // GB11 } // GB12 sot (RI RI)* RI × RI // GB13 [^RI] (RI RI)* RI × RI if (breakTypeA === 6 /* Regional_Indicator */ && breakTypeB === 6 /* Regional_Indicator */) { // Note: we are not implementing the rule entirely here to avoid introducing states return false; // GB12 & GB13 } // GB999 Any ÷ Any return true; } class GraphemeBreakTree { constructor() { this._data = getGraphemeBreakRawData(); } static getInstance() { if (!GraphemeBreakTree._INSTANCE) { GraphemeBreakTree._INSTANCE = new GraphemeBreakTree(); } return GraphemeBreakTree._INSTANCE; } getGraphemeBreakType(codePoint) { // !!! Let's make 7bit ASCII a bit faster: 0..31 if (codePoint < 32) { if (codePoint === 10 /* LineFeed */) { return 3 /* LF */; } if (codePoint === 13 /* CarriageReturn */) { return 2 /* CR */; } return 4 /* Control */; } // !!! Let's make 7bit ASCII a bit faster: 32..126 if (codePoint < 127) { return 0 /* Other */; } const data = this._data; const nodeCount = data.length / 3; let nodeIndex = 1; while (nodeIndex <= nodeCount) { if (codePoint < data[3 * nodeIndex]) { // go left nodeIndex = 2 * nodeIndex; } else if (codePoint > data[3 * nodeIndex + 1]) { // go right nodeIndex = 2 * nodeIndex + 1; } else { // hit return data[3 * nodeIndex + 2]; } } return 0 /* Other */; } } GraphemeBreakTree._INSTANCE = null; function getGraphemeBreakRawData() { // generated using https://github.com/alexdima/unicode-utils/blob/main/grapheme-break.js return JSON.parse('[0,0,0,51229,51255,12,44061,44087,12,127462,127487,6,7083,7085,5,47645,47671,12,54813,54839,12,128678,128678,14,3270,3270,5,9919,9923,14,45853,45879,12,49437,49463,12,53021,53047,12,71216,71218,7,128398,128399,14,129360,129374,14,2519,2519,5,4448,4519,9,9742,9742,14,12336,12336,14,44957,44983,12,46749,46775,12,48541,48567,12,50333,50359,12,52125,52151,12,53917,53943,12,69888,69890,5,73018,73018,5,127990,127990,14,128558,128559,14,128759,128760,14,129653,129655,14,2027,2035,5,2891,2892,7,3761,3761,5,6683,6683,5,8293,8293,4,9825,9826,14,9999,9999,14,43452,43453,5,44509,44535,12,45405,45431,12,46301,46327,12,47197,47223,12,48093,48119,12,48989,49015,12,49885,49911,12,50781,50807,12,51677,51703,12,52573,52599,12,53469,53495,12,54365,54391,12,65279,65279,4,70471,70472,7,72145,72147,7,119173,119179,5,127799,127818,14,128240,128244,14,128512,128512,14,128652,128652,14,128721,128722,14,129292,129292,14,129445,129450,14,129734,129743,14,1476,1477,5,2366,2368,7,2750,2752,7,3076,3076,5,3415,3415,5,4141,4144,5,6109,6109,5,6964,6964,5,7394,7400,5,9197,9198,14,9770,9770,14,9877,9877,14,9968,9969,14,10084,10084,14,43052,43052,5,43713,43713,5,44285,44311,12,44733,44759,12,45181,45207,12,45629,45655,12,46077,46103,12,46525,46551,12,46973,46999,12,47421,47447,12,47869,47895,12,48317,48343,12,48765,48791,12,49213,49239,12,49661,49687,12,50109,50135,12,50557,50583,12,51005,51031,12,51453,51479,12,51901,51927,12,52349,52375,12,52797,52823,12,53245,53271,12,53693,53719,12,54141,54167,12,54589,54615,12,55037,55063,12,69506,69509,5,70191,70193,5,70841,70841,7,71463,71467,5,72330,72342,5,94031,94031,5,123628,123631,5,127763,127765,14,127941,127941,14,128043,128062,14,128302,128317,14,128465,128467,14,128539,128539,14,128640,128640,14,128662,128662,14,128703,128703,14,128745,128745,14,129004,129007,14,129329,129330,14,129402,129402,14,129483,129483,14,129686,129704,14,130048,131069,14,173,173,4,1757,1757,1,2200,2207,5,2434,2435,7,2631,2632,5,2817,2817,5,3008,3008,5,3201,3201,5,3387,3388,5,3542,3542,5,3902,3903,7,4190,4192,5,6002,6003,5,6439,6440,5,6765,6770,7,7019,7027,5,7154,7155,7,8205,8205,13,8505,8505,14,9654,9654,14,9757,9757,14,9792,9792,14,9852,9853,14,9890,9894,14,9937,9937,14,9981,9981,14,10035,10036,14,11035,11036,14,42654,42655,5,43346,43347,7,43587,43587,5,44006,44007,7,44173,44199,12,44397,44423,12,44621,44647,12,44845,44871,12,45069,45095,12,45293,45319,12,45517,45543,12,45741,45767,12,45965,45991,12,46189,46215,12,46413,46439,12,46637,46663,12,46861,46887,12,47085,47111,12,47309,47335,12,47533,47559,12,47757,47783,12,47981,48007,12,48205,48231,12,48429,48455,12,48653,48679,12,48877,48903,12,49101,49127,12,49325,49351,12,49549,49575,12,49773,49799,12,49997,50023,12,50221,50247,12,50445,50471,12,50669,50695,12,50893,50919,12,51117,51143,12,51341,51367,12,51565,51591,12,51789,51815,12,52013,52039,12,52237,52263,12,52461,52487,12,52685,52711,12,52909,52935,12,53133,53159,12,53357,53383,12,53581,53607,12,53805,53831,12,54029,54055,12,54253,54279,12,54477,54503,12,54701,54727,12,54925,54951,12,55149,55175,12,68101,68102,5,69762,69762,7,70067,70069,7,70371,70378,5,70720,70721,7,71087,71087,5,71341,71341,5,71995,71996,5,72249,72249,7,72850,72871,5,73109,73109,5,118576,118598,5,121505,121519,5,127245,127247,14,127568,127569,14,127777,127777,14,127872,127891,14,127956,127967,14,128015,128016,14,128110,128172,14,128259,128259,14,128367,128368,14,128424,128424,14,128488,128488,14,128530,128532,14,128550,128551,14,128566,128566,14,128647,128647,14,128656,128656,14,128667,128673,14,128691,128693,14,128715,128715,14,128728,128732,14,128752,128752,14,128765,128767,14,129096,129103,14,129311,129311,14,129344,129349,14,129394,129394,14,129413,129425,14,129466,129471,14,129511,129535,14,129664,129666,14,129719,129722,14,129760,129767,14,917536,917631,5,13,13,2,1160,1161,5,1564,1564,4,1807,1807,1,2085,2087,5,2307,2307,7,2382,2383,7,2497,2500,5,2563,2563,7,2677,2677,5,2763,2764,7,2879,2879,5,2914,2915,5,3021,3021,5,3142,3144,5,3263,3263,5,3285,3286,5,3398,3400,7,3530,3530,5,3633,3633,5,3864,3865,5,3974,3975,5,4155,4156,7,4229,4230,5,5909,5909,7,6078,6085,7,6277,6278,5,6451,6456,7,6744,6750,5,6846,6846,5,6972,6972,5,7074,7077,5,7146,7148,7,7222,7223,5,7416,7417,5,8234,8238,4,8417,8417,5,9000,9000,14,9203,9203,14,9730,9731,14,9748,9749,14,9762,9763,14,9776,9783,14,9800,9811,14,9831,9831,14,9872,9873,14,9882,9882,14,9900,9903,14,9929,9933,14,9941,9960,14,9974,9974,14,9989,9989,14,10006,10006,14,10062,10062,14,10160,10160,14,11647,11647,5,12953,12953,14,43019,43019,5,43232,43249,5,43443,43443,5,43567,43568,7,43696,43696,5,43765,43765,7,44013,44013,5,44117,44143,12,44229,44255,12,44341,44367,12,44453,44479,12,44565,44591,12,44677,44703,12,44789,44815,12,44901,44927,12,45013,45039,12,45125,45151,12,45237,45263,12,45349,45375,12,45461,45487,12,45573,45599,12,45685,45711,12,45797,45823,12,45909,45935,12,46021,46047,12,46133,46159,12,46245,46271,12,46357,46383,12,46469,46495,12,46581,46607,12,46693,46719,12,46805,46831,12,46917,46943,12,47029,47055,12,47141,47167,12,47253,47279,12,47365,47391,12,47477,47503,12,47589,47615,12,47701,47727,12,47813,47839,12,47925,47951,12,48037,48063,12,48149,48175,12,48261,48287,12,48373,48399,12,48485,48511,12,48597,48623,12,48709,48735,12,48821,48847,12,48933,48959,12,49045,49071,12,49157,49183,12,49269,49295,12,49381,49407,12,49493,49519,12,49605,49631,12,49717,49743,12,49829,49855,12,49941,49967,12,50053,50079,12,50165,50191,12,50277,50303,12,50389,50415,12,50501,50527,12,50613,50639,12,50725,50751,12,50837,50863,12,50949,50975,12,51061,51087,12,51173,51199,12,51285,51311,12,51397,51423,12,51509,51535,12,51621,51647,12,51733,51759,12,51845,51871,12,51957,51983,12,52069,52095,12,52181,52207,12,52293,52319,12,52405,52431,12,52517,52543,12,52629,52655,12,52741,52767,12,52853,52879,12,52965,52991,12,53077,53103,12,53189,53215,12,53301,53327,12,53413,53439,12,53525,53551,12,53637,53663,12,53749,53775,12,53861,53887,12,53973,53999,12,54085,54111,12,54197,54223,12,54309,54335,12,54421,54447,12,54533,54559,12,54645,54671,12,54757,54783,12,54869,54895,12,54981,55007,12,55093,55119,12,55243,55291,10,66045,66045,5,68325,68326,5,69688,69702,5,69817,69818,5,69957,69958,7,70089,70092,5,70198,70199,5,70462,70462,5,70502,70508,5,70750,70750,5,70846,70846,7,71100,71101,5,71230,71230,7,71351,71351,5,71737,71738,5,72000,72000,7,72160,72160,5,72273,72278,5,72752,72758,5,72882,72883,5,73031,73031,5,73461,73462,7,94192,94193,7,119149,119149,7,121403,121452,5,122915,122916,5,126980,126980,14,127358,127359,14,127535,127535,14,127759,127759,14,127771,127771,14,127792,127793,14,127825,127867,14,127897,127899,14,127945,127945,14,127985,127986,14,128000,128007,14,128021,128021,14,128066,128100,14,128184,128235,14,128249,128252,14,128266,128276,14,128335,128335,14,128379,128390,14,128407,128419,14,128444,128444,14,128481,128481,14,128499,128499,14,128526,128526,14,128536,128536,14,128543,128543,14,128556,128556,14,128564,128564,14,128577,128580,14,128643,128645,14,128649,128649,14,128654,128654,14,128660,128660,14,128664,128664,14,128675,128675,14,128686,128689,14,128695,128696,14,128705,128709,14,128717,128719,14,128725,128725,14,128736,128741,14,128747,128748,14,128755,128755,14,128762,128762,14,128981,128991,14,129009,129023,14,129160,129167,14,129296,129304,14,129320,129327,14,129340,129342,14,129356,129356,14,129388,129392,14,129399,129400,14,129404,129407,14,129432,129442,14,129454,129455,14,129473,129474,14,129485,129487,14,129648,129651,14,129659,129660,14,129671,129679,14,129709,129711,14,129728,129730,14,129751,129753,14,129776,129782,14,917505,917505,4,917760,917999,5,10,10,3,127,159,4,768,879,5,1471,1471,5,1536,1541,1,1648,1648,5,1767,1768,5,1840,1866,5,2070,2073,5,2137,2139,5,2274,2274,1,2363,2363,7,2377,2380,7,2402,2403,5,2494,2494,5,2507,2508,7,2558,2558,5,2622,2624,7,2641,2641,5,2691,2691,7,2759,2760,5,2786,2787,5,2876,2876,5,2881,2884,5,2901,2902,5,3006,3006,5,3014,3016,7,3072,3072,5,3134,3136,5,3157,3158,5,3260,3260,5,3266,3266,5,3274,3275,7,3328,3329,5,3391,3392,7,3405,3405,5,3457,3457,5,3536,3537,7,3551,3551,5,3636,3642,5,3764,3772,5,3895,3895,5,3967,3967,7,3993,4028,5,4146,4151,5,4182,4183,7,4226,4226,5,4253,4253,5,4957,4959,5,5940,5940,7,6070,6070,7,6087,6088,7,6158,6158,4,6432,6434,5,6448,6449,7,6679,6680,5,6742,6742,5,6754,6754,5,6783,6783,5,6912,6915,5,6966,6970,5,6978,6978,5,7042,7042,7,7080,7081,5,7143,7143,7,7150,7150,7,7212,7219,5,7380,7392,5,7412,7412,5,8203,8203,4,8232,8232,4,8265,8265,14,8400,8412,5,8421,8432,5,8617,8618,14,9167,9167,14,9200,9200,14,9410,9410,14,9723,9726,14,9733,9733,14,9745,9745,14,9752,9752,14,9760,9760,14,9766,9766,14,9774,9774,14,9786,9786,14,9794,9794,14,9823,9823,14,9828,9828,14,9833,9850,14,9855,9855,14,9875,9875,14,9880,9880,14,9885,9887,14,9896,9897,14,9906,9916,14,9926,9927,14,9935,9935,14,9939,9939,14,9962,9962,14,9972,9972,14,9978,9978,14,9986,9986,14,9997,9997,14,10002,10002,14,10017,10017,14,10055,10055,14,10071,10071,14,10133,10135,14,10548,10549,14,11093,11093,14,12330,12333,5,12441,12442,5,42608,42610,5,43010,43010,5,43045,43046,5,43188,43203,7,43302,43309,5,43392,43394,5,43446,43449,5,43493,43493,5,43571,43572,7,43597,43597,7,43703,43704,5,43756,43757,5,44003,44004,7,44009,44010,7,44033,44059,12,44089,44115,12,44145,44171,12,44201,44227,12,44257,44283,12,44313,44339,12,44369,44395,12,44425,44451,12,44481,44507,12,44537,44563,12,44593,44619,12,44649,44675,12,44705,44731,12,44761,44787,12,44817,44843,12,44873,44899,12,44929,44955,12,44985,45011,12,45041,45067,12,45097,45123,12,45153,45179,12,45209,45235,12,45265,45291,12,45321,45347,12,45377,45403,12,45433,45459,12,45489,45515,12,45545,45571,12,45601,45627,12,45657,45683,12,45713,45739,12,45769,45795,12,45825,45851,12,45881,45907,12,45937,45963,12,45993,46019,12,46049,46075,12,46105,46131,12,46161,46187,12,46217,46243,12,46273,46299,12,46329,46355,12,46385,46411,12,46441,46467,12,46497,46523,12,46553,46579,12,46609,46635,12,46665,46691,12,46721,46747,12,46777,46803,12,46833,46859,12,46889,46915,12,46945,46971,12,47001,47027,12,47057,47083,12,47113,47139,12,47169,47195,12,47225,47251,12,47281,47307,12,47337,47363,12,47393,47419,12,47449,47475,12,47505,47531,12,47561,47587,12,47617,47643,12,47673,47699,12,47729,47755,12,47785,47811,12,47841,47867,12,47897,47923,12,47953,47979,12,48009,48035,12,48065,48091,12,48121,48147,12,48177,48203,12,48233,48259,12,48289,48315,12,48345,48371,12,48401,48427,12,48457,48483,12,48513,48539,12,48569,48595,12,48625,48651,12,48681,48707,12,48737,48763,12,48793,48819,12,48849,48875,12,48905,48931,12,48961,48987,12,49017,49043,12,49073,49099,12,49129,49155,12,49185,49211,12,49241,49267,12,49297,49323,12,49353,49379,12,49409,49435,12,49465,49491,12,49521,49547,12,49577,49603,12,49633,49659,12,49689,49715,12,49745,49771,12,49801,49827,12,49857,49883,12,49913,49939,12,49969,49995,12,50025,50051,12,50081,50107,12,50137,50163,12,50193,50219,12,50249,50275,12,50305,50331,12,50361,50387,12,50417,50443,12,50473,50499,12,50529,50555,12,50585,50611,12,50641,50667,12,50697,50723,12,50753,50779,12,50809,50835,12,50865,50891,12,50921,50947,12,50977,51003,12,51033,51059,12,51089,51115,12,51145,51171,12,51201,51227,12,51257,51283,12,51313,51339,12,51369,51395,12,51425,51451,12,51481,51507,12,51537,51563,12,51593,51619,12,51649,51675,12,51705,51731,12,51761,51787,12,51817,51843,12,51873,51899,12,51929,51955,12,51985,52011,12,52041,52067,12,52097,52123,12,52153,52179,12,52209,52235,12,52265,52291,12,52321,52347,12,52377,52403,12,52433,52459,12,52489,52515,12,52545,52571,12,52601,52627,12,52657,52683,12,52713,52739,12,52769,52795,12,52825,52851,12,52881,52907,12,52937,52963,12,52993,53019,12,53049,53075,12,53105,53131,12,53161,53187,12,53217,53243,12,53273,53299,12,53329,53355,12,53385,53411,12,53441,53467,12,53497,53523,12,53553,53579,12,53609,53635,12,53665,53691,12,53721,53747,12,53777,53803,12,53833,53859,12,53889,53915,12,53945,53971,12,54001,54027,12,54057,54083,12,54113,54139,12,54169,54195,12,54225,54251,12,54281,54307,12,54337,54363,12,54393,54419,12,54449,54475,12,54505,54531,12,54561,54587,12,54617,54643,12,54673,54699,12,54729,54755,12,54785,54811,12,54841,54867,12,54897,54923,12,54953,54979,12,55009,55035,12,55065,55091,12,55121,55147,12,55177,55203,12,65024,65039,5,65520,65528,4,66422,66426,5,68152,68154,5,69291,69292,5,69633,69633,5,69747,69748,5,69811,69814,5,69826,69826,5,69932,69932,7,70016,70017,5,70079,70080,7,70095,70095,5,70196,70196,5,70367,70367,5,70402,70403,7,70464,70464,5,70487,70487,5,70709,70711,7,70725,70725,7,70833,70834,7,70843,70844,7,70849,70849,7,71090,71093,5,71103,71104,5,71227,71228,7,71339,71339,5,71344,71349,5,71458,71461,5,71727,71735,5,71985,71989,7,71998,71998,5,72002,72002,7,72154,72155,5,72193,72202,5,72251,72254,5,72281,72283,5,72344,72345,5,72766,72766,7,72874,72880,5,72885,72886,5,73023,73029,5,73104,73105,5,73111,73111,5,92912,92916,5,94095,94098,5,113824,113827,4,119142,119142,7,119155,119162,4,119362,119364,5,121476,121476,5,122888,122904,5,123184,123190,5,125252,125258,5,127183,127183,14,127340,127343,14,127377,127386,14,127491,127503,14,127548,127551,14,127744,127756,14,127761,127761,14,127769,127769,14,127773,127774,14,127780,127788,14,127796,127797,14,127820,127823,14,127869,127869,14,127894,127895,14,127902,127903,14,127943,127943,14,127947,127950,14,127972,127972,14,127988,127988,14,127992,127994,14,128009,128011,14,128019,128019,14,128023,128041,14,128064,128064,14,128102,128107,14,128174,128181,14,128238,128238,14,128246,128247,14,128254,128254,14,128264,128264,14,128278,128299,14,128329,128330,14,128348,128359,14,128371,128377,14,128392,128393,14,128401,128404,14,128421,128421,14,128433,128434,14,128450,128452,14,128476,128478,14,128483,128483,14,128495,128495,14,128506,128506,14,128519,128520,14,128528,128528,14,128534,128534,14,128538,128538,14,128540,128542,14,128544,128549,14,128552,128555,14,128557,128557,14,128560,128563,14,128565,128565,14,128567,128576,14,128581,128591,14,128641,128642,14,128646,128646,14,128648,128648,14,128650,128651,14,128653,128653,14,128655,128655,14,128657,128659,14,128661,128661,14,128663,128663,14,128665,128666,14,128674,128674,14,128676,128677,14,128679,128685,14,128690,128690,14,128694,128694,14,128697,128702,14,128704,128704,14,128710,128714,14,128716,128716,14,128720,128720,14,128723,128724,14,128726,128727,14,128733,128735,14,128742,128744,14,128746,128746,14,128749,128751,14,128753,128754,14,128756,128758,14,128761,128761,14,128763,128764,14,128884,128895,14,128992,129003,14,129008,129008,14,129036,129039,14,129114,129119,14,129198,129279,14,129293,129295,14,129305,129310,14,129312,129319,14,129328,129328,14,129331,129338,14,129343,129343,14,129351,129355,14,129357,129359,14,129375,129387,14,129393,129393,14,129395,129398,14,129401,129401,14,129403,129403,14,129408,129412,14,129426,129431,14,129443,129444,14,129451,129453,14,129456,129465,14,129472,129472,14,129475,129482,14,129484,129484,14,129488,129510,14,129536,129647,14,129652,129652,14,129656,129658,14,129661,129663,14,129667,129670,14,129680,129685,14,129705,129708,14,129712,129718,14,129723,129727,14,129731,129733,14,129744,129750,14,129754,129759,14,129768,129775,14,129783,129791,14,917504,917504,4,917506,917535,4,917632,917759,4,918000,921599,4,0,9,4,11,12,4,14,31,4,169,169,14,174,174,14,1155,1159,5,1425,1469,5,1473,1474,5,1479,1479,5,1552,1562,5,1611,1631,5,1750,1756,5,1759,1764,5,1770,1773,5,1809,1809,5,1958,1968,5,2045,2045,5,2075,2083,5,2089,2093,5,2192,2193,1,2250,2273,5,2275,2306,5,2362,2362,5,2364,2364,5,2369,2376,5,2381,2381,5,2385,2391,5,2433,2433,5,2492,2492,5,2495,2496,7,2503,2504,7,2509,2509,5,2530,2531,5,2561,2562,5,2620,2620,5,2625,2626,5,2635,2637,5,2672,2673,5,2689,2690,5,2748,2748,5,2753,2757,5,2761,2761,7,2765,2765,5,2810,2815,5,2818,2819,7,2878,2878,5,2880,2880,7,2887,2888,7,2893,2893,5,2903,2903,5,2946,2946,5,3007,3007,7,3009,3010,7,3018,3020,7,3031,3031,5,3073,3075,7,3132,3132,5,3137,3140,7,3146,3149,5,3170,3171,5,3202,3203,7,3262,3262,7,3264,3265,7,3267,3268,7,3271,3272,7,3276,3277,5,3298,3299,5,3330,3331,7,3390,3390,5,3393,3396,5,3402,3404,7,3406,3406,1,3426,3427,5,3458,3459,7,3535,3535,5,3538,3540,5,3544,3550,7,3570,3571,7,3635,3635,7,3655,3662,5,3763,3763,7,3784,3789,5,3893,3893,5,3897,3897,5,3953,3966,5,3968,3972,5,3981,3991,5,4038,4038,5,4145,4145,7,4153,4154,5,4157,4158,5,4184,4185,5,4209,4212,5,4228,4228,7,4237,4237,5,4352,4447,8,4520,4607,10,5906,5908,5,5938,5939,5,5970,5971,5,6068,6069,5,6071,6077,5,6086,6086,5,6089,6099,5,6155,6157,5,6159,6159,5,6313,6313,5,6435,6438,7,6441,6443,7,6450,6450,5,6457,6459,5,6681,6682,7,6741,6741,7,6743,6743,7,6752,6752,5,6757,6764,5,6771,6780,5,6832,6845,5,6847,6862,5,6916,6916,7,6965,6965,5,6971,6971,7,6973,6977,7,6979,6980,7,7040,7041,5,7073,7073,7,7078,7079,7,7082,7082,7,7142,7142,5,7144,7145,5,7149,7149,5,7151,7153,5,7204,7211,7,7220,7221,7,7376,7378,5,7393,7393,7,7405,7405,5,7415,7415,7,7616,7679,5,8204,8204,5,8206,8207,4,8233,8233,4,8252,8252,14,8288,8292,4,8294,8303,4,8413,8416,5,8418,8420,5,8482,8482,14,8596,8601,14,8986,8987,14,9096,9096,14,9193,9196,14,9199,9199,14,9201,9202,14,9208,9210,14,9642,9643,14,9664,9664,14,9728,9729,14,9732,9732,14,9735,9741,14,9743,9744,14,9746,9746,14,9750,9751,14,9753,9756,14,9758,9759,14,9761,9761,14,9764,9765,14,9767,9769,14,9771,9773,14,9775,9775,14,9784,9785,14,9787,9791,14,9793,9793,14,9795,9799,14,9812,9822,14,9824,9824,14,9827,9827,14,9829,9830,14,9832,9832,14,9851,9851,14,9854,9854,14,9856,9861,14,9874,9874,14,9876,9876,14,9878,9879,14,9881,9881,14,9883,9884,14,9888,9889,14,9895,9895,14,9898,9899,14,9904,9905,14,9917,9918,14,9924,9925,14,9928,9928,14,9934,9934,14,9936,9936,14,9938,9938,14,9940,9940,14,9961,9961,14,9963,9967,14,9970,9971,14,9973,9973,14,9975,9977,14,9979,9980,14,9982,9985,14,9987,9988,14,9992,9996,14,9998,9998,14,10000,10001,14,10004,10004,14,10013,10013,14,10024,10024,14,10052,10052,14,10060,10060,14,10067,10069,14,10083,10083,14,10085,10087,14,10145,10145,14,10175,10175,14,11013,11015,14,11088,11088,14,11503,11505,5,11744,11775,5,12334,12335,5,12349,12349,14,12951,12951,14,42607,42607,5,42612,42621,5,42736,42737,5,43014,43014,5,43043,43044,7,43047,43047,7,43136,43137,7,43204,43205,5,43263,43263,5,43335,43345,5,43360,43388,8,43395,43395,7,43444,43445,7,43450,43451,7,43454,43456,7,43561,43566,5,43569,43570,5,43573,43574,5,43596,43596,5,43644,43644,5,43698,43700,5,43710,43711,5,43755,43755,7,43758,43759,7,43766,43766,5,44005,44005,5,44008,44008,5,44012,44012,7,44032,44032,11,44060,44060,11,44088,44088,11,44116,44116,11,44144,44144,11,44172,44172,11,44200,44200,11,44228,44228,11,44256,44256,11,44284,44284,11,44312,44312,11,44340,44340,11,44368,44368,11,44396,44396,11,44424,44424,11,44452,44452,11,44480,44480,11,44508,44508,11,44536,44536,11,44564,44564,11,44592,44592,11,44620,44620,11,44648,44648,11,44676,44676,11,44704,44704,11,44732,44732,11,44760,44760,11,44788,44788,11,44816,44816,11,44844,44844,11,44872,44872,11,44900,44900,11,44928,44928,11,44956,44956,11,44984,44984,11,45012,45012,11,45040,45040,11,45068,45068,11,45096,45096,11,45124,45124,11,45152,45152,11,45180,45180,11,45208,45208,11,45236,45236,11,45264,45264,11,45292,45292,11,45320,45320,11,45348,45348,11,45376,45376,11,45404,45404,11,45432,45432,11,45460,45460,11,45488,45488,11,45516,45516,11,45544,45544,11,45572,45572,11,45600,45600,11,45628,45628,11,45656,45656,11,45684,45684,11,45712,45712,11,45740,45740,11,45768,45768,11,45796,45796,11,45824,45824,11,45852,45852,11,45880,45880,11,45908,45908,11,45936,45936,11,45964,45964,11,45992,45992,11,46020,46020,11,46048,46048,11,46076,46076,11,46104,46104,11,46132,46132,11,46160,46160,11,46188,46188,11,46216,46216,11,46244,46244,11,46272,46272,11,46300,46300,11,46328,46328,11,46356,46356,11,46384,46384,11,46412,46412,11,46440,46440,11,46468,46468,11,46496,46496,11,46524,46524,11,46552,46552,11,46580,46580,11,46608,46608,11,46636,46636,11,46664,46664,11,46692,46692,11,46720,46720,11,46748,46748,11,46776,46776,11,46804,46804,11,46832,46832,11,46860,46860,11,46888,46888,11,46916,46916,11,46944,46944,11,46972,46972,11,47000,47000,11,47028,47028,11,47056,47056,11,47084,47084,11,47112,47112,11,47140,47140,11,47168,47168,11,47196,47196,11,47224,47224,11,47252,47252,11,47280,47280,11,47308,47308,11,47336,47336,11,47364,47364,11,47392,47392,11,47420,47420,11,47448,47448,11,47476,47476,11,47504,47504,11,47532,47532,11,47560,47560,11,47588,47588,11,47616,47616,11,47644,47644,11,47672,47672,11,47700,47700,11,47728,47728,11,47756,47756,11,47784,47784,11,47812,47812,11,47840,47840,11,47868,47868,11,47896,47896,11,47924,47924,11,47952,47952,11,47980,47980,11,48008,48008,11,48036,48036,11,48064,48064,11,48092,48092,11,48120,48120,11,48148,48148,11,48176,48176,11,48204,48204,11,48232,48232,11,48260,48260,11,48288,48288,11,48316,48316,11,48344,48344,11,48372,48372,11,48400,48400,11,48428,48428,11,48456,48456,11,48484,48484,11,48512,48512,11,48540,48540,11,48568,48568,11,48596,48596,11,48624,48624,11,48652,48652,11,48680,48680,11,48708,48708,11,48736,48736,11,48764,48764,11,48792,48792,11,48820,48820,11,48848,48848,11,48876,48876,11,48904,48904,11,48932,48932,11,48960,48960,11,48988,48988,11,49016,49016,11,49044,49044,11,49072,49072,11,49100,49100,11,49128,49128,11,49156,49156,11,49184,49184,11,49212,49212,11,49240,49240,11,49268,49268,11,49296,49296,11,49324,49324,11,49352,49352,11,49380,49380,11,49408,49408,11,49436,49436,11,49464,49464,11,49492,49492,11,49520,49520,11,49548,49548,11,49576,49576,11,49604,49604,11,49632,49632,11,49660,49660,11,49688,49688,11,49716,49716,11,49744,49744,11,49772,49772,11,49800,49800,11,49828,49828,11,49856,49856,11,49884,49884,11,49912,49912,11,49940,49940,11,49968,49968,11,49996,49996,11,50024,50024,11,50052,50052,11,50080,50080,11,50108,50108,11,50136,50136,11,50164,50164,11,50192,50192,11,50220,50220,11,50248,50248,11,50276,50276,11,50304,50304,11,50332,50332,11,50360,50360,11,50388,50388,11,50416,50416,11,50444,50444,11,50472,50472,11,50500,50500,11,50528,50528,11,50556,50556,11,50584,50584,11,50612,50612,11,50640,50640,11,50668,50668,11,50696,50696,11,50724,50724,11,50752,50752,11,50780,50780,11,50808,50808,11,50836,50836,11,50864,50864,11,50892,50892,11,50920,50920,11,50948,50948,11,50976,50976,11,51004,51004,11,51032,51032,11,51060,51060,11,51088,51088,11,51116,51116,11,51144,51144,11,51172,51172,11,51200,51200,11,51228,51228,11,51256,51256,11,51284,51284,11,51312,51312,11,51340,51340,11,51368,51368,11,51396,51396,11,51424,51424,11,51452,51452,11,51480,51480,11,51508,51508,11,51536,51536,11,51564,51564,11,51592,51592,11,51620,51620,11,51648,51648,11,51676,51676,11,51704,51704,11,51732,51732,11,51760,51760,11,51788,51788,11,51816,51816,11,51844,51844,11,51872,51872,11,51900,51900,11,51928,51928,11,51956,51956,11,51984,51984,11,52012,52012,11,52040,52040,11,52068,52068,11,52096,52096,11,52124,52124,11,52152,52152,11,52180,52180,11,52208,52208,11,52236,52236,11,52264,52264,11,52292,52292,11,52320,52320,11,52348,52348,11,52376,52376,11,52404,52404,11,52432,52432,11,52460,52460,11,52488,52488,11,52516,52516,11,52544,52544,11,52572,52572,11,52600,52600,11,52628,52628,11,52656,52656,11,52684,52684,11,52712,52712,11,52740,52740,11,52768,52768,11,52796,52796,11,52824,52824,11,52852,52852,11,52880,52880,11,52908,52908,11,52936,52936,11,52964,52964,11,52992,52992,11,53020,53020,11,53048,53048,11,53076,53076,11,53104,53104,11,53132,53132,11,53160,53160,11,53188,53188,11,53216,53216,11,53244,53244,11,53272,53272,11,53300,53300,11,53328,53328,11,53356,53356,11,53384,53384,11,53412,53412,11,53440,53440,11,53468,53468,11,53496,53496,11,53524,53524,11,53552,53552,11,53580,53580,11,53608,53608,11,53636,53636,11,53664,53664,11,53692,53692,11,53720,53720,11,53748,53748,11,53776,53776,11,53804,53804,11,53832,53832,11,53860,53860,11,53888,53888,11,53916,53916,11,53944,53944,11,53972,53972,11,54000,54000,11,54028,54028,11,54056,54056,11,54084,54084,11,54112,54112,11,54140,54140,11,54168,54168,11,54196,54196,11,54224,54224,11,54252,54252,11,54280,54280,11,54308,54308,11,54336,54336,11,54364,54364,11,54392,54392,11,54420,54420,11,54448,54448,11,54476,54476,11,54504,54504,11,54532,54532,11,54560,54560,11,54588,54588,11,54616,54616,11,54644,54644,11,54672,54672,11,54700,54700,11,54728,54728,11,54756,54756,11,54784,54784,11,54812,54812,11,54840,54840,11,54868,54868,11,54896,54896,11,54924,54924,11,54952,54952,11,54980,54980,11,55008,55008,11,55036,55036,11,55064,55064,11,55092,55092,11,55120,55120,11,55148,55148,11,55176,55176,11,55216,55238,9,64286,64286,5,65056,65071,5,65438,65439,5,65529,65531,4,66272,66272,5,68097,68099,5,68108,68111,5,68159,68159,5,68900,68903,5,69446,69456,5,69632,69632,7,69634,69634,7,69744,69744,5,69759,69761,5,69808,69810,7,69815,69816,7,69821,69821,1,69837,69837,1,69927,69931,5,69933,69940,5,70003,70003,5,70018,70018,7,70070,70078,5,70082,70083,1,70094,70094,7,70188,70190,7,70194,70195,7,70197,70197,7,70206,70206,5,70368,70370,7,70400,70401,5,70459,70460,5,70463,70463,7,70465,70468,7,70475,70477,7,70498,70499,7,70512,70516,5,70712,70719,5,70722,70724,5,70726,70726,5,70832,70832,5,70835,70840,5,70842,70842,5,70845,70845,5,70847,70848,5,70850,70851,5,71088,71089,7,71096,71099,7,71102,71102,7,71132,71133,5,71219,71226,5,71229,71229,5,71231,71232,5,71340,71340,7,71342,71343,7,71350,71350,7,71453,71455,5,71462,71462,7,71724,71726,7,71736,71736,7,71984,71984,5,71991,71992,7,71997,71997,7,71999,71999,1,72001,72001,1,72003,72003,5,72148,72151,5,72156,72159,7,72164,72164,7,72243,72248,5,72250,72250,1,72263,72263,5,72279,72280,7,72324,72329,1,72343,72343,7,72751,72751,7,72760,72765,5,72767,72767,5,72873,72873,7,72881,72881,7,72884,72884,7,73009,73014,5,73020,73021,5,73030,73030,1,73098,73102,7,73107,73108,7,73110,73110,7,73459,73460,5,78896,78904,4,92976,92982,5,94033,94087,7,94180,94180,5,113821,113822,5,118528,118573,5,119141,119141,5,119143,119145,5,119150,119154,5,119163,119170,5,119210,119213,5,121344,121398,5,121461,121461,5,121499,121503,5,122880,122886,5,122907,122913,5,122918,122922,5,123566,123566,5,125136,125142,5,126976,126979,14,126981,127182,14,127184,127231,14,127279,127279,14,127344,127345,14,127374,127374,14,127405,127461,14,127489,127490,14,127514,127514,14,127538,127546,14,127561,127567,14,127570,127743,14,127757,127758,14,127760,127760,14,127762,127762,14,127766,127768,14,127770,127770,14,127772,127772,14,127775,127776,14,127778,127779,14,127789,127791,14,127794,127795,14,127798,127798,14,127819,127819,14,127824,127824,14,127868,127868,14,127870,127871,14,127892,127893,14,127896,127896,14,127900,127901,14,127904,127940,14,127942,127942,14,127944,127944,14,127946,127946,14,127951,127955,14,127968,127971,14,127973,127984,14,127987,127987,14,127989,127989,14,127991,127991,14,127995,127999,5,128008,128008,14,128012,128014,14,128017,128018,14,128020,128020,14,128022,128022,14,128042,128042,14,128063,128063,14,128065,128065,14,128101,128101,14,128108,128109,14,128173,128173,14,128182,128183,14,128236,128237,14,128239,128239,14,128245,128245,14,128248,128248,14,128253,128253,14,128255,128258,14,128260,128263,14,128265,128265,14,128277,128277,14,128300,128301,14,128326,128328,14,128331,128334,14,128336,128347,14,128360,128366,14,128369,128370,14,128378,128378,14,128391,128391,14,128394,128397,14,128400,128400,14,128405,128406,14,128420,128420,14,128422,128423,14,128425,128432,14,128435,128443,14,128445,128449,14,128453,128464,14,128468,128475,14,128479,128480,14,128482,128482,14,128484,128487,14,128489,128494,14,128496,128498,14,128500,128505,14,128507,128511,14,128513,128518,14,128521,128525,14,128527,128527,14,128529,128529,14,128533,128533,14,128535,128535,14,128537,128537,14]'); } //#endregion /** * Computes the offset after performing a left delete on the given string, * while considering unicode grapheme/emoji rules. */ function getLeftDeleteOffset(offset, str) { if (offset === 0) { return 0; } // Try to delete emoji part. const emojiOffset = getOffsetBeforeLastEmojiComponent(offset, str); if (emojiOffset !== undefined) { return emojiOffset; } // Otherwise, just skip a single code point. const iterator = new CodePointIterator(str, offset); iterator.prevCodePoint(); return iterator.offset; } function getOffsetBeforeLastEmojiComponent(initialOffset, str) { // See https://www.unicode.org/reports/tr51/tr51-14.html#EBNF_and_Regex for the // structure of emojis. const iterator = new CodePointIterator(str, initialOffset); let codePoint = iterator.prevCodePoint(); // Skip modifiers while ((isEmojiModifier(codePoint) || codePoint === 65039 /* emojiVariantSelector */ || codePoint === 8419 /* enclosingKeyCap */)) { if (iterator.offset === 0) { // Cannot skip modifier, no preceding emoji base. return undefined; } codePoint = iterator.prevCodePoint(); } // Expect base emoji if (!isEmojiImprecise(codePoint)) { // Unexpected code point, not a valid emoji. return undefined; } let resultOffset = iterator.offset; if (resultOffset > 0) { // Skip optional ZWJ code points that combine multiple emojis. // In theory, we should check if that ZWJ actually combines multiple emojis // to prevent deleting ZWJs in situations we didn't account for. const optionalZwjCodePoint = iterator.prevCodePoint(); if (optionalZwjCodePoint === 8205 /* zwj */) { resultOffset = iterator.offset; } } return resultOffset; } function isEmojiModifier(codePoint) { return 0x1F3FB <= codePoint && codePoint <= 0x1F3FF; } const noBreakWhitespace = '\xa0'; class AmbiguousCharacters { constructor(confusableDictionary) { this.confusableDictionary = confusableDictionary; } static getInstance(locales) { return AmbiguousCharacters.cache.get(Array.from(locales)); } static getLocales() { return AmbiguousCharacters._locales.getValue(); } isAmbiguous(codePoint) { return this.confusableDictionary.has(codePoint); } /** * Returns the non basic ASCII code point that the given code point can be confused, * or undefined if such code point does note exist. */ getPrimaryConfusable(codePoint) { return this.confusableDictionary.get(codePoint); } getConfusableCodePoints() { return new Set(this.confusableDictionary.keys()); } } _a$c = AmbiguousCharacters; AmbiguousCharacters.ambiguousCharacterData = new Lazy(() => { // Generated using https://github.com/hediet/vscode-unicode-data // Stored as key1, value1, key2, value2, ... return JSON.parse('{\"_common\":[8232,32,8233,32,5760,32,8192,32,8193,32,8194,32,8195,32,8196,32,8197,32,8198,32,8200,32,8201,32,8202,32,8287,32,8199,32,8239,32,2042,95,65101,95,65102,95,65103,95,8208,45,8209,45,8210,45,65112,45,1748,45,8259,45,727,45,8722,45,10134,45,11450,45,1549,44,1643,44,8218,44,184,44,42233,44,894,59,2307,58,2691,58,1417,58,1795,58,1796,58,5868,58,65072,58,6147,58,6153,58,8282,58,1475,58,760,58,42889,58,8758,58,720,58,42237,58,451,33,11601,33,660,63,577,63,2429,63,5038,63,42731,63,119149,46,8228,46,1793,46,1794,46,42510,46,68176,46,1632,46,1776,46,42232,46,1373,96,65287,96,8219,96,8242,96,1370,96,1523,96,8175,96,65344,96,900,96,8189,96,8125,96,8127,96,8190,96,697,96,884,96,712,96,714,96,715,96,756,96,699,96,701,96,700,96,702,96,42892,96,1497,96,2036,96,2037,96,5194,96,5836,96,94033,96,94034,96,65339,91,10088,40,10098,40,12308,40,64830,40,65341,93,10089,41,10099,41,12309,41,64831,41,10100,123,119060,123,10101,125,65342,94,8270,42,1645,42,8727,42,66335,42,5941,47,8257,47,8725,47,8260,47,9585,47,10187,47,10744,47,119354,47,12755,47,12339,47,11462,47,20031,47,12035,47,65340,92,65128,92,8726,92,10189,92,10741,92,10745,92,119311,92,119355,92,12756,92,20022,92,12034,92,42872,38,708,94,710,94,5869,43,10133,43,66203,43,8249,60,10094,60,706,60,119350,60,5176,60,5810,60,5120,61,11840,61,12448,61,42239,61,8250,62,10095,62,707,62,119351,62,5171,62,94015,62,8275,126,732,126,8128,126,8764,126,65372,124,65293,45,120784,50,120794,50,120804,50,120814,50,120824,50,130034,50,42842,50,423,50,1000,50,42564,50,5311,50,42735,50,119302,51,120785,51,120795,51,120805,51,120815,51,120825,51,130035,51,42923,51,540,51,439,51,42858,51,11468,51,1248,51,94011,51,71882,51,120786,52,120796,52,120806,52,120816,52,120826,52,130036,52,5070,52,71855,52,120787,53,120797,53,120807,53,120817,53,120827,53,130037,53,444,53,71867,53,120788,54,120798,54,120808,54,120818,54,120828,54,130038,54,11474,54,5102,54,71893,54,119314,55,120789,55,120799,55,120809,55,120819,55,120829,55,130039,55,66770,55,71878,55,2819,56,2538,56,2666,56,125131,56,120790,56,120800,56,120810,56,120820,56,120830,56,130040,56,547,56,546,56,66330,56,2663,57,2920,57,2541,57,3437,57,120791,57,120801,57,120811,57,120821,57,120831,57,130041,57,42862,57,11466,57,71884,57,71852,57,71894,57,9082,97,65345,97,119834,97,119886,97,119938,97,119990,97,120042,97,120094,97,120146,97,120198,97,120250,97,120302,97,120354,97,120406,97,120458,97,593,97,945,97,120514,97,120572,97,120630,97,120688,97,120746,97,65313,65,119808,65,119860,65,119912,65,119964,65,120016,65,120068,65,120120,65,120172,65,120224,65,120276,65,120328,65,120380,65,120432,65,913,65,120488,65,120546,65,120604,65,120662,65,120720,65,5034,65,5573,65,42222,65,94016,65,66208,65,119835,98,119887,98,119939,98,119991,98,120043,98,120095,98,120147,98,120199,98,120251,98,120303,98,120355,98,120407,98,120459,98,388,98,5071,98,5234,98,5551,98,65314,66,8492,66,119809,66,119861,66,119913,66,120017,66,120069,66,120121,66,120173,66,120225,66,120277,66,120329,66,120381,66,120433,66,42932,66,914,66,120489,66,120547,66,120605,66,120663,66,120721,66,5108,66,5623,66,42192,66,66178,66,66209,66,66305,66,65347,99,8573,99,119836,99,119888,99,119940,99,119992,99,120044,99,120096,99,120148,99,120200,99,120252,99,120304,99,120356,99,120408,99,120460,99,7428,99,1010,99,11429,99,43951,99,66621,99,128844,67,71922,67,71913,67,65315,67,8557,67,8450,67,8493,67,119810,67,119862,67,119914,67,119966,67,120018,67,120174,67,120226,67,120278,67,120330,67,120382,67,120434,67,1017,67,11428,67,5087,67,42202,67,66210,67,66306,67,66581,67,66844,67,8574,100,8518,100,119837,100,119889,100,119941,100,119993,100,120045,100,120097,100,120149,100,120201,100,120253,100,120305,100,120357,100,120409,100,120461,100,1281,100,5095,100,5231,100,42194,100,8558,68,8517,68,119811,68,119863,68,119915,68,119967,68,120019,68,120071,68,120123,68,120175,68,120227,68,120279,68,120331,68,120383,68,120435,68,5024,68,5598,68,5610,68,42195,68,8494,101,65349,101,8495,101,8519,101,119838,101,119890,101,119942,101,120046,101,120098,101,120150,101,120202,101,120254,101,120306,101,120358,101,120410,101,120462,101,43826,101,1213,101,8959,69,65317,69,8496,69,119812,69,119864,69,119916,69,120020,69,120072,69,120124,69,120176,69,120228,69,120280,69,120332,69,120384,69,120436,69,917,69,120492,69,120550,69,120608,69,120666,69,120724,69,11577,69,5036,69,42224,69,71846,69,71854,69,66182,69,119839,102,119891,102,119943,102,119995,102,120047,102,120099,102,120151,102,120203,102,120255,102,120307,102,120359,102,120411,102,120463,102,43829,102,42905,102,383,102,7837,102,1412,102,119315,70,8497,70,119813,70,119865,70,119917,70,120021,70,120073,70,120125,70,120177,70,120229,70,120281,70,120333,70,120385,70,120437,70,42904,70,988,70,120778,70,5556,70,42205,70,71874,70,71842,70,66183,70,66213,70,66853,70,65351,103,8458,103,119840,103,119892,103,119944,103,120048,103,120100,103,120152,103,120204,103,120256,103,120308,103,120360,103,120412,103,120464,103,609,103,7555,103,397,103,1409,103,119814,71,119866,71,119918,71,119970,71,120022,71,120074,71,120126,71,120178,71,120230,71,120282,71,120334,71,120386,71,120438,71,1292,71,5056,71,5107,71,42198,71,65352,104,8462,104,119841,104,119945,104,119997,104,120049,104,120101,104,120153,104,120205,104,120257,104,120309,104,120361,104,120413,104,120465,104,1211,104,1392,104,5058,104,65320,72,8459,72,8460,72,8461,72,119815,72,119867,72,119919,72,120023,72,120179,72,120231,72,120283,72,120335,72,120387,72,120439,72,919,72,120494,72,120552,72,120610,72,120668,72,120726,72,11406,72,5051,72,5500,72,42215,72,66255,72,731,105,9075,105,65353,105,8560,105,8505,105,8520,105,119842,105,119894,105,119946,105,119998,105,120050,105,120102,105,120154,105,120206,105,120258,105,120310,105,120362,105,120414,105,120466,105,120484,105,618,105,617,105,953,105,8126,105,890,105,120522,105,120580,105,120638,105,120696,105,120754,105,1110,105,42567,105,1231,105,43893,105,5029,105,71875,105,65354,106,8521,106,119843,106,119895,106,119947,106,119999,106,120051,106,120103,106,120155,106,120207,106,120259,106,120311,106,120363,106,120415,106,120467,106,1011,106,1112,106,65322,74,119817,74,119869,74,119921,74,119973,74,120025,74,120077,74,120129,74,120181,74,120233,74,120285,74,120337,74,120389,74,120441,74,42930,74,895,74,1032,74,5035,74,5261,74,42201,74,119844,107,119896,107,119948,107,120000,107,120052,107,120104,107,120156,107,120208,107,120260,107,120312,107,120364,107,120416,107,120468,107,8490,75,65323,75,119818,75,119870,75,119922,75,119974,75,120026,75,120078,75,120130,75,120182,75,120234,75,120286,75,120338,75,120390,75,120442,75,922,75,120497,75,120555,75,120613,75,120671,75,120729,75,11412,75,5094,75,5845,75,42199,75,66840,75,1472,108,8739,73,9213,73,65512,73,1633,108,1777,73,66336,108,125127,108,120783,73,120793,73,120803,73,120813,73,120823,73,130033,73,65321,73,8544,73,8464,73,8465,73,119816,73,119868,73,119920,73,120024,73,120128,73,120180,73,120232,73,120284,73,120336,73,120388,73,120440,73,65356,108,8572,73,8467,108,119845,108,119897,108,119949,108,120001,108,120053,108,120105,73,120157,73,120209,73,120261,73,120313,73,120365,73,120417,73,120469,73,448,73,120496,73,120554,73,120612,73,120670,73,120728,73,11410,73,1030,73,1216,73,1493,108,1503,108,1575,108,126464,108,126592,108,65166,108,65165,108,1994,108,11599,73,5825,73,42226,73,93992,73,66186,124,66313,124,119338,76,8556,76,8466,76,119819,76,119871,76,119923,76,120027,76,120079,76,120131,76,120183,76,120235,76,120287,76,120339,76,120391,76,120443,76,11472,76,5086,76,5290,76,42209,76,93974,76,71843,76,71858,76,66587,76,66854,76,65325,77,8559,77,8499,77,119820,77,119872,77,119924,77,120028,77,120080,77,120132,77,120184,77,120236,77,120288,77,120340,77,120392,77,120444,77,924,77,120499,77,120557,77,120615,77,120673,77,120731,77,1018,77,11416,77,5047,77,5616,77,5846,77,42207,77,66224,77,66321,77,119847,110,119899,110,119951,110,120003,110,120055,110,120107,110,120159,110,120211,110,120263,110,120315,110,120367,110,120419,110,120471,110,1400,110,1404,110,65326,78,8469,78,119821,78,119873,78,119925,78,119977,78,120029,78,120081,78,120185,78,120237,78,120289,78,120341,78,120393,78,120445,78,925,78,120500,78,120558,78,120616,78,120674,78,120732,78,11418,78,42208,78,66835,78,3074,111,3202,111,3330,111,3458,111,2406,111,2662,111,2790,111,3046,111,3174,111,3302,111,3430,111,3664,111,3792,111,4160,111,1637,111,1781,111,65359,111,8500,111,119848,111,119900,111,119952,111,120056,111,120108,111,120160,111,120212,111,120264,111,120316,111,120368,111,120420,111,120472,111,7439,111,7441,111,43837,111,959,111,120528,111,120586,111,120644,111,120702,111,120760,111,963,111,120532,111,120590,111,120648,111,120706,111,120764,111,11423,111,4351,111,1413,111,1505,111,1607,111,126500,111,126564,111,126596,111,65259,111,65260,111,65258,111,65257,111,1726,111,64428,111,64429,111,64427,111,64426,111,1729,111,64424,111,64425,111,64423,111,64422,111,1749,111,3360,111,4125,111,66794,111,71880,111,71895,111,66604,111,1984,79,2534,79,2918,79,12295,79,70864,79,71904,79,120782,79,120792,79,120802,79,120812,79,120822,79,130032,79,65327,79,119822,79,119874,79,119926,79,119978,79,120030,79,120082,79,120134,79,120186,79,120238,79,120290,79,120342,79,120394,79,120446,79,927,79,120502,79,120560,79,120618,79,120676,79,120734,79,11422,79,1365,79,11604,79,4816,79,2848,79,66754,79,42227,79,71861,79,66194,79,66219,79,66564,79,66838,79,9076,112,65360,112,119849,112,119901,112,119953,112,120005,112,120057,112,120109,112,120161,112,120213,112,120265,112,120317,112,120369,112,120421,112,120473,112,961,112,120530,112,120544,112,120588,112,120602,112,120646,112,120660,112,120704,112,120718,112,120762,112,120776,112,11427,112,65328,80,8473,80,119823,80,119875,80,119927,80,119979,80,120031,80,120083,80,120187,80,120239,80,120291,80,120343,80,120395,80,120447,80,929,80,120504,80,120562,80,120620,80,120678,80,120736,80,11426,80,5090,80,5229,80,42193,80,66197,80,119850,113,119902,113,119954,113,120006,113,120058,113,120110,113,120162,113,120214,113,120266,113,120318,113,120370,113,120422,113,120474,113,1307,113,1379,113,1382,113,8474,81,119824,81,119876,81,119928,81,119980,81,120032,81,120084,81,120188,81,120240,81,120292,81,120344,81,120396,81,120448,81,11605,81,119851,114,119903,114,119955,114,120007,114,120059,114,120111,114,120163,114,120215,114,120267,114,120319,114,120371,114,120423,114,120475,114,43847,114,43848,114,7462,114,11397,114,43905,114,119318,82,8475,82,8476,82,8477,82,119825,82,119877,82,119929,82,120033,82,120189,82,120241,82,120293,82,120345,82,120397,82,120449,82,422,82,5025,82,5074,82,66740,82,5511,82,42211,82,94005,82,65363,115,119852,115,119904,115,119956,115,120008,115,120060,115,120112,115,120164,115,120216,115,120268,115,120320,115,120372,115,120424,115,120476,115,42801,115,445,115,1109,115,43946,115,71873,115,66632,115,65331,83,119826,83,119878,83,119930,83,119982,83,120034,83,120086,83,120138,83,120190,83,120242,83,120294,83,120346,83,120398,83,120450,83,1029,83,1359,83,5077,83,5082,83,42210,83,94010,83,66198,83,66592,83,119853,116,119905,116,119957,116,120009,116,120061,116,120113,116,120165,116,120217,116,120269,116,120321,116,120373,116,120425,116,120477,116,8868,84,10201,84,128872,84,65332,84,119827,84,119879,84,119931,84,119983,84,120035,84,120087,84,120139,84,120191,84,120243,84,120295,84,120347,84,120399,84,120451,84,932,84,120507,84,120565,84,120623,84,120681,84,120739,84,11430,84,5026,84,42196,84,93962,84,71868,84,66199,84,66225,84,66325,84,119854,117,119906,117,119958,117,120010,117,120062,117,120114,117,120166,117,120218,117,120270,117,120322,117,120374,117,120426,117,120478,117,42911,117,7452,117,43854,117,43858,117,651,117,965,117,120534,117,120592,117,120650,117,120708,117,120766,117,1405,117,66806,117,71896,117,8746,85,8899,85,119828,85,119880,85,119932,85,119984,85,120036,85,120088,85,120140,85,120192,85,120244,85,120296,85,120348,85,120400,85,120452,85,1357,85,4608,85,66766,85,5196,85,42228,85,94018,85,71864,85,8744,118,8897,118,65366,118,8564,118,119855,118,119907,118,119959,118,120011,118,120063,118,120115,118,120167,118,120219,118,120271,118,120323,118,120375,118,120427,118,120479,118,7456,118,957,118,120526,118,120584,118,120642,118,120700,118,120758,118,1141,118,1496,118,71430,118,43945,118,71872,118,119309,86,1639,86,1783,86,8548,86,119829,86,119881,86,119933,86,119985,86,120037,86,120089,86,120141,86,120193,86,120245,86,120297,86,120349,86,120401,86,120453,86,1140,86,11576,86,5081,86,5167,86,42719,86,42214,86,93960,86,71840,86,66845,86,623,119,119856,119,119908,119,119960,119,120012,119,120064,119,120116,119,120168,119,120220,119,120272,119,120324,119,120376,119,120428,119,120480,119,7457,119,1121,119,1309,119,1377,119,71434,119,71438,119,71439,119,43907,119,71919,87,71910,87,119830,87,119882,87,119934,87,119986,87,120038,87,120090,87,120142,87,120194,87,120246,87,120298,87,120350,87,120402,87,120454,87,1308,87,5043,87,5076,87,42218,87,5742,120,10539,120,10540,120,10799,120,65368,120,8569,120,119857,120,119909,120,119961,120,120013,120,120065,120,120117,120,120169,120,120221,120,120273,120,120325,120,120377,120,120429,120,120481,120,5441,120,5501,120,5741,88,9587,88,66338,88,71916,88,65336,88,8553,88,119831,88,119883,88,119935,88,119987,88,120039,88,120091,88,120143,88,120195,88,120247,88,120299,88,120351,88,120403,88,120455,88,42931,88,935,88,120510,88,120568,88,120626,88,120684,88,120742,88,11436,88,11613,88,5815,88,42219,88,66192,88,66228,88,66327,88,66855,88,611,121,7564,121,65369,121,119858,121,119910,121,119962,121,120014,121,120066,121,120118,121,120170,121,120222,121,120274,121,120326,121,120378,121,120430,121,120482,121,655,121,7935,121,43866,121,947,121,8509,121,120516,121,120574,121,120632,121,120690,121,120748,121,1199,121,4327,121,71900,121,65337,89,119832,89,119884,89,119936,89,119988,89,120040,89,120092,89,120144,89,120196,89,120248,89,120300,89,120352,89,120404,89,120456,89,933,89,978,89,120508,89,120566,89,120624,89,120682,89,120740,89,11432,89,1198,89,5033,89,5053,89,42220,89,94019,89,71844,89,66226,89,119859,122,119911,122,119963,122,120015,122,120067,122,120119,122,120171,122,120223,122,120275,122,120327,122,120379,122,120431,122,120483,122,7458,122,43923,122,71876,122,66293,90,71909,90,65338,90,8484,90,8488,90,119833,90,119885,90,119937,90,119989,90,120041,90,120197,90,120249,90,120301,90,120353,90,120405,90,120457,90,918,90,120493,90,120551,90,120609,90,120667,90,120725,90,5059,90,42204,90,71849,90,65282,34,65284,36,65285,37,65286,38,65290,42,65291,43,65294,46,65295,47,65296,48,65297,49,65298,50,65299,51,65300,52,65301,53,65302,54,65303,55,65304,56,65305,57,65308,60,65309,61,65310,62,65312,64,65316,68,65318,70,65319,71,65324,76,65329,81,65330,82,65333,85,65334,86,65335,87,65343,95,65346,98,65348,100,65350,102,65355,107,65357,109,65358,110,65361,113,65362,114,65364,116,65365,117,65367,119,65370,122,65371,123,65373,125],\"_default\":[160,32,8211,45,65374,126,65306,58,65281,33,8216,96,8217,96,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"cs\":[65374,126,65306,58,65281,33,8216,96,8217,96,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"de\":[65374,126,65306,58,65281,33,8216,96,8217,96,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"es\":[8211,45,65374,126,65306,58,65281,33,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"fr\":[65374,126,65306,58,65281,33,8216,96,8245,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"it\":[160,32,8211,45,65374,126,65306,58,65281,33,8216,96,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"ja\":[8211,45,65306,58,65281,33,8216,96,8217,96,8245,96,180,96,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65292,44,65307,59],\"ko\":[8211,45,65374,126,65306,58,65281,33,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"pl\":[65374,126,65306,58,65281,33,8216,96,8217,96,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"pt-BR\":[65374,126,65306,58,65281,33,8216,96,8217,96,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"qps-ploc\":[160,32,8211,45,65374,126,65306,58,65281,33,8216,96,8217,96,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"ru\":[65374,126,65306,58,65281,33,8216,96,8217,96,8245,96,180,96,12494,47,305,105,921,73,1009,112,215,120,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"tr\":[160,32,8211,45,65374,126,65306,58,65281,33,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65288,40,65289,41,65292,44,65307,59,65311,63],\"zh-hans\":[65374,126,65306,58,65281,33,8245,96,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65288,40,65289,41],\"zh-hant\":[8211,45,65374,126,180,96,12494,47,1047,51,1073,54,1072,97,1040,65,1068,98,1042,66,1089,99,1057,67,1077,101,1045,69,1053,72,305,105,1050,75,921,73,1052,77,1086,111,1054,79,1009,112,1088,112,1056,80,1075,114,1058,84,215,120,1093,120,1061,88,1091,121,1059,89,65283,35,65307,59]}'); }); AmbiguousCharacters.cache = new LRUCachedComputed((locales) => { function arrayToMap(arr) { const result = new Map(); for (let i = 0; i < arr.length; i += 2) { result.set(arr[i], arr[i + 1]); } return result; } function mergeMaps(map1, map2) { const result = new Map(map1); for (const [key, value] of map2) { result.set(key, value); } return result; } function intersectMaps(map1, map2) { if (!map1) { return map2; } const result = new Map(); for (const [key, value] of map1) { if (map2.has(key)) { result.set(key, value); } } return result; } const data = _a$c.ambiguousCharacterData.getValue(); let filteredLocales = locales.filter((l) => !l.startsWith('_') && l in data); if (filteredLocales.length === 0) { filteredLocales = ['_default']; } let languageSpecificMap = undefined; for (const locale of filteredLocales) { const map = arrayToMap(data[locale]); languageSpecificMap = intersectMaps(languageSpecificMap, map); } const commonMap = arrayToMap(data['_common']); const map = mergeMaps(commonMap, languageSpecificMap); return new AmbiguousCharacters(map); }); AmbiguousCharacters._locales = new Lazy(() => Object.keys(AmbiguousCharacters.ambiguousCharacterData.getValue()).filter((k) => !k.startsWith('_'))); class InvisibleCharacters { static getRawData() { // Generated using https://github.com/hediet/vscode-unicode-data return JSON.parse('[9,10,11,12,13,32,127,160,173,847,1564,4447,4448,6068,6069,6155,6156,6157,6158,7355,7356,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8203,8204,8205,8206,8207,8234,8235,8236,8237,8238,8239,8287,8288,8289,8290,8291,8292,8293,8294,8295,8296,8297,8298,8299,8300,8301,8302,8303,10240,12288,12644,65024,65025,65026,65027,65028,65029,65030,65031,65032,65033,65034,65035,65036,65037,65038,65039,65279,65440,65520,65521,65522,65523,65524,65525,65526,65527,65528,65532,78844,119155,119156,119157,119158,119159,119160,119161,119162,917504,917505,917506,917507,917508,917509,917510,917511,917512,917513,917514,917515,917516,917517,917518,917519,917520,917521,917522,917523,917524,917525,917526,917527,917528,917529,917530,917531,917532,917533,917534,917535,917536,917537,917538,917539,917540,917541,917542,917543,917544,917545,917546,917547,917548,917549,917550,917551,917552,917553,917554,917555,917556,917557,917558,917559,917560,917561,917562,917563,917564,917565,917566,917567,917568,917569,917570,917571,917572,917573,917574,917575,917576,917577,917578,917579,917580,917581,917582,917583,917584,917585,917586,917587,917588,917589,917590,917591,917592,917593,917594,917595,917596,917597,917598,917599,917600,917601,917602,917603,917604,917605,917606,917607,917608,917609,917610,917611,917612,917613,917614,917615,917616,917617,917618,917619,917620,917621,917622,917623,917624,917625,917626,917627,917628,917629,917630,917631,917760,917761,917762,917763,917764,917765,917766,917767,917768,917769,917770,917771,917772,917773,917774,917775,917776,917777,917778,917779,917780,917781,917782,917783,917784,917785,917786,917787,917788,917789,917790,917791,917792,917793,917794,917795,917796,917797,917798,917799,917800,917801,917802,917803,917804,917805,917806,917807,917808,917809,917810,917811,917812,917813,917814,917815,917816,917817,917818,917819,917820,917821,917822,917823,917824,917825,917826,917827,917828,917829,917830,917831,917832,917833,917834,917835,917836,917837,917838,917839,917840,917841,917842,917843,917844,917845,917846,917847,917848,917849,917850,917851,917852,917853,917854,917855,917856,917857,917858,917859,917860,917861,917862,917863,917864,917865,917866,917867,917868,917869,917870,917871,917872,917873,917874,917875,917876,917877,917878,917879,917880,917881,917882,917883,917884,917885,917886,917887,917888,917889,917890,917891,917892,917893,917894,917895,917896,917897,917898,917899,917900,917901,917902,917903,917904,917905,917906,917907,917908,917909,917910,917911,917912,917913,917914,917915,917916,917917,917918,917919,917920,917921,917922,917923,917924,917925,917926,917927,917928,917929,917930,917931,917932,917933,917934,917935,917936,917937,917938,917939,917940,917941,917942,917943,917944,917945,917946,917947,917948,917949,917950,917951,917952,917953,917954,917955,917956,917957,917958,917959,917960,917961,917962,917963,917964,917965,917966,917967,917968,917969,917970,917971,917972,917973,917974,917975,917976,917977,917978,917979,917980,917981,917982,917983,917984,917985,917986,917987,917988,917989,917990,917991,917992,917993,917994,917995,917996,917997,917998,917999]'); } static getData() { if (!this._data) { this._data = new Set(InvisibleCharacters.getRawData()); } return this._data; } static isInvisibleCharacter(codePoint) { return InvisibleCharacters.getData().has(codePoint); } static get codePoints() { return InvisibleCharacters.getData(); } } InvisibleCharacters._data = undefined; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function isPathSeparator(code) { return code === 47 /* Slash */ || code === 92 /* Backslash */; } /** * Takes a Windows OS path and changes backward slashes to forward slashes. * This should only be done for OS paths from Windows (or user provided paths potentially from Windows). * Using it on a Linux or MaxOS path might change it. */ function toSlashes(osPath) { return osPath.replace(/[\\/]/g, posix.sep); } /** * Takes a Windows OS path (using backward or forward slashes) and turns it into a posix path: * - turns backward slashes into forward slashes * - makes it absolute if it starts with a drive letter * This should only be done for OS paths from Windows (or user provided paths potentially from Windows). * Using it on a Linux or MaxOS path might change it. */ function toPosixPath(osPath) { if (osPath.indexOf('/') === -1) { osPath = toSlashes(osPath); } if (/^[a-zA-Z]:(\/|$)/.test(osPath)) { // starts with a drive letter osPath = '/' + osPath; } return osPath; } /** * Computes the _root_ this path, like `getRoot('c:\files') === c:\`, * `getRoot('files:///files/path') === files:///`, * or `getRoot('\\server\shares\path') === \\server\shares\` */ function getRoot(path, sep = posix.sep) { if (!path) { return ''; } const len = path.length; const firstLetter = path.charCodeAt(0); if (isPathSeparator(firstLetter)) { if (isPathSeparator(path.charCodeAt(1))) { // UNC candidate \\localhost\shares\ddd // ^^^^^^^^^^^^^^^^^^^ if (!isPathSeparator(path.charCodeAt(2))) { let pos = 3; const start = pos; for (; pos < len; pos++) { if (isPathSeparator(path.charCodeAt(pos))) { break; } } if (start !== pos && !isPathSeparator(path.charCodeAt(pos + 1))) { pos += 1; for (; pos < len; pos++) { if (isPathSeparator(path.charCodeAt(pos))) { return path.slice(0, pos + 1) // consume this separator .replace(/[\\/]/g, sep); } } } } } // /user/far // ^ return sep; } else if (isWindowsDriveLetter(firstLetter)) { // check for windows drive letter c:\ or c: if (path.charCodeAt(1) === 58 /* Colon */) { if (isPathSeparator(path.charCodeAt(2))) { // C:\fff // ^^^ return path.slice(0, 2) + sep; } else { // C: // ^^ return path.slice(0, 2); } } } // check for URI // scheme://authority/path // ^^^^^^^^^^^^^^^^^^^ let pos = path.indexOf('://'); if (pos !== -1) { pos += 3; // 3 -> "://".length for (; pos < len; pos++) { if (isPathSeparator(path.charCodeAt(pos))) { return path.slice(0, pos + 1); // consume this separator } } } return ''; } /** * @deprecated please use `IUriIdentityService.extUri.isEqualOrParent` instead. If * you are in a context without services, consider to pass down the `extUri` from the * outside, or use `extUriBiasedIgnorePathCase` if you know what you are doing. */ function isEqualOrParent(base, parentCandidate, ignoreCase, separator = sep) { if (base === parentCandidate) { return true; } if (!base || !parentCandidate) { return false; } if (parentCandidate.length > base.length) { return false; } if (ignoreCase) { const beginsWith = startsWithIgnoreCase(base, parentCandidate); if (!beginsWith) { return false; } if (parentCandidate.length === base.length) { return true; // same path, different casing } let sepOffset = parentCandidate.length; if (parentCandidate.charAt(parentCandidate.length - 1) === separator) { sepOffset--; // adjust the expected sep offset in case our candidate already ends in separator character } return base.charAt(sepOffset) === separator; } if (parentCandidate.charAt(parentCandidate.length - 1) !== separator) { parentCandidate += separator; } return base.indexOf(parentCandidate) === 0; } function isWindowsDriveLetter(char0) { return char0 >= 65 /* A */ && char0 <= 90 /* Z */ || char0 >= 97 /* a */ && char0 <= 122 /* z */; } function isRootOrDriveLetter(path) { const pathNormalized = normalize(path); if (isWindows) { if (path.length > 3) { return false; } return hasDriveLetter(pathNormalized) && (path.length === 2 || pathNormalized.charCodeAt(2) === 92 /* Backslash */); } return pathNormalized === posix.sep; } function hasDriveLetter(path, continueAsWindows) { const isWindowsPath = ((continueAsWindows !== undefined) ? continueAsWindows : isWindows); if (isWindowsPath) { return isWindowsDriveLetter(path.charCodeAt(0)) && path.charCodeAt(1) === 58 /* Colon */; } return false; } var _a$b, _b$1; class StringIterator { constructor() { this._value = ''; this._pos = 0; } reset(key) { this._value = key; this._pos = 0; return this; } next() { this._pos += 1; return this; } hasNext() { return this._pos < this._value.length - 1; } cmp(a) { const aCode = a.charCodeAt(0); const thisCode = this._value.charCodeAt(this._pos); return aCode - thisCode; } value() { return this._value[this._pos]; } } class ConfigKeysIterator { constructor(_caseSensitive = true) { this._caseSensitive = _caseSensitive; } reset(key) { this._value = key; this._from = 0; this._to = 0; return this.next(); } hasNext() { return this._to < this._value.length; } next() { // this._data = key.split(/[\\/]/).filter(s => !!s); this._from = this._to; let justSeps = true; for (; this._to < this._value.length; this._to++) { const ch = this._value.charCodeAt(this._to); if (ch === 46 /* Period */) { if (justSeps) { this._from++; } else { break; } } else { justSeps = false; } } return this; } cmp(a) { return this._caseSensitive ? compareSubstring(a, this._value, 0, a.length, this._from, this._to) : compareSubstringIgnoreCase(a, this._value, 0, a.length, this._from, this._to); } value() { return this._value.substring(this._from, this._to); } } class PathIterator { constructor(_splitOnBackslash = true, _caseSensitive = true) { this._splitOnBackslash = _splitOnBackslash; this._caseSensitive = _caseSensitive; } reset(key) { this._from = 0; this._to = 0; this._value = key; this._valueLen = key.length; for (let pos = key.length - 1; pos >= 0; pos--, this._valueLen--) { const ch = this._value.charCodeAt(pos); if (!(ch === 47 /* Slash */ || this._splitOnBackslash && ch === 92 /* Backslash */)) { break; } } return this.next(); } hasNext() { return this._to < this._valueLen; } next() { // this._data = key.split(/[\\/]/).filter(s => !!s); this._from = this._to; let justSeps = true; for (; this._to < this._valueLen; this._to++) { const ch = this._value.charCodeAt(this._to); if (ch === 47 /* Slash */ || this._splitOnBackslash && ch === 92 /* Backslash */) { if (justSeps) { this._from++; } else { break; } } else { justSeps = false; } } return this; } cmp(a) { return this._caseSensitive ? compareSubstring(a, this._value, 0, a.length, this._from, this._to) : compareSubstringIgnoreCase(a, this._value, 0, a.length, this._from, this._to); } value() { return this._value.substring(this._from, this._to); } } class UriIterator { constructor(_ignorePathCasing) { this._ignorePathCasing = _ignorePathCasing; this._states = []; this._stateIdx = 0; } reset(key) { this._value = key; this._states = []; if (this._value.scheme) { this._states.push(1 /* Scheme */); } if (this._value.authority) { this._states.push(2 /* Authority */); } if (this._value.path) { this._pathIterator = new PathIterator(false, !this._ignorePathCasing(key)); this._pathIterator.reset(key.path); if (this._pathIterator.value()) { this._states.push(3 /* Path */); } } if (this._value.query) { this._states.push(4 /* Query */); } if (this._value.fragment) { this._states.push(5 /* Fragment */); } this._stateIdx = 0; return this; } next() { if (this._states[this._stateIdx] === 3 /* Path */ && this._pathIterator.hasNext()) { this._pathIterator.next(); } else { this._stateIdx += 1; } return this; } hasNext() { return (this._states[this._stateIdx] === 3 /* Path */ && this._pathIterator.hasNext()) || this._stateIdx < this._states.length - 1; } cmp(a) { if (this._states[this._stateIdx] === 1 /* Scheme */) { return compareIgnoreCase(a, this._value.scheme); } else if (this._states[this._stateIdx] === 2 /* Authority */) { return compareIgnoreCase(a, this._value.authority); } else if (this._states[this._stateIdx] === 3 /* Path */) { return this._pathIterator.cmp(a); } else if (this._states[this._stateIdx] === 4 /* Query */) { return compare(a, this._value.query); } else if (this._states[this._stateIdx] === 5 /* Fragment */) { return compare(a, this._value.fragment); } throw new Error(); } value() { if (this._states[this._stateIdx] === 1 /* Scheme */) { return this._value.scheme; } else if (this._states[this._stateIdx] === 2 /* Authority */) { return this._value.authority; } else if (this._states[this._stateIdx] === 3 /* Path */) { return this._pathIterator.value(); } else if (this._states[this._stateIdx] === 4 /* Query */) { return this._value.query; } else if (this._states[this._stateIdx] === 5 /* Fragment */) { return this._value.fragment; } throw new Error(); } } class TernarySearchTreeNode { constructor() { this.height = 1; } rotateLeft() { const tmp = this.right; this.right = tmp.left; tmp.left = this; this.updateHeight(); tmp.updateHeight(); return tmp; } rotateRight() { const tmp = this.left; this.left = tmp.right; tmp.right = this; this.updateHeight(); tmp.updateHeight(); return tmp; } updateHeight() { this.height = 1 + Math.max(this.heightLeft, this.heightRight); } balanceFactor() { return this.heightRight - this.heightLeft; } get heightLeft() { var _c, _d; return (_d = (_c = this.left) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0; } get heightRight() { var _c, _d; return (_d = (_c = this.right) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0; } } class TernarySearchTree { constructor(segments) { this._iter = segments; } static forUris(ignorePathCasing = () => false) { return new TernarySearchTree(new UriIterator(ignorePathCasing)); } static forStrings() { return new TernarySearchTree(new StringIterator()); } static forConfigKeys() { return new TernarySearchTree(new ConfigKeysIterator()); } clear() { this._root = undefined; } set(key, element) { const iter = this._iter.reset(key); let node; if (!this._root) { this._root = new TernarySearchTreeNode(); this._root.segment = iter.value(); } const stack = []; // find insert_node node = this._root; while (true) { const val = iter.cmp(node.segment); if (val > 0) { // left if (!node.left) { node.left = new TernarySearchTreeNode(); node.left.segment = iter.value(); } stack.push([-1 /* Left */, node]); node = node.left; } else if (val < 0) { // right if (!node.right) { node.right = new TernarySearchTreeNode(); node.right.segment = iter.value(); } stack.push([1 /* Right */, node]); node = node.right; } else if (iter.hasNext()) { // mid iter.next(); if (!node.mid) { node.mid = new TernarySearchTreeNode(); node.mid.segment = iter.value(); } stack.push([0 /* Mid */, node]); node = node.mid; } else { break; } } // set value const oldElement = node.value; node.value = element; node.key = key; // balance for (let i = stack.length - 1; i >= 0; i--) { const node = stack[i][1]; node.updateHeight(); const bf = node.balanceFactor(); if (bf < -1 || bf > 1) { // needs rotate const d1 = stack[i][0]; const d2 = stack[i + 1][0]; if (d1 === 1 /* Right */ && d2 === 1 /* Right */) { //right, right -> rotate left stack[i][1] = node.rotateLeft(); } else if (d1 === -1 /* Left */ && d2 === -1 /* Left */) { // left, left -> rotate right stack[i][1] = node.rotateRight(); } else if (d1 === 1 /* Right */ && d2 === -1 /* Left */) { // right, left -> double rotate right, left node.right = stack[i + 1][1] = stack[i + 1][1].rotateRight(); stack[i][1] = node.rotateLeft(); } else if (d1 === -1 /* Left */ && d2 === 1 /* Right */) { // left, right -> double rotate left, right node.left = stack[i + 1][1] = stack[i + 1][1].rotateLeft(); stack[i][1] = node.rotateRight(); } else { throw new Error(); } // patch path to parent if (i > 0) { switch (stack[i - 1][0]) { case -1 /* Left */: stack[i - 1][1].left = stack[i][1]; break; case 1 /* Right */: stack[i - 1][1].right = stack[i][1]; break; case 0 /* Mid */: stack[i - 1][1].mid = stack[i][1]; break; } } else { this._root = stack[0][1]; } } } return oldElement; } get(key) { var _c; return (_c = this._getNode(key)) === null || _c === void 0 ? void 0 : _c.value; } _getNode(key) { const iter = this._iter.reset(key); let node = this._root; while (node) { const val = iter.cmp(node.segment); if (val > 0) { // left node = node.left; } else if (val < 0) { // right node = node.right; } else if (iter.hasNext()) { // mid iter.next(); node = node.mid; } else { break; } } return node; } has(key) { const node = this._getNode(key); return !((node === null || node === void 0 ? void 0 : node.value) === undefined && (node === null || node === void 0 ? void 0 : node.mid) === undefined); } delete(key) { return this._delete(key, false); } deleteSuperstr(key) { return this._delete(key, true); } _delete(key, superStr) { var _c; const iter = this._iter.reset(key); const stack = []; let node = this._root; // find node while (node) { const val = iter.cmp(node.segment); if (val > 0) { // left stack.push([-1 /* Left */, node]); node = node.left; } else if (val < 0) { // right stack.push([1 /* Right */, node]); node = node.right; } else if (iter.hasNext()) { // mid iter.next(); stack.push([0 /* Mid */, node]); node = node.mid; } else { break; } } if (!node) { // node not found return; } if (superStr) { // removing children, reset height node.left = undefined; node.mid = undefined; node.right = undefined; node.height = 1; } else { // removing element node.key = undefined; node.value = undefined; } // BST node removal if (!node.mid && !node.value) { if (node.left && node.right) { // full node const min = this._min(node.right); const { key, value, segment } = min; this._delete(min.key, false); node.key = key; node.value = value; node.segment = segment; } else { // empty or half empty const newChild = (_c = node.left) !== null && _c !== void 0 ? _c : node.right; if (stack.length > 0) { const [dir, parent] = stack[stack.length - 1]; switch (dir) { case -1 /* Left */: parent.left = newChild; break; case 0 /* Mid */: parent.mid = newChild; break; case 1 /* Right */: parent.right = newChild; break; } } else { this._root = newChild; } } } // AVL balance for (let i = stack.length - 1; i >= 0; i--) { const node = stack[i][1]; node.updateHeight(); const bf = node.balanceFactor(); if (bf > 1) { // right heavy if (node.right.balanceFactor() >= 0) { // right, right -> rotate left stack[i][1] = node.rotateLeft(); } else { // right, left -> double rotate node.right = node.right.rotateRight(); stack[i][1] = node.rotateLeft(); } } else if (bf < -1) { // left heavy if (node.left.balanceFactor() <= 0) { // left, left -> rotate right stack[i][1] = node.rotateRight(); } else { // left, right -> double rotate node.left = node.left.rotateLeft(); stack[i][1] = node.rotateRight(); } } // patch path to parent if (i > 0) { switch (stack[i - 1][0]) { case -1 /* Left */: stack[i - 1][1].left = stack[i][1]; break; case 1 /* Right */: stack[i - 1][1].right = stack[i][1]; break; case 0 /* Mid */: stack[i - 1][1].mid = stack[i][1]; break; } } else { this._root = stack[0][1]; } } } _min(node) { while (node.left) { node = node.left; } return node; } findSubstr(key) { const iter = this._iter.reset(key); let node = this._root; let candidate = undefined; while (node) { const val = iter.cmp(node.segment); if (val > 0) { // left node = node.left; } else if (val < 0) { // right node = node.right; } else if (iter.hasNext()) { // mid iter.next(); candidate = node.value || candidate; node = node.mid; } else { break; } } return node && node.value || candidate; } findSuperstr(key) { const iter = this._iter.reset(key); let node = this._root; while (node) { const val = iter.cmp(node.segment); if (val > 0) { // left node = node.left; } else if (val < 0) { // right node = node.right; } else if (iter.hasNext()) { // mid iter.next(); node = node.mid; } else { // collect if (!node.mid) { return undefined; } else { return this._entries(node.mid); } } } return undefined; } forEach(callback) { for (const [key, value] of this) { callback(value, key); } } *[Symbol.iterator]() { yield* this._entries(this._root); } *_entries(node) { // DFS if (!node) { return; } if (node.left) { yield* this._entries(node.left); } if (node.value) { yield [node.key, node.value]; } if (node.mid) { yield* this._entries(node.mid); } if (node.right) { yield* this._entries(node.right); } } } class ResourceMapEntry { constructor(uri, value) { this.uri = uri; this.value = value; } } class ResourceMap { constructor(mapOrKeyFn, toKey) { this[_a$b] = 'ResourceMap'; if (mapOrKeyFn instanceof ResourceMap) { this.map = new Map(mapOrKeyFn.map); this.toKey = toKey !== null && toKey !== void 0 ? toKey : ResourceMap.defaultToKey; } else { this.map = new Map(); this.toKey = mapOrKeyFn !== null && mapOrKeyFn !== void 0 ? mapOrKeyFn : ResourceMap.defaultToKey; } } set(resource, value) { this.map.set(this.toKey(resource), new ResourceMapEntry(resource, value)); return this; } get(resource) { var _c; return (_c = this.map.get(this.toKey(resource))) === null || _c === void 0 ? void 0 : _c.value; } has(resource) { return this.map.has(this.toKey(resource)); } get size() { return this.map.size; } clear() { this.map.clear(); } delete(resource) { return this.map.delete(this.toKey(resource)); } forEach(clb, thisArg) { if (typeof thisArg !== 'undefined') { clb = clb.bind(thisArg); } for (let [_, entry] of this.map) { clb(entry.value, entry.uri, this); } } *values() { for (let entry of this.map.values()) { yield entry.value; } } *keys() { for (let entry of this.map.values()) { yield entry.uri; } } *entries() { for (let entry of this.map.values()) { yield [entry.uri, entry.value]; } } *[(_a$b = Symbol.toStringTag, Symbol.iterator)]() { for (let [, entry] of this.map) { yield [entry.uri, entry.value]; } } } ResourceMap.defaultToKey = (resource) => resource.toString(); class LinkedMap { constructor() { this[_b$1] = 'LinkedMap'; this._map = new Map(); this._head = undefined; this._tail = undefined; this._size = 0; this._state = 0; } clear() { this._map.clear(); this._head = undefined; this._tail = undefined; this._size = 0; this._state++; } isEmpty() { return !this._head && !this._tail; } get size() { return this._size; } get first() { var _c; return (_c = this._head) === null || _c === void 0 ? void 0 : _c.value; } get last() { var _c; return (_c = this._tail) === null || _c === void 0 ? void 0 : _c.value; } has(key) { return this._map.has(key); } get(key, touch = 0 /* None */) { const item = this._map.get(key); if (!item) { return undefined; } if (touch !== 0 /* None */) { this.touch(item, touch); } return item.value; } set(key, value, touch = 0 /* None */) { let item = this._map.get(key); if (item) { item.value = value; if (touch !== 0 /* None */) { this.touch(item, touch); } } else { item = { key, value, next: undefined, previous: undefined }; switch (touch) { case 0 /* None */: this.addItemLast(item); break; case 1 /* AsOld */: this.addItemFirst(item); break; case 2 /* AsNew */: this.addItemLast(item); break; default: this.addItemLast(item); break; } this._map.set(key, item); this._size++; } return this; } delete(key) { return !!this.remove(key); } remove(key) { const item = this._map.get(key); if (!item) { return undefined; } this._map.delete(key); this.removeItem(item); this._size--; return item.value; } shift() { if (!this._head && !this._tail) { return undefined; } if (!this._head || !this._tail) { throw new Error('Invalid list'); } const item = this._head; this._map.delete(item.key); this.removeItem(item); this._size--; return item.value; } forEach(callbackfn, thisArg) { const state = this._state; let current = this._head; while (current) { if (thisArg) { callbackfn.bind(thisArg)(current.value, current.key, this); } else { callbackfn(current.value, current.key, this); } if (this._state !== state) { throw new Error(`LinkedMap got modified during iteration.`); } current = current.next; } } keys() { const map = this; const state = this._state; let current = this._head; const iterator = { [Symbol.iterator]() { return iterator; }, next() { if (map._state !== state) { throw new Error(`LinkedMap got modified during iteration.`); } if (current) { const result = { value: current.key, done: false }; current = current.next; return result; } else { return { value: undefined, done: true }; } } }; return iterator; } values() { const map = this; const state = this._state; let current = this._head; const iterator = { [Symbol.iterator]() { return iterator; }, next() { if (map._state !== state) { throw new Error(`LinkedMap got modified during iteration.`); } if (current) { const result = { value: current.value, done: false }; current = current.next; return result; } else { return { value: undefined, done: true }; } } }; return iterator; } entries() { const map = this; const state = this._state; let current = this._head; const iterator = { [Symbol.iterator]() { return iterator; }, next() { if (map._state !== state) { throw new Error(`LinkedMap got modified during iteration.`); } if (current) { const result = { value: [current.key, current.value], done: false }; current = current.next; return result; } else { return { value: undefined, done: true }; } } }; return iterator; } [(_b$1 = Symbol.toStringTag, Symbol.iterator)]() { return this.entries(); } trimOld(newSize) { if (newSize >= this.size) { return; } if (newSize === 0) { this.clear(); return; } let current = this._head; let currentSize = this.size; while (current && currentSize > newSize) { this._map.delete(current.key); current = current.next; currentSize--; } this._head = current; this._size = currentSize; if (current) { current.previous = undefined; } this._state++; } addItemFirst(item) { // First time Insert if (!this._head && !this._tail) { this._tail = item; } else if (!this._head) { throw new Error('Invalid list'); } else { item.next = this._head; this._head.previous = item; } this._head = item; this._state++; } addItemLast(item) { // First time Insert if (!this._head && !this._tail) { this._head = item; } else if (!this._tail) { throw new Error('Invalid list'); } else { item.previous = this._tail; this._tail.next = item; } this._tail = item; this._state++; } removeItem(item) { if (item === this._head && item === this._tail) { this._head = undefined; this._tail = undefined; } else if (item === this._head) { // This can only happen if size === 1 which is handled // by the case above. if (!item.next) { throw new Error('Invalid list'); } item.next.previous = undefined; this._head = item.next; } else if (item === this._tail) { // This can only happen if size === 1 which is handled // by the case above. if (!item.previous) { throw new Error('Invalid list'); } item.previous.next = undefined; this._tail = item.previous; } else { const next = item.next; const previous = item.previous; if (!next || !previous) { throw new Error('Invalid list'); } next.previous = previous; previous.next = next; } item.next = undefined; item.previous = undefined; this._state++; } touch(item, touch) { if (!this._head || !this._tail) { throw new Error('Invalid list'); } if ((touch !== 1 /* AsOld */ && touch !== 2 /* AsNew */)) { return; } if (touch === 1 /* AsOld */) { if (item === this._head) { return; } const next = item.next; const previous = item.previous; // Unlink the item if (item === this._tail) { // previous must be defined since item was not head but is tail // So there are more than on item in the map previous.next = undefined; this._tail = previous; } else { // Both next and previous are not undefined since item was neither head nor tail. next.previous = previous; previous.next = next; } // Insert the node at head item.previous = undefined; item.next = this._head; this._head.previous = item; this._head = item; this._state++; } else if (touch === 2 /* AsNew */) { if (item === this._tail) { return; } const next = item.next; const previous = item.previous; // Unlink the item. if (item === this._head) { // next must be defined since item was not tail but is head // So there are more than on item in the map next.previous = undefined; this._head = next; } else { // Both next and previous are not undefined since item was neither head nor tail. next.previous = previous; previous.next = next; } item.next = undefined; item.previous = this._tail; this._tail.next = item; this._tail = item; this._state++; } } toJSON() { const data = []; this.forEach((value, key) => { data.push([key, value]); }); return data; } fromJSON(data) { this.clear(); for (const [key, value] of data) { this.set(key, value); } } } class LRUCache extends LinkedMap { constructor(limit, ratio = 1) { super(); this._limit = limit; this._ratio = Math.min(Math.max(0, ratio), 1); } get limit() { return this._limit; } set limit(limit) { this._limit = limit; this.checkTrim(); } get(key, touch = 2 /* AsNew */) { return super.get(key, touch); } peek(key) { return super.get(key, 0 /* None */); } set(key, value) { super.set(key, value, 2 /* AsNew */); this.checkTrim(); return this; } checkTrim() { if (this.size > this._limit) { this.trimOld(Math.round(this._limit * this._ratio)); } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const GLOBSTAR = '**'; const GLOB_SPLIT = '/'; const PATH_REGEX = '[/\\\\]'; // any slash or backslash const NO_PATH_REGEX = '[^/\\\\]'; // any non-slash and non-backslash const ALL_FORWARD_SLASHES = /\//g; function starsToRegExp(starCount) { switch (starCount) { case 0: return ''; case 1: return `${NO_PATH_REGEX}*?`; // 1 star matches any number of characters except path separator (/ and \) - non greedy (?) default: // Matches: (Path Sep OR Path Val followed by Path Sep OR Path Sep followed by Path Val) 0-many times // Group is non capturing because we don't need to capture at all (?:...) // Overall we use non-greedy matching because it could be that we match too much return `(?:${PATH_REGEX}|${NO_PATH_REGEX}+${PATH_REGEX}|${PATH_REGEX}${NO_PATH_REGEX}+)*?`; } } function splitGlobAware(pattern, splitChar) { if (!pattern) { return []; } const segments = []; let inBraces = false; let inBrackets = false; let curVal = ''; for (const char of pattern) { switch (char) { case splitChar: if (!inBraces && !inBrackets) { segments.push(curVal); curVal = ''; continue; } break; case '{': inBraces = true; break; case '}': inBraces = false; break; case '[': inBrackets = true; break; case ']': inBrackets = false; break; } curVal += char; } // Tail if (curVal) { segments.push(curVal); } return segments; } function parseRegExp(pattern) { if (!pattern) { return ''; } let regEx = ''; // Split up into segments for each slash found const segments = splitGlobAware(pattern, GLOB_SPLIT); // Special case where we only have globstars if (segments.every(s => s === GLOBSTAR)) { regEx = '.*'; } // Build regex over segments else { let previousSegmentWasGlobStar = false; segments.forEach((segment, index) => { // Globstar is special if (segment === GLOBSTAR) { // if we have more than one globstar after another, just ignore it if (!previousSegmentWasGlobStar) { regEx += starsToRegExp(2); previousSegmentWasGlobStar = true; } return; } // States let inBraces = false; let braceVal = ''; let inBrackets = false; let bracketVal = ''; for (const char of segment) { // Support brace expansion if (char !== '}' && inBraces) { braceVal += char; continue; } // Support brackets if (inBrackets && (char !== ']' || !bracketVal) /* ] is literally only allowed as first character in brackets to match it */) { let res; // range operator if (char === '-') { res = char; } // negation operator (only valid on first index in bracket) else if ((char === '^' || char === '!') && !bracketVal) { res = '^'; } // glob split matching is not allowed within character ranges // see http://man7.org/linux/man-pages/man7/glob.7.html else if (char === GLOB_SPLIT) { res = ''; } // anything else gets escaped else { res = escapeRegExpCharacters(char); } bracketVal += res; continue; } switch (char) { case '{': inBraces = true; continue; case '[': inBrackets = true; continue; case '}': { const choices = splitGlobAware(braceVal, ','); // Converts {foo,bar} => [foo|bar] const braceRegExp = `(?:${choices.map(c => parseRegExp(c)).join('|')})`; regEx += braceRegExp; inBraces = false; braceVal = ''; break; } case ']': regEx += ('[' + bracketVal + ']'); inBrackets = false; bracketVal = ''; break; case '?': regEx += NO_PATH_REGEX; // 1 ? matches any single character except path separator (/ and \) continue; case '*': regEx += starsToRegExp(1); continue; default: regEx += escapeRegExpCharacters(char); } } // Tail: Add the slash we had split on if there is more to come and the remaining pattern is not a globstar // For example if pattern: some/**/*.js we want the "/" after some to be included in the RegEx to prevent // a folder called "something" to match as well. // However, if pattern: some/**, we tolerate that we also match on "something" because our globstar behaviour // is to match 0-N segments. if (index < segments.length - 1 && (segments[index + 1] !== GLOBSTAR || index + 2 < segments.length)) { regEx += PATH_REGEX; } // reset state previousSegmentWasGlobStar = false; }); } return regEx; } // regexes to check for trivial glob patterns that just check for String#endsWith const T1 = /^\*\*\/\*\.[\w\.-]+$/; // **/*.something const T2 = /^\*\*\/([\w\.-]+)\/?$/; // **/something const T3 = /^{\*\*\/[\*\.]?[\w\.-]+\/?(,\*\*\/[\*\.]?[\w\.-]+\/?)*}$/; // {**/*.something,**/*.else} or {**/package.json,**/project.json} const T3_2 = /^{\*\*\/[\*\.]?[\w\.-]+(\/(\*\*)?)?(,\*\*\/[\*\.]?[\w\.-]+(\/(\*\*)?)?)*}$/; // Like T3, with optional trailing /** const T4 = /^\*\*((\/[\w\.-]+)+)\/?$/; // **/something/else const T5 = /^([\w\.-]+(\/[\w\.-]+)*)\/?$/; // something/else const CACHE = new LRUCache(10000); // bounded to 10000 elements const FALSE = function () { return false; }; const NULL = function () { return null; }; function parsePattern(arg1, options) { if (!arg1) { return NULL; } // Handle IRelativePattern let pattern; if (typeof arg1 !== 'string') { pattern = arg1.pattern; } else { pattern = arg1; } // Whitespace trimming pattern = pattern.trim(); // Check cache const patternKey = `${pattern}_${!!options.trimForExclusions}`; let parsedPattern = CACHE.get(patternKey); if (parsedPattern) { return wrapRelativePattern(parsedPattern, arg1); } // Check for Trivials let match; if (T1.test(pattern)) { // common pattern: **/*.txt just need endsWith check const base = pattern.substr(4); // '**/*'.length === 4 parsedPattern = function (path, basename) { return typeof path === 'string' && path.endsWith(base) ? pattern : null; }; } else if (match = T2.exec(trimForExclusions(pattern, options))) { // common pattern: **/some.txt just need basename check parsedPattern = trivia2(match[1], pattern); } else if ((options.trimForExclusions ? T3_2 : T3).test(pattern)) { // repetition of common patterns (see above) {**/*.txt,**/*.png} parsedPattern = trivia3(pattern, options); } else if (match = T4.exec(trimForExclusions(pattern, options))) { // common pattern: **/something/else just need endsWith check parsedPattern = trivia4and5(match[1].substr(1), pattern, true); } else if (match = T5.exec(trimForExclusions(pattern, options))) { // common pattern: something/else just need equals check parsedPattern = trivia4and5(match[1], pattern, false); } // Otherwise convert to pattern else { parsedPattern = toRegExp(pattern); } // Cache CACHE.set(patternKey, parsedPattern); return wrapRelativePattern(parsedPattern, arg1); } function wrapRelativePattern(parsedPattern, arg2) { if (typeof arg2 === 'string') { return parsedPattern; } return function (path, basename) { if (!isEqualOrParent(path, arg2.base, !isLinux)) { // skip glob matching if `base` is not a parent of `path` return null; } // Given we have checked `base` being a parent of `path`, // we can now remove the `base` portion of the `path` // and only match on the remaining path components return parsedPattern(path.substr(arg2.base.length + 1), basename); }; } function trimForExclusions(pattern, options) { return options.trimForExclusions && pattern.endsWith('/**') ? pattern.substr(0, pattern.length - 2) : pattern; // dropping **, tailing / is dropped later } // common pattern: **/some.txt just need basename check function trivia2(base, originalPattern) { const slashBase = `/${base}`; const backslashBase = `\\${base}`; const parsedPattern = function (path, basename) { if (typeof path !== 'string') { return null; } if (basename) { return basename === base ? originalPattern : null; } return path === base || path.endsWith(slashBase) || path.endsWith(backslashBase) ? originalPattern : null; }; const basenames = [base]; parsedPattern.basenames = basenames; parsedPattern.patterns = [originalPattern]; parsedPattern.allBasenames = basenames; return parsedPattern; } // repetition of common patterns (see above) {**/*.txt,**/*.png} function trivia3(pattern, options) { const parsedPatterns = aggregateBasenameMatches(pattern.slice(1, -1).split(',') .map(pattern => parsePattern(pattern, options)) .filter(pattern => pattern !== NULL), pattern); const n = parsedPatterns.length; if (!n) { return NULL; } if (n === 1) { return parsedPatterns[0]; } const parsedPattern = function (path, basename) { for (let i = 0, n = parsedPatterns.length; i < n; i++) { if (parsedPatterns[i](path, basename)) { return pattern; } } return null; }; const withBasenames = parsedPatterns.find(pattern => !!pattern.allBasenames); if (withBasenames) { parsedPattern.allBasenames = withBasenames.allBasenames; } const allPaths = parsedPatterns.reduce((all, current) => current.allPaths ? all.concat(current.allPaths) : all, []); if (allPaths.length) { parsedPattern.allPaths = allPaths; } return parsedPattern; } // common patterns: **/something/else just need endsWith check, something/else just needs and equals check function trivia4and5(targetPath, pattern, matchPathEnds) { const usingPosixSep = sep === posix.sep; const nativePath = usingPosixSep ? targetPath : targetPath.replace(ALL_FORWARD_SLASHES, sep); const nativePathEnd = sep + nativePath; const targetPathEnd = posix.sep + targetPath; const parsedPattern = matchPathEnds ? function (testPath, basename) { return typeof testPath === 'string' && ((testPath === nativePath || testPath.endsWith(nativePathEnd)) || !usingPosixSep && (testPath === targetPath || testPath.endsWith(targetPathEnd))) ? pattern : null; } : function (testPath, basename) { return typeof testPath === 'string' && (testPath === nativePath || (!usingPosixSep && testPath === targetPath)) ? pattern : null; }; parsedPattern.allPaths = [(matchPathEnds ? '*/' : './') + targetPath]; return parsedPattern; } function toRegExp(pattern) { try { const regExp = new RegExp(`^${parseRegExp(pattern)}$`); return function (path) { regExp.lastIndex = 0; // reset RegExp to its initial state to reuse it! return typeof path === 'string' && regExp.test(path) ? pattern : null; }; } catch (error) { return NULL; } } function match(arg1, path, hasSibling) { if (!arg1 || typeof path !== 'string') { return false; } return parse$1(arg1)(path, undefined, hasSibling); } function parse$1(arg1, options = {}) { if (!arg1) { return FALSE; } // Glob with String if (typeof arg1 === 'string' || isRelativePattern(arg1)) { const parsedPattern = parsePattern(arg1, options); if (parsedPattern === NULL) { return FALSE; } const resultPattern = function (path, basename) { return !!parsedPattern(path, basename); }; if (parsedPattern.allBasenames) { resultPattern.allBasenames = parsedPattern.allBasenames; } if (parsedPattern.allPaths) { resultPattern.allPaths = parsedPattern.allPaths; } return resultPattern; } // Glob with Expression return parsedExpression(arg1, options); } function isRelativePattern(obj) { const rp = obj; if (!rp) { return false; } return typeof rp.base === 'string' && typeof rp.pattern === 'string'; } function parsedExpression(expression, options) { const parsedPatterns = aggregateBasenameMatches(Object.getOwnPropertyNames(expression) .map(pattern => parseExpressionPattern(pattern, expression[pattern], options)) .filter(pattern => pattern !== NULL)); const n = parsedPatterns.length; if (!n) { return NULL; } if (!parsedPatterns.some(parsedPattern => !!parsedPattern.requiresSiblings)) { if (n === 1) { return parsedPatterns[0]; } const resultExpression = function (path, basename) { for (let i = 0, n = parsedPatterns.length; i < n; i++) { // Pattern matches path const result = parsedPatterns[i](path, basename); if (result) { return result; } } return null; }; const withBasenames = parsedPatterns.find(pattern => !!pattern.allBasenames); if (withBasenames) { resultExpression.allBasenames = withBasenames.allBasenames; } const allPaths = parsedPatterns.reduce((all, current) => current.allPaths ? all.concat(current.allPaths) : all, []); if (allPaths.length) { resultExpression.allPaths = allPaths; } return resultExpression; } const resultExpression = function (path, base, hasSibling) { let name = undefined; for (let i = 0, n = parsedPatterns.length; i < n; i++) { // Pattern matches path const parsedPattern = parsedPatterns[i]; if (parsedPattern.requiresSiblings && hasSibling) { if (!base) { base = basename$1(path); } if (!name) { name = base.substr(0, base.length - extname$1(path).length); } } const result = parsedPattern(path, base, name, hasSibling); if (result) { return result; } } return null; }; const withBasenames = parsedPatterns.find(pattern => !!pattern.allBasenames); if (withBasenames) { resultExpression.allBasenames = withBasenames.allBasenames; } const allPaths = parsedPatterns.reduce((all, current) => current.allPaths ? all.concat(current.allPaths) : all, []); if (allPaths.length) { resultExpression.allPaths = allPaths; } return resultExpression; } function parseExpressionPattern(pattern, value, options) { if (value === false) { return NULL; // pattern is disabled } const parsedPattern = parsePattern(pattern, options); if (parsedPattern === NULL) { return NULL; } // Expression Pattern is if (typeof value === 'boolean') { return parsedPattern; } // Expression Pattern is if (value) { const when = value.when; if (typeof when === 'string') { const result = (path, basename, name, hasSibling) => { if (!hasSibling || !parsedPattern(path, basename)) { return null; } const clausePattern = when.replace('$(basename)', name); const matched = hasSibling(clausePattern); return isThenable$1(matched) ? matched.then(m => m ? pattern : null) : matched ? pattern : null; }; result.requiresSiblings = true; return result; } } // Expression is Anything return parsedPattern; } function aggregateBasenameMatches(parsedPatterns, result) { const basenamePatterns = parsedPatterns.filter(parsedPattern => !!parsedPattern.basenames); if (basenamePatterns.length < 2) { return parsedPatterns; } const basenames = basenamePatterns.reduce((all, current) => { const basenames = current.basenames; return basenames ? all.concat(basenames) : all; }, []); let patterns; if (result) { patterns = []; for (let i = 0, n = basenames.length; i < n; i++) { patterns.push(result); } } else { patterns = basenamePatterns.reduce((all, current) => { const patterns = current.patterns; return patterns ? all.concat(patterns) : all; }, []); } const aggregate = function (path, basename) { if (typeof path !== 'string') { return null; } if (!basename) { let i; for (i = path.length; i > 0; i--) { const ch = path.charCodeAt(i - 1); if (ch === 47 /* Slash */ || ch === 92 /* Backslash */) { break; } } basename = path.substr(i); } const index = basenames.indexOf(basename); return index !== -1 ? patterns[index] : null; }; aggregate.basenames = basenames; aggregate.patterns = patterns; aggregate.allBasenames = basenames; const aggregatedPatterns = parsedPatterns.filter(parsedPattern => !parsedPattern.basenames); aggregatedPatterns.push(aggregate); return aggregatedPatterns; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function score(selector, candidateUri, candidateLanguage, candidateIsSynchronized) { if (Array.isArray(selector)) { // array -> take max individual value let ret = 0; for (const filter of selector) { const value = score(filter, candidateUri, candidateLanguage, candidateIsSynchronized); if (value === 10) { return value; // already at the highest } if (value > ret) { ret = value; } } return ret; } else if (typeof selector === 'string') { if (!candidateIsSynchronized) { return 0; } // short-hand notion, desugars to // 'fooLang' -> { language: 'fooLang'} // '*' -> { language: '*' } if (selector === '*') { return 5; } else if (selector === candidateLanguage) { return 10; } else { return 0; } } else if (selector) { // filter -> select accordingly, use defaults for scheme const { language, pattern, scheme, hasAccessToAllModels } = selector; // TODO: microsoft/TypeScript#42768 if (!candidateIsSynchronized && !hasAccessToAllModels) { return 0; } let ret = 0; if (scheme) { if (scheme === candidateUri.scheme) { ret = 10; } else if (scheme === '*') { ret = 5; } else { return 0; } } if (language) { if (language === candidateLanguage) { ret = 10; } else if (language === '*') { ret = Math.max(ret, 5); } else { return 0; } } if (pattern) { let normalizedPattern; if (typeof pattern === 'string') { normalizedPattern = pattern; } else { // Since this pattern has a `base` property, we need // to normalize this path first before passing it on // because we will compare it against `Uri.fsPath` // which uses platform specific separators. // Refs: https://github.com/microsoft/vscode/issues/99938 normalizedPattern = Object.assign(Object.assign({}, pattern), { base: normalize(pattern.base) }); } if (normalizedPattern === candidateUri.fsPath || match(normalizedPattern, candidateUri.fsPath)) { ret = 10; } else { return 0; } } return ret; } else { return 0; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function isExclusive(selector) { if (typeof selector === 'string') { return false; } else if (Array.isArray(selector)) { return selector.every(isExclusive); } else { return !!selector.exclusive; // TODO: microsoft/TypeScript#42768 } } class LanguageFeatureRegistry { constructor() { this._clock = 0; this._entries = []; this._onDidChange = new Emitter$1(); } get onDidChange() { return this._onDidChange.event; } register(selector, provider) { let entry = { selector, provider, _score: -1, _time: this._clock++ }; this._entries.push(entry); this._lastCandidate = undefined; this._onDidChange.fire(this._entries.length); return toDisposable(() => { if (entry) { const idx = this._entries.indexOf(entry); if (idx >= 0) { this._entries.splice(idx, 1); this._lastCandidate = undefined; this._onDidChange.fire(this._entries.length); entry = undefined; } } }); } has(model) { return this.all(model).length > 0; } all(model) { if (!model) { return []; } this._updateScores(model); const result = []; // from registry for (let entry of this._entries) { if (entry._score > 0) { result.push(entry.provider); } } return result; } ordered(model) { const result = []; this._orderedForEach(model, entry => result.push(entry.provider)); return result; } orderedGroups(model) { const result = []; let lastBucket; let lastBucketScore; this._orderedForEach(model, entry => { if (lastBucket && lastBucketScore === entry._score) { lastBucket.push(entry.provider); } else { lastBucketScore = entry._score; lastBucket = [entry.provider]; result.push(lastBucket); } }); return result; } _orderedForEach(model, callback) { if (!model) { return; } this._updateScores(model); for (const entry of this._entries) { if (entry._score > 0) { callback(entry); } } } _updateScores(model) { const candidate = { uri: model.uri.toString(), language: model.getLanguageId() }; if (this._lastCandidate && this._lastCandidate.language === candidate.language && this._lastCandidate.uri === candidate.uri) { // nothing has changed return; } this._lastCandidate = candidate; for (let entry of this._entries) { entry._score = score(entry.selector, model.uri, model.getLanguageId(), shouldSynchronizeModel(model)); if (isExclusive(entry.selector) && entry._score > 0) { // support for one exclusive selector that overwrites // any other selector for (let entry of this._entries) { entry._score = 0; } entry._score = 1000; break; } } // needs sorting this._entries.sort(LanguageFeatureRegistry._compareByScoreAndTime); } static _compareByScoreAndTime(a, b) { if (a._score < b._score) { return 1; } else if (a._score > b._score) { return -1; } else if (a._time < b._time) { return 1; } else if (a._time > b._time) { return -1; } else { return 0; } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __awaiter$18 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; class TokenizationRegistry$1 { constructor() { this._map = new Map(); this._factories = new Map(); this._onDidChange = new Emitter$1(); this.onDidChange = this._onDidChange.event; this._colorMap = null; } fire(languages) { this._onDidChange.fire({ changedLanguages: languages, changedColorMap: false }); } register(language, support) { this._map.set(language, support); this.fire([language]); return toDisposable(() => { if (this._map.get(language) !== support) { return; } this._map.delete(language); this.fire([language]); }); } registerFactory(languageId, factory) { var _a; (_a = this._factories.get(languageId)) === null || _a === void 0 ? void 0 : _a.dispose(); const myData = new TokenizationSupportFactoryData(this, languageId, factory); this._factories.set(languageId, myData); return toDisposable(() => { const v = this._factories.get(languageId); if (!v || v !== myData) { return; } this._factories.delete(languageId); v.dispose(); }); } getOrCreate(languageId) { return __awaiter$18(this, void 0, void 0, function* () { // check first if the support is already set const tokenizationSupport = this.get(languageId); if (tokenizationSupport) { return tokenizationSupport; } const factory = this._factories.get(languageId); if (!factory || factory.isResolved) { // no factory or factory.resolve already finished return null; } yield factory.resolve(); return this.get(languageId); }); } get(language) { return (this._map.get(language) || null); } isResolved(languageId) { const tokenizationSupport = this.get(languageId); if (tokenizationSupport) { return true; } const factory = this._factories.get(languageId); if (!factory || factory.isResolved) { return true; } return false; } setColorMap(colorMap) { this._colorMap = colorMap; this._onDidChange.fire({ changedLanguages: Array.from(this._map.keys()), changedColorMap: true }); } getColorMap() { return this._colorMap; } getDefaultBackground() { if (this._colorMap && this._colorMap.length > 2 /* DefaultBackground */) { return this._colorMap[2 /* DefaultBackground */]; } return null; } } class TokenizationSupportFactoryData extends Disposable { constructor(_registry, _languageId, _factory) { super(); this._registry = _registry; this._languageId = _languageId; this._factory = _factory; this._isDisposed = false; this._resolvePromise = null; this._isResolved = false; } get isResolved() { return this._isResolved; } dispose() { this._isDisposed = true; super.dispose(); } resolve() { return __awaiter$18(this, void 0, void 0, function* () { if (!this._resolvePromise) { this._resolvePromise = this._create(); } return this._resolvePromise; }); } _create() { return __awaiter$18(this, void 0, void 0, function* () { const value = yield Promise.resolve(this._factory.createTokenizationSupport()); this._isResolved = true; if (value && !this._isDisposed) { this._register(this._registry.register(this._languageId, value)); } }); } } // Selects all codicon names encapsulated in the `$()` syntax and wraps the // results with spaces so that screen readers can read the text better. function getCodiconAriaLabel(text) { if (!text) { return ''; } return text.replace(/\$\((.*?)\)/g, (_match, codiconName) => ` ${codiconName} `).trim(); } /** * The Codicon library is a set of default icons that are built-in in VS Code. * * In the product (outside of base) Codicons should only be used as defaults. In order to have all icons in VS Code * themeable, component should define new, UI component specific icons using `iconRegistry.registerIcon`. * In that call a Codicon can be named as default. */ class Codicon { constructor(id, definition, description) { this.id = id; this.definition = definition; this.description = description; Codicon._allCodicons.push(this); } get classNames() { return 'codicon codicon-' + this.id; } // classNamesArray is useful for migrating to ES6 classlist get classNamesArray() { return ['codicon', 'codicon-' + this.id]; } get cssSelector() { return '.codicon.codicon-' + this.id; } /** * @returns Returns all default icons covered by the codicon font. Only to be used by the icon registry in platform. */ static getAll() { return Codicon._allCodicons; } } // registry Codicon._allCodicons = []; // built-in icons, with image name Codicon.add = new Codicon('add', { fontCharacter: '\\ea60' }); Codicon.plus = new Codicon('plus', Codicon.add.definition); Codicon.gistNew = new Codicon('gist-new', Codicon.add.definition); Codicon.repoCreate = new Codicon('repo-create', Codicon.add.definition); Codicon.lightbulb = new Codicon('lightbulb', { fontCharacter: '\\ea61' }); Codicon.lightBulb = new Codicon('light-bulb', { fontCharacter: '\\ea61' }); Codicon.repo = new Codicon('repo', { fontCharacter: '\\ea62' }); Codicon.repoDelete = new Codicon('repo-delete', { fontCharacter: '\\ea62' }); Codicon.gistFork = new Codicon('gist-fork', { fontCharacter: '\\ea63' }); Codicon.repoForked = new Codicon('repo-forked', { fontCharacter: '\\ea63' }); Codicon.gitPullRequest = new Codicon('git-pull-request', { fontCharacter: '\\ea64' }); Codicon.gitPullRequestAbandoned = new Codicon('git-pull-request-abandoned', { fontCharacter: '\\ea64' }); Codicon.recordKeys = new Codicon('record-keys', { fontCharacter: '\\ea65' }); Codicon.keyboard = new Codicon('keyboard', { fontCharacter: '\\ea65' }); Codicon.tag = new Codicon('tag', { fontCharacter: '\\ea66' }); Codicon.tagAdd = new Codicon('tag-add', { fontCharacter: '\\ea66' }); Codicon.tagRemove = new Codicon('tag-remove', { fontCharacter: '\\ea66' }); Codicon.person = new Codicon('person', { fontCharacter: '\\ea67' }); Codicon.personFollow = new Codicon('person-follow', { fontCharacter: '\\ea67' }); Codicon.personOutline = new Codicon('person-outline', { fontCharacter: '\\ea67' }); Codicon.personFilled = new Codicon('person-filled', { fontCharacter: '\\ea67' }); Codicon.gitBranch = new Codicon('git-branch', { fontCharacter: '\\ea68' }); Codicon.gitBranchCreate = new Codicon('git-branch-create', { fontCharacter: '\\ea68' }); Codicon.gitBranchDelete = new Codicon('git-branch-delete', { fontCharacter: '\\ea68' }); Codicon.sourceControl = new Codicon('source-control', { fontCharacter: '\\ea68' }); Codicon.mirror = new Codicon('mirror', { fontCharacter: '\\ea69' }); Codicon.mirrorPublic = new Codicon('mirror-public', { fontCharacter: '\\ea69' }); Codicon.star = new Codicon('star', { fontCharacter: '\\ea6a' }); Codicon.starAdd = new Codicon('star-add', { fontCharacter: '\\ea6a' }); Codicon.starDelete = new Codicon('star-delete', { fontCharacter: '\\ea6a' }); Codicon.starEmpty = new Codicon('star-empty', { fontCharacter: '\\ea6a' }); Codicon.comment = new Codicon('comment', { fontCharacter: '\\ea6b' }); Codicon.commentAdd = new Codicon('comment-add', { fontCharacter: '\\ea6b' }); Codicon.alert = new Codicon('alert', { fontCharacter: '\\ea6c' }); Codicon.warning = new Codicon('warning', { fontCharacter: '\\ea6c' }); Codicon.search = new Codicon('search', { fontCharacter: '\\ea6d' }); Codicon.searchSave = new Codicon('search-save', { fontCharacter: '\\ea6d' }); Codicon.logOut = new Codicon('log-out', { fontCharacter: '\\ea6e' }); Codicon.signOut = new Codicon('sign-out', { fontCharacter: '\\ea6e' }); Codicon.logIn = new Codicon('log-in', { fontCharacter: '\\ea6f' }); Codicon.signIn = new Codicon('sign-in', { fontCharacter: '\\ea6f' }); Codicon.eye = new Codicon('eye', { fontCharacter: '\\ea70' }); Codicon.eyeUnwatch = new Codicon('eye-unwatch', { fontCharacter: '\\ea70' }); Codicon.eyeWatch = new Codicon('eye-watch', { fontCharacter: '\\ea70' }); Codicon.circleFilled = new Codicon('circle-filled', { fontCharacter: '\\ea71' }); Codicon.primitiveDot = new Codicon('primitive-dot', { fontCharacter: '\\ea71' }); Codicon.closeDirty = new Codicon('close-dirty', { fontCharacter: '\\ea71' }); Codicon.debugBreakpoint = new Codicon('debug-breakpoint', { fontCharacter: '\\ea71' }); Codicon.debugBreakpointDisabled = new Codicon('debug-breakpoint-disabled', { fontCharacter: '\\ea71' }); Codicon.debugHint = new Codicon('debug-hint', { fontCharacter: '\\ea71' }); Codicon.primitiveSquare = new Codicon('primitive-square', { fontCharacter: '\\ea72' }); Codicon.edit = new Codicon('edit', { fontCharacter: '\\ea73' }); Codicon.pencil = new Codicon('pencil', { fontCharacter: '\\ea73' }); Codicon.info = new Codicon('info', { fontCharacter: '\\ea74' }); Codicon.issueOpened = new Codicon('issue-opened', { fontCharacter: '\\ea74' }); Codicon.gistPrivate = new Codicon('gist-private', { fontCharacter: '\\ea75' }); Codicon.gitForkPrivate = new Codicon('git-fork-private', { fontCharacter: '\\ea75' }); Codicon.lock = new Codicon('lock', { fontCharacter: '\\ea75' }); Codicon.mirrorPrivate = new Codicon('mirror-private', { fontCharacter: '\\ea75' }); Codicon.close = new Codicon('close', { fontCharacter: '\\ea76' }); Codicon.removeClose = new Codicon('remove-close', { fontCharacter: '\\ea76' }); Codicon.x = new Codicon('x', { fontCharacter: '\\ea76' }); Codicon.repoSync = new Codicon('repo-sync', { fontCharacter: '\\ea77' }); Codicon.sync = new Codicon('sync', { fontCharacter: '\\ea77' }); Codicon.clone = new Codicon('clone', { fontCharacter: '\\ea78' }); Codicon.desktopDownload = new Codicon('desktop-download', { fontCharacter: '\\ea78' }); Codicon.beaker = new Codicon('beaker', { fontCharacter: '\\ea79' }); Codicon.microscope = new Codicon('microscope', { fontCharacter: '\\ea79' }); Codicon.vm = new Codicon('vm', { fontCharacter: '\\ea7a' }); Codicon.deviceDesktop = new Codicon('device-desktop', { fontCharacter: '\\ea7a' }); Codicon.file = new Codicon('file', { fontCharacter: '\\ea7b' }); Codicon.fileText = new Codicon('file-text', { fontCharacter: '\\ea7b' }); Codicon.more = new Codicon('more', { fontCharacter: '\\ea7c' }); Codicon.ellipsis = new Codicon('ellipsis', { fontCharacter: '\\ea7c' }); Codicon.kebabHorizontal = new Codicon('kebab-horizontal', { fontCharacter: '\\ea7c' }); Codicon.mailReply = new Codicon('mail-reply', { fontCharacter: '\\ea7d' }); Codicon.reply = new Codicon('reply', { fontCharacter: '\\ea7d' }); Codicon.organization = new Codicon('organization', { fontCharacter: '\\ea7e' }); Codicon.organizationFilled = new Codicon('organization-filled', { fontCharacter: '\\ea7e' }); Codicon.organizationOutline = new Codicon('organization-outline', { fontCharacter: '\\ea7e' }); Codicon.newFile = new Codicon('new-file', { fontCharacter: '\\ea7f' }); Codicon.fileAdd = new Codicon('file-add', { fontCharacter: '\\ea7f' }); Codicon.newFolder = new Codicon('new-folder', { fontCharacter: '\\ea80' }); Codicon.fileDirectoryCreate = new Codicon('file-directory-create', { fontCharacter: '\\ea80' }); Codicon.trash = new Codicon('trash', { fontCharacter: '\\ea81' }); Codicon.trashcan = new Codicon('trashcan', { fontCharacter: '\\ea81' }); Codicon.history = new Codicon('history', { fontCharacter: '\\ea82' }); Codicon.clock = new Codicon('clock', { fontCharacter: '\\ea82' }); Codicon.folder = new Codicon('folder', { fontCharacter: '\\ea83' }); Codicon.fileDirectory = new Codicon('file-directory', { fontCharacter: '\\ea83' }); Codicon.symbolFolder = new Codicon('symbol-folder', { fontCharacter: '\\ea83' }); Codicon.logoGithub = new Codicon('logo-github', { fontCharacter: '\\ea84' }); Codicon.markGithub = new Codicon('mark-github', { fontCharacter: '\\ea84' }); Codicon.github = new Codicon('github', { fontCharacter: '\\ea84' }); Codicon.terminal = new Codicon('terminal', { fontCharacter: '\\ea85' }); Codicon.console = new Codicon('console', { fontCharacter: '\\ea85' }); Codicon.repl = new Codicon('repl', { fontCharacter: '\\ea85' }); Codicon.zap = new Codicon('zap', { fontCharacter: '\\ea86' }); Codicon.symbolEvent = new Codicon('symbol-event', { fontCharacter: '\\ea86' }); Codicon.error = new Codicon('error', { fontCharacter: '\\ea87' }); Codicon.stop = new Codicon('stop', { fontCharacter: '\\ea87' }); Codicon.variable = new Codicon('variable', { fontCharacter: '\\ea88' }); Codicon.symbolVariable = new Codicon('symbol-variable', { fontCharacter: '\\ea88' }); Codicon.array = new Codicon('array', { fontCharacter: '\\ea8a' }); Codicon.symbolArray = new Codicon('symbol-array', { fontCharacter: '\\ea8a' }); Codicon.symbolModule = new Codicon('symbol-module', { fontCharacter: '\\ea8b' }); Codicon.symbolPackage = new Codicon('symbol-package', { fontCharacter: '\\ea8b' }); Codicon.symbolNamespace = new Codicon('symbol-namespace', { fontCharacter: '\\ea8b' }); Codicon.symbolObject = new Codicon('symbol-object', { fontCharacter: '\\ea8b' }); Codicon.symbolMethod = new Codicon('symbol-method', { fontCharacter: '\\ea8c' }); Codicon.symbolFunction = new Codicon('symbol-function', { fontCharacter: '\\ea8c' }); Codicon.symbolConstructor = new Codicon('symbol-constructor', { fontCharacter: '\\ea8c' }); Codicon.symbolBoolean = new Codicon('symbol-boolean', { fontCharacter: '\\ea8f' }); Codicon.symbolNull = new Codicon('symbol-null', { fontCharacter: '\\ea8f' }); Codicon.symbolNumeric = new Codicon('symbol-numeric', { fontCharacter: '\\ea90' }); Codicon.symbolNumber = new Codicon('symbol-number', { fontCharacter: '\\ea90' }); Codicon.symbolStructure = new Codicon('symbol-structure', { fontCharacter: '\\ea91' }); Codicon.symbolStruct = new Codicon('symbol-struct', { fontCharacter: '\\ea91' }); Codicon.symbolParameter = new Codicon('symbol-parameter', { fontCharacter: '\\ea92' }); Codicon.symbolTypeParameter = new Codicon('symbol-type-parameter', { fontCharacter: '\\ea92' }); Codicon.symbolKey = new Codicon('symbol-key', { fontCharacter: '\\ea93' }); Codicon.symbolText = new Codicon('symbol-text', { fontCharacter: '\\ea93' }); Codicon.symbolReference = new Codicon('symbol-reference', { fontCharacter: '\\ea94' }); Codicon.goToFile = new Codicon('go-to-file', { fontCharacter: '\\ea94' }); Codicon.symbolEnum = new Codicon('symbol-enum', { fontCharacter: '\\ea95' }); Codicon.symbolValue = new Codicon('symbol-value', { fontCharacter: '\\ea95' }); Codicon.symbolRuler = new Codicon('symbol-ruler', { fontCharacter: '\\ea96' }); Codicon.symbolUnit = new Codicon('symbol-unit', { fontCharacter: '\\ea96' }); Codicon.activateBreakpoints = new Codicon('activate-breakpoints', { fontCharacter: '\\ea97' }); Codicon.archive = new Codicon('archive', { fontCharacter: '\\ea98' }); Codicon.arrowBoth = new Codicon('arrow-both', { fontCharacter: '\\ea99' }); Codicon.arrowDown = new Codicon('arrow-down', { fontCharacter: '\\ea9a' }); Codicon.arrowLeft = new Codicon('arrow-left', { fontCharacter: '\\ea9b' }); Codicon.arrowRight = new Codicon('arrow-right', { fontCharacter: '\\ea9c' }); Codicon.arrowSmallDown = new Codicon('arrow-small-down', { fontCharacter: '\\ea9d' }); Codicon.arrowSmallLeft = new Codicon('arrow-small-left', { fontCharacter: '\\ea9e' }); Codicon.arrowSmallRight = new Codicon('arrow-small-right', { fontCharacter: '\\ea9f' }); Codicon.arrowSmallUp = new Codicon('arrow-small-up', { fontCharacter: '\\eaa0' }); Codicon.arrowUp = new Codicon('arrow-up', { fontCharacter: '\\eaa1' }); Codicon.bell = new Codicon('bell', { fontCharacter: '\\eaa2' }); Codicon.bold = new Codicon('bold', { fontCharacter: '\\eaa3' }); Codicon.book = new Codicon('book', { fontCharacter: '\\eaa4' }); Codicon.bookmark = new Codicon('bookmark', { fontCharacter: '\\eaa5' }); Codicon.debugBreakpointConditionalUnverified = new Codicon('debug-breakpoint-conditional-unverified', { fontCharacter: '\\eaa6' }); Codicon.debugBreakpointConditional = new Codicon('debug-breakpoint-conditional', { fontCharacter: '\\eaa7' }); Codicon.debugBreakpointConditionalDisabled = new Codicon('debug-breakpoint-conditional-disabled', { fontCharacter: '\\eaa7' }); Codicon.debugBreakpointDataUnverified = new Codicon('debug-breakpoint-data-unverified', { fontCharacter: '\\eaa8' }); Codicon.debugBreakpointData = new Codicon('debug-breakpoint-data', { fontCharacter: '\\eaa9' }); Codicon.debugBreakpointDataDisabled = new Codicon('debug-breakpoint-data-disabled', { fontCharacter: '\\eaa9' }); Codicon.debugBreakpointLogUnverified = new Codicon('debug-breakpoint-log-unverified', { fontCharacter: '\\eaaa' }); Codicon.debugBreakpointLog = new Codicon('debug-breakpoint-log', { fontCharacter: '\\eaab' }); Codicon.debugBreakpointLogDisabled = new Codicon('debug-breakpoint-log-disabled', { fontCharacter: '\\eaab' }); Codicon.briefcase = new Codicon('briefcase', { fontCharacter: '\\eaac' }); Codicon.broadcast = new Codicon('broadcast', { fontCharacter: '\\eaad' }); Codicon.browser = new Codicon('browser', { fontCharacter: '\\eaae' }); Codicon.bug = new Codicon('bug', { fontCharacter: '\\eaaf' }); Codicon.calendar = new Codicon('calendar', { fontCharacter: '\\eab0' }); Codicon.caseSensitive = new Codicon('case-sensitive', { fontCharacter: '\\eab1' }); Codicon.check = new Codicon('check', { fontCharacter: '\\eab2' }); Codicon.checklist = new Codicon('checklist', { fontCharacter: '\\eab3' }); Codicon.chevronDown = new Codicon('chevron-down', { fontCharacter: '\\eab4' }); Codicon.dropDownButton = new Codicon('drop-down-button', Codicon.chevronDown.definition); Codicon.chevronLeft = new Codicon('chevron-left', { fontCharacter: '\\eab5' }); Codicon.chevronRight = new Codicon('chevron-right', { fontCharacter: '\\eab6' }); Codicon.chevronUp = new Codicon('chevron-up', { fontCharacter: '\\eab7' }); Codicon.chromeClose = new Codicon('chrome-close', { fontCharacter: '\\eab8' }); Codicon.chromeMaximize = new Codicon('chrome-maximize', { fontCharacter: '\\eab9' }); Codicon.chromeMinimize = new Codicon('chrome-minimize', { fontCharacter: '\\eaba' }); Codicon.chromeRestore = new Codicon('chrome-restore', { fontCharacter: '\\eabb' }); Codicon.circleOutline = new Codicon('circle-outline', { fontCharacter: '\\eabc' }); Codicon.debugBreakpointUnverified = new Codicon('debug-breakpoint-unverified', { fontCharacter: '\\eabc' }); Codicon.circleSlash = new Codicon('circle-slash', { fontCharacter: '\\eabd' }); Codicon.circuitBoard = new Codicon('circuit-board', { fontCharacter: '\\eabe' }); Codicon.clearAll = new Codicon('clear-all', { fontCharacter: '\\eabf' }); Codicon.clippy = new Codicon('clippy', { fontCharacter: '\\eac0' }); Codicon.closeAll = new Codicon('close-all', { fontCharacter: '\\eac1' }); Codicon.cloudDownload = new Codicon('cloud-download', { fontCharacter: '\\eac2' }); Codicon.cloudUpload = new Codicon('cloud-upload', { fontCharacter: '\\eac3' }); Codicon.code = new Codicon('code', { fontCharacter: '\\eac4' }); Codicon.collapseAll = new Codicon('collapse-all', { fontCharacter: '\\eac5' }); Codicon.colorMode = new Codicon('color-mode', { fontCharacter: '\\eac6' }); Codicon.commentDiscussion = new Codicon('comment-discussion', { fontCharacter: '\\eac7' }); Codicon.compareChanges = new Codicon('compare-changes', { fontCharacter: '\\eafd' }); Codicon.creditCard = new Codicon('credit-card', { fontCharacter: '\\eac9' }); Codicon.dash = new Codicon('dash', { fontCharacter: '\\eacc' }); Codicon.dashboard = new Codicon('dashboard', { fontCharacter: '\\eacd' }); Codicon.database = new Codicon('database', { fontCharacter: '\\eace' }); Codicon.debugContinue = new Codicon('debug-continue', { fontCharacter: '\\eacf' }); Codicon.debugDisconnect = new Codicon('debug-disconnect', { fontCharacter: '\\ead0' }); Codicon.debugPause = new Codicon('debug-pause', { fontCharacter: '\\ead1' }); Codicon.debugRestart = new Codicon('debug-restart', { fontCharacter: '\\ead2' }); Codicon.debugStart = new Codicon('debug-start', { fontCharacter: '\\ead3' }); Codicon.debugStepInto = new Codicon('debug-step-into', { fontCharacter: '\\ead4' }); Codicon.debugStepOut = new Codicon('debug-step-out', { fontCharacter: '\\ead5' }); Codicon.debugStepOver = new Codicon('debug-step-over', { fontCharacter: '\\ead6' }); Codicon.debugStop = new Codicon('debug-stop', { fontCharacter: '\\ead7' }); Codicon.debug = new Codicon('debug', { fontCharacter: '\\ead8' }); Codicon.deviceCameraVideo = new Codicon('device-camera-video', { fontCharacter: '\\ead9' }); Codicon.deviceCamera = new Codicon('device-camera', { fontCharacter: '\\eada' }); Codicon.deviceMobile = new Codicon('device-mobile', { fontCharacter: '\\eadb' }); Codicon.diffAdded = new Codicon('diff-added', { fontCharacter: '\\eadc' }); Codicon.diffIgnored = new Codicon('diff-ignored', { fontCharacter: '\\eadd' }); Codicon.diffModified = new Codicon('diff-modified', { fontCharacter: '\\eade' }); Codicon.diffRemoved = new Codicon('diff-removed', { fontCharacter: '\\eadf' }); Codicon.diffRenamed = new Codicon('diff-renamed', { fontCharacter: '\\eae0' }); Codicon.diff = new Codicon('diff', { fontCharacter: '\\eae1' }); Codicon.discard = new Codicon('discard', { fontCharacter: '\\eae2' }); Codicon.editorLayout = new Codicon('editor-layout', { fontCharacter: '\\eae3' }); Codicon.emptyWindow = new Codicon('empty-window', { fontCharacter: '\\eae4' }); Codicon.exclude = new Codicon('exclude', { fontCharacter: '\\eae5' }); Codicon.extensions = new Codicon('extensions', { fontCharacter: '\\eae6' }); Codicon.eyeClosed = new Codicon('eye-closed', { fontCharacter: '\\eae7' }); Codicon.fileBinary = new Codicon('file-binary', { fontCharacter: '\\eae8' }); Codicon.fileCode = new Codicon('file-code', { fontCharacter: '\\eae9' }); Codicon.fileMedia = new Codicon('file-media', { fontCharacter: '\\eaea' }); Codicon.filePdf = new Codicon('file-pdf', { fontCharacter: '\\eaeb' }); Codicon.fileSubmodule = new Codicon('file-submodule', { fontCharacter: '\\eaec' }); Codicon.fileSymlinkDirectory = new Codicon('file-symlink-directory', { fontCharacter: '\\eaed' }); Codicon.fileSymlinkFile = new Codicon('file-symlink-file', { fontCharacter: '\\eaee' }); Codicon.fileZip = new Codicon('file-zip', { fontCharacter: '\\eaef' }); Codicon.files = new Codicon('files', { fontCharacter: '\\eaf0' }); Codicon.filter = new Codicon('filter', { fontCharacter: '\\eaf1' }); Codicon.flame = new Codicon('flame', { fontCharacter: '\\eaf2' }); Codicon.foldDown = new Codicon('fold-down', { fontCharacter: '\\eaf3' }); Codicon.foldUp = new Codicon('fold-up', { fontCharacter: '\\eaf4' }); Codicon.fold = new Codicon('fold', { fontCharacter: '\\eaf5' }); Codicon.folderActive = new Codicon('folder-active', { fontCharacter: '\\eaf6' }); Codicon.folderOpened = new Codicon('folder-opened', { fontCharacter: '\\eaf7' }); Codicon.gear = new Codicon('gear', { fontCharacter: '\\eaf8' }); Codicon.gift = new Codicon('gift', { fontCharacter: '\\eaf9' }); Codicon.gistSecret = new Codicon('gist-secret', { fontCharacter: '\\eafa' }); Codicon.gist = new Codicon('gist', { fontCharacter: '\\eafb' }); Codicon.gitCommit = new Codicon('git-commit', { fontCharacter: '\\eafc' }); Codicon.gitCompare = new Codicon('git-compare', { fontCharacter: '\\eafd' }); Codicon.gitMerge = new Codicon('git-merge', { fontCharacter: '\\eafe' }); Codicon.githubAction = new Codicon('github-action', { fontCharacter: '\\eaff' }); Codicon.githubAlt = new Codicon('github-alt', { fontCharacter: '\\eb00' }); Codicon.globe = new Codicon('globe', { fontCharacter: '\\eb01' }); Codicon.grabber = new Codicon('grabber', { fontCharacter: '\\eb02' }); Codicon.graph = new Codicon('graph', { fontCharacter: '\\eb03' }); Codicon.gripper = new Codicon('gripper', { fontCharacter: '\\eb04' }); Codicon.heart = new Codicon('heart', { fontCharacter: '\\eb05' }); Codicon.home = new Codicon('home', { fontCharacter: '\\eb06' }); Codicon.horizontalRule = new Codicon('horizontal-rule', { fontCharacter: '\\eb07' }); Codicon.hubot = new Codicon('hubot', { fontCharacter: '\\eb08' }); Codicon.inbox = new Codicon('inbox', { fontCharacter: '\\eb09' }); Codicon.issueClosed = new Codicon('issue-closed', { fontCharacter: '\\eba4' }); Codicon.issueReopened = new Codicon('issue-reopened', { fontCharacter: '\\eb0b' }); Codicon.issues = new Codicon('issues', { fontCharacter: '\\eb0c' }); Codicon.italic = new Codicon('italic', { fontCharacter: '\\eb0d' }); Codicon.jersey = new Codicon('jersey', { fontCharacter: '\\eb0e' }); Codicon.json = new Codicon('json', { fontCharacter: '\\eb0f' }); Codicon.kebabVertical = new Codicon('kebab-vertical', { fontCharacter: '\\eb10' }); Codicon.key = new Codicon('key', { fontCharacter: '\\eb11' }); Codicon.law = new Codicon('law', { fontCharacter: '\\eb12' }); Codicon.lightbulbAutofix = new Codicon('lightbulb-autofix', { fontCharacter: '\\eb13' }); Codicon.linkExternal = new Codicon('link-external', { fontCharacter: '\\eb14' }); Codicon.link = new Codicon('link', { fontCharacter: '\\eb15' }); Codicon.listOrdered = new Codicon('list-ordered', { fontCharacter: '\\eb16' }); Codicon.listUnordered = new Codicon('list-unordered', { fontCharacter: '\\eb17' }); Codicon.liveShare = new Codicon('live-share', { fontCharacter: '\\eb18' }); Codicon.loading = new Codicon('loading', { fontCharacter: '\\eb19' }); Codicon.location = new Codicon('location', { fontCharacter: '\\eb1a' }); Codicon.mailRead = new Codicon('mail-read', { fontCharacter: '\\eb1b' }); Codicon.mail = new Codicon('mail', { fontCharacter: '\\eb1c' }); Codicon.markdown = new Codicon('markdown', { fontCharacter: '\\eb1d' }); Codicon.megaphone = new Codicon('megaphone', { fontCharacter: '\\eb1e' }); Codicon.mention = new Codicon('mention', { fontCharacter: '\\eb1f' }); Codicon.milestone = new Codicon('milestone', { fontCharacter: '\\eb20' }); Codicon.mortarBoard = new Codicon('mortar-board', { fontCharacter: '\\eb21' }); Codicon.move = new Codicon('move', { fontCharacter: '\\eb22' }); Codicon.multipleWindows = new Codicon('multiple-windows', { fontCharacter: '\\eb23' }); Codicon.mute = new Codicon('mute', { fontCharacter: '\\eb24' }); Codicon.noNewline = new Codicon('no-newline', { fontCharacter: '\\eb25' }); Codicon.note = new Codicon('note', { fontCharacter: '\\eb26' }); Codicon.octoface = new Codicon('octoface', { fontCharacter: '\\eb27' }); Codicon.openPreview = new Codicon('open-preview', { fontCharacter: '\\eb28' }); Codicon.package_ = new Codicon('package', { fontCharacter: '\\eb29' }); Codicon.paintcan = new Codicon('paintcan', { fontCharacter: '\\eb2a' }); Codicon.pin = new Codicon('pin', { fontCharacter: '\\eb2b' }); Codicon.play = new Codicon('play', { fontCharacter: '\\eb2c' }); Codicon.run = new Codicon('run', { fontCharacter: '\\eb2c' }); Codicon.plug = new Codicon('plug', { fontCharacter: '\\eb2d' }); Codicon.preserveCase = new Codicon('preserve-case', { fontCharacter: '\\eb2e' }); Codicon.preview = new Codicon('preview', { fontCharacter: '\\eb2f' }); Codicon.project = new Codicon('project', { fontCharacter: '\\eb30' }); Codicon.pulse = new Codicon('pulse', { fontCharacter: '\\eb31' }); Codicon.question = new Codicon('question', { fontCharacter: '\\eb32' }); Codicon.quote = new Codicon('quote', { fontCharacter: '\\eb33' }); Codicon.radioTower = new Codicon('radio-tower', { fontCharacter: '\\eb34' }); Codicon.reactions = new Codicon('reactions', { fontCharacter: '\\eb35' }); Codicon.references = new Codicon('references', { fontCharacter: '\\eb36' }); Codicon.refresh = new Codicon('refresh', { fontCharacter: '\\eb37' }); Codicon.regex = new Codicon('regex', { fontCharacter: '\\eb38' }); Codicon.remoteExplorer = new Codicon('remote-explorer', { fontCharacter: '\\eb39' }); Codicon.remote = new Codicon('remote', { fontCharacter: '\\eb3a' }); Codicon.remove = new Codicon('remove', { fontCharacter: '\\eb3b' }); Codicon.replaceAll = new Codicon('replace-all', { fontCharacter: '\\eb3c' }); Codicon.replace = new Codicon('replace', { fontCharacter: '\\eb3d' }); Codicon.repoClone = new Codicon('repo-clone', { fontCharacter: '\\eb3e' }); Codicon.repoForcePush = new Codicon('repo-force-push', { fontCharacter: '\\eb3f' }); Codicon.repoPull = new Codicon('repo-pull', { fontCharacter: '\\eb40' }); Codicon.repoPush = new Codicon('repo-push', { fontCharacter: '\\eb41' }); Codicon.report = new Codicon('report', { fontCharacter: '\\eb42' }); Codicon.requestChanges = new Codicon('request-changes', { fontCharacter: '\\eb43' }); Codicon.rocket = new Codicon('rocket', { fontCharacter: '\\eb44' }); Codicon.rootFolderOpened = new Codicon('root-folder-opened', { fontCharacter: '\\eb45' }); Codicon.rootFolder = new Codicon('root-folder', { fontCharacter: '\\eb46' }); Codicon.rss = new Codicon('rss', { fontCharacter: '\\eb47' }); Codicon.ruby = new Codicon('ruby', { fontCharacter: '\\eb48' }); Codicon.saveAll = new Codicon('save-all', { fontCharacter: '\\eb49' }); Codicon.saveAs = new Codicon('save-as', { fontCharacter: '\\eb4a' }); Codicon.save = new Codicon('save', { fontCharacter: '\\eb4b' }); Codicon.screenFull = new Codicon('screen-full', { fontCharacter: '\\eb4c' }); Codicon.screenNormal = new Codicon('screen-normal', { fontCharacter: '\\eb4d' }); Codicon.searchStop = new Codicon('search-stop', { fontCharacter: '\\eb4e' }); Codicon.server = new Codicon('server', { fontCharacter: '\\eb50' }); Codicon.settingsGear = new Codicon('settings-gear', { fontCharacter: '\\eb51' }); Codicon.settings = new Codicon('settings', { fontCharacter: '\\eb52' }); Codicon.shield = new Codicon('shield', { fontCharacter: '\\eb53' }); Codicon.smiley = new Codicon('smiley', { fontCharacter: '\\eb54' }); Codicon.sortPrecedence = new Codicon('sort-precedence', { fontCharacter: '\\eb55' }); Codicon.splitHorizontal = new Codicon('split-horizontal', { fontCharacter: '\\eb56' }); Codicon.splitVertical = new Codicon('split-vertical', { fontCharacter: '\\eb57' }); Codicon.squirrel = new Codicon('squirrel', { fontCharacter: '\\eb58' }); Codicon.starFull = new Codicon('star-full', { fontCharacter: '\\eb59' }); Codicon.starHalf = new Codicon('star-half', { fontCharacter: '\\eb5a' }); Codicon.symbolClass = new Codicon('symbol-class', { fontCharacter: '\\eb5b' }); Codicon.symbolColor = new Codicon('symbol-color', { fontCharacter: '\\eb5c' }); Codicon.symbolCustomColor = new Codicon('symbol-customcolor', { fontCharacter: '\\eb5c' }); Codicon.symbolConstant = new Codicon('symbol-constant', { fontCharacter: '\\eb5d' }); Codicon.symbolEnumMember = new Codicon('symbol-enum-member', { fontCharacter: '\\eb5e' }); Codicon.symbolField = new Codicon('symbol-field', { fontCharacter: '\\eb5f' }); Codicon.symbolFile = new Codicon('symbol-file', { fontCharacter: '\\eb60' }); Codicon.symbolInterface = new Codicon('symbol-interface', { fontCharacter: '\\eb61' }); Codicon.symbolKeyword = new Codicon('symbol-keyword', { fontCharacter: '\\eb62' }); Codicon.symbolMisc = new Codicon('symbol-misc', { fontCharacter: '\\eb63' }); Codicon.symbolOperator = new Codicon('symbol-operator', { fontCharacter: '\\eb64' }); Codicon.symbolProperty = new Codicon('symbol-property', { fontCharacter: '\\eb65' }); Codicon.wrench = new Codicon('wrench', { fontCharacter: '\\eb65' }); Codicon.wrenchSubaction = new Codicon('wrench-subaction', { fontCharacter: '\\eb65' }); Codicon.symbolSnippet = new Codicon('symbol-snippet', { fontCharacter: '\\eb66' }); Codicon.tasklist = new Codicon('tasklist', { fontCharacter: '\\eb67' }); Codicon.telescope = new Codicon('telescope', { fontCharacter: '\\eb68' }); Codicon.textSize = new Codicon('text-size', { fontCharacter: '\\eb69' }); Codicon.threeBars = new Codicon('three-bars', { fontCharacter: '\\eb6a' }); Codicon.thumbsdown = new Codicon('thumbsdown', { fontCharacter: '\\eb6b' }); Codicon.thumbsup = new Codicon('thumbsup', { fontCharacter: '\\eb6c' }); Codicon.tools = new Codicon('tools', { fontCharacter: '\\eb6d' }); Codicon.triangleDown = new Codicon('triangle-down', { fontCharacter: '\\eb6e' }); Codicon.triangleLeft = new Codicon('triangle-left', { fontCharacter: '\\eb6f' }); Codicon.triangleRight = new Codicon('triangle-right', { fontCharacter: '\\eb70' }); Codicon.triangleUp = new Codicon('triangle-up', { fontCharacter: '\\eb71' }); Codicon.twitter = new Codicon('twitter', { fontCharacter: '\\eb72' }); Codicon.unfold = new Codicon('unfold', { fontCharacter: '\\eb73' }); Codicon.unlock = new Codicon('unlock', { fontCharacter: '\\eb74' }); Codicon.unmute = new Codicon('unmute', { fontCharacter: '\\eb75' }); Codicon.unverified = new Codicon('unverified', { fontCharacter: '\\eb76' }); Codicon.verified = new Codicon('verified', { fontCharacter: '\\eb77' }); Codicon.versions = new Codicon('versions', { fontCharacter: '\\eb78' }); Codicon.vmActive = new Codicon('vm-active', { fontCharacter: '\\eb79' }); Codicon.vmOutline = new Codicon('vm-outline', { fontCharacter: '\\eb7a' }); Codicon.vmRunning = new Codicon('vm-running', { fontCharacter: '\\eb7b' }); Codicon.watch = new Codicon('watch', { fontCharacter: '\\eb7c' }); Codicon.whitespace = new Codicon('whitespace', { fontCharacter: '\\eb7d' }); Codicon.wholeWord = new Codicon('whole-word', { fontCharacter: '\\eb7e' }); Codicon.window = new Codicon('window', { fontCharacter: '\\eb7f' }); Codicon.wordWrap = new Codicon('word-wrap', { fontCharacter: '\\eb80' }); Codicon.zoomIn = new Codicon('zoom-in', { fontCharacter: '\\eb81' }); Codicon.zoomOut = new Codicon('zoom-out', { fontCharacter: '\\eb82' }); Codicon.listFilter = new Codicon('list-filter', { fontCharacter: '\\eb83' }); Codicon.listFlat = new Codicon('list-flat', { fontCharacter: '\\eb84' }); Codicon.listSelection = new Codicon('list-selection', { fontCharacter: '\\eb85' }); Codicon.selection = new Codicon('selection', { fontCharacter: '\\eb85' }); Codicon.listTree = new Codicon('list-tree', { fontCharacter: '\\eb86' }); Codicon.debugBreakpointFunctionUnverified = new Codicon('debug-breakpoint-function-unverified', { fontCharacter: '\\eb87' }); Codicon.debugBreakpointFunction = new Codicon('debug-breakpoint-function', { fontCharacter: '\\eb88' }); Codicon.debugBreakpointFunctionDisabled = new Codicon('debug-breakpoint-function-disabled', { fontCharacter: '\\eb88' }); Codicon.debugStackframeActive = new Codicon('debug-stackframe-active', { fontCharacter: '\\eb89' }); Codicon.debugStackframeDot = new Codicon('debug-stackframe-dot', { fontCharacter: '\\eb8a' }); Codicon.debugStackframe = new Codicon('debug-stackframe', { fontCharacter: '\\eb8b' }); Codicon.debugStackframeFocused = new Codicon('debug-stackframe-focused', { fontCharacter: '\\eb8b' }); Codicon.debugBreakpointUnsupported = new Codicon('debug-breakpoint-unsupported', { fontCharacter: '\\eb8c' }); Codicon.symbolString = new Codicon('symbol-string', { fontCharacter: '\\eb8d' }); Codicon.debugReverseContinue = new Codicon('debug-reverse-continue', { fontCharacter: '\\eb8e' }); Codicon.debugStepBack = new Codicon('debug-step-back', { fontCharacter: '\\eb8f' }); Codicon.debugRestartFrame = new Codicon('debug-restart-frame', { fontCharacter: '\\eb90' }); Codicon.callIncoming = new Codicon('call-incoming', { fontCharacter: '\\eb92' }); Codicon.callOutgoing = new Codicon('call-outgoing', { fontCharacter: '\\eb93' }); Codicon.menu = new Codicon('menu', { fontCharacter: '\\eb94' }); Codicon.expandAll = new Codicon('expand-all', { fontCharacter: '\\eb95' }); Codicon.feedback = new Codicon('feedback', { fontCharacter: '\\eb96' }); Codicon.groupByRefType = new Codicon('group-by-ref-type', { fontCharacter: '\\eb97' }); Codicon.ungroupByRefType = new Codicon('ungroup-by-ref-type', { fontCharacter: '\\eb98' }); Codicon.account = new Codicon('account', { fontCharacter: '\\eb99' }); Codicon.bellDot = new Codicon('bell-dot', { fontCharacter: '\\eb9a' }); Codicon.debugConsole = new Codicon('debug-console', { fontCharacter: '\\eb9b' }); Codicon.library = new Codicon('library', { fontCharacter: '\\eb9c' }); Codicon.output = new Codicon('output', { fontCharacter: '\\eb9d' }); Codicon.runAll = new Codicon('run-all', { fontCharacter: '\\eb9e' }); Codicon.syncIgnored = new Codicon('sync-ignored', { fontCharacter: '\\eb9f' }); Codicon.pinned = new Codicon('pinned', { fontCharacter: '\\eba0' }); Codicon.githubInverted = new Codicon('github-inverted', { fontCharacter: '\\eba1' }); Codicon.debugAlt = new Codicon('debug-alt', { fontCharacter: '\\eb91' }); Codicon.serverProcess = new Codicon('server-process', { fontCharacter: '\\eba2' }); Codicon.serverEnvironment = new Codicon('server-environment', { fontCharacter: '\\eba3' }); Codicon.pass = new Codicon('pass', { fontCharacter: '\\eba4' }); Codicon.stopCircle = new Codicon('stop-circle', { fontCharacter: '\\eba5' }); Codicon.playCircle = new Codicon('play-circle', { fontCharacter: '\\eba6' }); Codicon.record = new Codicon('record', { fontCharacter: '\\eba7' }); Codicon.debugAltSmall = new Codicon('debug-alt-small', { fontCharacter: '\\eba8' }); Codicon.vmConnect = new Codicon('vm-connect', { fontCharacter: '\\eba9' }); Codicon.cloud = new Codicon('cloud', { fontCharacter: '\\ebaa' }); Codicon.merge = new Codicon('merge', { fontCharacter: '\\ebab' }); Codicon.exportIcon = new Codicon('export', { fontCharacter: '\\ebac' }); Codicon.graphLeft = new Codicon('graph-left', { fontCharacter: '\\ebad' }); Codicon.magnet = new Codicon('magnet', { fontCharacter: '\\ebae' }); Codicon.notebook = new Codicon('notebook', { fontCharacter: '\\ebaf' }); Codicon.redo = new Codicon('redo', { fontCharacter: '\\ebb0' }); Codicon.checkAll = new Codicon('check-all', { fontCharacter: '\\ebb1' }); Codicon.pinnedDirty = new Codicon('pinned-dirty', { fontCharacter: '\\ebb2' }); Codicon.passFilled = new Codicon('pass-filled', { fontCharacter: '\\ebb3' }); Codicon.circleLargeFilled = new Codicon('circle-large-filled', { fontCharacter: '\\ebb4' }); Codicon.circleLargeOutline = new Codicon('circle-large-outline', { fontCharacter: '\\ebb5' }); Codicon.combine = new Codicon('combine', { fontCharacter: '\\ebb6' }); Codicon.gather = new Codicon('gather', { fontCharacter: '\\ebb6' }); Codicon.table = new Codicon('table', { fontCharacter: '\\ebb7' }); Codicon.variableGroup = new Codicon('variable-group', { fontCharacter: '\\ebb8' }); Codicon.typeHierarchy = new Codicon('type-hierarchy', { fontCharacter: '\\ebb9' }); Codicon.typeHierarchySub = new Codicon('type-hierarchy-sub', { fontCharacter: '\\ebba' }); Codicon.typeHierarchySuper = new Codicon('type-hierarchy-super', { fontCharacter: '\\ebbb' }); Codicon.gitPullRequestCreate = new Codicon('git-pull-request-create', { fontCharacter: '\\ebbc' }); Codicon.runAbove = new Codicon('run-above', { fontCharacter: '\\ebbd' }); Codicon.runBelow = new Codicon('run-below', { fontCharacter: '\\ebbe' }); Codicon.notebookTemplate = new Codicon('notebook-template', { fontCharacter: '\\ebbf' }); Codicon.debugRerun = new Codicon('debug-rerun', { fontCharacter: '\\ebc0' }); Codicon.workspaceTrusted = new Codicon('workspace-trusted', { fontCharacter: '\\ebc1' }); Codicon.workspaceUntrusted = new Codicon('workspace-untrusted', { fontCharacter: '\\ebc2' }); Codicon.workspaceUnspecified = new Codicon('workspace-unspecified', { fontCharacter: '\\ebc3' }); Codicon.terminalCmd = new Codicon('terminal-cmd', { fontCharacter: '\\ebc4' }); Codicon.terminalDebian = new Codicon('terminal-debian', { fontCharacter: '\\ebc5' }); Codicon.terminalLinux = new Codicon('terminal-linux', { fontCharacter: '\\ebc6' }); Codicon.terminalPowershell = new Codicon('terminal-powershell', { fontCharacter: '\\ebc7' }); Codicon.terminalTmux = new Codicon('terminal-tmux', { fontCharacter: '\\ebc8' }); Codicon.terminalUbuntu = new Codicon('terminal-ubuntu', { fontCharacter: '\\ebc9' }); Codicon.terminalBash = new Codicon('terminal-bash', { fontCharacter: '\\ebca' }); Codicon.arrowSwap = new Codicon('arrow-swap', { fontCharacter: '\\ebcb' }); Codicon.copy = new Codicon('copy', { fontCharacter: '\\ebcc' }); Codicon.personAdd = new Codicon('person-add', { fontCharacter: '\\ebcd' }); Codicon.filterFilled = new Codicon('filter-filled', { fontCharacter: '\\ebce' }); Codicon.wand = new Codicon('wand', { fontCharacter: '\\ebcf' }); Codicon.debugLineByLine = new Codicon('debug-line-by-line', { fontCharacter: '\\ebd0' }); Codicon.inspect = new Codicon('inspect', { fontCharacter: '\\ebd1' }); Codicon.layers = new Codicon('layers', { fontCharacter: '\\ebd2' }); Codicon.layersDot = new Codicon('layers-dot', { fontCharacter: '\\ebd3' }); Codicon.layersActive = new Codicon('layers-active', { fontCharacter: '\\ebd4' }); Codicon.compass = new Codicon('compass', { fontCharacter: '\\ebd5' }); Codicon.compassDot = new Codicon('compass-dot', { fontCharacter: '\\ebd6' }); Codicon.compassActive = new Codicon('compass-active', { fontCharacter: '\\ebd7' }); Codicon.azure = new Codicon('azure', { fontCharacter: '\\ebd8' }); Codicon.issueDraft = new Codicon('issue-draft', { fontCharacter: '\\ebd9' }); Codicon.gitPullRequestClosed = new Codicon('git-pull-request-closed', { fontCharacter: '\\ebda' }); Codicon.gitPullRequestDraft = new Codicon('git-pull-request-draft', { fontCharacter: '\\ebdb' }); Codicon.debugAll = new Codicon('debug-all', { fontCharacter: '\\ebdc' }); Codicon.debugCoverage = new Codicon('debug-coverage', { fontCharacter: '\\ebdd' }); Codicon.runErrors = new Codicon('run-errors', { fontCharacter: '\\ebde' }); Codicon.folderLibrary = new Codicon('folder-library', { fontCharacter: '\\ebdf' }); Codicon.debugContinueSmall = new Codicon('debug-continue-small', { fontCharacter: '\\ebe0' }); Codicon.beakerStop = new Codicon('beaker-stop', { fontCharacter: '\\ebe1' }); Codicon.graphLine = new Codicon('graph-line', { fontCharacter: '\\ebe2' }); Codicon.graphScatter = new Codicon('graph-scatter', { fontCharacter: '\\ebe3' }); Codicon.pieChart = new Codicon('pie-chart', { fontCharacter: '\\ebe4' }); Codicon.bracket = new Codicon('bracket', Codicon.json.definition); Codicon.bracketDot = new Codicon('bracket-dot', { fontCharacter: '\\ebe5' }); Codicon.bracketError = new Codicon('bracket-error', { fontCharacter: '\\ebe6' }); Codicon.lockSmall = new Codicon('lock-small', { fontCharacter: '\\ebe7' }); Codicon.azureDevops = new Codicon('azure-devops', { fontCharacter: '\\ebe8' }); Codicon.verifiedFilled = new Codicon('verified-filled', { fontCharacter: '\\ebe9' }); Codicon.newLine = new Codicon('newline', { fontCharacter: '\\ebea' }); Codicon.layout = new Codicon('layout', { fontCharacter: '\\ebeb' }); Codicon.layoutActivitybarLeft = new Codicon('layout-activitybar-left', { fontCharacter: '\\ebec' }); Codicon.layoutActivitybarRight = new Codicon('layout-activitybar-right', { fontCharacter: '\\ebed' }); Codicon.layoutPanelLeft = new Codicon('layout-panel-left', { fontCharacter: '\\ebee' }); Codicon.layoutPanelCenter = new Codicon('layout-panel-center', { fontCharacter: '\\ebef' }); Codicon.layoutPanelJustify = new Codicon('layout-panel-justify', { fontCharacter: '\\ebf0' }); Codicon.layoutPanelRight = new Codicon('layout-panel-right', { fontCharacter: '\\ebf1' }); Codicon.layoutPanel = new Codicon('layout-panel', { fontCharacter: '\\ebf2' }); Codicon.layoutSidebarLeft = new Codicon('layout-sidebar-left', { fontCharacter: '\\ebf3' }); Codicon.layoutSidebarRight = new Codicon('layout-sidebar-right', { fontCharacter: '\\ebf4' }); Codicon.layoutStatusbar = new Codicon('layout-statusbar', { fontCharacter: '\\ebf5' }); Codicon.layoutMenubar = new Codicon('layout-menubar', { fontCharacter: '\\ebf6' }); Codicon.layoutCentered = new Codicon('layout-centered', { fontCharacter: '\\ebf7' }); Codicon.target = new Codicon('target', { fontCharacter: '\\ebf8' }); // derived icons, that could become separate icons Codicon.dialogError = new Codicon('dialog-error', Codicon.error.definition); Codicon.dialogWarning = new Codicon('dialog-warning', Codicon.warning.definition); Codicon.dialogInfo = new Codicon('dialog-info', Codicon.info.definition); Codicon.dialogClose = new Codicon('dialog-close', Codicon.close.definition); Codicon.treeItemExpanded = new Codicon('tree-item-expanded', Codicon.chevronDown.definition); // collapsed is done with rotation Codicon.treeFilterOnTypeOn = new Codicon('tree-filter-on-type-on', Codicon.listFilter.definition); Codicon.treeFilterOnTypeOff = new Codicon('tree-filter-on-type-off', Codicon.listSelection.definition); Codicon.treeFilterClear = new Codicon('tree-filter-clear', Codicon.close.definition); Codicon.treeItemLoading = new Codicon('tree-item-loading', Codicon.loading.definition); Codicon.menuSelection = new Codicon('menu-selection', Codicon.check.definition); Codicon.menuSubmenu = new Codicon('menu-submenu', Codicon.chevronRight.definition); Codicon.menuBarMore = new Codicon('menubar-more', Codicon.more.definition); Codicon.scrollbarButtonLeft = new Codicon('scrollbar-button-left', Codicon.triangleLeft.definition); Codicon.scrollbarButtonRight = new Codicon('scrollbar-button-right', Codicon.triangleRight.definition); Codicon.scrollbarButtonUp = new Codicon('scrollbar-button-up', Codicon.triangleUp.definition); Codicon.scrollbarButtonDown = new Codicon('scrollbar-button-down', Codicon.triangleDown.definition); Codicon.toolBarMore = new Codicon('toolbar-more', Codicon.more.definition); Codicon.quickInputBack = new Codicon('quick-input-back', Codicon.arrowLeft.definition); var CSSIcon; (function (CSSIcon) { CSSIcon.iconNameSegment = '[A-Za-z0-9]+'; CSSIcon.iconNameExpression = '[A-Za-z0-9-]+'; CSSIcon.iconModifierExpression = '~[A-Za-z]+'; CSSIcon.iconNameCharacter = '[A-Za-z0-9~-]'; const cssIconIdRegex = new RegExp(`^(${CSSIcon.iconNameExpression})(${CSSIcon.iconModifierExpression})?$`); function asClassNameArray(icon) { if (icon instanceof Codicon) { return ['codicon', 'codicon-' + icon.id]; } const match = cssIconIdRegex.exec(icon.id); if (!match) { return asClassNameArray(Codicon.error); } let [, id, modifier] = match; const classNames = ['codicon', 'codicon-' + id]; if (modifier) { classNames.push('codicon-modifier-' + modifier.substr(1)); } return classNames; } CSSIcon.asClassNameArray = asClassNameArray; function asClassName(icon) { return asClassNameArray(icon).join(' '); } CSSIcon.asClassName = asClassName; function asCSSSelector(icon) { return '.' + asClassNameArray(icon).join('.'); } CSSIcon.asCSSSelector = asCSSSelector; })(CSSIcon || (CSSIcon = {})); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * @internal */ class TokenMetadata { static getLanguageId(metadata) { return (metadata & 255 /* LANGUAGEID_MASK */) >>> 0 /* LANGUAGEID_OFFSET */; } static getTokenType(metadata) { return (metadata & 768 /* TOKEN_TYPE_MASK */) >>> 8 /* TOKEN_TYPE_OFFSET */; } static getFontStyle(metadata) { return (metadata & 15360 /* FONT_STYLE_MASK */) >>> 10 /* FONT_STYLE_OFFSET */; } static getForeground(metadata) { return (metadata & 8372224 /* FOREGROUND_MASK */) >>> 14 /* FOREGROUND_OFFSET */; } static getBackground(metadata) { return (metadata & 4286578688 /* BACKGROUND_MASK */) >>> 23 /* BACKGROUND_OFFSET */; } static getClassNameFromMetadata(metadata) { const foreground = this.getForeground(metadata); let className = 'mtk' + foreground; const fontStyle = this.getFontStyle(metadata); if (fontStyle & 1 /* Italic */) { className += ' mtki'; } if (fontStyle & 2 /* Bold */) { className += ' mtkb'; } if (fontStyle & 4 /* Underline */) { className += ' mtku'; } if (fontStyle & 8 /* Strikethrough */) { className += ' mtks'; } return className; } static getInlineStyleFromMetadata(metadata, colorMap) { const foreground = this.getForeground(metadata); const fontStyle = this.getFontStyle(metadata); let result = `color: ${colorMap[foreground]};`; if (fontStyle & 1 /* Italic */) { result += 'font-style: italic;'; } if (fontStyle & 2 /* Bold */) { result += 'font-weight: bold;'; } let textDecoration = ''; if (fontStyle & 4 /* Underline */) { textDecoration += ' underline'; } if (fontStyle & 8 /* Strikethrough */) { textDecoration += ' line-through'; } if (textDecoration) { result += `text-decoration:${textDecoration};`; } return result; } static getPresentationFromMetadata(metadata) { const foreground = this.getForeground(metadata); const fontStyle = this.getFontStyle(metadata); return { foreground: foreground, italic: Boolean(fontStyle & 1 /* Italic */), bold: Boolean(fontStyle & 2 /* Bold */), underline: Boolean(fontStyle & 4 /* Underline */), strikethrough: Boolean(fontStyle & 8 /* Strikethrough */), }; } } class Token$2 { constructor(offset, type, language) { this._tokenBrand = undefined; this.offset = offset; this.type = type; this.language = language; } toString() { return '(' + this.offset + ', ' + this.type + ')'; } } /** * @internal */ class TokenizationResult { constructor(tokens, endState) { this._tokenizationResultBrand = undefined; this.tokens = tokens; this.endState = endState; } } /** * @internal */ class EncodedTokenizationResult { constructor(tokens, endState) { this._encodedTokenizationResultBrand = undefined; this.tokens = tokens; this.endState = endState; } } /** * @internal */ var CompletionItemKinds; (function (CompletionItemKinds) { const byKind = new Map(); byKind.set(0 /* Method */, Codicon.symbolMethod); byKind.set(1 /* Function */, Codicon.symbolFunction); byKind.set(2 /* Constructor */, Codicon.symbolConstructor); byKind.set(3 /* Field */, Codicon.symbolField); byKind.set(4 /* Variable */, Codicon.symbolVariable); byKind.set(5 /* Class */, Codicon.symbolClass); byKind.set(6 /* Struct */, Codicon.symbolStruct); byKind.set(7 /* Interface */, Codicon.symbolInterface); byKind.set(8 /* Module */, Codicon.symbolModule); byKind.set(9 /* Property */, Codicon.symbolProperty); byKind.set(10 /* Event */, Codicon.symbolEvent); byKind.set(11 /* Operator */, Codicon.symbolOperator); byKind.set(12 /* Unit */, Codicon.symbolUnit); byKind.set(13 /* Value */, Codicon.symbolValue); byKind.set(15 /* Enum */, Codicon.symbolEnum); byKind.set(14 /* Constant */, Codicon.symbolConstant); byKind.set(15 /* Enum */, Codicon.symbolEnum); byKind.set(16 /* EnumMember */, Codicon.symbolEnumMember); byKind.set(17 /* Keyword */, Codicon.symbolKeyword); byKind.set(27 /* Snippet */, Codicon.symbolSnippet); byKind.set(18 /* Text */, Codicon.symbolText); byKind.set(19 /* Color */, Codicon.symbolColor); byKind.set(20 /* File */, Codicon.symbolFile); byKind.set(21 /* Reference */, Codicon.symbolReference); byKind.set(22 /* Customcolor */, Codicon.symbolCustomColor); byKind.set(23 /* Folder */, Codicon.symbolFolder); byKind.set(24 /* TypeParameter */, Codicon.symbolTypeParameter); byKind.set(25 /* User */, Codicon.account); byKind.set(26 /* Issue */, Codicon.issues); /** * @internal */ function toIcon(kind) { let codicon = byKind.get(kind); if (!codicon) { console.info('No codicon found for CompletionItemKind ' + kind); codicon = Codicon.symbolProperty; } return codicon; } CompletionItemKinds.toIcon = toIcon; const data = new Map(); data.set('method', 0 /* Method */); data.set('function', 1 /* Function */); data.set('constructor', 2 /* Constructor */); data.set('field', 3 /* Field */); data.set('variable', 4 /* Variable */); data.set('class', 5 /* Class */); data.set('struct', 6 /* Struct */); data.set('interface', 7 /* Interface */); data.set('module', 8 /* Module */); data.set('property', 9 /* Property */); data.set('event', 10 /* Event */); data.set('operator', 11 /* Operator */); data.set('unit', 12 /* Unit */); data.set('value', 13 /* Value */); data.set('constant', 14 /* Constant */); data.set('enum', 15 /* Enum */); data.set('enum-member', 16 /* EnumMember */); data.set('enumMember', 16 /* EnumMember */); data.set('keyword', 17 /* Keyword */); data.set('snippet', 27 /* Snippet */); data.set('text', 18 /* Text */); data.set('color', 19 /* Color */); data.set('file', 20 /* File */); data.set('reference', 21 /* Reference */); data.set('customcolor', 22 /* Customcolor */); data.set('folder', 23 /* Folder */); data.set('type-parameter', 24 /* TypeParameter */); data.set('typeParameter', 24 /* TypeParameter */); data.set('account', 25 /* User */); data.set('issue', 26 /* Issue */); /** * @internal */ function fromString(value, strict) { let res = data.get(value); if (typeof res === 'undefined' && !strict) { res = 9 /* Property */; } return res; } CompletionItemKinds.fromString = fromString; })(CompletionItemKinds || (CompletionItemKinds = {})); /** * How an {@link InlineCompletionsProvider inline completion provider} was triggered. */ var InlineCompletionTriggerKind$1; (function (InlineCompletionTriggerKind) { /** * Completion was triggered automatically while editing. * It is sufficient to return a single completion item in this case. */ InlineCompletionTriggerKind[InlineCompletionTriggerKind["Automatic"] = 0] = "Automatic"; /** * Completion was triggered explicitly by a user gesture. * Return multiple completion items to enable cycling through them. */ InlineCompletionTriggerKind[InlineCompletionTriggerKind["Explicit"] = 1] = "Explicit"; })(InlineCompletionTriggerKind$1 || (InlineCompletionTriggerKind$1 = {})); var SignatureHelpTriggerKind$1; (function (SignatureHelpTriggerKind) { SignatureHelpTriggerKind[SignatureHelpTriggerKind["Invoke"] = 1] = "Invoke"; SignatureHelpTriggerKind[SignatureHelpTriggerKind["TriggerCharacter"] = 2] = "TriggerCharacter"; SignatureHelpTriggerKind[SignatureHelpTriggerKind["ContentChange"] = 3] = "ContentChange"; })(SignatureHelpTriggerKind$1 || (SignatureHelpTriggerKind$1 = {})); /** * A document highlight kind. */ var DocumentHighlightKind$4; (function (DocumentHighlightKind) { /** * A textual occurrence. */ DocumentHighlightKind[DocumentHighlightKind["Text"] = 0] = "Text"; /** * Read-access of a symbol, like reading a variable. */ DocumentHighlightKind[DocumentHighlightKind["Read"] = 1] = "Read"; /** * Write-access of a symbol, like writing to a variable. */ DocumentHighlightKind[DocumentHighlightKind["Write"] = 2] = "Write"; })(DocumentHighlightKind$4 || (DocumentHighlightKind$4 = {})); /** * @internal */ function isLocationLink(thing) { return thing && URI.isUri(thing.uri) && Range$5.isIRange(thing.range) && (Range$5.isIRange(thing.originSelectionRange) || Range$5.isIRange(thing.targetSelectionRange)); } /** * @internal */ var SymbolKinds; (function (SymbolKinds) { const byKind = new Map(); byKind.set(0 /* File */, Codicon.symbolFile); byKind.set(1 /* Module */, Codicon.symbolModule); byKind.set(2 /* Namespace */, Codicon.symbolNamespace); byKind.set(3 /* Package */, Codicon.symbolPackage); byKind.set(4 /* Class */, Codicon.symbolClass); byKind.set(5 /* Method */, Codicon.symbolMethod); byKind.set(6 /* Property */, Codicon.symbolProperty); byKind.set(7 /* Field */, Codicon.symbolField); byKind.set(8 /* Constructor */, Codicon.symbolConstructor); byKind.set(9 /* Enum */, Codicon.symbolEnum); byKind.set(10 /* Interface */, Codicon.symbolInterface); byKind.set(11 /* Function */, Codicon.symbolFunction); byKind.set(12 /* Variable */, Codicon.symbolVariable); byKind.set(13 /* Constant */, Codicon.symbolConstant); byKind.set(14 /* String */, Codicon.symbolString); byKind.set(15 /* Number */, Codicon.symbolNumber); byKind.set(16 /* Boolean */, Codicon.symbolBoolean); byKind.set(17 /* Array */, Codicon.symbolArray); byKind.set(18 /* Object */, Codicon.symbolObject); byKind.set(19 /* Key */, Codicon.symbolKey); byKind.set(20 /* Null */, Codicon.symbolNull); byKind.set(21 /* EnumMember */, Codicon.symbolEnumMember); byKind.set(22 /* Struct */, Codicon.symbolStruct); byKind.set(23 /* Event */, Codicon.symbolEvent); byKind.set(24 /* Operator */, Codicon.symbolOperator); byKind.set(25 /* TypeParameter */, Codicon.symbolTypeParameter); /** * @internal */ function toIcon(kind) { let icon = byKind.get(kind); if (!icon) { console.info('No codicon found for SymbolKind ' + kind); icon = Codicon.symbolProperty; } return icon; } SymbolKinds.toIcon = toIcon; })(SymbolKinds || (SymbolKinds = {})); class FoldingRangeKind$3 { /** * Creates a new {@link FoldingRangeKind}. * * @param value of the kind. */ constructor(value) { this.value = value; } } /** * Kind for folding range representing a comment. The value of the kind is 'comment'. */ FoldingRangeKind$3.Comment = new FoldingRangeKind$3('comment'); /** * Kind for folding range representing a import. The value of the kind is 'imports'. */ FoldingRangeKind$3.Imports = new FoldingRangeKind$3('imports'); /** * Kind for folding range representing regions (for example marked by `#region`, `#endregion`). * The value of the kind is 'region'. */ FoldingRangeKind$3.Region = new FoldingRangeKind$3('region'); /** * @internal */ var Command$4; (function (Command) { /** * @internal */ function is(obj) { if (!obj || typeof obj !== 'object') { return false; } return typeof obj.id === 'string' && typeof obj.title === 'string'; } Command.is = is; })(Command$4 || (Command$4 = {})); var InlayHintKind$1; (function (InlayHintKind) { InlayHintKind[InlayHintKind["Other"] = 0] = "Other"; InlayHintKind[InlayHintKind["Type"] = 1] = "Type"; InlayHintKind[InlayHintKind["Parameter"] = 2] = "Parameter"; })(InlayHintKind$1 || (InlayHintKind$1 = {})); // --- feature registries ------ /** * @internal */ const ReferenceProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const RenameProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const CompletionProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const InlineCompletionsProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const SignatureHelpProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const HoverProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ new LanguageFeatureRegistry(); /** * @internal */ new LanguageFeatureRegistry(); /** * @internal */ const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const LinkedEditingRangeProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const DefinitionProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const DeclarationProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const ImplementationProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const CodeLensProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const InlayHintsProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const CodeActionProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const LinkProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const ColorProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const SelectionRangeRegistry = new LanguageFeatureRegistry(); /** * @internal */ const FoldingRangeProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const DocumentSemanticTokensProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const DocumentRangeSemanticTokensProviderRegistry = new LanguageFeatureRegistry(); /** * @internal */ const TokenizationRegistry = new TokenizationRegistry$1(); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ // THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. var AccessibilitySupport; (function (AccessibilitySupport) { /** * This should be the browser case where it is not known if a screen reader is attached or no. */ AccessibilitySupport[AccessibilitySupport["Unknown"] = 0] = "Unknown"; AccessibilitySupport[AccessibilitySupport["Disabled"] = 1] = "Disabled"; AccessibilitySupport[AccessibilitySupport["Enabled"] = 2] = "Enabled"; })(AccessibilitySupport || (AccessibilitySupport = {})); var CompletionItemInsertTextRule; (function (CompletionItemInsertTextRule) { /** * Adjust whitespace/indentation of multiline insert texts to * match the current line indentation. */ CompletionItemInsertTextRule[CompletionItemInsertTextRule["KeepWhitespace"] = 1] = "KeepWhitespace"; /** * `insertText` is a snippet. */ CompletionItemInsertTextRule[CompletionItemInsertTextRule["InsertAsSnippet"] = 4] = "InsertAsSnippet"; })(CompletionItemInsertTextRule || (CompletionItemInsertTextRule = {})); var CompletionItemKind$3; (function (CompletionItemKind) { CompletionItemKind[CompletionItemKind["Method"] = 0] = "Method"; CompletionItemKind[CompletionItemKind["Function"] = 1] = "Function"; CompletionItemKind[CompletionItemKind["Constructor"] = 2] = "Constructor"; CompletionItemKind[CompletionItemKind["Field"] = 3] = "Field"; CompletionItemKind[CompletionItemKind["Variable"] = 4] = "Variable"; CompletionItemKind[CompletionItemKind["Class"] = 5] = "Class"; CompletionItemKind[CompletionItemKind["Struct"] = 6] = "Struct"; CompletionItemKind[CompletionItemKind["Interface"] = 7] = "Interface"; CompletionItemKind[CompletionItemKind["Module"] = 8] = "Module"; CompletionItemKind[CompletionItemKind["Property"] = 9] = "Property"; CompletionItemKind[CompletionItemKind["Event"] = 10] = "Event"; CompletionItemKind[CompletionItemKind["Operator"] = 11] = "Operator"; CompletionItemKind[CompletionItemKind["Unit"] = 12] = "Unit"; CompletionItemKind[CompletionItemKind["Value"] = 13] = "Value"; CompletionItemKind[CompletionItemKind["Constant"] = 14] = "Constant"; CompletionItemKind[CompletionItemKind["Enum"] = 15] = "Enum"; CompletionItemKind[CompletionItemKind["EnumMember"] = 16] = "EnumMember"; CompletionItemKind[CompletionItemKind["Keyword"] = 17] = "Keyword"; CompletionItemKind[CompletionItemKind["Text"] = 18] = "Text"; CompletionItemKind[CompletionItemKind["Color"] = 19] = "Color"; CompletionItemKind[CompletionItemKind["File"] = 20] = "File"; CompletionItemKind[CompletionItemKind["Reference"] = 21] = "Reference"; CompletionItemKind[CompletionItemKind["Customcolor"] = 22] = "Customcolor"; CompletionItemKind[CompletionItemKind["Folder"] = 23] = "Folder"; CompletionItemKind[CompletionItemKind["TypeParameter"] = 24] = "TypeParameter"; CompletionItemKind[CompletionItemKind["User"] = 25] = "User"; CompletionItemKind[CompletionItemKind["Issue"] = 26] = "Issue"; CompletionItemKind[CompletionItemKind["Snippet"] = 27] = "Snippet"; })(CompletionItemKind$3 || (CompletionItemKind$3 = {})); var CompletionItemTag$3; (function (CompletionItemTag) { CompletionItemTag[CompletionItemTag["Deprecated"] = 1] = "Deprecated"; })(CompletionItemTag$3 || (CompletionItemTag$3 = {})); /** * How a suggest provider was triggered. */ var CompletionTriggerKind; (function (CompletionTriggerKind) { CompletionTriggerKind[CompletionTriggerKind["Invoke"] = 0] = "Invoke"; CompletionTriggerKind[CompletionTriggerKind["TriggerCharacter"] = 1] = "TriggerCharacter"; CompletionTriggerKind[CompletionTriggerKind["TriggerForIncompleteCompletions"] = 2] = "TriggerForIncompleteCompletions"; })(CompletionTriggerKind || (CompletionTriggerKind = {})); /** * A positioning preference for rendering content widgets. */ var ContentWidgetPositionPreference; (function (ContentWidgetPositionPreference) { /** * Place the content widget exactly at a position */ ContentWidgetPositionPreference[ContentWidgetPositionPreference["EXACT"] = 0] = "EXACT"; /** * Place the content widget above a position */ ContentWidgetPositionPreference[ContentWidgetPositionPreference["ABOVE"] = 1] = "ABOVE"; /** * Place the content widget below a position */ ContentWidgetPositionPreference[ContentWidgetPositionPreference["BELOW"] = 2] = "BELOW"; })(ContentWidgetPositionPreference || (ContentWidgetPositionPreference = {})); /** * Describes the reason the cursor has changed its position. */ var CursorChangeReason; (function (CursorChangeReason) { /** * Unknown or not set. */ CursorChangeReason[CursorChangeReason["NotSet"] = 0] = "NotSet"; /** * A `model.setValue()` was called. */ CursorChangeReason[CursorChangeReason["ContentFlush"] = 1] = "ContentFlush"; /** * The `model` has been changed outside of this cursor and the cursor recovers its position from associated markers. */ CursorChangeReason[CursorChangeReason["RecoverFromMarkers"] = 2] = "RecoverFromMarkers"; /** * There was an explicit user gesture. */ CursorChangeReason[CursorChangeReason["Explicit"] = 3] = "Explicit"; /** * There was a Paste. */ CursorChangeReason[CursorChangeReason["Paste"] = 4] = "Paste"; /** * There was an Undo. */ CursorChangeReason[CursorChangeReason["Undo"] = 5] = "Undo"; /** * There was a Redo. */ CursorChangeReason[CursorChangeReason["Redo"] = 6] = "Redo"; })(CursorChangeReason || (CursorChangeReason = {})); /** * The default end of line to use when instantiating models. */ var DefaultEndOfLine; (function (DefaultEndOfLine) { /** * Use line feed (\n) as the end of line character. */ DefaultEndOfLine[DefaultEndOfLine["LF"] = 1] = "LF"; /** * Use carriage return and line feed (\r\n) as the end of line character. */ DefaultEndOfLine[DefaultEndOfLine["CRLF"] = 2] = "CRLF"; })(DefaultEndOfLine || (DefaultEndOfLine = {})); /** * A document highlight kind. */ var DocumentHighlightKind$3; (function (DocumentHighlightKind) { /** * A textual occurrence. */ DocumentHighlightKind[DocumentHighlightKind["Text"] = 0] = "Text"; /** * Read-access of a symbol, like reading a variable. */ DocumentHighlightKind[DocumentHighlightKind["Read"] = 1] = "Read"; /** * Write-access of a symbol, like writing to a variable. */ DocumentHighlightKind[DocumentHighlightKind["Write"] = 2] = "Write"; })(DocumentHighlightKind$3 || (DocumentHighlightKind$3 = {})); /** * Configuration options for auto indentation in the editor */ var EditorAutoIndentStrategy; (function (EditorAutoIndentStrategy) { EditorAutoIndentStrategy[EditorAutoIndentStrategy["None"] = 0] = "None"; EditorAutoIndentStrategy[EditorAutoIndentStrategy["Keep"] = 1] = "Keep"; EditorAutoIndentStrategy[EditorAutoIndentStrategy["Brackets"] = 2] = "Brackets"; EditorAutoIndentStrategy[EditorAutoIndentStrategy["Advanced"] = 3] = "Advanced"; EditorAutoIndentStrategy[EditorAutoIndentStrategy["Full"] = 4] = "Full"; })(EditorAutoIndentStrategy || (EditorAutoIndentStrategy = {})); var EditorOption; (function (EditorOption) { EditorOption[EditorOption["acceptSuggestionOnCommitCharacter"] = 0] = "acceptSuggestionOnCommitCharacter"; EditorOption[EditorOption["acceptSuggestionOnEnter"] = 1] = "acceptSuggestionOnEnter"; EditorOption[EditorOption["accessibilitySupport"] = 2] = "accessibilitySupport"; EditorOption[EditorOption["accessibilityPageSize"] = 3] = "accessibilityPageSize"; EditorOption[EditorOption["ariaLabel"] = 4] = "ariaLabel"; EditorOption[EditorOption["autoClosingBrackets"] = 5] = "autoClosingBrackets"; EditorOption[EditorOption["autoClosingDelete"] = 6] = "autoClosingDelete"; EditorOption[EditorOption["autoClosingOvertype"] = 7] = "autoClosingOvertype"; EditorOption[EditorOption["autoClosingQuotes"] = 8] = "autoClosingQuotes"; EditorOption[EditorOption["autoIndent"] = 9] = "autoIndent"; EditorOption[EditorOption["automaticLayout"] = 10] = "automaticLayout"; EditorOption[EditorOption["autoSurround"] = 11] = "autoSurround"; EditorOption[EditorOption["bracketPairColorization"] = 12] = "bracketPairColorization"; EditorOption[EditorOption["guides"] = 13] = "guides"; EditorOption[EditorOption["codeLens"] = 14] = "codeLens"; EditorOption[EditorOption["codeLensFontFamily"] = 15] = "codeLensFontFamily"; EditorOption[EditorOption["codeLensFontSize"] = 16] = "codeLensFontSize"; EditorOption[EditorOption["colorDecorators"] = 17] = "colorDecorators"; EditorOption[EditorOption["columnSelection"] = 18] = "columnSelection"; EditorOption[EditorOption["comments"] = 19] = "comments"; EditorOption[EditorOption["contextmenu"] = 20] = "contextmenu"; EditorOption[EditorOption["copyWithSyntaxHighlighting"] = 21] = "copyWithSyntaxHighlighting"; EditorOption[EditorOption["cursorBlinking"] = 22] = "cursorBlinking"; EditorOption[EditorOption["cursorSmoothCaretAnimation"] = 23] = "cursorSmoothCaretAnimation"; EditorOption[EditorOption["cursorStyle"] = 24] = "cursorStyle"; EditorOption[EditorOption["cursorSurroundingLines"] = 25] = "cursorSurroundingLines"; EditorOption[EditorOption["cursorSurroundingLinesStyle"] = 26] = "cursorSurroundingLinesStyle"; EditorOption[EditorOption["cursorWidth"] = 27] = "cursorWidth"; EditorOption[EditorOption["disableLayerHinting"] = 28] = "disableLayerHinting"; EditorOption[EditorOption["disableMonospaceOptimizations"] = 29] = "disableMonospaceOptimizations"; EditorOption[EditorOption["domReadOnly"] = 30] = "domReadOnly"; EditorOption[EditorOption["dragAndDrop"] = 31] = "dragAndDrop"; EditorOption[EditorOption["emptySelectionClipboard"] = 32] = "emptySelectionClipboard"; EditorOption[EditorOption["extraEditorClassName"] = 33] = "extraEditorClassName"; EditorOption[EditorOption["fastScrollSensitivity"] = 34] = "fastScrollSensitivity"; EditorOption[EditorOption["find"] = 35] = "find"; EditorOption[EditorOption["fixedOverflowWidgets"] = 36] = "fixedOverflowWidgets"; EditorOption[EditorOption["folding"] = 37] = "folding"; EditorOption[EditorOption["foldingStrategy"] = 38] = "foldingStrategy"; EditorOption[EditorOption["foldingHighlight"] = 39] = "foldingHighlight"; EditorOption[EditorOption["foldingImportsByDefault"] = 40] = "foldingImportsByDefault"; EditorOption[EditorOption["foldingMaximumRegions"] = 41] = "foldingMaximumRegions"; EditorOption[EditorOption["unfoldOnClickAfterEndOfLine"] = 42] = "unfoldOnClickAfterEndOfLine"; EditorOption[EditorOption["fontFamily"] = 43] = "fontFamily"; EditorOption[EditorOption["fontInfo"] = 44] = "fontInfo"; EditorOption[EditorOption["fontLigatures"] = 45] = "fontLigatures"; EditorOption[EditorOption["fontSize"] = 46] = "fontSize"; EditorOption[EditorOption["fontWeight"] = 47] = "fontWeight"; EditorOption[EditorOption["formatOnPaste"] = 48] = "formatOnPaste"; EditorOption[EditorOption["formatOnType"] = 49] = "formatOnType"; EditorOption[EditorOption["glyphMargin"] = 50] = "glyphMargin"; EditorOption[EditorOption["gotoLocation"] = 51] = "gotoLocation"; EditorOption[EditorOption["hideCursorInOverviewRuler"] = 52] = "hideCursorInOverviewRuler"; EditorOption[EditorOption["hover"] = 53] = "hover"; EditorOption[EditorOption["inDiffEditor"] = 54] = "inDiffEditor"; EditorOption[EditorOption["inlineSuggest"] = 55] = "inlineSuggest"; EditorOption[EditorOption["letterSpacing"] = 56] = "letterSpacing"; EditorOption[EditorOption["lightbulb"] = 57] = "lightbulb"; EditorOption[EditorOption["lineDecorationsWidth"] = 58] = "lineDecorationsWidth"; EditorOption[EditorOption["lineHeight"] = 59] = "lineHeight"; EditorOption[EditorOption["lineNumbers"] = 60] = "lineNumbers"; EditorOption[EditorOption["lineNumbersMinChars"] = 61] = "lineNumbersMinChars"; EditorOption[EditorOption["linkedEditing"] = 62] = "linkedEditing"; EditorOption[EditorOption["links"] = 63] = "links"; EditorOption[EditorOption["matchBrackets"] = 64] = "matchBrackets"; EditorOption[EditorOption["minimap"] = 65] = "minimap"; EditorOption[EditorOption["mouseStyle"] = 66] = "mouseStyle"; EditorOption[EditorOption["mouseWheelScrollSensitivity"] = 67] = "mouseWheelScrollSensitivity"; EditorOption[EditorOption["mouseWheelZoom"] = 68] = "mouseWheelZoom"; EditorOption[EditorOption["multiCursorMergeOverlapping"] = 69] = "multiCursorMergeOverlapping"; EditorOption[EditorOption["multiCursorModifier"] = 70] = "multiCursorModifier"; EditorOption[EditorOption["multiCursorPaste"] = 71] = "multiCursorPaste"; EditorOption[EditorOption["occurrencesHighlight"] = 72] = "occurrencesHighlight"; EditorOption[EditorOption["overviewRulerBorder"] = 73] = "overviewRulerBorder"; EditorOption[EditorOption["overviewRulerLanes"] = 74] = "overviewRulerLanes"; EditorOption[EditorOption["padding"] = 75] = "padding"; EditorOption[EditorOption["parameterHints"] = 76] = "parameterHints"; EditorOption[EditorOption["peekWidgetDefaultFocus"] = 77] = "peekWidgetDefaultFocus"; EditorOption[EditorOption["definitionLinkOpensInPeek"] = 78] = "definitionLinkOpensInPeek"; EditorOption[EditorOption["quickSuggestions"] = 79] = "quickSuggestions"; EditorOption[EditorOption["quickSuggestionsDelay"] = 80] = "quickSuggestionsDelay"; EditorOption[EditorOption["readOnly"] = 81] = "readOnly"; EditorOption[EditorOption["renameOnType"] = 82] = "renameOnType"; EditorOption[EditorOption["renderControlCharacters"] = 83] = "renderControlCharacters"; EditorOption[EditorOption["renderFinalNewline"] = 84] = "renderFinalNewline"; EditorOption[EditorOption["renderLineHighlight"] = 85] = "renderLineHighlight"; EditorOption[EditorOption["renderLineHighlightOnlyWhenFocus"] = 86] = "renderLineHighlightOnlyWhenFocus"; EditorOption[EditorOption["renderValidationDecorations"] = 87] = "renderValidationDecorations"; EditorOption[EditorOption["renderWhitespace"] = 88] = "renderWhitespace"; EditorOption[EditorOption["revealHorizontalRightPadding"] = 89] = "revealHorizontalRightPadding"; EditorOption[EditorOption["roundedSelection"] = 90] = "roundedSelection"; EditorOption[EditorOption["rulers"] = 91] = "rulers"; EditorOption[EditorOption["scrollbar"] = 92] = "scrollbar"; EditorOption[EditorOption["scrollBeyondLastColumn"] = 93] = "scrollBeyondLastColumn"; EditorOption[EditorOption["scrollBeyondLastLine"] = 94] = "scrollBeyondLastLine"; EditorOption[EditorOption["scrollPredominantAxis"] = 95] = "scrollPredominantAxis"; EditorOption[EditorOption["selectionClipboard"] = 96] = "selectionClipboard"; EditorOption[EditorOption["selectionHighlight"] = 97] = "selectionHighlight"; EditorOption[EditorOption["selectOnLineNumbers"] = 98] = "selectOnLineNumbers"; EditorOption[EditorOption["showFoldingControls"] = 99] = "showFoldingControls"; EditorOption[EditorOption["showUnused"] = 100] = "showUnused"; EditorOption[EditorOption["snippetSuggestions"] = 101] = "snippetSuggestions"; EditorOption[EditorOption["smartSelect"] = 102] = "smartSelect"; EditorOption[EditorOption["smoothScrolling"] = 103] = "smoothScrolling"; EditorOption[EditorOption["stickyTabStops"] = 104] = "stickyTabStops"; EditorOption[EditorOption["stopRenderingLineAfter"] = 105] = "stopRenderingLineAfter"; EditorOption[EditorOption["suggest"] = 106] = "suggest"; EditorOption[EditorOption["suggestFontSize"] = 107] = "suggestFontSize"; EditorOption[EditorOption["suggestLineHeight"] = 108] = "suggestLineHeight"; EditorOption[EditorOption["suggestOnTriggerCharacters"] = 109] = "suggestOnTriggerCharacters"; EditorOption[EditorOption["suggestSelection"] = 110] = "suggestSelection"; EditorOption[EditorOption["tabCompletion"] = 111] = "tabCompletion"; EditorOption[EditorOption["tabIndex"] = 112] = "tabIndex"; EditorOption[EditorOption["unicodeHighlighting"] = 113] = "unicodeHighlighting"; EditorOption[EditorOption["unusualLineTerminators"] = 114] = "unusualLineTerminators"; EditorOption[EditorOption["useShadowDOM"] = 115] = "useShadowDOM"; EditorOption[EditorOption["useTabStops"] = 116] = "useTabStops"; EditorOption[EditorOption["wordSeparators"] = 117] = "wordSeparators"; EditorOption[EditorOption["wordWrap"] = 118] = "wordWrap"; EditorOption[EditorOption["wordWrapBreakAfterCharacters"] = 119] = "wordWrapBreakAfterCharacters"; EditorOption[EditorOption["wordWrapBreakBeforeCharacters"] = 120] = "wordWrapBreakBeforeCharacters"; EditorOption[EditorOption["wordWrapColumn"] = 121] = "wordWrapColumn"; EditorOption[EditorOption["wordWrapOverride1"] = 122] = "wordWrapOverride1"; EditorOption[EditorOption["wordWrapOverride2"] = 123] = "wordWrapOverride2"; EditorOption[EditorOption["wrappingIndent"] = 124] = "wrappingIndent"; EditorOption[EditorOption["wrappingStrategy"] = 125] = "wrappingStrategy"; EditorOption[EditorOption["showDeprecated"] = 126] = "showDeprecated"; EditorOption[EditorOption["inlayHints"] = 127] = "inlayHints"; EditorOption[EditorOption["editorClassName"] = 128] = "editorClassName"; EditorOption[EditorOption["pixelRatio"] = 129] = "pixelRatio"; EditorOption[EditorOption["tabFocusMode"] = 130] = "tabFocusMode"; EditorOption[EditorOption["layoutInfo"] = 131] = "layoutInfo"; EditorOption[EditorOption["wrappingInfo"] = 132] = "wrappingInfo"; })(EditorOption || (EditorOption = {})); /** * End of line character preference. */ var EndOfLinePreference; (function (EndOfLinePreference) { /** * Use the end of line character identified in the text buffer. */ EndOfLinePreference[EndOfLinePreference["TextDefined"] = 0] = "TextDefined"; /** * Use line feed (\n) as the end of line character. */ EndOfLinePreference[EndOfLinePreference["LF"] = 1] = "LF"; /** * Use carriage return and line feed (\r\n) as the end of line character. */ EndOfLinePreference[EndOfLinePreference["CRLF"] = 2] = "CRLF"; })(EndOfLinePreference || (EndOfLinePreference = {})); /** * End of line character preference. */ var EndOfLineSequence; (function (EndOfLineSequence) { /** * Use line feed (\n) as the end of line character. */ EndOfLineSequence[EndOfLineSequence["LF"] = 0] = "LF"; /** * Use carriage return and line feed (\r\n) as the end of line character. */ EndOfLineSequence[EndOfLineSequence["CRLF"] = 1] = "CRLF"; })(EndOfLineSequence || (EndOfLineSequence = {})); /** * Describes what to do with the indentation when pressing Enter. */ var IndentAction$1; (function (IndentAction) { /** * Insert new line and copy the previous line's indentation. */ IndentAction[IndentAction["None"] = 0] = "None"; /** * Insert new line and indent once (relative to the previous line's indentation). */ IndentAction[IndentAction["Indent"] = 1] = "Indent"; /** * Insert two new lines: * - the first one indented which will hold the cursor * - the second one at the same indentation level */ IndentAction[IndentAction["IndentOutdent"] = 2] = "IndentOutdent"; /** * Insert new line and outdent once (relative to the previous line's indentation). */ IndentAction[IndentAction["Outdent"] = 3] = "Outdent"; })(IndentAction$1 || (IndentAction$1 = {})); var InjectedTextCursorStops; (function (InjectedTextCursorStops) { InjectedTextCursorStops[InjectedTextCursorStops["Both"] = 0] = "Both"; InjectedTextCursorStops[InjectedTextCursorStops["Right"] = 1] = "Right"; InjectedTextCursorStops[InjectedTextCursorStops["Left"] = 2] = "Left"; InjectedTextCursorStops[InjectedTextCursorStops["None"] = 3] = "None"; })(InjectedTextCursorStops || (InjectedTextCursorStops = {})); var InlayHintKind; (function (InlayHintKind) { InlayHintKind[InlayHintKind["Other"] = 0] = "Other"; InlayHintKind[InlayHintKind["Type"] = 1] = "Type"; InlayHintKind[InlayHintKind["Parameter"] = 2] = "Parameter"; })(InlayHintKind || (InlayHintKind = {})); /** * How an {@link InlineCompletionsProvider inline completion provider} was triggered. */ var InlineCompletionTriggerKind; (function (InlineCompletionTriggerKind) { /** * Completion was triggered automatically while editing. * It is sufficient to return a single completion item in this case. */ InlineCompletionTriggerKind[InlineCompletionTriggerKind["Automatic"] = 0] = "Automatic"; /** * Completion was triggered explicitly by a user gesture. * Return multiple completion items to enable cycling through them. */ InlineCompletionTriggerKind[InlineCompletionTriggerKind["Explicit"] = 1] = "Explicit"; })(InlineCompletionTriggerKind || (InlineCompletionTriggerKind = {})); /** * Virtual Key Codes, the value does not hold any inherent meaning. * Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx * But these are "more general", as they should work across browsers & OS`s. */ var KeyCode$1; (function (KeyCode) { KeyCode[KeyCode["DependsOnKbLayout"] = -1] = "DependsOnKbLayout"; /** * Placed first to cover the 0 value of the enum. */ KeyCode[KeyCode["Unknown"] = 0] = "Unknown"; KeyCode[KeyCode["Backspace"] = 1] = "Backspace"; KeyCode[KeyCode["Tab"] = 2] = "Tab"; KeyCode[KeyCode["Enter"] = 3] = "Enter"; KeyCode[KeyCode["Shift"] = 4] = "Shift"; KeyCode[KeyCode["Ctrl"] = 5] = "Ctrl"; KeyCode[KeyCode["Alt"] = 6] = "Alt"; KeyCode[KeyCode["PauseBreak"] = 7] = "PauseBreak"; KeyCode[KeyCode["CapsLock"] = 8] = "CapsLock"; KeyCode[KeyCode["Escape"] = 9] = "Escape"; KeyCode[KeyCode["Space"] = 10] = "Space"; KeyCode[KeyCode["PageUp"] = 11] = "PageUp"; KeyCode[KeyCode["PageDown"] = 12] = "PageDown"; KeyCode[KeyCode["End"] = 13] = "End"; KeyCode[KeyCode["Home"] = 14] = "Home"; KeyCode[KeyCode["LeftArrow"] = 15] = "LeftArrow"; KeyCode[KeyCode["UpArrow"] = 16] = "UpArrow"; KeyCode[KeyCode["RightArrow"] = 17] = "RightArrow"; KeyCode[KeyCode["DownArrow"] = 18] = "DownArrow"; KeyCode[KeyCode["Insert"] = 19] = "Insert"; KeyCode[KeyCode["Delete"] = 20] = "Delete"; KeyCode[KeyCode["Digit0"] = 21] = "Digit0"; KeyCode[KeyCode["Digit1"] = 22] = "Digit1"; KeyCode[KeyCode["Digit2"] = 23] = "Digit2"; KeyCode[KeyCode["Digit3"] = 24] = "Digit3"; KeyCode[KeyCode["Digit4"] = 25] = "Digit4"; KeyCode[KeyCode["Digit5"] = 26] = "Digit5"; KeyCode[KeyCode["Digit6"] = 27] = "Digit6"; KeyCode[KeyCode["Digit7"] = 28] = "Digit7"; KeyCode[KeyCode["Digit8"] = 29] = "Digit8"; KeyCode[KeyCode["Digit9"] = 30] = "Digit9"; KeyCode[KeyCode["KeyA"] = 31] = "KeyA"; KeyCode[KeyCode["KeyB"] = 32] = "KeyB"; KeyCode[KeyCode["KeyC"] = 33] = "KeyC"; KeyCode[KeyCode["KeyD"] = 34] = "KeyD"; KeyCode[KeyCode["KeyE"] = 35] = "KeyE"; KeyCode[KeyCode["KeyF"] = 36] = "KeyF"; KeyCode[KeyCode["KeyG"] = 37] = "KeyG"; KeyCode[KeyCode["KeyH"] = 38] = "KeyH"; KeyCode[KeyCode["KeyI"] = 39] = "KeyI"; KeyCode[KeyCode["KeyJ"] = 40] = "KeyJ"; KeyCode[KeyCode["KeyK"] = 41] = "KeyK"; KeyCode[KeyCode["KeyL"] = 42] = "KeyL"; KeyCode[KeyCode["KeyM"] = 43] = "KeyM"; KeyCode[KeyCode["KeyN"] = 44] = "KeyN"; KeyCode[KeyCode["KeyO"] = 45] = "KeyO"; KeyCode[KeyCode["KeyP"] = 46] = "KeyP"; KeyCode[KeyCode["KeyQ"] = 47] = "KeyQ"; KeyCode[KeyCode["KeyR"] = 48] = "KeyR"; KeyCode[KeyCode["KeyS"] = 49] = "KeyS"; KeyCode[KeyCode["KeyT"] = 50] = "KeyT"; KeyCode[KeyCode["KeyU"] = 51] = "KeyU"; KeyCode[KeyCode["KeyV"] = 52] = "KeyV"; KeyCode[KeyCode["KeyW"] = 53] = "KeyW"; KeyCode[KeyCode["KeyX"] = 54] = "KeyX"; KeyCode[KeyCode["KeyY"] = 55] = "KeyY"; KeyCode[KeyCode["KeyZ"] = 56] = "KeyZ"; KeyCode[KeyCode["Meta"] = 57] = "Meta"; KeyCode[KeyCode["ContextMenu"] = 58] = "ContextMenu"; KeyCode[KeyCode["F1"] = 59] = "F1"; KeyCode[KeyCode["F2"] = 60] = "F2"; KeyCode[KeyCode["F3"] = 61] = "F3"; KeyCode[KeyCode["F4"] = 62] = "F4"; KeyCode[KeyCode["F5"] = 63] = "F5"; KeyCode[KeyCode["F6"] = 64] = "F6"; KeyCode[KeyCode["F7"] = 65] = "F7"; KeyCode[KeyCode["F8"] = 66] = "F8"; KeyCode[KeyCode["F9"] = 67] = "F9"; KeyCode[KeyCode["F10"] = 68] = "F10"; KeyCode[KeyCode["F11"] = 69] = "F11"; KeyCode[KeyCode["F12"] = 70] = "F12"; KeyCode[KeyCode["F13"] = 71] = "F13"; KeyCode[KeyCode["F14"] = 72] = "F14"; KeyCode[KeyCode["F15"] = 73] = "F15"; KeyCode[KeyCode["F16"] = 74] = "F16"; KeyCode[KeyCode["F17"] = 75] = "F17"; KeyCode[KeyCode["F18"] = 76] = "F18"; KeyCode[KeyCode["F19"] = 77] = "F19"; KeyCode[KeyCode["NumLock"] = 78] = "NumLock"; KeyCode[KeyCode["ScrollLock"] = 79] = "ScrollLock"; /** * Used for miscellaneous characters; it can vary by keyboard. * For the US standard keyboard, the ';:' key */ KeyCode[KeyCode["Semicolon"] = 80] = "Semicolon"; /** * For any country/region, the '+' key * For the US standard keyboard, the '=+' key */ KeyCode[KeyCode["Equal"] = 81] = "Equal"; /** * For any country/region, the ',' key * For the US standard keyboard, the ',<' key */ KeyCode[KeyCode["Comma"] = 82] = "Comma"; /** * For any country/region, the '-' key * For the US standard keyboard, the '-_' key */ KeyCode[KeyCode["Minus"] = 83] = "Minus"; /** * For any country/region, the '.' key * For the US standard keyboard, the '.>' key */ KeyCode[KeyCode["Period"] = 84] = "Period"; /** * Used for miscellaneous characters; it can vary by keyboard. * For the US standard keyboard, the '/?' key */ KeyCode[KeyCode["Slash"] = 85] = "Slash"; /** * Used for miscellaneous characters; it can vary by keyboard. * For the US standard keyboard, the '`~' key */ KeyCode[KeyCode["Backquote"] = 86] = "Backquote"; /** * Used for miscellaneous characters; it can vary by keyboard. * For the US standard keyboard, the '[{' key */ KeyCode[KeyCode["BracketLeft"] = 87] = "BracketLeft"; /** * Used for miscellaneous characters; it can vary by keyboard. * For the US standard keyboard, the '\|' key */ KeyCode[KeyCode["Backslash"] = 88] = "Backslash"; /** * Used for miscellaneous characters; it can vary by keyboard. * For the US standard keyboard, the ']}' key */ KeyCode[KeyCode["BracketRight"] = 89] = "BracketRight"; /** * Used for miscellaneous characters; it can vary by keyboard. * For the US standard keyboard, the ''"' key */ KeyCode[KeyCode["Quote"] = 90] = "Quote"; /** * Used for miscellaneous characters; it can vary by keyboard. */ KeyCode[KeyCode["OEM_8"] = 91] = "OEM_8"; /** * Either the angle bracket key or the backslash key on the RT 102-key keyboard. */ KeyCode[KeyCode["IntlBackslash"] = 92] = "IntlBackslash"; KeyCode[KeyCode["Numpad0"] = 93] = "Numpad0"; KeyCode[KeyCode["Numpad1"] = 94] = "Numpad1"; KeyCode[KeyCode["Numpad2"] = 95] = "Numpad2"; KeyCode[KeyCode["Numpad3"] = 96] = "Numpad3"; KeyCode[KeyCode["Numpad4"] = 97] = "Numpad4"; KeyCode[KeyCode["Numpad5"] = 98] = "Numpad5"; KeyCode[KeyCode["Numpad6"] = 99] = "Numpad6"; KeyCode[KeyCode["Numpad7"] = 100] = "Numpad7"; KeyCode[KeyCode["Numpad8"] = 101] = "Numpad8"; KeyCode[KeyCode["Numpad9"] = 102] = "Numpad9"; KeyCode[KeyCode["NumpadMultiply"] = 103] = "NumpadMultiply"; KeyCode[KeyCode["NumpadAdd"] = 104] = "NumpadAdd"; KeyCode[KeyCode["NUMPAD_SEPARATOR"] = 105] = "NUMPAD_SEPARATOR"; KeyCode[KeyCode["NumpadSubtract"] = 106] = "NumpadSubtract"; KeyCode[KeyCode["NumpadDecimal"] = 107] = "NumpadDecimal"; KeyCode[KeyCode["NumpadDivide"] = 108] = "NumpadDivide"; /** * Cover all key codes when IME is processing input. */ KeyCode[KeyCode["KEY_IN_COMPOSITION"] = 109] = "KEY_IN_COMPOSITION"; KeyCode[KeyCode["ABNT_C1"] = 110] = "ABNT_C1"; KeyCode[KeyCode["ABNT_C2"] = 111] = "ABNT_C2"; KeyCode[KeyCode["AudioVolumeMute"] = 112] = "AudioVolumeMute"; KeyCode[KeyCode["AudioVolumeUp"] = 113] = "AudioVolumeUp"; KeyCode[KeyCode["AudioVolumeDown"] = 114] = "AudioVolumeDown"; KeyCode[KeyCode["BrowserSearch"] = 115] = "BrowserSearch"; KeyCode[KeyCode["BrowserHome"] = 116] = "BrowserHome"; KeyCode[KeyCode["BrowserBack"] = 117] = "BrowserBack"; KeyCode[KeyCode["BrowserForward"] = 118] = "BrowserForward"; KeyCode[KeyCode["MediaTrackNext"] = 119] = "MediaTrackNext"; KeyCode[KeyCode["MediaTrackPrevious"] = 120] = "MediaTrackPrevious"; KeyCode[KeyCode["MediaStop"] = 121] = "MediaStop"; KeyCode[KeyCode["MediaPlayPause"] = 122] = "MediaPlayPause"; KeyCode[KeyCode["LaunchMediaPlayer"] = 123] = "LaunchMediaPlayer"; KeyCode[KeyCode["LaunchMail"] = 124] = "LaunchMail"; KeyCode[KeyCode["LaunchApp2"] = 125] = "LaunchApp2"; /** * Placed last to cover the length of the enum. * Please do not depend on this value! */ KeyCode[KeyCode["MAX_VALUE"] = 126] = "MAX_VALUE"; })(KeyCode$1 || (KeyCode$1 = {})); var MarkerSeverity$2; (function (MarkerSeverity) { MarkerSeverity[MarkerSeverity["Hint"] = 1] = "Hint"; MarkerSeverity[MarkerSeverity["Info"] = 2] = "Info"; MarkerSeverity[MarkerSeverity["Warning"] = 4] = "Warning"; MarkerSeverity[MarkerSeverity["Error"] = 8] = "Error"; })(MarkerSeverity$2 || (MarkerSeverity$2 = {})); var MarkerTag$1; (function (MarkerTag) { MarkerTag[MarkerTag["Unnecessary"] = 1] = "Unnecessary"; MarkerTag[MarkerTag["Deprecated"] = 2] = "Deprecated"; })(MarkerTag$1 || (MarkerTag$1 = {})); /** * Position in the minimap to render the decoration. */ var MinimapPosition; (function (MinimapPosition) { MinimapPosition[MinimapPosition["Inline"] = 1] = "Inline"; MinimapPosition[MinimapPosition["Gutter"] = 2] = "Gutter"; })(MinimapPosition || (MinimapPosition = {})); /** * Type of hit element with the mouse in the editor. */ var MouseTargetType; (function (MouseTargetType) { /** * Mouse is on top of an unknown element. */ MouseTargetType[MouseTargetType["UNKNOWN"] = 0] = "UNKNOWN"; /** * Mouse is on top of the textarea used for input. */ MouseTargetType[MouseTargetType["TEXTAREA"] = 1] = "TEXTAREA"; /** * Mouse is on top of the glyph margin */ MouseTargetType[MouseTargetType["GUTTER_GLYPH_MARGIN"] = 2] = "GUTTER_GLYPH_MARGIN"; /** * Mouse is on top of the line numbers */ MouseTargetType[MouseTargetType["GUTTER_LINE_NUMBERS"] = 3] = "GUTTER_LINE_NUMBERS"; /** * Mouse is on top of the line decorations */ MouseTargetType[MouseTargetType["GUTTER_LINE_DECORATIONS"] = 4] = "GUTTER_LINE_DECORATIONS"; /** * Mouse is on top of the whitespace left in the gutter by a view zone. */ MouseTargetType[MouseTargetType["GUTTER_VIEW_ZONE"] = 5] = "GUTTER_VIEW_ZONE"; /** * Mouse is on top of text in the content. */ MouseTargetType[MouseTargetType["CONTENT_TEXT"] = 6] = "CONTENT_TEXT"; /** * Mouse is on top of empty space in the content (e.g. after line text or below last line) */ MouseTargetType[MouseTargetType["CONTENT_EMPTY"] = 7] = "CONTENT_EMPTY"; /** * Mouse is on top of a view zone in the content. */ MouseTargetType[MouseTargetType["CONTENT_VIEW_ZONE"] = 8] = "CONTENT_VIEW_ZONE"; /** * Mouse is on top of a content widget. */ MouseTargetType[MouseTargetType["CONTENT_WIDGET"] = 9] = "CONTENT_WIDGET"; /** * Mouse is on top of the decorations overview ruler. */ MouseTargetType[MouseTargetType["OVERVIEW_RULER"] = 10] = "OVERVIEW_RULER"; /** * Mouse is on top of a scrollbar. */ MouseTargetType[MouseTargetType["SCROLLBAR"] = 11] = "SCROLLBAR"; /** * Mouse is on top of an overlay widget. */ MouseTargetType[MouseTargetType["OVERLAY_WIDGET"] = 12] = "OVERLAY_WIDGET"; /** * Mouse is outside of the editor. */ MouseTargetType[MouseTargetType["OUTSIDE_EDITOR"] = 13] = "OUTSIDE_EDITOR"; })(MouseTargetType || (MouseTargetType = {})); /** * A positioning preference for rendering overlay widgets. */ var OverlayWidgetPositionPreference; (function (OverlayWidgetPositionPreference) { /** * Position the overlay widget in the top right corner */ OverlayWidgetPositionPreference[OverlayWidgetPositionPreference["TOP_RIGHT_CORNER"] = 0] = "TOP_RIGHT_CORNER"; /** * Position the overlay widget in the bottom right corner */ OverlayWidgetPositionPreference[OverlayWidgetPositionPreference["BOTTOM_RIGHT_CORNER"] = 1] = "BOTTOM_RIGHT_CORNER"; /** * Position the overlay widget in the top center */ OverlayWidgetPositionPreference[OverlayWidgetPositionPreference["TOP_CENTER"] = 2] = "TOP_CENTER"; })(OverlayWidgetPositionPreference || (OverlayWidgetPositionPreference = {})); /** * Vertical Lane in the overview ruler of the editor. */ var OverviewRulerLane; (function (OverviewRulerLane) { OverviewRulerLane[OverviewRulerLane["Left"] = 1] = "Left"; OverviewRulerLane[OverviewRulerLane["Center"] = 2] = "Center"; OverviewRulerLane[OverviewRulerLane["Right"] = 4] = "Right"; OverviewRulerLane[OverviewRulerLane["Full"] = 7] = "Full"; })(OverviewRulerLane || (OverviewRulerLane = {})); var PositionAffinity; (function (PositionAffinity) { /** * Prefers the left most position. */ PositionAffinity[PositionAffinity["Left"] = 0] = "Left"; /** * Prefers the right most position. */ PositionAffinity[PositionAffinity["Right"] = 1] = "Right"; /** * No preference. */ PositionAffinity[PositionAffinity["None"] = 2] = "None"; })(PositionAffinity || (PositionAffinity = {})); var RenderLineNumbersType; (function (RenderLineNumbersType) { RenderLineNumbersType[RenderLineNumbersType["Off"] = 0] = "Off"; RenderLineNumbersType[RenderLineNumbersType["On"] = 1] = "On"; RenderLineNumbersType[RenderLineNumbersType["Relative"] = 2] = "Relative"; RenderLineNumbersType[RenderLineNumbersType["Interval"] = 3] = "Interval"; RenderLineNumbersType[RenderLineNumbersType["Custom"] = 4] = "Custom"; })(RenderLineNumbersType || (RenderLineNumbersType = {})); var RenderMinimap; (function (RenderMinimap) { RenderMinimap[RenderMinimap["None"] = 0] = "None"; RenderMinimap[RenderMinimap["Text"] = 1] = "Text"; RenderMinimap[RenderMinimap["Blocks"] = 2] = "Blocks"; })(RenderMinimap || (RenderMinimap = {})); var ScrollType; (function (ScrollType) { ScrollType[ScrollType["Smooth"] = 0] = "Smooth"; ScrollType[ScrollType["Immediate"] = 1] = "Immediate"; })(ScrollType || (ScrollType = {})); var ScrollbarVisibility; (function (ScrollbarVisibility) { ScrollbarVisibility[ScrollbarVisibility["Auto"] = 1] = "Auto"; ScrollbarVisibility[ScrollbarVisibility["Hidden"] = 2] = "Hidden"; ScrollbarVisibility[ScrollbarVisibility["Visible"] = 3] = "Visible"; })(ScrollbarVisibility || (ScrollbarVisibility = {})); /** * The direction of a selection. */ var SelectionDirection$1; (function (SelectionDirection) { /** * The selection starts above where it ends. */ SelectionDirection[SelectionDirection["LTR"] = 0] = "LTR"; /** * The selection starts below where it ends. */ SelectionDirection[SelectionDirection["RTL"] = 1] = "RTL"; })(SelectionDirection$1 || (SelectionDirection$1 = {})); var SignatureHelpTriggerKind; (function (SignatureHelpTriggerKind) { SignatureHelpTriggerKind[SignatureHelpTriggerKind["Invoke"] = 1] = "Invoke"; SignatureHelpTriggerKind[SignatureHelpTriggerKind["TriggerCharacter"] = 2] = "TriggerCharacter"; SignatureHelpTriggerKind[SignatureHelpTriggerKind["ContentChange"] = 3] = "ContentChange"; })(SignatureHelpTriggerKind || (SignatureHelpTriggerKind = {})); /** * A symbol kind. */ var SymbolKind$3; (function (SymbolKind) { SymbolKind[SymbolKind["File"] = 0] = "File"; SymbolKind[SymbolKind["Module"] = 1] = "Module"; SymbolKind[SymbolKind["Namespace"] = 2] = "Namespace"; SymbolKind[SymbolKind["Package"] = 3] = "Package"; SymbolKind[SymbolKind["Class"] = 4] = "Class"; SymbolKind[SymbolKind["Method"] = 5] = "Method"; SymbolKind[SymbolKind["Property"] = 6] = "Property"; SymbolKind[SymbolKind["Field"] = 7] = "Field"; SymbolKind[SymbolKind["Constructor"] = 8] = "Constructor"; SymbolKind[SymbolKind["Enum"] = 9] = "Enum"; SymbolKind[SymbolKind["Interface"] = 10] = "Interface"; SymbolKind[SymbolKind["Function"] = 11] = "Function"; SymbolKind[SymbolKind["Variable"] = 12] = "Variable"; SymbolKind[SymbolKind["Constant"] = 13] = "Constant"; SymbolKind[SymbolKind["String"] = 14] = "String"; SymbolKind[SymbolKind["Number"] = 15] = "Number"; SymbolKind[SymbolKind["Boolean"] = 16] = "Boolean"; SymbolKind[SymbolKind["Array"] = 17] = "Array"; SymbolKind[SymbolKind["Object"] = 18] = "Object"; SymbolKind[SymbolKind["Key"] = 19] = "Key"; SymbolKind[SymbolKind["Null"] = 20] = "Null"; SymbolKind[SymbolKind["EnumMember"] = 21] = "EnumMember"; SymbolKind[SymbolKind["Struct"] = 22] = "Struct"; SymbolKind[SymbolKind["Event"] = 23] = "Event"; SymbolKind[SymbolKind["Operator"] = 24] = "Operator"; SymbolKind[SymbolKind["TypeParameter"] = 25] = "TypeParameter"; })(SymbolKind$3 || (SymbolKind$3 = {})); var SymbolTag$3; (function (SymbolTag) { SymbolTag[SymbolTag["Deprecated"] = 1] = "Deprecated"; })(SymbolTag$3 || (SymbolTag$3 = {})); /** * The kind of animation in which the editor's cursor should be rendered. */ var TextEditorCursorBlinkingStyle; (function (TextEditorCursorBlinkingStyle) { /** * Hidden */ TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Hidden"] = 0] = "Hidden"; /** * Blinking */ TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Blink"] = 1] = "Blink"; /** * Blinking with smooth fading */ TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Smooth"] = 2] = "Smooth"; /** * Blinking with prolonged filled state and smooth fading */ TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Phase"] = 3] = "Phase"; /** * Expand collapse animation on the y axis */ TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Expand"] = 4] = "Expand"; /** * No-Blinking */ TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Solid"] = 5] = "Solid"; })(TextEditorCursorBlinkingStyle || (TextEditorCursorBlinkingStyle = {})); /** * The style in which the editor's cursor should be rendered. */ var TextEditorCursorStyle; (function (TextEditorCursorStyle) { /** * As a vertical line (sitting between two characters). */ TextEditorCursorStyle[TextEditorCursorStyle["Line"] = 1] = "Line"; /** * As a block (sitting on top of a character). */ TextEditorCursorStyle[TextEditorCursorStyle["Block"] = 2] = "Block"; /** * As a horizontal line (sitting under a character). */ TextEditorCursorStyle[TextEditorCursorStyle["Underline"] = 3] = "Underline"; /** * As a thin vertical line (sitting between two characters). */ TextEditorCursorStyle[TextEditorCursorStyle["LineThin"] = 4] = "LineThin"; /** * As an outlined block (sitting on top of a character). */ TextEditorCursorStyle[TextEditorCursorStyle["BlockOutline"] = 5] = "BlockOutline"; /** * As a thin horizontal line (sitting under a character). */ TextEditorCursorStyle[TextEditorCursorStyle["UnderlineThin"] = 6] = "UnderlineThin"; })(TextEditorCursorStyle || (TextEditorCursorStyle = {})); /** * Describes the behavior of decorations when typing/editing near their edges. * Note: Please do not edit the values, as they very carefully match `DecorationRangeBehavior` */ var TrackedRangeStickiness; (function (TrackedRangeStickiness) { TrackedRangeStickiness[TrackedRangeStickiness["AlwaysGrowsWhenTypingAtEdges"] = 0] = "AlwaysGrowsWhenTypingAtEdges"; TrackedRangeStickiness[TrackedRangeStickiness["NeverGrowsWhenTypingAtEdges"] = 1] = "NeverGrowsWhenTypingAtEdges"; TrackedRangeStickiness[TrackedRangeStickiness["GrowsOnlyWhenTypingBefore"] = 2] = "GrowsOnlyWhenTypingBefore"; TrackedRangeStickiness[TrackedRangeStickiness["GrowsOnlyWhenTypingAfter"] = 3] = "GrowsOnlyWhenTypingAfter"; })(TrackedRangeStickiness || (TrackedRangeStickiness = {})); /** * Describes how to indent wrapped lines. */ var WrappingIndent; (function (WrappingIndent) { /** * No indentation => wrapped lines begin at column 1. */ WrappingIndent[WrappingIndent["None"] = 0] = "None"; /** * Same => wrapped lines get the same indentation as the parent. */ WrappingIndent[WrappingIndent["Same"] = 1] = "Same"; /** * Indent => wrapped lines get +1 indentation toward the parent. */ WrappingIndent[WrappingIndent["Indent"] = 2] = "Indent"; /** * DeepIndent => wrapped lines get +2 indentation toward the parent. */ WrappingIndent[WrappingIndent["DeepIndent"] = 3] = "DeepIndent"; })(WrappingIndent || (WrappingIndent = {})); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class KeyMod$1 { static chord(firstPart, secondPart) { return KeyChord(firstPart, secondPart); } } KeyMod$1.CtrlCmd = 2048 /* CtrlCmd */; KeyMod$1.Shift = 1024 /* Shift */; KeyMod$1.Alt = 512 /* Alt */; KeyMod$1.WinCtrl = 256 /* WinCtrl */; function createMonacoBaseAPI() { return { editor: undefined, languages: undefined, CancellationTokenSource: CancellationTokenSource$1, Emitter: Emitter$1, KeyCode: KeyCode$1, KeyMod: KeyMod$1, Position: Position$4, Range: Range$5, Selection: Selection$1, SelectionDirection: SelectionDirection$1, MarkerSeverity: MarkerSeverity$2, MarkerTag: MarkerTag$1, Uri: URI, Token: Token$2 }; } var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n .scrollbar,\n\t.monaco-editor.vs-dark .monaco-scrollable-element > .scrollbar {\n\t\t-ms-high-contrast-adjust: none;\n\t\tbackground: background !important;\n\t\tborder: 1px solid windowtext;\n\t\tbox-sizing: border-box;\n\t}\n\t.monaco-editor.vs .monaco-scrollable-element > .scrollbar > .slider,\n\t.monaco-editor.vs-dark .monaco-scrollable-element > .scrollbar > .slider {\n\t\tbackground: windowtext !important;\n\t}\n\t.monaco-editor.vs .monaco-scrollable-element > .scrollbar > .slider:hover,\n\t.monaco-editor.vs-dark .monaco-scrollable-element > .scrollbar > .slider:hover {\n\t\tbackground: highlight !important;\n\t}\n\t.monaco-editor.vs .monaco-scrollable-element > .scrollbar > .slider.active,\n\t.monaco-editor.vs-dark .monaco-scrollable-element > .scrollbar > .slider.active {\n\t\tbackground: highlight !important;\n\t}\n\n\t/* overview ruler */\n\t.monaco-editor.vs .decorationsOverviewRuler,\n\t.monaco-editor.vs-dark .decorationsOverviewRuler {\n\t\topacity: 0;\n\t}\n\n\t/* minimap */\n\t.monaco-editor.vs .minimap,\n\t.monaco-editor.vs-dark .minimap {\n\t\tdisplay: none;\n\t}\n\n\t/* squiggles */\n\t.monaco-editor.vs .squiggly-d-error,\n\t.monaco-editor.vs-dark .squiggly-d-error {\n\t\tbackground: transparent !important;\n\t\tborder-bottom: 4px double #E47777;\n\t}\n\t.monaco-editor.vs .squiggly-c-warning,\n\t.monaco-editor.vs-dark .squiggly-c-warning {\n\t\tborder-bottom: 4px double #71B771;\n\t}\n\t.monaco-editor.vs .squiggly-b-info,\n\t.monaco-editor.vs-dark .squiggly-b-info {\n\t\tborder-bottom: 4px double #71B771;\n\t}\n\t.monaco-editor.vs .squiggly-a-hint,\n\t.monaco-editor.vs-dark .squiggly-a-hint {\n\t\tborder-bottom: 4px double #6c6c6c;\n\t}\n\n\t/* contextmenu */\n\t.monaco-editor.vs .monaco-menu .monaco-action-bar.vertical .action-menu-item:focus .action-label,\n\t.monaco-editor.vs-dark .monaco-menu .monaco-action-bar.vertical .action-menu-item:focus .action-label {\n\t\t-ms-high-contrast-adjust: none;\n\t\tcolor: highlighttext !important;\n\t\tbackground-color: highlight !important;\n\t}\n\t.monaco-editor.vs .monaco-menu .monaco-action-bar.vertical .action-menu-item:hover .action-label,\n\t.monaco-editor.vs-dark .monaco-menu .monaco-action-bar.vertical .action-menu-item:hover .action-label {\n\t\t-ms-high-contrast-adjust: none;\n\t\tbackground: transparent !important;\n\t\tborder: 1px solid highlight;\n\t\tbox-sizing: border-box;\n\t}\n\n\t/* diff editor */\n\t.monaco-diff-editor.vs .diffOverviewRuler,\n\t.monaco-diff-editor.vs-dark .diffOverviewRuler {\n\t\tdisplay: none;\n\t}\n\t.monaco-editor.vs .line-insert,\n\t.monaco-editor.vs-dark .line-insert,\n\t.monaco-editor.vs .line-delete,\n\t.monaco-editor.vs-dark .line-delete {\n\t\tbackground: transparent !important;\n\t\tborder: 1px solid highlight !important;\n\t\tbox-sizing: border-box;\n\t}\n\t.monaco-editor.vs .char-insert,\n\t.monaco-editor.vs-dark .char-insert,\n\t.monaco-editor.vs .char-delete,\n\t.monaco-editor.vs-dark .char-delete {\n\t\tbackground: transparent !important;\n\t}\n}\n\n/*.monaco-editor.vs [tabindex=\"0\"]:focus {\n\toutline: 1px solid rgba(0, 122, 204, 0.4);\n\toutline-offset: -1px;\n\topacity: 1 !important;\n}\n\n.monaco-editor.vs-dark [tabindex=\"0\"]:focus {\n\toutline: 1px solid rgba(14, 99, 156, 0.6);\n\toutline-offset: -1px;\n\topacity: 1 !important;\n}*/\n"; n(css$16,{}); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class WindowManager { constructor() { // --- Zoom Factor this._zoomFactor = 1; } getZoomFactor() { return this._zoomFactor; } } WindowManager.INSTANCE = new WindowManager(); class PixelRatioImpl extends Disposable { constructor() { super(); this._onDidChange = this._register(new Emitter$1()); this.onDidChange = this._onDidChange.event; this._value = this._getPixelRatio(); this._removeListener = this._installResolutionListener(); } get value() { return this._value; } dispose() { this._removeListener(); super.dispose(); } _installResolutionListener() { // See https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes const mediaQueryList = matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`); const listener = () => this._updateValue(); mediaQueryList.addEventListener('change', listener); return () => { mediaQueryList.removeEventListener('change', listener); }; } _updateValue() { this._value = this._getPixelRatio(); this._onDidChange.fire(this._value); this._removeListener = this._installResolutionListener(); } _getPixelRatio() { const ctx = document.createElement('canvas').getContext('2d'); const dpr = window.devicePixelRatio || 1; const bsr = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1; return dpr / bsr; } } class PixelRatioFacade { constructor() { this._pixelRatioMonitor = null; } _getOrCreatePixelRatioMonitor() { if (!this._pixelRatioMonitor) { this._pixelRatioMonitor = new PixelRatioImpl(); } return this._pixelRatioMonitor; } /** * Get the current value. */ get value() { return this._getOrCreatePixelRatioMonitor().value; } /** * Listen for changes. */ get onDidChange() { return this._getOrCreatePixelRatioMonitor().onDidChange; } } /** * Returns the pixel ratio. * * This is useful for rendering elements at native screen resolution or for being used as * a cache key when storing font measurements. Fonts might render differently depending on resolution * and any measurements need to be discarded for example when a window is moved from a monitor to another. */ const PixelRatio = new PixelRatioFacade(); /** The zoom scale for an index, e.g. 1, 1.2, 1.4 */ function getZoomFactor() { return WindowManager.INSTANCE.getZoomFactor(); } const userAgent = navigator.userAgent; const isFirefox = (userAgent.indexOf('Firefox') >= 0); const isWebKit = (userAgent.indexOf('AppleWebKit') >= 0); const isChrome = (userAgent.indexOf('Chrome') >= 0); const isSafari = (!isChrome && (userAgent.indexOf('Safari') >= 0)); const isWebkitWebView = (!isChrome && !isSafari && isWebKit); const isEdgeLegacyWebView = (userAgent.indexOf('Edge/') >= 0) && (userAgent.indexOf('WebView/') >= 0); const isElectron = (userAgent.indexOf('Electron/') >= 0); const isAndroid = (userAgent.indexOf('Android') >= 0); const isStandalone = (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches); var browser = /*#__PURE__*/Object.freeze({ __proto__: null, PixelRatio: PixelRatio, getZoomFactor: getZoomFactor, isFirefox: isFirefox, isWebKit: isWebKit, isChrome: isChrome, isSafari: isSafari, isWebkitWebView: isWebkitWebView, isEdgeLegacyWebView: isEdgeLegacyWebView, isElectron: isElectron, isAndroid: isAndroid, isStandalone: isStandalone }); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class FastDomNode { constructor(domNode) { this.domNode = domNode; this._maxWidth = -1; this._width = -1; this._height = -1; this._top = -1; this._left = -1; this._bottom = -1; this._right = -1; this._fontFamily = ''; this._fontWeight = ''; this._fontSize = -1; this._fontFeatureSettings = ''; this._lineHeight = -1; this._letterSpacing = -100; this._className = ''; this._display = ''; this._position = ''; this._visibility = ''; this._backgroundColor = ''; this._layerHint = false; this._contain = 'none'; this._boxShadow = ''; } setMaxWidth(maxWidth) { if (this._maxWidth === maxWidth) { return; } this._maxWidth = maxWidth; this.domNode.style.maxWidth = this._maxWidth + 'px'; } setWidth(width) { if (this._width === width) { return; } this._width = width; this.domNode.style.width = this._width + 'px'; } setHeight(height) { if (this._height === height) { return; } this._height = height; this.domNode.style.height = this._height + 'px'; } setTop(top) { if (this._top === top) { return; } this._top = top; this.domNode.style.top = this._top + 'px'; } unsetTop() { if (this._top === -1) { return; } this._top = -1; this.domNode.style.top = ''; } setLeft(left) { if (this._left === left) { return; } this._left = left; this.domNode.style.left = this._left + 'px'; } setBottom(bottom) { if (this._bottom === bottom) { return; } this._bottom = bottom; this.domNode.style.bottom = this._bottom + 'px'; } setRight(right) { if (this._right === right) { return; } this._right = right; this.domNode.style.right = this._right + 'px'; } setFontFamily(fontFamily) { if (this._fontFamily === fontFamily) { return; } this._fontFamily = fontFamily; this.domNode.style.fontFamily = this._fontFamily; } setFontWeight(fontWeight) { if (this._fontWeight === fontWeight) { return; } this._fontWeight = fontWeight; this.domNode.style.fontWeight = this._fontWeight; } setFontSize(fontSize) { if (this._fontSize === fontSize) { return; } this._fontSize = fontSize; this.domNode.style.fontSize = this._fontSize + 'px'; } setFontFeatureSettings(fontFeatureSettings) { if (this._fontFeatureSettings === fontFeatureSettings) { return; } this._fontFeatureSettings = fontFeatureSettings; this.domNode.style.fontFeatureSettings = this._fontFeatureSettings; } setLineHeight(lineHeight) { if (this._lineHeight === lineHeight) { return; } this._lineHeight = lineHeight; this.domNode.style.lineHeight = this._lineHeight + 'px'; } setLetterSpacing(letterSpacing) { if (this._letterSpacing === letterSpacing) { return; } this._letterSpacing = letterSpacing; this.domNode.style.letterSpacing = this._letterSpacing + 'px'; } setClassName(className) { if (this._className === className) { return; } this._className = className; this.domNode.className = this._className; } toggleClassName(className, shouldHaveIt) { this.domNode.classList.toggle(className, shouldHaveIt); this._className = this.domNode.className; } setDisplay(display) { if (this._display === display) { return; } this._display = display; this.domNode.style.display = this._display; } setPosition(position) { if (this._position === position) { return; } this._position = position; this.domNode.style.position = this._position; } setVisibility(visibility) { if (this._visibility === visibility) { return; } this._visibility = visibility; this.domNode.style.visibility = this._visibility; } setBackgroundColor(backgroundColor) { if (this._backgroundColor === backgroundColor) { return; } this._backgroundColor = backgroundColor; this.domNode.style.backgroundColor = this._backgroundColor; } setLayerHinting(layerHint) { if (this._layerHint === layerHint) { return; } this._layerHint = layerHint; this.domNode.style.transform = this._layerHint ? 'translate3d(0px, 0px, 0px)' : ''; } setBoxShadow(boxShadow) { if (this._boxShadow === boxShadow) { return; } this._boxShadow = boxShadow; this.domNode.style.boxShadow = boxShadow; } setContain(contain) { if (this._contain === contain) { return; } this._contain = contain; this.domNode.style.contain = this._contain; } setAttribute(name, value) { this.domNode.setAttribute(name, value); } removeAttribute(name) { this.domNode.removeAttribute(name); } appendChild(child) { this.domNode.appendChild(child.domNode); } removeChild(child) { this.domNode.removeChild(child.domNode); } } function createFastDomNode(domNode) { return new FastDomNode(domNode); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function applyFontInfo(domNode, fontInfo) { if (domNode instanceof FastDomNode) { domNode.setFontFamily(fontInfo.getMassagedFontFamily(isSafari ? EDITOR_FONT_DEFAULTS.fontFamily : null)); domNode.setFontWeight(fontInfo.fontWeight); domNode.setFontSize(fontInfo.fontSize); domNode.setFontFeatureSettings(fontInfo.fontFeatureSettings); domNode.setLineHeight(fontInfo.lineHeight); domNode.setLetterSpacing(fontInfo.letterSpacing); } else { domNode.style.fontFamily = fontInfo.getMassagedFontFamily(isSafari ? EDITOR_FONT_DEFAULTS.fontFamily : null); domNode.style.fontWeight = fontInfo.fontWeight; domNode.style.fontSize = fontInfo.fontSize + 'px'; domNode.style.fontFeatureSettings = fontInfo.fontFeatureSettings; domNode.style.lineHeight = fontInfo.lineHeight + 'px'; domNode.style.letterSpacing = fontInfo.letterSpacing + 'px'; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class CharWidthRequest { constructor(chr, type) { this.chr = chr; this.type = type; this.width = 0; } fulfill(width) { this.width = width; } } class DomCharWidthReader { constructor(bareFontInfo, requests) { this._bareFontInfo = bareFontInfo; this._requests = requests; this._container = null; this._testElements = null; } read() { // Create a test container with all these test elements this._createDomElements(); // Add the container to the DOM document.body.appendChild(this._container); // Read character widths this._readFromDomElements(); // Remove the container from the DOM document.body.removeChild(this._container); this._container = null; this._testElements = null; } _createDomElements() { const container = document.createElement('div'); container.style.position = 'absolute'; container.style.top = '-50000px'; container.style.width = '50000px'; const regularDomNode = document.createElement('div'); applyFontInfo(regularDomNode, this._bareFontInfo); container.appendChild(regularDomNode); const boldDomNode = document.createElement('div'); applyFontInfo(boldDomNode, this._bareFontInfo); boldDomNode.style.fontWeight = 'bold'; container.appendChild(boldDomNode); const italicDomNode = document.createElement('div'); applyFontInfo(italicDomNode, this._bareFontInfo); italicDomNode.style.fontStyle = 'italic'; container.appendChild(italicDomNode); const testElements = []; for (const request of this._requests) { let parent; if (request.type === 0 /* Regular */) { parent = regularDomNode; } if (request.type === 2 /* Bold */) { parent = boldDomNode; } if (request.type === 1 /* Italic */) { parent = italicDomNode; } parent.appendChild(document.createElement('br')); const testElement = document.createElement('span'); DomCharWidthReader._render(testElement, request); parent.appendChild(testElement); testElements.push(testElement); } this._container = container; this._testElements = testElements; } static _render(testElement, request) { if (request.chr === ' ') { let htmlString = '\u00a0'; // Repeat character 256 (2^8) times for (let i = 0; i < 8; i++) { htmlString += htmlString; } testElement.innerText = htmlString; } else { let testString = request.chr; // Repeat character 256 (2^8) times for (let i = 0; i < 8; i++) { testString += testString; } testElement.textContent = testString; } } _readFromDomElements() { for (let i = 0, len = this._requests.length; i < len; i++) { const request = this._requests[i]; const testElement = this._testElements[i]; request.fulfill(testElement.offsetWidth / 256); } } } function readCharWidths(bareFontInfo, requests) { const reader = new DomCharWidthReader(bareFontInfo, requests); reader.read(); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const EditorZoom = new class { constructor() { this._zoomLevel = 0; this._onDidChangeZoomLevel = new Emitter$1(); this.onDidChangeZoomLevel = this._onDidChangeZoomLevel.event; } getZoomLevel() { return this._zoomLevel; } setZoomLevel(zoomLevel) { zoomLevel = Math.min(Math.max(-5, zoomLevel), 20); if (this._zoomLevel === zoomLevel) { return; } this._zoomLevel = zoomLevel; this._onDidChangeZoomLevel.fire(this._zoomLevel); } }; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Determined from empirical observations. * @internal */ const GOLDEN_LINE_HEIGHT_RATIO = isMacintosh ? 1.5 : 1.35; /** * @internal */ const MINIMUM_LINE_HEIGHT = 8; class BareFontInfo { /** * @internal */ constructor(opts) { this._bareFontInfoBrand = undefined; this.pixelRatio = opts.pixelRatio; this.fontFamily = String(opts.fontFamily); this.fontWeight = String(opts.fontWeight); this.fontSize = opts.fontSize; this.fontFeatureSettings = opts.fontFeatureSettings; this.lineHeight = opts.lineHeight | 0; this.letterSpacing = opts.letterSpacing; } /** * @internal */ static createFromValidatedSettings(options, pixelRatio, ignoreEditorZoom) { const fontFamily = options.get(43 /* fontFamily */); const fontWeight = options.get(47 /* fontWeight */); const fontSize = options.get(46 /* fontSize */); const fontFeatureSettings = options.get(45 /* fontLigatures */); const lineHeight = options.get(59 /* lineHeight */); const letterSpacing = options.get(56 /* letterSpacing */); return BareFontInfo._create(fontFamily, fontWeight, fontSize, fontFeatureSettings, lineHeight, letterSpacing, pixelRatio, ignoreEditorZoom); } /** * @internal */ static _create(fontFamily, fontWeight, fontSize, fontFeatureSettings, lineHeight, letterSpacing, pixelRatio, ignoreEditorZoom) { if (lineHeight === 0) { lineHeight = GOLDEN_LINE_HEIGHT_RATIO * fontSize; } else if (lineHeight < MINIMUM_LINE_HEIGHT) { // Values too small to be line heights in pixels are in ems. lineHeight = lineHeight * fontSize; } // Enforce integer, minimum constraints lineHeight = Math.round(lineHeight); if (lineHeight < MINIMUM_LINE_HEIGHT) { lineHeight = MINIMUM_LINE_HEIGHT; } const editorZoomLevelMultiplier = 1 + (ignoreEditorZoom ? 0 : EditorZoom.getZoomLevel() * 0.1); fontSize *= editorZoomLevelMultiplier; lineHeight *= editorZoomLevelMultiplier; return new BareFontInfo({ pixelRatio: pixelRatio, fontFamily: fontFamily, fontWeight: fontWeight, fontSize: fontSize, fontFeatureSettings: fontFeatureSettings, lineHeight: lineHeight, letterSpacing: letterSpacing }); } /** * @internal */ getId() { return `${this.pixelRatio}-${this.fontFamily}-${this.fontWeight}-${this.fontSize}-${this.fontFeatureSettings}-${this.lineHeight}-${this.letterSpacing}`; } /** * @internal */ getMassagedFontFamily(fallbackFontFamily) { const fontFamily = BareFontInfo._wrapInQuotes(this.fontFamily); if (fallbackFontFamily && this.fontFamily !== fallbackFontFamily) { return `${fontFamily}, ${fallbackFontFamily}`; } return fontFamily; } static _wrapInQuotes(fontFamily) { if (/[,"']/.test(fontFamily)) { // Looks like the font family might be already escaped return fontFamily; } if (/[+ ]/.test(fontFamily)) { // Wrap a font family using + or with quotes return `"${fontFamily}"`; } return fontFamily; } } // change this whenever `FontInfo` members are changed const SERIALIZED_FONT_INFO_VERSION = 1; class FontInfo extends BareFontInfo { /** * @internal */ constructor(opts, isTrusted) { super(opts); this._editorStylingBrand = undefined; this.version = SERIALIZED_FONT_INFO_VERSION; this.isTrusted = isTrusted; this.isMonospace = opts.isMonospace; this.typicalHalfwidthCharacterWidth = opts.typicalHalfwidthCharacterWidth; this.typicalFullwidthCharacterWidth = opts.typicalFullwidthCharacterWidth; this.canUseHalfwidthRightwardsArrow = opts.canUseHalfwidthRightwardsArrow; this.spaceWidth = opts.spaceWidth; this.middotWidth = opts.middotWidth; this.wsmiddotWidth = opts.wsmiddotWidth; this.maxDigitWidth = opts.maxDigitWidth; } /** * @internal */ equals(other) { return (this.fontFamily === other.fontFamily && this.fontWeight === other.fontWeight && this.fontSize === other.fontSize && this.fontFeatureSettings === other.fontFeatureSettings && this.lineHeight === other.lineHeight && this.letterSpacing === other.letterSpacing && this.typicalHalfwidthCharacterWidth === other.typicalHalfwidthCharacterWidth && this.typicalFullwidthCharacterWidth === other.typicalFullwidthCharacterWidth && this.canUseHalfwidthRightwardsArrow === other.canUseHalfwidthRightwardsArrow && this.spaceWidth === other.spaceWidth && this.middotWidth === other.middotWidth && this.wsmiddotWidth === other.wsmiddotWidth && this.maxDigitWidth === other.maxDigitWidth); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class FontMeasurementsImpl extends Disposable { constructor() { super(); this._onDidChange = this._register(new Emitter$1()); this.onDidChange = this._onDidChange.event; this._cache = new FontMeasurementsCache(); this._evictUntrustedReadingsTimeout = -1; } dispose() { if (this._evictUntrustedReadingsTimeout !== -1) { window.clearTimeout(this._evictUntrustedReadingsTimeout); this._evictUntrustedReadingsTimeout = -1; } super.dispose(); } /** * Clear all cached font information and trigger a change event. */ clearAllFontInfos() { this._cache = new FontMeasurementsCache(); this._onDidChange.fire(); } _writeToCache(item, value) { this._cache.put(item, value); if (!value.isTrusted && this._evictUntrustedReadingsTimeout === -1) { // Try reading again after some time this._evictUntrustedReadingsTimeout = window.setTimeout(() => { this._evictUntrustedReadingsTimeout = -1; this._evictUntrustedReadings(); }, 5000); } } _evictUntrustedReadings() { const values = this._cache.getValues(); let somethingRemoved = false; for (const item of values) { if (!item.isTrusted) { somethingRemoved = true; this._cache.remove(item); } } if (somethingRemoved) { this._onDidChange.fire(); } } /** * Read font information. */ readFontInfo(bareFontInfo) { if (!this._cache.has(bareFontInfo)) { let readConfig = this._actualReadFontInfo(bareFontInfo); if (readConfig.typicalHalfwidthCharacterWidth <= 2 || readConfig.typicalFullwidthCharacterWidth <= 2 || readConfig.spaceWidth <= 2 || readConfig.maxDigitWidth <= 2) { // Hey, it's Bug 14341 ... we couldn't read readConfig = new FontInfo({ pixelRatio: PixelRatio.value, fontFamily: readConfig.fontFamily, fontWeight: readConfig.fontWeight, fontSize: readConfig.fontSize, fontFeatureSettings: readConfig.fontFeatureSettings, lineHeight: readConfig.lineHeight, letterSpacing: readConfig.letterSpacing, isMonospace: readConfig.isMonospace, typicalHalfwidthCharacterWidth: Math.max(readConfig.typicalHalfwidthCharacterWidth, 5), typicalFullwidthCharacterWidth: Math.max(readConfig.typicalFullwidthCharacterWidth, 5), canUseHalfwidthRightwardsArrow: readConfig.canUseHalfwidthRightwardsArrow, spaceWidth: Math.max(readConfig.spaceWidth, 5), middotWidth: Math.max(readConfig.middotWidth, 5), wsmiddotWidth: Math.max(readConfig.wsmiddotWidth, 5), maxDigitWidth: Math.max(readConfig.maxDigitWidth, 5), }, false); } this._writeToCache(bareFontInfo, readConfig); } return this._cache.get(bareFontInfo); } _createRequest(chr, type, all, monospace) { const result = new CharWidthRequest(chr, type); all.push(result); if (monospace) { monospace.push(result); } return result; } _actualReadFontInfo(bareFontInfo) { const all = []; const monospace = []; const typicalHalfwidthCharacter = this._createRequest('n', 0 /* Regular */, all, monospace); const typicalFullwidthCharacter = this._createRequest('\uff4d', 0 /* Regular */, all, null); const space = this._createRequest(' ', 0 /* Regular */, all, monospace); const digit0 = this._createRequest('0', 0 /* Regular */, all, monospace); const digit1 = this._createRequest('1', 0 /* Regular */, all, monospace); const digit2 = this._createRequest('2', 0 /* Regular */, all, monospace); const digit3 = this._createRequest('3', 0 /* Regular */, all, monospace); const digit4 = this._createRequest('4', 0 /* Regular */, all, monospace); const digit5 = this._createRequest('5', 0 /* Regular */, all, monospace); const digit6 = this._createRequest('6', 0 /* Regular */, all, monospace); const digit7 = this._createRequest('7', 0 /* Regular */, all, monospace); const digit8 = this._createRequest('8', 0 /* Regular */, all, monospace); const digit9 = this._createRequest('9', 0 /* Regular */, all, monospace); // monospace test: used for whitespace rendering const rightwardsArrow = this._createRequest('→', 0 /* Regular */, all, monospace); const halfwidthRightwardsArrow = this._createRequest('→', 0 /* Regular */, all, null); // U+00B7 - MIDDLE DOT const middot = this._createRequest('·', 0 /* Regular */, all, monospace); // U+2E31 - WORD SEPARATOR MIDDLE DOT const wsmiddotWidth = this._createRequest(String.fromCharCode(0x2E31), 0 /* Regular */, all, null); // monospace test: some characters const monospaceTestChars = '|/-_ilm%'; for (let i = 0, len = monospaceTestChars.length; i < len; i++) { this._createRequest(monospaceTestChars.charAt(i), 0 /* Regular */, all, monospace); this._createRequest(monospaceTestChars.charAt(i), 1 /* Italic */, all, monospace); this._createRequest(monospaceTestChars.charAt(i), 2 /* Bold */, all, monospace); } readCharWidths(bareFontInfo, all); const maxDigitWidth = Math.max(digit0.width, digit1.width, digit2.width, digit3.width, digit4.width, digit5.width, digit6.width, digit7.width, digit8.width, digit9.width); let isMonospace = (bareFontInfo.fontFeatureSettings === EditorFontLigatures.OFF); const referenceWidth = monospace[0].width; for (let i = 1, len = monospace.length; isMonospace && i < len; i++) { const diff = referenceWidth - monospace[i].width; if (diff < -0.001 || diff > 0.001) { isMonospace = false; break; } } let canUseHalfwidthRightwardsArrow = true; if (isMonospace && halfwidthRightwardsArrow.width !== referenceWidth) { // using a halfwidth rightwards arrow would break monospace... canUseHalfwidthRightwardsArrow = false; } if (halfwidthRightwardsArrow.width > rightwardsArrow.width) { // using a halfwidth rightwards arrow would paint a larger arrow than a regular rightwards arrow canUseHalfwidthRightwardsArrow = false; } return new FontInfo({ pixelRatio: PixelRatio.value, fontFamily: bareFontInfo.fontFamily, fontWeight: bareFontInfo.fontWeight, fontSize: bareFontInfo.fontSize, fontFeatureSettings: bareFontInfo.fontFeatureSettings, lineHeight: bareFontInfo.lineHeight, letterSpacing: bareFontInfo.letterSpacing, isMonospace: isMonospace, typicalHalfwidthCharacterWidth: typicalHalfwidthCharacter.width, typicalFullwidthCharacterWidth: typicalFullwidthCharacter.width, canUseHalfwidthRightwardsArrow: canUseHalfwidthRightwardsArrow, spaceWidth: space.width, middotWidth: middot.width, wsmiddotWidth: wsmiddotWidth.width, maxDigitWidth: maxDigitWidth }, true); } } class FontMeasurementsCache { constructor() { this._keys = Object.create(null); this._values = Object.create(null); } has(item) { const itemId = item.getId(); return !!this._values[itemId]; } get(item) { const itemId = item.getId(); return this._values[itemId]; } put(item, value) { const itemId = item.getId(); this._keys[itemId] = item; this._values[itemId] = value; } remove(item) { const itemId = item.getId(); delete this._keys[itemId]; delete this._values[itemId]; } getValues() { return Object.keys(this._keys).map(id => this._values[id]); } } const FontMeasurements = new FontMeasurementsImpl(); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ // ------ internal util var _util; (function (_util) { _util.serviceIds = new Map(); _util.DI_TARGET = '$di$target'; _util.DI_DEPENDENCIES = '$di$dependencies'; function getServiceDependencies(ctor) { return ctor[_util.DI_DEPENDENCIES] || []; } _util.getServiceDependencies = getServiceDependencies; })(_util || (_util = {})); const IInstantiationService = createDecorator('instantiationService'); function storeServiceDependency(id, target, index, optional) { if (target[_util.DI_TARGET] === target) { target[_util.DI_DEPENDENCIES].push({ id, index, optional }); } else { target[_util.DI_DEPENDENCIES] = [{ id, index, optional }]; target[_util.DI_TARGET] = target; } } /** * The *only* valid way to create a {{ServiceIdentifier}}. */ function createDecorator(serviceId) { if (_util.serviceIds.has(serviceId)) { return _util.serviceIds.get(serviceId); } const id = function (target, key, index) { if (arguments.length !== 3) { throw new Error('@IServiceName-decorator can only be used to decorate a parameter'); } storeServiceDependency(id, target, index, false); }; id.toString = () => serviceId; _util.serviceIds.set(serviceId, id); return id; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const ICodeEditorService = createDecorator('codeEditorService'); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Throws an error with the provided message if the provided value does not evaluate to a true Javascript value. */ function ok(value, message) { if (!value) { throw new Error(message ? `Assertion failed (${message})` : 'Assertion Failed'); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const defaultOptions$3 = { followsCaret: true, ignoreCharChanges: true, alwaysRevealFirst: true }; /** * Create a new diff navigator for the provided diff editor. */ class DiffNavigator extends Disposable { constructor(editor, options = {}) { super(); this._onDidUpdate = this._register(new Emitter$1()); this._editor = editor; this._options = mixin(options, defaultOptions$3, false); this.disposed = false; this.nextIdx = -1; this.ranges = []; this.ignoreSelectionChange = false; this.revealFirst = Boolean(this._options.alwaysRevealFirst); // hook up to diff editor for diff, disposal, and caret move this._register(this._editor.onDidDispose(() => this.dispose())); this._register(this._editor.onDidUpdateDiff(() => this._onDiffUpdated())); if (this._options.followsCaret) { this._register(this._editor.getModifiedEditor().onDidChangeCursorPosition((e) => { if (this.ignoreSelectionChange) { return; } this.nextIdx = -1; })); } if (this._options.alwaysRevealFirst) { this._register(this._editor.getModifiedEditor().onDidChangeModel((e) => { this.revealFirst = true; })); } // init things this._init(); } _init() { const changes = this._editor.getLineChanges(); if (!changes) { return; } } _onDiffUpdated() { this._init(); this._compute(this._editor.getLineChanges()); if (this.revealFirst) { // Only reveal first on first non-null changes if (this._editor.getLineChanges() !== null) { this.revealFirst = false; this.nextIdx = -1; this.next(1 /* Immediate */); } } } _compute(lineChanges) { // new ranges this.ranges = []; if (lineChanges) { // create ranges from changes lineChanges.forEach((lineChange) => { if (!this._options.ignoreCharChanges && lineChange.charChanges) { lineChange.charChanges.forEach((charChange) => { this.ranges.push({ rhs: true, range: new Range$5(charChange.modifiedStartLineNumber, charChange.modifiedStartColumn, charChange.modifiedEndLineNumber, charChange.modifiedEndColumn) }); }); } else { if (lineChange.modifiedEndLineNumber === 0) { // a deletion this.ranges.push({ rhs: true, range: new Range$5(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedStartLineNumber + 1, 1) }); } else { // an insertion or modification this.ranges.push({ rhs: true, range: new Range$5(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber + 1, 1) }); } } }); } // sort this.ranges.sort((left, right) => Range$5.compareRangesUsingStarts(left.range, right.range)); this._onDidUpdate.fire(this); } _initIdx(fwd) { let found = false; const position = this._editor.getPosition(); if (!position) { this.nextIdx = 0; return; } for (let i = 0, len = this.ranges.length; i < len && !found; i++) { const range = this.ranges[i].range; if (position.isBeforeOrEqual(range.getStartPosition())) { this.nextIdx = i + (fwd ? 0 : -1); found = true; } } if (!found) { // after the last change this.nextIdx = fwd ? 0 : this.ranges.length - 1; } if (this.nextIdx < 0) { this.nextIdx = this.ranges.length - 1; } } _move(fwd, scrollType) { ok(!this.disposed, 'Illegal State - diff navigator has been disposed'); if (!this.canNavigate()) { return; } if (this.nextIdx === -1) { this._initIdx(fwd); } else if (fwd) { this.nextIdx += 1; if (this.nextIdx >= this.ranges.length) { this.nextIdx = 0; } } else { this.nextIdx -= 1; if (this.nextIdx < 0) { this.nextIdx = this.ranges.length - 1; } } const info = this.ranges[this.nextIdx]; this.ignoreSelectionChange = true; try { const pos = info.range.getStartPosition(); this._editor.setPosition(pos); this._editor.revealRangeInCenter(info.range, scrollType); } finally { this.ignoreSelectionChange = false; } } canNavigate() { return this.ranges && this.ranges.length > 0; } next(scrollType = 0 /* Smooth */) { this._move(true, scrollType); } previous(scrollType = 0 /* Smooth */) { this._move(false, scrollType); } dispose() { super.dispose(); this.ranges = []; this.disposed = true; } } /** * The type of the `IEditor`. */ const EditorType = { ICodeEditor: 'vs.editor.ICodeEditor', IDiffEditor: 'vs.editor.IDiffEditor' }; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Describes what to do with the indentation when pressing Enter. */ var IndentAction; (function (IndentAction) { /** * Insert new line and copy the previous line's indentation. */ IndentAction[IndentAction["None"] = 0] = "None"; /** * Insert new line and indent once (relative to the previous line's indentation). */ IndentAction[IndentAction["Indent"] = 1] = "Indent"; /** * Insert two new lines: * - the first one indented which will hold the cursor * - the second one at the same indentation level */ IndentAction[IndentAction["IndentOutdent"] = 2] = "IndentOutdent"; /** * Insert new line and outdent once (relative to the previous line's indentation). */ IndentAction[IndentAction["Outdent"] = 3] = "Outdent"; })(IndentAction || (IndentAction = {})); /** * @internal */ class StandardAutoClosingPairConditional { constructor(source) { this._neutralCharacter = null; this._neutralCharacterSearched = false; this.open = source.open; this.close = source.close; // initially allowed in all tokens this._inString = true; this._inComment = true; this._inRegEx = true; if (Array.isArray(source.notIn)) { for (let i = 0, len = source.notIn.length; i < len; i++) { const notIn = source.notIn[i]; switch (notIn) { case 'string': this._inString = false; break; case 'comment': this._inComment = false; break; case 'regex': this._inRegEx = false; break; } } } } isOK(standardToken) { switch (standardToken) { case 0 /* Other */: return true; case 1 /* Comment */: return this._inComment; case 2 /* String */: return this._inString; case 3 /* RegEx */: return this._inRegEx; } } shouldAutoClose(context, column) { // Always complete on empty line if (context.getTokenCount() === 0) { return true; } const tokenIndex = context.findTokenIndexAtOffset(column - 2); const standardTokenType = context.getStandardTokenType(tokenIndex); return this.isOK(standardTokenType); } _findNeutralCharacterInRange(fromCharCode, toCharCode) { for (let charCode = fromCharCode; charCode <= toCharCode; charCode++) { const character = String.fromCharCode(charCode); if (!this.open.includes(character) && !this.close.includes(character)) { return character; } } return null; } /** * Find a character in the range [0-9a-zA-Z] that does not appear in the open or close */ findNeutralCharacter() { if (!this._neutralCharacterSearched) { this._neutralCharacterSearched = true; if (!this._neutralCharacter) { this._neutralCharacter = this._findNeutralCharacterInRange(48 /* Digit0 */, 57 /* Digit9 */); } if (!this._neutralCharacter) { this._neutralCharacter = this._findNeutralCharacterInRange(97 /* a */, 122 /* z */); } if (!this._neutralCharacter) { this._neutralCharacter = this._findNeutralCharacterInRange(65 /* A */, 90 /* Z */); } } return this._neutralCharacter; } } /** * @internal */ class AutoClosingPairs { constructor(autoClosingPairs) { this.autoClosingPairsOpenByStart = new Map(); this.autoClosingPairsOpenByEnd = new Map(); this.autoClosingPairsCloseByStart = new Map(); this.autoClosingPairsCloseByEnd = new Map(); this.autoClosingPairsCloseSingleChar = new Map(); for (const pair of autoClosingPairs) { appendEntry(this.autoClosingPairsOpenByStart, pair.open.charAt(0), pair); appendEntry(this.autoClosingPairsOpenByEnd, pair.open.charAt(pair.open.length - 1), pair); appendEntry(this.autoClosingPairsCloseByStart, pair.close.charAt(0), pair); appendEntry(this.autoClosingPairsCloseByEnd, pair.close.charAt(pair.close.length - 1), pair); if (pair.close.length === 1 && pair.open.length === 1) { appendEntry(this.autoClosingPairsCloseSingleChar, pair.close, pair); } } } } function appendEntry(target, key, value) { if (target.has(key)) { target.get(key).push(value); } else { target.set(key, [value]); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function createScopedLineTokens(context, offset) { const tokenCount = context.getCount(); const tokenIndex = context.findTokenIndexAtOffset(offset); const desiredLanguageId = context.getLanguageId(tokenIndex); let lastTokenIndex = tokenIndex; while (lastTokenIndex + 1 < tokenCount && context.getLanguageId(lastTokenIndex + 1) === desiredLanguageId) { lastTokenIndex++; } let firstTokenIndex = tokenIndex; while (firstTokenIndex > 0 && context.getLanguageId(firstTokenIndex - 1) === desiredLanguageId) { firstTokenIndex--; } return new ScopedLineTokens(context, desiredLanguageId, firstTokenIndex, lastTokenIndex + 1, context.getStartOffset(firstTokenIndex), context.getEndOffset(lastTokenIndex)); } class ScopedLineTokens { constructor(actual, languageId, firstTokenIndex, lastTokenIndex, firstCharOffset, lastCharOffset) { this._scopedLineTokensBrand = undefined; this._actual = actual; this.languageId = languageId; this._firstTokenIndex = firstTokenIndex; this._lastTokenIndex = lastTokenIndex; this.firstCharOffset = firstCharOffset; this._lastCharOffset = lastCharOffset; } getLineContent() { const actualLineContent = this._actual.getLineContent(); return actualLineContent.substring(this.firstCharOffset, this._lastCharOffset); } getActualLineContentBefore(offset) { const actualLineContent = this._actual.getLineContent(); return actualLineContent.substring(0, this.firstCharOffset + offset); } getTokenCount() { return this._lastTokenIndex - this._firstTokenIndex; } findTokenIndexAtOffset(offset) { return this._actual.findTokenIndexAtOffset(offset + this.firstCharOffset) - this._firstTokenIndex; } getStandardTokenType(tokenIndex) { return this._actual.getStandardTokenType(tokenIndex + this._firstTokenIndex); } } function ignoreBracketsInToken(standardTokenType) { return (standardTokenType & 3 /* value */) !== 0; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class CharacterPairSupport { constructor(config) { if (config.autoClosingPairs) { this._autoClosingPairs = config.autoClosingPairs.map(el => new StandardAutoClosingPairConditional(el)); } else if (config.brackets) { this._autoClosingPairs = config.brackets.map(b => new StandardAutoClosingPairConditional({ open: b[0], close: b[1] })); } else { this._autoClosingPairs = []; } if (config.colorizedBracketPairs) { this._colorizedBracketPairs = filterValidBrackets(config.colorizedBracketPairs.map(b => [b[0], b[1]])); } else if (config.brackets) { this._colorizedBracketPairs = filterValidBrackets(config.brackets .map((b) => [b[0], b[1]]) // Many languages set < ... > as bracket pair, even though they also use it as comparison operator. // This leads to problems when colorizing this bracket, so we exclude it by default. // Languages can still override this by configuring `colorizedBracketPairs` // https://github.com/microsoft/vscode/issues/132476 .filter((p) => !(p[0] === '<' && p[1] === '>'))); } else { this._colorizedBracketPairs = []; } if (config.__electricCharacterSupport && config.__electricCharacterSupport.docComment) { const docComment = config.__electricCharacterSupport.docComment; // IDocComment is legacy, only partially supported this._autoClosingPairs.push(new StandardAutoClosingPairConditional({ open: docComment.open, close: docComment.close || '' })); } this._autoCloseBefore = typeof config.autoCloseBefore === 'string' ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED; this._surroundingPairs = config.surroundingPairs || this._autoClosingPairs; } getAutoClosingPairs() { return this._autoClosingPairs; } getAutoCloseBeforeSet() { return this._autoCloseBefore; } getSurroundingPairs() { return this._surroundingPairs; } getColorizedBrackets() { return this._colorizedBracketPairs; } } CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED = ';:.,=}])> \n\t'; function filterValidBrackets(bracketPairs) { return bracketPairs.filter(([open, close]) => open !== '' && close !== ''); } const hasBuffer = (typeof Buffer !== 'undefined'); let textDecoder; class VSBuffer { constructor(buffer) { this.buffer = buffer; this.byteLength = this.buffer.byteLength; } /** * When running in a nodejs context, if `actual` is not a nodejs Buffer, the backing store for * the returned `VSBuffer` instance might use a nodejs Buffer allocated from node's Buffer pool, * which is not transferrable. */ static wrap(actual) { if (hasBuffer && !(Buffer.isBuffer(actual))) { // https://nodejs.org/dist/latest-v10.x/docs/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length // Create a zero-copy Buffer wrapper around the ArrayBuffer pointed to by the Uint8Array actual = Buffer.from(actual.buffer, actual.byteOffset, actual.byteLength); } return new VSBuffer(actual); } toString() { if (hasBuffer) { return this.buffer.toString(); } else { if (!textDecoder) { textDecoder = new TextDecoder(); } return textDecoder.decode(this.buffer); } } } function readUInt16LE(source, offset) { return (((source[offset + 0] << 0) >>> 0) | ((source[offset + 1] << 8) >>> 0)); } function writeUInt16LE(destination, value, offset) { destination[offset + 0] = (value & 0b11111111); value = value >>> 8; destination[offset + 1] = (value & 0b11111111); } function readUInt32BE(source, offset) { return (source[offset] * Math.pow(2, 24) + source[offset + 1] * Math.pow(2, 16) + source[offset + 2] * Math.pow(2, 8) + source[offset + 3]); } function writeUInt32BE(destination, value, offset) { destination[offset + 3] = value; value = value >>> 8; destination[offset + 2] = value; value = value >>> 8; destination[offset + 1] = value; value = value >>> 8; destination[offset] = value; } function readUInt8(source, offset) { return source[offset]; } function writeUInt8(destination, value, offset) { destination[offset] = value; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ let _utf16LE_TextDecoder; function getUTF16LE_TextDecoder() { if (!_utf16LE_TextDecoder) { _utf16LE_TextDecoder = new TextDecoder('UTF-16LE'); } return _utf16LE_TextDecoder; } let _utf16BE_TextDecoder; function getUTF16BE_TextDecoder() { if (!_utf16BE_TextDecoder) { _utf16BE_TextDecoder = new TextDecoder('UTF-16BE'); } return _utf16BE_TextDecoder; } let _platformTextDecoder; function getPlatformTextDecoder() { if (!_platformTextDecoder) { _platformTextDecoder = isLittleEndian() ? getUTF16LE_TextDecoder() : getUTF16BE_TextDecoder(); } return _platformTextDecoder; } const hasTextDecoder = (typeof TextDecoder !== 'undefined'); let createStringBuilder; let decodeUTF16LE; if (hasTextDecoder) { createStringBuilder = (capacity) => new StringBuilder(capacity); decodeUTF16LE = standardDecodeUTF16LE; } else { createStringBuilder = (capacity) => new CompatStringBuilder(); decodeUTF16LE = compatDecodeUTF16LE; } function standardDecodeUTF16LE(source, offset, len) { const view = new Uint16Array(source.buffer, offset, len); if (len > 0 && (view[0] === 0xFEFF || view[0] === 0xFFFE)) { // UTF16 sometimes starts with a BOM https://de.wikipedia.org/wiki/Byte_Order_Mark // It looks like TextDecoder.decode will eat up a leading BOM (0xFEFF or 0xFFFE) // We don't want that behavior because we know the string is UTF16LE and the BOM should be maintained // So we use the manual decoder return compatDecodeUTF16LE(source, offset, len); } return getUTF16LE_TextDecoder().decode(view); } function compatDecodeUTF16LE(source, offset, len) { const result = []; let resultLen = 0; for (let i = 0; i < len; i++) { const charCode = readUInt16LE(source, offset); offset += 2; result[resultLen++] = String.fromCharCode(charCode); } return result.join(''); } class StringBuilder { constructor(capacity) { this._capacity = capacity | 0; this._buffer = new Uint16Array(this._capacity); this._completedStrings = null; this._bufferLength = 0; } reset() { this._completedStrings = null; this._bufferLength = 0; } build() { if (this._completedStrings !== null) { this._flushBuffer(); return this._completedStrings.join(''); } return this._buildBuffer(); } _buildBuffer() { if (this._bufferLength === 0) { return ''; } const view = new Uint16Array(this._buffer.buffer, 0, this._bufferLength); return getPlatformTextDecoder().decode(view); } _flushBuffer() { const bufferString = this._buildBuffer(); this._bufferLength = 0; if (this._completedStrings === null) { this._completedStrings = [bufferString]; } else { this._completedStrings[this._completedStrings.length] = bufferString; } } write1(charCode) { const remainingSpace = this._capacity - this._bufferLength; if (remainingSpace <= 1) { if (remainingSpace === 0 || isHighSurrogate(charCode)) { this._flushBuffer(); } } this._buffer[this._bufferLength++] = charCode; } appendASCII(charCode) { if (this._bufferLength === this._capacity) { // buffer is full this._flushBuffer(); } this._buffer[this._bufferLength++] = charCode; } appendASCIIString(str) { const strLen = str.length; if (this._bufferLength + strLen >= this._capacity) { // This string does not fit in the remaining buffer space this._flushBuffer(); this._completedStrings[this._completedStrings.length] = str; return; } for (let i = 0; i < strLen; i++) { this._buffer[this._bufferLength++] = str.charCodeAt(i); } } } class CompatStringBuilder { constructor() { this._pieces = []; this._piecesLen = 0; } reset() { this._pieces = []; this._piecesLen = 0; } build() { return this._pieces.join(''); } write1(charCode) { this._pieces[this._piecesLen++] = String.fromCharCode(charCode); } appendASCII(charCode) { this._pieces[this._piecesLen++] = String.fromCharCode(charCode); } appendASCIIString(str) { this._pieces[this._piecesLen++] = str; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Represents a grouping of colliding bracket pairs. * * Most of the times this contains a single bracket pair, * but sometimes this contains multiple bracket pairs in cases * where the same string appears as a closing bracket for multiple * bracket pairs, or the same string appears an opening bracket for * multiple bracket pairs. * * e.g. of a group containing a single pair: * open: ['{'], close: ['}'] * * e.g. of a group containing multiple pairs: * open: ['if', 'for'], close: ['end', 'end'] */ class RichEditBracket { constructor(languageId, index, open, close, forwardRegex, reversedRegex) { this._richEditBracketBrand = undefined; this.languageId = languageId; this.index = index; this.open = open; this.close = close; this.forwardRegex = forwardRegex; this.reversedRegex = reversedRegex; this._openSet = RichEditBracket._toSet(this.open); this._closeSet = RichEditBracket._toSet(this.close); } /** * Check if the provided `text` is an open bracket in this group. */ isOpen(text) { return this._openSet.has(text); } /** * Check if the provided `text` is a close bracket in this group. */ isClose(text) { return this._closeSet.has(text); } static _toSet(arr) { const result = new Set(); for (const element of arr) { result.add(element); } return result; } } /** * Groups together brackets that have equal open or close sequences. * * For example, if the following brackets are defined: * ['IF','END'] * ['for','end'] * ['{','}'] * * Then the grouped brackets would be: * { open: ['if', 'for'], close: ['end', 'end'] } * { open: ['{'], close: ['}'] } * */ function groupFuzzyBrackets(brackets) { const N = brackets.length; brackets = brackets.map(b => [b[0].toLowerCase(), b[1].toLowerCase()]); const group = []; for (let i = 0; i < N; i++) { group[i] = i; } const areOverlapping = (a, b) => { const [aOpen, aClose] = a; const [bOpen, bClose] = b; return (aOpen === bOpen || aOpen === bClose || aClose === bOpen || aClose === bClose); }; const mergeGroups = (g1, g2) => { const newG = Math.min(g1, g2); const oldG = Math.max(g1, g2); for (let i = 0; i < N; i++) { if (group[i] === oldG) { group[i] = newG; } } }; // group together brackets that have the same open or the same close sequence for (let i = 0; i < N; i++) { const a = brackets[i]; for (let j = i + 1; j < N; j++) { const b = brackets[j]; if (areOverlapping(a, b)) { mergeGroups(group[i], group[j]); } } } const result = []; for (let g = 0; g < N; g++) { const currentOpen = []; const currentClose = []; for (let i = 0; i < N; i++) { if (group[i] === g) { const [open, close] = brackets[i]; currentOpen.push(open); currentClose.push(close); } } if (currentOpen.length > 0) { result.push({ open: currentOpen, close: currentClose }); } } return result; } class RichEditBrackets { constructor(languageId, _brackets) { this._richEditBracketsBrand = undefined; const brackets = groupFuzzyBrackets(_brackets); this.brackets = brackets.map((b, index) => { return new RichEditBracket(languageId, index, b.open, b.close, getRegexForBracketPair(b.open, b.close, brackets, index), getReversedRegexForBracketPair(b.open, b.close, brackets, index)); }); this.forwardRegex = getRegexForBrackets(this.brackets); this.reversedRegex = getReversedRegexForBrackets(this.brackets); this.textIsBracket = {}; this.textIsOpenBracket = {}; this.maxBracketLength = 0; for (const bracket of this.brackets) { for (const open of bracket.open) { this.textIsBracket[open] = bracket; this.textIsOpenBracket[open] = true; this.maxBracketLength = Math.max(this.maxBracketLength, open.length); } for (const close of bracket.close) { this.textIsBracket[close] = bracket; this.textIsOpenBracket[close] = false; this.maxBracketLength = Math.max(this.maxBracketLength, close.length); } } } } function collectSuperstrings(str, brackets, currentIndex, dest) { for (let i = 0, len = brackets.length; i < len; i++) { if (i === currentIndex) { continue; } const bracket = brackets[i]; for (const open of bracket.open) { if (open.indexOf(str) >= 0) { dest.push(open); } } for (const close of bracket.close) { if (close.indexOf(str) >= 0) { dest.push(close); } } } } function lengthcmp(a, b) { return a.length - b.length; } function unique(arr) { if (arr.length <= 1) { return arr; } const result = []; const seen = new Set(); for (const element of arr) { if (seen.has(element)) { continue; } result.push(element); seen.add(element); } return result; } /** * Create a regular expression that can be used to search forward in a piece of text * for a group of bracket pairs. But this regex must be built in a way in which * it is aware of the other bracket pairs defined for the language. * * For example, if a language contains the following bracket pairs: * ['begin', 'end'] * ['if', 'end if'] * The two bracket pairs do not collide because no open or close brackets are equal. * So the function getRegexForBracketPair is called twice, once with * the ['begin'], ['end'] group consisting of one bracket pair, and once with * the ['if'], ['end if'] group consiting of the other bracket pair. * * But there could be a situation where an occurrence of 'end if' is mistaken * for an occurrence of 'end'. * * Therefore, for the bracket pair ['begin', 'end'], the regex will also * target 'end if'. The regex will be something like: * /(\bend if\b)|(\bend\b)|(\bif\b)/ * * The regex also searches for "superstrings" (other brackets that might be mistaken with the current bracket). * */ function getRegexForBracketPair(open, close, brackets, currentIndex) { // search in all brackets for other brackets that are a superstring of these brackets let pieces = []; pieces = pieces.concat(open); pieces = pieces.concat(close); for (let i = 0, len = pieces.length; i < len; i++) { collectSuperstrings(pieces[i], brackets, currentIndex, pieces); } pieces = unique(pieces); pieces.sort(lengthcmp); pieces.reverse(); return createBracketOrRegExp(pieces); } /** * Matching a regular expression in JS can only be done "forwards". So JS offers natively only * methods to find the first match of a regex in a string. But sometimes, it is useful to * find the last match of a regex in a string. For such a situation, a nice solution is to * simply reverse the string and then search for a reversed regex. * * This function also has the fine details of `getRegexForBracketPair`. For the same example * given above, the regex produced here would look like: * /(\bfi dne\b)|(\bdne\b)|(\bfi\b)/ */ function getReversedRegexForBracketPair(open, close, brackets, currentIndex) { // search in all brackets for other brackets that are a superstring of these brackets let pieces = []; pieces = pieces.concat(open); pieces = pieces.concat(close); for (let i = 0, len = pieces.length; i < len; i++) { collectSuperstrings(pieces[i], brackets, currentIndex, pieces); } pieces = unique(pieces); pieces.sort(lengthcmp); pieces.reverse(); return createBracketOrRegExp(pieces.map(toReversedString)); } /** * Creates a regular expression that targets all bracket pairs. * * e.g. for the bracket pairs: * ['{','}'] * ['begin,'end'] * ['for','end'] * the regex would look like: * /(\{)|(\})|(\bbegin\b)|(\bend\b)|(\bfor\b)/ */ function getRegexForBrackets(brackets) { let pieces = []; for (const bracket of brackets) { for (const open of bracket.open) { pieces.push(open); } for (const close of bracket.close) { pieces.push(close); } } pieces = unique(pieces); return createBracketOrRegExp(pieces); } /** * Matching a regular expression in JS can only be done "forwards". So JS offers natively only * methods to find the first match of a regex in a string. But sometimes, it is useful to * find the last match of a regex in a string. For such a situation, a nice solution is to * simply reverse the string and then search for a reversed regex. * * e.g. for the bracket pairs: * ['{','}'] * ['begin,'end'] * ['for','end'] * the regex would look like: * /(\{)|(\})|(\bnigeb\b)|(\bdne\b)|(\brof\b)/ */ function getReversedRegexForBrackets(brackets) { let pieces = []; for (const bracket of brackets) { for (const open of bracket.open) { pieces.push(open); } for (const close of bracket.close) { pieces.push(close); } } pieces = unique(pieces); return createBracketOrRegExp(pieces.map(toReversedString)); } function prepareBracketForRegExp$1(str) { // This bracket pair uses letters like e.g. "begin" - "end" const insertWordBoundaries = (/^[\w ]+$/.test(str)); str = escapeRegExpCharacters(str); return (insertWordBoundaries ? `\\b${str}\\b` : str); } function createBracketOrRegExp(pieces) { const regexStr = `(${pieces.map(prepareBracketForRegExp$1).join(')|(')})`; return createRegExp(regexStr, true); } const toReversedString = (function () { function reverse(str) { if (hasTextDecoder) { // create a Uint16Array and then use a TextDecoder to create a string const arr = new Uint16Array(str.length); let offset = 0; for (let i = str.length - 1; i >= 0; i--) { arr[offset++] = str.charCodeAt(i); } return getPlatformTextDecoder().decode(arr); } else { const result = []; let resultLen = 0; for (let i = str.length - 1; i >= 0; i--) { result[resultLen++] = str.charAt(i); } return result.join(''); } } let lastInput = null; let lastOutput = null; return function toReversedString(str) { if (lastInput !== str) { lastInput = str; lastOutput = reverse(lastInput); } return lastOutput; }; })(); class BracketsUtils { static _findPrevBracketInText(reversedBracketRegex, lineNumber, reversedText, offset) { const m = reversedText.match(reversedBracketRegex); if (!m) { return null; } const matchOffset = reversedText.length - (m.index || 0); const matchLength = m[0].length; const absoluteMatchOffset = offset + matchOffset; return new Range$5(lineNumber, absoluteMatchOffset - matchLength + 1, lineNumber, absoluteMatchOffset + 1); } static findPrevBracketInRange(reversedBracketRegex, lineNumber, lineText, startOffset, endOffset) { // Because JS does not support backwards regex search, we search forwards in a reversed string with a reversed regex ;) const reversedLineText = toReversedString(lineText); const reversedSubstr = reversedLineText.substring(lineText.length - endOffset, lineText.length - startOffset); return this._findPrevBracketInText(reversedBracketRegex, lineNumber, reversedSubstr, startOffset); } static findNextBracketInText(bracketRegex, lineNumber, text, offset) { const m = text.match(bracketRegex); if (!m) { return null; } const matchOffset = m.index || 0; const matchLength = m[0].length; if (matchLength === 0) { return null; } const absoluteMatchOffset = offset + matchOffset; return new Range$5(lineNumber, absoluteMatchOffset + 1, lineNumber, absoluteMatchOffset + 1 + matchLength); } static findNextBracketInRange(bracketRegex, lineNumber, lineText, startOffset, endOffset) { const substr = lineText.substring(startOffset, endOffset); return this.findNextBracketInText(bracketRegex, lineNumber, substr, startOffset); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class BracketElectricCharacterSupport { constructor(richEditBrackets) { this._richEditBrackets = richEditBrackets; } getElectricCharacters() { const result = []; if (this._richEditBrackets) { for (const bracket of this._richEditBrackets.brackets) { for (const close of bracket.close) { const lastChar = close.charAt(close.length - 1); result.push(lastChar); } } } return distinct(result); } onElectricCharacter(character, context, column) { if (!this._richEditBrackets || this._richEditBrackets.brackets.length === 0) { return null; } const tokenIndex = context.findTokenIndexAtOffset(column - 1); if (ignoreBracketsInToken(context.getStandardTokenType(tokenIndex))) { return null; } const reversedBracketRegex = this._richEditBrackets.reversedRegex; const text = context.getLineContent().substring(0, column - 1) + character; const r = BracketsUtils.findPrevBracketInRange(reversedBracketRegex, 1, text, 0, text.length); if (!r) { return null; } const bracketText = text.substring(r.startColumn - 1, r.endColumn - 1).toLowerCase(); const isOpen = this._richEditBrackets.textIsOpenBracket[bracketText]; if (isOpen) { return null; } const textBeforeBracket = context.getActualLineContentBefore(r.startColumn - 1); if (!/^\s*$/.test(textBeforeBracket)) { // There is other text on the line before the bracket return null; } return { matchOpenBracket: bracketText }; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function resetGlobalRegex(reg) { if (reg.global) { reg.lastIndex = 0; } return true; } class IndentRulesSupport { constructor(indentationRules) { this._indentationRules = indentationRules; } shouldIncrease(text) { if (this._indentationRules) { if (this._indentationRules.increaseIndentPattern && resetGlobalRegex(this._indentationRules.increaseIndentPattern) && this._indentationRules.increaseIndentPattern.test(text)) { return true; } // if (this._indentationRules.indentNextLinePattern && this._indentationRules.indentNextLinePattern.test(text)) { // return true; // } } return false; } shouldDecrease(text) { if (this._indentationRules && this._indentationRules.decreaseIndentPattern && resetGlobalRegex(this._indentationRules.decreaseIndentPattern) && this._indentationRules.decreaseIndentPattern.test(text)) { return true; } return false; } shouldIndentNextLine(text) { if (this._indentationRules && this._indentationRules.indentNextLinePattern && resetGlobalRegex(this._indentationRules.indentNextLinePattern) && this._indentationRules.indentNextLinePattern.test(text)) { return true; } return false; } shouldIgnore(text) { // the text matches `unIndentedLinePattern` if (this._indentationRules && this._indentationRules.unIndentedLinePattern && resetGlobalRegex(this._indentationRules.unIndentedLinePattern) && this._indentationRules.unIndentedLinePattern.test(text)) { return true; } return false; } getIndentMetadata(text) { let ret = 0; if (this.shouldIncrease(text)) { ret += 1 /* INCREASE_MASK */; } if (this.shouldDecrease(text)) { ret += 2 /* DECREASE_MASK */; } if (this.shouldIndentNextLine(text)) { ret += 4 /* INDENT_NEXTLINE_MASK */; } if (this.shouldIgnore(text)) { ret += 8 /* UNINDENT_MASK */; } return ret; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class OnEnterSupport { constructor(opts) { opts = opts || {}; opts.brackets = opts.brackets || [ ['(', ')'], ['{', '}'], ['[', ']'] ]; this._brackets = []; opts.brackets.forEach((bracket) => { const openRegExp = OnEnterSupport._createOpenBracketRegExp(bracket[0]); const closeRegExp = OnEnterSupport._createCloseBracketRegExp(bracket[1]); if (openRegExp && closeRegExp) { this._brackets.push({ open: bracket[0], openRegExp: openRegExp, close: bracket[1], closeRegExp: closeRegExp, }); } }); this._regExpRules = opts.onEnterRules || []; } onEnter(autoIndent, previousLineText, beforeEnterText, afterEnterText) { // (1): `regExpRules` if (autoIndent >= 3 /* Advanced */) { for (let i = 0, len = this._regExpRules.length; i < len; i++) { const rule = this._regExpRules[i]; const regResult = [{ reg: rule.beforeText, text: beforeEnterText }, { reg: rule.afterText, text: afterEnterText }, { reg: rule.previousLineText, text: previousLineText }].every((obj) => { if (!obj.reg) { return true; } obj.reg.lastIndex = 0; // To disable the effect of the "g" flag. return obj.reg.test(obj.text); }); if (regResult) { return rule.action; } } } // (2): Special indent-outdent if (autoIndent >= 2 /* Brackets */) { if (beforeEnterText.length > 0 && afterEnterText.length > 0) { for (let i = 0, len = this._brackets.length; i < len; i++) { const bracket = this._brackets[i]; if (bracket.openRegExp.test(beforeEnterText) && bracket.closeRegExp.test(afterEnterText)) { return { indentAction: IndentAction.IndentOutdent }; } } } } // (4): Open bracket based logic if (autoIndent >= 2 /* Brackets */) { if (beforeEnterText.length > 0) { for (let i = 0, len = this._brackets.length; i < len; i++) { const bracket = this._brackets[i]; if (bracket.openRegExp.test(beforeEnterText)) { return { indentAction: IndentAction.Indent }; } } } } return null; } static _createOpenBracketRegExp(bracket) { let str = escapeRegExpCharacters(bracket); if (!/\B/.test(str.charAt(0))) { str = '\\b' + str; } str += '\\s*$'; return OnEnterSupport._safeRegExp(str); } static _createCloseBracketRegExp(bracket) { let str = escapeRegExpCharacters(bracket); if (!/\B/.test(str.charAt(str.length - 1))) { str = str + '\\b'; } str = '^\\s*' + str; return OnEnterSupport._safeRegExp(str); } static _safeRegExp(def) { try { return new RegExp(def); } catch (err) { onUnexpectedError(err); return null; } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const IConfigurationService = createDecorator('configurationService'); function toValuesTree(properties, conflictReporter) { const root = Object.create(null); for (let key in properties) { addToValueTree(root, key, properties[key], conflictReporter); } return root; } function addToValueTree(settingsTreeRoot, key, value, conflictReporter) { const segments = key.split('.'); const last = segments.pop(); let curr = settingsTreeRoot; for (let i = 0; i < segments.length; i++) { let s = segments[i]; let obj = curr[s]; switch (typeof obj) { case 'undefined': obj = curr[s] = Object.create(null); break; case 'object': break; default: conflictReporter(`Ignoring ${key} as ${segments.slice(0, i + 1).join('.')} is ${JSON.stringify(obj)}`); return; } curr = obj; } if (typeof curr === 'object' && curr !== null) { try { curr[last] = value; // workaround https://github.com/microsoft/vscode/issues/13606 } catch (e) { conflictReporter(`Ignoring ${key} as ${segments.join('.')} is ${JSON.stringify(curr)}`); } } else { conflictReporter(`Ignoring ${key} as ${segments.join('.')} is ${JSON.stringify(curr)}`); } } function removeFromValueTree(valueTree, key) { const segments = key.split('.'); doRemoveFromValueTree(valueTree, segments); } function doRemoveFromValueTree(valueTree, segments) { const first = segments.shift(); if (segments.length === 0) { // Reached last segment delete valueTree[first]; return; } if (Object.keys(valueTree).indexOf(first) !== -1) { const value = valueTree[first]; if (typeof value === 'object' && !Array.isArray(value)) { doRemoveFromValueTree(value, segments); if (Object.keys(value).length === 0) { delete valueTree[first]; } } } } /** * A helper function to get the configuration value with a specific settings path (e.g. config.some.setting) */ function getConfigurationValue(config, settingPath, defaultValue) { function accessSetting(config, path) { let current = config; for (const component of path) { if (typeof current !== 'object' || current === null) { return undefined; } current = current[component]; } return current; } const path = settingPath.split('.'); const result = accessSetting(config, path); return typeof result === 'undefined' ? defaultValue : result; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const ILanguageService = createDecorator('languageService'); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class SyncDescriptor { constructor(ctor, staticArguments = [], supportsDelayedInstantiation = false) { this.ctor = ctor; this.staticArguments = staticArguments; this.supportsDelayedInstantiation = supportsDelayedInstantiation; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const _registry = []; function registerSingleton(id, ctorOrDescriptor, supportsDelayedInstantiation) { if (!(ctorOrDescriptor instanceof SyncDescriptor)) { ctorOrDescriptor = new SyncDescriptor(ctorOrDescriptor, [], supportsDelayedInstantiation); } _registry.push([id, ctorOrDescriptor]); } function getSingletonServiceDescriptors() { return _registry; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate$1G = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param$1A = (undefined && undefined.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; class LanguageConfigurationServiceChangeEvent { constructor(languageId) { this.languageId = languageId; } affects(languageId) { return !this.languageId ? true : this.languageId === languageId; } } const ILanguageConfigurationService = createDecorator('languageConfigurationService'); let LanguageConfigurationService = class LanguageConfigurationService extends Disposable { constructor(configurationService, languageService) { super(); this.configurationService = configurationService; this.languageService = languageService; this.onDidChangeEmitter = this._register(new Emitter$1()); this.onDidChange = this.onDidChangeEmitter.event; this.configurations = new Map(); const languageConfigKeys = new Set(Object.values(customizedLanguageConfigKeys)); this._register(this.configurationService.onDidChangeConfiguration((e) => { const globalConfigChanged = e.change.keys.some((k) => languageConfigKeys.has(k)); const localConfigChanged = e.change.overrides .filter(([overrideLangName, keys]) => keys.some((k) => languageConfigKeys.has(k))) .map(([overrideLangName]) => overrideLangName); if (globalConfigChanged) { this.configurations.clear(); this.onDidChangeEmitter.fire(new LanguageConfigurationServiceChangeEvent(undefined)); } else { for (const languageId of localConfigChanged) { if (this.languageService.isRegisteredLanguageId(languageId)) { this.configurations.delete(languageId); this.onDidChangeEmitter.fire(new LanguageConfigurationServiceChangeEvent(languageId)); } } } })); this._register(LanguageConfigurationRegistry.onDidChange((e) => { this.configurations.delete(e.languageId); this.onDidChangeEmitter.fire(new LanguageConfigurationServiceChangeEvent(e.languageId)); })); } getLanguageConfiguration(languageId) { let result = this.configurations.get(languageId); if (!result) { result = computeConfig(languageId, this.configurationService, this.languageService); this.configurations.set(languageId, result); } return result; } }; LanguageConfigurationService = __decorate$1G([ __param$1A(0, IConfigurationService), __param$1A(1, ILanguageService) ], LanguageConfigurationService); function computeConfig(languageId, configurationService, languageService) { let languageConfig = LanguageConfigurationRegistry.getLanguageConfiguration(languageId); if (!languageConfig) { if (!languageService.isRegisteredLanguageId(languageId)) { throw new Error('Unexpected languageId'); } languageConfig = new ResolvedLanguageConfiguration(languageId, {}); } const customizedConfig = getCustomizedLanguageConfig(languageConfig.languageId, configurationService); const data = combineLanguageConfigurations([languageConfig.underlyingConfig, customizedConfig]); const config = new ResolvedLanguageConfiguration(languageConfig.languageId, data); return config; } const customizedLanguageConfigKeys = { brackets: 'editor.language.brackets', colorizedBracketPairs: 'editor.language.colorizedBracketPairs' }; function getCustomizedLanguageConfig(languageId, configurationService) { const brackets = configurationService.getValue(customizedLanguageConfigKeys.brackets, { overrideIdentifier: languageId, }); const colorizedBracketPairs = configurationService.getValue(customizedLanguageConfigKeys.colorizedBracketPairs, { overrideIdentifier: languageId, }); return { brackets: validateBracketPairs(brackets), colorizedBracketPairs: validateBracketPairs(colorizedBracketPairs), }; } function validateBracketPairs(data) { if (!Array.isArray(data)) { return undefined; } return data.map(pair => { if (!Array.isArray(pair) || pair.length !== 2) { return undefined; } return [pair[0], pair[1]]; }).filter((p) => !!p); } class LanguageConfigurationChangeEvent { constructor(languageId) { this.languageId = languageId; } } class LanguageConfigurationRegistryImpl { constructor() { this._entries = new Map(); this._onDidChange = new Emitter$1(); this.onDidChange = this._onDidChange.event; } /** * @param priority Use a higher number for higher priority */ register(languageId, configuration, priority = 0) { let entries = this._entries.get(languageId); if (!entries) { entries = new ComposedLanguageConfiguration(languageId); this._entries.set(languageId, entries); } const disposable = entries.register(configuration, priority); this._onDidChange.fire(new LanguageConfigurationChangeEvent(languageId)); return toDisposable(() => { disposable.dispose(); this._onDidChange.fire(new LanguageConfigurationChangeEvent(languageId)); }); } getLanguageConfiguration(languageId) { const entries = this._entries.get(languageId); return (entries === null || entries === void 0 ? void 0 : entries.getResolvedConfiguration()) || null; } getComments(languageId) { const value = this.getLanguageConfiguration(languageId); if (!value) { return null; } return value.comments || null; } // begin Indent Rules getIndentRulesSupport(languageId) { const value = this.getLanguageConfiguration(languageId); if (!value) { return null; } return value.indentRulesSupport || null; } /** * Get nearest preceding line which doesn't match unIndentPattern or contains all whitespace. * Result: * -1: run into the boundary of embedded languages * 0: every line above are invalid * else: nearest preceding line of the same language */ getPrecedingValidLine(model, lineNumber, indentRulesSupport) { const languageId = model.getLanguageIdAtPosition(lineNumber, 0); if (lineNumber > 1) { let lastLineNumber; let resultLineNumber = -1; for (lastLineNumber = lineNumber - 1; lastLineNumber >= 1; lastLineNumber--) { if (model.getLanguageIdAtPosition(lastLineNumber, 0) !== languageId) { return resultLineNumber; } const text = model.getLineContent(lastLineNumber); if (indentRulesSupport.shouldIgnore(text) || /^\s+$/.test(text) || text === '') { resultLineNumber = lastLineNumber; continue; } return lastLineNumber; } } return -1; } /** * Get inherited indentation from above lines. * 1. Find the nearest preceding line which doesn't match unIndentedLinePattern. * 2. If this line matches indentNextLinePattern or increaseIndentPattern, it means that the indent level of `lineNumber` should be 1 greater than this line. * 3. If this line doesn't match any indent rules * a. check whether the line above it matches indentNextLinePattern * b. If not, the indent level of this line is the result * c. If so, it means the indent of this line is *temporary*, go upward utill we find a line whose indent is not temporary (the same workflow a -> b -> c). * 4. Otherwise, we fail to get an inherited indent from aboves. Return null and we should not touch the indent of `lineNumber` * * This function only return the inherited indent based on above lines, it doesn't check whether current line should decrease or not. */ getInheritIndentForLine(autoIndent, model, lineNumber, honorIntentialIndent = true) { if (autoIndent < 4 /* Full */) { return null; } const indentRulesSupport = this.getIndentRulesSupport(model.getLanguageId()); if (!indentRulesSupport) { return null; } if (lineNumber <= 1) { return { indentation: '', action: null }; } const precedingUnIgnoredLine = this.getPrecedingValidLine(model, lineNumber, indentRulesSupport); if (precedingUnIgnoredLine < 0) { return null; } else if (precedingUnIgnoredLine < 1) { return { indentation: '', action: null }; } const precedingUnIgnoredLineContent = model.getLineContent(precedingUnIgnoredLine); if (indentRulesSupport.shouldIncrease(precedingUnIgnoredLineContent) || indentRulesSupport.shouldIndentNextLine(precedingUnIgnoredLineContent)) { return { indentation: getLeadingWhitespace(precedingUnIgnoredLineContent), action: IndentAction.Indent, line: precedingUnIgnoredLine }; } else if (indentRulesSupport.shouldDecrease(precedingUnIgnoredLineContent)) { return { indentation: getLeadingWhitespace(precedingUnIgnoredLineContent), action: null, line: precedingUnIgnoredLine }; } else { // precedingUnIgnoredLine can not be ignored. // it doesn't increase indent of following lines // it doesn't increase just next line // so current line is not affect by precedingUnIgnoredLine // and then we should get a correct inheritted indentation from above lines if (precedingUnIgnoredLine === 1) { return { indentation: getLeadingWhitespace(model.getLineContent(precedingUnIgnoredLine)), action: null, line: precedingUnIgnoredLine }; } const previousLine = precedingUnIgnoredLine - 1; const previousLineIndentMetadata = indentRulesSupport.getIndentMetadata(model.getLineContent(previousLine)); if (!(previousLineIndentMetadata & (1 /* INCREASE_MASK */ | 2 /* DECREASE_MASK */)) && (previousLineIndentMetadata & 4 /* INDENT_NEXTLINE_MASK */)) { let stopLine = 0; for (let i = previousLine - 1; i > 0; i--) { if (indentRulesSupport.shouldIndentNextLine(model.getLineContent(i))) { continue; } stopLine = i; break; } return { indentation: getLeadingWhitespace(model.getLineContent(stopLine + 1)), action: null, line: stopLine + 1 }; } if (honorIntentialIndent) { return { indentation: getLeadingWhitespace(model.getLineContent(precedingUnIgnoredLine)), action: null, line: precedingUnIgnoredLine }; } else { // search from precedingUnIgnoredLine until we find one whose indent is not temporary for (let i = precedingUnIgnoredLine; i > 0; i--) { const lineContent = model.getLineContent(i); if (indentRulesSupport.shouldIncrease(lineContent)) { return { indentation: getLeadingWhitespace(lineContent), action: IndentAction.Indent, line: i }; } else if (indentRulesSupport.shouldIndentNextLine(lineContent)) { let stopLine = 0; for (let j = i - 1; j > 0; j--) { if (indentRulesSupport.shouldIndentNextLine(model.getLineContent(i))) { continue; } stopLine = j; break; } return { indentation: getLeadingWhitespace(model.getLineContent(stopLine + 1)), action: null, line: stopLine + 1 }; } else if (indentRulesSupport.shouldDecrease(lineContent)) { return { indentation: getLeadingWhitespace(lineContent), action: null, line: i }; } } return { indentation: getLeadingWhitespace(model.getLineContent(1)), action: null, line: 1 }; } } } getGoodIndentForLine(autoIndent, virtualModel, languageId, lineNumber, indentConverter) { if (autoIndent < 4 /* Full */) { return null; } const richEditSupport = this.getLanguageConfiguration(languageId); if (!richEditSupport) { return null; } const indentRulesSupport = this.getIndentRulesSupport(languageId); if (!indentRulesSupport) { return null; } const indent = this.getInheritIndentForLine(autoIndent, virtualModel, lineNumber); const lineContent = virtualModel.getLineContent(lineNumber); if (indent) { const inheritLine = indent.line; if (inheritLine !== undefined) { const enterResult = richEditSupport.onEnter(autoIndent, '', virtualModel.getLineContent(inheritLine), ''); if (enterResult) { let indentation = getLeadingWhitespace(virtualModel.getLineContent(inheritLine)); if (enterResult.removeText) { indentation = indentation.substring(0, indentation.length - enterResult.removeText); } if ((enterResult.indentAction === IndentAction.Indent) || (enterResult.indentAction === IndentAction.IndentOutdent)) { indentation = indentConverter.shiftIndent(indentation); } else if (enterResult.indentAction === IndentAction.Outdent) { indentation = indentConverter.unshiftIndent(indentation); } if (indentRulesSupport.shouldDecrease(lineContent)) { indentation = indentConverter.unshiftIndent(indentation); } if (enterResult.appendText) { indentation += enterResult.appendText; } return getLeadingWhitespace(indentation); } } if (indentRulesSupport.shouldDecrease(lineContent)) { if (indent.action === IndentAction.Indent) { return indent.indentation; } else { return indentConverter.unshiftIndent(indent.indentation); } } else { if (indent.action === IndentAction.Indent) { return indentConverter.shiftIndent(indent.indentation); } else { return indent.indentation; } } } return null; } getIndentForEnter(autoIndent, model, range, indentConverter) { if (autoIndent < 4 /* Full */) { return null; } model.forceTokenization(range.startLineNumber); const lineTokens = model.getLineTokens(range.startLineNumber); const scopedLineTokens = createScopedLineTokens(lineTokens, range.startColumn - 1); const scopedLineText = scopedLineTokens.getLineContent(); let embeddedLanguage = false; let beforeEnterText; if (scopedLineTokens.firstCharOffset > 0 && lineTokens.getLanguageId(0) !== scopedLineTokens.languageId) { // we are in the embeded language content embeddedLanguage = true; // if embeddedLanguage is true, then we don't touch the indentation of current line beforeEnterText = scopedLineText.substr(0, range.startColumn - 1 - scopedLineTokens.firstCharOffset); } else { beforeEnterText = lineTokens.getLineContent().substring(0, range.startColumn - 1); } let afterEnterText; if (range.isEmpty()) { afterEnterText = scopedLineText.substr(range.startColumn - 1 - scopedLineTokens.firstCharOffset); } else { const endScopedLineTokens = this.getScopedLineTokens(model, range.endLineNumber, range.endColumn); afterEnterText = endScopedLineTokens.getLineContent().substr(range.endColumn - 1 - scopedLineTokens.firstCharOffset); } const indentRulesSupport = this.getIndentRulesSupport(scopedLineTokens.languageId); if (!indentRulesSupport) { return null; } const beforeEnterResult = beforeEnterText; const beforeEnterIndent = getLeadingWhitespace(beforeEnterText); const virtualModel = { getLineTokens: (lineNumber) => { return model.getLineTokens(lineNumber); }, getLanguageId: () => { return model.getLanguageId(); }, getLanguageIdAtPosition: (lineNumber, column) => { return model.getLanguageIdAtPosition(lineNumber, column); }, getLineContent: (lineNumber) => { if (lineNumber === range.startLineNumber) { return beforeEnterResult; } else { return model.getLineContent(lineNumber); } } }; const currentLineIndent = getLeadingWhitespace(lineTokens.getLineContent()); const afterEnterAction = this.getInheritIndentForLine(autoIndent, virtualModel, range.startLineNumber + 1); if (!afterEnterAction) { const beforeEnter = embeddedLanguage ? currentLineIndent : beforeEnterIndent; return { beforeEnter: beforeEnter, afterEnter: beforeEnter }; } let afterEnterIndent = embeddedLanguage ? currentLineIndent : afterEnterAction.indentation; if (afterEnterAction.action === IndentAction.Indent) { afterEnterIndent = indentConverter.shiftIndent(afterEnterIndent); } if (indentRulesSupport.shouldDecrease(afterEnterText)) { afterEnterIndent = indentConverter.unshiftIndent(afterEnterIndent); } return { beforeEnter: embeddedLanguage ? currentLineIndent : beforeEnterIndent, afterEnter: afterEnterIndent }; } /** * We should always allow intentional indentation. It means, if users change the indentation of `lineNumber` and the content of * this line doesn't match decreaseIndentPattern, we should not adjust the indentation. */ getIndentActionForType(autoIndent, model, range, ch, indentConverter) { if (autoIndent < 4 /* Full */) { return null; } const scopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber, range.startColumn); if (scopedLineTokens.firstCharOffset) { // this line has mixed languages and indentation rules will not work return null; } const indentRulesSupport = this.getIndentRulesSupport(scopedLineTokens.languageId); if (!indentRulesSupport) { return null; } const scopedLineText = scopedLineTokens.getLineContent(); const beforeTypeText = scopedLineText.substr(0, range.startColumn - 1 - scopedLineTokens.firstCharOffset); // selection support let afterTypeText; if (range.isEmpty()) { afterTypeText = scopedLineText.substr(range.startColumn - 1 - scopedLineTokens.firstCharOffset); } else { const endScopedLineTokens = this.getScopedLineTokens(model, range.endLineNumber, range.endColumn); afterTypeText = endScopedLineTokens.getLineContent().substr(range.endColumn - 1 - scopedLineTokens.firstCharOffset); } // If previous content already matches decreaseIndentPattern, it means indentation of this line should already be adjusted // Users might change the indentation by purpose and we should honor that instead of readjusting. if (!indentRulesSupport.shouldDecrease(beforeTypeText + afterTypeText) && indentRulesSupport.shouldDecrease(beforeTypeText + ch + afterTypeText)) { // after typing `ch`, the content matches decreaseIndentPattern, we should adjust the indent to a good manner. // 1. Get inherited indent action const r = this.getInheritIndentForLine(autoIndent, model, range.startLineNumber, false); if (!r) { return null; } let indentation = r.indentation; if (r.action !== IndentAction.Indent) { indentation = indentConverter.unshiftIndent(indentation); } return indentation; } return null; } getIndentMetadata(model, lineNumber) { const indentRulesSupport = this.getIndentRulesSupport(model.getLanguageId()); if (!indentRulesSupport) { return null; } if (lineNumber < 1 || lineNumber > model.getLineCount()) { return null; } return indentRulesSupport.getIndentMetadata(model.getLineContent(lineNumber)); } // end Indent Rules // begin onEnter getEnterAction(autoIndent, model, range) { const scopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber, range.startColumn); const richEditSupport = this.getLanguageConfiguration(scopedLineTokens.languageId); if (!richEditSupport) { return null; } const scopedLineText = scopedLineTokens.getLineContent(); const beforeEnterText = scopedLineText.substr(0, range.startColumn - 1 - scopedLineTokens.firstCharOffset); // selection support let afterEnterText; if (range.isEmpty()) { afterEnterText = scopedLineText.substr(range.startColumn - 1 - scopedLineTokens.firstCharOffset); } else { const endScopedLineTokens = this.getScopedLineTokens(model, range.endLineNumber, range.endColumn); afterEnterText = endScopedLineTokens.getLineContent().substr(range.endColumn - 1 - scopedLineTokens.firstCharOffset); } let previousLineText = ''; if (range.startLineNumber > 1 && scopedLineTokens.firstCharOffset === 0) { // This is not the first line and the entire line belongs to this mode const oneLineAboveScopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber - 1); if (oneLineAboveScopedLineTokens.languageId === scopedLineTokens.languageId) { // The line above ends with text belonging to the same mode previousLineText = oneLineAboveScopedLineTokens.getLineContent(); } } const enterResult = richEditSupport.onEnter(autoIndent, previousLineText, beforeEnterText, afterEnterText); if (!enterResult) { return null; } const indentAction = enterResult.indentAction; let appendText = enterResult.appendText; const removeText = enterResult.removeText || 0; // Here we add `\t` to appendText first because enterAction is leveraging appendText and removeText to change indentation. if (!appendText) { if ((indentAction === IndentAction.Indent) || (indentAction === IndentAction.IndentOutdent)) { appendText = '\t'; } else { appendText = ''; } } else if (indentAction === IndentAction.Indent) { appendText = '\t' + appendText; } let indentation = this.getIndentationAtPosition(model, range.startLineNumber, range.startColumn); if (removeText) { indentation = indentation.substring(0, indentation.length - removeText); } return { indentAction: indentAction, appendText: appendText, removeText: removeText, indentation: indentation }; } getIndentationAtPosition(model, lineNumber, column) { const lineText = model.getLineContent(lineNumber); let indentation = getLeadingWhitespace(lineText); if (indentation.length > column - 1) { indentation = indentation.substring(0, column - 1); } return indentation; } getScopedLineTokens(model, lineNumber, columnNumber) { model.forceTokenization(lineNumber); const lineTokens = model.getLineTokens(lineNumber); const column = (typeof columnNumber === 'undefined' ? model.getLineMaxColumn(lineNumber) - 1 : columnNumber - 1); return createScopedLineTokens(lineTokens, column); } } /** * @deprecated Use ILanguageConfigurationService instead. */ const LanguageConfigurationRegistry = new LanguageConfigurationRegistryImpl(); class ComposedLanguageConfiguration { constructor(languageId) { this.languageId = languageId; this._resolved = null; this._entries = []; this._order = 0; this._resolved = null; } register(configuration, priority) { const entry = new LanguageConfigurationContribution(configuration, priority, ++this._order); this._entries.push(entry); this._resolved = null; return toDisposable(() => { for (let i = 0; i < this._entries.length; i++) { if (this._entries[i] === entry) { this._entries.splice(i, 1); this._resolved = null; break; } } }); } getResolvedConfiguration() { if (!this._resolved) { const config = this._resolve(); if (config) { this._resolved = new ResolvedLanguageConfiguration(this.languageId, config); } } return this._resolved; } _resolve() { if (this._entries.length === 0) { return null; } this._entries.sort(LanguageConfigurationContribution.cmp); return combineLanguageConfigurations(this._entries.map(e => e.configuration)); } } function combineLanguageConfigurations(configs) { let result = { comments: undefined, brackets: undefined, wordPattern: undefined, indentationRules: undefined, onEnterRules: undefined, autoClosingPairs: undefined, surroundingPairs: undefined, autoCloseBefore: undefined, folding: undefined, colorizedBracketPairs: undefined, __electricCharacterSupport: undefined, }; for (const entry of configs) { result = { comments: entry.comments || result.comments, brackets: entry.brackets || result.brackets, wordPattern: entry.wordPattern || result.wordPattern, indentationRules: entry.indentationRules || result.indentationRules, onEnterRules: entry.onEnterRules || result.onEnterRules, autoClosingPairs: entry.autoClosingPairs || result.autoClosingPairs, surroundingPairs: entry.surroundingPairs || result.surroundingPairs, autoCloseBefore: entry.autoCloseBefore || result.autoCloseBefore, folding: entry.folding || result.folding, colorizedBracketPairs: entry.colorizedBracketPairs || result.colorizedBracketPairs, __electricCharacterSupport: entry.__electricCharacterSupport || result.__electricCharacterSupport, }; } return result; } class LanguageConfigurationContribution { constructor(configuration, priority, order) { this.configuration = configuration; this.priority = priority; this.order = order; } static cmp(a, b) { if (a.priority === b.priority) { // higher order last return a.order - b.order; } // higher priority last return a.priority - b.priority; } } /** * Immutable. */ class ResolvedLanguageConfiguration { constructor(languageId, underlyingConfig) { this.languageId = languageId; this.underlyingConfig = underlyingConfig; this._brackets = null; this._electricCharacter = null; this._onEnterSupport = this.underlyingConfig.brackets || this.underlyingConfig.indentationRules || this.underlyingConfig.onEnterRules ? new OnEnterSupport(this.underlyingConfig) : null; this.comments = ResolvedLanguageConfiguration._handleComments(this.underlyingConfig); this.characterPair = new CharacterPairSupport(this.underlyingConfig); this.wordDefinition = this.underlyingConfig.wordPattern || DEFAULT_WORD_REGEXP; this.indentationRules = this.underlyingConfig.indentationRules; if (this.underlyingConfig.indentationRules) { this.indentRulesSupport = new IndentRulesSupport(this.underlyingConfig.indentationRules); } else { this.indentRulesSupport = null; } this.foldingRules = this.underlyingConfig.folding || {}; } getWordDefinition() { return ensureValidWordDefinition(this.wordDefinition); } get brackets() { if (!this._brackets && this.underlyingConfig.brackets) { this._brackets = new RichEditBrackets(this.languageId, this.underlyingConfig.brackets); } return this._brackets; } get electricCharacter() { if (!this._electricCharacter) { this._electricCharacter = new BracketElectricCharacterSupport(this.brackets); } return this._electricCharacter; } onEnter(autoIndent, previousLineText, beforeEnterText, afterEnterText) { if (!this._onEnterSupport) { return null; } return this._onEnterSupport.onEnter(autoIndent, previousLineText, beforeEnterText, afterEnterText); } getAutoClosingPairs() { return new AutoClosingPairs(this.characterPair.getAutoClosingPairs()); } getAutoCloseBeforeSet() { return this.characterPair.getAutoCloseBeforeSet(); } getSurroundingPairs() { return this.characterPair.getSurroundingPairs(); } static _handleComments(conf) { const commentRule = conf.comments; if (!commentRule) { return null; } // comment configuration const comments = {}; if (commentRule.lineComment) { comments.lineCommentToken = commentRule.lineComment; } if (commentRule.blockComment) { const [blockStart, blockEnd] = commentRule.blockComment; comments.blockCommentStartToken = blockStart; comments.blockCommentEndToken = blockEnd; } return comments; } } registerSingleton(ILanguageConfigurationService, LanguageConfigurationService); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const NullState = new class { clone() { return this; } equals(other) { return (this === other); } }; function nullTokenize(languageId, state) { return new TokenizationResult([new Token$2(0, '', languageId)], state); } function nullTokenizeEncoded(languageId, state) { const tokens = new Uint32Array(2); tokens[0] = 0; tokens[1] = ((languageId << 0 /* LANGUAGEID_OFFSET */) | (0 /* Other */ << 8 /* TOKEN_TYPE_OFFSET */) | (0 /* None */ << 10 /* FONT_STYLE_OFFSET */) | (1 /* DefaultForeground */ << 14 /* FOREGROUND_OFFSET */) | (2 /* DefaultBackground */ << 23 /* BACKGROUND_OFFSET */)) >>> 0; return new EncodedTokenizationResult(tokens, state === null ? NullState : state); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const IModelService = createDecorator('modelService'); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const INITIALIZE = '$initialize'; let webWorkerWarningLogged = false; function logOnceWebWorkerWarning(err) { if (!isWeb) { // running tests return; } if (!webWorkerWarningLogged) { webWorkerWarningLogged = true; console.warn('Could not create web worker(s). Falling back to loading web worker code in main thread, which might cause UI freezes. Please see https://github.com/microsoft/monaco-editor#faq'); } console.warn(err.message); } class RequestMessage { constructor(vsWorker, req, method, args) { this.vsWorker = vsWorker; this.req = req; this.method = method; this.args = args; this.type = 0 /* Request */; } } class ReplyMessage { constructor(vsWorker, seq, res, err) { this.vsWorker = vsWorker; this.seq = seq; this.res = res; this.err = err; this.type = 1 /* Reply */; } } class SubscribeEventMessage { constructor(vsWorker, req, eventName, arg) { this.vsWorker = vsWorker; this.req = req; this.eventName = eventName; this.arg = arg; this.type = 2 /* SubscribeEvent */; } } class EventMessage { constructor(vsWorker, req, event) { this.vsWorker = vsWorker; this.req = req; this.event = event; this.type = 3 /* Event */; } } class UnsubscribeEventMessage { constructor(vsWorker, req) { this.vsWorker = vsWorker; this.req = req; this.type = 4 /* UnsubscribeEvent */; } } class SimpleWorkerProtocol { constructor(handler) { this._workerId = -1; this._handler = handler; this._lastSentReq = 0; this._pendingReplies = Object.create(null); this._pendingEmitters = new Map(); this._pendingEvents = new Map(); } setWorkerId(workerId) { this._workerId = workerId; } sendMessage(method, args) { const req = String(++this._lastSentReq); return new Promise((resolve, reject) => { this._pendingReplies[req] = { resolve: resolve, reject: reject }; this._send(new RequestMessage(this._workerId, req, method, args)); }); } listen(eventName, arg) { let req = null; const emitter = new Emitter$1({ onFirstListenerAdd: () => { req = String(++this._lastSentReq); this._pendingEmitters.set(req, emitter); this._send(new SubscribeEventMessage(this._workerId, req, eventName, arg)); }, onLastListenerRemove: () => { this._pendingEmitters.delete(req); this._send(new UnsubscribeEventMessage(this._workerId, req)); req = null; } }); return emitter.event; } handleMessage(message) { if (!message || !message.vsWorker) { return; } if (this._workerId !== -1 && message.vsWorker !== this._workerId) { return; } this._handleMessage(message); } _handleMessage(msg) { switch (msg.type) { case 1 /* Reply */: return this._handleReplyMessage(msg); case 0 /* Request */: return this._handleRequestMessage(msg); case 2 /* SubscribeEvent */: return this._handleSubscribeEventMessage(msg); case 3 /* Event */: return this._handleEventMessage(msg); case 4 /* UnsubscribeEvent */: return this._handleUnsubscribeEventMessage(msg); } } _handleReplyMessage(replyMessage) { if (!this._pendingReplies[replyMessage.seq]) { console.warn('Got reply to unknown seq'); return; } let reply = this._pendingReplies[replyMessage.seq]; delete this._pendingReplies[replyMessage.seq]; if (replyMessage.err) { let err = replyMessage.err; if (replyMessage.err.$isError) { err = new Error(); err.name = replyMessage.err.name; err.message = replyMessage.err.message; err.stack = replyMessage.err.stack; } reply.reject(err); return; } reply.resolve(replyMessage.res); } _handleRequestMessage(requestMessage) { let req = requestMessage.req; let result = this._handler.handleMessage(requestMessage.method, requestMessage.args); result.then((r) => { this._send(new ReplyMessage(this._workerId, req, r, undefined)); }, (e) => { if (e.detail instanceof Error) { // Loading errors have a detail property that points to the actual error e.detail = transformErrorForSerialization(e.detail); } this._send(new ReplyMessage(this._workerId, req, undefined, transformErrorForSerialization(e))); }); } _handleSubscribeEventMessage(msg) { const req = msg.req; const disposable = this._handler.handleEvent(msg.eventName, msg.arg)((event) => { this._send(new EventMessage(this._workerId, req, event)); }); this._pendingEvents.set(req, disposable); } _handleEventMessage(msg) { if (!this._pendingEmitters.has(msg.req)) { console.warn('Got event for unknown req'); return; } this._pendingEmitters.get(msg.req).fire(msg.event); } _handleUnsubscribeEventMessage(msg) { if (!this._pendingEvents.has(msg.req)) { console.warn('Got unsubscribe for unknown req'); return; } this._pendingEvents.get(msg.req).dispose(); this._pendingEvents.delete(msg.req); } _send(msg) { let transfer = []; if (msg.type === 0 /* Request */) { for (let i = 0; i < msg.args.length; i++) { if (msg.args[i] instanceof ArrayBuffer) { transfer.push(msg.args[i]); } } } else if (msg.type === 1 /* Reply */) { if (msg.res instanceof ArrayBuffer) { transfer.push(msg.res); } } this._handler.sendMessage(msg, transfer); } } /** * Main thread side */ class SimpleWorkerClient extends Disposable { constructor(workerFactory, moduleId, host) { super(); let lazyProxyReject = null; this._worker = this._register(workerFactory.create('vs/base/common/worker/simpleWorker', (msg) => { this._protocol.handleMessage(msg); }, (err) => { // in Firefox, web workers fail lazily :( // we will reject the proxy if (lazyProxyReject) { lazyProxyReject(err); } })); this._protocol = new SimpleWorkerProtocol({ sendMessage: (msg, transfer) => { this._worker.postMessage(msg, transfer); }, handleMessage: (method, args) => { if (typeof host[method] !== 'function') { return Promise.reject(new Error('Missing method ' + method + ' on main thread host.')); } try { return Promise.resolve(host[method].apply(host, args)); } catch (e) { return Promise.reject(e); } }, handleEvent: (eventName, arg) => { if (propertyIsDynamicEvent(eventName)) { const event = host[eventName].call(host, arg); if (typeof event !== 'function') { throw new Error(`Missing dynamic event ${eventName} on main thread host.`); } return event; } if (propertyIsEvent(eventName)) { const event = host[eventName]; if (typeof event !== 'function') { throw new Error(`Missing event ${eventName} on main thread host.`); } return event; } throw new Error(`Malformed event name ${eventName}`); } }); this._protocol.setWorkerId(this._worker.getId()); // Gather loader configuration let loaderConfiguration = null; if (typeof globals.require !== 'undefined' && typeof globals.require.getConfig === 'function') { // Get the configuration from the Monaco AMD Loader loaderConfiguration = globals.require.getConfig(); } else if (typeof globals.requirejs !== 'undefined') { // Get the configuration from requirejs loaderConfiguration = globals.requirejs.s.contexts._.config; } const hostMethods = getAllMethodNames(host); // Send initialize message this._onModuleLoaded = this._protocol.sendMessage(INITIALIZE, [ this._worker.getId(), JSON.parse(JSON.stringify(loaderConfiguration)), moduleId, hostMethods, ]); // Create proxy to loaded code const proxyMethodRequest = (method, args) => { return this._request(method, args); }; const proxyListen = (eventName, arg) => { return this._protocol.listen(eventName, arg); }; this._lazyProxy = new Promise((resolve, reject) => { lazyProxyReject = reject; this._onModuleLoaded.then((availableMethods) => { resolve(createProxyObject(availableMethods, proxyMethodRequest, proxyListen)); }, (e) => { reject(e); this._onError('Worker failed to load ' + moduleId, e); }); }); } getProxyObject() { return this._lazyProxy; } _request(method, args) { return new Promise((resolve, reject) => { this._onModuleLoaded.then(() => { this._protocol.sendMessage(method, args).then(resolve, reject); }, reject); }); } _onError(message, error) { console.error(message); console.info(error); } } function propertyIsEvent(name) { // Assume a property is an event if it has a form of "onSomething" return name[0] === 'o' && name[1] === 'n' && isUpperAsciiLetter(name.charCodeAt(2)); } function propertyIsDynamicEvent(name) { // Assume a property is a dynamic event (a method that returns an event) if it has a form of "onDynamicSomething" return /^onDynamic/.test(name) && isUpperAsciiLetter(name.charCodeAt(9)); } function createProxyObject(methodNames, invoke, proxyListen) { const createProxyMethod = (method) => { return function () { const args = Array.prototype.slice.call(arguments, 0); return invoke(method, args); }; }; const createProxyDynamicEvent = (eventName) => { return function (arg) { return proxyListen(eventName, arg); }; }; let result = {}; for (const methodName of methodNames) { if (propertyIsDynamicEvent(methodName)) { result[methodName] = createProxyDynamicEvent(methodName); continue; } if (propertyIsEvent(methodName)) { result[methodName] = proxyListen(methodName, undefined); continue; } result[methodName] = createProxyMethod(methodName); } return result; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var _a$a; const ttPolicy$4 = (_a$a = window.trustedTypes) === null || _a$a === void 0 ? void 0 : _a$a.createPolicy('defaultWorkerFactory', { createScriptURL: value => value }); function getWorker(label) { // Option for hosts to overwrite the worker script (used in the standalone editor) if (globals.MonacoEnvironment) { if (typeof globals.MonacoEnvironment.getWorker === 'function') { return globals.MonacoEnvironment.getWorker('workerMain.js', label); } if (typeof globals.MonacoEnvironment.getWorkerUrl === 'function') { const workerUrl = globals.MonacoEnvironment.getWorkerUrl('workerMain.js', label); return new Worker(ttPolicy$4 ? ttPolicy$4.createScriptURL(workerUrl) : workerUrl, { name: label }); } } // ESM-comment-begin // if (typeof require === 'function') { // // check if the JS lives on a different origin // const workerMain = require.toUrl('vs/base/worker/workerMain.js'); // explicitly using require.toUrl(), see https://github.com/microsoft/vscode/issues/107440#issuecomment-698982321 // const workerUrl = getWorkerBootstrapUrl(workerMain, label); // return new Worker(ttPolicy ? ttPolicy.createScriptURL(workerUrl) as unknown as string : workerUrl, { name: label }); // } // ESM-comment-end throw new Error(`You must define a function MonacoEnvironment.getWorkerUrl or MonacoEnvironment.getWorker`); } // ESM-comment-begin // export function getWorkerBootstrapUrl(scriptPath: string, label: string): string { // if (/^((http:)|(https:)|(file:))/.test(scriptPath) && scriptPath.substring(0, self.origin.length) !== self.origin) { // // this is the cross-origin case // // i.e. the webpage is running at a different origin than where the scripts are loaded from // const myPath = 'vs/base/worker/defaultWorkerFactory.js'; // const workerBaseUrl = require.toUrl(myPath).slice(0, -myPath.length); // explicitly using require.toUrl(), see https://github.com/microsoft/vscode/issues/107440#issuecomment-698982321 // const js = `/*${label}*/self.MonacoEnvironment={baseUrl: '${workerBaseUrl}'};const ttPolicy = self.trustedTypes?.createPolicy('defaultWorkerFactory', { createScriptURL: value => value });importScripts(ttPolicy?.createScriptURL('${scriptPath}') ?? '${scriptPath}');/*${label}*/`; // const blob = new Blob([js], { type: 'application/javascript' }); // return URL.createObjectURL(blob); // } // return scriptPath + '#' + label; // } // ESM-comment-end function isPromiseLike(obj) { if (typeof obj.then === 'function') { return true; } return false; } /** * A worker that uses HTML5 web workers so that is has * its own global scope and its own thread. */ class WebWorker { constructor(moduleId, id, label, onMessageCallback, onErrorCallback) { this.id = id; const workerOrPromise = getWorker(label); if (isPromiseLike(workerOrPromise)) { this.worker = workerOrPromise; } else { this.worker = Promise.resolve(workerOrPromise); } this.postMessage(moduleId, []); this.worker.then((w) => { w.onmessage = function (ev) { onMessageCallback(ev.data); }; w.onmessageerror = onErrorCallback; if (typeof w.addEventListener === 'function') { w.addEventListener('error', onErrorCallback); } }); } getId() { return this.id; } postMessage(message, transfer) { if (this.worker) { this.worker.then(w => w.postMessage(message, transfer)); } } dispose() { if (this.worker) { this.worker.then(w => w.terminate()); } this.worker = null; } } class DefaultWorkerFactory { constructor(label) { this._label = label; this._webWorkerFailedBeforeError = false; } create(moduleId, onMessageCallback, onErrorCallback) { let workerId = (++DefaultWorkerFactory.LAST_WORKER_ID); if (this._webWorkerFailedBeforeError) { throw this._webWorkerFailedBeforeError; } return new WebWorker(moduleId, workerId, this._label || 'anonymous' + workerId, onMessageCallback, (err) => { logOnceWebWorkerWarning(err); this._webWorkerFailedBeforeError = err; onErrorCallback(err); }); } } DefaultWorkerFactory.LAST_WORKER_ID = 0; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Represents information about a specific difference between two sequences. */ class DiffChange { /** * Constructs a new DiffChange with the given sequence information * and content. */ constructor(originalStart, originalLength, modifiedStart, modifiedLength) { //Debug.Assert(originalLength > 0 || modifiedLength > 0, "originalLength and modifiedLength cannot both be <= 0"); this.originalStart = originalStart; this.originalLength = originalLength; this.modifiedStart = modifiedStart; this.modifiedLength = modifiedLength; } /** * The end point (exclusive) of the change in the original sequence. */ getOriginalEnd() { return this.originalStart + this.originalLength; } /** * The end point (exclusive) of the change in the modified sequence. */ getModifiedEnd() { return this.modifiedStart + this.modifiedLength; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Return a hash value for an object. */ function hash(obj) { return doHash(obj, 0); } function doHash(obj, hashVal) { switch (typeof obj) { case 'object': if (obj === null) { return numberHash(349, hashVal); } else if (Array.isArray(obj)) { return arrayHash(obj, hashVal); } return objectHash(obj, hashVal); case 'string': return stringHash(obj, hashVal); case 'boolean': return booleanHash(obj, hashVal); case 'number': return numberHash(obj, hashVal); case 'undefined': return numberHash(937, hashVal); default: return numberHash(617, hashVal); } } function numberHash(val, initialHashVal) { return (((initialHashVal << 5) - initialHashVal) + val) | 0; // hashVal * 31 + ch, keep as int32 } function booleanHash(b, initialHashVal) { return numberHash(b ? 433 : 863, initialHashVal); } function stringHash(s, hashVal) { hashVal = numberHash(149417, hashVal); for (let i = 0, length = s.length; i < length; i++) { hashVal = numberHash(s.charCodeAt(i), hashVal); } return hashVal; } function arrayHash(arr, initialHashVal) { initialHashVal = numberHash(104579, initialHashVal); return arr.reduce((hashVal, item) => doHash(item, hashVal), initialHashVal); } function objectHash(obj, initialHashVal) { initialHashVal = numberHash(181387, initialHashVal); return Object.keys(obj).sort().reduce((hashVal, key) => { hashVal = stringHash(key, hashVal); return doHash(obj[key], hashVal); }, initialHashVal); } function leftRotate$2(value, bits, totalBits = 32) { // delta + bits = totalBits const delta = totalBits - bits; // All ones, expect `delta` zeros aligned to the right const mask = ~((1 << delta) - 1); // Join (value left-shifted `bits` bits) with (masked value right-shifted `delta` bits) return ((value << bits) | ((mask & value) >>> delta)) >>> 0; } function fill(dest, index = 0, count = dest.byteLength, value = 0) { for (let i = 0; i < count; i++) { dest[index + i] = value; } } function leftPad(value, length, char = '0') { while (value.length < length) { value = char + value; } return value; } function toHexString(bufferOrValue, bitsize = 32) { if (bufferOrValue instanceof ArrayBuffer) { return Array.from(new Uint8Array(bufferOrValue)).map(b => b.toString(16).padStart(2, '0')).join(''); } return leftPad((bufferOrValue >>> 0).toString(16), bitsize / 4); } /** * A SHA1 implementation that works with strings and does not allocate. */ class StringSHA1 { constructor() { this._h0 = 0x67452301; this._h1 = 0xEFCDAB89; this._h2 = 0x98BADCFE; this._h3 = 0x10325476; this._h4 = 0xC3D2E1F0; this._buff = new Uint8Array(64 /* BLOCK_SIZE */ + 3 /* to fit any utf-8 */); this._buffDV = new DataView(this._buff.buffer); this._buffLen = 0; this._totalLen = 0; this._leftoverHighSurrogate = 0; this._finished = false; } update(str) { const strLen = str.length; if (strLen === 0) { return; } const buff = this._buff; let buffLen = this._buffLen; let leftoverHighSurrogate = this._leftoverHighSurrogate; let charCode; let offset; if (leftoverHighSurrogate !== 0) { charCode = leftoverHighSurrogate; offset = -1; leftoverHighSurrogate = 0; } else { charCode = str.charCodeAt(0); offset = 0; } while (true) { let codePoint = charCode; if (isHighSurrogate(charCode)) { if (offset + 1 < strLen) { const nextCharCode = str.charCodeAt(offset + 1); if (isLowSurrogate(nextCharCode)) { offset++; codePoint = computeCodePoint(charCode, nextCharCode); } else { // illegal => unicode replacement character codePoint = 65533 /* UNICODE_REPLACEMENT */; } } else { // last character is a surrogate pair leftoverHighSurrogate = charCode; break; } } else if (isLowSurrogate(charCode)) { // illegal => unicode replacement character codePoint = 65533 /* UNICODE_REPLACEMENT */; } buffLen = this._push(buff, buffLen, codePoint); offset++; if (offset < strLen) { charCode = str.charCodeAt(offset); } else { break; } } this._buffLen = buffLen; this._leftoverHighSurrogate = leftoverHighSurrogate; } _push(buff, buffLen, codePoint) { if (codePoint < 0x0080) { buff[buffLen++] = codePoint; } else if (codePoint < 0x0800) { buff[buffLen++] = 0b11000000 | ((codePoint & 0b00000000000000000000011111000000) >>> 6); buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0); } else if (codePoint < 0x10000) { buff[buffLen++] = 0b11100000 | ((codePoint & 0b00000000000000001111000000000000) >>> 12); buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000111111000000) >>> 6); buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0); } else { buff[buffLen++] = 0b11110000 | ((codePoint & 0b00000000000111000000000000000000) >>> 18); buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000111111000000000000) >>> 12); buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000111111000000) >>> 6); buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0); } if (buffLen >= 64 /* BLOCK_SIZE */) { this._step(); buffLen -= 64 /* BLOCK_SIZE */; this._totalLen += 64 /* BLOCK_SIZE */; // take last 3 in case of UTF8 overflow buff[0] = buff[64 /* BLOCK_SIZE */ + 0]; buff[1] = buff[64 /* BLOCK_SIZE */ + 1]; buff[2] = buff[64 /* BLOCK_SIZE */ + 2]; } return buffLen; } digest() { if (!this._finished) { this._finished = true; if (this._leftoverHighSurrogate) { // illegal => unicode replacement character this._leftoverHighSurrogate = 0; this._buffLen = this._push(this._buff, this._buffLen, 65533 /* UNICODE_REPLACEMENT */); } this._totalLen += this._buffLen; this._wrapUp(); } return toHexString(this._h0) + toHexString(this._h1) + toHexString(this._h2) + toHexString(this._h3) + toHexString(this._h4); } _wrapUp() { this._buff[this._buffLen++] = 0x80; fill(this._buff, this._buffLen); if (this._buffLen > 56) { this._step(); fill(this._buff); } // this will fit because the mantissa can cover up to 52 bits const ml = 8 * this._totalLen; this._buffDV.setUint32(56, Math.floor(ml / 4294967296), false); this._buffDV.setUint32(60, ml % 4294967296, false); this._step(); } _step() { const bigBlock32 = StringSHA1._bigBlock32; const data = this._buffDV; for (let j = 0; j < 64 /* 16*4 */; j += 4) { bigBlock32.setUint32(j, data.getUint32(j, false), false); } for (let j = 64; j < 320 /* 80*4 */; j += 4) { bigBlock32.setUint32(j, leftRotate$2((bigBlock32.getUint32(j - 12, false) ^ bigBlock32.getUint32(j - 32, false) ^ bigBlock32.getUint32(j - 56, false) ^ bigBlock32.getUint32(j - 64, false)), 1), false); } let a = this._h0; let b = this._h1; let c = this._h2; let d = this._h3; let e = this._h4; let f, k; let temp; for (let j = 0; j < 80; j++) { if (j < 20) { f = (b & c) | ((~b) & d); k = 0x5A827999; } else if (j < 40) { f = b ^ c ^ d; k = 0x6ED9EBA1; } else if (j < 60) { f = (b & c) | (b & d) | (c & d); k = 0x8F1BBCDC; } else { f = b ^ c ^ d; k = 0xCA62C1D6; } temp = (leftRotate$2(a, 5) + f + e + k + bigBlock32.getUint32(j * 4, false)) & 0xffffffff; e = d; d = c; c = leftRotate$2(b, 30); b = a; a = temp; } this._h0 = (this._h0 + a) & 0xffffffff; this._h1 = (this._h1 + b) & 0xffffffff; this._h2 = (this._h2 + c) & 0xffffffff; this._h3 = (this._h3 + d) & 0xffffffff; this._h4 = (this._h4 + e) & 0xffffffff; } } StringSHA1._bigBlock32 = new DataView(new ArrayBuffer(320)); // 80 * 4 = 320 /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class StringDiffSequence { constructor(source) { this.source = source; } getElements() { const source = this.source; const characters = new Int32Array(source.length); for (let i = 0, len = source.length; i < len; i++) { characters[i] = source.charCodeAt(i); } return characters; } } function stringDiff(original, modified, pretty) { return new LcsDiff(new StringDiffSequence(original), new StringDiffSequence(modified)).ComputeDiff(pretty).changes; } // // The code below has been ported from a C# implementation in VS // class Debug { static Assert(condition, message) { if (!condition) { throw new Error(message); } } } class MyArray { /** * Copies a range of elements from an Array starting at the specified source index and pastes * them to another Array starting at the specified destination index. The length and the indexes * are specified as 64-bit integers. * sourceArray: * The Array that contains the data to copy. * sourceIndex: * A 64-bit integer that represents the index in the sourceArray at which copying begins. * destinationArray: * The Array that receives the data. * destinationIndex: * A 64-bit integer that represents the index in the destinationArray at which storing begins. * length: * A 64-bit integer that represents the number of elements to copy. */ static Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length) { for (let i = 0; i < length; i++) { destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i]; } } static Copy2(sourceArray, sourceIndex, destinationArray, destinationIndex, length) { for (let i = 0; i < length; i++) { destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i]; } } } /** * A utility class which helps to create the set of DiffChanges from * a difference operation. This class accepts original DiffElements and * modified DiffElements that are involved in a particular change. The * MarkNextChange() method can be called to mark the separation between * distinct changes. At the end, the Changes property can be called to retrieve * the constructed changes. */ class DiffChangeHelper { /** * Constructs a new DiffChangeHelper for the given DiffSequences. */ constructor() { this.m_changes = []; this.m_originalStart = 1073741824 /* MAX_SAFE_SMALL_INTEGER */; this.m_modifiedStart = 1073741824 /* MAX_SAFE_SMALL_INTEGER */; this.m_originalCount = 0; this.m_modifiedCount = 0; } /** * Marks the beginning of the next change in the set of differences. */ MarkNextChange() { // Only add to the list if there is something to add if (this.m_originalCount > 0 || this.m_modifiedCount > 0) { // Add the new change to our list this.m_changes.push(new DiffChange(this.m_originalStart, this.m_originalCount, this.m_modifiedStart, this.m_modifiedCount)); } // Reset for the next change this.m_originalCount = 0; this.m_modifiedCount = 0; this.m_originalStart = 1073741824 /* MAX_SAFE_SMALL_INTEGER */; this.m_modifiedStart = 1073741824 /* MAX_SAFE_SMALL_INTEGER */; } /** * Adds the original element at the given position to the elements * affected by the current change. The modified index gives context * to the change position with respect to the original sequence. * @param originalIndex The index of the original element to add. * @param modifiedIndex The index of the modified element that provides corresponding position in the modified sequence. */ AddOriginalElement(originalIndex, modifiedIndex) { // The 'true' start index is the smallest of the ones we've seen this.m_originalStart = Math.min(this.m_originalStart, originalIndex); this.m_modifiedStart = Math.min(this.m_modifiedStart, modifiedIndex); this.m_originalCount++; } /** * Adds the modified element at the given position to the elements * affected by the current change. The original index gives context * to the change position with respect to the modified sequence. * @param originalIndex The index of the original element that provides corresponding position in the original sequence. * @param modifiedIndex The index of the modified element to add. */ AddModifiedElement(originalIndex, modifiedIndex) { // The 'true' start index is the smallest of the ones we've seen this.m_originalStart = Math.min(this.m_originalStart, originalIndex); this.m_modifiedStart = Math.min(this.m_modifiedStart, modifiedIndex); this.m_modifiedCount++; } /** * Retrieves all of the changes marked by the class. */ getChanges() { if (this.m_originalCount > 0 || this.m_modifiedCount > 0) { // Finish up on whatever is left this.MarkNextChange(); } return this.m_changes; } /** * Retrieves all of the changes marked by the class in the reverse order */ getReverseChanges() { if (this.m_originalCount > 0 || this.m_modifiedCount > 0) { // Finish up on whatever is left this.MarkNextChange(); } this.m_changes.reverse(); return this.m_changes; } } /** * An implementation of the difference algorithm described in * "An O(ND) Difference Algorithm and its variations" by Eugene W. Myers */ class LcsDiff { /** * Constructs the DiffFinder */ constructor(originalSequence, modifiedSequence, continueProcessingPredicate = null) { this.ContinueProcessingPredicate = continueProcessingPredicate; this._originalSequence = originalSequence; this._modifiedSequence = modifiedSequence; const [originalStringElements, originalElementsOrHash, originalHasStrings] = LcsDiff._getElements(originalSequence); const [modifiedStringElements, modifiedElementsOrHash, modifiedHasStrings] = LcsDiff._getElements(modifiedSequence); this._hasStrings = (originalHasStrings && modifiedHasStrings); this._originalStringElements = originalStringElements; this._originalElementsOrHash = originalElementsOrHash; this._modifiedStringElements = modifiedStringElements; this._modifiedElementsOrHash = modifiedElementsOrHash; this.m_forwardHistory = []; this.m_reverseHistory = []; } static _isStringArray(arr) { return (arr.length > 0 && typeof arr[0] === 'string'); } static _getElements(sequence) { const elements = sequence.getElements(); if (LcsDiff._isStringArray(elements)) { const hashes = new Int32Array(elements.length); for (let i = 0, len = elements.length; i < len; i++) { hashes[i] = stringHash(elements[i], 0); } return [elements, hashes, true]; } if (elements instanceof Int32Array) { return [[], elements, false]; } return [[], new Int32Array(elements), false]; } ElementsAreEqual(originalIndex, newIndex) { if (this._originalElementsOrHash[originalIndex] !== this._modifiedElementsOrHash[newIndex]) { return false; } return (this._hasStrings ? this._originalStringElements[originalIndex] === this._modifiedStringElements[newIndex] : true); } ElementsAreStrictEqual(originalIndex, newIndex) { if (!this.ElementsAreEqual(originalIndex, newIndex)) { return false; } const originalElement = LcsDiff._getStrictElement(this._originalSequence, originalIndex); const modifiedElement = LcsDiff._getStrictElement(this._modifiedSequence, newIndex); return (originalElement === modifiedElement); } static _getStrictElement(sequence, index) { if (typeof sequence.getStrictElement === 'function') { return sequence.getStrictElement(index); } return null; } OriginalElementsAreEqual(index1, index2) { if (this._originalElementsOrHash[index1] !== this._originalElementsOrHash[index2]) { return false; } return (this._hasStrings ? this._originalStringElements[index1] === this._originalStringElements[index2] : true); } ModifiedElementsAreEqual(index1, index2) { if (this._modifiedElementsOrHash[index1] !== this._modifiedElementsOrHash[index2]) { return false; } return (this._hasStrings ? this._modifiedStringElements[index1] === this._modifiedStringElements[index2] : true); } ComputeDiff(pretty) { return this._ComputeDiff(0, this._originalElementsOrHash.length - 1, 0, this._modifiedElementsOrHash.length - 1, pretty); } /** * Computes the differences between the original and modified input * sequences on the bounded range. * @returns An array of the differences between the two input sequences. */ _ComputeDiff(originalStart, originalEnd, modifiedStart, modifiedEnd, pretty) { const quitEarlyArr = [false]; let changes = this.ComputeDiffRecursive(originalStart, originalEnd, modifiedStart, modifiedEnd, quitEarlyArr); if (pretty) { // We have to clean up the computed diff to be more intuitive // but it turns out this cannot be done correctly until the entire set // of diffs have been computed changes = this.PrettifyChanges(changes); } return { quitEarly: quitEarlyArr[0], changes: changes }; } /** * Private helper method which computes the differences on the bounded range * recursively. * @returns An array of the differences between the two input sequences. */ ComputeDiffRecursive(originalStart, originalEnd, modifiedStart, modifiedEnd, quitEarlyArr) { quitEarlyArr[0] = false; // Find the start of the differences while (originalStart <= originalEnd && modifiedStart <= modifiedEnd && this.ElementsAreEqual(originalStart, modifiedStart)) { originalStart++; modifiedStart++; } // Find the end of the differences while (originalEnd >= originalStart && modifiedEnd >= modifiedStart && this.ElementsAreEqual(originalEnd, modifiedEnd)) { originalEnd--; modifiedEnd--; } // In the special case where we either have all insertions or all deletions or the sequences are identical if (originalStart > originalEnd || modifiedStart > modifiedEnd) { let changes; if (modifiedStart <= modifiedEnd) { Debug.Assert(originalStart === originalEnd + 1, 'originalStart should only be one more than originalEnd'); // All insertions changes = [ new DiffChange(originalStart, 0, modifiedStart, modifiedEnd - modifiedStart + 1) ]; } else if (originalStart <= originalEnd) { Debug.Assert(modifiedStart === modifiedEnd + 1, 'modifiedStart should only be one more than modifiedEnd'); // All deletions changes = [ new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, 0) ]; } else { Debug.Assert(originalStart === originalEnd + 1, 'originalStart should only be one more than originalEnd'); Debug.Assert(modifiedStart === modifiedEnd + 1, 'modifiedStart should only be one more than modifiedEnd'); // Identical sequences - No differences changes = []; } return changes; } // This problem can be solved using the Divide-And-Conquer technique. const midOriginalArr = [0]; const midModifiedArr = [0]; const result = this.ComputeRecursionPoint(originalStart, originalEnd, modifiedStart, modifiedEnd, midOriginalArr, midModifiedArr, quitEarlyArr); const midOriginal = midOriginalArr[0]; const midModified = midModifiedArr[0]; if (result !== null) { // Result is not-null when there was enough memory to compute the changes while // searching for the recursion point return result; } else if (!quitEarlyArr[0]) { // We can break the problem down recursively by finding the changes in the // First Half: (originalStart, modifiedStart) to (midOriginal, midModified) // Second Half: (midOriginal + 1, minModified + 1) to (originalEnd, modifiedEnd) // NOTE: ComputeDiff() is inclusive, therefore the second range starts on the next point const leftChanges = this.ComputeDiffRecursive(originalStart, midOriginal, modifiedStart, midModified, quitEarlyArr); let rightChanges = []; if (!quitEarlyArr[0]) { rightChanges = this.ComputeDiffRecursive(midOriginal + 1, originalEnd, midModified + 1, modifiedEnd, quitEarlyArr); } else { // We didn't have time to finish the first half, so we don't have time to compute this half. // Consider the entire rest of the sequence different. rightChanges = [ new DiffChange(midOriginal + 1, originalEnd - (midOriginal + 1) + 1, midModified + 1, modifiedEnd - (midModified + 1) + 1) ]; } return this.ConcatenateChanges(leftChanges, rightChanges); } // If we hit here, we quit early, and so can't return anything meaningful return [ new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, modifiedEnd - modifiedStart + 1) ]; } WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr) { let forwardChanges = null; let reverseChanges = null; // First, walk backward through the forward diagonals history let changeHelper = new DiffChangeHelper(); let diagonalMin = diagonalForwardStart; let diagonalMax = diagonalForwardEnd; let diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalForwardOffset; let lastOriginalIndex = -1073741824 /* MIN_SAFE_SMALL_INTEGER */; let historyIndex = this.m_forwardHistory.length - 1; do { // Get the diagonal index from the relative diagonal number const diagonal = diagonalRelative + diagonalForwardBase; // Figure out where we came from if (diagonal === diagonalMin || (diagonal < diagonalMax && forwardPoints[diagonal - 1] < forwardPoints[diagonal + 1])) { // Vertical line (the element is an insert) originalIndex = forwardPoints[diagonal + 1]; modifiedIndex = originalIndex - diagonalRelative - diagonalForwardOffset; if (originalIndex < lastOriginalIndex) { changeHelper.MarkNextChange(); } lastOriginalIndex = originalIndex; changeHelper.AddModifiedElement(originalIndex + 1, modifiedIndex); diagonalRelative = (diagonal + 1) - diagonalForwardBase; //Setup for the next iteration } else { // Horizontal line (the element is a deletion) originalIndex = forwardPoints[diagonal - 1] + 1; modifiedIndex = originalIndex - diagonalRelative - diagonalForwardOffset; if (originalIndex < lastOriginalIndex) { changeHelper.MarkNextChange(); } lastOriginalIndex = originalIndex - 1; changeHelper.AddOriginalElement(originalIndex, modifiedIndex + 1); diagonalRelative = (diagonal - 1) - diagonalForwardBase; //Setup for the next iteration } if (historyIndex >= 0) { forwardPoints = this.m_forwardHistory[historyIndex]; diagonalForwardBase = forwardPoints[0]; //We stored this in the first spot diagonalMin = 1; diagonalMax = forwardPoints.length - 1; } } while (--historyIndex >= -1); // Ironically, we get the forward changes as the reverse of the // order we added them since we technically added them backwards forwardChanges = changeHelper.getReverseChanges(); if (quitEarlyArr[0]) { // TODO: Calculate a partial from the reverse diagonals. // For now, just assume everything after the midOriginal/midModified point is a diff let originalStartPoint = midOriginalArr[0] + 1; let modifiedStartPoint = midModifiedArr[0] + 1; if (forwardChanges !== null && forwardChanges.length > 0) { const lastForwardChange = forwardChanges[forwardChanges.length - 1]; originalStartPoint = Math.max(originalStartPoint, lastForwardChange.getOriginalEnd()); modifiedStartPoint = Math.max(modifiedStartPoint, lastForwardChange.getModifiedEnd()); } reverseChanges = [ new DiffChange(originalStartPoint, originalEnd - originalStartPoint + 1, modifiedStartPoint, modifiedEnd - modifiedStartPoint + 1) ]; } else { // Now walk backward through the reverse diagonals history changeHelper = new DiffChangeHelper(); diagonalMin = diagonalReverseStart; diagonalMax = diagonalReverseEnd; diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalReverseOffset; lastOriginalIndex = 1073741824 /* MAX_SAFE_SMALL_INTEGER */; historyIndex = (deltaIsEven) ? this.m_reverseHistory.length - 1 : this.m_reverseHistory.length - 2; do { // Get the diagonal index from the relative diagonal number const diagonal = diagonalRelative + diagonalReverseBase; // Figure out where we came from if (diagonal === diagonalMin || (diagonal < diagonalMax && reversePoints[diagonal - 1] >= reversePoints[diagonal + 1])) { // Horizontal line (the element is a deletion)) originalIndex = reversePoints[diagonal + 1] - 1; modifiedIndex = originalIndex - diagonalRelative - diagonalReverseOffset; if (originalIndex > lastOriginalIndex) { changeHelper.MarkNextChange(); } lastOriginalIndex = originalIndex + 1; changeHelper.AddOriginalElement(originalIndex + 1, modifiedIndex + 1); diagonalRelative = (diagonal + 1) - diagonalReverseBase; //Setup for the next iteration } else { // Vertical line (the element is an insertion) originalIndex = reversePoints[diagonal - 1]; modifiedIndex = originalIndex - diagonalRelative - diagonalReverseOffset; if (originalIndex > lastOriginalIndex) { changeHelper.MarkNextChange(); } lastOriginalIndex = originalIndex; changeHelper.AddModifiedElement(originalIndex + 1, modifiedIndex + 1); diagonalRelative = (diagonal - 1) - diagonalReverseBase; //Setup for the next iteration } if (historyIndex >= 0) { reversePoints = this.m_reverseHistory[historyIndex]; diagonalReverseBase = reversePoints[0]; //We stored this in the first spot diagonalMin = 1; diagonalMax = reversePoints.length - 1; } } while (--historyIndex >= -1); // There are cases where the reverse history will find diffs that // are correct, but not intuitive, so we need shift them. reverseChanges = changeHelper.getChanges(); } return this.ConcatenateChanges(forwardChanges, reverseChanges); } /** * Given the range to compute the diff on, this method finds the point: * (midOriginal, midModified) * that exists in the middle of the LCS of the two sequences and * is the point at which the LCS problem may be broken down recursively. * This method will try to keep the LCS trace in memory. If the LCS recursion * point is calculated and the full trace is available in memory, then this method * will return the change list. * @param originalStart The start bound of the original sequence range * @param originalEnd The end bound of the original sequence range * @param modifiedStart The start bound of the modified sequence range * @param modifiedEnd The end bound of the modified sequence range * @param midOriginal The middle point of the original sequence range * @param midModified The middle point of the modified sequence range * @returns The diff changes, if available, otherwise null */ ComputeRecursionPoint(originalStart, originalEnd, modifiedStart, modifiedEnd, midOriginalArr, midModifiedArr, quitEarlyArr) { let originalIndex = 0, modifiedIndex = 0; let diagonalForwardStart = 0, diagonalForwardEnd = 0; let diagonalReverseStart = 0, diagonalReverseEnd = 0; // To traverse the edit graph and produce the proper LCS, our actual // start position is just outside the given boundary originalStart--; modifiedStart--; // We set these up to make the compiler happy, but they will // be replaced before we return with the actual recursion point midOriginalArr[0] = 0; midModifiedArr[0] = 0; // Clear out the history this.m_forwardHistory = []; this.m_reverseHistory = []; // Each cell in the two arrays corresponds to a diagonal in the edit graph. // The integer value in the cell represents the originalIndex of the furthest // reaching point found so far that ends in that diagonal. // The modifiedIndex can be computed mathematically from the originalIndex and the diagonal number. const maxDifferences = (originalEnd - originalStart) + (modifiedEnd - modifiedStart); const numDiagonals = maxDifferences + 1; const forwardPoints = new Int32Array(numDiagonals); const reversePoints = new Int32Array(numDiagonals); // diagonalForwardBase: Index into forwardPoints of the diagonal which passes through (originalStart, modifiedStart) // diagonalReverseBase: Index into reversePoints of the diagonal which passes through (originalEnd, modifiedEnd) const diagonalForwardBase = (modifiedEnd - modifiedStart); const diagonalReverseBase = (originalEnd - originalStart); // diagonalForwardOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the // diagonal number (relative to diagonalForwardBase) // diagonalReverseOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the // diagonal number (relative to diagonalReverseBase) const diagonalForwardOffset = (originalStart - modifiedStart); const diagonalReverseOffset = (originalEnd - modifiedEnd); // delta: The difference between the end diagonal and the start diagonal. This is used to relate diagonal numbers // relative to the start diagonal with diagonal numbers relative to the end diagonal. // The Even/Oddn-ness of this delta is important for determining when we should check for overlap const delta = diagonalReverseBase - diagonalForwardBase; const deltaIsEven = (delta % 2 === 0); // Here we set up the start and end points as the furthest points found so far // in both the forward and reverse directions, respectively forwardPoints[diagonalForwardBase] = originalStart; reversePoints[diagonalReverseBase] = originalEnd; // Remember if we quit early, and thus need to do a best-effort result instead of a real result. quitEarlyArr[0] = false; // A couple of points: // --With this method, we iterate on the number of differences between the two sequences. // The more differences there actually are, the longer this will take. // --Also, as the number of differences increases, we have to search on diagonals further // away from the reference diagonal (which is diagonalForwardBase for forward, diagonalReverseBase for reverse). // --We extend on even diagonals (relative to the reference diagonal) only when numDifferences // is even and odd diagonals only when numDifferences is odd. for (let numDifferences = 1; numDifferences <= (maxDifferences / 2) + 1; numDifferences++) { let furthestOriginalIndex = 0; let furthestModifiedIndex = 0; // Run the algorithm in the forward direction diagonalForwardStart = this.ClipDiagonalBound(diagonalForwardBase - numDifferences, numDifferences, diagonalForwardBase, numDiagonals); diagonalForwardEnd = this.ClipDiagonalBound(diagonalForwardBase + numDifferences, numDifferences, diagonalForwardBase, numDiagonals); for (let diagonal = diagonalForwardStart; diagonal <= diagonalForwardEnd; diagonal += 2) { // STEP 1: We extend the furthest reaching point in the present diagonal // by looking at the diagonals above and below and picking the one whose point // is further away from the start point (originalStart, modifiedStart) if (diagonal === diagonalForwardStart || (diagonal < diagonalForwardEnd && forwardPoints[diagonal - 1] < forwardPoints[diagonal + 1])) { originalIndex = forwardPoints[diagonal + 1]; } else { originalIndex = forwardPoints[diagonal - 1] + 1; } modifiedIndex = originalIndex - (diagonal - diagonalForwardBase) - diagonalForwardOffset; // Save the current originalIndex so we can test for false overlap in step 3 const tempOriginalIndex = originalIndex; // STEP 2: We can continue to extend the furthest reaching point in the present diagonal // so long as the elements are equal. while (originalIndex < originalEnd && modifiedIndex < modifiedEnd && this.ElementsAreEqual(originalIndex + 1, modifiedIndex + 1)) { originalIndex++; modifiedIndex++; } forwardPoints[diagonal] = originalIndex; if (originalIndex + modifiedIndex > furthestOriginalIndex + furthestModifiedIndex) { furthestOriginalIndex = originalIndex; furthestModifiedIndex = modifiedIndex; } // STEP 3: If delta is odd (overlap first happens on forward when delta is odd) // and diagonal is in the range of reverse diagonals computed for numDifferences-1 // (the previous iteration; we haven't computed reverse diagonals for numDifferences yet) // then check for overlap. if (!deltaIsEven && Math.abs(diagonal - diagonalReverseBase) <= (numDifferences - 1)) { if (originalIndex >= reversePoints[diagonal]) { midOriginalArr[0] = originalIndex; midModifiedArr[0] = modifiedIndex; if (tempOriginalIndex <= reversePoints[diagonal] && 1447 /* MaxDifferencesHistory */ > 0 && numDifferences <= (1447 /* MaxDifferencesHistory */ + 1)) { // BINGO! We overlapped, and we have the full trace in memory! return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr); } else { // Either false overlap, or we didn't have enough memory for the full trace // Just return the recursion point return null; } } } } // Check to see if we should be quitting early, before moving on to the next iteration. const matchLengthOfLongest = ((furthestOriginalIndex - originalStart) + (furthestModifiedIndex - modifiedStart) - numDifferences) / 2; if (this.ContinueProcessingPredicate !== null && !this.ContinueProcessingPredicate(furthestOriginalIndex, matchLengthOfLongest)) { // We can't finish, so skip ahead to generating a result from what we have. quitEarlyArr[0] = true; // Use the furthest distance we got in the forward direction. midOriginalArr[0] = furthestOriginalIndex; midModifiedArr[0] = furthestModifiedIndex; if (matchLengthOfLongest > 0 && 1447 /* MaxDifferencesHistory */ > 0 && numDifferences <= (1447 /* MaxDifferencesHistory */ + 1)) { // Enough of the history is in memory to walk it backwards return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr); } else { // We didn't actually remember enough of the history. //Since we are quitting the diff early, we need to shift back the originalStart and modified start //back into the boundary limits since we decremented their value above beyond the boundary limit. originalStart++; modifiedStart++; return [ new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, modifiedEnd - modifiedStart + 1) ]; } } // Run the algorithm in the reverse direction diagonalReverseStart = this.ClipDiagonalBound(diagonalReverseBase - numDifferences, numDifferences, diagonalReverseBase, numDiagonals); diagonalReverseEnd = this.ClipDiagonalBound(diagonalReverseBase + numDifferences, numDifferences, diagonalReverseBase, numDiagonals); for (let diagonal = diagonalReverseStart; diagonal <= diagonalReverseEnd; diagonal += 2) { // STEP 1: We extend the furthest reaching point in the present diagonal // by looking at the diagonals above and below and picking the one whose point // is further away from the start point (originalEnd, modifiedEnd) if (diagonal === diagonalReverseStart || (diagonal < diagonalReverseEnd && reversePoints[diagonal - 1] >= reversePoints[diagonal + 1])) { originalIndex = reversePoints[diagonal + 1] - 1; } else { originalIndex = reversePoints[diagonal - 1]; } modifiedIndex = originalIndex - (diagonal - diagonalReverseBase) - diagonalReverseOffset; // Save the current originalIndex so we can test for false overlap const tempOriginalIndex = originalIndex; // STEP 2: We can continue to extend the furthest reaching point in the present diagonal // as long as the elements are equal. while (originalIndex > originalStart && modifiedIndex > modifiedStart && this.ElementsAreEqual(originalIndex, modifiedIndex)) { originalIndex--; modifiedIndex--; } reversePoints[diagonal] = originalIndex; // STEP 4: If delta is even (overlap first happens on reverse when delta is even) // and diagonal is in the range of forward diagonals computed for numDifferences // then check for overlap. if (deltaIsEven && Math.abs(diagonal - diagonalForwardBase) <= numDifferences) { if (originalIndex <= forwardPoints[diagonal]) { midOriginalArr[0] = originalIndex; midModifiedArr[0] = modifiedIndex; if (tempOriginalIndex >= forwardPoints[diagonal] && 1447 /* MaxDifferencesHistory */ > 0 && numDifferences <= (1447 /* MaxDifferencesHistory */ + 1)) { // BINGO! We overlapped, and we have the full trace in memory! return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr); } else { // Either false overlap, or we didn't have enough memory for the full trace // Just return the recursion point return null; } } } } // Save current vectors to history before the next iteration if (numDifferences <= 1447 /* MaxDifferencesHistory */) { // We are allocating space for one extra int, which we fill with // the index of the diagonal base index let temp = new Int32Array(diagonalForwardEnd - diagonalForwardStart + 2); temp[0] = diagonalForwardBase - diagonalForwardStart + 1; MyArray.Copy2(forwardPoints, diagonalForwardStart, temp, 1, diagonalForwardEnd - diagonalForwardStart + 1); this.m_forwardHistory.push(temp); temp = new Int32Array(diagonalReverseEnd - diagonalReverseStart + 2); temp[0] = diagonalReverseBase - diagonalReverseStart + 1; MyArray.Copy2(reversePoints, diagonalReverseStart, temp, 1, diagonalReverseEnd - diagonalReverseStart + 1); this.m_reverseHistory.push(temp); } } // If we got here, then we have the full trace in history. We just have to convert it to a change list // NOTE: This part is a bit messy return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr); } /** * Shifts the given changes to provide a more intuitive diff. * While the first element in a diff matches the first element after the diff, * we shift the diff down. * * @param changes The list of changes to shift * @returns The shifted changes */ PrettifyChanges(changes) { // Shift all the changes down first for (let i = 0; i < changes.length; i++) { const change = changes[i]; const originalStop = (i < changes.length - 1) ? changes[i + 1].originalStart : this._originalElementsOrHash.length; const modifiedStop = (i < changes.length - 1) ? changes[i + 1].modifiedStart : this._modifiedElementsOrHash.length; const checkOriginal = change.originalLength > 0; const checkModified = change.modifiedLength > 0; while (change.originalStart + change.originalLength < originalStop && change.modifiedStart + change.modifiedLength < modifiedStop && (!checkOriginal || this.OriginalElementsAreEqual(change.originalStart, change.originalStart + change.originalLength)) && (!checkModified || this.ModifiedElementsAreEqual(change.modifiedStart, change.modifiedStart + change.modifiedLength))) { const startStrictEqual = this.ElementsAreStrictEqual(change.originalStart, change.modifiedStart); const endStrictEqual = this.ElementsAreStrictEqual(change.originalStart + change.originalLength, change.modifiedStart + change.modifiedLength); if (endStrictEqual && !startStrictEqual) { // moving the change down would create an equal change, but the elements are not strict equal break; } change.originalStart++; change.modifiedStart++; } let mergedChangeArr = [null]; if (i < changes.length - 1 && this.ChangesOverlap(changes[i], changes[i + 1], mergedChangeArr)) { changes[i] = mergedChangeArr[0]; changes.splice(i + 1, 1); i--; continue; } } // Shift changes back up until we hit empty or whitespace-only lines for (let i = changes.length - 1; i >= 0; i--) { const change = changes[i]; let originalStop = 0; let modifiedStop = 0; if (i > 0) { const prevChange = changes[i - 1]; originalStop = prevChange.originalStart + prevChange.originalLength; modifiedStop = prevChange.modifiedStart + prevChange.modifiedLength; } const checkOriginal = change.originalLength > 0; const checkModified = change.modifiedLength > 0; let bestDelta = 0; let bestScore = this._boundaryScore(change.originalStart, change.originalLength, change.modifiedStart, change.modifiedLength); for (let delta = 1;; delta++) { const originalStart = change.originalStart - delta; const modifiedStart = change.modifiedStart - delta; if (originalStart < originalStop || modifiedStart < modifiedStop) { break; } if (checkOriginal && !this.OriginalElementsAreEqual(originalStart, originalStart + change.originalLength)) { break; } if (checkModified && !this.ModifiedElementsAreEqual(modifiedStart, modifiedStart + change.modifiedLength)) { break; } const touchingPreviousChange = (originalStart === originalStop && modifiedStart === modifiedStop); const score = ((touchingPreviousChange ? 5 : 0) + this._boundaryScore(originalStart, change.originalLength, modifiedStart, change.modifiedLength)); if (score > bestScore) { bestScore = score; bestDelta = delta; } } change.originalStart -= bestDelta; change.modifiedStart -= bestDelta; const mergedChangeArr = [null]; if (i > 0 && this.ChangesOverlap(changes[i - 1], changes[i], mergedChangeArr)) { changes[i - 1] = mergedChangeArr[0]; changes.splice(i, 1); i++; continue; } } // There could be multiple longest common substrings. // Give preference to the ones containing longer lines if (this._hasStrings) { for (let i = 1, len = changes.length; i < len; i++) { const aChange = changes[i - 1]; const bChange = changes[i]; const matchedLength = bChange.originalStart - aChange.originalStart - aChange.originalLength; const aOriginalStart = aChange.originalStart; const bOriginalEnd = bChange.originalStart + bChange.originalLength; const abOriginalLength = bOriginalEnd - aOriginalStart; const aModifiedStart = aChange.modifiedStart; const bModifiedEnd = bChange.modifiedStart + bChange.modifiedLength; const abModifiedLength = bModifiedEnd - aModifiedStart; // Avoid wasting a lot of time with these searches if (matchedLength < 5 && abOriginalLength < 20 && abModifiedLength < 20) { const t = this._findBetterContiguousSequence(aOriginalStart, abOriginalLength, aModifiedStart, abModifiedLength, matchedLength); if (t) { const [originalMatchStart, modifiedMatchStart] = t; if (originalMatchStart !== aChange.originalStart + aChange.originalLength || modifiedMatchStart !== aChange.modifiedStart + aChange.modifiedLength) { // switch to another sequence that has a better score aChange.originalLength = originalMatchStart - aChange.originalStart; aChange.modifiedLength = modifiedMatchStart - aChange.modifiedStart; bChange.originalStart = originalMatchStart + matchedLength; bChange.modifiedStart = modifiedMatchStart + matchedLength; bChange.originalLength = bOriginalEnd - bChange.originalStart; bChange.modifiedLength = bModifiedEnd - bChange.modifiedStart; } } } } } return changes; } _findBetterContiguousSequence(originalStart, originalLength, modifiedStart, modifiedLength, desiredLength) { if (originalLength < desiredLength || modifiedLength < desiredLength) { return null; } const originalMax = originalStart + originalLength - desiredLength + 1; const modifiedMax = modifiedStart + modifiedLength - desiredLength + 1; let bestScore = 0; let bestOriginalStart = 0; let bestModifiedStart = 0; for (let i = originalStart; i < originalMax; i++) { for (let j = modifiedStart; j < modifiedMax; j++) { const score = this._contiguousSequenceScore(i, j, desiredLength); if (score > 0 && score > bestScore) { bestScore = score; bestOriginalStart = i; bestModifiedStart = j; } } } if (bestScore > 0) { return [bestOriginalStart, bestModifiedStart]; } return null; } _contiguousSequenceScore(originalStart, modifiedStart, length) { let score = 0; for (let l = 0; l < length; l++) { if (!this.ElementsAreEqual(originalStart + l, modifiedStart + l)) { return 0; } score += this._originalStringElements[originalStart + l].length; } return score; } _OriginalIsBoundary(index) { if (index <= 0 || index >= this._originalElementsOrHash.length - 1) { return true; } return (this._hasStrings && /^\s*$/.test(this._originalStringElements[index])); } _OriginalRegionIsBoundary(originalStart, originalLength) { if (this._OriginalIsBoundary(originalStart) || this._OriginalIsBoundary(originalStart - 1)) { return true; } if (originalLength > 0) { const originalEnd = originalStart + originalLength; if (this._OriginalIsBoundary(originalEnd - 1) || this._OriginalIsBoundary(originalEnd)) { return true; } } return false; } _ModifiedIsBoundary(index) { if (index <= 0 || index >= this._modifiedElementsOrHash.length - 1) { return true; } return (this._hasStrings && /^\s*$/.test(this._modifiedStringElements[index])); } _ModifiedRegionIsBoundary(modifiedStart, modifiedLength) { if (this._ModifiedIsBoundary(modifiedStart) || this._ModifiedIsBoundary(modifiedStart - 1)) { return true; } if (modifiedLength > 0) { const modifiedEnd = modifiedStart + modifiedLength; if (this._ModifiedIsBoundary(modifiedEnd - 1) || this._ModifiedIsBoundary(modifiedEnd)) { return true; } } return false; } _boundaryScore(originalStart, originalLength, modifiedStart, modifiedLength) { const originalScore = (this._OriginalRegionIsBoundary(originalStart, originalLength) ? 1 : 0); const modifiedScore = (this._ModifiedRegionIsBoundary(modifiedStart, modifiedLength) ? 1 : 0); return (originalScore + modifiedScore); } /** * Concatenates the two input DiffChange lists and returns the resulting * list. * @param The left changes * @param The right changes * @returns The concatenated list */ ConcatenateChanges(left, right) { let mergedChangeArr = []; if (left.length === 0 || right.length === 0) { return (right.length > 0) ? right : left; } else if (this.ChangesOverlap(left[left.length - 1], right[0], mergedChangeArr)) { // Since we break the problem down recursively, it is possible that we // might recurse in the middle of a change thereby splitting it into // two changes. Here in the combining stage, we detect and fuse those // changes back together const result = new Array(left.length + right.length - 1); MyArray.Copy(left, 0, result, 0, left.length - 1); result[left.length - 1] = mergedChangeArr[0]; MyArray.Copy(right, 1, result, left.length, right.length - 1); return result; } else { const result = new Array(left.length + right.length); MyArray.Copy(left, 0, result, 0, left.length); MyArray.Copy(right, 0, result, left.length, right.length); return result; } } /** * Returns true if the two changes overlap and can be merged into a single * change * @param left The left change * @param right The right change * @param mergedChange The merged change if the two overlap, null otherwise * @returns True if the two changes overlap */ ChangesOverlap(left, right, mergedChangeArr) { Debug.Assert(left.originalStart <= right.originalStart, 'Left change is not less than or equal to right change'); Debug.Assert(left.modifiedStart <= right.modifiedStart, 'Left change is not less than or equal to right change'); if (left.originalStart + left.originalLength >= right.originalStart || left.modifiedStart + left.modifiedLength >= right.modifiedStart) { const originalStart = left.originalStart; let originalLength = left.originalLength; const modifiedStart = left.modifiedStart; let modifiedLength = left.modifiedLength; if (left.originalStart + left.originalLength >= right.originalStart) { originalLength = right.originalStart + right.originalLength - left.originalStart; } if (left.modifiedStart + left.modifiedLength >= right.modifiedStart) { modifiedLength = right.modifiedStart + right.modifiedLength - left.modifiedStart; } mergedChangeArr[0] = new DiffChange(originalStart, originalLength, modifiedStart, modifiedLength); return true; } else { mergedChangeArr[0] = null; return false; } } /** * Helper method used to clip a diagonal index to the range of valid * diagonals. This also decides whether or not the diagonal index, * if it exceeds the boundary, should be clipped to the boundary or clipped * one inside the boundary depending on the Even/Odd status of the boundary * and numDifferences. * @param diagonal The index of the diagonal to clip. * @param numDifferences The current number of differences being iterated upon. * @param diagonalBaseIndex The base reference diagonal. * @param numDiagonals The total number of diagonals. * @returns The clipped diagonal index. */ ClipDiagonalBound(diagonal, numDifferences, diagonalBaseIndex, numDiagonals) { if (diagonal >= 0 && diagonal < numDiagonals) { // Nothing to clip, its in range return diagonal; } // diagonalsBelow: The number of diagonals below the reference diagonal // diagonalsAbove: The number of diagonals above the reference diagonal const diagonalsBelow = diagonalBaseIndex; const diagonalsAbove = numDiagonals - diagonalBaseIndex - 1; const diffEven = (numDifferences % 2 === 0); if (diagonal < 0) { const lowerBoundEven = (diagonalsBelow % 2 === 0); return (diffEven === lowerBoundEven) ? 0 : 1; } else { const upperBoundEven = (diagonalsAbove % 2 === 0); return (diffEven === upperBoundEven) ? numDiagonals - 1 : numDiagonals - 2; } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const MINIMUM_MATCHING_CHARACTER_LENGTH = 3; function computeDiff(originalSequence, modifiedSequence, continueProcessingPredicate, pretty) { const diffAlgo = new LcsDiff(originalSequence, modifiedSequence, continueProcessingPredicate); return diffAlgo.ComputeDiff(pretty); } class LineSequence { constructor(lines) { const startColumns = []; const endColumns = []; for (let i = 0, length = lines.length; i < length; i++) { startColumns[i] = getFirstNonBlankColumn(lines[i], 1); endColumns[i] = getLastNonBlankColumn(lines[i], 1); } this.lines = lines; this._startColumns = startColumns; this._endColumns = endColumns; } getElements() { const elements = []; for (let i = 0, len = this.lines.length; i < len; i++) { elements[i] = this.lines[i].substring(this._startColumns[i] - 1, this._endColumns[i] - 1); } return elements; } getStrictElement(index) { return this.lines[index]; } getStartLineNumber(i) { return i + 1; } getEndLineNumber(i) { return i + 1; } createCharSequence(shouldIgnoreTrimWhitespace, startIndex, endIndex) { const charCodes = []; const lineNumbers = []; const columns = []; let len = 0; for (let index = startIndex; index <= endIndex; index++) { const lineContent = this.lines[index]; const startColumn = (shouldIgnoreTrimWhitespace ? this._startColumns[index] : 1); const endColumn = (shouldIgnoreTrimWhitespace ? this._endColumns[index] : lineContent.length + 1); for (let col = startColumn; col < endColumn; col++) { charCodes[len] = lineContent.charCodeAt(col - 1); lineNumbers[len] = index + 1; columns[len] = col; len++; } } return new CharSequence(charCodes, lineNumbers, columns); } } class CharSequence { constructor(charCodes, lineNumbers, columns) { this._charCodes = charCodes; this._lineNumbers = lineNumbers; this._columns = columns; } getElements() { return this._charCodes; } getStartLineNumber(i) { return this._lineNumbers[i]; } getStartColumn(i) { return this._columns[i]; } getEndLineNumber(i) { return this._lineNumbers[i]; } getEndColumn(i) { return this._columns[i] + 1; } } class CharChange { constructor(originalStartLineNumber, originalStartColumn, originalEndLineNumber, originalEndColumn, modifiedStartLineNumber, modifiedStartColumn, modifiedEndLineNumber, modifiedEndColumn) { this.originalStartLineNumber = originalStartLineNumber; this.originalStartColumn = originalStartColumn; this.originalEndLineNumber = originalEndLineNumber; this.originalEndColumn = originalEndColumn; this.modifiedStartLineNumber = modifiedStartLineNumber; this.modifiedStartColumn = modifiedStartColumn; this.modifiedEndLineNumber = modifiedEndLineNumber; this.modifiedEndColumn = modifiedEndColumn; } static createFromDiffChange(diffChange, originalCharSequence, modifiedCharSequence) { let originalStartLineNumber; let originalStartColumn; let originalEndLineNumber; let originalEndColumn; let modifiedStartLineNumber; let modifiedStartColumn; let modifiedEndLineNumber; let modifiedEndColumn; if (diffChange.originalLength === 0) { originalStartLineNumber = 0; originalStartColumn = 0; originalEndLineNumber = 0; originalEndColumn = 0; } else { originalStartLineNumber = originalCharSequence.getStartLineNumber(diffChange.originalStart); originalStartColumn = originalCharSequence.getStartColumn(diffChange.originalStart); originalEndLineNumber = originalCharSequence.getEndLineNumber(diffChange.originalStart + diffChange.originalLength - 1); originalEndColumn = originalCharSequence.getEndColumn(diffChange.originalStart + diffChange.originalLength - 1); } if (diffChange.modifiedLength === 0) { modifiedStartLineNumber = 0; modifiedStartColumn = 0; modifiedEndLineNumber = 0; modifiedEndColumn = 0; } else { modifiedStartLineNumber = modifiedCharSequence.getStartLineNumber(diffChange.modifiedStart); modifiedStartColumn = modifiedCharSequence.getStartColumn(diffChange.modifiedStart); modifiedEndLineNumber = modifiedCharSequence.getEndLineNumber(diffChange.modifiedStart + diffChange.modifiedLength - 1); modifiedEndColumn = modifiedCharSequence.getEndColumn(diffChange.modifiedStart + diffChange.modifiedLength - 1); } return new CharChange(originalStartLineNumber, originalStartColumn, originalEndLineNumber, originalEndColumn, modifiedStartLineNumber, modifiedStartColumn, modifiedEndLineNumber, modifiedEndColumn); } } function postProcessCharChanges(rawChanges) { if (rawChanges.length <= 1) { return rawChanges; } const result = [rawChanges[0]]; let prevChange = result[0]; for (let i = 1, len = rawChanges.length; i < len; i++) { const currChange = rawChanges[i]; const originalMatchingLength = currChange.originalStart - (prevChange.originalStart + prevChange.originalLength); const modifiedMatchingLength = currChange.modifiedStart - (prevChange.modifiedStart + prevChange.modifiedLength); // Both of the above should be equal, but the continueProcessingPredicate may prevent this from being true const matchingLength = Math.min(originalMatchingLength, modifiedMatchingLength); if (matchingLength < MINIMUM_MATCHING_CHARACTER_LENGTH) { // Merge the current change into the previous one prevChange.originalLength = (currChange.originalStart + currChange.originalLength) - prevChange.originalStart; prevChange.modifiedLength = (currChange.modifiedStart + currChange.modifiedLength) - prevChange.modifiedStart; } else { // Add the current change result.push(currChange); prevChange = currChange; } } return result; } class LineChange { constructor(originalStartLineNumber, originalEndLineNumber, modifiedStartLineNumber, modifiedEndLineNumber, charChanges) { this.originalStartLineNumber = originalStartLineNumber; this.originalEndLineNumber = originalEndLineNumber; this.modifiedStartLineNumber = modifiedStartLineNumber; this.modifiedEndLineNumber = modifiedEndLineNumber; this.charChanges = charChanges; } static createFromDiffResult(shouldIgnoreTrimWhitespace, diffChange, originalLineSequence, modifiedLineSequence, continueCharDiff, shouldComputeCharChanges, shouldPostProcessCharChanges) { let originalStartLineNumber; let originalEndLineNumber; let modifiedStartLineNumber; let modifiedEndLineNumber; let charChanges = undefined; if (diffChange.originalLength === 0) { originalStartLineNumber = originalLineSequence.getStartLineNumber(diffChange.originalStart) - 1; originalEndLineNumber = 0; } else { originalStartLineNumber = originalLineSequence.getStartLineNumber(diffChange.originalStart); originalEndLineNumber = originalLineSequence.getEndLineNumber(diffChange.originalStart + diffChange.originalLength - 1); } if (diffChange.modifiedLength === 0) { modifiedStartLineNumber = modifiedLineSequence.getStartLineNumber(diffChange.modifiedStart) - 1; modifiedEndLineNumber = 0; } else { modifiedStartLineNumber = modifiedLineSequence.getStartLineNumber(diffChange.modifiedStart); modifiedEndLineNumber = modifiedLineSequence.getEndLineNumber(diffChange.modifiedStart + diffChange.modifiedLength - 1); } if (shouldComputeCharChanges && diffChange.originalLength > 0 && diffChange.originalLength < 20 && diffChange.modifiedLength > 0 && diffChange.modifiedLength < 20 && continueCharDiff()) { // Compute character changes for diff chunks of at most 20 lines... const originalCharSequence = originalLineSequence.createCharSequence(shouldIgnoreTrimWhitespace, diffChange.originalStart, diffChange.originalStart + diffChange.originalLength - 1); const modifiedCharSequence = modifiedLineSequence.createCharSequence(shouldIgnoreTrimWhitespace, diffChange.modifiedStart, diffChange.modifiedStart + diffChange.modifiedLength - 1); let rawChanges = computeDiff(originalCharSequence, modifiedCharSequence, continueCharDiff, true).changes; if (shouldPostProcessCharChanges) { rawChanges = postProcessCharChanges(rawChanges); } charChanges = []; for (let i = 0, length = rawChanges.length; i < length; i++) { charChanges.push(CharChange.createFromDiffChange(rawChanges[i], originalCharSequence, modifiedCharSequence)); } } return new LineChange(originalStartLineNumber, originalEndLineNumber, modifiedStartLineNumber, modifiedEndLineNumber, charChanges); } } class DiffComputer { constructor(originalLines, modifiedLines, opts) { this.shouldComputeCharChanges = opts.shouldComputeCharChanges; this.shouldPostProcessCharChanges = opts.shouldPostProcessCharChanges; this.shouldIgnoreTrimWhitespace = opts.shouldIgnoreTrimWhitespace; this.shouldMakePrettyDiff = opts.shouldMakePrettyDiff; this.originalLines = originalLines; this.modifiedLines = modifiedLines; this.original = new LineSequence(originalLines); this.modified = new LineSequence(modifiedLines); this.continueLineDiff = createContinueProcessingPredicate(opts.maxComputationTime); this.continueCharDiff = createContinueProcessingPredicate(opts.maxComputationTime === 0 ? 0 : Math.min(opts.maxComputationTime, 5000)); // never run after 5s for character changes... } computeDiff() { if (this.original.lines.length === 1 && this.original.lines[0].length === 0) { // empty original => fast path if (this.modified.lines.length === 1 && this.modified.lines[0].length === 0) { return { quitEarly: false, changes: [] }; } return { quitEarly: false, changes: [{ originalStartLineNumber: 1, originalEndLineNumber: 1, modifiedStartLineNumber: 1, modifiedEndLineNumber: this.modified.lines.length, charChanges: [{ modifiedEndColumn: 0, modifiedEndLineNumber: 0, modifiedStartColumn: 0, modifiedStartLineNumber: 0, originalEndColumn: 0, originalEndLineNumber: 0, originalStartColumn: 0, originalStartLineNumber: 0 }] }] }; } if (this.modified.lines.length === 1 && this.modified.lines[0].length === 0) { // empty modified => fast path return { quitEarly: false, changes: [{ originalStartLineNumber: 1, originalEndLineNumber: this.original.lines.length, modifiedStartLineNumber: 1, modifiedEndLineNumber: 1, charChanges: [{ modifiedEndColumn: 0, modifiedEndLineNumber: 0, modifiedStartColumn: 0, modifiedStartLineNumber: 0, originalEndColumn: 0, originalEndLineNumber: 0, originalStartColumn: 0, originalStartLineNumber: 0 }] }] }; } const diffResult = computeDiff(this.original, this.modified, this.continueLineDiff, this.shouldMakePrettyDiff); const rawChanges = diffResult.changes; const quitEarly = diffResult.quitEarly; // The diff is always computed with ignoring trim whitespace // This ensures we get the prettiest diff if (this.shouldIgnoreTrimWhitespace) { const lineChanges = []; for (let i = 0, length = rawChanges.length; i < length; i++) { lineChanges.push(LineChange.createFromDiffResult(this.shouldIgnoreTrimWhitespace, rawChanges[i], this.original, this.modified, this.continueCharDiff, this.shouldComputeCharChanges, this.shouldPostProcessCharChanges)); } return { quitEarly: quitEarly, changes: lineChanges }; } // Need to post-process and introduce changes where the trim whitespace is different // Note that we are looping starting at -1 to also cover the lines before the first change const result = []; let originalLineIndex = 0; let modifiedLineIndex = 0; for (let i = -1 /* !!!! */, len = rawChanges.length; i < len; i++) { const nextChange = (i + 1 < len ? rawChanges[i + 1] : null); const originalStop = (nextChange ? nextChange.originalStart : this.originalLines.length); const modifiedStop = (nextChange ? nextChange.modifiedStart : this.modifiedLines.length); while (originalLineIndex < originalStop && modifiedLineIndex < modifiedStop) { const originalLine = this.originalLines[originalLineIndex]; const modifiedLine = this.modifiedLines[modifiedLineIndex]; if (originalLine !== modifiedLine) { // These lines differ only in trim whitespace // Check the leading whitespace { let originalStartColumn = getFirstNonBlankColumn(originalLine, 1); let modifiedStartColumn = getFirstNonBlankColumn(modifiedLine, 1); while (originalStartColumn > 1 && modifiedStartColumn > 1) { const originalChar = originalLine.charCodeAt(originalStartColumn - 2); const modifiedChar = modifiedLine.charCodeAt(modifiedStartColumn - 2); if (originalChar !== modifiedChar) { break; } originalStartColumn--; modifiedStartColumn--; } if (originalStartColumn > 1 || modifiedStartColumn > 1) { this._pushTrimWhitespaceCharChange(result, originalLineIndex + 1, 1, originalStartColumn, modifiedLineIndex + 1, 1, modifiedStartColumn); } } // Check the trailing whitespace { let originalEndColumn = getLastNonBlankColumn(originalLine, 1); let modifiedEndColumn = getLastNonBlankColumn(modifiedLine, 1); const originalMaxColumn = originalLine.length + 1; const modifiedMaxColumn = modifiedLine.length + 1; while (originalEndColumn < originalMaxColumn && modifiedEndColumn < modifiedMaxColumn) { const originalChar = originalLine.charCodeAt(originalEndColumn - 1); const modifiedChar = originalLine.charCodeAt(modifiedEndColumn - 1); if (originalChar !== modifiedChar) { break; } originalEndColumn++; modifiedEndColumn++; } if (originalEndColumn < originalMaxColumn || modifiedEndColumn < modifiedMaxColumn) { this._pushTrimWhitespaceCharChange(result, originalLineIndex + 1, originalEndColumn, originalMaxColumn, modifiedLineIndex + 1, modifiedEndColumn, modifiedMaxColumn); } } } originalLineIndex++; modifiedLineIndex++; } if (nextChange) { // Emit the actual change result.push(LineChange.createFromDiffResult(this.shouldIgnoreTrimWhitespace, nextChange, this.original, this.modified, this.continueCharDiff, this.shouldComputeCharChanges, this.shouldPostProcessCharChanges)); originalLineIndex += nextChange.originalLength; modifiedLineIndex += nextChange.modifiedLength; } } return { quitEarly: quitEarly, changes: result }; } _pushTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn) { if (this._mergeTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn)) { // Merged into previous return; } let charChanges = undefined; if (this.shouldComputeCharChanges) { charChanges = [new CharChange(originalLineNumber, originalStartColumn, originalLineNumber, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedLineNumber, modifiedEndColumn)]; } result.push(new LineChange(originalLineNumber, originalLineNumber, modifiedLineNumber, modifiedLineNumber, charChanges)); } _mergeTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn) { const len = result.length; if (len === 0) { return false; } const prevChange = result[len - 1]; if (prevChange.originalEndLineNumber === 0 || prevChange.modifiedEndLineNumber === 0) { // Don't merge with inserts/deletes return false; } if (prevChange.originalEndLineNumber + 1 === originalLineNumber && prevChange.modifiedEndLineNumber + 1 === modifiedLineNumber) { prevChange.originalEndLineNumber = originalLineNumber; prevChange.modifiedEndLineNumber = modifiedLineNumber; if (this.shouldComputeCharChanges && prevChange.charChanges) { prevChange.charChanges.push(new CharChange(originalLineNumber, originalStartColumn, originalLineNumber, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedLineNumber, modifiedEndColumn)); } return true; } return false; } } function getFirstNonBlankColumn(txt, defaultValue) { const r = firstNonWhitespaceIndex(txt); if (r === -1) { return defaultValue; } return r + 1; } function getLastNonBlankColumn(txt, defaultValue) { const r = lastNonWhitespaceIndex(txt); if (r === -1) { return defaultValue; } return r + 2; } function createContinueProcessingPredicate(maximumRuntime) { if (maximumRuntime === 0) { return () => true; } const startTime = Date.now(); return () => { return Date.now() - startTime < maximumRuntime; }; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function toUint8(v) { if (v < 0) { return 0; } if (v > 255 /* MAX_UINT_8 */) { return 255 /* MAX_UINT_8 */; } return v | 0; } function toUint32(v) { if (v < 0) { return 0; } if (v > 4294967295 /* MAX_UINT_32 */) { return 4294967295 /* MAX_UINT_32 */; } return v | 0; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class PrefixSumComputer { constructor(values) { this.values = values; this.prefixSum = new Uint32Array(values.length); this.prefixSumValidIndex = new Int32Array(1); this.prefixSumValidIndex[0] = -1; } insertValues(insertIndex, insertValues) { insertIndex = toUint32(insertIndex); const oldValues = this.values; const oldPrefixSum = this.prefixSum; const insertValuesLen = insertValues.length; if (insertValuesLen === 0) { return false; } this.values = new Uint32Array(oldValues.length + insertValuesLen); this.values.set(oldValues.subarray(0, insertIndex), 0); this.values.set(oldValues.subarray(insertIndex), insertIndex + insertValuesLen); this.values.set(insertValues, insertIndex); if (insertIndex - 1 < this.prefixSumValidIndex[0]) { this.prefixSumValidIndex[0] = insertIndex - 1; } this.prefixSum = new Uint32Array(this.values.length); if (this.prefixSumValidIndex[0] >= 0) { this.prefixSum.set(oldPrefixSum.subarray(0, this.prefixSumValidIndex[0] + 1)); } return true; } setValue(index, value) { index = toUint32(index); value = toUint32(value); if (this.values[index] === value) { return false; } this.values[index] = value; if (index - 1 < this.prefixSumValidIndex[0]) { this.prefixSumValidIndex[0] = index - 1; } return true; } removeValues(startIndex, count) { startIndex = toUint32(startIndex); count = toUint32(count); const oldValues = this.values; const oldPrefixSum = this.prefixSum; if (startIndex >= oldValues.length) { return false; } const maxCount = oldValues.length - startIndex; if (count >= maxCount) { count = maxCount; } if (count === 0) { return false; } this.values = new Uint32Array(oldValues.length - count); this.values.set(oldValues.subarray(0, startIndex), 0); this.values.set(oldValues.subarray(startIndex + count), startIndex); this.prefixSum = new Uint32Array(this.values.length); if (startIndex - 1 < this.prefixSumValidIndex[0]) { this.prefixSumValidIndex[0] = startIndex - 1; } if (this.prefixSumValidIndex[0] >= 0) { this.prefixSum.set(oldPrefixSum.subarray(0, this.prefixSumValidIndex[0] + 1)); } return true; } getTotalSum() { if (this.values.length === 0) { return 0; } return this._getPrefixSum(this.values.length - 1); } /** * Returns the sum of the first `index + 1` many items. * @returns `SUM(0 <= j <= index, values[j])`. */ getPrefixSum(index) { if (index < 0) { return 0; } index = toUint32(index); return this._getPrefixSum(index); } _getPrefixSum(index) { if (index <= this.prefixSumValidIndex[0]) { return this.prefixSum[index]; } let startIndex = this.prefixSumValidIndex[0] + 1; if (startIndex === 0) { this.prefixSum[0] = this.values[0]; startIndex++; } if (index >= this.values.length) { index = this.values.length - 1; } for (let i = startIndex; i <= index; i++) { this.prefixSum[i] = this.prefixSum[i - 1] + this.values[i]; } this.prefixSumValidIndex[0] = Math.max(this.prefixSumValidIndex[0], index); return this.prefixSum[index]; } getIndexOf(sum) { sum = Math.floor(sum); // Compute all sums (to get a fully valid prefixSum) this.getTotalSum(); let low = 0; let high = this.values.length - 1; let mid = 0; let midStop = 0; let midStart = 0; while (low <= high) { mid = low + ((high - low) / 2) | 0; midStop = this.prefixSum[mid]; midStart = midStop - this.values[mid]; if (sum < midStart) { high = mid - 1; } else if (sum >= midStop) { low = mid + 1; } else { break; } } return new PrefixSumIndexOfResult(mid, sum - midStart); } } /** * {@link getIndexOf} has an amortized runtime complexity of O(1). * * ({@link PrefixSumComputer.getIndexOf} is just O(log n)) */ class ConstantTimePrefixSumComputer { constructor(values) { this._values = values; this._isValid = false; this._validEndIndex = -1; this._prefixSum = []; this._indexBySum = []; } /** * @returns SUM(0 <= j < values.length, values[j]) */ getTotalSum() { this._ensureValid(); return this._indexBySum.length; } /** * Returns the sum of the first `count` many items. * @returns `SUM(0 <= j < count, values[j])`. */ getPrefixSum(count) { this._ensureValid(); if (count === 0) { return 0; } return this._prefixSum[count - 1]; } /** * @returns `result`, such that `getPrefixSum(result.index) + result.remainder = sum` */ getIndexOf(sum) { this._ensureValid(); const idx = this._indexBySum[sum]; const viewLinesAbove = idx > 0 ? this._prefixSum[idx - 1] : 0; return new PrefixSumIndexOfResult(idx, sum - viewLinesAbove); } removeValues(start, deleteCount) { this._values.splice(start, deleteCount); this._invalidate(start); } insertValues(insertIndex, insertArr) { this._values = arrayInsert(this._values, insertIndex, insertArr); this._invalidate(insertIndex); } _invalidate(index) { this._isValid = false; this._validEndIndex = Math.min(this._validEndIndex, index - 1); } _ensureValid() { if (this._isValid) { return; } for (let i = this._validEndIndex + 1, len = this._values.length; i < len; i++) { const value = this._values[i]; const sumAbove = i > 0 ? this._prefixSum[i - 1] : 0; this._prefixSum[i] = sumAbove + value; for (let j = 0; j < value; j++) { this._indexBySum[sumAbove + j] = i; } } // trim things this._prefixSum.length = this._values.length; this._indexBySum.length = this._prefixSum[this._prefixSum.length - 1]; // mark as valid this._isValid = true; this._validEndIndex = this._values.length - 1; } setValue(index, value) { if (this._values[index] === value) { // no change return; } this._values[index] = value; this._invalidate(index); } } class PrefixSumIndexOfResult { constructor(index, remainder) { this.index = index; this.remainder = remainder; this._prefixSumIndexOfResultBrand = undefined; this.index = index; this.remainder = remainder; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class MirrorTextModel { constructor(uri, lines, eol, versionId) { this._uri = uri; this._lines = lines; this._eol = eol; this._versionId = versionId; this._lineStarts = null; this._cachedTextValue = null; } dispose() { this._lines.length = 0; } get version() { return this._versionId; } getText() { if (this._cachedTextValue === null) { this._cachedTextValue = this._lines.join(this._eol); } return this._cachedTextValue; } onEvents(e) { if (e.eol && e.eol !== this._eol) { this._eol = e.eol; this._lineStarts = null; } // Update my lines const changes = e.changes; for (const change of changes) { this._acceptDeleteRange(change.range); this._acceptInsertText(new Position$4(change.range.startLineNumber, change.range.startColumn), change.text); } this._versionId = e.versionId; this._cachedTextValue = null; } _ensureLineStarts() { if (!this._lineStarts) { const eolLength = this._eol.length; const linesLength = this._lines.length; const lineStartValues = new Uint32Array(linesLength); for (let i = 0; i < linesLength; i++) { lineStartValues[i] = this._lines[i].length + eolLength; } this._lineStarts = new PrefixSumComputer(lineStartValues); } } /** * All changes to a line's text go through this method */ _setLineText(lineIndex, newValue) { this._lines[lineIndex] = newValue; if (this._lineStarts) { // update prefix sum this._lineStarts.setValue(lineIndex, this._lines[lineIndex].length + this._eol.length); } } _acceptDeleteRange(range) { if (range.startLineNumber === range.endLineNumber) { if (range.startColumn === range.endColumn) { // Nothing to delete return; } // Delete text on the affected line this._setLineText(range.startLineNumber - 1, this._lines[range.startLineNumber - 1].substring(0, range.startColumn - 1) + this._lines[range.startLineNumber - 1].substring(range.endColumn - 1)); return; } // Take remaining text on last line and append it to remaining text on first line this._setLineText(range.startLineNumber - 1, this._lines[range.startLineNumber - 1].substring(0, range.startColumn - 1) + this._lines[range.endLineNumber - 1].substring(range.endColumn - 1)); // Delete middle lines this._lines.splice(range.startLineNumber, range.endLineNumber - range.startLineNumber); if (this._lineStarts) { // update prefix sum this._lineStarts.removeValues(range.startLineNumber, range.endLineNumber - range.startLineNumber); } } _acceptInsertText(position, insertText) { if (insertText.length === 0) { // Nothing to insert return; } const insertLines = splitLines(insertText); if (insertLines.length === 1) { // Inserting text on one line this._setLineText(position.lineNumber - 1, this._lines[position.lineNumber - 1].substring(0, position.column - 1) + insertLines[0] + this._lines[position.lineNumber - 1].substring(position.column - 1)); return; } // Append overflowing text from first line to the end of text to insert insertLines[insertLines.length - 1] += this._lines[position.lineNumber - 1].substring(position.column - 1); // Delete overflowing text from first line and insert text on first line this._setLineText(position.lineNumber - 1, this._lines[position.lineNumber - 1].substring(0, position.column - 1) + insertLines[0]); // Insert new lines & store lengths const newLengths = new Uint32Array(insertLines.length - 1); for (let i = 1; i < insertLines.length; i++) { this._lines.splice(position.lineNumber + i - 1, 0, insertLines[i]); newLengths[i - 1] = insertLines[i].length + this._eol.length; } if (this._lineStarts) { // update prefix sum this._lineStarts.insertValues(position.lineNumber, newLengths); } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * A fast character classifier that uses a compact array for ASCII values. */ class CharacterClassifier { constructor(_defaultValue) { const defaultValue = toUint8(_defaultValue); this._defaultValue = defaultValue; this._asciiMap = CharacterClassifier._createAsciiMap(defaultValue); this._map = new Map(); } static _createAsciiMap(defaultValue) { const asciiMap = new Uint8Array(256); for (let i = 0; i < 256; i++) { asciiMap[i] = defaultValue; } return asciiMap; } set(charCode, _value) { const value = toUint8(_value); if (charCode >= 0 && charCode < 256) { this._asciiMap[charCode] = value; } else { this._map.set(charCode, value); } } get(charCode) { if (charCode >= 0 && charCode < 256) { return this._asciiMap[charCode]; } else { return (this._map.get(charCode) || this._defaultValue); } } } class CharacterSet { constructor() { this._actual = new CharacterClassifier(0 /* False */); } add(charCode) { this._actual.set(charCode, 1 /* True */); } has(charCode) { return (this._actual.get(charCode) === 1 /* True */); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class Uint8Matrix { constructor(rows, cols, defaultValue) { const data = new Uint8Array(rows * cols); for (let i = 0, len = rows * cols; i < len; i++) { data[i] = defaultValue; } this._data = data; this.rows = rows; this.cols = cols; } get(row, col) { return this._data[row * this.cols + col]; } set(row, col, value) { this._data[row * this.cols + col] = value; } } class StateMachine { constructor(edges) { let maxCharCode = 0; let maxState = 0 /* Invalid */; for (let i = 0, len = edges.length; i < len; i++) { const [from, chCode, to] = edges[i]; if (chCode > maxCharCode) { maxCharCode = chCode; } if (from > maxState) { maxState = from; } if (to > maxState) { maxState = to; } } maxCharCode++; maxState++; const states = new Uint8Matrix(maxState, maxCharCode, 0 /* Invalid */); for (let i = 0, len = edges.length; i < len; i++) { const [from, chCode, to] = edges[i]; states.set(from, chCode, to); } this._states = states; this._maxCharCode = maxCharCode; } nextState(currentState, chCode) { if (chCode < 0 || chCode >= this._maxCharCode) { return 0 /* Invalid */; } return this._states.get(currentState, chCode); } } // State machine for http:// or https:// or file:// let _stateMachine = null; function getStateMachine() { if (_stateMachine === null) { _stateMachine = new StateMachine([ [1 /* Start */, 104 /* h */, 2 /* H */], [1 /* Start */, 72 /* H */, 2 /* H */], [1 /* Start */, 102 /* f */, 6 /* F */], [1 /* Start */, 70 /* F */, 6 /* F */], [2 /* H */, 116 /* t */, 3 /* HT */], [2 /* H */, 84 /* T */, 3 /* HT */], [3 /* HT */, 116 /* t */, 4 /* HTT */], [3 /* HT */, 84 /* T */, 4 /* HTT */], [4 /* HTT */, 112 /* p */, 5 /* HTTP */], [4 /* HTT */, 80 /* P */, 5 /* HTTP */], [5 /* HTTP */, 115 /* s */, 9 /* BeforeColon */], [5 /* HTTP */, 83 /* S */, 9 /* BeforeColon */], [5 /* HTTP */, 58 /* Colon */, 10 /* AfterColon */], [6 /* F */, 105 /* i */, 7 /* FI */], [6 /* F */, 73 /* I */, 7 /* FI */], [7 /* FI */, 108 /* l */, 8 /* FIL */], [7 /* FI */, 76 /* L */, 8 /* FIL */], [8 /* FIL */, 101 /* e */, 9 /* BeforeColon */], [8 /* FIL */, 69 /* E */, 9 /* BeforeColon */], [9 /* BeforeColon */, 58 /* Colon */, 10 /* AfterColon */], [10 /* AfterColon */, 47 /* Slash */, 11 /* AlmostThere */], [11 /* AlmostThere */, 47 /* Slash */, 12 /* End */], ]); } return _stateMachine; } let _classifier = null; function getClassifier() { if (_classifier === null) { _classifier = new CharacterClassifier(0 /* None */); // allow-any-unicode-next-line const FORCE_TERMINATION_CHARACTERS = ' \t<>\'\"、。。、,.:;‘〈「『〔([{「」}])〕』」〉’`~…'; for (let i = 0; i < FORCE_TERMINATION_CHARACTERS.length; i++) { _classifier.set(FORCE_TERMINATION_CHARACTERS.charCodeAt(i), 1 /* ForceTermination */); } const CANNOT_END_WITH_CHARACTERS = '.,;'; for (let i = 0; i < CANNOT_END_WITH_CHARACTERS.length; i++) { _classifier.set(CANNOT_END_WITH_CHARACTERS.charCodeAt(i), 2 /* CannotEndIn */); } } return _classifier; } class LinkComputer { static _createLink(classifier, line, lineNumber, linkBeginIndex, linkEndIndex) { // Do not allow to end link in certain characters... let lastIncludedCharIndex = linkEndIndex - 1; do { const chCode = line.charCodeAt(lastIncludedCharIndex); const chClass = classifier.get(chCode); if (chClass !== 2 /* CannotEndIn */) { break; } lastIncludedCharIndex--; } while (lastIncludedCharIndex > linkBeginIndex); // Handle links enclosed in parens, square brackets and curlys. if (linkBeginIndex > 0) { const charCodeBeforeLink = line.charCodeAt(linkBeginIndex - 1); const lastCharCodeInLink = line.charCodeAt(lastIncludedCharIndex); if ((charCodeBeforeLink === 40 /* OpenParen */ && lastCharCodeInLink === 41 /* CloseParen */) || (charCodeBeforeLink === 91 /* OpenSquareBracket */ && lastCharCodeInLink === 93 /* CloseSquareBracket */) || (charCodeBeforeLink === 123 /* OpenCurlyBrace */ && lastCharCodeInLink === 125 /* CloseCurlyBrace */)) { // Do not end in ) if ( is before the link start // Do not end in ] if [ is before the link start // Do not end in } if { is before the link start lastIncludedCharIndex--; } } return { range: { startLineNumber: lineNumber, startColumn: linkBeginIndex + 1, endLineNumber: lineNumber, endColumn: lastIncludedCharIndex + 2 }, url: line.substring(linkBeginIndex, lastIncludedCharIndex + 1) }; } static computeLinks(model, stateMachine = getStateMachine()) { const classifier = getClassifier(); const result = []; for (let i = 1, lineCount = model.getLineCount(); i <= lineCount; i++) { const line = model.getLineContent(i); const len = line.length; let j = 0; let linkBeginIndex = 0; let linkBeginChCode = 0; let state = 1 /* Start */; let hasOpenParens = false; let hasOpenSquareBracket = false; let inSquareBrackets = false; let hasOpenCurlyBracket = false; while (j < len) { let resetStateMachine = false; const chCode = line.charCodeAt(j); if (state === 13 /* Accept */) { let chClass; switch (chCode) { case 40 /* OpenParen */: hasOpenParens = true; chClass = 0 /* None */; break; case 41 /* CloseParen */: chClass = (hasOpenParens ? 0 /* None */ : 1 /* ForceTermination */); break; case 91 /* OpenSquareBracket */: inSquareBrackets = true; hasOpenSquareBracket = true; chClass = 0 /* None */; break; case 93 /* CloseSquareBracket */: inSquareBrackets = false; chClass = (hasOpenSquareBracket ? 0 /* None */ : 1 /* ForceTermination */); break; case 123 /* OpenCurlyBrace */: hasOpenCurlyBracket = true; chClass = 0 /* None */; break; case 125 /* CloseCurlyBrace */: chClass = (hasOpenCurlyBracket ? 0 /* None */ : 1 /* ForceTermination */); break; /* The following three rules make it that ' or " or ` are allowed inside links if the link began with a different one */ case 39 /* SingleQuote */: chClass = (linkBeginChCode === 34 /* DoubleQuote */ || linkBeginChCode === 96 /* BackTick */) ? 0 /* None */ : 1 /* ForceTermination */; break; case 34 /* DoubleQuote */: chClass = (linkBeginChCode === 39 /* SingleQuote */ || linkBeginChCode === 96 /* BackTick */) ? 0 /* None */ : 1 /* ForceTermination */; break; case 96 /* BackTick */: chClass = (linkBeginChCode === 39 /* SingleQuote */ || linkBeginChCode === 34 /* DoubleQuote */) ? 0 /* None */ : 1 /* ForceTermination */; break; case 42 /* Asterisk */: // `*` terminates a link if the link began with `*` chClass = (linkBeginChCode === 42 /* Asterisk */) ? 1 /* ForceTermination */ : 0 /* None */; break; case 124 /* Pipe */: // `|` terminates a link if the link began with `|` chClass = (linkBeginChCode === 124 /* Pipe */) ? 1 /* ForceTermination */ : 0 /* None */; break; case 32 /* Space */: // ` ` allow space in between [ and ] chClass = (inSquareBrackets ? 0 /* None */ : 1 /* ForceTermination */); break; default: chClass = classifier.get(chCode); } // Check if character terminates link if (chClass === 1 /* ForceTermination */) { result.push(LinkComputer._createLink(classifier, line, i, linkBeginIndex, j)); resetStateMachine = true; } } else if (state === 12 /* End */) { let chClass; if (chCode === 91 /* OpenSquareBracket */) { // Allow for the authority part to contain ipv6 addresses which contain [ and ] hasOpenSquareBracket = true; chClass = 0 /* None */; } else { chClass = classifier.get(chCode); } // Check if character terminates link if (chClass === 1 /* ForceTermination */) { resetStateMachine = true; } else { state = 13 /* Accept */; } } else { state = stateMachine.nextState(state, chCode); if (state === 0 /* Invalid */) { resetStateMachine = true; } } if (resetStateMachine) { state = 1 /* Start */; hasOpenParens = false; hasOpenSquareBracket = false; hasOpenCurlyBracket = false; // Record where the link started linkBeginIndex = j + 1; linkBeginChCode = chCode; } j++; } if (state === 13 /* Accept */) { result.push(LinkComputer._createLink(classifier, line, i, linkBeginIndex, len)); } } return result; } } /** * Returns an array of all links contains in the provided * document. *Note* that this operation is computational * expensive and should not run in the UI thread. */ function computeLinks(model) { if (!model || typeof model.getLineCount !== 'function' || typeof model.getLineContent !== 'function') { // Unknown caller! return []; } return LinkComputer.computeLinks(model); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class BasicInplaceReplace { constructor() { this._defaultValueSet = [ ['true', 'false'], ['True', 'False'], ['Private', 'Public', 'Friend', 'ReadOnly', 'Partial', 'Protected', 'WriteOnly'], ['public', 'protected', 'private'], ]; } navigateValueSet(range1, text1, range2, text2, up) { if (range1 && text1) { const result = this.doNavigateValueSet(text1, up); if (result) { return { range: range1, value: result }; } } if (range2 && text2) { const result = this.doNavigateValueSet(text2, up); if (result) { return { range: range2, value: result }; } } return null; } doNavigateValueSet(text, up) { const numberResult = this.numberReplace(text, up); if (numberResult !== null) { return numberResult; } return this.textReplace(text, up); } numberReplace(value, up) { const precision = Math.pow(10, value.length - (value.lastIndexOf('.') + 1)); let n1 = Number(value); let n2 = parseFloat(value); if (!isNaN(n1) && !isNaN(n2) && n1 === n2) { if (n1 === 0 && !up) { return null; // don't do negative // } else if(n1 === 9 && up) { // return null; // don't insert 10 into a number } else { n1 = Math.floor(n1 * precision); n1 += up ? precision : -precision; return String(n1 / precision); } } return null; } textReplace(value, up) { return this.valueSetsReplace(this._defaultValueSet, value, up); } valueSetsReplace(valueSets, value, up) { let result = null; for (let i = 0, len = valueSets.length; result === null && i < len; i++) { result = this.valueSetReplace(valueSets[i], value, up); } return result; } valueSetReplace(valueSet, value, up) { let idx = valueSet.indexOf(value); if (idx >= 0) { idx += up ? +1 : -1; if (idx < 0) { idx = valueSet.length - 1; } else { idx %= valueSet.length; } return valueSet[idx]; } return null; } } BasicInplaceReplace.INSTANCE = new BasicInplaceReplace(); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class WordCharacterClassifier extends CharacterClassifier { constructor(wordSeparators) { super(0 /* Regular */); for (let i = 0, len = wordSeparators.length; i < len; i++) { this.set(wordSeparators.charCodeAt(i), 2 /* WordSeparator */); } this.set(32 /* Space */, 1 /* Whitespace */); this.set(9 /* Tab */, 1 /* Whitespace */); } } function once(computeFn) { const cache = {}; // TODO@Alex unbounded cache return (input) => { if (!cache.hasOwnProperty(input)) { cache[input] = computeFn(input); } return cache[input]; }; } const getMapForWordSeparators = once((input) => new WordCharacterClassifier(input)); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const LIMIT_FIND_COUNT$1 = 999; class SearchParams { constructor(searchString, isRegex, matchCase, wordSeparators) { this.searchString = searchString; this.isRegex = isRegex; this.matchCase = matchCase; this.wordSeparators = wordSeparators; } parseSearchRequest() { if (this.searchString === '') { return null; } // Try to create a RegExp out of the params let multiline; if (this.isRegex) { multiline = isMultilineRegexSource(this.searchString); } else { multiline = (this.searchString.indexOf('\n') >= 0); } let regex = null; try { regex = createRegExp(this.searchString, this.isRegex, { matchCase: this.matchCase, wholeWord: false, multiline: multiline, global: true, unicode: true }); } catch (err) { return null; } if (!regex) { return null; } let canUseSimpleSearch = (!this.isRegex && !multiline); if (canUseSimpleSearch && this.searchString.toLowerCase() !== this.searchString.toUpperCase()) { // casing might make a difference canUseSimpleSearch = this.matchCase; } return new SearchData(regex, this.wordSeparators ? getMapForWordSeparators(this.wordSeparators) : null, canUseSimpleSearch ? this.searchString : null); } } function isMultilineRegexSource(searchString) { if (!searchString || searchString.length === 0) { return false; } for (let i = 0, len = searchString.length; i < len; i++) { const chCode = searchString.charCodeAt(i); if (chCode === 92 /* Backslash */) { // move to next char i++; if (i >= len) { // string ends with a \ break; } const nextChCode = searchString.charCodeAt(i); if (nextChCode === 110 /* n */ || nextChCode === 114 /* r */ || nextChCode === 87 /* W */) { return true; } } } return false; } function createFindMatch(range, rawMatches, captureMatches) { if (!captureMatches) { return new FindMatch(range, null); } const matches = []; for (let i = 0, len = rawMatches.length; i < len; i++) { matches[i] = rawMatches[i]; } return new FindMatch(range, matches); } class LineFeedCounter { constructor(text) { const lineFeedsOffsets = []; let lineFeedsOffsetsLen = 0; for (let i = 0, textLen = text.length; i < textLen; i++) { if (text.charCodeAt(i) === 10 /* LineFeed */) { lineFeedsOffsets[lineFeedsOffsetsLen++] = i; } } this._lineFeedsOffsets = lineFeedsOffsets; } findLineFeedCountBeforeOffset(offset) { const lineFeedsOffsets = this._lineFeedsOffsets; let min = 0; let max = lineFeedsOffsets.length - 1; if (max === -1) { // no line feeds return 0; } if (offset <= lineFeedsOffsets[0]) { // before first line feed return 0; } while (min < max) { const mid = min + ((max - min) / 2 >> 0); if (lineFeedsOffsets[mid] >= offset) { max = mid - 1; } else { if (lineFeedsOffsets[mid + 1] >= offset) { // bingo! min = mid; max = mid; } else { min = mid + 1; } } } return min + 1; } } class TextModelSearch { static findMatches(model, searchParams, searchRange, captureMatches, limitResultCount) { const searchData = searchParams.parseSearchRequest(); if (!searchData) { return []; } if (searchData.regex.multiline) { return this._doFindMatchesMultiline(model, searchRange, new Searcher(searchData.wordSeparators, searchData.regex), captureMatches, limitResultCount); } return this._doFindMatchesLineByLine(model, searchRange, searchData, captureMatches, limitResultCount); } /** * Multiline search always executes on the lines concatenated with \n. * We must therefore compensate for the count of \n in case the model is CRLF */ static _getMultilineMatchRange(model, deltaOffset, text, lfCounter, matchIndex, match0) { let startOffset; let lineFeedCountBeforeMatch = 0; if (lfCounter) { lineFeedCountBeforeMatch = lfCounter.findLineFeedCountBeforeOffset(matchIndex); startOffset = deltaOffset + matchIndex + lineFeedCountBeforeMatch /* add as many \r as there were \n */; } else { startOffset = deltaOffset + matchIndex; } let endOffset; if (lfCounter) { const lineFeedCountBeforeEndOfMatch = lfCounter.findLineFeedCountBeforeOffset(matchIndex + match0.length); const lineFeedCountInMatch = lineFeedCountBeforeEndOfMatch - lineFeedCountBeforeMatch; endOffset = startOffset + match0.length + lineFeedCountInMatch /* add as many \r as there were \n */; } else { endOffset = startOffset + match0.length; } const startPosition = model.getPositionAt(startOffset); const endPosition = model.getPositionAt(endOffset); return new Range$5(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column); } static _doFindMatchesMultiline(model, searchRange, searcher, captureMatches, limitResultCount) { const deltaOffset = model.getOffsetAt(searchRange.getStartPosition()); // We always execute multiline search over the lines joined with \n // This makes it that \n will match the EOL for both CRLF and LF models // We compensate for offset errors in `_getMultilineMatchRange` const text = model.getValueInRange(searchRange, 1 /* LF */); const lfCounter = (model.getEOL() === '\r\n' ? new LineFeedCounter(text) : null); const result = []; let counter = 0; let m; searcher.reset(0); while ((m = searcher.next(text))) { result[counter++] = createFindMatch(this._getMultilineMatchRange(model, deltaOffset, text, lfCounter, m.index, m[0]), m, captureMatches); if (counter >= limitResultCount) { return result; } } return result; } static _doFindMatchesLineByLine(model, searchRange, searchData, captureMatches, limitResultCount) { const result = []; let resultLen = 0; // Early case for a search range that starts & stops on the same line number if (searchRange.startLineNumber === searchRange.endLineNumber) { const text = model.getLineContent(searchRange.startLineNumber).substring(searchRange.startColumn - 1, searchRange.endColumn - 1); resultLen = this._findMatchesInLine(searchData, text, searchRange.startLineNumber, searchRange.startColumn - 1, resultLen, result, captureMatches, limitResultCount); return result; } // Collect results from first line const text = model.getLineContent(searchRange.startLineNumber).substring(searchRange.startColumn - 1); resultLen = this._findMatchesInLine(searchData, text, searchRange.startLineNumber, searchRange.startColumn - 1, resultLen, result, captureMatches, limitResultCount); // Collect results from middle lines for (let lineNumber = searchRange.startLineNumber + 1; lineNumber < searchRange.endLineNumber && resultLen < limitResultCount; lineNumber++) { resultLen = this._findMatchesInLine(searchData, model.getLineContent(lineNumber), lineNumber, 0, resultLen, result, captureMatches, limitResultCount); } // Collect results from last line if (resultLen < limitResultCount) { const text = model.getLineContent(searchRange.endLineNumber).substring(0, searchRange.endColumn - 1); resultLen = this._findMatchesInLine(searchData, text, searchRange.endLineNumber, 0, resultLen, result, captureMatches, limitResultCount); } return result; } static _findMatchesInLine(searchData, text, lineNumber, deltaOffset, resultLen, result, captureMatches, limitResultCount) { const wordSeparators = searchData.wordSeparators; if (!captureMatches && searchData.simpleSearch) { const searchString = searchData.simpleSearch; const searchStringLen = searchString.length; const textLength = text.length; let lastMatchIndex = -searchStringLen; while ((lastMatchIndex = text.indexOf(searchString, lastMatchIndex + searchStringLen)) !== -1) { if (!wordSeparators || isValidMatch(wordSeparators, text, textLength, lastMatchIndex, searchStringLen)) { result[resultLen++] = new FindMatch(new Range$5(lineNumber, lastMatchIndex + 1 + deltaOffset, lineNumber, lastMatchIndex + 1 + searchStringLen + deltaOffset), null); if (resultLen >= limitResultCount) { return resultLen; } } } return resultLen; } const searcher = new Searcher(searchData.wordSeparators, searchData.regex); let m; // Reset regex to search from the beginning searcher.reset(0); do { m = searcher.next(text); if (m) { result[resultLen++] = createFindMatch(new Range$5(lineNumber, m.index + 1 + deltaOffset, lineNumber, m.index + 1 + m[0].length + deltaOffset), m, captureMatches); if (resultLen >= limitResultCount) { return resultLen; } } } while (m); return resultLen; } static findNextMatch(model, searchParams, searchStart, captureMatches) { const searchData = searchParams.parseSearchRequest(); if (!searchData) { return null; } const searcher = new Searcher(searchData.wordSeparators, searchData.regex); if (searchData.regex.multiline) { return this._doFindNextMatchMultiline(model, searchStart, searcher, captureMatches); } return this._doFindNextMatchLineByLine(model, searchStart, searcher, captureMatches); } static _doFindNextMatchMultiline(model, searchStart, searcher, captureMatches) { const searchTextStart = new Position$4(searchStart.lineNumber, 1); const deltaOffset = model.getOffsetAt(searchTextStart); const lineCount = model.getLineCount(); // We always execute multiline search over the lines joined with \n // This makes it that \n will match the EOL for both CRLF and LF models // We compensate for offset errors in `_getMultilineMatchRange` const text = model.getValueInRange(new Range$5(searchTextStart.lineNumber, searchTextStart.column, lineCount, model.getLineMaxColumn(lineCount)), 1 /* LF */); const lfCounter = (model.getEOL() === '\r\n' ? new LineFeedCounter(text) : null); searcher.reset(searchStart.column - 1); let m = searcher.next(text); if (m) { return createFindMatch(this._getMultilineMatchRange(model, deltaOffset, text, lfCounter, m.index, m[0]), m, captureMatches); } if (searchStart.lineNumber !== 1 || searchStart.column !== 1) { // Try again from the top return this._doFindNextMatchMultiline(model, new Position$4(1, 1), searcher, captureMatches); } return null; } static _doFindNextMatchLineByLine(model, searchStart, searcher, captureMatches) { const lineCount = model.getLineCount(); const startLineNumber = searchStart.lineNumber; // Look in first line const text = model.getLineContent(startLineNumber); const r = this._findFirstMatchInLine(searcher, text, startLineNumber, searchStart.column, captureMatches); if (r) { return r; } for (let i = 1; i <= lineCount; i++) { const lineIndex = (startLineNumber + i - 1) % lineCount; const text = model.getLineContent(lineIndex + 1); const r = this._findFirstMatchInLine(searcher, text, lineIndex + 1, 1, captureMatches); if (r) { return r; } } return null; } static _findFirstMatchInLine(searcher, text, lineNumber, fromColumn, captureMatches) { // Set regex to search from column searcher.reset(fromColumn - 1); const m = searcher.next(text); if (m) { return createFindMatch(new Range$5(lineNumber, m.index + 1, lineNumber, m.index + 1 + m[0].length), m, captureMatches); } return null; } static findPreviousMatch(model, searchParams, searchStart, captureMatches) { const searchData = searchParams.parseSearchRequest(); if (!searchData) { return null; } const searcher = new Searcher(searchData.wordSeparators, searchData.regex); if (searchData.regex.multiline) { return this._doFindPreviousMatchMultiline(model, searchStart, searcher, captureMatches); } return this._doFindPreviousMatchLineByLine(model, searchStart, searcher, captureMatches); } static _doFindPreviousMatchMultiline(model, searchStart, searcher, captureMatches) { const matches = this._doFindMatchesMultiline(model, new Range$5(1, 1, searchStart.lineNumber, searchStart.column), searcher, captureMatches, 10 * LIMIT_FIND_COUNT$1); if (matches.length > 0) { return matches[matches.length - 1]; } const lineCount = model.getLineCount(); if (searchStart.lineNumber !== lineCount || searchStart.column !== model.getLineMaxColumn(lineCount)) { // Try again with all content return this._doFindPreviousMatchMultiline(model, new Position$4(lineCount, model.getLineMaxColumn(lineCount)), searcher, captureMatches); } return null; } static _doFindPreviousMatchLineByLine(model, searchStart, searcher, captureMatches) { const lineCount = model.getLineCount(); const startLineNumber = searchStart.lineNumber; // Look in first line const text = model.getLineContent(startLineNumber).substring(0, searchStart.column - 1); const r = this._findLastMatchInLine(searcher, text, startLineNumber, captureMatches); if (r) { return r; } for (let i = 1; i <= lineCount; i++) { const lineIndex = (lineCount + startLineNumber - i - 1) % lineCount; const text = model.getLineContent(lineIndex + 1); const r = this._findLastMatchInLine(searcher, text, lineIndex + 1, captureMatches); if (r) { return r; } } return null; } static _findLastMatchInLine(searcher, text, lineNumber, captureMatches) { let bestResult = null; let m; searcher.reset(0); while ((m = searcher.next(text))) { bestResult = createFindMatch(new Range$5(lineNumber, m.index + 1, lineNumber, m.index + 1 + m[0].length), m, captureMatches); } return bestResult; } } function leftIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength) { if (matchStartIndex === 0) { // Match starts at start of string return true; } const charBefore = text.charCodeAt(matchStartIndex - 1); if (wordSeparators.get(charBefore) !== 0 /* Regular */) { // The character before the match is a word separator return true; } if (charBefore === 13 /* CarriageReturn */ || charBefore === 10 /* LineFeed */) { // The character before the match is line break or carriage return. return true; } if (matchLength > 0) { const firstCharInMatch = text.charCodeAt(matchStartIndex); if (wordSeparators.get(firstCharInMatch) !== 0 /* Regular */) { // The first character inside the match is a word separator return true; } } return false; } function rightIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength) { if (matchStartIndex + matchLength === textLength) { // Match ends at end of string return true; } const charAfter = text.charCodeAt(matchStartIndex + matchLength); if (wordSeparators.get(charAfter) !== 0 /* Regular */) { // The character after the match is a word separator return true; } if (charAfter === 13 /* CarriageReturn */ || charAfter === 10 /* LineFeed */) { // The character after the match is line break or carriage return. return true; } if (matchLength > 0) { const lastCharInMatch = text.charCodeAt(matchStartIndex + matchLength - 1); if (wordSeparators.get(lastCharInMatch) !== 0 /* Regular */) { // The last character in the match is a word separator return true; } } return false; } function isValidMatch(wordSeparators, text, textLength, matchStartIndex, matchLength) { return (leftIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength) && rightIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength)); } class Searcher { constructor(wordSeparators, searchRegex) { this._wordSeparators = wordSeparators; this._searchRegex = searchRegex; this._prevMatchStartIndex = -1; this._prevMatchLength = 0; } reset(lastIndex) { this._searchRegex.lastIndex = lastIndex; this._prevMatchStartIndex = -1; this._prevMatchLength = 0; } next(text) { const textLength = text.length; let m; do { if (this._prevMatchStartIndex + this._prevMatchLength === textLength) { // Reached the end of the line return null; } m = this._searchRegex.exec(text); if (!m) { return null; } const matchStartIndex = m.index; const matchLength = m[0].length; if (matchStartIndex === this._prevMatchStartIndex && matchLength === this._prevMatchLength) { if (matchLength === 0) { // the search result is an empty string and won't advance `regex.lastIndex`, so `regex.exec` will stuck here // we attempt to recover from that by advancing by two if surrogate pair found and by one otherwise if (getNextCodePoint(text, textLength, this._searchRegex.lastIndex) > 0xFFFF) { this._searchRegex.lastIndex += 2; } else { this._searchRegex.lastIndex += 1; } continue; } // Exit early if the regex matches the same range twice return null; } this._prevMatchStartIndex = matchStartIndex; this._prevMatchLength = matchLength; if (!this._wordSeparators || isValidMatch(this._wordSeparators, text, textLength, matchStartIndex, matchLength)) { return m; } } while (m); return null; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class UnicodeTextModelHighlighter { static computeUnicodeHighlights(model, options, range) { const startLine = range ? range.startLineNumber : 1; const endLine = range ? range.endLineNumber : model.getLineCount(); const codePointHighlighter = new CodePointHighlighter(options); const candidates = codePointHighlighter.getCandidateCodePoints(); let regex; if (candidates === 'allNonBasicAscii') { regex = new RegExp('[^\\t\\n\\r\\x20-\\x7E]', 'g'); } else { regex = new RegExp(`${buildRegExpCharClassExpr(Array.from(candidates))}`, 'g'); } const searcher = new Searcher(null, regex); const ranges = []; let hasMore = false; let m; let ambiguousCharacterCount = 0; let invisibleCharacterCount = 0; let nonBasicAsciiCharacterCount = 0; forLoop: for (let lineNumber = startLine, lineCount = endLine; lineNumber <= lineCount; lineNumber++) { const lineContent = model.getLineContent(lineNumber); const lineLength = lineContent.length; // Reset regex to search from the beginning searcher.reset(0); do { m = searcher.next(lineContent); if (m) { let startIndex = m.index; let endIndex = m.index + m[0].length; // Extend range to entire code point if (startIndex > 0) { const charCodeBefore = lineContent.charCodeAt(startIndex - 1); if (isHighSurrogate(charCodeBefore)) { startIndex--; } } if (endIndex + 1 < lineLength) { const charCodeBefore = lineContent.charCodeAt(endIndex - 1); if (isHighSurrogate(charCodeBefore)) { endIndex++; } } const str = lineContent.substring(startIndex, endIndex); const highlightReason = codePointHighlighter.shouldHighlightNonBasicASCII(str); if (highlightReason !== 0 /* None */) { if (highlightReason === 3 /* Ambiguous */) { ambiguousCharacterCount++; } else if (highlightReason === 2 /* Invisible */) { invisibleCharacterCount++; } else if (highlightReason === 1 /* NonBasicASCII */) { nonBasicAsciiCharacterCount++; } else { assertNever(); } const MAX_RESULT_LENGTH = 1000; if (ranges.length >= MAX_RESULT_LENGTH) { hasMore = true; break forLoop; } ranges.push(new Range$5(lineNumber, startIndex + 1, lineNumber, endIndex + 1)); } } } while (m); } return { ranges, hasMore, ambiguousCharacterCount, invisibleCharacterCount, nonBasicAsciiCharacterCount }; } static computeUnicodeHighlightReason(char, options) { const codePointHighlighter = new CodePointHighlighter(options); const reason = codePointHighlighter.shouldHighlightNonBasicASCII(char); switch (reason) { case 0 /* None */: return null; case 2 /* Invisible */: return { kind: 1 /* Invisible */ }; case 3 /* Ambiguous */: { const codePoint = char.codePointAt(0); const primaryConfusable = codePointHighlighter.ambiguousCharacters.getPrimaryConfusable(codePoint); const notAmbiguousInLocales = AmbiguousCharacters.getLocales().filter((l) => !AmbiguousCharacters.getInstance(new Set([...options.allowedLocales, l])).isAmbiguous(codePoint)); return { kind: 0 /* Ambiguous */, confusableWith: String.fromCodePoint(primaryConfusable), notAmbiguousInLocales }; } case 1 /* NonBasicASCII */: return { kind: 2 /* NonBasicAscii */ }; } } } function buildRegExpCharClassExpr(codePoints, flags) { const src = `[${escapeRegExpCharacters(codePoints.map((i) => String.fromCodePoint(i)).join(''))}]`; return src; } class CodePointHighlighter { constructor(options) { this.options = options; this.allowedCodePoints = new Set(options.allowedCodePoints); this.ambiguousCharacters = AmbiguousCharacters.getInstance(new Set(options.allowedLocales)); } getCandidateCodePoints() { if (this.options.nonBasicASCII) { return 'allNonBasicAscii'; } const set = new Set(); if (this.options.invisibleCharacters) { for (const cp of InvisibleCharacters.codePoints) { set.add(cp); } } if (this.options.ambiguousCharacters) { for (const cp of this.ambiguousCharacters.getConfusableCodePoints()) { set.add(cp); } } for (const cp of this.allowedCodePoints) { set.delete(cp); } return set; } shouldHighlightNonBasicASCII(character) { const codePoint = character.codePointAt(0); if (this.allowedCodePoints.has(codePoint)) { return 0 /* None */; } if (this.options.nonBasicASCII) { return 1 /* NonBasicASCII */; } if (this.options.invisibleCharacters) { const isAllowedInvisibleCharacter = character === ' ' || character === '\n' || character === '\t'; // TODO check for emojis if (!isAllowedInvisibleCharacter && InvisibleCharacters.isInvisibleCharacter(codePoint)) { return 2 /* Invisible */; } } if (this.options.ambiguousCharacters) { if (this.ambiguousCharacters.isAmbiguous(codePoint)) { return 3 /* Ambiguous */; } } return 0 /* None */; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __awaiter$17 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; /** * @internal */ class MirrorModel extends MirrorTextModel { get uri() { return this._uri; } get eol() { return this._eol; } getValue() { return this.getText(); } getLinesContent() { return this._lines.slice(0); } getLineCount() { return this._lines.length; } getLineContent(lineNumber) { return this._lines[lineNumber - 1]; } getWordAtPosition(position, wordDefinition) { const wordAtText = getWordAtText(position.column, ensureValidWordDefinition(wordDefinition), this._lines[position.lineNumber - 1], 0); if (wordAtText) { return new Range$5(position.lineNumber, wordAtText.startColumn, position.lineNumber, wordAtText.endColumn); } return null; } words(wordDefinition) { const lines = this._lines; const wordenize = this._wordenize.bind(this); let lineNumber = 0; let lineText = ''; let wordRangesIdx = 0; let wordRanges = []; return { *[Symbol.iterator]() { while (true) { if (wordRangesIdx < wordRanges.length) { const value = lineText.substring(wordRanges[wordRangesIdx].start, wordRanges[wordRangesIdx].end); wordRangesIdx += 1; yield value; } else { if (lineNumber < lines.length) { lineText = lines[lineNumber]; wordRanges = wordenize(lineText, wordDefinition); wordRangesIdx = 0; lineNumber += 1; } else { break; } } } } }; } getLineWords(lineNumber, wordDefinition) { const content = this._lines[lineNumber - 1]; const ranges = this._wordenize(content, wordDefinition); const words = []; for (const range of ranges) { words.push({ word: content.substring(range.start, range.end), startColumn: range.start + 1, endColumn: range.end + 1 }); } return words; } _wordenize(content, wordDefinition) { const result = []; let match; wordDefinition.lastIndex = 0; // reset lastIndex just to be sure while (match = wordDefinition.exec(content)) { if (match[0].length === 0) { // it did match the empty string break; } result.push({ start: match.index, end: match.index + match[0].length }); } return result; } getValueInRange(range) { range = this._validateRange(range); if (range.startLineNumber === range.endLineNumber) { return this._lines[range.startLineNumber - 1].substring(range.startColumn - 1, range.endColumn - 1); } const lineEnding = this._eol; const startLineIndex = range.startLineNumber - 1; const endLineIndex = range.endLineNumber - 1; const resultLines = []; resultLines.push(this._lines[startLineIndex].substring(range.startColumn - 1)); for (let i = startLineIndex + 1; i < endLineIndex; i++) { resultLines.push(this._lines[i]); } resultLines.push(this._lines[endLineIndex].substring(0, range.endColumn - 1)); return resultLines.join(lineEnding); } offsetAt(position) { position = this._validatePosition(position); this._ensureLineStarts(); return this._lineStarts.getPrefixSum(position.lineNumber - 2) + (position.column - 1); } positionAt(offset) { offset = Math.floor(offset); offset = Math.max(0, offset); this._ensureLineStarts(); const out = this._lineStarts.getIndexOf(offset); const lineLength = this._lines[out.index].length; // Ensure we return a valid position return { lineNumber: 1 + out.index, column: 1 + Math.min(out.remainder, lineLength) }; } _validateRange(range) { const start = this._validatePosition({ lineNumber: range.startLineNumber, column: range.startColumn }); const end = this._validatePosition({ lineNumber: range.endLineNumber, column: range.endColumn }); if (start.lineNumber !== range.startLineNumber || start.column !== range.startColumn || end.lineNumber !== range.endLineNumber || end.column !== range.endColumn) { return { startLineNumber: start.lineNumber, startColumn: start.column, endLineNumber: end.lineNumber, endColumn: end.column }; } return range; } _validatePosition(position) { if (!Position$4.isIPosition(position)) { throw new Error('bad position'); } let { lineNumber, column } = position; let hasChanged = false; if (lineNumber < 1) { lineNumber = 1; column = 1; hasChanged = true; } else if (lineNumber > this._lines.length) { lineNumber = this._lines.length; column = this._lines[lineNumber - 1].length + 1; hasChanged = true; } else { const maxCharacter = this._lines[lineNumber - 1].length + 1; if (column < 1) { column = 1; hasChanged = true; } else if (column > maxCharacter) { column = maxCharacter; hasChanged = true; } } if (!hasChanged) { return position; } else { return { lineNumber, column }; } } } /** * @internal */ class EditorSimpleWorker { constructor(host, foreignModuleFactory) { this._host = host; this._models = Object.create(null); this._foreignModuleFactory = foreignModuleFactory; this._foreignModule = null; } dispose() { this._models = Object.create(null); } _getModel(uri) { return this._models[uri]; } _getModels() { const all = []; Object.keys(this._models).forEach((key) => all.push(this._models[key])); return all; } acceptNewModel(data) { this._models[data.url] = new MirrorModel(URI.parse(data.url), data.lines, data.EOL, data.versionId); } acceptModelChanged(strURL, e) { if (!this._models[strURL]) { return; } const model = this._models[strURL]; model.onEvents(e); } acceptRemovedModel(strURL) { if (!this._models[strURL]) { return; } delete this._models[strURL]; } computeUnicodeHighlights(url, options, range) { return __awaiter$17(this, void 0, void 0, function* () { const model = this._getModel(url); if (!model) { return { ranges: [], hasMore: false, ambiguousCharacterCount: 0, invisibleCharacterCount: 0, nonBasicAsciiCharacterCount: 0 }; } return UnicodeTextModelHighlighter.computeUnicodeHighlights(model, options, range); }); } // ---- BEGIN diff -------------------------------------------------------------------------- computeDiff(originalUrl, modifiedUrl, ignoreTrimWhitespace, maxComputationTime) { return __awaiter$17(this, void 0, void 0, function* () { const original = this._getModel(originalUrl); const modified = this._getModel(modifiedUrl); if (!original || !modified) { return null; } const originalLines = original.getLinesContent(); const modifiedLines = modified.getLinesContent(); const diffComputer = new DiffComputer(originalLines, modifiedLines, { shouldComputeCharChanges: true, shouldPostProcessCharChanges: true, shouldIgnoreTrimWhitespace: ignoreTrimWhitespace, shouldMakePrettyDiff: true, maxComputationTime: maxComputationTime }); const diffResult = diffComputer.computeDiff(); const identical = (diffResult.changes.length > 0 ? false : this._modelsAreIdentical(original, modified)); return { quitEarly: diffResult.quitEarly, identical: identical, changes: diffResult.changes }; }); } _modelsAreIdentical(original, modified) { const originalLineCount = original.getLineCount(); const modifiedLineCount = modified.getLineCount(); if (originalLineCount !== modifiedLineCount) { return false; } for (let line = 1; line <= originalLineCount; line++) { const originalLine = original.getLineContent(line); const modifiedLine = modified.getLineContent(line); if (originalLine !== modifiedLine) { return false; } } return true; } computeMoreMinimalEdits(modelUrl, edits) { return __awaiter$17(this, void 0, void 0, function* () { const model = this._getModel(modelUrl); if (!model) { return edits; } const result = []; let lastEol = undefined; edits = edits.slice(0).sort((a, b) => { if (a.range && b.range) { return Range$5.compareRangesUsingStarts(a.range, b.range); } // eol only changes should go to the end const aRng = a.range ? 0 : 1; const bRng = b.range ? 0 : 1; return aRng - bRng; }); for (let { range, text, eol } of edits) { if (typeof eol === 'number') { lastEol = eol; } if (Range$5.isEmpty(range) && !text) { // empty change continue; } const original = model.getValueInRange(range); text = text.replace(/\r\n|\n|\r/g, model.eol); if (original === text) { // noop continue; } // make sure diff won't take too long if (Math.max(text.length, original.length) > EditorSimpleWorker._diffLimit) { result.push({ range, text }); continue; } // compute diff between original and edit.text const changes = stringDiff(original, text, false); const editOffset = model.offsetAt(Range$5.lift(range).getStartPosition()); for (const change of changes) { const start = model.positionAt(editOffset + change.originalStart); const end = model.positionAt(editOffset + change.originalStart + change.originalLength); const newEdit = { text: text.substr(change.modifiedStart, change.modifiedLength), range: { startLineNumber: start.lineNumber, startColumn: start.column, endLineNumber: end.lineNumber, endColumn: end.column } }; if (model.getValueInRange(newEdit.range) !== newEdit.text) { result.push(newEdit); } } } if (typeof lastEol === 'number') { result.push({ eol: lastEol, text: '', range: { startLineNumber: 0, startColumn: 0, endLineNumber: 0, endColumn: 0 } }); } return result; }); } // ---- END minimal edits --------------------------------------------------------------- computeLinks(modelUrl) { return __awaiter$17(this, void 0, void 0, function* () { const model = this._getModel(modelUrl); if (!model) { return null; } return computeLinks(model); }); } textualSuggest(modelUrls, leadingWord, wordDef, wordDefFlags) { return __awaiter$17(this, void 0, void 0, function* () { const sw = new StopWatch(true); const wordDefRegExp = new RegExp(wordDef, wordDefFlags); const seen = new Set(); outer: for (let url of modelUrls) { const model = this._getModel(url); if (!model) { continue; } for (let word of model.words(wordDefRegExp)) { if (word === leadingWord || !isNaN(Number(word))) { continue; } seen.add(word); if (seen.size > EditorSimpleWorker._suggestionsLimit) { break outer; } } } return { words: Array.from(seen), duration: sw.elapsed() }; }); } // ---- END suggest -------------------------------------------------------------------------- //#region -- word ranges -- computeWordRanges(modelUrl, range, wordDef, wordDefFlags) { return __awaiter$17(this, void 0, void 0, function* () { const model = this._getModel(modelUrl); if (!model) { return Object.create(null); } const wordDefRegExp = new RegExp(wordDef, wordDefFlags); const result = Object.create(null); for (let line = range.startLineNumber; line < range.endLineNumber; line++) { const words = model.getLineWords(line, wordDefRegExp); for (const word of words) { if (!isNaN(Number(word.word))) { continue; } let array = result[word.word]; if (!array) { array = []; result[word.word] = array; } array.push({ startLineNumber: line, startColumn: word.startColumn, endLineNumber: line, endColumn: word.endColumn }); } } return result; }); } //#endregion navigateValueSet(modelUrl, range, up, wordDef, wordDefFlags) { return __awaiter$17(this, void 0, void 0, function* () { const model = this._getModel(modelUrl); if (!model) { return null; } const wordDefRegExp = new RegExp(wordDef, wordDefFlags); if (range.startColumn === range.endColumn) { range = { startLineNumber: range.startLineNumber, startColumn: range.startColumn, endLineNumber: range.endLineNumber, endColumn: range.endColumn + 1 }; } const selectionText = model.getValueInRange(range); const wordRange = model.getWordAtPosition({ lineNumber: range.startLineNumber, column: range.startColumn }, wordDefRegExp); if (!wordRange) { return null; } const word = model.getValueInRange(wordRange); const result = BasicInplaceReplace.INSTANCE.navigateValueSet(range, selectionText, wordRange, word, up); return result; }); } // ---- BEGIN foreign module support -------------------------------------------------------------------------- loadForeignModule(moduleId, createData, foreignHostMethods) { const proxyMethodRequest = (method, args) => { return this._host.fhr(method, args); }; const foreignHost = createProxyObject$1(foreignHostMethods, proxyMethodRequest); const ctx = { host: foreignHost, getMirrorModels: () => { return this._getModels(); } }; if (this._foreignModuleFactory) { this._foreignModule = this._foreignModuleFactory(ctx, createData); // static foreing module return Promise.resolve(getAllMethodNames(this._foreignModule)); } // ESM-comment-begin // return new Promise((resolve, reject) => { // require([moduleId], (foreignModule: { create: IForeignModuleFactory }) => { // this._foreignModule = foreignModule.create(ctx, createData); // // resolve(types.getAllMethodNames(this._foreignModule)); // // }, reject); // }); // ESM-comment-end // ESM-uncomment-begin return Promise.reject(new Error(`Unexpected usage`)); // ESM-uncomment-end } // foreign method request fmr(method, args) { if (!this._foreignModule || typeof this._foreignModule[method] !== 'function') { return Promise.reject(new Error('Missing requestHandler or method: ' + method)); } try { return Promise.resolve(this._foreignModule[method].apply(this._foreignModule, args)); } catch (e) { return Promise.reject(e); } } } // ---- END diff -------------------------------------------------------------------------- // ---- BEGIN minimal edits --------------------------------------------------------------- EditorSimpleWorker._diffLimit = 100000; // ---- BEGIN suggest -------------------------------------------------------------------------- EditorSimpleWorker._suggestionsLimit = 10000; if (typeof importScripts === 'function') { // Running in a web worker globals.monaco = createMonacoBaseAPI(); } const ITextResourceConfigurationService = createDecorator('textResourceConfigurationService'); const ITextResourcePropertiesService = createDecorator('textResourcePropertiesService'); const ILogService = createDecorator('logService'); var LogLevel; (function (LogLevel) { LogLevel[LogLevel["Trace"] = 0] = "Trace"; LogLevel[LogLevel["Debug"] = 1] = "Debug"; LogLevel[LogLevel["Info"] = 2] = "Info"; LogLevel[LogLevel["Warning"] = 3] = "Warning"; LogLevel[LogLevel["Error"] = 4] = "Error"; LogLevel[LogLevel["Critical"] = 5] = "Critical"; LogLevel[LogLevel["Off"] = 6] = "Off"; })(LogLevel || (LogLevel = {})); const DEFAULT_LOG_LEVEL = LogLevel.Info; class AbstractLogger extends Disposable { constructor() { super(...arguments); this.level = DEFAULT_LOG_LEVEL; this._onDidChangeLogLevel = this._register(new Emitter$1()); } setLevel(level) { if (this.level !== level) { this.level = level; this._onDidChangeLogLevel.fire(this.level); } } getLevel() { return this.level; } } class ConsoleLogger extends AbstractLogger { constructor(logLevel = DEFAULT_LOG_LEVEL) { super(); this.setLevel(logLevel); } trace(message, ...args) { if (this.getLevel() <= LogLevel.Trace) { console.log('%cTRACE', 'color: #888', message, ...args); } } debug(message, ...args) { if (this.getLevel() <= LogLevel.Debug) { console.log('%cDEBUG', 'background: #eee; color: #888', message, ...args); } } info(message, ...args) { if (this.getLevel() <= LogLevel.Info) { console.log('%c INFO', 'color: #33f', message, ...args); } } error(message, ...args) { if (this.getLevel() <= LogLevel.Error) { console.log('%c ERR', 'color: #f33', message, ...args); } } dispose() { // noop } } class LogService extends Disposable { constructor(logger) { super(); this.logger = logger; this._register(logger); } getLevel() { return this.logger.getLevel(); } trace(message, ...args) { this.logger.trace(message, ...args); } debug(message, ...args) { this.logger.debug(message, ...args); } info(message, ...args) { this.logger.info(message, ...args); } error(message, ...args) { this.logger.error(message, ...args); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate$1F = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param$1z = (undefined && undefined.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __awaiter$16 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; /** * Stop syncing a model to the worker if it was not needed for 1 min. */ const STOP_SYNC_MODEL_DELTA_TIME_MS = 60 * 1000; /** * Stop the worker if it was not needed for 5 min. */ const STOP_WORKER_DELTA_TIME_MS = 5 * 60 * 1000; function canSyncModel(modelService, resource) { const model = modelService.getModel(resource); if (!model) { return false; } if (model.isTooLargeForSyncing()) { return false; } return true; } let EditorWorkerService = class EditorWorkerService extends Disposable { constructor(modelService, configurationService, logService, languageConfigurationService) { super(); this._modelService = modelService; this._workerManager = this._register(new WorkerManager$4(this._modelService, languageConfigurationService)); this._logService = logService; // register default link-provider and default completions-provider this._register(LinkProviderRegistry.register({ language: '*', hasAccessToAllModels: true }, { provideLinks: (model, token) => { if (!canSyncModel(this._modelService, model.uri)) { return Promise.resolve({ links: [] }); // File too large } return this._workerManager.withWorker().then(client => client.computeLinks(model.uri)).then(links => { return links && { links }; }); } })); this._register(CompletionProviderRegistry.register('*', new WordBasedCompletionItemProvider(this._workerManager, configurationService, this._modelService, languageConfigurationService))); } dispose() { super.dispose(); } canComputeUnicodeHighlights(uri) { return canSyncModel(this._modelService, uri); } computedUnicodeHighlights(uri, options, range) { return this._workerManager.withWorker().then(client => client.computedUnicodeHighlights(uri, options, range)); } computeDiff(original, modified, ignoreTrimWhitespace, maxComputationTime) { return this._workerManager.withWorker().then(client => client.computeDiff(original, modified, ignoreTrimWhitespace, maxComputationTime)); } computeMoreMinimalEdits(resource, edits) { if (isNonEmptyArray(edits)) { if (!canSyncModel(this._modelService, resource)) { return Promise.resolve(edits); // File too large } const sw = StopWatch.create(true); const result = this._workerManager.withWorker().then(client => client.computeMoreMinimalEdits(resource, edits)); result.finally(() => this._logService.trace('FORMAT#computeMoreMinimalEdits', resource.toString(true), sw.elapsed())); return Promise.race([result, timeout(1000).then(() => edits)]); } else { return Promise.resolve(undefined); } } canNavigateValueSet(resource) { return (canSyncModel(this._modelService, resource)); } navigateValueSet(resource, range, up) { return this._workerManager.withWorker().then(client => client.navigateValueSet(resource, range, up)); } canComputeWordRanges(resource) { return canSyncModel(this._modelService, resource); } computeWordRanges(resource, range) { return this._workerManager.withWorker().then(client => client.computeWordRanges(resource, range)); } }; EditorWorkerService = __decorate$1F([ __param$1z(0, IModelService), __param$1z(1, ITextResourceConfigurationService), __param$1z(2, ILogService), __param$1z(3, ILanguageConfigurationService) ], EditorWorkerService); class WordBasedCompletionItemProvider { constructor(workerManager, configurationService, modelService, languageConfigurationService) { this.languageConfigurationService = languageConfigurationService; this._debugDisplayName = 'wordbasedCompletions'; this._workerManager = workerManager; this._configurationService = configurationService; this._modelService = modelService; } provideCompletionItems(model, position) { return __awaiter$16(this, void 0, void 0, function* () { const config = this._configurationService.getValue(model.uri, position, 'editor'); if (!config.wordBasedSuggestions) { return undefined; } const models = []; if (config.wordBasedSuggestionsMode === 'currentDocument') { // only current file and only if not too large if (canSyncModel(this._modelService, model.uri)) { models.push(model.uri); } } else { // either all files or files of same language for (const candidate of this._modelService.getModels()) { if (!canSyncModel(this._modelService, candidate.uri)) { continue; } if (candidate === model) { models.unshift(candidate.uri); } else if (config.wordBasedSuggestionsMode === 'allDocuments' || candidate.getLanguageId() === model.getLanguageId()) { models.push(candidate.uri); } } } if (models.length === 0) { return undefined; // File too large, no other files } const wordDefRegExp = this.languageConfigurationService.getLanguageConfiguration(model.getLanguageId()).getWordDefinition(); const word = model.getWordAtPosition(position); const replace = !word ? Range$5.fromPositions(position) : new Range$5(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn); const insert = replace.setEndPosition(position.lineNumber, position.column); const client = yield this._workerManager.withWorker(); const data = yield client.textualSuggest(models, word === null || word === void 0 ? void 0 : word.word, wordDefRegExp); if (!data) { return undefined; } return { duration: data.duration, suggestions: data.words.map((word) => { return { kind: 18 /* Text */, label: word, insertText: word, range: { insert, replace } }; }), }; }); } } class WorkerManager$4 extends Disposable { constructor(modelService, languageConfigurationService) { super(); this.languageConfigurationService = languageConfigurationService; this._modelService = modelService; this._editorWorkerClient = null; this._lastWorkerUsedTime = (new Date()).getTime(); const stopWorkerInterval = this._register(new IntervalTimer()); stopWorkerInterval.cancelAndSet(() => this._checkStopIdleWorker(), Math.round(STOP_WORKER_DELTA_TIME_MS / 2)); this._register(this._modelService.onModelRemoved(_ => this._checkStopEmptyWorker())); } dispose() { if (this._editorWorkerClient) { this._editorWorkerClient.dispose(); this._editorWorkerClient = null; } super.dispose(); } /** * Check if the model service has no more models and stop the worker if that is the case. */ _checkStopEmptyWorker() { if (!this._editorWorkerClient) { return; } const models = this._modelService.getModels(); if (models.length === 0) { // There are no more models => nothing possible for me to do this._editorWorkerClient.dispose(); this._editorWorkerClient = null; } } /** * Check if the worker has been idle for a while and then stop it. */ _checkStopIdleWorker() { if (!this._editorWorkerClient) { return; } const timeSinceLastWorkerUsedTime = (new Date()).getTime() - this._lastWorkerUsedTime; if (timeSinceLastWorkerUsedTime > STOP_WORKER_DELTA_TIME_MS) { this._editorWorkerClient.dispose(); this._editorWorkerClient = null; } } withWorker() { this._lastWorkerUsedTime = (new Date()).getTime(); if (!this._editorWorkerClient) { this._editorWorkerClient = new EditorWorkerClient(this._modelService, false, 'editorWorkerService', this.languageConfigurationService); } return Promise.resolve(this._editorWorkerClient); } } class EditorModelManager extends Disposable { constructor(proxy, modelService, keepIdleModels) { super(); this._syncedModels = Object.create(null); this._syncedModelsLastUsedTime = Object.create(null); this._proxy = proxy; this._modelService = modelService; if (!keepIdleModels) { const timer = new IntervalTimer(); timer.cancelAndSet(() => this._checkStopModelSync(), Math.round(STOP_SYNC_MODEL_DELTA_TIME_MS / 2)); this._register(timer); } } dispose() { for (let modelUrl in this._syncedModels) { dispose(this._syncedModels[modelUrl]); } this._syncedModels = Object.create(null); this._syncedModelsLastUsedTime = Object.create(null); super.dispose(); } ensureSyncedResources(resources, forceLargeModels) { for (const resource of resources) { const resourceStr = resource.toString(); if (!this._syncedModels[resourceStr]) { this._beginModelSync(resource, forceLargeModels); } if (this._syncedModels[resourceStr]) { this._syncedModelsLastUsedTime[resourceStr] = (new Date()).getTime(); } } } _checkStopModelSync() { const currentTime = (new Date()).getTime(); const toRemove = []; for (let modelUrl in this._syncedModelsLastUsedTime) { const elapsedTime = currentTime - this._syncedModelsLastUsedTime[modelUrl]; if (elapsedTime > STOP_SYNC_MODEL_DELTA_TIME_MS) { toRemove.push(modelUrl); } } for (const e of toRemove) { this._stopModelSync(e); } } _beginModelSync(resource, forceLargeModels) { const model = this._modelService.getModel(resource); if (!model) { return; } if (!forceLargeModels && model.isTooLargeForSyncing()) { return; } const modelUrl = resource.toString(); this._proxy.acceptNewModel({ url: model.uri.toString(), lines: model.getLinesContent(), EOL: model.getEOL(), versionId: model.getVersionId() }); const toDispose = new DisposableStore(); toDispose.add(model.onDidChangeContent((e) => { this._proxy.acceptModelChanged(modelUrl.toString(), e); })); toDispose.add(model.onWillDispose(() => { this._stopModelSync(modelUrl); })); toDispose.add(toDisposable(() => { this._proxy.acceptRemovedModel(modelUrl); })); this._syncedModels[modelUrl] = toDispose; } _stopModelSync(modelUrl) { const toDispose = this._syncedModels[modelUrl]; delete this._syncedModels[modelUrl]; delete this._syncedModelsLastUsedTime[modelUrl]; dispose(toDispose); } } class SynchronousWorkerClient { constructor(instance) { this._instance = instance; this._proxyObj = Promise.resolve(this._instance); } dispose() { this._instance.dispose(); } getProxyObject() { return this._proxyObj; } } class EditorWorkerHost { constructor(workerClient) { this._workerClient = workerClient; } // foreign host request fhr(method, args) { return this._workerClient.fhr(method, args); } } class EditorWorkerClient extends Disposable { constructor(modelService, keepIdleModels, label, languageConfigurationService) { super(); this.languageConfigurationService = languageConfigurationService; this._disposed = false; this._modelService = modelService; this._keepIdleModels = keepIdleModels; this._workerFactory = new DefaultWorkerFactory(label); this._worker = null; this._modelManager = null; } // foreign host request fhr(method, args) { throw new Error(`Not implemented!`); } _getOrCreateWorker() { if (!this._worker) { try { this._worker = this._register(new SimpleWorkerClient(this._workerFactory, 'vs/editor/common/services/editorSimpleWorker', new EditorWorkerHost(this))); } catch (err) { logOnceWebWorkerWarning(err); this._worker = new SynchronousWorkerClient(new EditorSimpleWorker(new EditorWorkerHost(this), null)); } } return this._worker; } _getProxy() { return this._getOrCreateWorker().getProxyObject().then(undefined, (err) => { logOnceWebWorkerWarning(err); this._worker = new SynchronousWorkerClient(new EditorSimpleWorker(new EditorWorkerHost(this), null)); return this._getOrCreateWorker().getProxyObject(); }); } _getOrCreateModelManager(proxy) { if (!this._modelManager) { this._modelManager = this._register(new EditorModelManager(proxy, this._modelService, this._keepIdleModels)); } return this._modelManager; } _withSyncedResources(resources, forceLargeModels = false) { return __awaiter$16(this, void 0, void 0, function* () { if (this._disposed) { return Promise.reject(canceled()); } return this._getProxy().then((proxy) => { this._getOrCreateModelManager(proxy).ensureSyncedResources(resources, forceLargeModels); return proxy; }); }); } computedUnicodeHighlights(uri, options, range) { return this._withSyncedResources([uri]).then(proxy => { return proxy.computeUnicodeHighlights(uri.toString(), options, range); }); } computeDiff(original, modified, ignoreTrimWhitespace, maxComputationTime) { return this._withSyncedResources([original, modified], /* forceLargeModels */ true).then(proxy => { return proxy.computeDiff(original.toString(), modified.toString(), ignoreTrimWhitespace, maxComputationTime); }); } computeMoreMinimalEdits(resource, edits) { return this._withSyncedResources([resource]).then(proxy => { return proxy.computeMoreMinimalEdits(resource.toString(), edits); }); } computeLinks(resource) { return this._withSyncedResources([resource]).then(proxy => { return proxy.computeLinks(resource.toString()); }); } textualSuggest(resources, leadingWord, wordDefRegExp) { return __awaiter$16(this, void 0, void 0, function* () { const proxy = yield this._withSyncedResources(resources); const wordDef = wordDefRegExp.source; const wordDefFlags = regExpFlags(wordDefRegExp); return proxy.textualSuggest(resources.map(r => r.toString()), leadingWord, wordDef, wordDefFlags); }); } computeWordRanges(resource, range) { return this._withSyncedResources([resource]).then(proxy => { const model = this._modelService.getModel(resource); if (!model) { return Promise.resolve(null); } const wordDefRegExp = this.languageConfigurationService.getLanguageConfiguration(model.getLanguageId()).getWordDefinition(); const wordDef = wordDefRegExp.source; const wordDefFlags = regExpFlags(wordDefRegExp); return proxy.computeWordRanges(resource.toString(), range, wordDef, wordDefFlags); }); } navigateValueSet(resource, range, up) { return this._withSyncedResources([resource]).then(proxy => { const model = this._modelService.getModel(resource); if (!model) { return null; } const wordDefRegExp = this.languageConfigurationService.getLanguageConfiguration(model.getLanguageId()).getWordDefinition(); const wordDef = wordDefRegExp.source; const wordDefFlags = regExpFlags(wordDefRegExp); return proxy.navigateValueSet(resource.toString(), range, up, wordDef, wordDefFlags); }); } dispose() { super.dispose(); this._disposed = true; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Create a new web worker that has model syncing capabilities built in. * Specify an AMD module to load that will `create` an object that will be proxied. */ function createWebWorker$1(modelService, languageConfigurationService, opts) { return new MonacoWebWorkerImpl(modelService, languageConfigurationService, opts); } class MonacoWebWorkerImpl extends EditorWorkerClient { constructor(modelService, languageConfigurationService, opts) { super(modelService, opts.keepIdleModels || false, opts.label, languageConfigurationService); this._foreignModuleId = opts.moduleId; this._foreignModuleCreateData = opts.createData || null; this._foreignModuleHost = opts.host || null; this._foreignProxy = null; } // foreign host request fhr(method, args) { if (!this._foreignModuleHost || typeof this._foreignModuleHost[method] !== 'function') { return Promise.reject(new Error('Missing method ' + method + ' or missing main thread foreign host.')); } try { return Promise.resolve(this._foreignModuleHost[method].apply(this._foreignModuleHost, args)); } catch (e) { return Promise.reject(e); } } _getForeignProxy() { if (!this._foreignProxy) { this._foreignProxy = this._getProxy().then((proxy) => { const foreignHostMethods = this._foreignModuleHost ? getAllMethodNames(this._foreignModuleHost) : []; return proxy.loadForeignModule(this._foreignModuleId, this._foreignModuleCreateData, foreignHostMethods).then((foreignMethods) => { this._foreignModuleCreateData = null; const proxyMethodRequest = (method, args) => { return proxy.fmr(method, args); }; const createProxyMethod = (method, proxyMethodRequest) => { return function () { const args = Array.prototype.slice.call(arguments, 0); return proxyMethodRequest(method, args); }; }; const foreignProxy = {}; for (const foreignMethod of foreignMethods) { foreignProxy[foreignMethod] = createProxyMethod(foreignMethod, proxyMethodRequest); } return foreignProxy; }); }); } return this._foreignProxy; } getProxy() { return this._getForeignProxy(); } withSyncedResources(resources) { return this._withSyncedResources(resources).then(_ => this.getProxy()); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class LineTokens { constructor(tokens, text, decoder) { this._lineTokensBrand = undefined; this._tokens = tokens; this._tokensCount = (this._tokens.length >>> 1); this._text = text; this._languageIdCodec = decoder; } static createEmpty(lineContent, decoder) { const defaultMetadata = LineTokens.defaultTokenMetadata; const tokens = new Uint32Array(2); tokens[0] = lineContent.length; tokens[1] = defaultMetadata; return new LineTokens(tokens, lineContent, decoder); } equals(other) { if (other instanceof LineTokens) { return this.slicedEquals(other, 0, this._tokensCount); } return false; } slicedEquals(other, sliceFromTokenIndex, sliceTokenCount) { if (this._text !== other._text) { return false; } if (this._tokensCount !== other._tokensCount) { return false; } const from = (sliceFromTokenIndex << 1); const to = from + (sliceTokenCount << 1); for (let i = from; i < to; i++) { if (this._tokens[i] !== other._tokens[i]) { return false; } } return true; } getLineContent() { return this._text; } getCount() { return this._tokensCount; } getStartOffset(tokenIndex) { if (tokenIndex > 0) { return this._tokens[(tokenIndex - 1) << 1]; } return 0; } getMetadata(tokenIndex) { const metadata = this._tokens[(tokenIndex << 1) + 1]; return metadata; } getLanguageId(tokenIndex) { const metadata = this._tokens[(tokenIndex << 1) + 1]; const languageId = TokenMetadata.getLanguageId(metadata); return this._languageIdCodec.decodeLanguageId(languageId); } getStandardTokenType(tokenIndex) { const metadata = this._tokens[(tokenIndex << 1) + 1]; return TokenMetadata.getTokenType(metadata); } getForeground(tokenIndex) { const metadata = this._tokens[(tokenIndex << 1) + 1]; return TokenMetadata.getForeground(metadata); } getClassName(tokenIndex) { const metadata = this._tokens[(tokenIndex << 1) + 1]; return TokenMetadata.getClassNameFromMetadata(metadata); } getInlineStyle(tokenIndex, colorMap) { const metadata = this._tokens[(tokenIndex << 1) + 1]; return TokenMetadata.getInlineStyleFromMetadata(metadata, colorMap); } getPresentation(tokenIndex) { const metadata = this._tokens[(tokenIndex << 1) + 1]; return TokenMetadata.getPresentationFromMetadata(metadata); } getEndOffset(tokenIndex) { return this._tokens[tokenIndex << 1]; } /** * Find the token containing offset `offset`. * @param offset The search offset * @return The index of the token containing the offset. */ findTokenIndexAtOffset(offset) { return LineTokens.findIndexInTokensArray(this._tokens, offset); } inflate() { return this; } sliceAndInflate(startOffset, endOffset, deltaOffset) { return new SliceLineTokens(this, startOffset, endOffset, deltaOffset); } static convertToEndOffset(tokens, lineTextLength) { const tokenCount = (tokens.length >>> 1); const lastTokenIndex = tokenCount - 1; for (let tokenIndex = 0; tokenIndex < lastTokenIndex; tokenIndex++) { tokens[tokenIndex << 1] = tokens[(tokenIndex + 1) << 1]; } tokens[lastTokenIndex << 1] = lineTextLength; } static findIndexInTokensArray(tokens, desiredIndex) { if (tokens.length <= 2) { return 0; } let low = 0; let high = (tokens.length >>> 1) - 1; while (low < high) { const mid = low + Math.floor((high - low) / 2); const endOffset = tokens[(mid << 1)]; if (endOffset === desiredIndex) { return mid + 1; } else if (endOffset < desiredIndex) { low = mid + 1; } else if (endOffset > desiredIndex) { high = mid; } } return low; } /** * @pure * @param insertTokens Must be sorted by offset. */ withInserted(insertTokens) { if (insertTokens.length === 0) { return this; } let nextOriginalTokenIdx = 0; let nextInsertTokenIdx = 0; let text = ''; const newTokens = new Array(); let originalEndOffset = 0; while (true) { const nextOriginalTokenEndOffset = nextOriginalTokenIdx < this._tokensCount ? this._tokens[nextOriginalTokenIdx << 1] : -1; const nextInsertToken = nextInsertTokenIdx < insertTokens.length ? insertTokens[nextInsertTokenIdx] : null; if (nextOriginalTokenEndOffset !== -1 && (nextInsertToken === null || nextOriginalTokenEndOffset <= nextInsertToken.offset)) { // original token ends before next insert token text += this._text.substring(originalEndOffset, nextOriginalTokenEndOffset); const metadata = this._tokens[(nextOriginalTokenIdx << 1) + 1]; newTokens.push(text.length, metadata); nextOriginalTokenIdx++; originalEndOffset = nextOriginalTokenEndOffset; } else if (nextInsertToken) { if (nextInsertToken.offset > originalEndOffset) { // insert token is in the middle of the next token. text += this._text.substring(originalEndOffset, nextInsertToken.offset); const metadata = this._tokens[(nextOriginalTokenIdx << 1) + 1]; newTokens.push(text.length, metadata); originalEndOffset = nextInsertToken.offset; } text += nextInsertToken.text; newTokens.push(text.length, nextInsertToken.tokenMetadata); nextInsertTokenIdx++; } else { break; } } return new LineTokens(new Uint32Array(newTokens), text, this._languageIdCodec); } } LineTokens.defaultTokenMetadata = ((0 /* None */ << 10 /* FONT_STYLE_OFFSET */) | (1 /* DefaultForeground */ << 14 /* FOREGROUND_OFFSET */) | (2 /* DefaultBackground */ << 23 /* BACKGROUND_OFFSET */)) >>> 0; class SliceLineTokens { constructor(source, startOffset, endOffset, deltaOffset) { this._source = source; this._startOffset = startOffset; this._endOffset = endOffset; this._deltaOffset = deltaOffset; this._firstTokenIndex = source.findTokenIndexAtOffset(startOffset); this._tokensCount = 0; for (let i = this._firstTokenIndex, len = source.getCount(); i < len; i++) { const tokenStartOffset = source.getStartOffset(i); if (tokenStartOffset >= endOffset) { break; } this._tokensCount++; } } getMetadata(tokenIndex) { return this._source.getMetadata(this._firstTokenIndex + tokenIndex); } getLanguageId(tokenIndex) { return this._source.getLanguageId(this._firstTokenIndex + tokenIndex); } getLineContent() { return this._source.getLineContent().substring(this._startOffset, this._endOffset); } equals(other) { if (other instanceof SliceLineTokens) { return (this._startOffset === other._startOffset && this._endOffset === other._endOffset && this._deltaOffset === other._deltaOffset && this._source.slicedEquals(other._source, this._firstTokenIndex, this._tokensCount)); } return false; } getCount() { return this._tokensCount; } getForeground(tokenIndex) { return this._source.getForeground(this._firstTokenIndex + tokenIndex); } getEndOffset(tokenIndex) { const tokenEndOffset = this._source.getEndOffset(this._firstTokenIndex + tokenIndex); return Math.min(this._endOffset, tokenEndOffset) - this._startOffset + this._deltaOffset; } getClassName(tokenIndex) { return this._source.getClassName(this._firstTokenIndex + tokenIndex); } getInlineStyle(tokenIndex, colorMap) { return this._source.getInlineStyle(this._firstTokenIndex + tokenIndex, colorMap); } getPresentation(tokenIndex) { return this._source.getPresentation(this._firstTokenIndex + tokenIndex); } findTokenIndexAtOffset(offset) { return this._source.findTokenIndexAtOffset(offset + this._startOffset - this._deltaOffset) - this._firstTokenIndex; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class LineDecoration { constructor(startColumn, endColumn, className, type) { this.startColumn = startColumn; this.endColumn = endColumn; this.className = className; this.type = type; this._lineDecorationBrand = undefined; } static _equals(a, b) { return (a.startColumn === b.startColumn && a.endColumn === b.endColumn && a.className === b.className && a.type === b.type); } static equalsArr(a, b) { const aLen = a.length; const bLen = b.length; if (aLen !== bLen) { return false; } for (let i = 0; i < aLen; i++) { if (!LineDecoration._equals(a[i], b[i])) { return false; } } return true; } static extractWrapped(arr, startOffset, endOffset) { if (arr.length === 0) { return arr; } const startColumn = startOffset + 1; const endColumn = endOffset + 1; const lineLength = endOffset - startOffset; const r = []; let rLength = 0; for (const dec of arr) { if (dec.endColumn <= startColumn || dec.startColumn >= endColumn) { continue; } r[rLength++] = new LineDecoration(Math.max(1, dec.startColumn - startColumn + 1), Math.min(lineLength + 1, dec.endColumn - startColumn + 1), dec.className, dec.type); } return r; } static filter(lineDecorations, lineNumber, minLineColumn, maxLineColumn) { if (lineDecorations.length === 0) { return []; } const result = []; let resultLen = 0; for (let i = 0, len = lineDecorations.length; i < len; i++) { const d = lineDecorations[i]; const range = d.range; if (range.endLineNumber < lineNumber || range.startLineNumber > lineNumber) { // Ignore decorations that sit outside this line continue; } if (range.isEmpty() && (d.type === 0 /* Regular */ || d.type === 3 /* RegularAffectingLetterSpacing */)) { // Ignore empty range decorations continue; } const startColumn = (range.startLineNumber === lineNumber ? range.startColumn : minLineColumn); const endColumn = (range.endLineNumber === lineNumber ? range.endColumn : maxLineColumn); result[resultLen++] = new LineDecoration(startColumn, endColumn, d.inlineClassName, d.type); } return result; } static _typeCompare(a, b) { const ORDER = [2, 0, 1, 3]; return ORDER[a] - ORDER[b]; } static compare(a, b) { if (a.startColumn !== b.startColumn) { return a.startColumn - b.startColumn; } if (a.endColumn !== b.endColumn) { return a.endColumn - b.endColumn; } const typeCmp = LineDecoration._typeCompare(a.type, b.type); if (typeCmp !== 0) { return typeCmp; } if (a.className !== b.className) { return a.className < b.className ? -1 : 1; } return 0; } } class DecorationSegment { constructor(startOffset, endOffset, className, metadata) { this.startOffset = startOffset; this.endOffset = endOffset; this.className = className; this.metadata = metadata; } } class Stack { constructor() { this.stopOffsets = []; this.classNames = []; this.metadata = []; this.count = 0; } static _metadata(metadata) { let result = 0; for (let i = 0, len = metadata.length; i < len; i++) { result |= metadata[i]; } return result; } consumeLowerThan(maxStopOffset, nextStartOffset, result) { while (this.count > 0 && this.stopOffsets[0] < maxStopOffset) { let i = 0; // Take all equal stopping offsets while (i + 1 < this.count && this.stopOffsets[i] === this.stopOffsets[i + 1]) { i++; } // Basically we are consuming the first i + 1 elements of the stack result.push(new DecorationSegment(nextStartOffset, this.stopOffsets[i], this.classNames.join(' '), Stack._metadata(this.metadata))); nextStartOffset = this.stopOffsets[i] + 1; // Consume them this.stopOffsets.splice(0, i + 1); this.classNames.splice(0, i + 1); this.metadata.splice(0, i + 1); this.count -= (i + 1); } if (this.count > 0 && nextStartOffset < maxStopOffset) { result.push(new DecorationSegment(nextStartOffset, maxStopOffset - 1, this.classNames.join(' '), Stack._metadata(this.metadata))); nextStartOffset = maxStopOffset; } return nextStartOffset; } insert(stopOffset, className, metadata) { if (this.count === 0 || this.stopOffsets[this.count - 1] <= stopOffset) { // Insert at the end this.stopOffsets.push(stopOffset); this.classNames.push(className); this.metadata.push(metadata); } else { // Find the insertion position for `stopOffset` for (let i = 0; i < this.count; i++) { if (this.stopOffsets[i] >= stopOffset) { this.stopOffsets.splice(i, 0, stopOffset); this.classNames.splice(i, 0, className); this.metadata.splice(i, 0, metadata); break; } } } this.count++; return; } } class LineDecorationsNormalizer { /** * Normalize line decorations. Overlapping decorations will generate multiple segments */ static normalize(lineContent, lineDecorations) { if (lineDecorations.length === 0) { return []; } const result = []; const stack = new Stack(); let nextStartOffset = 0; for (let i = 0, len = lineDecorations.length; i < len; i++) { const d = lineDecorations[i]; let startColumn = d.startColumn; let endColumn = d.endColumn; const className = d.className; const metadata = (d.type === 1 /* Before */ ? 2 /* PSEUDO_BEFORE */ : d.type === 2 /* After */ ? 4 /* PSEUDO_AFTER */ : 0); // If the position would end up in the middle of a high-low surrogate pair, we move it to before the pair if (startColumn > 1) { const charCodeBefore = lineContent.charCodeAt(startColumn - 2); if (isHighSurrogate(charCodeBefore)) { startColumn--; } } if (endColumn > 1) { const charCodeBefore = lineContent.charCodeAt(endColumn - 2); if (isHighSurrogate(charCodeBefore)) { endColumn--; } } const currentStartOffset = startColumn - 1; const currentEndOffset = endColumn - 2; nextStartOffset = stack.consumeLowerThan(currentStartOffset, nextStartOffset, result); if (stack.count === 0) { nextStartOffset = currentStartOffset; } stack.insert(currentEndOffset, className, metadata); } stack.consumeLowerThan(1073741824 /* MAX_SAFE_SMALL_INTEGER */, nextStartOffset, result); return result; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class LinePart { constructor(endIndex, type, metadata) { this._linePartBrand = undefined; this.endIndex = endIndex; this.type = type; this.metadata = metadata; } isWhitespace() { return (this.metadata & 1 /* IS_WHITESPACE_MASK */ ? true : false); } isPseudoAfter() { return (this.metadata & 4 /* PSEUDO_AFTER_MASK */ ? true : false); } } class LineRange { constructor(startIndex, endIndex) { this.startOffset = startIndex; this.endOffset = endIndex; } equals(otherLineRange) { return this.startOffset === otherLineRange.startOffset && this.endOffset === otherLineRange.endOffset; } } class RenderLineInput { constructor(useMonospaceOptimizations, canUseHalfwidthRightwardsArrow, lineContent, continuesWithWrappedLine, isBasicASCII, containsRTL, fauxIndentLength, lineTokens, lineDecorations, tabSize, startVisibleColumn, spaceWidth, middotWidth, wsmiddotWidth, stopRenderingLineAfter, renderWhitespace, renderControlCharacters, fontLigatures, selectionsOnLine) { this.useMonospaceOptimizations = useMonospaceOptimizations; this.canUseHalfwidthRightwardsArrow = canUseHalfwidthRightwardsArrow; this.lineContent = lineContent; this.continuesWithWrappedLine = continuesWithWrappedLine; this.isBasicASCII = isBasicASCII; this.containsRTL = containsRTL; this.fauxIndentLength = fauxIndentLength; this.lineTokens = lineTokens; this.lineDecorations = lineDecorations.sort(LineDecoration.compare); this.tabSize = tabSize; this.startVisibleColumn = startVisibleColumn; this.spaceWidth = spaceWidth; this.stopRenderingLineAfter = stopRenderingLineAfter; this.renderWhitespace = (renderWhitespace === 'all' ? 4 /* All */ : renderWhitespace === 'boundary' ? 1 /* Boundary */ : renderWhitespace === 'selection' ? 2 /* Selection */ : renderWhitespace === 'trailing' ? 3 /* Trailing */ : 0 /* None */); this.renderControlCharacters = renderControlCharacters; this.fontLigatures = fontLigatures; this.selectionsOnLine = selectionsOnLine && selectionsOnLine.sort((a, b) => a.startOffset < b.startOffset ? -1 : 1); const wsmiddotDiff = Math.abs(wsmiddotWidth - spaceWidth); const middotDiff = Math.abs(middotWidth - spaceWidth); if (wsmiddotDiff < middotDiff) { this.renderSpaceWidth = wsmiddotWidth; this.renderSpaceCharCode = 0x2E31; // U+2E31 - WORD SEPARATOR MIDDLE DOT } else { this.renderSpaceWidth = middotWidth; this.renderSpaceCharCode = 0xB7; // U+00B7 - MIDDLE DOT } } sameSelection(otherSelections) { if (this.selectionsOnLine === null) { return otherSelections === null; } if (otherSelections === null) { return false; } if (otherSelections.length !== this.selectionsOnLine.length) { return false; } for (let i = 0; i < this.selectionsOnLine.length; i++) { if (!this.selectionsOnLine[i].equals(otherSelections[i])) { return false; } } return true; } equals(other) { return (this.useMonospaceOptimizations === other.useMonospaceOptimizations && this.canUseHalfwidthRightwardsArrow === other.canUseHalfwidthRightwardsArrow && this.lineContent === other.lineContent && this.continuesWithWrappedLine === other.continuesWithWrappedLine && this.isBasicASCII === other.isBasicASCII && this.containsRTL === other.containsRTL && this.fauxIndentLength === other.fauxIndentLength && this.tabSize === other.tabSize && this.startVisibleColumn === other.startVisibleColumn && this.spaceWidth === other.spaceWidth && this.renderSpaceWidth === other.renderSpaceWidth && this.renderSpaceCharCode === other.renderSpaceCharCode && this.stopRenderingLineAfter === other.stopRenderingLineAfter && this.renderWhitespace === other.renderWhitespace && this.renderControlCharacters === other.renderControlCharacters && this.fontLigatures === other.fontLigatures && LineDecoration.equalsArr(this.lineDecorations, other.lineDecorations) && this.lineTokens.equals(other.lineTokens) && this.sameSelection(other.selectionsOnLine)); } } class DomPosition { constructor(partIndex, charIndex) { this.partIndex = partIndex; this.charIndex = charIndex; } } /** * Provides a both direction mapping between a line's character and its rendered position. */ class CharacterMapping { constructor(length, partCount) { this.length = length; this._data = new Uint32Array(this.length); this._absoluteOffsets = new Uint32Array(this.length); } static getPartIndex(partData) { return (partData & 4294901760 /* PART_INDEX_MASK */) >>> 16 /* PART_INDEX_OFFSET */; } static getCharIndex(partData) { return (partData & 65535 /* CHAR_INDEX_MASK */) >>> 0 /* CHAR_INDEX_OFFSET */; } setColumnInfo(column, partIndex, charIndex, partAbsoluteOffset) { const partData = ((partIndex << 16 /* PART_INDEX_OFFSET */) | (charIndex << 0 /* CHAR_INDEX_OFFSET */)) >>> 0; this._data[column - 1] = partData; this._absoluteOffsets[column - 1] = partAbsoluteOffset + charIndex; } getAbsoluteOffset(column) { if (this._absoluteOffsets.length === 0) { // No characters on this line return 0; } return this._absoluteOffsets[column - 1]; } charOffsetToPartData(charOffset) { if (this.length === 0) { return 0; } if (charOffset < 0) { return this._data[0]; } if (charOffset >= this.length) { return this._data[this.length - 1]; } return this._data[charOffset]; } getDomPosition(column) { const partData = this.charOffsetToPartData(column - 1); const partIndex = CharacterMapping.getPartIndex(partData); const charIndex = CharacterMapping.getCharIndex(partData); return new DomPosition(partIndex, charIndex); } getColumn(domPosition, partLength) { const charOffset = this.partDataToCharOffset(domPosition.partIndex, partLength, domPosition.charIndex); return charOffset + 1; } partDataToCharOffset(partIndex, partLength, charIndex) { if (this.length === 0) { return 0; } const searchEntry = ((partIndex << 16 /* PART_INDEX_OFFSET */) | (charIndex << 0 /* CHAR_INDEX_OFFSET */)) >>> 0; let min = 0; let max = this.length - 1; while (min + 1 < max) { const mid = ((min + max) >>> 1); const midEntry = this._data[mid]; if (midEntry === searchEntry) { return mid; } else if (midEntry > searchEntry) { max = mid; } else { min = mid; } } if (min === max) { return min; } const minEntry = this._data[min]; const maxEntry = this._data[max]; if (minEntry === searchEntry) { return min; } if (maxEntry === searchEntry) { return max; } const minPartIndex = CharacterMapping.getPartIndex(minEntry); const minCharIndex = CharacterMapping.getCharIndex(minEntry); const maxPartIndex = CharacterMapping.getPartIndex(maxEntry); let maxCharIndex; if (minPartIndex !== maxPartIndex) { // sitting between parts maxCharIndex = partLength; } else { maxCharIndex = CharacterMapping.getCharIndex(maxEntry); } const minEntryDistance = charIndex - minCharIndex; const maxEntryDistance = maxCharIndex - charIndex; if (minEntryDistance <= maxEntryDistance) { return min; } return max; } } class RenderLineOutput { constructor(characterMapping, containsRTL, containsForeignElements) { this._renderLineOutputBrand = undefined; this.characterMapping = characterMapping; this.containsRTL = containsRTL; this.containsForeignElements = containsForeignElements; } } function renderViewLine(input, sb) { if (input.lineContent.length === 0) { if (input.lineDecorations.length > 0) { // This line is empty, but it contains inline decorations sb.appendASCIIString(``); let beforeCount = 0; let afterCount = 0; let containsForeignElements = 0 /* None */; for (const lineDecoration of input.lineDecorations) { if (lineDecoration.type === 1 /* Before */ || lineDecoration.type === 2 /* After */) { sb.appendASCIIString(``); if (lineDecoration.type === 1 /* Before */) { containsForeignElements |= 1 /* Before */; beforeCount++; } if (lineDecoration.type === 2 /* After */) { containsForeignElements |= 2 /* After */; afterCount++; } } } sb.appendASCIIString(``); const characterMapping = new CharacterMapping(1, beforeCount + afterCount); characterMapping.setColumnInfo(1, beforeCount, 0, 0); return new RenderLineOutput(characterMapping, false, containsForeignElements); } // completely empty line sb.appendASCIIString(''); return new RenderLineOutput(new CharacterMapping(0, 0), false, 0 /* None */); } return _renderLine(resolveRenderLineInput(input), sb); } class RenderLineOutput2 { constructor(characterMapping, html, containsRTL, containsForeignElements) { this.characterMapping = characterMapping; this.html = html; this.containsRTL = containsRTL; this.containsForeignElements = containsForeignElements; } } function renderViewLine2(input) { const sb = createStringBuilder(10000); const out = renderViewLine(input, sb); return new RenderLineOutput2(out.characterMapping, sb.build(), out.containsRTL, out.containsForeignElements); } class ResolvedRenderLineInput { constructor(fontIsMonospace, canUseHalfwidthRightwardsArrow, lineContent, len, isOverflowing, parts, containsForeignElements, fauxIndentLength, tabSize, startVisibleColumn, containsRTL, spaceWidth, renderSpaceCharCode, renderWhitespace, renderControlCharacters) { this.fontIsMonospace = fontIsMonospace; this.canUseHalfwidthRightwardsArrow = canUseHalfwidthRightwardsArrow; this.lineContent = lineContent; this.len = len; this.isOverflowing = isOverflowing; this.parts = parts; this.containsForeignElements = containsForeignElements; this.fauxIndentLength = fauxIndentLength; this.tabSize = tabSize; this.startVisibleColumn = startVisibleColumn; this.containsRTL = containsRTL; this.spaceWidth = spaceWidth; this.renderSpaceCharCode = renderSpaceCharCode; this.renderWhitespace = renderWhitespace; this.renderControlCharacters = renderControlCharacters; // } } function resolveRenderLineInput(input) { const lineContent = input.lineContent; let isOverflowing; let len; if (input.stopRenderingLineAfter !== -1 && input.stopRenderingLineAfter < lineContent.length) { isOverflowing = true; len = input.stopRenderingLineAfter; } else { isOverflowing = false; len = lineContent.length; } let tokens = transformAndRemoveOverflowing(input.lineTokens, input.fauxIndentLength, len); if (input.renderControlCharacters && !input.isBasicASCII) { // Calling `extractControlCharacters` before adding (possibly empty) line parts // for inline decorations. `extractControlCharacters` removes empty line parts. tokens = extractControlCharacters(lineContent, tokens); } if (input.renderWhitespace === 4 /* All */ || input.renderWhitespace === 1 /* Boundary */ || (input.renderWhitespace === 2 /* Selection */ && !!input.selectionsOnLine) || input.renderWhitespace === 3 /* Trailing */) { tokens = _applyRenderWhitespace(input, lineContent, len, tokens); } let containsForeignElements = 0 /* None */; if (input.lineDecorations.length > 0) { for (let i = 0, len = input.lineDecorations.length; i < len; i++) { const lineDecoration = input.lineDecorations[i]; if (lineDecoration.type === 3 /* RegularAffectingLetterSpacing */) { // Pretend there are foreign elements... although not 100% accurate. containsForeignElements |= 1 /* Before */; } else if (lineDecoration.type === 1 /* Before */) { containsForeignElements |= 1 /* Before */; } else if (lineDecoration.type === 2 /* After */) { containsForeignElements |= 2 /* After */; } } tokens = _applyInlineDecorations(lineContent, len, tokens, input.lineDecorations); } if (!input.containsRTL) { // We can never split RTL text, as it ruins the rendering tokens = splitLargeTokens(lineContent, tokens, !input.isBasicASCII || input.fontLigatures); } return new ResolvedRenderLineInput(input.useMonospaceOptimizations, input.canUseHalfwidthRightwardsArrow, lineContent, len, isOverflowing, tokens, containsForeignElements, input.fauxIndentLength, input.tabSize, input.startVisibleColumn, input.containsRTL, input.spaceWidth, input.renderSpaceCharCode, input.renderWhitespace, input.renderControlCharacters); } /** * In the rendering phase, characters are always looped until token.endIndex. * Ensure that all tokens end before `len` and the last one ends precisely at `len`. */ function transformAndRemoveOverflowing(tokens, fauxIndentLength, len) { const result = []; let resultLen = 0; // The faux indent part of the line should have no token type if (fauxIndentLength > 0) { result[resultLen++] = new LinePart(fauxIndentLength, '', 0); } for (let tokenIndex = 0, tokensLen = tokens.getCount(); tokenIndex < tokensLen; tokenIndex++) { const endIndex = tokens.getEndOffset(tokenIndex); if (endIndex <= fauxIndentLength) { // The faux indent part of the line should have no token type continue; } const type = tokens.getClassName(tokenIndex); if (endIndex >= len) { result[resultLen++] = new LinePart(len, type, 0); break; } result[resultLen++] = new LinePart(endIndex, type, 0); } return result; } /** * See https://github.com/microsoft/vscode/issues/6885. * It appears that having very large spans causes very slow reading of character positions. * So here we try to avoid that. */ function splitLargeTokens(lineContent, tokens, onlyAtSpaces) { let lastTokenEndIndex = 0; const result = []; let resultLen = 0; if (onlyAtSpaces) { // Split only at spaces => we need to walk each character for (let i = 0, len = tokens.length; i < len; i++) { const token = tokens[i]; const tokenEndIndex = token.endIndex; if (lastTokenEndIndex + 50 /* LongToken */ < tokenEndIndex) { const tokenType = token.type; const tokenMetadata = token.metadata; let lastSpaceOffset = -1; let currTokenStart = lastTokenEndIndex; for (let j = lastTokenEndIndex; j < tokenEndIndex; j++) { if (lineContent.charCodeAt(j) === 32 /* Space */) { lastSpaceOffset = j; } if (lastSpaceOffset !== -1 && j - currTokenStart >= 50 /* LongToken */) { // Split at `lastSpaceOffset` + 1 result[resultLen++] = new LinePart(lastSpaceOffset + 1, tokenType, tokenMetadata); currTokenStart = lastSpaceOffset + 1; lastSpaceOffset = -1; } } if (currTokenStart !== tokenEndIndex) { result[resultLen++] = new LinePart(tokenEndIndex, tokenType, tokenMetadata); } } else { result[resultLen++] = token; } lastTokenEndIndex = tokenEndIndex; } } else { // Split anywhere => we don't need to walk each character for (let i = 0, len = tokens.length; i < len; i++) { const token = tokens[i]; const tokenEndIndex = token.endIndex; const diff = (tokenEndIndex - lastTokenEndIndex); if (diff > 50 /* LongToken */) { const tokenType = token.type; const tokenMetadata = token.metadata; const piecesCount = Math.ceil(diff / 50 /* LongToken */); for (let j = 1; j < piecesCount; j++) { const pieceEndIndex = lastTokenEndIndex + (j * 50 /* LongToken */); result[resultLen++] = new LinePart(pieceEndIndex, tokenType, tokenMetadata); } result[resultLen++] = new LinePart(tokenEndIndex, tokenType, tokenMetadata); } else { result[resultLen++] = token; } lastTokenEndIndex = tokenEndIndex; } } return result; } function isControlCharacter(charCode) { if (charCode < 32) { return (charCode !== 9 /* Tab */); } if (charCode === 127) { // DEL return true; } if ((charCode >= 0x202A && charCode <= 0x202E) || (charCode >= 0x2066 && charCode <= 0x2069) || (charCode >= 0x200E && charCode <= 0x200F) || charCode === 0x061C) { // Unicode Directional Formatting Characters // LRE U+202A LEFT-TO-RIGHT EMBEDDING // RLE U+202B RIGHT-TO-LEFT EMBEDDING // PDF U+202C POP DIRECTIONAL FORMATTING // LRO U+202D LEFT-TO-RIGHT OVERRIDE // RLO U+202E RIGHT-TO-LEFT OVERRIDE // LRI U+2066 LEFT-TO-RIGHT ISOLATE // RLI U+2067 RIGHT-TO-LEFT ISOLATE // FSI U+2068 FIRST STRONG ISOLATE // PDI U+2069 POP DIRECTIONAL ISOLATE // LRM U+200E LEFT-TO-RIGHT MARK // RLM U+200F RIGHT-TO-LEFT MARK // ALM U+061C ARABIC LETTER MARK return true; } return false; } function extractControlCharacters(lineContent, tokens) { const result = []; let lastLinePart = new LinePart(0, '', 0); let charOffset = 0; for (const token of tokens) { const tokenEndIndex = token.endIndex; for (; charOffset < tokenEndIndex; charOffset++) { const charCode = lineContent.charCodeAt(charOffset); if (isControlCharacter(charCode)) { if (charOffset > lastLinePart.endIndex) { // emit previous part if it has text lastLinePart = new LinePart(charOffset, token.type, token.metadata); result.push(lastLinePart); } lastLinePart = new LinePart(charOffset + 1, 'mtkcontrol', token.metadata); result.push(lastLinePart); } } if (charOffset > lastLinePart.endIndex) { // emit previous part if it has text lastLinePart = new LinePart(tokenEndIndex, token.type, token.metadata); result.push(lastLinePart); } } return result; } /** * Whitespace is rendered by "replacing" tokens with a special-purpose `mtkw` type that is later recognized in the rendering phase. * Moreover, a token is created for every visual indent because on some fonts the glyphs used for rendering whitespace (→ or ·) do not have the same width as  . * The rendering phase will generate `style="width:..."` for these tokens. */ function _applyRenderWhitespace(input, lineContent, len, tokens) { const continuesWithWrappedLine = input.continuesWithWrappedLine; const fauxIndentLength = input.fauxIndentLength; const tabSize = input.tabSize; const startVisibleColumn = input.startVisibleColumn; const useMonospaceOptimizations = input.useMonospaceOptimizations; const selections = input.selectionsOnLine; const onlyBoundary = (input.renderWhitespace === 1 /* Boundary */); const onlyTrailing = (input.renderWhitespace === 3 /* Trailing */); const generateLinePartForEachWhitespace = (input.renderSpaceWidth !== input.spaceWidth); const result = []; let resultLen = 0; let tokenIndex = 0; let tokenType = tokens[tokenIndex].type; let tokenEndIndex = tokens[tokenIndex].endIndex; const tokensLength = tokens.length; let lineIsEmptyOrWhitespace = false; let firstNonWhitespaceIndex$1 = firstNonWhitespaceIndex(lineContent); let lastNonWhitespaceIndex$1; if (firstNonWhitespaceIndex$1 === -1) { lineIsEmptyOrWhitespace = true; firstNonWhitespaceIndex$1 = len; lastNonWhitespaceIndex$1 = len; } else { lastNonWhitespaceIndex$1 = lastNonWhitespaceIndex(lineContent); } let wasInWhitespace = false; let currentSelectionIndex = 0; let currentSelection = selections && selections[currentSelectionIndex]; let tmpIndent = startVisibleColumn % tabSize; for (let charIndex = fauxIndentLength; charIndex < len; charIndex++) { const chCode = lineContent.charCodeAt(charIndex); if (currentSelection && charIndex >= currentSelection.endOffset) { currentSelectionIndex++; currentSelection = selections && selections[currentSelectionIndex]; } let isInWhitespace; if (charIndex < firstNonWhitespaceIndex$1 || charIndex > lastNonWhitespaceIndex$1) { // in leading or trailing whitespace isInWhitespace = true; } else if (chCode === 9 /* Tab */) { // a tab character is rendered both in all and boundary cases isInWhitespace = true; } else if (chCode === 32 /* Space */) { // hit a space character if (onlyBoundary) { // rendering only boundary whitespace if (wasInWhitespace) { isInWhitespace = true; } else { const nextChCode = (charIndex + 1 < len ? lineContent.charCodeAt(charIndex + 1) : 0 /* Null */); isInWhitespace = (nextChCode === 32 /* Space */ || nextChCode === 9 /* Tab */); } } else { isInWhitespace = true; } } else { isInWhitespace = false; } // If rendering whitespace on selection, check that the charIndex falls within a selection if (isInWhitespace && selections) { isInWhitespace = !!currentSelection && currentSelection.startOffset <= charIndex && currentSelection.endOffset > charIndex; } // If rendering only trailing whitespace, check that the charIndex points to trailing whitespace. if (isInWhitespace && onlyTrailing) { isInWhitespace = lineIsEmptyOrWhitespace || charIndex > lastNonWhitespaceIndex$1; } if (wasInWhitespace) { // was in whitespace token if (!isInWhitespace || (!useMonospaceOptimizations && tmpIndent >= tabSize)) { // leaving whitespace token or entering a new indent if (generateLinePartForEachWhitespace) { const lastEndIndex = (resultLen > 0 ? result[resultLen - 1].endIndex : fauxIndentLength); for (let i = lastEndIndex + 1; i <= charIndex; i++) { result[resultLen++] = new LinePart(i, 'mtkw', 1 /* IS_WHITESPACE */); } } else { result[resultLen++] = new LinePart(charIndex, 'mtkw', 1 /* IS_WHITESPACE */); } tmpIndent = tmpIndent % tabSize; } } else { // was in regular token if (charIndex === tokenEndIndex || (isInWhitespace && charIndex > fauxIndentLength)) { result[resultLen++] = new LinePart(charIndex, tokenType, 0); tmpIndent = tmpIndent % tabSize; } } if (chCode === 9 /* Tab */) { tmpIndent = tabSize; } else if (isFullWidthCharacter(chCode)) { tmpIndent += 2; } else { tmpIndent++; } wasInWhitespace = isInWhitespace; while (charIndex === tokenEndIndex) { tokenIndex++; if (tokenIndex < tokensLength) { tokenType = tokens[tokenIndex].type; tokenEndIndex = tokens[tokenIndex].endIndex; } else { break; } } } let generateWhitespace = false; if (wasInWhitespace) { // was in whitespace token if (continuesWithWrappedLine && onlyBoundary) { const lastCharCode = (len > 0 ? lineContent.charCodeAt(len - 1) : 0 /* Null */); const prevCharCode = (len > 1 ? lineContent.charCodeAt(len - 2) : 0 /* Null */); const isSingleTrailingSpace = (lastCharCode === 32 /* Space */ && (prevCharCode !== 32 /* Space */ && prevCharCode !== 9 /* Tab */)); if (!isSingleTrailingSpace) { generateWhitespace = true; } } else { generateWhitespace = true; } } if (generateWhitespace) { if (generateLinePartForEachWhitespace) { const lastEndIndex = (resultLen > 0 ? result[resultLen - 1].endIndex : fauxIndentLength); for (let i = lastEndIndex + 1; i <= len; i++) { result[resultLen++] = new LinePart(i, 'mtkw', 1 /* IS_WHITESPACE */); } } else { result[resultLen++] = new LinePart(len, 'mtkw', 1 /* IS_WHITESPACE */); } } else { result[resultLen++] = new LinePart(len, tokenType, 0); } return result; } /** * Inline decorations are "merged" on top of tokens. * Special care must be taken when multiple inline decorations are at play and they overlap. */ function _applyInlineDecorations(lineContent, len, tokens, _lineDecorations) { _lineDecorations.sort(LineDecoration.compare); const lineDecorations = LineDecorationsNormalizer.normalize(lineContent, _lineDecorations); const lineDecorationsLen = lineDecorations.length; let lineDecorationIndex = 0; const result = []; let resultLen = 0; let lastResultEndIndex = 0; for (let tokenIndex = 0, len = tokens.length; tokenIndex < len; tokenIndex++) { const token = tokens[tokenIndex]; const tokenEndIndex = token.endIndex; const tokenType = token.type; const tokenMetadata = token.metadata; while (lineDecorationIndex < lineDecorationsLen && lineDecorations[lineDecorationIndex].startOffset < tokenEndIndex) { const lineDecoration = lineDecorations[lineDecorationIndex]; if (lineDecoration.startOffset > lastResultEndIndex) { lastResultEndIndex = lineDecoration.startOffset; result[resultLen++] = new LinePart(lastResultEndIndex, tokenType, tokenMetadata); } if (lineDecoration.endOffset + 1 <= tokenEndIndex) { // This line decoration ends before this token ends lastResultEndIndex = lineDecoration.endOffset + 1; result[resultLen++] = new LinePart(lastResultEndIndex, tokenType + ' ' + lineDecoration.className, tokenMetadata | lineDecoration.metadata); lineDecorationIndex++; } else { // This line decoration continues on to the next token lastResultEndIndex = tokenEndIndex; result[resultLen++] = new LinePart(lastResultEndIndex, tokenType + ' ' + lineDecoration.className, tokenMetadata | lineDecoration.metadata); break; } } if (tokenEndIndex > lastResultEndIndex) { lastResultEndIndex = tokenEndIndex; result[resultLen++] = new LinePart(lastResultEndIndex, tokenType, tokenMetadata); } } const lastTokenEndIndex = tokens[tokens.length - 1].endIndex; if (lineDecorationIndex < lineDecorationsLen && lineDecorations[lineDecorationIndex].startOffset === lastTokenEndIndex) { while (lineDecorationIndex < lineDecorationsLen && lineDecorations[lineDecorationIndex].startOffset === lastTokenEndIndex) { const lineDecoration = lineDecorations[lineDecorationIndex]; result[resultLen++] = new LinePart(lastResultEndIndex, lineDecoration.className, lineDecoration.metadata); lineDecorationIndex++; } } return result; } /** * This function is on purpose not split up into multiple functions to allow runtime type inference (i.e. performance reasons). * Notice how all the needed data is fully resolved and passed in (i.e. no other calls). */ function _renderLine(input, sb) { const fontIsMonospace = input.fontIsMonospace; const canUseHalfwidthRightwardsArrow = input.canUseHalfwidthRightwardsArrow; const containsForeignElements = input.containsForeignElements; const lineContent = input.lineContent; const len = input.len; const isOverflowing = input.isOverflowing; const parts = input.parts; const fauxIndentLength = input.fauxIndentLength; const tabSize = input.tabSize; const startVisibleColumn = input.startVisibleColumn; const containsRTL = input.containsRTL; const spaceWidth = input.spaceWidth; const renderSpaceCharCode = input.renderSpaceCharCode; const renderWhitespace = input.renderWhitespace; const renderControlCharacters = input.renderControlCharacters; const characterMapping = new CharacterMapping(len + 1, parts.length); let lastCharacterMappingDefined = false; let charIndex = 0; let visibleColumn = startVisibleColumn; let charOffsetInPart = 0; let partDisplacement = 0; let prevPartContentCnt = 0; let partAbsoluteOffset = 0; if (containsRTL) { sb.appendASCIIString(''); } else { sb.appendASCIIString(''); } for (let partIndex = 0, tokensLen = parts.length; partIndex < tokensLen; partIndex++) { partAbsoluteOffset += prevPartContentCnt; const part = parts[partIndex]; const partEndIndex = part.endIndex; const partType = part.type; const partRendersWhitespace = (renderWhitespace !== 0 /* None */ && part.isWhitespace()); const partRendersWhitespaceWithWidth = partRendersWhitespace && !fontIsMonospace && (partType === 'mtkw' /*only whitespace*/ || !containsForeignElements); const partIsEmptyAndHasPseudoAfter = (charIndex === partEndIndex && part.isPseudoAfter()); charOffsetInPart = 0; sb.appendASCIIString(' 1) { sb.write1(0x2192); // RIGHTWARDS ARROW } else { sb.write1(0xFFEB); // HALFWIDTH RIGHTWARDS ARROW } for (let space = 2; space <= charWidth; space++) { sb.write1(0xA0); //   } } else { // must be CharCode.Space charWidth = 1; sb.write1(renderSpaceCharCode); // · or word separator middle dot } charOffsetInPart += charWidth; if (charIndex >= fauxIndentLength) { visibleColumn += charWidth; } } prevPartContentCnt = partContentCnt; } else { let partContentCnt = 0; sb.appendASCII(62 /* GreaterThan */); for (; charIndex < partEndIndex; charIndex++) { characterMapping.setColumnInfo(charIndex + 1, partIndex - partDisplacement, charOffsetInPart, partAbsoluteOffset); partDisplacement = 0; const charCode = lineContent.charCodeAt(charIndex); let producedCharacters = 1; let charWidth = 1; switch (charCode) { case 9 /* Tab */: producedCharacters = (tabSize - (visibleColumn % tabSize)); charWidth = producedCharacters; for (let space = 1; space <= producedCharacters; space++) { sb.write1(0xA0); //   } break; case 32 /* Space */: sb.write1(0xA0); //   break; case 60 /* LessThan */: sb.appendASCIIString('<'); break; case 62 /* GreaterThan */: sb.appendASCIIString('>'); break; case 38 /* Ampersand */: sb.appendASCIIString('&'); break; case 0 /* Null */: if (renderControlCharacters) { // See https://unicode-table.com/en/blocks/control-pictures/ sb.write1(9216); } else { sb.appendASCIIString('�'); } break; case 65279 /* UTF8_BOM */: case 8232 /* LINE_SEPARATOR */: case 8233 /* PARAGRAPH_SEPARATOR */: case 133 /* NEXT_LINE */: sb.write1(0xFFFD); break; default: if (isFullWidthCharacter(charCode)) { charWidth++; } // See https://unicode-table.com/en/blocks/control-pictures/ if (renderControlCharacters && charCode < 32) { sb.write1(9216 + charCode); } else if (renderControlCharacters && charCode === 127) { // DEL sb.write1(9249); } else if (renderControlCharacters && isControlCharacter(charCode)) { sb.appendASCIIString('[U+'); sb.appendASCIIString(to4CharHex(charCode)); sb.appendASCIIString(']'); producedCharacters = 8; } else { sb.write1(charCode); } } charOffsetInPart += producedCharacters; partContentCnt += producedCharacters; if (charIndex >= fauxIndentLength) { visibleColumn += charWidth; } } prevPartContentCnt = partContentCnt; } if (partIsEmptyAndHasPseudoAfter) { partDisplacement++; } else { partDisplacement = 0; } if (charIndex >= len && !lastCharacterMappingDefined && part.isPseudoAfter()) { lastCharacterMappingDefined = true; characterMapping.setColumnInfo(charIndex + 1, partIndex, charOffsetInPart, partAbsoluteOffset); } sb.appendASCIIString(''); } if (!lastCharacterMappingDefined) { // When getting client rects for the last character, we will position the // text range at the end of the span, insteaf of at the beginning of next span characterMapping.setColumnInfo(len + 1, parts.length - 1, charOffsetInPart, partAbsoluteOffset); } if (isOverflowing) { sb.appendASCIIString(''); } sb.appendASCIIString(''); return new RenderLineOutput(characterMapping, containsRTL, containsForeignElements); } function to4CharHex(n) { return n.toString(16).toUpperCase().padStart(4, '0'); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class Viewport { constructor(top, left, width, height) { this._viewportBrand = undefined; this.top = top | 0; this.left = left | 0; this.width = width | 0; this.height = height | 0; } } class MinimapLinesRenderingData { constructor(tabSize, data) { this.tabSize = tabSize; this.data = data; } } class ViewLineData { constructor(content, continuesWithWrappedLine, minColumn, maxColumn, startVisibleColumn, tokens, inlineDecorations) { this._viewLineDataBrand = undefined; this.content = content; this.continuesWithWrappedLine = continuesWithWrappedLine; this.minColumn = minColumn; this.maxColumn = maxColumn; this.startVisibleColumn = startVisibleColumn; this.tokens = tokens; this.inlineDecorations = inlineDecorations; } } class ViewLineRenderingData { constructor(minColumn, maxColumn, content, continuesWithWrappedLine, mightContainRTL, mightContainNonBasicASCII, tokens, inlineDecorations, tabSize, startVisibleColumn) { this.minColumn = minColumn; this.maxColumn = maxColumn; this.content = content; this.continuesWithWrappedLine = continuesWithWrappedLine; this.isBasicASCII = ViewLineRenderingData.isBasicASCII(content, mightContainNonBasicASCII); this.containsRTL = ViewLineRenderingData.containsRTL(content, this.isBasicASCII, mightContainRTL); this.tokens = tokens; this.inlineDecorations = inlineDecorations; this.tabSize = tabSize; this.startVisibleColumn = startVisibleColumn; } static isBasicASCII(lineContent, mightContainNonBasicASCII) { if (mightContainNonBasicASCII) { return isBasicASCII(lineContent); } return true; } static containsRTL(lineContent, isBasicASCII, mightContainRTL) { if (!isBasicASCII && mightContainRTL) { return containsRTL(lineContent); } return false; } } class InlineDecoration { constructor(range, inlineClassName, type) { this.range = range; this.inlineClassName = inlineClassName; this.type = type; } } class SingleLineInlineDecoration { constructor(startOffset, endOffset, inlineClassName, inlineClassNameAffectsLetterSpacing) { this.startOffset = startOffset; this.endOffset = endOffset; this.inlineClassName = inlineClassName; this.inlineClassNameAffectsLetterSpacing = inlineClassNameAffectsLetterSpacing; } toInlineDecoration(lineNumber) { return new InlineDecoration(new Range$5(lineNumber, this.startOffset + 1, lineNumber, this.endOffset + 1), this.inlineClassName, this.inlineClassNameAffectsLetterSpacing ? 3 /* RegularAffectingLetterSpacing */ : 0 /* Regular */); } } class ViewModelDecoration { constructor(range, options) { this._viewModelDecorationBrand = undefined; this.range = range; this.options = options; } } class OverviewRulerDecorationsGroup { constructor(color, zIndex, /** * Decorations are encoded in a number array using the following scheme: * - 3*i = lane * - 3*i+1 = startLineNumber * - 3*i+2 = endLineNumber */ data) { this.color = color; this.zIndex = zIndex; this.data = data; } static cmp(a, b) { if (a.zIndex === b.zIndex) { if (a.color < b.color) { return -1; } if (a.color > b.color) { return 1; } return 0; } return a.zIndex - b.zIndex; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function isFuzzyActionArr(what) { return (Array.isArray(what)); } function isFuzzyAction(what) { return !isFuzzyActionArr(what); } function isString(what) { return (typeof what === 'string'); } function isIAction(what) { return !isString(what); } // Small helper functions /** * Is a string null, undefined, or empty? */ function empty(s) { return (s ? false : true); } /** * Puts a string to lower case if 'ignoreCase' is set. */ function fixCase(lexer, str) { return (lexer.ignoreCase && str ? str.toLowerCase() : str); } /** * Ensures there are no bad characters in a CSS token class. */ function sanitize$1(s) { return s.replace(/[&<>'"_]/g, '-'); // used on all output token CSS classes } // Logging /** * Logs a message. */ function log(lexer, msg) { console.log(`${lexer.languageId}: ${msg}`); } // Throwing errors function createError(lexer, msg) { return new Error(`${lexer.languageId}: ${msg}`); } // Helper functions for rule finding and substitution /** * substituteMatches is used on lexer strings and can substitutes predefined patterns: * $$ => $ * $# => id * $n => matched entry n * @attr => contents of lexer[attr] * * See documentation for more info */ function substituteMatches(lexer, str, id, matches, state) { const re = /\$((\$)|(#)|(\d\d?)|[sS](\d\d?)|@(\w+))/g; let stateMatches = null; return str.replace(re, function (full, sub, dollar, hash, n, s, attr, ofs, total) { if (!empty(dollar)) { return '$'; // $$ } if (!empty(hash)) { return fixCase(lexer, id); // default $# } if (!empty(n) && n < matches.length) { return fixCase(lexer, matches[n]); // $n } if (!empty(attr) && lexer && typeof (lexer[attr]) === 'string') { return lexer[attr]; //@attribute } if (stateMatches === null) { // split state on demand stateMatches = state.split('.'); stateMatches.unshift(state); } if (!empty(s) && s < stateMatches.length) { return fixCase(lexer, stateMatches[s]); //$Sn } return ''; }); } /** * Find the tokenizer rules for a specific state (i.e. next action) */ function findRules(lexer, inState) { let state = inState; while (state && state.length > 0) { const rules = lexer.tokenizer[state]; if (rules) { return rules; } const idx = state.lastIndexOf('.'); if (idx < 0) { state = null; // no further parent } else { state = state.substr(0, idx); } } return null; } /** * Is a certain state defined? In contrast to 'findRules' this works on a ILexerMin. * This is used during compilation where we may know the defined states * but not yet whether the corresponding rules are correct. */ function stateExists(lexer, inState) { let state = inState; while (state && state.length > 0) { const exist = lexer.stateNames[state]; if (exist) { return true; } const idx = state.lastIndexOf('.'); if (idx < 0) { state = null; // no further parent } else { state = state.substr(0, idx); } } return false; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const CACHE_STACK_DEPTH = 5; /** * Reuse the same stack elements up to a certain depth. */ class MonarchStackElementFactory { constructor(maxCacheDepth) { this._maxCacheDepth = maxCacheDepth; this._entries = Object.create(null); } static create(parent, state) { return this._INSTANCE.create(parent, state); } create(parent, state) { if (parent !== null && parent.depth >= this._maxCacheDepth) { // no caching above a certain depth return new MonarchStackElement(parent, state); } let stackElementId = MonarchStackElement.getStackElementId(parent); if (stackElementId.length > 0) { stackElementId += '|'; } stackElementId += state; let result = this._entries[stackElementId]; if (result) { return result; } result = new MonarchStackElement(parent, state); this._entries[stackElementId] = result; return result; } } MonarchStackElementFactory._INSTANCE = new MonarchStackElementFactory(CACHE_STACK_DEPTH); class MonarchStackElement { constructor(parent, state) { this.parent = parent; this.state = state; this.depth = (this.parent ? this.parent.depth : 0) + 1; } static getStackElementId(element) { let result = ''; while (element !== null) { if (result.length > 0) { result += '|'; } result += element.state; element = element.parent; } return result; } static _equals(a, b) { while (a !== null && b !== null) { if (a === b) { return true; } if (a.state !== b.state) { return false; } a = a.parent; b = b.parent; } if (a === null && b === null) { return true; } return false; } equals(other) { return MonarchStackElement._equals(this, other); } push(state) { return MonarchStackElementFactory.create(this, state); } pop() { return this.parent; } popall() { let result = this; while (result.parent) { result = result.parent; } return result; } switchTo(state) { return MonarchStackElementFactory.create(this.parent, state); } } class EmbeddedLanguageData { constructor(languageId, state) { this.languageId = languageId; this.state = state; } equals(other) { return (this.languageId === other.languageId && this.state.equals(other.state)); } clone() { const stateClone = this.state.clone(); // save an object if (stateClone === this.state) { return this; } return new EmbeddedLanguageData(this.languageId, this.state); } } /** * Reuse the same line states up to a certain depth. */ class MonarchLineStateFactory { constructor(maxCacheDepth) { this._maxCacheDepth = maxCacheDepth; this._entries = Object.create(null); } static create(stack, embeddedLanguageData) { return this._INSTANCE.create(stack, embeddedLanguageData); } create(stack, embeddedLanguageData) { if (embeddedLanguageData !== null) { // no caching when embedding return new MonarchLineState(stack, embeddedLanguageData); } if (stack !== null && stack.depth >= this._maxCacheDepth) { // no caching above a certain depth return new MonarchLineState(stack, embeddedLanguageData); } const stackElementId = MonarchStackElement.getStackElementId(stack); let result = this._entries[stackElementId]; if (result) { return result; } result = new MonarchLineState(stack, null); this._entries[stackElementId] = result; return result; } } MonarchLineStateFactory._INSTANCE = new MonarchLineStateFactory(CACHE_STACK_DEPTH); class MonarchLineState { constructor(stack, embeddedLanguageData) { this.stack = stack; this.embeddedLanguageData = embeddedLanguageData; } clone() { const embeddedlanguageDataClone = this.embeddedLanguageData ? this.embeddedLanguageData.clone() : null; // save an object if (embeddedlanguageDataClone === this.embeddedLanguageData) { return this; } return MonarchLineStateFactory.create(this.stack, this.embeddedLanguageData); } equals(other) { if (!(other instanceof MonarchLineState)) { return false; } if (!this.stack.equals(other.stack)) { return false; } if (this.embeddedLanguageData === null && other.embeddedLanguageData === null) { return true; } if (this.embeddedLanguageData === null || other.embeddedLanguageData === null) { return false; } return this.embeddedLanguageData.equals(other.embeddedLanguageData); } } class MonarchClassicTokensCollector { constructor() { this._tokens = []; this._languageId = null; this._lastTokenType = null; this._lastTokenLanguage = null; } enterLanguage(languageId) { this._languageId = languageId; } emit(startOffset, type) { if (this._lastTokenType === type && this._lastTokenLanguage === this._languageId) { return; } this._lastTokenType = type; this._lastTokenLanguage = this._languageId; this._tokens.push(new Token$2(startOffset, type, this._languageId)); } nestedLanguageTokenize(embeddedLanguageLine, hasEOL, embeddedLanguageData, offsetDelta) { const nestedLanguageId = embeddedLanguageData.languageId; const embeddedModeState = embeddedLanguageData.state; const nestedLanguageTokenizationSupport = TokenizationRegistry.get(nestedLanguageId); if (!nestedLanguageTokenizationSupport) { this.enterLanguage(nestedLanguageId); this.emit(offsetDelta, ''); return embeddedModeState; } const nestedResult = nestedLanguageTokenizationSupport.tokenize(embeddedLanguageLine, hasEOL, embeddedModeState); if (offsetDelta !== 0) { for (const token of nestedResult.tokens) { this._tokens.push(new Token$2(token.offset + offsetDelta, token.type, token.language)); } } else { this._tokens = this._tokens.concat(nestedResult.tokens); } this._lastTokenType = null; this._lastTokenLanguage = null; this._languageId = null; return nestedResult.endState; } finalize(endState) { return new TokenizationResult(this._tokens, endState); } } class MonarchModernTokensCollector { constructor(languageService, theme) { this._languageService = languageService; this._theme = theme; this._prependTokens = null; this._tokens = []; this._currentLanguageId = 0 /* Null */; this._lastTokenMetadata = 0; } enterLanguage(languageId) { this._currentLanguageId = this._languageService.languageIdCodec.encodeLanguageId(languageId); } emit(startOffset, type) { const metadata = this._theme.match(this._currentLanguageId, type); if (this._lastTokenMetadata === metadata) { return; } this._lastTokenMetadata = metadata; this._tokens.push(startOffset); this._tokens.push(metadata); } static _merge(a, b, c) { const aLen = (a !== null ? a.length : 0); const bLen = b.length; const cLen = (c !== null ? c.length : 0); if (aLen === 0 && bLen === 0 && cLen === 0) { return new Uint32Array(0); } if (aLen === 0 && bLen === 0) { return c; } if (bLen === 0 && cLen === 0) { return a; } const result = new Uint32Array(aLen + bLen + cLen); if (a !== null) { result.set(a); } for (let i = 0; i < bLen; i++) { result[aLen + i] = b[i]; } if (c !== null) { result.set(c, aLen + bLen); } return result; } nestedLanguageTokenize(embeddedLanguageLine, hasEOL, embeddedLanguageData, offsetDelta) { const nestedLanguageId = embeddedLanguageData.languageId; const embeddedModeState = embeddedLanguageData.state; const nestedLanguageTokenizationSupport = TokenizationRegistry.get(nestedLanguageId); if (!nestedLanguageTokenizationSupport) { this.enterLanguage(nestedLanguageId); this.emit(offsetDelta, ''); return embeddedModeState; } const nestedResult = nestedLanguageTokenizationSupport.tokenizeEncoded(embeddedLanguageLine, hasEOL, embeddedModeState); if (offsetDelta !== 0) { for (let i = 0, len = nestedResult.tokens.length; i < len; i += 2) { nestedResult.tokens[i] += offsetDelta; } } this._prependTokens = MonarchModernTokensCollector._merge(this._prependTokens, this._tokens, nestedResult.tokens); this._tokens = []; this._currentLanguageId = 0; this._lastTokenMetadata = 0; return nestedResult.endState; } finalize(endState) { return new EncodedTokenizationResult(MonarchModernTokensCollector._merge(this._prependTokens, this._tokens, null), endState); } } class MonarchTokenizer { constructor(languageService, standaloneThemeService, languageId, lexer) { this._languageService = languageService; this._standaloneThemeService = standaloneThemeService; this._languageId = languageId; this._lexer = lexer; this._embeddedLanguages = Object.create(null); this.embeddedLoaded = Promise.resolve(undefined); // Set up listening for embedded modes let emitting = false; this._tokenizationRegistryListener = TokenizationRegistry.onDidChange((e) => { if (emitting) { return; } let isOneOfMyEmbeddedModes = false; for (let i = 0, len = e.changedLanguages.length; i < len; i++) { const language = e.changedLanguages[i]; if (this._embeddedLanguages[language]) { isOneOfMyEmbeddedModes = true; break; } } if (isOneOfMyEmbeddedModes) { emitting = true; TokenizationRegistry.fire([this._languageId]); emitting = false; } }); } dispose() { this._tokenizationRegistryListener.dispose(); } getLoadStatus() { const promises = []; for (let nestedLanguageId in this._embeddedLanguages) { const tokenizationSupport = TokenizationRegistry.get(nestedLanguageId); if (tokenizationSupport) { // The nested language is already loaded if (tokenizationSupport instanceof MonarchTokenizer) { const nestedModeStatus = tokenizationSupport.getLoadStatus(); if (nestedModeStatus.loaded === false) { promises.push(nestedModeStatus.promise); } } continue; } if (!TokenizationRegistry.isResolved(nestedLanguageId)) { // The nested language is in the process of being loaded promises.push(TokenizationRegistry.getOrCreate(nestedLanguageId)); } } if (promises.length === 0) { return { loaded: true }; } return { loaded: false, promise: Promise.all(promises).then(_ => undefined) }; } getInitialState() { const rootState = MonarchStackElementFactory.create(null, this._lexer.start); return MonarchLineStateFactory.create(rootState, null); } tokenize(line, hasEOL, lineState) { const tokensCollector = new MonarchClassicTokensCollector(); const endLineState = this._tokenize(line, hasEOL, lineState, tokensCollector); return tokensCollector.finalize(endLineState); } tokenizeEncoded(line, hasEOL, lineState) { const tokensCollector = new MonarchModernTokensCollector(this._languageService, this._standaloneThemeService.getColorTheme().tokenTheme); const endLineState = this._tokenize(line, hasEOL, lineState, tokensCollector); return tokensCollector.finalize(endLineState); } _tokenize(line, hasEOL, lineState, collector) { if (lineState.embeddedLanguageData) { return this._nestedTokenize(line, hasEOL, lineState, 0, collector); } else { return this._myTokenize(line, hasEOL, lineState, 0, collector); } } _findLeavingNestedLanguageOffset(line, state) { let rules = this._lexer.tokenizer[state.stack.state]; if (!rules) { rules = findRules(this._lexer, state.stack.state); // do parent matching if (!rules) { throw createError(this._lexer, 'tokenizer state is not defined: ' + state.stack.state); } } let popOffset = -1; let hasEmbeddedPopRule = false; for (const rule of rules) { if (!isIAction(rule.action) || rule.action.nextEmbedded !== '@pop') { continue; } hasEmbeddedPopRule = true; let regex = rule.regex; const regexSource = rule.regex.source; if (regexSource.substr(0, 4) === '^(?:' && regexSource.substr(regexSource.length - 1, 1) === ')') { const flags = (regex.ignoreCase ? 'i' : '') + (regex.unicode ? 'u' : ''); regex = new RegExp(regexSource.substr(4, regexSource.length - 5), flags); } const result = line.search(regex); if (result === -1 || (result !== 0 && rule.matchOnlyAtLineStart)) { continue; } if (popOffset === -1 || result < popOffset) { popOffset = result; } } if (!hasEmbeddedPopRule) { throw createError(this._lexer, 'no rule containing nextEmbedded: "@pop" in tokenizer embedded state: ' + state.stack.state); } return popOffset; } _nestedTokenize(line, hasEOL, lineState, offsetDelta, tokensCollector) { const popOffset = this._findLeavingNestedLanguageOffset(line, lineState); if (popOffset === -1) { // tokenization will not leave nested language const nestedEndState = tokensCollector.nestedLanguageTokenize(line, hasEOL, lineState.embeddedLanguageData, offsetDelta); return MonarchLineStateFactory.create(lineState.stack, new EmbeddedLanguageData(lineState.embeddedLanguageData.languageId, nestedEndState)); } const nestedLanguageLine = line.substring(0, popOffset); if (nestedLanguageLine.length > 0) { // tokenize with the nested language tokensCollector.nestedLanguageTokenize(nestedLanguageLine, false, lineState.embeddedLanguageData, offsetDelta); } const restOfTheLine = line.substring(popOffset); return this._myTokenize(restOfTheLine, hasEOL, lineState, offsetDelta + popOffset, tokensCollector); } _safeRuleName(rule) { if (rule) { return rule.name; } return '(unknown)'; } _myTokenize(lineWithoutLF, hasEOL, lineState, offsetDelta, tokensCollector) { tokensCollector.enterLanguage(this._languageId); const lineWithoutLFLength = lineWithoutLF.length; const line = (hasEOL && this._lexer.includeLF ? lineWithoutLF + '\n' : lineWithoutLF); const lineLength = line.length; let embeddedLanguageData = lineState.embeddedLanguageData; let stack = lineState.stack; let pos = 0; let groupMatching = null; // See https://github.com/microsoft/monaco-editor/issues/1235 // Evaluate rules at least once for an empty line let forceEvaluation = true; while (forceEvaluation || pos < lineLength) { const pos0 = pos; const stackLen0 = stack.depth; const groupLen0 = groupMatching ? groupMatching.groups.length : 0; const state = stack.state; let matches = null; let matched = null; let action = null; let rule = null; let enteringEmbeddedLanguage = null; // check if we need to process group matches first if (groupMatching) { matches = groupMatching.matches; const groupEntry = groupMatching.groups.shift(); matched = groupEntry.matched; action = groupEntry.action; rule = groupMatching.rule; // cleanup if necessary if (groupMatching.groups.length === 0) { groupMatching = null; } } else { // otherwise we match on the token stream if (!forceEvaluation && pos >= lineLength) { // nothing to do break; } forceEvaluation = false; // get the rules for this state let rules = this._lexer.tokenizer[state]; if (!rules) { rules = findRules(this._lexer, state); // do parent matching if (!rules) { throw createError(this._lexer, 'tokenizer state is not defined: ' + state); } } // try each rule until we match let restOfLine = line.substr(pos); for (const rule of rules) { if (pos === 0 || !rule.matchOnlyAtLineStart) { matches = restOfLine.match(rule.regex); if (matches) { matched = matches[0]; action = rule.action; break; } } } } // We matched 'rule' with 'matches' and 'action' if (!matches) { matches = ['']; matched = ''; } if (!action) { // bad: we didn't match anything, and there is no action to take // we need to advance the stream or we get progress trouble if (pos < lineLength) { matches = [line.charAt(pos)]; matched = matches[0]; } action = this._lexer.defaultToken; } if (matched === null) { // should never happen, needed for strict null checking break; } // advance stream pos += matched.length; // maybe call action function (used for 'cases') while (isFuzzyAction(action) && isIAction(action) && action.test) { action = action.test(matched, matches, state, pos === lineLength); } let result = null; // set the result: either a string or an array of actions if (typeof action === 'string' || Array.isArray(action)) { result = action; } else if (action.group) { result = action.group; } else if (action.token !== null && action.token !== undefined) { // do $n replacements? if (action.tokenSubst) { result = substituteMatches(this._lexer, action.token, matched, matches, state); } else { result = action.token; } // enter embedded language? if (action.nextEmbedded) { if (action.nextEmbedded === '@pop') { if (!embeddedLanguageData) { throw createError(this._lexer, 'cannot pop embedded language if not inside one'); } embeddedLanguageData = null; } else if (embeddedLanguageData) { throw createError(this._lexer, 'cannot enter embedded language from within an embedded language'); } else { enteringEmbeddedLanguage = substituteMatches(this._lexer, action.nextEmbedded, matched, matches, state); } } // state transformations if (action.goBack) { // back up the stream.. pos = Math.max(0, pos - action.goBack); } if (action.switchTo && typeof action.switchTo === 'string') { let nextState = substituteMatches(this._lexer, action.switchTo, matched, matches, state); // switch state without a push... if (nextState[0] === '@') { nextState = nextState.substr(1); // peel off starting '@' } if (!findRules(this._lexer, nextState)) { throw createError(this._lexer, 'trying to switch to a state \'' + nextState + '\' that is undefined in rule: ' + this._safeRuleName(rule)); } else { stack = stack.switchTo(nextState); } } else if (action.transform && typeof action.transform === 'function') { throw createError(this._lexer, 'action.transform not supported'); } else if (action.next) { if (action.next === '@push') { if (stack.depth >= this._lexer.maxStack) { throw createError(this._lexer, 'maximum tokenizer stack size reached: [' + stack.state + ',' + stack.parent.state + ',...]'); } else { stack = stack.push(state); } } else if (action.next === '@pop') { if (stack.depth <= 1) { throw createError(this._lexer, 'trying to pop an empty stack in rule: ' + this._safeRuleName(rule)); } else { stack = stack.pop(); } } else if (action.next === '@popall') { stack = stack.popall(); } else { let nextState = substituteMatches(this._lexer, action.next, matched, matches, state); if (nextState[0] === '@') { nextState = nextState.substr(1); // peel off starting '@' } if (!findRules(this._lexer, nextState)) { throw createError(this._lexer, 'trying to set a next state \'' + nextState + '\' that is undefined in rule: ' + this._safeRuleName(rule)); } else { stack = stack.push(nextState); } } } if (action.log && typeof (action.log) === 'string') { log(this._lexer, this._lexer.languageId + ': ' + substituteMatches(this._lexer, action.log, matched, matches, state)); } } // check result if (result === null) { throw createError(this._lexer, 'lexer rule has no well-defined action in rule: ' + this._safeRuleName(rule)); } const computeNewStateForEmbeddedLanguage = (enteringEmbeddedLanguage) => { // support language names, mime types, and language ids const languageId = (this._languageService.getLanguageIdByLanguageName(enteringEmbeddedLanguage) || this._languageService.getLanguageIdByMimeType(enteringEmbeddedLanguage) || enteringEmbeddedLanguage); const embeddedLanguageData = this._getNestedEmbeddedLanguageData(languageId); if (pos < lineLength) { // there is content from the embedded language on this line const restOfLine = lineWithoutLF.substr(pos); return this._nestedTokenize(restOfLine, hasEOL, MonarchLineStateFactory.create(stack, embeddedLanguageData), offsetDelta + pos, tokensCollector); } else { return MonarchLineStateFactory.create(stack, embeddedLanguageData); } }; // is the result a group match? if (Array.isArray(result)) { if (groupMatching && groupMatching.groups.length > 0) { throw createError(this._lexer, 'groups cannot be nested: ' + this._safeRuleName(rule)); } if (matches.length !== result.length + 1) { throw createError(this._lexer, 'matched number of groups does not match the number of actions in rule: ' + this._safeRuleName(rule)); } let totalLen = 0; for (let i = 1; i < matches.length; i++) { totalLen += matches[i].length; } if (totalLen !== matched.length) { throw createError(this._lexer, 'with groups, all characters should be matched in consecutive groups in rule: ' + this._safeRuleName(rule)); } groupMatching = { rule: rule, matches: matches, groups: [] }; for (let i = 0; i < result.length; i++) { groupMatching.groups[i] = { action: result[i], matched: matches[i + 1] }; } pos -= matched.length; // call recursively to initiate first result match continue; } else { // regular result // check for '@rematch' if (result === '@rematch') { pos -= matched.length; matched = ''; // better set the next state too.. matches = null; result = ''; // Even though `@rematch` was specified, if `nextEmbedded` also specified, // a state transition should occur. if (enteringEmbeddedLanguage !== null) { return computeNewStateForEmbeddedLanguage(enteringEmbeddedLanguage); } } // check progress if (matched.length === 0) { if (lineLength === 0 || stackLen0 !== stack.depth || state !== stack.state || (!groupMatching ? 0 : groupMatching.groups.length) !== groupLen0) { continue; } else { throw createError(this._lexer, 'no progress in tokenizer in rule: ' + this._safeRuleName(rule)); } } // return the result (and check for brace matching) // todo: for efficiency we could pre-sanitize tokenPostfix and substitutions let tokenType = null; if (isString(result) && result.indexOf('@brackets') === 0) { const rest = result.substr('@brackets'.length); const bracket = findBracket(this._lexer, matched); if (!bracket) { throw createError(this._lexer, '@brackets token returned but no bracket defined as: ' + matched); } tokenType = sanitize$1(bracket.token + rest); } else { const token = (result === '' ? '' : result + this._lexer.tokenPostfix); tokenType = sanitize$1(token); } if (pos0 < lineWithoutLFLength) { tokensCollector.emit(pos0 + offsetDelta, tokenType); } } if (enteringEmbeddedLanguage !== null) { return computeNewStateForEmbeddedLanguage(enteringEmbeddedLanguage); } } return MonarchLineStateFactory.create(stack, embeddedLanguageData); } _getNestedEmbeddedLanguageData(languageId) { if (!this._languageService.isRegisteredLanguageId(languageId)) { return new EmbeddedLanguageData(languageId, NullState); } if (languageId !== this._languageId) { // Fire language loading event TokenizationRegistry.getOrCreate(languageId); this._embeddedLanguages[languageId] = true; } const tokenizationSupport = TokenizationRegistry.get(languageId); if (tokenizationSupport) { return new EmbeddedLanguageData(languageId, tokenizationSupport.getInitialState()); } return new EmbeddedLanguageData(languageId, NullState); } } /** * Searches for a bracket in the 'brackets' attribute that matches the input. */ function findBracket(lexer, matched) { if (!matched) { return null; } matched = fixCase(lexer, matched); const brackets = lexer.brackets; for (const bracket of brackets) { if (bracket.open === matched) { return { token: bracket.token, bracketType: 1 /* Open */ }; } else if (bracket.close === matched) { return { token: bracket.token, bracketType: -1 /* Close */ }; } } return null; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __awaiter$15 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var _a$9; const ttPolicy$3 = (_a$9 = window.trustedTypes) === null || _a$9 === void 0 ? void 0 : _a$9.createPolicy('standaloneColorizer', { createHTML: value => value }); class Colorizer { static colorizeElement(themeService, languageService, domNode, options) { options = options || {}; const theme = options.theme || 'vs'; const mimeType = options.mimeType || domNode.getAttribute('lang') || domNode.getAttribute('data-lang'); if (!mimeType) { console.error('Mode not detected'); return Promise.resolve(); } const languageId = languageService.getLanguageIdByMimeType(mimeType) || mimeType; themeService.setTheme(theme); const text = domNode.firstChild ? domNode.firstChild.nodeValue : ''; domNode.className += ' ' + theme; const render = (str) => { var _a; const trustedhtml = (_a = ttPolicy$3 === null || ttPolicy$3 === void 0 ? void 0 : ttPolicy$3.createHTML(str)) !== null && _a !== void 0 ? _a : str; domNode.innerHTML = trustedhtml; }; return this.colorize(languageService, text || '', languageId, options).then(render, (err) => console.error(err)); } static colorize(languageService, text, languageId, options) { return __awaiter$15(this, void 0, void 0, function* () { const languageIdCodec = languageService.languageIdCodec; let tabSize = 4; if (options && typeof options.tabSize === 'number') { tabSize = options.tabSize; } if (startsWithUTF8BOM(text)) { text = text.substr(1); } const lines = splitLines(text); if (!languageService.isRegisteredLanguageId(languageId)) { return _fakeColorize(lines, tabSize, languageIdCodec); } const tokenizationSupport = yield TokenizationRegistry.getOrCreate(languageId); if (tokenizationSupport) { return _colorize(lines, tabSize, tokenizationSupport, languageIdCodec); } return _fakeColorize(lines, tabSize, languageIdCodec); }); } static colorizeLine(line, mightContainNonBasicASCII, mightContainRTL, tokens, tabSize = 4) { const isBasicASCII = ViewLineRenderingData.isBasicASCII(line, mightContainNonBasicASCII); const containsRTL = ViewLineRenderingData.containsRTL(line, isBasicASCII, mightContainRTL); const renderResult = renderViewLine2(new RenderLineInput(false, true, line, false, isBasicASCII, containsRTL, 0, tokens, [], tabSize, 0, 0, 0, 0, -1, 'none', false, false, null)); return renderResult.html; } static colorizeModelLine(model, lineNumber, tabSize = 4) { const content = model.getLineContent(lineNumber); model.forceTokenization(lineNumber); const tokens = model.getLineTokens(lineNumber); const inflatedTokens = tokens.inflate(); return this.colorizeLine(content, model.mightContainNonBasicASCII(), model.mightContainRTL(), inflatedTokens, tabSize); } } function _colorize(lines, tabSize, tokenizationSupport, languageIdCodec) { return new Promise((c, e) => { const execute = () => { const result = _actualColorize(lines, tabSize, tokenizationSupport, languageIdCodec); if (tokenizationSupport instanceof MonarchTokenizer) { const status = tokenizationSupport.getLoadStatus(); if (status.loaded === false) { status.promise.then(execute, e); return; } } c(result); }; execute(); }); } function _fakeColorize(lines, tabSize, languageIdCodec) { let html = []; const defaultMetadata = ((0 /* None */ << 10 /* FONT_STYLE_OFFSET */) | (1 /* DefaultForeground */ << 14 /* FOREGROUND_OFFSET */) | (2 /* DefaultBackground */ << 23 /* BACKGROUND_OFFSET */)) >>> 0; const tokens = new Uint32Array(2); tokens[0] = 0; tokens[1] = defaultMetadata; for (let i = 0, length = lines.length; i < length; i++) { const line = lines[i]; tokens[0] = line.length; const lineTokens = new LineTokens(tokens, line, languageIdCodec); const isBasicASCII = ViewLineRenderingData.isBasicASCII(line, /* check for basic ASCII */ true); const containsRTL = ViewLineRenderingData.containsRTL(line, isBasicASCII, /* check for RTL */ true); const renderResult = renderViewLine2(new RenderLineInput(false, true, line, false, isBasicASCII, containsRTL, 0, lineTokens, [], tabSize, 0, 0, 0, 0, -1, 'none', false, false, null)); html = html.concat(renderResult.html); html.push('
'); } return html.join(''); } function _actualColorize(lines, tabSize, tokenizationSupport, languageIdCodec) { let html = []; let state = tokenizationSupport.getInitialState(); for (let i = 0, length = lines.length; i < length; i++) { const line = lines[i]; const tokenizeResult = tokenizationSupport.tokenizeEncoded(line, true, state); LineTokens.convertToEndOffset(tokenizeResult.tokens, line.length); const lineTokens = new LineTokens(tokenizeResult.tokens, line, languageIdCodec); const isBasicASCII = ViewLineRenderingData.isBasicASCII(line, /* check for basic ASCII */ true); const containsRTL = ViewLineRenderingData.containsRTL(line, isBasicASCII, /* check for RTL */ true); const renderResult = renderViewLine2(new RenderLineInput(false, true, line, false, isBasicASCII, containsRTL, 0, lineTokens.inflate(), [], tabSize, 0, 0, 0, 0, -1, 'none', false, false, null)); html = html.concat(renderResult.html); html.push('
'); state = tokenizeResult.endState; } return html.join(''); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Browser feature we can support in current platform, browser and environment. */ const BrowserFeatures = { clipboard: { writeText: (isNative || (document.queryCommandSupported && document.queryCommandSupported('copy')) || !!(navigator && navigator.clipboard && navigator.clipboard.writeText)), readText: (isNative || !!(navigator && navigator.clipboard && navigator.clipboard.readText)) }, keyboard: (() => { if (isNative || isStandalone) { return 0 /* Always */; } if (navigator.keyboard || isSafari) { return 1 /* FullScreen */; } return 2 /* None */; })(), // 'ontouchstart' in window always evaluates to true with typescript's modern typings. This causes `window` to be // `never` later in `window.navigator`. That's why we need the explicit `window as Window` cast touch: 'ontouchstart' in window || navigator.maxTouchPoints > 0, pointerEvents: window.PointerEvent && ('ontouchstart' in window || window.navigator.maxTouchPoints > 0 || navigator.maxTouchPoints > 0) }; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function createKeybinding(keybinding, OS) { if (keybinding === 0) { return null; } const firstPart = (keybinding & 0x0000FFFF) >>> 0; const chordPart = (keybinding & 0xFFFF0000) >>> 16; if (chordPart !== 0) { return new ChordKeybinding([ createSimpleKeybinding(firstPart, OS), createSimpleKeybinding(chordPart, OS) ]); } return new ChordKeybinding([createSimpleKeybinding(firstPart, OS)]); } function createSimpleKeybinding(keybinding, OS) { const ctrlCmd = (keybinding & 2048 /* CtrlCmd */ ? true : false); const winCtrl = (keybinding & 256 /* WinCtrl */ ? true : false); const ctrlKey = (OS === 2 /* Macintosh */ ? winCtrl : ctrlCmd); const shiftKey = (keybinding & 1024 /* Shift */ ? true : false); const altKey = (keybinding & 512 /* Alt */ ? true : false); const metaKey = (OS === 2 /* Macintosh */ ? ctrlCmd : winCtrl); const keyCode = (keybinding & 255 /* KeyCode */); return new SimpleKeybinding(ctrlKey, shiftKey, altKey, metaKey, keyCode); } class SimpleKeybinding { constructor(ctrlKey, shiftKey, altKey, metaKey, keyCode) { this.ctrlKey = ctrlKey; this.shiftKey = shiftKey; this.altKey = altKey; this.metaKey = metaKey; this.keyCode = keyCode; } equals(other) { return (this.ctrlKey === other.ctrlKey && this.shiftKey === other.shiftKey && this.altKey === other.altKey && this.metaKey === other.metaKey && this.keyCode === other.keyCode); } isModifierKey() { return (this.keyCode === 0 /* Unknown */ || this.keyCode === 5 /* Ctrl */ || this.keyCode === 57 /* Meta */ || this.keyCode === 6 /* Alt */ || this.keyCode === 4 /* Shift */); } toChord() { return new ChordKeybinding([this]); } /** * Does this keybinding refer to the key code of a modifier and it also has the modifier flag? */ isDuplicateModifierCase() { return ((this.ctrlKey && this.keyCode === 5 /* Ctrl */) || (this.shiftKey && this.keyCode === 4 /* Shift */) || (this.altKey && this.keyCode === 6 /* Alt */) || (this.metaKey && this.keyCode === 57 /* Meta */)); } } class ChordKeybinding { constructor(parts) { if (parts.length === 0) { throw illegalArgument(`parts`); } this.parts = parts; } } class ResolvedKeybindingPart { constructor(ctrlKey, shiftKey, altKey, metaKey, kbLabel, kbAriaLabel) { this.ctrlKey = ctrlKey; this.shiftKey = shiftKey; this.altKey = altKey; this.metaKey = metaKey; this.keyLabel = kbLabel; this.keyAriaLabel = kbAriaLabel; } } /** * A resolved keybinding. Can be a simple keybinding or a chord keybinding. */ class ResolvedKeybinding { } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function extractKeyCode(e) { if (e.charCode) { // "keypress" events mostly let char = String.fromCharCode(e.charCode).toUpperCase(); return KeyCodeUtils.fromString(char); } const keyCode = e.keyCode; // browser quirks if (keyCode === 3) { return 7 /* PauseBreak */; } else if (isFirefox) { if (keyCode === 59) { return 80 /* Semicolon */; } else if (keyCode === 107) { return 81 /* Equal */; } else if (keyCode === 109) { return 83 /* Minus */; } else if (isMacintosh && keyCode === 224) { return 57 /* Meta */; } } else if (isWebKit) { if (keyCode === 91) { return 57 /* Meta */; } else if (isMacintosh && keyCode === 93) { // the two meta keys in the Mac have different key codes (91 and 93) return 57 /* Meta */; } else if (!isMacintosh && keyCode === 92) { return 57 /* Meta */; } } // cross browser keycodes: return EVENT_KEY_CODE_MAP[keyCode] || 0 /* Unknown */; } const ctrlKeyMod$1 = (isMacintosh ? 256 /* WinCtrl */ : 2048 /* CtrlCmd */); const altKeyMod = 512 /* Alt */; const shiftKeyMod = 1024 /* Shift */; const metaKeyMod = (isMacintosh ? 2048 /* CtrlCmd */ : 256 /* WinCtrl */); class StandardKeyboardEvent { constructor(source) { this._standardKeyboardEventBrand = true; let e = source; this.browserEvent = e; this.target = e.target; this.ctrlKey = e.ctrlKey; this.shiftKey = e.shiftKey; this.altKey = e.altKey; this.metaKey = e.metaKey; this.keyCode = extractKeyCode(e); this.code = e.code; // console.info(e.type + ": keyCode: " + e.keyCode + ", which: " + e.which + ", charCode: " + e.charCode + ", detail: " + e.detail + " ====> " + this.keyCode + ' -- ' + KeyCode[this.keyCode]); this.ctrlKey = this.ctrlKey || this.keyCode === 5 /* Ctrl */; this.altKey = this.altKey || this.keyCode === 6 /* Alt */; this.shiftKey = this.shiftKey || this.keyCode === 4 /* Shift */; this.metaKey = this.metaKey || this.keyCode === 57 /* Meta */; this._asKeybinding = this._computeKeybinding(); this._asRuntimeKeybinding = this._computeRuntimeKeybinding(); // console.log(`code: ${e.code}, keyCode: ${e.keyCode}, key: ${e.key}`); } preventDefault() { if (this.browserEvent && this.browserEvent.preventDefault) { this.browserEvent.preventDefault(); } } stopPropagation() { if (this.browserEvent && this.browserEvent.stopPropagation) { this.browserEvent.stopPropagation(); } } toKeybinding() { return this._asRuntimeKeybinding; } equals(other) { return this._asKeybinding === other; } _computeKeybinding() { let key = 0 /* Unknown */; if (this.keyCode !== 5 /* Ctrl */ && this.keyCode !== 4 /* Shift */ && this.keyCode !== 6 /* Alt */ && this.keyCode !== 57 /* Meta */) { key = this.keyCode; } let result = 0; if (this.ctrlKey) { result |= ctrlKeyMod$1; } if (this.altKey) { result |= altKeyMod; } if (this.shiftKey) { result |= shiftKeyMod; } if (this.metaKey) { result |= metaKeyMod; } result |= key; return result; } _computeRuntimeKeybinding() { let key = 0 /* Unknown */; if (this.keyCode !== 5 /* Ctrl */ && this.keyCode !== 4 /* Shift */ && this.keyCode !== 6 /* Alt */ && this.keyCode !== 57 /* Meta */) { key = this.keyCode; } return new SimpleKeybinding(this.ctrlKey, this.shiftKey, this.altKey, this.metaKey, key); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ let hasDifferentOriginAncestorFlag = false; let sameOriginWindowChainCache = null; function getParentWindowIfSameOrigin(w) { if (!w.parent || w.parent === w) { return null; } // Cannot really tell if we have access to the parent window unless we try to access something in it try { let location = w.location; let parentLocation = w.parent.location; if (location.origin !== 'null' && parentLocation.origin !== 'null' && location.origin !== parentLocation.origin) { hasDifferentOriginAncestorFlag = true; return null; } } catch (e) { hasDifferentOriginAncestorFlag = true; return null; } return w.parent; } class IframeUtils { /** * Returns a chain of embedded windows with the same origin (which can be accessed programmatically). * Having a chain of length 1 might mean that the current execution environment is running outside of an iframe or inside an iframe embedded in a window with a different origin. * To distinguish if at one point the current execution environment is running inside a window with a different origin, see hasDifferentOriginAncestor() */ static getSameOriginWindowChain() { if (!sameOriginWindowChainCache) { sameOriginWindowChainCache = []; let w = window; let parent; do { parent = getParentWindowIfSameOrigin(w); if (parent) { sameOriginWindowChainCache.push({ window: w, iframeElement: w.frameElement || null }); } else { sameOriginWindowChainCache.push({ window: w, iframeElement: null }); } w = parent; } while (w); } return sameOriginWindowChainCache.slice(0); } /** * Returns true if the current execution environment is chained in a list of iframes which at one point ends in a window with a different origin. * Returns false if the current execution environment is not running inside an iframe or if the entire chain of iframes have the same origin. */ static hasDifferentOriginAncestor() { if (!sameOriginWindowChainCache) { this.getSameOriginWindowChain(); } return hasDifferentOriginAncestorFlag; } /** * Returns the position of `childWindow` relative to `ancestorWindow` */ static getPositionOfChildWindowRelativeToAncestorWindow(childWindow, ancestorWindow) { if (!ancestorWindow || childWindow === ancestorWindow) { return { top: 0, left: 0 }; } let top = 0, left = 0; let windowChain = this.getSameOriginWindowChain(); for (const windowChainEl of windowChain) { top += windowChainEl.window.scrollY; left += windowChainEl.window.scrollX; if (windowChainEl.window === ancestorWindow) { break; } if (!windowChainEl.iframeElement) { break; } let boundingRect = windowChainEl.iframeElement.getBoundingClientRect(); top += boundingRect.top; left += boundingRect.left; } return { top: top, left: left }; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class StandardMouseEvent { constructor(e) { this.timestamp = Date.now(); this.browserEvent = e; this.leftButton = e.button === 0; this.middleButton = e.button === 1; this.rightButton = e.button === 2; this.buttons = e.buttons; this.target = e.target; this.detail = e.detail || 1; if (e.type === 'dblclick') { this.detail = 2; } this.ctrlKey = e.ctrlKey; this.shiftKey = e.shiftKey; this.altKey = e.altKey; this.metaKey = e.metaKey; if (typeof e.pageX === 'number') { this.posx = e.pageX; this.posy = e.pageY; } else { // Probably hit by MSGestureEvent this.posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; this.posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } // Find the position of the iframe this code is executing in relative to the iframe where the event was captured. let iframeOffsets = IframeUtils.getPositionOfChildWindowRelativeToAncestorWindow(self, e.view); this.posx -= iframeOffsets.left; this.posy -= iframeOffsets.top; } preventDefault() { this.browserEvent.preventDefault(); } stopPropagation() { this.browserEvent.stopPropagation(); } } class StandardWheelEvent { constructor(e, deltaX = 0, deltaY = 0) { this.browserEvent = e || null; this.target = e ? (e.target || e.targetNode || e.srcElement) : null; this.deltaY = deltaY; this.deltaX = deltaX; if (e) { // Old (deprecated) wheel events let e1 = e; let e2 = e; // vertical delta scroll if (typeof e1.wheelDeltaY !== 'undefined') { this.deltaY = e1.wheelDeltaY / 120; } else if (typeof e2.VERTICAL_AXIS !== 'undefined' && e2.axis === e2.VERTICAL_AXIS) { this.deltaY = -e2.detail / 3; } else if (e.type === 'wheel') { // Modern wheel event // https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent const ev = e; if (ev.deltaMode === ev.DOM_DELTA_LINE) { // the deltas are expressed in lines if (isFirefox && !isMacintosh) { this.deltaY = -e.deltaY / 3; } else { this.deltaY = -e.deltaY; } } else { this.deltaY = -e.deltaY / 40; } } // horizontal delta scroll if (typeof e1.wheelDeltaX !== 'undefined') { if (isSafari && isWindows) { this.deltaX = -(e1.wheelDeltaX / 120); } else { this.deltaX = e1.wheelDeltaX / 120; } } else if (typeof e2.HORIZONTAL_AXIS !== 'undefined' && e2.axis === e2.HORIZONTAL_AXIS) { this.deltaX = -e.detail / 3; } else if (e.type === 'wheel') { // Modern wheel event // https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent const ev = e; if (ev.deltaMode === ev.DOM_DELTA_LINE) { // the deltas are expressed in lines if (isFirefox && !isMacintosh) { this.deltaX = -e.deltaX / 3; } else { this.deltaX = -e.deltaX; } } else { this.deltaX = -e.deltaX / 40; } } // Assume a vertical scroll if nothing else worked if (this.deltaY === 0 && this.deltaX === 0 && e.wheelDelta) { this.deltaY = e.wheelDelta / 120; } } } preventDefault() { if (this.browserEvent) { this.browserEvent.preventDefault(); } } stopPropagation() { if (this.browserEvent) { this.browserEvent.stopPropagation(); } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var Schemas; (function (Schemas) { /** * A schema that is used for models that exist in memory * only and that have no correspondence on a server or such. */ Schemas.inMemory = 'inmemory'; /** * A schema that is used for setting files */ Schemas.vscode = 'vscode'; /** * A schema that is used for internal private files */ Schemas.internal = 'private'; /** * A walk-through document. */ Schemas.walkThrough = 'walkThrough'; /** * An embedded code snippet. */ Schemas.walkThroughSnippet = 'walkThroughSnippet'; Schemas.http = 'http'; Schemas.https = 'https'; Schemas.file = 'file'; Schemas.mailto = 'mailto'; Schemas.untitled = 'untitled'; Schemas.data = 'data'; Schemas.command = 'command'; Schemas.vscodeRemote = 'vscode-remote'; Schemas.vscodeRemoteResource = 'vscode-remote-resource'; Schemas.userData = 'vscode-userdata'; Schemas.vscodeCustomEditor = 'vscode-custom-editor'; Schemas.vscodeNotebook = 'vscode-notebook'; Schemas.vscodeNotebookCell = 'vscode-notebook-cell'; Schemas.vscodeNotebookCellMetadata = 'vscode-notebook-cell-metadata'; Schemas.vscodeNotebookCellOutput = 'vscode-notebook-cell-output'; Schemas.vscodeInteractive = 'vscode-interactive'; Schemas.vscodeInteractiveInput = 'vscode-interactive-input'; Schemas.vscodeSettings = 'vscode-settings'; Schemas.vscodeWorkspaceTrust = 'vscode-workspace-trust'; Schemas.vscodeTerminal = 'vscode-terminal'; /** * Scheme used internally for webviews that aren't linked to a resource (i.e. not custom editors) */ Schemas.webviewPanel = 'webview-panel'; /** * Scheme used for loading the wrapper html and script in webviews. */ Schemas.vscodeWebview = 'vscode-webview'; /** * Scheme used for extension pages */ Schemas.extension = 'extension'; /** * Scheme used as a replacement of `file` scheme to load * files with our custom protocol handler (desktop only). */ Schemas.vscodeFileResource = 'vscode-file'; /** * Scheme used for temporary resources */ Schemas.tmp = 'tmp'; /** * Scheme used vs live share */ Schemas.vsls = 'vsls'; })(Schemas || (Schemas = {})); const connectionTokenQueryName = 'tkn'; class RemoteAuthoritiesImpl { constructor() { this._hosts = Object.create(null); this._ports = Object.create(null); this._connectionTokens = Object.create(null); this._preferredWebSchema = 'http'; this._delegate = null; } setPreferredWebSchema(schema) { this._preferredWebSchema = schema; } rewrite(uri) { if (this._delegate) { return this._delegate(uri); } const authority = uri.authority; let host = this._hosts[authority]; if (host && host.indexOf(':') !== -1) { host = `[${host}]`; } const port = this._ports[authority]; const connectionToken = this._connectionTokens[authority]; let query = `path=${encodeURIComponent(uri.path)}`; if (typeof connectionToken === 'string') { query += `&${connectionTokenQueryName}=${encodeURIComponent(connectionToken)}`; } return URI.from({ scheme: isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource, authority: `${host}:${port}`, path: `/vscode-remote-resource`, query }); } } const RemoteAuthorities = new RemoteAuthoritiesImpl(); class FileAccessImpl { asBrowserUri(uriOrModule, moduleIdToUrl) { const uri = this.toUri(uriOrModule, moduleIdToUrl); // Handle remote URIs via `RemoteAuthorities` if (uri.scheme === Schemas.vscodeRemote) { return RemoteAuthorities.rewrite(uri); } // Convert to `vscode-file` resource.. if ( // ...only ever for `file` resources uri.scheme === Schemas.file && ( // ...and we run in native environments isNative || // ...or web worker extensions on desktop (typeof globals.importScripts === 'function' && globals.origin === `${Schemas.vscodeFileResource}://${FileAccessImpl.FALLBACK_AUTHORITY}`))) { return uri.with({ scheme: Schemas.vscodeFileResource, // We need to provide an authority here so that it can serve // as origin for network and loading matters in chromium. // If the URI is not coming with an authority already, we // add our own authority: uri.authority || FileAccessImpl.FALLBACK_AUTHORITY, query: null, fragment: null }); } return uri; } toUri(uriOrModule, moduleIdToUrl) { if (URI.isUri(uriOrModule)) { return uriOrModule; } return URI.parse(moduleIdToUrl.toUrl(uriOrModule)); } } FileAccessImpl.FALLBACK_AUTHORITY = 'vscode-app'; const FileAccess = new FileAccessImpl(); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function clearNode(node) { while (node.firstChild) { node.firstChild.remove(); } } /** * @deprecated Use node.isConnected directly */ function isInDOM(node) { var _a; return (_a = node === null || node === void 0 ? void 0 : node.isConnected) !== null && _a !== void 0 ? _a : false; } class DomListener { constructor(node, type, handler, options) { this._node = node; this._type = type; this._handler = handler; this._options = (options || false); this._node.addEventListener(this._type, this._handler, this._options); } dispose() { if (!this._handler) { // Already disposed return; } this._node.removeEventListener(this._type, this._handler, this._options); // Prevent leakers from holding on to the dom or handler func this._node = null; this._handler = null; } } function addDisposableListener(node, type, handler, useCaptureOrOptions) { return new DomListener(node, type, handler, useCaptureOrOptions); } function _wrapAsStandardMouseEvent(handler) { return function (e) { return handler(new StandardMouseEvent(e)); }; } function _wrapAsStandardKeyboardEvent(handler) { return function (e) { return handler(new StandardKeyboardEvent(e)); }; } let addStandardDisposableListener = function addStandardDisposableListener(node, type, handler, useCapture) { let wrapHandler = handler; if (type === 'click' || type === 'mousedown') { wrapHandler = _wrapAsStandardMouseEvent(handler); } else if (type === 'keydown' || type === 'keypress' || type === 'keyup') { wrapHandler = _wrapAsStandardKeyboardEvent(handler); } return addDisposableListener(node, type, wrapHandler, useCapture); }; let addStandardDisposableGenericMouseDownListner = function addStandardDisposableListener(node, handler, useCapture) { let wrapHandler = _wrapAsStandardMouseEvent(handler); return addDisposableGenericMouseDownListner(node, wrapHandler, useCapture); }; function addDisposableGenericMouseDownListner(node, handler, useCapture) { return addDisposableListener(node, isIOS && BrowserFeatures.pointerEvents ? EventType$1.POINTER_DOWN : EventType$1.MOUSE_DOWN, handler, useCapture); } function addDisposableGenericMouseUpListner(node, handler, useCapture) { return addDisposableListener(node, isIOS && BrowserFeatures.pointerEvents ? EventType$1.POINTER_UP : EventType$1.MOUSE_UP, handler, useCapture); } function addDisposableNonBubblingMouseOutListener(node, handler) { return addDisposableListener(node, 'mouseout', (e) => { // Mouse out bubbles, so this is an attempt to ignore faux mouse outs coming from children elements let toElement = (e.relatedTarget); while (toElement && toElement !== node) { toElement = toElement.parentNode; } if (toElement === node) { return; } handler(e); }); } function addDisposableNonBubblingPointerOutListener(node, handler) { return addDisposableListener(node, 'pointerout', (e) => { // Mouse out bubbles, so this is an attempt to ignore faux mouse outs coming from children elements let toElement = (e.relatedTarget); while (toElement && toElement !== node) { toElement = toElement.parentNode; } if (toElement === node) { return; } handler(e); }); } function createEventEmitter(target, type, options) { let domListener = null; const handler = (e) => result.fire(e); const onFirstListenerAdd = () => { if (!domListener) { domListener = new DomListener(target, type, handler, options); } }; const onLastListenerRemove = () => { if (domListener) { domListener.dispose(); domListener = null; } }; const result = new Emitter$1({ onFirstListenerAdd, onLastListenerRemove }); return result; } let _animationFrame = null; function doRequestAnimationFrame(callback) { if (!_animationFrame) { const emulatedRequestAnimationFrame = (callback) => { return setTimeout(() => callback(new Date().getTime()), 0); }; _animationFrame = (self.requestAnimationFrame || self.msRequestAnimationFrame || self.webkitRequestAnimationFrame || self.mozRequestAnimationFrame || self.oRequestAnimationFrame || emulatedRequestAnimationFrame); } return _animationFrame.call(self, callback); } /** * Schedule a callback to be run at the next animation frame. * This allows multiple parties to register callbacks that should run at the next animation frame. * If currently in an animation frame, `runner` will be executed immediately. * @return token that can be used to cancel the scheduled runner (only if `runner` was not executed immediately). */ let runAtThisOrScheduleAtNextAnimationFrame; /** * Schedule a callback to be run at the next animation frame. * This allows multiple parties to register callbacks that should run at the next animation frame. * If currently in an animation frame, `runner` will be executed at the next animation frame. * @return token that can be used to cancel the scheduled runner. */ let scheduleAtNextAnimationFrame; class AnimationFrameQueueItem { constructor(runner, priority = 0) { this._runner = runner; this.priority = priority; this._canceled = false; } dispose() { this._canceled = true; } execute() { if (this._canceled) { return; } try { this._runner(); } catch (e) { onUnexpectedError(e); } } // Sort by priority (largest to lowest) static sort(a, b) { return b.priority - a.priority; } } (function () { /** * The runners scheduled at the next animation frame */ let NEXT_QUEUE = []; /** * The runners scheduled at the current animation frame */ let CURRENT_QUEUE = null; /** * A flag to keep track if the native requestAnimationFrame was already called */ let animFrameRequested = false; /** * A flag to indicate if currently handling a native requestAnimationFrame callback */ let inAnimationFrameRunner = false; let animationFrameRunner = () => { animFrameRequested = false; CURRENT_QUEUE = NEXT_QUEUE; NEXT_QUEUE = []; inAnimationFrameRunner = true; while (CURRENT_QUEUE.length > 0) { CURRENT_QUEUE.sort(AnimationFrameQueueItem.sort); let top = CURRENT_QUEUE.shift(); top.execute(); } inAnimationFrameRunner = false; }; scheduleAtNextAnimationFrame = (runner, priority = 0) => { let item = new AnimationFrameQueueItem(runner, priority); NEXT_QUEUE.push(item); if (!animFrameRequested) { animFrameRequested = true; doRequestAnimationFrame(animationFrameRunner); } return item; }; runAtThisOrScheduleAtNextAnimationFrame = (runner, priority) => { if (inAnimationFrameRunner) { let item = new AnimationFrameQueueItem(runner, priority); CURRENT_QUEUE.push(item); return item; } else { return scheduleAtNextAnimationFrame(runner, priority); } }; })(); const MINIMUM_TIME_MS = 8; const DEFAULT_EVENT_MERGER = function (lastEvent, currentEvent) { return currentEvent; }; class TimeoutThrottledDomListener extends Disposable { constructor(node, type, handler, eventMerger = DEFAULT_EVENT_MERGER, minimumTimeMs = MINIMUM_TIME_MS) { super(); let lastEvent = null; let lastHandlerTime = 0; let timeout = this._register(new TimeoutTimer()); let invokeHandler = () => { lastHandlerTime = (new Date()).getTime(); handler(lastEvent); lastEvent = null; }; this._register(addDisposableListener(node, type, (e) => { lastEvent = eventMerger(lastEvent, e); let elapsedTime = (new Date()).getTime() - lastHandlerTime; if (elapsedTime >= minimumTimeMs) { timeout.cancel(); invokeHandler(); } else { timeout.setIfNotSet(invokeHandler, minimumTimeMs - elapsedTime); } })); } } function addDisposableThrottledListener(node, type, handler, eventMerger, minimumTimeMs) { return new TimeoutThrottledDomListener(node, type, handler, eventMerger, minimumTimeMs); } function getComputedStyle$1(el) { return document.defaultView.getComputedStyle(el, null); } function getClientArea(element) { // Try with DOM clientWidth / clientHeight if (element !== document.body) { return new Dimension(element.clientWidth, element.clientHeight); } // If visual view port exits and it's on mobile, it should be used instead of window innerWidth / innerHeight, or document.body.clientWidth / document.body.clientHeight if (isIOS && window.visualViewport) { return new Dimension(window.visualViewport.width, window.visualViewport.height); } // Try innerWidth / innerHeight if (window.innerWidth && window.innerHeight) { return new Dimension(window.innerWidth, window.innerHeight); } // Try with document.body.clientWidth / document.body.clientHeight if (document.body && document.body.clientWidth && document.body.clientHeight) { return new Dimension(document.body.clientWidth, document.body.clientHeight); } // Try with document.documentElement.clientWidth / document.documentElement.clientHeight if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) { return new Dimension(document.documentElement.clientWidth, document.documentElement.clientHeight); } throw new Error('Unable to figure out browser width and height'); } class SizeUtils { // Adapted from WinJS // Converts a CSS positioning string for the specified element to pixels. static convertToPixels(element, value) { return parseFloat(value) || 0; } static getDimension(element, cssPropertyName, jsPropertyName) { let computedStyle = getComputedStyle$1(element); let value = '0'; if (computedStyle) { if (computedStyle.getPropertyValue) { value = computedStyle.getPropertyValue(cssPropertyName); } else { // IE8 value = computedStyle.getAttribute(jsPropertyName); } } return SizeUtils.convertToPixels(element, value); } static getBorderLeftWidth(element) { return SizeUtils.getDimension(element, 'border-left-width', 'borderLeftWidth'); } static getBorderRightWidth(element) { return SizeUtils.getDimension(element, 'border-right-width', 'borderRightWidth'); } static getBorderTopWidth(element) { return SizeUtils.getDimension(element, 'border-top-width', 'borderTopWidth'); } static getBorderBottomWidth(element) { return SizeUtils.getDimension(element, 'border-bottom-width', 'borderBottomWidth'); } static getPaddingLeft(element) { return SizeUtils.getDimension(element, 'padding-left', 'paddingLeft'); } static getPaddingRight(element) { return SizeUtils.getDimension(element, 'padding-right', 'paddingRight'); } static getPaddingTop(element) { return SizeUtils.getDimension(element, 'padding-top', 'paddingTop'); } static getPaddingBottom(element) { return SizeUtils.getDimension(element, 'padding-bottom', 'paddingBottom'); } static getMarginLeft(element) { return SizeUtils.getDimension(element, 'margin-left', 'marginLeft'); } static getMarginTop(element) { return SizeUtils.getDimension(element, 'margin-top', 'marginTop'); } static getMarginRight(element) { return SizeUtils.getDimension(element, 'margin-right', 'marginRight'); } static getMarginBottom(element) { return SizeUtils.getDimension(element, 'margin-bottom', 'marginBottom'); } } class Dimension { constructor(width, height) { this.width = width; this.height = height; } with(width = this.width, height = this.height) { if (width !== this.width || height !== this.height) { return new Dimension(width, height); } else { return this; } } static is(obj) { return typeof obj === 'object' && typeof obj.height === 'number' && typeof obj.width === 'number'; } static lift(obj) { if (obj instanceof Dimension) { return obj; } else { return new Dimension(obj.width, obj.height); } } static equals(a, b) { if (a === b) { return true; } if (!a || !b) { return false; } return a.width === b.width && a.height === b.height; } } Dimension.None = new Dimension(0, 0); function getTopLeftOffset(element) { // Adapted from WinJS.Utilities.getPosition // and added borders to the mix let offsetParent = element.offsetParent; let top = element.offsetTop; let left = element.offsetLeft; while ((element = element.parentNode) !== null && element !== document.body && element !== document.documentElement) { top -= element.scrollTop; const c = isShadowRoot(element) ? null : getComputedStyle$1(element); if (c) { left -= c.direction !== 'rtl' ? element.scrollLeft : -element.scrollLeft; } if (element === offsetParent) { left += SizeUtils.getBorderLeftWidth(element); top += SizeUtils.getBorderTopWidth(element); top += element.offsetTop; left += element.offsetLeft; offsetParent = element.offsetParent; } } return { left: left, top: top }; } function size(element, width, height) { if (typeof width === 'number') { element.style.width = `${width}px`; } if (typeof height === 'number') { element.style.height = `${height}px`; } } /** * Returns the position of a dom node relative to the entire page. */ function getDomNodePagePosition(domNode) { let bb = domNode.getBoundingClientRect(); return { left: bb.left + StandardWindow.scrollX, top: bb.top + StandardWindow.scrollY, width: bb.width, height: bb.height }; } const StandardWindow = new class { get scrollX() { if (typeof window.scrollX === 'number') { // modern browsers return window.scrollX; } else { return document.body.scrollLeft + document.documentElement.scrollLeft; } } get scrollY() { if (typeof window.scrollY === 'number') { // modern browsers return window.scrollY; } else { return document.body.scrollTop + document.documentElement.scrollTop; } } }; // Adapted from WinJS // Gets the width of the element, including margins. function getTotalWidth(element) { let margin = SizeUtils.getMarginLeft(element) + SizeUtils.getMarginRight(element); return element.offsetWidth + margin; } function getContentWidth(element) { let border = SizeUtils.getBorderLeftWidth(element) + SizeUtils.getBorderRightWidth(element); let padding = SizeUtils.getPaddingLeft(element) + SizeUtils.getPaddingRight(element); return element.offsetWidth - border - padding; } // Adapted from WinJS // Gets the height of the content of the specified element. The content height does not include borders or padding. function getContentHeight(element) { let border = SizeUtils.getBorderTopWidth(element) + SizeUtils.getBorderBottomWidth(element); let padding = SizeUtils.getPaddingTop(element) + SizeUtils.getPaddingBottom(element); return element.offsetHeight - border - padding; } // Adapted from WinJS // Gets the height of the element, including its margins. function getTotalHeight(element) { let margin = SizeUtils.getMarginTop(element) + SizeUtils.getMarginBottom(element); return element.offsetHeight + margin; } // ---------------------------------------------------------------------------------------- function isAncestor$1(testChild, testAncestor) { while (testChild) { if (testChild === testAncestor) { return true; } testChild = testChild.parentNode; } return false; } function findParentWithClass(node, clazz, stopAtClazzOrNode) { while (node && node.nodeType === node.ELEMENT_NODE) { if (node.classList.contains(clazz)) { return node; } if (stopAtClazzOrNode) { if (typeof stopAtClazzOrNode === 'string') { if (node.classList.contains(stopAtClazzOrNode)) { return null; } } else { if (node === stopAtClazzOrNode) { return null; } } } node = node.parentNode; } return null; } function hasParentWithClass(node, clazz, stopAtClazzOrNode) { return !!findParentWithClass(node, clazz, stopAtClazzOrNode); } function isShadowRoot(node) { return (node && !!node.host && !!node.mode); } function isInShadowDOM(domNode) { return !!getShadowRoot(domNode); } function getShadowRoot(domNode) { while (domNode.parentNode) { if (domNode === document.body) { // reached the body return null; } domNode = domNode.parentNode; } return isShadowRoot(domNode) ? domNode : null; } function getActiveElement() { let result = document.activeElement; while (result === null || result === void 0 ? void 0 : result.shadowRoot) { result = result.shadowRoot.activeElement; } return result; } function createStyleSheet(container = document.getElementsByTagName('head')[0]) { let style = document.createElement('style'); style.type = 'text/css'; style.media = 'screen'; container.appendChild(style); return style; } let _sharedStyleSheet = null; function getSharedStyleSheet() { if (!_sharedStyleSheet) { _sharedStyleSheet = createStyleSheet(); } return _sharedStyleSheet; } function getDynamicStyleSheetRules(style) { var _a, _b; if ((_a = style === null || style === void 0 ? void 0 : style.sheet) === null || _a === void 0 ? void 0 : _a.rules) { // Chrome, IE return style.sheet.rules; } if ((_b = style === null || style === void 0 ? void 0 : style.sheet) === null || _b === void 0 ? void 0 : _b.cssRules) { // FF return style.sheet.cssRules; } return []; } function createCSSRule(selector, cssText, style = getSharedStyleSheet()) { if (!style || !cssText) { return; } style.sheet.insertRule(selector + '{' + cssText + '}', 0); } function removeCSSRulesContainingSelector(ruleName, style = getSharedStyleSheet()) { if (!style) { return; } let rules = getDynamicStyleSheetRules(style); let toDelete = []; for (let i = 0; i < rules.length; i++) { let rule = rules[i]; if (rule.selectorText.indexOf(ruleName) !== -1) { toDelete.push(i); } } for (let i = toDelete.length - 1; i >= 0; i--) { style.sheet.deleteRule(toDelete[i]); } } function isHTMLElement(o) { if (typeof HTMLElement === 'object') { return o instanceof HTMLElement; } return o && typeof o === 'object' && o.nodeType === 1 && typeof o.nodeName === 'string'; } const EventType$1 = { // Mouse CLICK: 'click', AUXCLICK: 'auxclick', DBLCLICK: 'dblclick', MOUSE_UP: 'mouseup', MOUSE_DOWN: 'mousedown', MOUSE_OVER: 'mouseover', MOUSE_MOVE: 'mousemove', MOUSE_OUT: 'mouseout', MOUSE_ENTER: 'mouseenter', MOUSE_LEAVE: 'mouseleave', MOUSE_WHEEL: 'wheel', POINTER_UP: 'pointerup', POINTER_DOWN: 'pointerdown', POINTER_MOVE: 'pointermove', CONTEXT_MENU: 'contextmenu', WHEEL: 'wheel', // Keyboard KEY_DOWN: 'keydown', KEY_PRESS: 'keypress', KEY_UP: 'keyup', // HTML Document LOAD: 'load', BEFORE_UNLOAD: 'beforeunload', UNLOAD: 'unload', PAGE_SHOW: 'pageshow', PAGE_HIDE: 'pagehide', ABORT: 'abort', ERROR: 'error', RESIZE: 'resize', SCROLL: 'scroll', FULLSCREEN_CHANGE: 'fullscreenchange', WK_FULLSCREEN_CHANGE: 'webkitfullscreenchange', // Form SELECT: 'select', CHANGE: 'change', SUBMIT: 'submit', RESET: 'reset', FOCUS: 'focus', FOCUS_IN: 'focusin', FOCUS_OUT: 'focusout', BLUR: 'blur', INPUT: 'input', // Local Storage STORAGE: 'storage', // Drag DRAG_START: 'dragstart', DRAG: 'drag', DRAG_ENTER: 'dragenter', DRAG_LEAVE: 'dragleave', DRAG_OVER: 'dragover', DROP: 'drop', DRAG_END: 'dragend', // Animation ANIMATION_START: isWebKit ? 'webkitAnimationStart' : 'animationstart', ANIMATION_END: isWebKit ? 'webkitAnimationEnd' : 'animationend', ANIMATION_ITERATION: isWebKit ? 'webkitAnimationIteration' : 'animationiteration' }; const EventHelper = { stop: function (e, cancelBubble) { if (e.preventDefault) { e.preventDefault(); } else { // IE8 e.returnValue = false; } if (cancelBubble) { if (e.stopPropagation) { e.stopPropagation(); } else { // IE8 e.cancelBubble = true; } } } }; function saveParentsScrollTop(node) { let r = []; for (let i = 0; node && node.nodeType === node.ELEMENT_NODE; i++) { r[i] = node.scrollTop; node = node.parentNode; } return r; } function restoreParentsScrollTop(node, state) { for (let i = 0; node && node.nodeType === node.ELEMENT_NODE; i++) { if (node.scrollTop !== state[i]) { node.scrollTop = state[i]; } node = node.parentNode; } } class FocusTracker extends Disposable { constructor(element) { super(); this._onDidFocus = this._register(new Emitter$1()); this.onDidFocus = this._onDidFocus.event; this._onDidBlur = this._register(new Emitter$1()); this.onDidBlur = this._onDidBlur.event; let hasFocus = FocusTracker.hasFocusWithin(element); let loosingFocus = false; const onFocus = () => { loosingFocus = false; if (!hasFocus) { hasFocus = true; this._onDidFocus.fire(); } }; const onBlur = () => { if (hasFocus) { loosingFocus = true; window.setTimeout(() => { if (loosingFocus) { loosingFocus = false; hasFocus = false; this._onDidBlur.fire(); } }, 0); } }; this._refreshStateHandler = () => { let currentNodeHasFocus = FocusTracker.hasFocusWithin(element); if (currentNodeHasFocus !== hasFocus) { if (hasFocus) { onBlur(); } else { onFocus(); } } }; this._register(addDisposableListener(element, EventType$1.FOCUS, onFocus, true)); this._register(addDisposableListener(element, EventType$1.BLUR, onBlur, true)); this._register(addDisposableListener(element, EventType$1.FOCUS_IN, () => this._refreshStateHandler())); this._register(addDisposableListener(element, EventType$1.FOCUS_OUT, () => this._refreshStateHandler())); } static hasFocusWithin(element) { const shadowRoot = getShadowRoot(element); const activeElement = (shadowRoot ? shadowRoot.activeElement : document.activeElement); return isAncestor$1(activeElement, element); } } function trackFocus(element) { return new FocusTracker(element); } function append$1(parent, ...children) { parent.append(...children); if (children.length === 1 && typeof children[0] !== 'string') { return children[0]; } } function prepend$1(parent, child) { parent.insertBefore(child, parent.firstChild); return child; } /** * Removes all children from `parent` and appends `children` */ function reset(parent, ...children) { parent.innerText = ''; append$1(parent, ...children); } const SELECTOR_REGEX = /([\w\-]+)?(#([\w\-]+))?((\.([\w\-]+))*)/; var Namespace; (function (Namespace) { Namespace["HTML"] = "http://www.w3.org/1999/xhtml"; Namespace["SVG"] = "http://www.w3.org/2000/svg"; })(Namespace || (Namespace = {})); function _$(namespace, description, attrs, ...children) { let match = SELECTOR_REGEX.exec(description); if (!match) { throw new Error('Bad use of emmet'); } attrs = Object.assign({}, (attrs || {})); let tagName = match[1] || 'div'; let result; if (namespace !== Namespace.HTML) { result = document.createElementNS(namespace, tagName); } else { result = document.createElement(tagName); } if (match[3]) { result.id = match[3]; } if (match[4]) { result.className = match[4].replace(/\./g, ' ').trim(); } Object.keys(attrs).forEach(name => { const value = attrs[name]; if (typeof value === 'undefined') { return; } if (/^on\w+$/.test(name)) { result[name] = value; } else if (name === 'selected') { if (value) { result.setAttribute(name, 'true'); } } else { result.setAttribute(name, value); } }); result.append(...children); return result; } function $$c(description, attrs, ...children) { return _$(Namespace.HTML, description, attrs, ...children); } $$c.SVG = function (description, attrs, ...children) { return _$(Namespace.SVG, description, attrs, ...children); }; function show(...elements) { for (let element of elements) { element.style.display = ''; element.removeAttribute('aria-hidden'); } } function hide(...elements) { for (let element of elements) { element.style.display = 'none'; element.setAttribute('aria-hidden', 'true'); } } function getElementsByTagName(tag) { return Array.prototype.slice.call(document.getElementsByTagName(tag), 0); } /** * Find a value usable for a dom node size such that the likelihood that it would be * displayed with constant screen pixels size is as high as possible. * * e.g. We would desire for the cursors to be 2px (CSS px) wide. Under a devicePixelRatio * of 1.25, the cursor will be 2.5 screen pixels wide. Depending on how the dom node aligns/"snaps" * with the screen pixels, it will sometimes be rendered with 2 screen pixels, and sometimes with 3 screen pixels. */ function computeScreenAwareSize(cssPx) { const screenPx = window.devicePixelRatio * cssPx; return Math.max(1, Math.floor(screenPx)) / window.devicePixelRatio; } /** * Open safely a new window. This is the best way to do so, but you cannot tell * if the window was opened or if it was blocked by the browser's popup blocker. * If you want to tell if the browser blocked the new window, use {@link windowOpenWithSuccess}. * * See https://github.com/microsoft/monaco-editor/issues/601 * To protect against malicious code in the linked site, particularly phishing attempts, * the window.opener should be set to null to prevent the linked site from having access * to change the location of the current page. * See https://mathiasbynens.github.io/rel-noopener/ */ function windowOpenNoOpener(url) { // By using 'noopener' in the `windowFeatures` argument, the newly created window will // not be able to use `window.opener` to reach back to the current page. // See https://stackoverflow.com/a/46958731 // See https://developer.mozilla.org/en-US/docs/Web/API/Window/open#noopener // However, this also doesn't allow us to realize if the browser blocked // the creation of the window. window.open(url, '_blank', 'noopener'); } function animate(fn) { const step = () => { fn(); stepDisposable = scheduleAtNextAnimationFrame(step); }; let stepDisposable = scheduleAtNextAnimationFrame(step); return toDisposable(() => stepDisposable.dispose()); } RemoteAuthorities.setPreferredWebSchema(/^https:/.test(window.location.href) ? 'https' : 'http'); /** * returns url('...') */ function asCSSUrl(uri) { if (!uri) { return `url('')`; } return `url('${FileAccess.asBrowserUri(uri).toString(true).replace(/'/g, '%27')}')`; } function asCSSPropertyValue(value) { return `'${value.replace(/'/g, '%27')}'`; } class ModifierKeyEmitter extends Emitter$1 { constructor() { super(); this._subscriptions = new DisposableStore(); this._keyStatus = { altKey: false, shiftKey: false, ctrlKey: false, metaKey: false }; this._subscriptions.add(addDisposableListener(window, 'keydown', e => { if (e.defaultPrevented) { return; } const event = new StandardKeyboardEvent(e); // If Alt-key keydown event is repeated, ignore it #112347 // Only known to be necessary for Alt-Key at the moment #115810 if (event.keyCode === 6 /* Alt */ && e.repeat) { return; } if (e.altKey && !this._keyStatus.altKey) { this._keyStatus.lastKeyPressed = 'alt'; } else if (e.ctrlKey && !this._keyStatus.ctrlKey) { this._keyStatus.lastKeyPressed = 'ctrl'; } else if (e.metaKey && !this._keyStatus.metaKey) { this._keyStatus.lastKeyPressed = 'meta'; } else if (e.shiftKey && !this._keyStatus.shiftKey) { this._keyStatus.lastKeyPressed = 'shift'; } else if (event.keyCode !== 6 /* Alt */) { this._keyStatus.lastKeyPressed = undefined; } else { return; } this._keyStatus.altKey = e.altKey; this._keyStatus.ctrlKey = e.ctrlKey; this._keyStatus.metaKey = e.metaKey; this._keyStatus.shiftKey = e.shiftKey; if (this._keyStatus.lastKeyPressed) { this._keyStatus.event = e; this.fire(this._keyStatus); } }, true)); this._subscriptions.add(addDisposableListener(window, 'keyup', e => { if (e.defaultPrevented) { return; } if (!e.altKey && this._keyStatus.altKey) { this._keyStatus.lastKeyReleased = 'alt'; } else if (!e.ctrlKey && this._keyStatus.ctrlKey) { this._keyStatus.lastKeyReleased = 'ctrl'; } else if (!e.metaKey && this._keyStatus.metaKey) { this._keyStatus.lastKeyReleased = 'meta'; } else if (!e.shiftKey && this._keyStatus.shiftKey) { this._keyStatus.lastKeyReleased = 'shift'; } else { this._keyStatus.lastKeyReleased = undefined; } if (this._keyStatus.lastKeyPressed !== this._keyStatus.lastKeyReleased) { this._keyStatus.lastKeyPressed = undefined; } this._keyStatus.altKey = e.altKey; this._keyStatus.ctrlKey = e.ctrlKey; this._keyStatus.metaKey = e.metaKey; this._keyStatus.shiftKey = e.shiftKey; if (this._keyStatus.lastKeyReleased) { this._keyStatus.event = e; this.fire(this._keyStatus); } }, true)); this._subscriptions.add(addDisposableListener(document.body, 'mousedown', () => { this._keyStatus.lastKeyPressed = undefined; }, true)); this._subscriptions.add(addDisposableListener(document.body, 'mouseup', () => { this._keyStatus.lastKeyPressed = undefined; }, true)); this._subscriptions.add(addDisposableListener(document.body, 'mousemove', e => { if (e.buttons) { this._keyStatus.lastKeyPressed = undefined; } }, true)); this._subscriptions.add(addDisposableListener(window, 'blur', () => { this.resetKeyStatus(); })); } get keyStatus() { return this._keyStatus; } /** * Allows to explicitly reset the key status based on more knowledge (#109062) */ resetKeyStatus() { this.doResetKeyStatus(); this.fire(this._keyStatus); } doResetKeyStatus() { this._keyStatus = { altKey: false, shiftKey: false, ctrlKey: false, metaKey: false }; } static getInstance() { if (!ModifierKeyEmitter.instance) { ModifierKeyEmitter.instance = new ModifierKeyEmitter(); } return ModifierKeyEmitter.instance; } dispose() { super.dispose(); this._subscriptions.dispose(); } } function addMatchMediaChangeListener(query, callback) { const mediaQueryList = window.matchMedia(query); mediaQueryList.addEventListener('change', callback); } var css$15 = "/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\n.monaco-aria-container {\n\tposition: absolute; /* try to hide from window but not from screen readers */\n\tleft:-999em;\n}"; n(css$15,{}); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ // Use a max length since we are inserting the whole msg in the DOM and that can cause browsers to freeze for long messages #94233 const MAX_MESSAGE_LENGTH = 20000; let ariaContainer; let alertContainer; let alertContainer2; let statusContainer; let statusContainer2; function setARIAContainer(parent) { ariaContainer = document.createElement('div'); ariaContainer.className = 'monaco-aria-container'; const createAlertContainer = () => { const element = document.createElement('div'); element.className = 'monaco-alert'; element.setAttribute('role', 'alert'); element.setAttribute('aria-atomic', 'true'); ariaContainer.appendChild(element); return element; }; alertContainer = createAlertContainer(); alertContainer2 = createAlertContainer(); const createStatusContainer = () => { const element = document.createElement('div'); element.className = 'monaco-status'; element.setAttribute('role', 'complementary'); element.setAttribute('aria-live', 'polite'); element.setAttribute('aria-atomic', 'true'); ariaContainer.appendChild(element); return element; }; statusContainer = createStatusContainer(); statusContainer2 = createStatusContainer(); parent.appendChild(ariaContainer); } /** * Given the provided message, will make sure that it is read as alert to screen readers. */ function alert(msg) { if (!ariaContainer) { return; } // Use alternate containers such that duplicated messages get read out by screen readers #99466 if (alertContainer.textContent !== msg) { clearNode(alertContainer2); insertMessage(alertContainer, msg); } else { clearNode(alertContainer); insertMessage(alertContainer2, msg); } } /** * Given the provided message, will make sure that it is read as status to screen readers. */ function status(msg) { if (!ariaContainer) { return; } if (isMacintosh) { alert(msg); // VoiceOver does not seem to support status role } else { if (statusContainer.textContent !== msg) { clearNode(statusContainer2); insertMessage(statusContainer, msg); } else { clearNode(statusContainer); insertMessage(statusContainer2, msg); } } } function insertMessage(target, msg) { clearNode(target); if (msg.length > MAX_MESSAGE_LENGTH) { msg = msg.substr(0, MAX_MESSAGE_LENGTH); } target.textContent = msg; // See https://www.paciellogroup.com/blog/2012/06/html5-accessibility-chops-aria-rolealert-browser-support/ target.style.visibility = 'hidden'; target.style.visibility = 'visible'; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const IMarkerDecorationsService = createDecorator('markerDecorationsService'); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const ITextModelService = createDecorator('textModelService'); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __awaiter$14 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; class Action extends Disposable { constructor(id, label = '', cssClass = '', enabled = true, actionCallback) { super(); this._onDidChange = this._register(new Emitter$1()); this.onDidChange = this._onDidChange.event; this._enabled = true; this._id = id; this._label = label; this._cssClass = cssClass; this._enabled = enabled; this._actionCallback = actionCallback; } get id() { return this._id; } get label() { return this._label; } set label(value) { this._setLabel(value); } _setLabel(value) { if (this._label !== value) { this._label = value; this._onDidChange.fire({ label: value }); } } get tooltip() { return this._tooltip || ''; } set tooltip(value) { this._setTooltip(value); } _setTooltip(value) { if (this._tooltip !== value) { this._tooltip = value; this._onDidChange.fire({ tooltip: value }); } } get class() { return this._cssClass; } set class(value) { this._setClass(value); } _setClass(value) { if (this._cssClass !== value) { this._cssClass = value; this._onDidChange.fire({ class: value }); } } get enabled() { return this._enabled; } set enabled(value) { this._setEnabled(value); } _setEnabled(value) { if (this._enabled !== value) { this._enabled = value; this._onDidChange.fire({ enabled: value }); } } get checked() { return this._checked; } set checked(value) { this._setChecked(value); } _setChecked(value) { if (this._checked !== value) { this._checked = value; this._onDidChange.fire({ checked: value }); } } run(event, data) { return __awaiter$14(this, void 0, void 0, function* () { if (this._actionCallback) { yield this._actionCallback(event); } }); } } class ActionRunner extends Disposable { constructor() { super(...arguments); this._onBeforeRun = this._register(new Emitter$1()); this.onBeforeRun = this._onBeforeRun.event; this._onDidRun = this._register(new Emitter$1()); this.onDidRun = this._onDidRun.event; } run(action, context) { return __awaiter$14(this, void 0, void 0, function* () { if (!action.enabled) { return; } this._onBeforeRun.fire({ action }); let error = undefined; try { yield this.runAction(action, context); } catch (e) { error = e; } this._onDidRun.fire({ action, error }); }); } runAction(action, context) { return __awaiter$14(this, void 0, void 0, function* () { yield action.run(context); }); } } class Separator extends Action { constructor(label) { super(Separator.ID, label, label ? 'separator text' : 'separator'); this.checked = false; this.enabled = false; } } Separator.ID = 'vs.actions.separator'; class SubmenuAction { constructor(id, label, actions, cssClass) { this.tooltip = ''; this.enabled = true; this.checked = undefined; this.id = id; this.label = label; this.class = cssClass; this._actions = actions; } get actions() { return this._actions; } dispose() { // there is NOTHING to dispose and the SubmenuAction should // never have anything to dispose as it is a convenience type // to bridge into the rendering world. } run() { return __awaiter$14(this, void 0, void 0, function* () { }); } } class EmptySubmenuAction extends Action { constructor() { super(EmptySubmenuAction.ID, localize('submenu.empty', '(empty)'), undefined, false); } } EmptySubmenuAction.ID = 'vs.actions.empty'; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const ICommandService = createDecorator('commandService'); const CommandsRegistry = new class { constructor() { this._commands = new Map(); this._onDidRegisterCommand = new Emitter$1(); this.onDidRegisterCommand = this._onDidRegisterCommand.event; } registerCommand(idOrCommand, handler) { if (!idOrCommand) { throw new Error(`invalid command`); } if (typeof idOrCommand === 'string') { if (!handler) { throw new Error(`invalid command`); } return this.registerCommand({ id: idOrCommand, handler }); } // add argument validation if rich command metadata is provided if (idOrCommand.description) { const constraints = []; for (let arg of idOrCommand.description.args) { constraints.push(arg.constraint); } const actualHandler = idOrCommand.handler; idOrCommand.handler = function (accessor, ...args) { validateConstraints(args, constraints); return actualHandler(accessor, ...args); }; } // find a place to store the command const { id } = idOrCommand; let commands = this._commands.get(id); if (!commands) { commands = new LinkedList(); this._commands.set(id, commands); } let removeFn = commands.unshift(idOrCommand); let ret = toDisposable(() => { removeFn(); const command = this._commands.get(id); if (command === null || command === void 0 ? void 0 : command.isEmpty()) { this._commands.delete(id); } }); // tell the world about this command this._onDidRegisterCommand.fire(id); return ret; } registerCommandAlias(oldId, newId) { return CommandsRegistry.registerCommand(oldId, (accessor, ...args) => accessor.get(ICommandService).executeCommand(newId, ...args)); } getCommand(id) { const list = this._commands.get(id); if (!list || list.isEmpty()) { return undefined; } return Iterable.first(list); } getCommands() { const result = new Map(); for (const key of this._commands.keys()) { const command = this.getCommand(key); if (command) { result.set(key, command); } } return result; } }; CommandsRegistry.registerCommand('noop', () => { }); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const CONSTANT_VALUES = new Map(); CONSTANT_VALUES.set('false', false); CONSTANT_VALUES.set('true', true); CONSTANT_VALUES.set('isMac', isMacintosh); CONSTANT_VALUES.set('isLinux', isLinux); CONSTANT_VALUES.set('isWindows', isWindows); CONSTANT_VALUES.set('isWeb', isWeb); CONSTANT_VALUES.set('isMacNative', isMacintosh && !isWeb); CONSTANT_VALUES.set('isEdge', isEdge); CONSTANT_VALUES.set('isFirefox', isFirefox$1); CONSTANT_VALUES.set('isChrome', isChrome$1); CONSTANT_VALUES.set('isSafari', isSafari$1); const hasOwnProperty$3 = Object.prototype.hasOwnProperty; class ContextKeyExpr { static has(key) { return ContextKeyDefinedExpr.create(key); } static equals(key, value) { return ContextKeyEqualsExpr.create(key, value); } static regex(key, value) { return ContextKeyRegexExpr.create(key, value); } static not(key) { return ContextKeyNotExpr.create(key); } static and(...expr) { return ContextKeyAndExpr.create(expr, null); } static or(...expr) { return ContextKeyOrExpr.create(expr, null, true); } static deserialize(serialized, strict = false) { if (!serialized) { return undefined; } return this._deserializeOrExpression(serialized, strict); } static _deserializeOrExpression(serialized, strict) { let pieces = serialized.split('||'); return ContextKeyOrExpr.create(pieces.map(p => this._deserializeAndExpression(p, strict)), null, true); } static _deserializeAndExpression(serialized, strict) { let pieces = serialized.split('&&'); return ContextKeyAndExpr.create(pieces.map(p => this._deserializeOne(p, strict)), null); } static _deserializeOne(serializedOne, strict) { serializedOne = serializedOne.trim(); if (serializedOne.indexOf('!=') >= 0) { let pieces = serializedOne.split('!='); return ContextKeyNotEqualsExpr.create(pieces[0].trim(), this._deserializeValue(pieces[1], strict)); } if (serializedOne.indexOf('==') >= 0) { let pieces = serializedOne.split('=='); return ContextKeyEqualsExpr.create(pieces[0].trim(), this._deserializeValue(pieces[1], strict)); } if (serializedOne.indexOf('=~') >= 0) { let pieces = serializedOne.split('=~'); return ContextKeyRegexExpr.create(pieces[0].trim(), this._deserializeRegexValue(pieces[1], strict)); } if (serializedOne.indexOf(' in ') >= 0) { let pieces = serializedOne.split(' in '); return ContextKeyInExpr.create(pieces[0].trim(), pieces[1].trim()); } if (/^[^<=>]+>=[^<=>]+$/.test(serializedOne)) { const pieces = serializedOne.split('>='); return ContextKeyGreaterEqualsExpr.create(pieces[0].trim(), pieces[1].trim()); } if (/^[^<=>]+>[^<=>]+$/.test(serializedOne)) { const pieces = serializedOne.split('>'); return ContextKeyGreaterExpr.create(pieces[0].trim(), pieces[1].trim()); } if (/^[^<=>]+<=[^<=>]+$/.test(serializedOne)) { const pieces = serializedOne.split('<='); return ContextKeySmallerEqualsExpr.create(pieces[0].trim(), pieces[1].trim()); } if (/^[^<=>]+<[^<=>]+$/.test(serializedOne)) { const pieces = serializedOne.split('<'); return ContextKeySmallerExpr.create(pieces[0].trim(), pieces[1].trim()); } if (/^\!\s*/.test(serializedOne)) { return ContextKeyNotExpr.create(serializedOne.substr(1).trim()); } return ContextKeyDefinedExpr.create(serializedOne); } static _deserializeValue(serializedValue, strict) { serializedValue = serializedValue.trim(); if (serializedValue === 'true') { return true; } if (serializedValue === 'false') { return false; } let m = /^'([^']*)'$/.exec(serializedValue); if (m) { return m[1].trim(); } return serializedValue; } static _deserializeRegexValue(serializedValue, strict) { if (isFalsyOrWhitespace(serializedValue)) { if (strict) { throw new Error('missing regexp-value for =~-expression'); } else { console.warn('missing regexp-value for =~-expression'); } return null; } let start = serializedValue.indexOf('/'); let end = serializedValue.lastIndexOf('/'); if (start === end || start < 0 /* || to < 0 */) { if (strict) { throw new Error(`bad regexp-value '${serializedValue}', missing /-enclosure`); } else { console.warn(`bad regexp-value '${serializedValue}', missing /-enclosure`); } return null; } let value = serializedValue.slice(start + 1, end); let caseIgnoreFlag = serializedValue[end + 1] === 'i' ? 'i' : ''; try { return new RegExp(value, caseIgnoreFlag); } catch (e) { if (strict) { throw new Error(`bad regexp-value '${serializedValue}', parse error: ${e}`); } else { console.warn(`bad regexp-value '${serializedValue}', parse error: ${e}`); } return null; } } } function expressionsAreEqualWithConstantSubstitution(a, b) { const aExpr = a ? a.substituteConstants() : undefined; const bExpr = b ? b.substituteConstants() : undefined; if (!aExpr && !bExpr) { return true; } if (!aExpr || !bExpr) { return false; } return aExpr.equals(bExpr); } function cmp(a, b) { return a.cmp(b); } class ContextKeyFalseExpr { constructor() { this.type = 0 /* False */; } cmp(other) { return this.type - other.type; } equals(other) { return (other.type === this.type); } substituteConstants() { return this; } evaluate(context) { return false; } serialize() { return 'false'; } keys() { return []; } negate() { return ContextKeyTrueExpr.INSTANCE; } } ContextKeyFalseExpr.INSTANCE = new ContextKeyFalseExpr(); class ContextKeyTrueExpr { constructor() { this.type = 1 /* True */; } cmp(other) { return this.type - other.type; } equals(other) { return (other.type === this.type); } substituteConstants() { return this; } evaluate(context) { return true; } serialize() { return 'true'; } keys() { return []; } negate() { return ContextKeyFalseExpr.INSTANCE; } } ContextKeyTrueExpr.INSTANCE = new ContextKeyTrueExpr(); class ContextKeyDefinedExpr { constructor(key, negated) { this.key = key; this.negated = negated; this.type = 2 /* Defined */; } static create(key, negated = null) { const constantValue = CONSTANT_VALUES.get(key); if (typeof constantValue === 'boolean') { return constantValue ? ContextKeyTrueExpr.INSTANCE : ContextKeyFalseExpr.INSTANCE; } return new ContextKeyDefinedExpr(key, negated); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp1(this.key, other.key); } equals(other) { if (other.type === this.type) { return (this.key === other.key); } return false; } substituteConstants() { const constantValue = CONSTANT_VALUES.get(this.key); if (typeof constantValue === 'boolean') { return constantValue ? ContextKeyTrueExpr.INSTANCE : ContextKeyFalseExpr.INSTANCE; } return this; } evaluate(context) { return (!!context.getValue(this.key)); } serialize() { return this.key; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeyNotExpr.create(this.key, this); } return this.negated; } } class ContextKeyEqualsExpr { constructor(key, value, negated) { this.key = key; this.value = value; this.negated = negated; this.type = 4 /* Equals */; } static create(key, value, negated = null) { if (typeof value === 'boolean') { return (value ? ContextKeyDefinedExpr.create(key, negated) : ContextKeyNotExpr.create(key, negated)); } const constantValue = CONSTANT_VALUES.get(key); if (typeof constantValue === 'boolean') { const trueValue = constantValue ? 'true' : 'false'; return (value === trueValue ? ContextKeyTrueExpr.INSTANCE : ContextKeyFalseExpr.INSTANCE); } return new ContextKeyEqualsExpr(key, value, negated); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp2(this.key, this.value, other.key, other.value); } equals(other) { if (other.type === this.type) { return (this.key === other.key && this.value === other.value); } return false; } substituteConstants() { const constantValue = CONSTANT_VALUES.get(this.key); if (typeof constantValue === 'boolean') { const trueValue = constantValue ? 'true' : 'false'; return (this.value === trueValue ? ContextKeyTrueExpr.INSTANCE : ContextKeyFalseExpr.INSTANCE); } return this; } evaluate(context) { // Intentional == // eslint-disable-next-line eqeqeq return (context.getValue(this.key) == this.value); } serialize() { return `${this.key} == '${this.value}'`; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeyNotEqualsExpr.create(this.key, this.value, this); } return this.negated; } } class ContextKeyInExpr { constructor(key, valueKey) { this.key = key; this.valueKey = valueKey; this.type = 10 /* In */; this.negated = null; } static create(key, valueKey) { return new ContextKeyInExpr(key, valueKey); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp2(this.key, this.valueKey, other.key, other.valueKey); } equals(other) { if (other.type === this.type) { return (this.key === other.key && this.valueKey === other.valueKey); } return false; } substituteConstants() { return this; } evaluate(context) { const source = context.getValue(this.valueKey); const item = context.getValue(this.key); if (Array.isArray(source)) { return (source.indexOf(item) >= 0); } if (typeof item === 'string' && typeof source === 'object' && source !== null) { return hasOwnProperty$3.call(source, item); } return false; } serialize() { return `${this.key} in '${this.valueKey}'`; } keys() { return [this.key, this.valueKey]; } negate() { if (!this.negated) { this.negated = ContextKeyNotInExpr.create(this); } return this.negated; } } class ContextKeyNotInExpr { constructor(_actual) { this._actual = _actual; this.type = 11 /* NotIn */; // } static create(actual) { return new ContextKeyNotInExpr(actual); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return this._actual.cmp(other._actual); } equals(other) { if (other.type === this.type) { return this._actual.equals(other._actual); } return false; } substituteConstants() { return this; } evaluate(context) { return !this._actual.evaluate(context); } serialize() { throw new Error('Method not implemented.'); } keys() { return this._actual.keys(); } negate() { return this._actual; } } class ContextKeyNotEqualsExpr { constructor(key, value, negated) { this.key = key; this.value = value; this.negated = negated; this.type = 5 /* NotEquals */; } static create(key, value, negated = null) { if (typeof value === 'boolean') { if (value) { return ContextKeyNotExpr.create(key, negated); } return ContextKeyDefinedExpr.create(key, negated); } const constantValue = CONSTANT_VALUES.get(key); if (typeof constantValue === 'boolean') { const falseValue = constantValue ? 'true' : 'false'; return (value === falseValue ? ContextKeyFalseExpr.INSTANCE : ContextKeyTrueExpr.INSTANCE); } return new ContextKeyNotEqualsExpr(key, value, negated); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp2(this.key, this.value, other.key, other.value); } equals(other) { if (other.type === this.type) { return (this.key === other.key && this.value === other.value); } return false; } substituteConstants() { const constantValue = CONSTANT_VALUES.get(this.key); if (typeof constantValue === 'boolean') { const falseValue = constantValue ? 'true' : 'false'; return (this.value === falseValue ? ContextKeyFalseExpr.INSTANCE : ContextKeyTrueExpr.INSTANCE); } return this; } evaluate(context) { // Intentional != // eslint-disable-next-line eqeqeq return (context.getValue(this.key) != this.value); } serialize() { return `${this.key} != '${this.value}'`; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeyEqualsExpr.create(this.key, this.value, this); } return this.negated; } } class ContextKeyNotExpr { constructor(key, negated) { this.key = key; this.negated = negated; this.type = 3 /* Not */; } static create(key, negated = null) { const constantValue = CONSTANT_VALUES.get(key); if (typeof constantValue === 'boolean') { return (constantValue ? ContextKeyFalseExpr.INSTANCE : ContextKeyTrueExpr.INSTANCE); } return new ContextKeyNotExpr(key, negated); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp1(this.key, other.key); } equals(other) { if (other.type === this.type) { return (this.key === other.key); } return false; } substituteConstants() { const constantValue = CONSTANT_VALUES.get(this.key); if (typeof constantValue === 'boolean') { return (constantValue ? ContextKeyFalseExpr.INSTANCE : ContextKeyTrueExpr.INSTANCE); } return this; } evaluate(context) { return (!context.getValue(this.key)); } serialize() { return `!${this.key}`; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeyDefinedExpr.create(this.key, this); } return this.negated; } } function withFloatOrStr(value, callback) { if (typeof value === 'string') { const n = parseFloat(value); if (!isNaN(n)) { value = n; } } if (typeof value === 'string' || typeof value === 'number') { return callback(value); } return ContextKeyFalseExpr.INSTANCE; } class ContextKeyGreaterExpr { constructor(key, value, negated) { this.key = key; this.value = value; this.negated = negated; this.type = 12 /* Greater */; } static create(key, _value, negated = null) { return withFloatOrStr(_value, (value) => new ContextKeyGreaterExpr(key, value, negated)); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp2(this.key, this.value, other.key, other.value); } equals(other) { if (other.type === this.type) { return (this.key === other.key && this.value === other.value); } return false; } substituteConstants() { return this; } evaluate(context) { if (typeof this.value === 'string') { return false; } return (parseFloat(context.getValue(this.key)) > this.value); } serialize() { return `${this.key} > ${this.value}`; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeySmallerEqualsExpr.create(this.key, this.value, this); } return this.negated; } } class ContextKeyGreaterEqualsExpr { constructor(key, value, negated) { this.key = key; this.value = value; this.negated = negated; this.type = 13 /* GreaterEquals */; } static create(key, _value, negated = null) { return withFloatOrStr(_value, (value) => new ContextKeyGreaterEqualsExpr(key, value, negated)); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp2(this.key, this.value, other.key, other.value); } equals(other) { if (other.type === this.type) { return (this.key === other.key && this.value === other.value); } return false; } substituteConstants() { return this; } evaluate(context) { if (typeof this.value === 'string') { return false; } return (parseFloat(context.getValue(this.key)) >= this.value); } serialize() { return `${this.key} >= ${this.value}`; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeySmallerExpr.create(this.key, this.value, this); } return this.negated; } } class ContextKeySmallerExpr { constructor(key, value, negated) { this.key = key; this.value = value; this.negated = negated; this.type = 14 /* Smaller */; } static create(key, _value, negated = null) { return withFloatOrStr(_value, (value) => new ContextKeySmallerExpr(key, value, negated)); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp2(this.key, this.value, other.key, other.value); } equals(other) { if (other.type === this.type) { return (this.key === other.key && this.value === other.value); } return false; } substituteConstants() { return this; } evaluate(context) { if (typeof this.value === 'string') { return false; } return (parseFloat(context.getValue(this.key)) < this.value); } serialize() { return `${this.key} < ${this.value}`; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeyGreaterEqualsExpr.create(this.key, this.value, this); } return this.negated; } } class ContextKeySmallerEqualsExpr { constructor(key, value, negated) { this.key = key; this.value = value; this.negated = negated; this.type = 15 /* SmallerEquals */; } static create(key, _value, negated = null) { return withFloatOrStr(_value, (value) => new ContextKeySmallerEqualsExpr(key, value, negated)); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return cmp2(this.key, this.value, other.key, other.value); } equals(other) { if (other.type === this.type) { return (this.key === other.key && this.value === other.value); } return false; } substituteConstants() { return this; } evaluate(context) { if (typeof this.value === 'string') { return false; } return (parseFloat(context.getValue(this.key)) <= this.value); } serialize() { return `${this.key} <= ${this.value}`; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeyGreaterExpr.create(this.key, this.value, this); } return this.negated; } } class ContextKeyRegexExpr { constructor(key, regexp) { this.key = key; this.regexp = regexp; this.type = 7 /* Regex */; this.negated = null; // } static create(key, regexp) { return new ContextKeyRegexExpr(key, regexp); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } if (this.key < other.key) { return -1; } if (this.key > other.key) { return 1; } const thisSource = this.regexp ? this.regexp.source : ''; const otherSource = other.regexp ? other.regexp.source : ''; if (thisSource < otherSource) { return -1; } if (thisSource > otherSource) { return 1; } return 0; } equals(other) { if (other.type === this.type) { const thisSource = this.regexp ? this.regexp.source : ''; const otherSource = other.regexp ? other.regexp.source : ''; return (this.key === other.key && thisSource === otherSource); } return false; } substituteConstants() { return this; } evaluate(context) { let value = context.getValue(this.key); return this.regexp ? this.regexp.test(value) : false; } serialize() { const value = this.regexp ? `/${this.regexp.source}/${this.regexp.ignoreCase ? 'i' : ''}` : '/invalid/'; return `${this.key} =~ ${value}`; } keys() { return [this.key]; } negate() { if (!this.negated) { this.negated = ContextKeyNotRegexExpr.create(this); } return this.negated; } } class ContextKeyNotRegexExpr { constructor(_actual) { this._actual = _actual; this.type = 8 /* NotRegex */; // } static create(actual) { return new ContextKeyNotRegexExpr(actual); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } return this._actual.cmp(other._actual); } equals(other) { if (other.type === this.type) { return this._actual.equals(other._actual); } return false; } substituteConstants() { return this; } evaluate(context) { return !this._actual.evaluate(context); } serialize() { throw new Error('Method not implemented.'); } keys() { return this._actual.keys(); } negate() { return this._actual; } } /** * @returns the same instance if nothing changed. */ function eliminateConstantsInArray(arr) { // Allocate array only if there is a difference let newArr = null; for (let i = 0, len = arr.length; i < len; i++) { const newExpr = arr[i].substituteConstants(); if (arr[i] !== newExpr) { // something has changed! // allocate array on first difference if (newArr === null) { newArr = []; for (let j = 0; j < i; j++) { newArr[j] = arr[j]; } } } if (newArr !== null) { newArr[i] = newExpr; } } if (newArr === null) { return arr; } return newArr; } class ContextKeyAndExpr { constructor(expr, negated) { this.expr = expr; this.negated = negated; this.type = 6 /* And */; } static create(_expr, negated) { return ContextKeyAndExpr._normalizeArr(_expr, negated); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } if (this.expr.length < other.expr.length) { return -1; } if (this.expr.length > other.expr.length) { return 1; } for (let i = 0, len = this.expr.length; i < len; i++) { const r = cmp(this.expr[i], other.expr[i]); if (r !== 0) { return r; } } return 0; } equals(other) { if (other.type === this.type) { if (this.expr.length !== other.expr.length) { return false; } for (let i = 0, len = this.expr.length; i < len; i++) { if (!this.expr[i].equals(other.expr[i])) { return false; } } return true; } return false; } substituteConstants() { const exprArr = eliminateConstantsInArray(this.expr); if (exprArr === this.expr) { // no change return this; } return ContextKeyAndExpr.create(exprArr, this.negated); } evaluate(context) { for (let i = 0, len = this.expr.length; i < len; i++) { if (!this.expr[i].evaluate(context)) { return false; } } return true; } static _normalizeArr(arr, negated) { const expr = []; let hasTrue = false; for (const e of arr) { if (!e) { continue; } if (e.type === 1 /* True */) { // anything && true ==> anything hasTrue = true; continue; } if (e.type === 0 /* False */) { // anything && false ==> false return ContextKeyFalseExpr.INSTANCE; } if (e.type === 6 /* And */) { expr.push(...e.expr); continue; } expr.push(e); } if (expr.length === 0 && hasTrue) { return ContextKeyTrueExpr.INSTANCE; } if (expr.length === 0) { return undefined; } if (expr.length === 1) { return expr[0]; } expr.sort(cmp); // eliminate duplicate terms for (let i = 1; i < expr.length; i++) { if (expr[i - 1].equals(expr[i])) { expr.splice(i, 1); i--; } } if (expr.length === 1) { return expr[0]; } // We must distribute any OR expression because we don't support parens // OR extensions will be at the end (due to sorting rules) while (expr.length > 1) { const lastElement = expr[expr.length - 1]; if (lastElement.type !== 9 /* Or */) { break; } // pop the last element expr.pop(); // pop the second to last element const secondToLastElement = expr.pop(); const isFinished = (expr.length === 0); // distribute `lastElement` over `secondToLastElement` const resultElement = ContextKeyOrExpr.create(lastElement.expr.map(el => ContextKeyAndExpr.create([el, secondToLastElement], null)), null, isFinished); if (resultElement) { expr.push(resultElement); expr.sort(cmp); } } if (expr.length === 1) { return expr[0]; } return new ContextKeyAndExpr(expr, negated); } serialize() { return this.expr.map(e => e.serialize()).join(' && '); } keys() { const result = []; for (let expr of this.expr) { result.push(...expr.keys()); } return result; } negate() { if (!this.negated) { const result = []; for (let expr of this.expr) { result.push(expr.negate()); } this.negated = ContextKeyOrExpr.create(result, this, true); } return this.negated; } } class ContextKeyOrExpr { constructor(expr, negated) { this.expr = expr; this.negated = negated; this.type = 9 /* Or */; } static create(_expr, negated, extraRedundantCheck) { return ContextKeyOrExpr._normalizeArr(_expr, negated, extraRedundantCheck); } cmp(other) { if (other.type !== this.type) { return this.type - other.type; } if (this.expr.length < other.expr.length) { return -1; } if (this.expr.length > other.expr.length) { return 1; } for (let i = 0, len = this.expr.length; i < len; i++) { const r = cmp(this.expr[i], other.expr[i]); if (r !== 0) { return r; } } return 0; } equals(other) { if (other.type === this.type) { if (this.expr.length !== other.expr.length) { return false; } for (let i = 0, len = this.expr.length; i < len; i++) { if (!this.expr[i].equals(other.expr[i])) { return false; } } return true; } return false; } substituteConstants() { const exprArr = eliminateConstantsInArray(this.expr); if (exprArr === this.expr) { // no change return this; } return ContextKeyOrExpr.create(exprArr, this.negated, false); } evaluate(context) { for (let i = 0, len = this.expr.length; i < len; i++) { if (this.expr[i].evaluate(context)) { return true; } } return false; } static _normalizeArr(arr, negated, extraRedundantCheck) { let expr = []; let hasFalse = false; if (arr) { for (let i = 0, len = arr.length; i < len; i++) { const e = arr[i]; if (!e) { continue; } if (e.type === 0 /* False */) { // anything || false ==> anything hasFalse = true; continue; } if (e.type === 1 /* True */) { // anything || true ==> true return ContextKeyTrueExpr.INSTANCE; } if (e.type === 9 /* Or */) { expr = expr.concat(e.expr); continue; } expr.push(e); } if (expr.length === 0 && hasFalse) { return ContextKeyFalseExpr.INSTANCE; } expr.sort(cmp); } if (expr.length === 0) { return undefined; } if (expr.length === 1) { return expr[0]; } // eliminate duplicate terms for (let i = 1; i < expr.length; i++) { if (expr[i - 1].equals(expr[i])) { expr.splice(i, 1); i--; } } if (expr.length === 1) { return expr[0]; } // eliminate redundant terms if (extraRedundantCheck) { for (let i = 0; i < expr.length; i++) { for (let j = i + 1; j < expr.length; j++) { if (implies(expr[i], expr[j])) { expr.splice(j, 1); j--; } } } if (expr.length === 1) { return expr[0]; } } return new ContextKeyOrExpr(expr, negated); } serialize() { return this.expr.map(e => e.serialize()).join(' || '); } keys() { const result = []; for (let expr of this.expr) { result.push(...expr.keys()); } return result; } negate() { if (!this.negated) { let result = []; for (let expr of this.expr) { result.push(expr.negate()); } // We don't support parens, so here we distribute the AND over the OR terminals // We always take the first 2 AND pairs and distribute them while (result.length > 1) { const LEFT = result.shift(); const RIGHT = result.shift(); const all = []; for (const left of getTerminals(LEFT)) { for (const right of getTerminals(RIGHT)) { all.push(ContextKeyAndExpr.create([left, right], null)); } } const isFinished = (result.length === 0); result.unshift(ContextKeyOrExpr.create(all, null, isFinished)); } this.negated = result[0]; } return this.negated; } } class RawContextKey extends ContextKeyDefinedExpr { constructor(key, defaultValue, metaOrHide) { super(key, null); this._defaultValue = defaultValue; // collect all context keys into a central place if (typeof metaOrHide === 'object') { RawContextKey._info.push(Object.assign(Object.assign({}, metaOrHide), { key })); } else if (metaOrHide !== true) { RawContextKey._info.push({ key, description: metaOrHide, type: defaultValue !== null && defaultValue !== undefined ? typeof defaultValue : undefined }); } } static all() { return RawContextKey._info.values(); } bindTo(target) { return target.createKey(this.key, this._defaultValue); } getValue(target) { return target.getContextKeyValue(this.key); } toNegated() { return this.negate(); } isEqualTo(value) { return ContextKeyEqualsExpr.create(this.key, value); } } RawContextKey._info = []; const IContextKeyService = createDecorator('contextKeyService'); const SET_CONTEXT_COMMAND_ID = 'setContext'; function cmp1(key1, key2) { if (key1 < key2) { return -1; } if (key1 > key2) { return 1; } return 0; } function cmp2(key1, value1, key2, value2) { if (key1 < key2) { return -1; } if (key1 > key2) { return 1; } if (value1 < value2) { return -1; } if (value1 > value2) { return 1; } return 0; } /** * Returns true if it is provable `p` implies `q`. */ function implies(p, q) { if (q.type === 6 /* And */ && (p.type !== 9 /* Or */ && p.type !== 6 /* And */)) { // covers the case: A implies A && B for (const qTerm of q.expr) { if (p.equals(qTerm)) { return true; } } } const notP = p.negate(); const expr = getTerminals(notP).concat(getTerminals(q)); expr.sort(cmp); for (let i = 0; i < expr.length; i++) { const a = expr[i]; const notA = a.negate(); for (let j = i + 1; j < expr.length; j++) { const b = expr[j]; if (notA.equals(b)) { return true; } } } return false; } function getTerminals(node) { if (node.type === 9 /* Or */) { return node.expr; } return [node]; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class RegistryImpl { constructor() { this.data = new Map(); } add(id, data) { ok(isString$1(id)); ok(isObject(data)); ok(!this.data.has(id), 'There is already an extension with this id'); this.data.set(id, data); } as(id) { return this.data.get(id) || null; } } const Registry = new RegistryImpl(); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Color scheme used by the OS and by color themes. */ var ColorScheme; (function (ColorScheme) { ColorScheme["DARK"] = "dark"; ColorScheme["LIGHT"] = "light"; ColorScheme["HIGH_CONTRAST"] = "hc"; })(ColorScheme || (ColorScheme = {})); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const IThemeService = createDecorator('themeService'); var ThemeColor; (function (ThemeColor) { function isThemeColor(obj) { return obj && typeof obj === 'object' && typeof obj.id === 'string'; } ThemeColor.isThemeColor = isThemeColor; })(ThemeColor || (ThemeColor = {})); function themeColorFromId(id) { return { id }; } var ThemeIcon; (function (ThemeIcon) { function isThemeIcon(obj) { return obj && typeof obj === 'object' && typeof obj.id === 'string' && (typeof obj.color === 'undefined' || ThemeColor.isThemeColor(obj.color)); } ThemeIcon.isThemeIcon = isThemeIcon; const _regexFromString = new RegExp(`^\\$\\((${CSSIcon.iconNameExpression}(?:${CSSIcon.iconModifierExpression})?)\\)$`); function fromString(str) { const match = _regexFromString.exec(str); if (!match) { return undefined; } let [, name] = match; return { id: name }; } ThemeIcon.fromString = fromString; function fromId(id) { return { id }; } ThemeIcon.fromId = fromId; function modify(icon, modifier) { let id = icon.id; const tildeIndex = id.lastIndexOf('~'); if (tildeIndex !== -1) { id = id.substring(0, tildeIndex); } if (modifier) { id = `${id}~${modifier}`; } return { id }; } ThemeIcon.modify = modify; function getModifier(icon) { const tildeIndex = icon.id.lastIndexOf('~'); if (tildeIndex !== -1) { return icon.id.substring(tildeIndex + 1); } return undefined; } ThemeIcon.getModifier = getModifier; function isEqual(ti1, ti2) { var _a, _b; return ti1.id === ti2.id && ((_a = ti1.color) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ti2.color) === null || _b === void 0 ? void 0 : _b.id); } ThemeIcon.isEqual = isEqual; function asThemeIcon(codicon, color) { return { id: codicon.id, color: color ? themeColorFromId(color) : undefined }; } ThemeIcon.asThemeIcon = asThemeIcon; ThemeIcon.asClassNameArray = CSSIcon.asClassNameArray; ThemeIcon.asClassName = CSSIcon.asClassName; ThemeIcon.asCSSSelector = CSSIcon.asCSSSelector; })(ThemeIcon || (ThemeIcon = {})); function getThemeTypeSelector(type) { switch (type) { case ColorScheme.DARK: return 'vs-dark'; case ColorScheme.HIGH_CONTRAST: return 'hc-black'; default: return 'vs'; } } // static theming participant const Extensions$8 = { ThemingContribution: 'base.contributions.theming' }; class ThemingRegistry { constructor() { this.themingParticipants = []; this.themingParticipants = []; this.onThemingParticipantAddedEmitter = new Emitter$1(); } onColorThemeChange(participant) { this.themingParticipants.push(participant); this.onThemingParticipantAddedEmitter.fire(participant); return toDisposable(() => { const idx = this.themingParticipants.indexOf(participant); this.themingParticipants.splice(idx, 1); }); } getThemingParticipants() { return this.themingParticipants; } } let themingRegistry$1 = new ThemingRegistry(); Registry.add(Extensions$8.ThemingContribution, themingRegistry$1); function registerThemingParticipant(participant) { return themingRegistry$1.onColorThemeChange(participant); } /** * Utility base class for all themable components. */ class Themable extends Disposable { constructor(themeService) { super(); this.themeService = themeService; this.theme = themeService.getColorTheme(); // Hook up to theme changes this._register(this.themeService.onDidColorThemeChange(theme => this.onThemeChange(theme))); } onThemeChange(theme) { this.theme = theme; this.updateStyles(); } updateStyles() { // Subclasses to override } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate$1E = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param$1y = (undefined && undefined.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; function isIMenuItem(item) { return item.command !== undefined; } class MenuId { constructor(debugName) { this.id = MenuId._idPool++; this._debugName = debugName; } } MenuId._idPool = 0; MenuId.CommandPalette = new MenuId('CommandPalette'); MenuId.DebugBreakpointsContext = new MenuId('DebugBreakpointsContext'); MenuId.DebugCallStackContext = new MenuId('DebugCallStackContext'); MenuId.DebugConsoleContext = new MenuId('DebugConsoleContext'); MenuId.DebugVariablesContext = new MenuId('DebugVariablesContext'); MenuId.DebugWatchContext = new MenuId('DebugWatchContext'); MenuId.DebugToolBar = new MenuId('DebugToolBar'); MenuId.EditorContext = new MenuId('EditorContext'); MenuId.SimpleEditorContext = new MenuId('SimpleEditorContext'); MenuId.EditorContextCopy = new MenuId('EditorContextCopy'); MenuId.EditorContextPeek = new MenuId('EditorContextPeek'); MenuId.EditorTitle = new MenuId('EditorTitle'); MenuId.EditorTitleRun = new MenuId('EditorTitleRun'); MenuId.EditorTitleContext = new MenuId('EditorTitleContext'); MenuId.EmptyEditorGroup = new MenuId('EmptyEditorGroup'); MenuId.EmptyEditorGroupContext = new MenuId('EmptyEditorGroupContext'); MenuId.ExplorerContext = new MenuId('ExplorerContext'); MenuId.ExtensionContext = new MenuId('ExtensionContext'); MenuId.GlobalActivity = new MenuId('GlobalActivity'); MenuId.LayoutControlMenu = new MenuId('LayoutControlMenu'); MenuId.MenubarMainMenu = new MenuId('MenubarMainMenu'); MenuId.MenubarAppearanceMenu = new MenuId('MenubarAppearanceMenu'); MenuId.MenubarDebugMenu = new MenuId('MenubarDebugMenu'); MenuId.MenubarEditMenu = new MenuId('MenubarEditMenu'); MenuId.MenubarCopy = new MenuId('MenubarCopy'); MenuId.MenubarFileMenu = new MenuId('MenubarFileMenu'); MenuId.MenubarGoMenu = new MenuId('MenubarGoMenu'); MenuId.MenubarHelpMenu = new MenuId('MenubarHelpMenu'); MenuId.MenubarLayoutMenu = new MenuId('MenubarLayoutMenu'); MenuId.MenubarNewBreakpointMenu = new MenuId('MenubarNewBreakpointMenu'); MenuId.MenubarPanelAlignmentMenu = new MenuId('MenubarPanelAlignmentMenu'); MenuId.MenubarPreferencesMenu = new MenuId('MenubarPreferencesMenu'); MenuId.MenubarRecentMenu = new MenuId('MenubarRecentMenu'); MenuId.MenubarSelectionMenu = new MenuId('MenubarSelectionMenu'); MenuId.MenubarSwitchEditorMenu = new MenuId('MenubarSwitchEditorMenu'); MenuId.MenubarSwitchGroupMenu = new MenuId('MenubarSwitchGroupMenu'); MenuId.MenubarTerminalMenu = new MenuId('MenubarTerminalMenu'); MenuId.MenubarViewMenu = new MenuId('MenubarViewMenu'); MenuId.MenubarHomeMenu = new MenuId('MenubarHomeMenu'); MenuId.OpenEditorsContext = new MenuId('OpenEditorsContext'); MenuId.ProblemsPanelContext = new MenuId('ProblemsPanelContext'); MenuId.SCMChangeContext = new MenuId('SCMChangeContext'); MenuId.SCMResourceContext = new MenuId('SCMResourceContext'); MenuId.SCMResourceFolderContext = new MenuId('SCMResourceFolderContext'); MenuId.SCMResourceGroupContext = new MenuId('SCMResourceGroupContext'); MenuId.SCMSourceControl = new MenuId('SCMSourceControl'); MenuId.SCMTitle = new MenuId('SCMTitle'); MenuId.SearchContext = new MenuId('SearchContext'); MenuId.StatusBarWindowIndicatorMenu = new MenuId('StatusBarWindowIndicatorMenu'); MenuId.StatusBarRemoteIndicatorMenu = new MenuId('StatusBarRemoteIndicatorMenu'); MenuId.TestItem = new MenuId('TestItem'); MenuId.TestItemGutter = new MenuId('TestItemGutter'); MenuId.TestPeekElement = new MenuId('TestPeekElement'); MenuId.TestPeekTitle = new MenuId('TestPeekTitle'); MenuId.TouchBarContext = new MenuId('TouchBarContext'); MenuId.TitleBarContext = new MenuId('TitleBarContext'); MenuId.TunnelContext = new MenuId('TunnelContext'); MenuId.TunnelPrivacy = new MenuId('TunnelPrivacy'); MenuId.TunnelProtocol = new MenuId('TunnelProtocol'); MenuId.TunnelPortInline = new MenuId('TunnelInline'); MenuId.TunnelTitle = new MenuId('TunnelTitle'); MenuId.TunnelLocalAddressInline = new MenuId('TunnelLocalAddressInline'); MenuId.TunnelOriginInline = new MenuId('TunnelOriginInline'); MenuId.ViewItemContext = new MenuId('ViewItemContext'); MenuId.ViewContainerTitle = new MenuId('ViewContainerTitle'); MenuId.ViewContainerTitleContext = new MenuId('ViewContainerTitleContext'); MenuId.ViewTitle = new MenuId('ViewTitle'); MenuId.ViewTitleContext = new MenuId('ViewTitleContext'); MenuId.CommentThreadTitle = new MenuId('CommentThreadTitle'); MenuId.CommentThreadActions = new MenuId('CommentThreadActions'); MenuId.CommentTitle = new MenuId('CommentTitle'); MenuId.CommentActions = new MenuId('CommentActions'); MenuId.InteractiveToolbar = new MenuId('InteractiveToolbar'); MenuId.InteractiveCellTitle = new MenuId('InteractiveCellTitle'); MenuId.InteractiveCellExecute = new MenuId('InteractiveCellExecute'); MenuId.InteractiveInputExecute = new MenuId('InteractiveInputExecute'); MenuId.NotebookToolbar = new MenuId('NotebookToolbar'); MenuId.NotebookCellTitle = new MenuId('NotebookCellTitle'); MenuId.NotebookCellInsert = new MenuId('NotebookCellInsert'); MenuId.NotebookCellBetween = new MenuId('NotebookCellBetween'); MenuId.NotebookCellListTop = new MenuId('NotebookCellTop'); MenuId.NotebookCellExecute = new MenuId('NotebookCellExecute'); MenuId.NotebookCellExecutePrimary = new MenuId('NotebookCellExecutePrimary'); MenuId.NotebookDiffCellInputTitle = new MenuId('NotebookDiffCellInputTitle'); MenuId.NotebookDiffCellMetadataTitle = new MenuId('NotebookDiffCellMetadataTitle'); MenuId.NotebookDiffCellOutputsTitle = new MenuId('NotebookDiffCellOutputsTitle'); MenuId.NotebookOutputToolbar = new MenuId('NotebookOutputToolbar'); MenuId.NotebookEditorLayoutConfigure = new MenuId('NotebookEditorLayoutConfigure'); MenuId.BulkEditTitle = new MenuId('BulkEditTitle'); MenuId.BulkEditContext = new MenuId('BulkEditContext'); MenuId.TimelineItemContext = new MenuId('TimelineItemContext'); MenuId.TimelineTitle = new MenuId('TimelineTitle'); MenuId.TimelineTitleContext = new MenuId('TimelineTitleContext'); MenuId.AccountsContext = new MenuId('AccountsContext'); MenuId.PanelTitle = new MenuId('PanelTitle'); MenuId.TerminalInstanceContext = new MenuId('TerminalInstanceContext'); MenuId.TerminalEditorInstanceContext = new MenuId('TerminalEditorInstanceContext'); MenuId.TerminalNewDropdownContext = new MenuId('TerminalNewDropdownContext'); MenuId.TerminalTabContext = new MenuId('TerminalTabContext'); MenuId.TerminalTabEmptyAreaContext = new MenuId('TerminalTabEmptyAreaContext'); MenuId.TerminalInlineTabContext = new MenuId('TerminalInlineTabContext'); MenuId.WebviewContext = new MenuId('WebviewContext'); MenuId.InlineCompletionsActions = new MenuId('InlineCompletionsActions'); MenuId.NewFile = new MenuId('NewFile'); const IMenuService = createDecorator('menuService'); const MenuRegistry = new class { constructor() { this._commands = new Map(); this._menuItems = new Map(); this._onDidChangeMenu = new Emitter$1(); this.onDidChangeMenu = this._onDidChangeMenu.event; this._commandPaletteChangeEvent = { has: id => id === MenuId.CommandPalette }; } addCommand(command) { return this.addCommands(Iterable.single(command)); } addCommands(commands) { for (const command of commands) { this._commands.set(command.id, command); } this._onDidChangeMenu.fire(this._commandPaletteChangeEvent); return toDisposable(() => { let didChange = false; for (const command of commands) { didChange = this._commands.delete(command.id) || didChange; } if (didChange) { this._onDidChangeMenu.fire(this._commandPaletteChangeEvent); } }); } getCommand(id) { return this._commands.get(id); } getCommands() { const map = new Map(); this._commands.forEach((value, key) => map.set(key, value)); return map; } appendMenuItem(id, item) { return this.appendMenuItems(Iterable.single({ id, item })); } appendMenuItems(items) { const changedIds = new Set(); const toRemove = new LinkedList(); for (const { id, item } of items) { let list = this._menuItems.get(id); if (!list) { list = new LinkedList(); this._menuItems.set(id, list); } toRemove.push(list.push(item)); changedIds.add(id); } this._onDidChangeMenu.fire(changedIds); return toDisposable(() => { if (toRemove.size > 0) { for (let fn of toRemove) { fn(); } this._onDidChangeMenu.fire(changedIds); toRemove.clear(); } }); } getMenuItems(id) { let result; if (this._menuItems.has(id)) { result = [...this._menuItems.get(id)]; } else { result = []; } if (id === MenuId.CommandPalette) { // CommandPalette is special because it shows // all commands by default this._appendImplicitItems(result); } return result; } _appendImplicitItems(result) { const set = new Set(); for (const item of result) { if (isIMenuItem(item)) { set.add(item.command.id); if (item.alt) { set.add(item.alt.id); } } } this._commands.forEach((command, id) => { if (!set.has(id)) { result.push({ command }); } }); } }; class SubmenuItemAction extends SubmenuAction { constructor(item, _menuService, _contextKeyService, _options) { super(`submenuitem.${item.submenu.id}`, typeof item.title === 'string' ? item.title : item.title.value, [], 'submenu'); this.item = item; this._menuService = _menuService; this._contextKeyService = _contextKeyService; this._options = _options; } get actions() { const result = []; const menu = this._menuService.createMenu(this.item.submenu, this._contextKeyService); const groups = menu.getActions(this._options); menu.dispose(); for (const [, actions] of groups) { if (actions.length > 0) { result.push(...actions); result.push(new Separator()); } } if (result.length) { result.pop(); // remove last separator } return result; } } // implements IAction, does NOT extend Action, so that no one // subscribes to events of Action or modified properties let MenuItemAction = class MenuItemAction { constructor(item, alt, options, contextKeyService, _commandService) { var _a, _b; this._commandService = _commandService; this.id = item.id; this.label = (options === null || options === void 0 ? void 0 : options.renderShortTitle) && item.shortTitle ? (typeof item.shortTitle === 'string' ? item.shortTitle : item.shortTitle.value) : (typeof item.title === 'string' ? item.title : item.title.value); this.tooltip = (_b = (typeof item.tooltip === 'string' ? item.tooltip : (_a = item.tooltip) === null || _a === void 0 ? void 0 : _a.value)) !== null && _b !== void 0 ? _b : ''; this.enabled = !item.precondition || contextKeyService.contextMatchesRules(item.precondition); this.checked = undefined; if (item.toggled) { const toggled = (item.toggled.condition ? item.toggled : { condition: item.toggled }); this.checked = contextKeyService.contextMatchesRules(toggled.condition); if (this.checked && toggled.tooltip) { this.tooltip = typeof toggled.tooltip === 'string' ? toggled.tooltip : toggled.tooltip.value; } if (toggled.title) { this.label = typeof toggled.title === 'string' ? toggled.title : toggled.title.value; } } this.item = item; this.alt = alt ? new MenuItemAction(alt, undefined, options, contextKeyService, _commandService) : undefined; this._options = options; if (ThemeIcon.isThemeIcon(item.icon)) { this.class = CSSIcon.asClassName(item.icon); } } dispose() { // there is NOTHING to dispose and the MenuItemAction should // never have anything to dispose as it is a convenience type // to bridge into the rendering world. } run(...args) { var _a, _b; let runArgs = []; if ((_a = this._options) === null || _a === void 0 ? void 0 : _a.arg) { runArgs = [...runArgs, this._options.arg]; } if ((_b = this._options) === null || _b === void 0 ? void 0 : _b.shouldForwardArgs) { runArgs = [...runArgs, ...args]; } return this._commandService.executeCommand(this.id, ...runArgs); } }; MenuItemAction = __decorate$1E([ __param$1y(3, IContextKeyService), __param$1y(4, ICommandService) ], MenuItemAction); //#endregion /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class KeybindingsRegistryImpl { constructor() { this._coreKeybindings = []; this._extensionKeybindings = []; this._cachedMergedKeybindings = null; } /** * Take current platform into account and reduce to primary & secondary. */ static bindToCurrentPlatform(kb) { if (OS === 1 /* Windows */) { if (kb && kb.win) { return kb.win; } } else if (OS === 2 /* Macintosh */) { if (kb && kb.mac) { return kb.mac; } } else { if (kb && kb.linux) { return kb.linux; } } return kb; } registerKeybindingRule(rule) { const actualKb = KeybindingsRegistryImpl.bindToCurrentPlatform(rule); if (actualKb && actualKb.primary) { const kk = createKeybinding(actualKb.primary, OS); if (kk) { this._registerDefaultKeybinding(kk, rule.id, rule.args, rule.weight, 0, rule.when); } } if (actualKb && Array.isArray(actualKb.secondary)) { for (let i = 0, len = actualKb.secondary.length; i < len; i++) { const k = actualKb.secondary[i]; const kk = createKeybinding(k, OS); if (kk) { this._registerDefaultKeybinding(kk, rule.id, rule.args, rule.weight, -i - 1, rule.when); } } } } registerCommandAndKeybindingRule(desc) { this.registerKeybindingRule(desc); CommandsRegistry.registerCommand(desc); } static _mightProduceChar(keyCode) { if (keyCode >= 21 /* Digit0 */ && keyCode <= 30 /* Digit9 */) { return true; } if (keyCode >= 31 /* KeyA */ && keyCode <= 56 /* KeyZ */) { return true; } return (keyCode === 80 /* Semicolon */ || keyCode === 81 /* Equal */ || keyCode === 82 /* Comma */ || keyCode === 83 /* Minus */ || keyCode === 84 /* Period */ || keyCode === 85 /* Slash */ || keyCode === 86 /* Backquote */ || keyCode === 110 /* ABNT_C1 */ || keyCode === 111 /* ABNT_C2 */ || keyCode === 87 /* BracketLeft */ || keyCode === 88 /* Backslash */ || keyCode === 89 /* BracketRight */ || keyCode === 90 /* Quote */ || keyCode === 91 /* OEM_8 */ || keyCode === 92 /* IntlBackslash */); } _assertNoCtrlAlt(keybinding, commandId) { if (keybinding.ctrlKey && keybinding.altKey && !keybinding.metaKey) { if (KeybindingsRegistryImpl._mightProduceChar(keybinding.keyCode)) { console.warn('Ctrl+Alt+ keybindings should not be used by default under Windows. Offender: ', keybinding, ' for ', commandId); } } } _registerDefaultKeybinding(keybinding, commandId, commandArgs, weight1, weight2, when) { if (OS === 1 /* Windows */) { this._assertNoCtrlAlt(keybinding.parts[0], commandId); } this._coreKeybindings.push({ keybinding: keybinding.parts, command: commandId, commandArgs: commandArgs, when: when, weight1: weight1, weight2: weight2, extensionId: null, isBuiltinExtension: false }); this._cachedMergedKeybindings = null; } getDefaultKeybindings() { if (!this._cachedMergedKeybindings) { this._cachedMergedKeybindings = [].concat(this._coreKeybindings).concat(this._extensionKeybindings); this._cachedMergedKeybindings.sort(sorter); } return this._cachedMergedKeybindings.slice(0); } } const KeybindingsRegistry = new KeybindingsRegistryImpl(); // Define extension point ids const Extensions$7 = { EditorModes: 'platform.keybindingsRegistry' }; Registry.add(Extensions$7.EditorModes, KeybindingsRegistry); function sorter(a, b) { if (a.weight1 !== b.weight1) { return a.weight1 - b.weight1; } if (a.command < b.command) { return -1; } if (a.command > b.command) { return 1; } return a.weight2 - b.weight2; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const ITelemetryService = createDecorator('telemetryService'); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class Command$3 { constructor(opts) { this.id = opts.id; this.precondition = opts.precondition; this._kbOpts = opts.kbOpts; this._menuOpts = opts.menuOpts; this._description = opts.description; } register() { if (Array.isArray(this._menuOpts)) { this._menuOpts.forEach(this._registerMenuItem, this); } else if (this._menuOpts) { this._registerMenuItem(this._menuOpts); } if (this._kbOpts) { const kbOptsArr = Array.isArray(this._kbOpts) ? this._kbOpts : [this._kbOpts]; for (const kbOpts of kbOptsArr) { let kbWhen = kbOpts.kbExpr; if (this.precondition) { if (kbWhen) { kbWhen = ContextKeyExpr.and(kbWhen, this.precondition); } else { kbWhen = this.precondition; } } const desc = { id: this.id, weight: kbOpts.weight, args: kbOpts.args, when: kbWhen, primary: kbOpts.primary, secondary: kbOpts.secondary, win: kbOpts.win, linux: kbOpts.linux, mac: kbOpts.mac, }; KeybindingsRegistry.registerKeybindingRule(desc); } } CommandsRegistry.registerCommand({ id: this.id, handler: (accessor, args) => this.runCommand(accessor, args), description: this._description }); } _registerMenuItem(item) { MenuRegistry.appendMenuItem(item.menuId, { group: item.group, command: { id: this.id, title: item.title, icon: item.icon, precondition: this.precondition }, when: item.when, order: item.order }); } } class MultiCommand extends Command$3 { constructor() { super(...arguments); this._implementations = []; } /** * A higher priority gets to be looked at first */ addImplementation(priority, name, implementation) { this._implementations.push({ priority, name, implementation }); this._implementations.sort((a, b) => b.priority - a.priority); return { dispose: () => { for (let i = 0; i < this._implementations.length; i++) { if (this._implementations[i].implementation === implementation) { this._implementations.splice(i, 1); return; } } } }; } runCommand(accessor, args) { const logService = accessor.get(ILogService); logService.trace(`Executing Command '${this.id}' which has ${this._implementations.length} bound.`); for (const impl of this._implementations) { const result = impl.implementation(accessor, args); if (result) { logService.trace(`Command '${this.id}' was handled by '${impl.name}'.`); if (typeof result === 'boolean') { return; } return result; } } logService.trace(`The Command '${this.id}' was not handled by any implementation.`); } } //#endregion /** * A command that delegates to another command's implementation. * * This lets different commands be registered but share the same implementation */ class ProxyCommand extends Command$3 { constructor(command, opts) { super(opts); this.command = command; } runCommand(accessor, args) { return this.command.runCommand(accessor, args); } } class EditorCommand extends Command$3 { /** * Create a command class that is bound to a certain editor contribution. */ static bindToContribution(controllerGetter) { return class EditorControllerCommandImpl extends EditorCommand { constructor(opts) { super(opts); this._callback = opts.handler; } runEditorCommand(accessor, editor, args) { const controller = controllerGetter(editor); if (controller) { this._callback(controller, args); } } }; } runCommand(accessor, args) { const codeEditorService = accessor.get(ICodeEditorService); // Find the editor with text focus or active const editor = codeEditorService.getFocusedCodeEditor() || codeEditorService.getActiveCodeEditor(); if (!editor) { // well, at least we tried... return; } return editor.invokeWithinContext((editorAccessor) => { const kbService = editorAccessor.get(IContextKeyService); if (!kbService.contextMatchesRules(withNullAsUndefined(this.precondition))) { // precondition does not hold return; } return this.runEditorCommand(editorAccessor, editor, args); }); } } class EditorAction extends EditorCommand { constructor(opts) { super(EditorAction.convertOptions(opts)); this.label = opts.label; this.alias = opts.alias; } static convertOptions(opts) { let menuOpts; if (Array.isArray(opts.menuOpts)) { menuOpts = opts.menuOpts; } else if (opts.menuOpts) { menuOpts = [opts.menuOpts]; } else { menuOpts = []; } function withDefaults(item) { if (!item.menuId) { item.menuId = MenuId.EditorContext; } if (!item.title) { item.title = opts.label; } item.when = ContextKeyExpr.and(opts.precondition, item.when); return item; } if (Array.isArray(opts.contextMenuOpts)) { menuOpts.push(...opts.contextMenuOpts.map(withDefaults)); } else if (opts.contextMenuOpts) { menuOpts.push(withDefaults(opts.contextMenuOpts)); } opts.menuOpts = menuOpts; return opts; } runEditorCommand(accessor, editor, args) { this.reportTelemetry(accessor, editor); return this.run(accessor, editor, args || {}); } reportTelemetry(accessor, editor) { accessor.get(ITelemetryService).publicLog2('editorActionInvoked', { name: this.label, id: this.id }); } } class MultiEditorAction extends EditorAction { constructor() { super(...arguments); this._implementations = []; } /** * A higher priority gets to be looked at first */ addImplementation(priority, implementation) { this._implementations.push([priority, implementation]); this._implementations.sort((a, b) => b[0] - a[0]); return { dispose: () => { for (let i = 0; i < this._implementations.length; i++) { if (this._implementations[i][1] === implementation) { this._implementations.splice(i, 1); return; } } } }; } run(accessor, editor, args) { for (const impl of this._implementations) { const result = impl[1](accessor, editor, args); if (result) { if (typeof result === 'boolean') { return; } return result; } } } } //#endregion // --- Registration of commands and actions function registerModelAndPositionCommand(id, handler) { CommandsRegistry.registerCommand(id, function (accessor, ...args) { const [resource, position] = args; assertType(URI.isUri(resource)); assertType(Position$4.isIPosition(position)); const model = accessor.get(IModelService).getModel(resource); if (model) { const editorPosition = Position$4.lift(position); return handler(model, editorPosition, ...args.slice(2)); } return accessor.get(ITextModelService).createModelReference(resource).then(reference => { return new Promise((resolve, reject) => { try { const result = handler(reference.object.textEditorModel, Position$4.lift(position), args.slice(2)); resolve(result); } catch (err) { reject(err); } }).finally(() => { reference.dispose(); }); }); }); } function registerModelCommand(id, handler) { CommandsRegistry.registerCommand(id, function (accessor, ...args) { const [resource] = args; assertType(URI.isUri(resource)); const model = accessor.get(IModelService).getModel(resource); if (model) { return handler(model, ...args.slice(1)); } return accessor.get(ITextModelService).createModelReference(resource).then(reference => { return new Promise((resolve, reject) => { try { const result = handler(reference.object.textEditorModel, args.slice(1)); resolve(result); } catch (err) { reject(err); } }).finally(() => { reference.dispose(); }); }); }); } function registerEditorCommand(editorCommand) { EditorContributionRegistry.INSTANCE.registerEditorCommand(editorCommand); return editorCommand; } function registerEditorAction(ctor) { const action = new ctor(); EditorContributionRegistry.INSTANCE.registerEditorAction(action); return action; } function registerMultiEditorAction(action) { EditorContributionRegistry.INSTANCE.registerEditorAction(action); return action; } function registerInstantiatedEditorAction(editorAction) { EditorContributionRegistry.INSTANCE.registerEditorAction(editorAction); } function registerEditorContribution(id, ctor) { EditorContributionRegistry.INSTANCE.registerEditorContribution(id, ctor); } var EditorExtensionsRegistry; (function (EditorExtensionsRegistry) { function getEditorCommand(commandId) { return EditorContributionRegistry.INSTANCE.getEditorCommand(commandId); } EditorExtensionsRegistry.getEditorCommand = getEditorCommand; function getEditorActions() { return EditorContributionRegistry.INSTANCE.getEditorActions(); } EditorExtensionsRegistry.getEditorActions = getEditorActions; function getEditorContributions() { return EditorContributionRegistry.INSTANCE.getEditorContributions(); } EditorExtensionsRegistry.getEditorContributions = getEditorContributions; function getSomeEditorContributions(ids) { return EditorContributionRegistry.INSTANCE.getEditorContributions().filter(c => ids.indexOf(c.id) >= 0); } EditorExtensionsRegistry.getSomeEditorContributions = getSomeEditorContributions; function getDiffEditorContributions() { return EditorContributionRegistry.INSTANCE.getDiffEditorContributions(); } EditorExtensionsRegistry.getDiffEditorContributions = getDiffEditorContributions; })(EditorExtensionsRegistry || (EditorExtensionsRegistry = {})); // Editor extension points const Extensions$6 = { EditorCommonContributions: 'editor.contributions' }; class EditorContributionRegistry { constructor() { this.editorContributions = []; this.diffEditorContributions = []; this.editorActions = []; this.editorCommands = Object.create(null); } registerEditorContribution(id, ctor) { this.editorContributions.push({ id, ctor: ctor }); } getEditorContributions() { return this.editorContributions.slice(0); } getDiffEditorContributions() { return this.diffEditorContributions.slice(0); } registerEditorAction(action) { action.register(); this.editorActions.push(action); } getEditorActions() { return this.editorActions.slice(0); } registerEditorCommand(editorCommand) { editorCommand.register(); this.editorCommands[editorCommand.id] = editorCommand; } getEditorCommand(commandId) { return (this.editorCommands[commandId] || null); } } EditorContributionRegistry.INSTANCE = new EditorContributionRegistry(); Registry.add(Extensions$6.EditorCommonContributions, EditorContributionRegistry.INSTANCE); function registerCommand$3(command) { command.register(); return command; } const UndoCommand = registerCommand$3(new MultiCommand({ id: 'undo', precondition: undefined, kbOpts: { weight: 0 /* EditorCore */, primary: 2048 /* CtrlCmd */ | 56 /* KeyZ */ }, menuOpts: [{ menuId: MenuId.MenubarEditMenu, group: '1_do', title: localize({ key: 'miUndo', comment: ['&& denotes a mnemonic'] }, "&&Undo"), order: 1 }, { menuId: MenuId.CommandPalette, group: '', title: localize('undo', "Undo"), order: 1 }] })); registerCommand$3(new ProxyCommand(UndoCommand, { id: 'default:undo', precondition: undefined })); const RedoCommand = registerCommand$3(new MultiCommand({ id: 'redo', precondition: undefined, kbOpts: { weight: 0 /* EditorCore */, primary: 2048 /* CtrlCmd */ | 55 /* KeyY */, secondary: [2048 /* CtrlCmd */ | 1024 /* Shift */ | 56 /* KeyZ */], mac: { primary: 2048 /* CtrlCmd */ | 1024 /* Shift */ | 56 /* KeyZ */ } }, menuOpts: [{ menuId: MenuId.MenubarEditMenu, group: '1_do', title: localize({ key: 'miRedo', comment: ['&& denotes a mnemonic'] }, "&&Redo"), order: 2 }, { menuId: MenuId.CommandPalette, group: '', title: localize('redo', "Redo"), order: 1 }] })); registerCommand$3(new ProxyCommand(RedoCommand, { id: 'default:redo', precondition: undefined })); const SelectAllCommand = registerCommand$3(new MultiCommand({ id: 'editor.action.selectAll', precondition: undefined, kbOpts: { weight: 0 /* EditorCore */, kbExpr: null, primary: 2048 /* CtrlCmd */ | 31 /* KeyA */ }, menuOpts: [{ menuId: MenuId.MenubarSelectionMenu, group: '1_basic', title: localize({ key: 'miSelectAll', comment: ['&& denotes a mnemonic'] }, "&&Select All"), order: 1 }, { menuId: MenuId.CommandPalette, group: '', title: localize('selectAll', "Select All"), order: 1 }] })); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate$1D = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param$1x = (undefined && undefined.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; let MarkerDecorationsContribution = class MarkerDecorationsContribution { constructor(_editor, _markerDecorationsService) { // Doesn't do anything, just requires `IMarkerDecorationsService` to make sure it gets instantiated } dispose() { } }; MarkerDecorationsContribution.ID = 'editor.contrib.markerDecorations'; MarkerDecorationsContribution = __decorate$1D([ __param$1x(1, IMarkerDecorationsService) ], MarkerDecorationsContribution); registerEditorContribution(MarkerDecorationsContribution.ID, MarkerDecorationsContribution); var css$14 = "/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\n/* -------------------- IE10 remove auto clear button -------------------- */\n\n::-ms-clear {\n\tdisplay: none;\n}\n\n/* All widgets */\n/* I am not a big fan of this rule */\n.monaco-editor .editor-widget input {\n\tcolor: inherit;\n}\n\n/* -------------------- Editor -------------------- */\n\n.monaco-editor {\n\tposition: relative;\n\toverflow: visible;\n\t-webkit-text-size-adjust: 100%;\n}\n\n/* -------------------- Misc -------------------- */\n\n.monaco-editor .overflow-guard {\n\tposition: relative;\n\toverflow: hidden;\n}\n\n.monaco-editor .view-overlays {\n\tposition: absolute;\n\ttop: 0;\n}\n\n/*\n.monaco-editor .auto-closed-character {\n\topacity: 0.3;\n}\n*/\n"; n(css$14,{}); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class ElementSizeObserver extends Disposable { constructor(referenceDomElement, dimension) { super(); this._onDidChange = this._register(new Emitter$1()); this.onDidChange = this._onDidChange.event; this._referenceDomElement = referenceDomElement; this._width = -1; this._height = -1; this._resizeObserver = null; this.measureReferenceDomElement(false, dimension); } dispose() { this.stopObserving(); super.dispose(); } getWidth() { return this._width; } getHeight() { return this._height; } startObserving() { if (!this._resizeObserver && this._referenceDomElement) { this._resizeObserver = new ResizeObserver((entries) => { if (entries && entries[0] && entries[0].contentRect) { this.observe({ width: entries[0].contentRect.width, height: entries[0].contentRect.height }); } else { this.observe(); } }); this._resizeObserver.observe(this._referenceDomElement); } } stopObserving() { if (this._resizeObserver) { this._resizeObserver.disconnect(); this._resizeObserver = null; } } observe(dimension) { this.measureReferenceDomElement(true, dimension); } measureReferenceDomElement(emitEvent, dimension) { let observedWidth = 0; let observedHeight = 0; if (dimension) { observedWidth = dimension.width; observedHeight = dimension.height; } else if (this._referenceDomElement) { observedWidth = this._referenceDomElement.clientWidth; observedHeight = this._referenceDomElement.clientHeight; } observedWidth = Math.max(5, observedWidth); observedHeight = Math.max(5, observedHeight); if (this._width !== observedWidth || this._height !== observedHeight) { this._width = observedWidth; this._height = observedHeight; if (emitEvent) { this._onDidChange.fire(); } } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const hasOwnProperty$2 = Object.prototype.hasOwnProperty; /** * Iterates over each entry in the provided dictionary. The iterator allows * to remove elements and will stop when the callback returns {{false}}. */ function forEach(from, callback) { for (let key in from) { if (hasOwnProperty$2.call(from, key)) { const result = callback({ key: key, value: from[key] }, function () { delete from[key]; }); if (result === false) { return; } } } } class SetMap { constructor() { this.map = new Map(); } add(key, value) { let values = this.map.get(key); if (!values) { values = new Set(); this.map.set(key, values); } values.add(value); } delete(key, value) { const values = this.map.get(key); if (!values) { return; } values.delete(value); if (values.size === 0) { this.map.delete(key); } } forEach(key, fn) { const values = this.map.get(key); if (!values) { return; } values.forEach(fn); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Compatibility with old options */ function migrateOptions(options) { const wordWrap = options.wordWrap; if (wordWrap === true) { options.wordWrap = 'on'; } else if (wordWrap === false) { options.wordWrap = 'off'; } const lineNumbers = options.lineNumbers; if (lineNumbers === true) { options.lineNumbers = 'on'; } else if (lineNumbers === false) { options.lineNumbers = 'off'; } const autoClosingBrackets = options.autoClosingBrackets; if (autoClosingBrackets === false) { options.autoClosingBrackets = 'never'; options.autoClosingQuotes = 'never'; options.autoSurround = 'never'; } const cursorBlinking = options.cursorBlinking; if (cursorBlinking === 'visible') { options.cursorBlinking = 'solid'; } const renderWhitespace = options.renderWhitespace; if (renderWhitespace === true) { options.renderWhitespace = 'boundary'; } else if (renderWhitespace === false) { options.renderWhitespace = 'none'; } const renderLineHighlight = options.renderLineHighlight; if (renderLineHighlight === true) { options.renderLineHighlight = 'line'; } else if (renderLineHighlight === false) { options.renderLineHighlight = 'none'; } const acceptSuggestionOnEnter = options.acceptSuggestionOnEnter; if (acceptSuggestionOnEnter === true) { options.acceptSuggestionOnEnter = 'on'; } else if (acceptSuggestionOnEnter === false) { options.acceptSuggestionOnEnter = 'off'; } const tabCompletion = options.tabCompletion; if (tabCompletion === false) { options.tabCompletion = 'off'; } else if (tabCompletion === true) { options.tabCompletion = 'onlySnippets'; } const suggest = options.suggest; if (suggest && typeof suggest.filteredTypes === 'object' && suggest.filteredTypes) { const mapping = {}; mapping['method'] = 'showMethods'; mapping['function'] = 'showFunctions'; mapping['constructor'] = 'showConstructors'; mapping['deprecated'] = 'showDeprecated'; mapping['field'] = 'showFields'; mapping['variable'] = 'showVariables'; mapping['class'] = 'showClasses'; mapping['struct'] = 'showStructs'; mapping['interface'] = 'showInterfaces'; mapping['module'] = 'showModules'; mapping['property'] = 'showProperties'; mapping['event'] = 'showEvents'; mapping['operator'] = 'showOperators'; mapping['unit'] = 'showUnits'; mapping['value'] = 'showValues'; mapping['constant'] = 'showConstants'; mapping['enum'] = 'showEnums'; mapping['enumMember'] = 'showEnumMembers'; mapping['keyword'] = 'showKeywords'; mapping['text'] = 'showWords'; mapping['color'] = 'showColors'; mapping['file'] = 'showFiles'; mapping['reference'] = 'showReferences'; mapping['folder'] = 'showFolders'; mapping['typeParameter'] = 'showTypeParameters'; mapping['snippet'] = 'showSnippets'; forEach(mapping, entry => { const value = suggest.filteredTypes[entry.key]; if (value === false) { suggest[entry.value] = value; } }); // delete (suggest).filteredTypes; } const hover = options.hover; if (hover === true) { options.hover = { enabled: true }; } else if (hover === false) { options.hover = { enabled: false }; } const parameterHints = options.parameterHints; if (parameterHints === true) { options.parameterHints = { enabled: true }; } else if (parameterHints === false) { options.parameterHints = { enabled: false }; } const autoIndent = options.autoIndent; if (autoIndent === true) { options.autoIndent = 'full'; } else if (autoIndent === false) { options.autoIndent = 'advanced'; } const matchBrackets = options.matchBrackets; if (matchBrackets === true) { options.matchBrackets = 'always'; } else if (matchBrackets === false) { options.matchBrackets = 'never'; } const { renderIndentGuides, highlightActiveIndentGuide } = options; if (!options.guides) { options.guides = {}; } if (renderIndentGuides !== undefined) { options.guides.indentation = !!renderIndentGuides; } if (highlightActiveIndentGuide !== undefined) { options.guides.highlightActiveIndentation = !!highlightActiveIndentGuide; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class TabFocusImpl { constructor() { this._tabFocus = false; this._onDidChangeTabFocus = new Emitter$1(); this.onDidChangeTabFocus = this._onDidChangeTabFocus.event; } getTabFocusMode() { return this._tabFocus; } setTabFocusMode(tabFocusMode) { if (this._tabFocus === tabFocusMode) { return; } this._tabFocus = tabFocusMode; this._onDidChangeTabFocus.fire(this._tabFocus); } } /** * Control what pressing Tab does. * If it is false, pressing Tab or Shift-Tab will be handled by the editor. * If it is true, pressing Tab or Shift-Tab will move the browser focus. * Defaults to false. */ const TabFocus = new TabFocusImpl(); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const IAccessibilityService = createDecorator('accessibilityService'); const CONTEXT_ACCESSIBILITY_MODE_ENABLED = new RawContextKey('accessibilityModeEnabled', false); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate$1C = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param$1w = (undefined && undefined.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; let EditorConfiguration = class EditorConfiguration extends Disposable { constructor(isSimpleWidget, options, container, _accessibilityService) { super(); this._accessibilityService = _accessibilityService; this._onDidChange = this._register(new Emitter$1()); this.onDidChange = this._onDidChange.event; this._onDidChangeFast = this._register(new Emitter$1()); this.onDidChangeFast = this._onDidChangeFast.event; this._isDominatedByLongLines = false; this._viewLineCount = 1; this._lineNumbersDigitCount = 1; this._reservedHeight = 0; this._computeOptionsMemory = new ComputeOptionsMemory(); this.isSimpleWidget = isSimpleWidget; this._containerObserver = this._register(new ElementSizeObserver(container, options.dimension)); this._rawOptions = deepCloneAndMigrateOptions(options); this._validatedOptions = EditorOptionsUtil.validateOptions(this._rawOptions); this.options = this._computeOptions(); if (this.options.get(10 /* automaticLayout */)) { this._containerObserver.startObserving(); } this._register(EditorZoom.onDidChangeZoomLevel(() => this._recomputeOptions())); this._register(TabFocus.onDidChangeTabFocus(() => this._recomputeOptions())); this._register(this._containerObserver.onDidChange(() => this._recomputeOptions())); this._register(FontMeasurements.onDidChange(() => this._recomputeOptions())); this._register(PixelRatio.onDidChange(() => this._recomputeOptions())); this._register(this._accessibilityService.onDidChangeScreenReaderOptimized(() => this._recomputeOptions())); } _recomputeOptions() { const newOptions = this._computeOptions(); const changeEvent = EditorOptionsUtil.checkEquals(this.options, newOptions); if (changeEvent === null) { // nothing changed! return; } this.options = newOptions; this._onDidChangeFast.fire(changeEvent); this._onDidChange.fire(changeEvent); } _computeOptions() { const partialEnv = this._readEnvConfiguration(); const bareFontInfo = BareFontInfo.createFromValidatedSettings(this._validatedOptions, partialEnv.pixelRatio, this.isSimpleWidget); const fontInfo = this._readFontInfo(bareFontInfo); const env = { memory: this._computeOptionsMemory, outerWidth: partialEnv.outerWidth, outerHeight: partialEnv.outerHeight - this._reservedHeight, fontInfo: fontInfo, extraEditorClassName: partialEnv.extraEditorClassName, isDominatedByLongLines: this._isDominatedByLongLines, viewLineCount: this._viewLineCount, lineNumbersDigitCount: this._lineNumbersDigitCount, emptySelectionClipboard: partialEnv.emptySelectionClipboard, pixelRatio: partialEnv.pixelRatio, tabFocusMode: TabFocus.getTabFocusMode(), accessibilitySupport: partialEnv.accessibilitySupport }; return EditorOptionsUtil.computeOptions(this._validatedOptions, env); } _readEnvConfiguration() { return { extraEditorClassName: getExtraEditorClassName(), outerWidth: this._containerObserver.getWidth(), outerHeight: this._containerObserver.getHeight(), emptySelectionClipboard: isWebKit || isFirefox, pixelRatio: PixelRatio.value, accessibilitySupport: (this._accessibilityService.isScreenReaderOptimized() ? 2 /* Enabled */ : this._accessibilityService.getAccessibilitySupport()) }; } _readFontInfo(bareFontInfo) { return FontMeasurements.readFontInfo(bareFontInfo); } getRawOptions() { return this._rawOptions; } updateOptions(_newOptions) { const newOptions = deepCloneAndMigrateOptions(_newOptions); const didChange = EditorOptionsUtil.applyUpdate(this._rawOptions, newOptions); if (!didChange) { return; } this._validatedOptions = EditorOptionsUtil.validateOptions(this._rawOptions); this._recomputeOptions(); } observeContainer(dimension) { this._containerObserver.observe(dimension); } setIsDominatedByLongLines(isDominatedByLongLines) { if (this._isDominatedByLongLines === isDominatedByLongLines) { return; } this._isDominatedByLongLines = isDominatedByLongLines; this._recomputeOptions(); } setModelLineCount(modelLineCount) { const lineNumbersDigitCount = digitCount(modelLineCount); if (this._lineNumbersDigitCount === lineNumbersDigitCount) { return; } this._lineNumbersDigitCount = lineNumbersDigitCount; this._recomputeOptions(); } setViewLineCount(viewLineCount) { if (this._viewLineCount === viewLineCount) { return; } this._viewLineCount = viewLineCount; this._recomputeOptions(); } setReservedHeight(reservedHeight) { if (this._reservedHeight === reservedHeight) { return; } this._reservedHeight = reservedHeight; this._recomputeOptions(); } }; EditorConfiguration = __decorate$1C([ __param$1w(3, IAccessibilityService) ], EditorConfiguration); function digitCount(n) { let r = 0; while (n) { n = Math.floor(n / 10); r++; } return r ? r : 1; } function getExtraEditorClassName() { let extra = ''; if (!isSafari && !isWebkitWebView) { // Use user-select: none in all browsers except Safari and native macOS WebView extra += 'no-user-select '; } if (isSafari) { // See https://github.com/microsoft/vscode/issues/108822 extra += 'no-minimap-shadow '; } if (isMacintosh) { extra += 'mac '; } return extra; } class ValidatedEditorOptions { constructor() { this._values = []; } _read(option) { return this._values[option]; } get(id) { return this._values[id]; } _write(option, value) { this._values[option] = value; } } class ComputedEditorOptions { constructor() { this._values = []; } _read(id) { if (id >= this._values.length) { throw new Error('Cannot read uninitialized value'); } return this._values[id]; } get(id) { return this._read(id); } _write(id, value) { this._values[id] = value; } } class EditorOptionsUtil { static validateOptions(options) { const result = new ValidatedEditorOptions(); for (const editorOption of editorOptionsRegistry) { const value = (editorOption.name === '_never_' ? undefined : options[editorOption.name]); result._write(editorOption.id, editorOption.validate(value)); } return result; } static computeOptions(options, env) { const result = new ComputedEditorOptions(); for (const editorOption of editorOptionsRegistry) { result._write(editorOption.id, editorOption.compute(env, result, options._read(editorOption.id))); } return result; } static _deepEquals(a, b) { if (typeof a !== 'object' || typeof b !== 'object' || !a || !b) { return a === b; } if (Array.isArray(a) || Array.isArray(b)) { return (Array.isArray(a) && Array.isArray(b) ? equals$1(a, b) : false); } if (Object.keys(a).length !== Object.keys(b).length) { return false; } for (const key in a) { if (!EditorOptionsUtil._deepEquals(a[key], b[key])) { return false; } } return true; } static checkEquals(a, b) { const result = []; let somethingChanged = false; for (const editorOption of editorOptionsRegistry) { const changed = !EditorOptionsUtil._deepEquals(a._read(editorOption.id), b._read(editorOption.id)); result[editorOption.id] = changed; if (changed) { somethingChanged = true; } } return (somethingChanged ? new ConfigurationChangedEvent(result) : null); } /** * Returns true if something changed. * Modifies `options`. */ static applyUpdate(options, update) { let changed = false; for (const editorOption of editorOptionsRegistry) { if (update.hasOwnProperty(editorOption.name)) { const result = editorOption.applyUpdate(options[editorOption.name], update[editorOption.name]); options[editorOption.name] = result.newValue; changed = changed || result.didChange; } } return changed; } } function deepCloneAndMigrateOptions(_options) { const options = deepClone(_options); migrateOptions(options); return options; } function memoize(_target, key, descriptor) { let fnKey = null; let fn = null; if (typeof descriptor.value === 'function') { fnKey = 'value'; fn = descriptor.value; if (fn.length !== 0) { console.warn('Memoize should only be used in functions with zero parameters'); } } else if (typeof descriptor.get === 'function') { fnKey = 'get'; fn = descriptor.get; } if (!fn) { throw new Error('not supported'); } const memoizeKey = `$memoize$${key}`; descriptor[fnKey] = function (...args) { if (!this.hasOwnProperty(memoizeKey)) { Object.defineProperty(this, memoizeKey, { configurable: false, enumerable: false, writable: false, value: fn.apply(this, args) }); } return this[memoizeKey]; }; } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate$1B = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var EventType; (function (EventType) { EventType.Tap = '-monaco-gesturetap'; EventType.Change = '-monaco-gesturechange'; EventType.Start = '-monaco-gesturestart'; EventType.End = '-monaco-gesturesend'; EventType.Contextmenu = '-monaco-gesturecontextmenu'; })(EventType || (EventType = {})); class Gesture extends Disposable { constructor() { super(); this.dispatched = false; this.activeTouches = {}; this.handle = null; this.targets = []; this.ignoreTargets = []; this._lastSetTapCountTime = 0; this._register(addDisposableListener(document, 'touchstart', (e) => this.onTouchStart(e), { passive: false })); this._register(addDisposableListener(document, 'touchend', (e) => this.onTouchEnd(e))); this._register(addDisposableListener(document, 'touchmove', (e) => this.onTouchMove(e), { passive: false })); } static addTarget(element) { if (!Gesture.isTouchDevice()) { return Disposable.None; } if (!Gesture.INSTANCE) { Gesture.INSTANCE = new Gesture(); } Gesture.INSTANCE.targets.push(element); return { dispose: () => { Gesture.INSTANCE.targets = Gesture.INSTANCE.targets.filter(t => t !== element); } }; } static ignoreTarget(element) { if (!Gesture.isTouchDevice()) { return Disposable.None; } if (!Gesture.INSTANCE) { Gesture.INSTANCE = new Gesture(); } Gesture.INSTANCE.ignoreTargets.push(element); return { dispose: () => { Gesture.INSTANCE.ignoreTargets = Gesture.INSTANCE.ignoreTargets.filter(t => t !== element); } }; } static isTouchDevice() { // `'ontouchstart' in window` always evaluates to true with typescript's modern typings. This causes `window` to be // `never` later in `window.navigator`. That's why we need the explicit `window as Window` cast return 'ontouchstart' in window || navigator.maxTouchPoints > 0; } dispose() { if (this.handle) { this.handle.dispose(); this.handle = null; } super.dispose(); } onTouchStart(e) { let timestamp = Date.now(); // use Date.now() because on FF e.timeStamp is not epoch based. if (this.handle) { this.handle.dispose(); this.handle = null; } for (let i = 0, len = e.targetTouches.length; i < len; i++) { let touch = e.targetTouches.item(i); this.activeTouches[touch.identifier] = { id: touch.identifier, initialTarget: touch.target, initialTimeStamp: timestamp, initialPageX: touch.pageX, initialPageY: touch.pageY, rollingTimestamps: [timestamp], rollingPageX: [touch.pageX], rollingPageY: [touch.pageY] }; let evt = this.newGestureEvent(EventType.Start, touch.target); evt.pageX = touch.pageX; evt.pageY = touch.pageY; this.dispatchEvent(evt); } if (this.dispatched) { e.preventDefault(); e.stopPropagation(); this.dispatched = false; } } onTouchEnd(e) { let timestamp = Date.now(); // use Date.now() because on FF e.timeStamp is not epoch based. let activeTouchCount = Object.keys(this.activeTouches).length; for (let i = 0, len = e.changedTouches.length; i < len; i++) { let touch = e.changedTouches.item(i); if (!this.activeTouches.hasOwnProperty(String(touch.identifier))) { console.warn('move of an UNKNOWN touch', touch); continue; } let data = this.activeTouches[touch.identifier], holdTime = Date.now() - data.initialTimeStamp; if (holdTime < Gesture.HOLD_DELAY && Math.abs(data.initialPageX - tail(data.rollingPageX)) < 30 && Math.abs(data.initialPageY - tail(data.rollingPageY)) < 30) { let evt = this.newGestureEvent(EventType.Tap, data.initialTarget); evt.pageX = tail(data.rollingPageX); evt.pageY = tail(data.rollingPageY); this.dispatchEvent(evt); } else if (holdTime >= Gesture.HOLD_DELAY && Math.abs(data.initialPageX - tail(data.rollingPageX)) < 30 && Math.abs(data.initialPageY - tail(data.rollingPageY)) < 30) { let evt = this.newGestureEvent(EventType.Contextmenu, data.initialTarget); evt.pageX = tail(data.rollingPageX); evt.pageY = tail(data.rollingPageY); this.dispatchEvent(evt); } else if (activeTouchCount === 1) { let finalX = tail(data.rollingPageX); let finalY = tail(data.rollingPageY); let deltaT = tail(data.rollingTimestamps) - data.rollingTimestamps[0]; let deltaX = finalX - data.rollingPageX[0]; let deltaY = finalY - data.rollingPageY[0]; // We need to get all the dispatch targets on the start of the inertia event const dispatchTo = this.targets.filter(t => data.initialTarget instanceof Node && t.contains(data.initialTarget)); this.inertia(dispatchTo, timestamp, // time now Math.abs(deltaX) / deltaT, // speed deltaX > 0 ? 1 : -1, // x direction finalX, // x now Math.abs(deltaY) / deltaT, // y speed deltaY > 0 ? 1 : -1, // y direction finalY // y now ); } this.dispatchEvent(this.newGestureEvent(EventType.End, data.initialTarget)); // forget about this touch delete this.activeTouches[touch.identifier]; } if (this.dispatched) { e.preventDefault(); e.stopPropagation(); this.dispatched = false; } } newGestureEvent(type, initialTarget) { let event = document.createEvent('CustomEvent'); event.initEvent(type, false, true); event.initialTarget = initialTarget; event.tapCount = 0; return event; } dispatchEvent(event) { if (event.type === EventType.Tap) { const currentTime = (new Date()).getTime(); let setTapCount = 0; if (currentTime - this._lastSetTapCountTime > Gesture.CLEAR_TAP_COUNT_TIME) { setTapCount = 1; } else { setTapCount = 2; } this._lastSetTapCountTime = currentTime; event.tapCount = setTapCount; } else if (event.type === EventType.Change || event.type === EventType.Contextmenu) { // tap is canceled by scrolling or context menu this._lastSetTapCountTime = 0; } for (let i = 0; i < this.ignoreTargets.length; i++) { if (event.initialTarget instanceof Node && this.ignoreTargets[i].contains(event.initialTarget)) { return; } } this.targets.forEach(target => { if (event.initialTarget instanceof Node && target.contains(event.initialTarget)) { target.dispatchEvent(event); this.dispatched = true; } }); } inertia(dispatchTo, t1, vX, dirX, x, vY, dirY, y) { this.handle = scheduleAtNextAnimationFrame(() => { let now = Date.now(); // velocity: old speed + accel_over_time let deltaT = now - t1, delta_pos_x = 0, delta_pos_y = 0, stopped = true; vX += Gesture.SCROLL_FRICTION * deltaT; vY += Gesture.SCROLL_FRICTION * deltaT; if (vX > 0) { stopped = false; delta_pos_x = dirX * vX * deltaT; } if (vY > 0) { stopped = false; delta_pos_y = dirY * vY * deltaT; } // dispatch translation event let evt = this.newGestureEvent(EventType.Change); evt.translationX = delta_pos_x; evt.translationY = delta_pos_y; dispatchTo.forEach(d => d.dispatchEvent(evt)); if (!stopped) { this.inertia(dispatchTo, now, vX, dirX, x + delta_pos_x, vY, dirY, y + delta_pos_y); } }); } onTouchMove(e) { let timestamp = Date.now(); // use Date.now() because on FF e.timeStamp is not epoch based. for (let i = 0, len = e.changedTouches.length; i < len; i++) { let touch = e.changedTouches.item(i); if (!this.activeTouches.hasOwnProperty(String(touch.identifier))) { console.warn('end of an UNKNOWN touch', touch); continue; } let data = this.activeTouches[touch.identifier]; let evt = this.newGestureEvent(EventType.Change, data.initialTarget); evt.translationX = touch.pageX - tail(data.rollingPageX); evt.translationY = touch.pageY - tail(data.rollingPageY); evt.pageX = touch.pageX; evt.pageY = touch.pageY; this.dispatchEvent(evt); // only keep a few data points, to average the final speed if (data.rollingPageX.length > 3) { data.rollingPageX.shift(); data.rollingPageY.shift(); data.rollingTimestamps.shift(); } data.rollingPageX.push(touch.pageX); data.rollingPageY.push(touch.pageY); data.rollingTimestamps.push(timestamp); } if (this.dispatched) { e.preventDefault(); e.stopPropagation(); this.dispatched = false; } } } Gesture.SCROLL_FRICTION = -0.005; Gesture.HOLD_DELAY = 700; Gesture.CLEAR_TAP_COUNT_TIME = 400; // ms __decorate$1B([ memoize ], Gesture, "isTouchDevice", null); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function standardMouseMoveMerger(lastEvent, currentEvent) { let ev = new StandardMouseEvent(currentEvent); ev.preventDefault(); return { leftButton: ev.leftButton, buttons: ev.buttons, posx: ev.posx, posy: ev.posy }; } class GlobalMouseMoveMonitor { constructor() { this._hooks = new DisposableStore(); this._mouseMoveEventMerger = null; this._mouseMoveCallback = null; this._onStopCallback = null; } dispose() { this.stopMonitoring(false); this._hooks.dispose(); } stopMonitoring(invokeStopCallback, browserEvent) { if (!this.isMonitoring()) { // Not monitoring return; } // Unhook this._hooks.clear(); this._mouseMoveEventMerger = null; this._mouseMoveCallback = null; const onStopCallback = this._onStopCallback; this._onStopCallback = null; if (invokeStopCallback && onStopCallback) { onStopCallback(browserEvent); } } isMonitoring() { return !!this._mouseMoveEventMerger; } startMonitoring(initialElement, initialButtons, mouseMoveEventMerger, mouseMoveCallback, onStopCallback) { if (this.isMonitoring()) { // I am already hooked return; } this._mouseMoveEventMerger = mouseMoveEventMerger; this._mouseMoveCallback = mouseMoveCallback; this._onStopCallback = onStopCallback; const windowChain = IframeUtils.getSameOriginWindowChain(); const mouseMove = isIOS ? 'pointermove' : 'mousemove'; // Safari sends wrong event, workaround for #122653 const mouseUp = 'mouseup'; const listenTo = windowChain.map(element => element.window.document); const shadowRoot = getShadowRoot(initialElement); if (shadowRoot) { listenTo.unshift(shadowRoot); } for (const element of listenTo) { this._hooks.add(addDisposableThrottledListener(element, mouseMove, (data) => { if (data.buttons !== initialButtons) { // Buttons state has changed in the meantime this.stopMonitoring(true); return; } this._mouseMoveCallback(data); }, (lastEvent, currentEvent) => this._mouseMoveEventMerger(lastEvent, currentEvent))); this._hooks.add(addDisposableListener(element, mouseUp, (e) => this.stopMonitoring(true))); } if (IframeUtils.hasDifferentOriginAncestor()) { let lastSameOriginAncestor = windowChain[windowChain.length - 1]; // We might miss a mouse up if it happens outside the iframe // This one is for Chrome this._hooks.add(addDisposableListener(lastSameOriginAncestor.window.document, 'mouseout', (browserEvent) => { let e = new StandardMouseEvent(browserEvent); if (e.target.tagName.toLowerCase() === 'html') { this.stopMonitoring(true); } })); // This one is for FF this._hooks.add(addDisposableListener(lastSameOriginAncestor.window.document, 'mouseover', (browserEvent) => { let e = new StandardMouseEvent(browserEvent); if (e.target.tagName.toLowerCase() === 'html') { this.stopMonitoring(true); } })); // This one is for IE this._hooks.add(addDisposableListener(lastSameOriginAncestor.window.document.body, 'mouseleave', (browserEvent) => { this.stopMonitoring(true); })); } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ function roundFloat(number, decimalPoints) { const decimal = Math.pow(10, decimalPoints); return Math.round(number * decimal) / decimal; } class RGBA { constructor(r, g, b, a = 1) { this._rgbaBrand = undefined; this.r = Math.min(255, Math.max(0, r)) | 0; this.g = Math.min(255, Math.max(0, g)) | 0; this.b = Math.min(255, Math.max(0, b)) | 0; this.a = roundFloat(Math.max(Math.min(1, a), 0), 3); } static equals(a, b) { return a.r === b.r && a.g === b.g && a.b === b.b && a.a === b.a; } } class HSLA { constructor(h, s, l, a) { this._hslaBrand = undefined; this.h = Math.max(Math.min(360, h), 0) | 0; this.s = roundFloat(Math.max(Math.min(1, s), 0), 3); this.l = roundFloat(Math.max(Math.min(1, l), 0), 3); this.a = roundFloat(Math.max(Math.min(1, a), 0), 3); } static equals(a, b) { return a.h === b.h && a.s === b.s && a.l === b.l && a.a === b.a; } /** * Converts an RGB color value to HSL. Conversion formula * adapted from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes r, g, and b are contained in the set [0, 255] and * returns h in the set [0, 360], s, and l in the set [0, 1]. */ static fromRGBA(rgba) { const r = rgba.r / 255; const g = rgba.g / 255; const b = rgba.b / 255; const a = rgba.a; const max = Math.max(r, g, b); const min = Math.min(r, g, b); let h = 0; let s = 0; const l = (min + max) / 2; const chroma = max - min; if (chroma > 0) { s = Math.min((l <= 0.5 ? chroma / (2 * l) : chroma / (2 - (2 * l))), 1); switch (max) { case r: h = (g - b) / chroma + (g < b ? 6 : 0); break; case g: h = (b - r) / chroma + 2; break; case b: h = (r - g) / chroma + 4; break; } h *= 60; h = Math.round(h); } return new HSLA(h, s, l, a); } static _hue2rgb(p, q, t) { if (t < 0) { t += 1; } if (t > 1) { t -= 1; } if (t < 1 / 6) { return p + (q - p) * 6 * t; } if (t < 1 / 2) { return q; } if (t < 2 / 3) { return p + (q - p) * (2 / 3 - t) * 6; } return p; } /** * Converts an HSL color value to RGB. Conversion formula * adapted from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes h in the set [0, 360] s, and l are contained in the set [0, 1] and * returns r, g, and b in the set [0, 255]. */ static toRGBA(hsla) { const h = hsla.h / 360; const { s, l, a } = hsla; let r, g, b; if (s === 0) { r = g = b = l; // achromatic } else { const q = l < 0.5 ? l * (1 + s) : l + s - l * s; const p = 2 * l - q; r = HSLA._hue2rgb(p, q, h + 1 / 3); g = HSLA._hue2rgb(p, q, h); b = HSLA._hue2rgb(p, q, h - 1 / 3); } return new RGBA(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a); } } class HSVA { constructor(h, s, v, a) { this._hsvaBrand = undefined; this.h = Math.max(Math.min(360, h), 0) | 0; this.s = roundFloat(Math.max(Math.min(1, s), 0), 3); this.v = roundFloat(Math.max(Math.min(1, v), 0), 3); this.a = roundFloat(Math.max(Math.min(1, a), 0), 3); } static equals(a, b) { return a.h === b.h && a.s === b.s && a.v === b.v && a.a === b.a; } // from http://www.rapidtables.com/convert/color/rgb-to-hsv.htm static fromRGBA(rgba) { const r = rgba.r / 255; const g = rgba.g / 255; const b = rgba.b / 255; const cmax = Math.max(r, g, b); const cmin = Math.min(r, g, b); const delta = cmax - cmin; const s = cmax === 0 ? 0 : (delta / cmax); let m; if (delta === 0) { m = 0; } else if (cmax === r) { m = ((((g - b) / delta) % 6) + 6) % 6; } else if (cmax === g) { m = ((b - r) / delta) + 2; } else { m = ((r - g) / delta) + 4; } return new HSVA(Math.round(m * 60), s, cmax, rgba.a); } // from http://www.rapidtables.com/convert/color/hsv-to-rgb.htm static toRGBA(hsva) { const { h, s, v, a } = hsva; const c = v * s; const x = c * (1 - Math.abs((h / 60) % 2 - 1)); const m = v - c; let [r, g, b] = [0, 0, 0]; if (h < 60) { r = c; g = x; } else if (h < 120) { r = x; g = c; } else if (h < 180) { g = c; b = x; } else if (h < 240) { g = x; b = c; } else if (h < 300) { r = x; b = c; } else if (h <= 360) { r = c; b = x; } r = Math.round((r + m) * 255); g = Math.round((g + m) * 255); b = Math.round((b + m) * 255); return new RGBA(r, g, b, a); } } class Color$3 { constructor(arg) { if (!arg) { throw new Error('Color needs a value'); } else if (arg instanceof RGBA) { this.rgba = arg; } else if (arg instanceof HSLA) { this._hsla = arg; this.rgba = HSLA.toRGBA(arg); } else if (arg instanceof HSVA) { this._hsva = arg; this.rgba = HSVA.toRGBA(arg); } else { throw new Error('Invalid color ctor argument'); } } static fromHex(hex) { return Color$3.Format.CSS.parseHex(hex) || Color$3.red; } get hsla() { if (this._hsla) { return this._hsla; } else { return HSLA.fromRGBA(this.rgba); } } get hsva() { if (this._hsva) { return this._hsva; } return HSVA.fromRGBA(this.rgba); } equals(other) { return !!other && RGBA.equals(this.rgba, other.rgba) && HSLA.equals(this.hsla, other.hsla) && HSVA.equals(this.hsva, other.hsva); } /** * http://www.w3.org/TR/WCAG20/#relativeluminancedef * Returns the number in the set [0, 1]. O => Darkest Black. 1 => Lightest white. */ getRelativeLuminance() { const R = Color$3._relativeLuminanceForComponent(this.rgba.r); const G = Color$3._relativeLuminanceForComponent(this.rgba.g); const B = Color$3._relativeLuminanceForComponent(this.rgba.b); const luminance = 0.2126 * R + 0.7152 * G + 0.0722 * B; return roundFloat(luminance, 4); } static _relativeLuminanceForComponent(color) { const c = color / 255; return (c <= 0.03928) ? c / 12.92 : Math.pow(((c + 0.055) / 1.055), 2.4); } /** * http://24ways.org/2010/calculating-color-contrast * Return 'true' if lighter color otherwise 'false' */ isLighter() { const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000; return yiq >= 128; } isLighterThan(another) { const lum1 = this.getRelativeLuminance(); const lum2 = another.getRelativeLuminance(); return lum1 > lum2; } isDarkerThan(another) { const lum1 = this.getRelativeLuminance(); const lum2 = another.getRelativeLuminance(); return lum1 < lum2; } lighten(factor) { return new Color$3(new HSLA(this.hsla.h, this.hsla.s, this.hsla.l + this.hsla.l * factor, this.hsla.a)); } darken(factor) { return new Color$3(new HSLA(this.hsla.h, this.hsla.s, this.hsla.l - this.hsla.l * factor, this.hsla.a)); } transparent(factor) { const { r, g, b, a } = this.rgba; return new Color$3(new RGBA(r, g, b, a * factor)); } isTransparent() { return this.rgba.a === 0; } isOpaque() { return this.rgba.a === 1; } opposite() { return new Color$3(new RGBA(255 - this.rgba.r, 255 - this.rgba.g, 255 - this.rgba.b, this.rgba.a)); } toString() { if (!this._toString) { this._toString = Color$3.Format.CSS.format(this); } return this._toString; } static getLighterColor(of, relative, factor) { if (of.isLighterThan(relative)) { return of; } factor = factor ? factor : 0.5; const lum1 = of.getRelativeLuminance(); const lum2 = relative.getRelativeLuminance(); factor = factor * (lum2 - lum1) / lum2; return of.lighten(factor); } static getDarkerColor(of, relative, factor) { if (of.isDarkerThan(relative)) { return of; } factor = factor ? factor : 0.5; const lum1 = of.getRelativeLuminance(); const lum2 = relative.getRelativeLuminance(); factor = factor * (lum1 - lum2) / lum1; return of.darken(factor); } } Color$3.white = new Color$3(new RGBA(255, 255, 255, 1)); Color$3.black = new Color$3(new RGBA(0, 0, 0, 1)); Color$3.red = new Color$3(new RGBA(255, 0, 0, 1)); Color$3.blue = new Color$3(new RGBA(0, 0, 255, 1)); Color$3.green = new Color$3(new RGBA(0, 255, 0, 1)); Color$3.cyan = new Color$3(new RGBA(0, 255, 255, 1)); Color$3.lightgrey = new Color$3(new RGBA(211, 211, 211, 1)); Color$3.transparent = new Color$3(new RGBA(0, 0, 0, 0)); (function (Color) { (function (Format) { (function (CSS) { function formatRGB(color) { if (color.rgba.a === 1) { return `rgb(${color.rgba.r}, ${color.rgba.g}, ${color.rgba.b})`; } return Color.Format.CSS.formatRGBA(color); } CSS.formatRGB = formatRGB; function formatRGBA(color) { return `rgba(${color.rgba.r}, ${color.rgba.g}, ${color.rgba.b}, ${+(color.rgba.a).toFixed(2)})`; } CSS.formatRGBA = formatRGBA; function formatHSL(color) { if (color.hsla.a === 1) { return `hsl(${color.hsla.h}, ${(color.hsla.s * 100).toFixed(2)}%, ${(color.hsla.l * 100).toFixed(2)}%)`; } return Color.Format.CSS.formatHSLA(color); } CSS.formatHSL = formatHSL; function formatHSLA(color) { return `hsla(${color.hsla.h}, ${(color.hsla.s * 100).toFixed(2)}%, ${(color.hsla.l * 100).toFixed(2)}%, ${color.hsla.a.toFixed(2)})`; } CSS.formatHSLA = formatHSLA; function _toTwoDigitHex(n) { const r = n.toString(16); return r.length !== 2 ? '0' + r : r; } /** * Formats the color as #RRGGBB */ function formatHex(color) { return `#${_toTwoDigitHex(color.rgba.r)}${_toTwoDigitHex(color.rgba.g)}${_toTwoDigitHex(color.rgba.b)}`; } CSS.formatHex = formatHex; /** * Formats the color as #RRGGBBAA * If 'compact' is set, colors without transparancy will be printed as #RRGGBB */ function formatHexA(color, compact = false) { if (compact && color.rgba.a === 1) { return Color.Format.CSS.formatHex(color); } return `#${_toTwoDigitHex(color.rgba.r)}${_toTwoDigitHex(color.rgba.g)}${_toTwoDigitHex(color.rgba.b)}${_toTwoDigitHex(Math.round(color.rgba.a * 255))}`; } CSS.formatHexA = formatHexA; /** * The default format will use HEX if opaque and RGBA otherwise. */ function format(color) { if (color.isOpaque()) { return Color.Format.CSS.formatHex(color); } return Color.Format.CSS.formatRGBA(color); } CSS.format = format; /** * Converts an Hex color value to a Color. * returns r, g, and b are contained in the set [0, 255] * @param hex string (#RGB, #RGBA, #RRGGBB or #RRGGBBAA). */ function parseHex(hex) { const length = hex.length; if (length === 0) { // Invalid color return null; } if (hex.charCodeAt(0) !== 35 /* Hash */) { // Does not begin with a # return null; } if (length === 7) { // #RRGGBB format const r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2)); const g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4)); const b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6)); return new Color(new RGBA(r, g, b, 1)); } if (length === 9) { // #RRGGBBAA format const r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2)); const g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4)); const b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6)); const a = 16 * _parseHexDigit(hex.charCodeAt(7)) + _parseHexDigit(hex.charCodeAt(8)); return new Color(new RGBA(r, g, b, a / 255)); } if (length === 4) { // #RGB format const r = _parseHexDigit(hex.charCodeAt(1)); const g = _parseHexDigit(hex.charCodeAt(2)); const b = _parseHexDigit(hex.charCodeAt(3)); return new Color(new RGBA(16 * r + r, 16 * g + g, 16 * b + b)); } if (length === 5) { // #RGBA format const r = _parseHexDigit(hex.charCodeAt(1)); const g = _parseHexDigit(hex.charCodeAt(2)); const b = _parseHexDigit(hex.charCodeAt(3)); const a = _parseHexDigit(hex.charCodeAt(4)); return new Color(new RGBA(16 * r + r, 16 * g + g, 16 * b + b, (16 * a + a) / 255)); } // Invalid color return null; } CSS.parseHex = parseHex; function _parseHexDigit(charCode) { switch (charCode) { case 48 /* Digit0 */: return 0; case 49 /* Digit1 */: return 1; case 50 /* Digit2 */: return 2; case 51 /* Digit3 */: return 3; case 52 /* Digit4 */: return 4; case 53 /* Digit5 */: return 5; case 54 /* Digit6 */: return 6; case 55 /* Digit7 */: return 7; case 56 /* Digit8 */: return 8; case 57 /* Digit9 */: return 9; case 97 /* a */: return 10; case 65 /* A */: return 10; case 98 /* b */: return 11; case 66 /* B */: return 11; case 99 /* c */: return 12; case 67 /* C */: return 12; case 100 /* d */: return 13; case 68 /* D */: return 13; case 101 /* e */: return 14; case 69 /* E */: return 14; case 102 /* f */: return 15; case 70 /* F */: return 15; } return 0; } })(Format.CSS || (Format.CSS = {})); })(Color.Format || (Color.Format = {})); })(Color$3 || (Color$3 = {})); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const Extensions$5 = { JSONContribution: 'base.contributions.json' }; function normalizeId(id) { if (id.length > 0 && id.charAt(id.length - 1) === '#') { return id.substring(0, id.length - 1); } return id; } class JSONContributionRegistry { constructor() { this._onDidChangeSchema = new Emitter$1(); this.schemasById = {}; } registerSchema(uri, unresolvedSchemaContent) { this.schemasById[normalizeId(uri)] = unresolvedSchemaContent; this._onDidChangeSchema.fire(uri); } notifySchemaChanged(uri) { this._onDidChangeSchema.fire(uri); } } const jsonContributionRegistry = new JSONContributionRegistry(); Registry.add(Extensions$5.JSONContribution, jsonContributionRegistry); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Returns the css variable name for the given color identifier. Dots (`.`) are replaced with hyphens (`-`) and * everything is prefixed with `--vscode-`. * * @sample `editorSuggestWidget.background` is `--vscode-editorSuggestWidget-background`. */ function asCssVariableName(colorIdent) { return `--vscode-${colorIdent.replace('.', '-')}`; } // color registry const Extensions$4 = { ColorContribution: 'base.contributions.colors' }; class ColorRegistry { constructor() { this._onDidChangeSchema = new Emitter$1(); this.onDidChangeSchema = this._onDidChangeSchema.event; this.colorSchema = { type: 'object', properties: {} }; this.colorReferenceSchema = { type: 'string', enum: [], enumDescriptions: [] }; this.colorsById = {}; } registerColor(id, defaults, description, needsTransparency = false, deprecationMessage) { let colorContribution = { id, description, defaults, needsTransparency, deprecationMessage }; this.colorsById[id] = colorContribution; let propertySchema = { type: 'string', description, format: 'color-hex', defaultSnippets: [{ body: '${1:#ff0000}' }] }; if (deprecationMessage) { propertySchema.deprecationMessage = deprecationMessage; } this.colorSchema.properties[id] = propertySchema; this.colorReferenceSchema.enum.push(id); this.colorReferenceSchema.enumDescriptions.push(description); this._onDidChangeSchema.fire(); return id; } getColors() { return Object.keys(this.colorsById).map(id => this.colorsById[id]); } resolveDefaultColor(id, theme) { const colorDesc = this.colorsById[id]; if (colorDesc && colorDesc.defaults) { const colorValue = colorDesc.defaults[theme.type]; return resolveColorValue(colorValue, theme); } return undefined; } getColorSchema() { return this.colorSchema; } toString() { let sorter = (a, b) => { let cat1 = a.indexOf('.') === -1 ? 0 : 1; let cat2 = b.indexOf('.') === -1 ? 0 : 1; if (cat1 !== cat2) { return cat1 - cat2; } return a.localeCompare(b); }; return Object.keys(this.colorsById).sort(sorter).map(k => `- \`${k}\`: ${this.colorsById[k].description}`).join('\n'); } } const colorRegistry$1 = new ColorRegistry(); Registry.add(Extensions$4.ColorContribution, colorRegistry$1); function registerColor(id, defaults, description, needsTransparency, deprecationMessage) { return colorRegistry$1.registerColor(id, defaults, description, needsTransparency, deprecationMessage); } // ----- base colors const foreground = registerColor('foreground', { dark: '#CCCCCC', light: '#616161', hc: '#FFFFFF' }, localize('foreground', "Overall foreground color. This color is only used if not overridden by a component.")); const errorForeground = registerColor('errorForeground', { dark: '#F48771', light: '#A1260D', hc: '#F48771' }, localize('errorForeground', "Overall foreground color for error messages. This color is only used if not overridden by a component.")); registerColor('descriptionForeground', { light: '#717171', dark: transparent(foreground, 0.7), hc: transparent(foreground, 0.7) }, localize('descriptionForeground', "Foreground color for description text providing additional information, for example for a label.")); const iconForeground = registerColor('icon.foreground', { dark: '#C5C5C5', light: '#424242', hc: '#FFFFFF' }, localize('iconForeground', "The default color for icons in the workbench.")); const focusBorder = registerColor('focusBorder', { dark: '#007FD4', light: '#0090F1', hc: '#F38518' }, localize('focusBorder', "Overall border color for focused elements. This color is only used if not overridden by a component.")); const contrastBorder = registerColor('contrastBorder', { light: null, dark: null, hc: '#6FC3DF' }, localize('contrastBorder', "An extra border around elements to separate them from others for greater contrast.")); const activeContrastBorder = registerColor('contrastActiveBorder', { light: null, dark: null, hc: focusBorder }, localize('activeContrastBorder', "An extra border around active elements to separate them from others for greater contrast.")); registerColor('selection.background', { light: null, dark: null, hc: null }, localize('selectionBackground', "The background color of text selections in the workbench (e.g. for input fields or text areas). Note that this does not apply to selections within the editor.")); // ------ text colors registerColor('textSeparator.foreground', { light: '#0000002e', dark: '#ffffff2e', hc: Color$3.black }, localize('textSeparatorForeground', "Color for text separators.")); const textLinkForeground = registerColor('textLink.foreground', { light: '#006AB1', dark: '#3794FF', hc: '#3794FF' }, localize('textLinkForeground', "Foreground color for links in text.")); const textLinkActiveForeground = registerColor('textLink.activeForeground', { light: '#006AB1', dark: '#3794FF', hc: '#3794FF' }, localize('textLinkActiveForeground', "Foreground color for links in text when clicked on and on mouse hover.")); registerColor('textPreformat.foreground', { light: '#A31515', dark: '#D7BA7D', hc: '#D7BA7D' }, localize('textPreformatForeground', "Foreground color for preformatted text segments.")); registerColor('textBlockQuote.background', { light: '#7f7f7f1a', dark: '#7f7f7f1a', hc: null }, localize('textBlockQuoteBackground', "Background color for block quotes in text.")); registerColor('textBlockQuote.border', { light: '#007acc80', dark: '#007acc80', hc: Color$3.white }, localize('textBlockQuoteBorder', "Border color for block quotes in text.")); const textCodeBlockBackground = registerColor('textCodeBlock.background', { light: '#dcdcdc66', dark: '#0a0a0a66', hc: Color$3.black }, localize('textCodeBlockBackground', "Background color for code blocks in text.")); // ----- widgets const widgetShadow = registerColor('widget.shadow', { dark: transparent(Color$3.black, .36), light: transparent(Color$3.black, .16), hc: null }, localize('widgetShadow', 'Shadow color of widgets such as find/replace inside the editor.')); const inputBackground = registerColor('input.background', { dark: '#3C3C3C', light: Color$3.white, hc: Color$3.black }, localize('inputBoxBackground', "Input box background.")); const inputForeground = registerColor('input.foreground', { dark: foreground, light: foreground, hc: foreground }, localize('inputBoxForeground', "Input box foreground.")); const inputBorder = registerColor('input.border', { dark: null, light: null, hc: contrastBorder }, localize('inputBoxBorder', "Input box border.")); const inputActiveOptionBorder = registerColor('inputOption.activeBorder', { dark: '#007ACC00', light: '#007ACC00', hc: contrastBorder }, localize('inputBoxActiveOptionBorder', "Border color of activated options in input fields.")); registerColor('inputOption.hoverBackground', { dark: '#5a5d5e80', light: '#b8b8b850', hc: null }, localize('inputOption.hoverBackground', "Background color of activated options in input fields.")); const inputActiveOptionBackground = registerColor('inputOption.activeBackground', { dark: transparent(focusBorder, 0.4), light: transparent(focusBorder, 0.2), hc: Color$3.transparent }, localize('inputOption.activeBackground', "Background hover color of options in input fields.")); const inputActiveOptionForeground = registerColor('inputOption.activeForeground', { dark: Color$3.white, light: Color$3.black, hc: null }, localize('inputOption.activeForeground', "Foreground color of activated options in input fields.")); registerColor('input.placeholderForeground', { light: transparent(foreground, 0.5), dark: transparent(foreground, 0.5), hc: transparent(foreground, 0.7) }, localize('inputPlaceholderForeground', "Input box foreground color for placeholder text.")); const inputValidationInfoBackground = registerColor('inputValidation.infoBackground', { dark: '#063B49', light: '#D6ECF2', hc: Color$3.black }, localize('inputValidationInfoBackground', "Input validation background color for information severity.")); const inputValidationInfoForeground = registerColor('inputValidation.infoForeground', { dark: null, light: null, hc: null }, localize('inputValidationInfoForeground', "Input validation foreground color for information severity.")); const inputValidationInfoBorder = registerColor('inputValidation.infoBorder', { dark: '#007acc', light: '#007acc', hc: contrastBorder }, localize('inputValidationInfoBorder', "Input validation border color for information severity.")); const inputValidationWarningBackground = registerColor('inputValidation.warningBackground', { dark: '#352A05', light: '#F6F5D2', hc: Color$3.black }, localize('inputValidationWarningBackground', "Input validation background color for warning severity.")); const inputValidationWarningForeground = registerColor('inputValidation.warningForeground', { dark: null, light: null, hc: null }, localize('inputValidationWarningForeground', "Input validation foreground color for warning severity.")); const inputValidationWarningBorder = registerColor('inputValidation.warningBorder', { dark: '#B89500', light: '#B89500', hc: contrastBorder }, localize('inputValidationWarningBorder', "Input validation border color for warning severity.")); const inputValidationErrorBackground = registerColor('inputValidation.errorBackground', { dark: '#5A1D1D', light: '#F2DEDE', hc: Color$3.black }, localize('inputValidationErrorBackground', "Input validation background color for error severity.")); const inputValidationErrorForeground = registerColor('inputValidation.errorForeground', { dark: null, light: null, hc: null }, localize('inputValidationErrorForeground', "Input validation foreground color for error severity.")); const inputValidationErrorBorder = registerColor('inputValidation.errorBorder', { dark: '#BE1100', light: '#BE1100', hc: contrastBorder }, localize('inputValidationErrorBorder', "Input validation border color for error severity.")); const selectBackground = registerColor('dropdown.background', { dark: '#3C3C3C', light: Color$3.white, hc: Color$3.black }, localize('dropdownBackground', "Dropdown background.")); registerColor('dropdown.listBackground', { dark: null, light: null, hc: Color$3.black }, localize('dropdownListBackground', "Dropdown list background.")); const selectForeground = registerColor('dropdown.foreground', { dark: '#F0F0F0', light: null, hc: Color$3.white }, localize('dropdownForeground', "Dropdown foreground.")); const selectBorder = registerColor('dropdown.border', { dark: selectBackground, light: '#CECECE', hc: contrastBorder }, localize('dropdownBorder', "Dropdown border.")); registerColor('checkbox.background', { dark: selectBackground, light: selectBackground, hc: selectBackground }, localize('checkbox.background', "Background color of checkbox widget.")); registerColor('checkbox.foreground', { dark: selectForeground, light: selectForeground, hc: selectForeground }, localize('checkbox.foreground', "Foreground color of checkbox widget.")); registerColor('checkbox.border', { dark: selectBorder, light: selectBorder, hc: selectBorder }, localize('checkbox.border', "Border color of checkbox widget.")); const buttonForeground = registerColor('button.foreground', { dark: Color$3.white, light: Color$3.white, hc: Color$3.white }, localize('buttonForeground', "Button foreground color.")); const buttonBackground = registerColor('button.background', { dark: '#0E639C', light: '#007ACC', hc: null }, localize('buttonBackground', "Button background color.")); const buttonHoverBackground = registerColor('button.hoverBackground', { dark: lighten(buttonBackground, 0.2), light: darken(buttonBackground, 0.2), hc: null }, localize('buttonHoverBackground', "Button background color when hovering.")); registerColor('button.border', { dark: contrastBorder, light: contrastBorder, hc: contrastBorder }, localize('buttonBorder', "Button border color.")); registerColor('button.secondaryForeground', { dark: Color$3.white, light: Color$3.white, hc: Color$3.white }, localize('buttonSecondaryForeground', "Secondary button foreground color.")); const buttonSecondaryBackground = registerColor('button.secondaryBackground', { dark: '#3A3D41', light: '#5F6A79', hc: null }, localize('buttonSecondaryBackground', "Secondary button background color.")); registerColor('button.secondaryHoverBackground', { dark: lighten(buttonSecondaryBackground, 0.2), light: darken(buttonSecondaryBackground, 0.2), hc: null }, localize('buttonSecondaryHoverBackground', "Secondary button background color when hovering.")); const badgeBackground = registerColor('badge.background', { dark: '#4D4D4D', light: '#C4C4C4', hc: Color$3.black }, localize('badgeBackground', "Badge background color. Badges are small information labels, e.g. for search results count.")); const badgeForeground = registerColor('badge.foreground', { dark: Color$3.white, light: '#333', hc: Color$3.white }, localize('badgeForeground', "Badge foreground color. Badges are small information labels, e.g. for search results count.")); const scrollbarShadow = registerColor('scrollbar.shadow', { dark: '#000000', light: '#DDDDDD', hc: null }, localize('scrollbarShadow', "Scrollbar shadow to indicate that the view is scrolled.")); const scrollbarSliderBackground = registerColor('scrollbarSlider.background', { dark: Color$3.fromHex('#797979').transparent(0.4), light: Color$3.fromHex('#646464').transparent(0.4), hc: transparent(contrastBorder, 0.6) }, localize('scrollbarSliderBackground', "Scrollbar slider background color.")); const scrollbarSliderHoverBackground = registerColor('scrollbarSlider.hoverBackground', { dark: Color$3.fromHex('#646464').transparent(0.7), light: Color$3.fromHex('#646464').transparent(0.7), hc: transparent(contrastBorder, 0.8) }, localize('scrollbarSliderHoverBackground', "Scrollbar slider background color when hovering.")); const scrollbarSliderActiveBackground = registerColor('scrollbarSlider.activeBackground', { dark: Color$3.fromHex('#BFBFBF').transparent(0.4), light: Color$3.fromHex('#000000').transparent(0.6), hc: contrastBorder }, localize('scrollbarSliderActiveBackground', "Scrollbar slider background color when clicked on.")); const progressBarBackground = registerColor('progressBar.background', { dark: Color$3.fromHex('#0E70C0'), light: Color$3.fromHex('#0E70C0'), hc: contrastBorder }, localize('progressBarBackground', "Background color of the progress bar that can show for long running operations.")); const editorErrorBackground = registerColor('editorError.background', { dark: null, light: null, hc: null }, localize('editorError.background', 'Background color of error text in the editor. The color must not be opaque so as not to hide underlying decorations.'), true); const editorErrorForeground = registerColor('editorError.foreground', { dark: '#F14C4C', light: '#E51400', hc: null }, localize('editorError.foreground', 'Foreground color of error squigglies in the editor.')); const editorErrorBorder = registerColor('editorError.border', { dark: null, light: null, hc: Color$3.fromHex('#E47777').transparent(0.8) }, localize('errorBorder', 'Border color of error boxes in the editor.')); const editorWarningBackground = registerColor('editorWarning.background', { dark: null, light: null, hc: null }, localize('editorWarning.background', 'Background color of warning text in the editor. The color must not be opaque so as not to hide underlying decorations.'), true); const editorWarningForeground = registerColor('editorWarning.foreground', { dark: '#CCA700', light: '#BF8803', hc: null }, localize('editorWarning.foreground', 'Foreground color of warning squigglies in the editor.')); const editorWarningBorder = registerColor('editorWarning.border', { dark: null, light: null, hc: Color$3.fromHex('#FFCC00').transparent(0.8) }, localize('warningBorder', 'Border color of warning boxes in the editor.')); const editorInfoBackground = registerColor('editorInfo.background', { dark: null, light: null, hc: null }, localize('editorInfo.background', 'Background color of info text in the editor. The color must not be opaque so as not to hide underlying decorations.'), true); const editorInfoForeground = registerColor('editorInfo.foreground', { dark: '#3794FF', light: '#1a85ff', hc: '#3794FF' }, localize('editorInfo.foreground', 'Foreground color of info squigglies in the editor.')); const editorInfoBorder = registerColor('editorInfo.border', { dark: null, light: null, hc: Color$3.fromHex('#3794FF').transparent(0.8) }, localize('infoBorder', 'Border color of info boxes in the editor.')); const editorHintForeground = registerColor('editorHint.foreground', { dark: Color$3.fromHex('#eeeeee').transparent(0.7), light: '#6c6c6c', hc: null }, localize('editorHint.foreground', 'Foreground color of hint squigglies in the editor.')); const editorHintBorder = registerColor('editorHint.border', { dark: null, light: null, hc: Color$3.fromHex('#eeeeee').transparent(0.8) }, localize('hintBorder', 'Border color of hint boxes in the editor.')); registerColor('sash.hoverBorder', { dark: focusBorder, light: focusBorder, hc: focusBorder }, localize('sashActiveBorder', "Border color of active sashes.")); /** * Editor background color. * Because of bug https://monacotools.visualstudio.com/DefaultCollection/Monaco/_workitems/edit/13254 * we are *not* using the color white (or #ffffff, rgba(255,255,255)) but something very close to white. */ const editorBackground = registerColor('editor.background', { light: '#fffffe', dark: '#1E1E1E', hc: Color$3.black }, localize('editorBackground', "Editor background color.")); /** * Editor foreground color. */ const editorForeground = registerColor('editor.foreground', { light: '#333333', dark: '#BBBBBB', hc: Color$3.white }, localize('editorForeground', "Editor default foreground color.")); /** * Editor widgets */ const editorWidgetBackground = registerColor('editorWidget.background', { dark: '#252526', light: '#F3F3F3', hc: '#0C141F' }, localize('editorWidgetBackground', 'Background color of editor widgets, such as find/replace.')); const editorWidgetForeground = registerColor('editorWidget.foreground', { dark: foreground, light: foreground, hc: foreground }, localize('editorWidgetForeground', 'Foreground color of editor widgets, such as find/replace.')); const editorWidgetBorder = registerColor('editorWidget.border', { dark: '#454545', light: '#C8C8C8', hc: contrastBorder }, localize('editorWidgetBorder', 'Border color of editor widgets. The color is only used if the widget chooses to have a border and if the color is not overridden by a widget.')); const editorWidgetResizeBorder = registerColor('editorWidget.resizeBorder', { light: null, dark: null, hc: null }, localize('editorWidgetResizeBorder', "Border color of the resize bar of editor widgets. The color is only used if the widget chooses to have a resize border and if the color is not overridden by a widget.")); /** * Quick pick widget */ const quickInputBackground = registerColor('quickInput.background', { dark: editorWidgetBackground, light: editorWidgetBackground, hc: editorWidgetBackground }, localize('pickerBackground', "Quick picker background color. The quick picker widget is the container for pickers like the command palette.")); const quickInputForeground = registerColor('quickInput.foreground', { dark: editorWidgetForeground, light: editorWidgetForeground, hc: editorWidgetForeground }, localize('pickerForeground', "Quick picker foreground color. The quick picker widget is the container for pickers like the command palette.")); const quickInputTitleBackground = registerColor('quickInputTitle.background', { dark: new Color$3(new RGBA(255, 255, 255, 0.105)), light: new Color$3(new RGBA(0, 0, 0, 0.06)), hc: '#000000' }, localize('pickerTitleBackground', "Quick picker title background color. The quick picker widget is the container for pickers like the command palette.")); const pickerGroupForeground = registerColor('pickerGroup.foreground', { dark: '#3794FF', light: '#0066BF', hc: Color$3.white }, localize('pickerGroupForeground', "Quick picker color for grouping labels.")); const pickerGroupBorder = registerColor('pickerGroup.border', { dark: '#3F3F46', light: '#CCCEDB', hc: Color$3.white }, localize('pickerGroupBorder', "Quick picker color for grouping borders.")); /** * Keybinding label */ const keybindingLabelBackground = registerColor('keybindingLabel.background', { dark: new Color$3(new RGBA(128, 128, 128, 0.17)), light: new Color$3(new RGBA(221, 221, 221, 0.4)), hc: Color$3.transparent }, localize('keybindingLabelBackground', "Keybinding label background color. The keybinding label is used to represent a keyboard shortcut.")); const keybindingLabelForeground = registerColor('keybindingLabel.foreground', { dark: Color$3.fromHex('#CCCCCC'), light: Color$3.fromHex('#555555'), hc: Color$3.white }, localize('keybindingLabelForeground', "Keybinding label foreground color. The keybinding label is used to represent a keyboard shortcut.")); const keybindingLabelBorder = registerColor('keybindingLabel.border', { dark: new Color$3(new RGBA(51, 51, 51, 0.6)), light: new Color$3(new RGBA(204, 204, 204, 0.4)), hc: new Color$3(new RGBA(111, 195, 223)) }, localize('keybindingLabelBorder', "Keybinding label border color. The keybinding label is used to represent a keyboard shortcut.")); const keybindingLabelBottomBorder = registerColor('keybindingLabel.bottomBorder', { dark: new Color$3(new RGBA(68, 68, 68, 0.6)), light: new Color$3(new RGBA(187, 187, 187, 0.4)), hc: new Color$3(new RGBA(111, 195, 223)) }, localize('keybindingLabelBottomBorder', "Keybinding label border bottom color. The keybinding label is used to represent a keyboard shortcut.")); /** * Editor selection colors. */ const editorSelectionBackground = registerColor('editor.selectionBackground', { light: '#ADD6FF', dark: '#264F78', hc: '#f3f518' }, localize('editorSelectionBackground', "Color of the editor selection.")); const editorSelectionForeground = registerColor('editor.selectionForeground', { light: null, dark: null, hc: '#000000' }, localize('editorSelectionForeground', "Color of the selected text for high contrast.")); const editorInactiveSelection = registerColor('editor.inactiveSelectionBackground', { light: transparent(editorSelectionBackground, 0.5), dark: transparent(editorSelectionBackground, 0.5), hc: transparent(editorSelectionBackground, 0.5) }, localize('editorInactiveSelection', "Color of the selection in an inactive editor. The color must not be opaque so as not to hide underlying decorations."), true); const editorSelectionHighlight = registerColor('editor.selectionHighlightBackground', { light: lessProminent(editorSelectionBackground, editorBackground, 0.3, 0.6), dark: lessProminent(editorSelectionBackground, editorBackground, 0.3, 0.6), hc: null }, localize('editorSelectionHighlight', 'Color for regions with the same content as the selection. The color must not be opaque so as not to hide underlying decorations.'), true); const editorSelectionHighlightBorder = registerColor('editor.selectionHighlightBorder', { light: null, dark: null, hc: activeContrastBorder }, localize('editorSelectionHighlightBorder', "Border color for regions with the same content as the selection.")); /** * Editor find match colors. */ const editorFindMatch = registerColor('editor.findMatchBackground', { light: '#A8AC94', dark: '#515C6A', hc: null }, localize('editorFindMatch', "Color of the current search match.")); const editorFindMatchHighlight = registerColor('editor.findMatchHighlightBackground', { light: '#EA5C0055', dark: '#EA5C0055', hc: null }, localize('findMatchHighlight', "Color of the other search matches. The color must not be opaque so as not to hide underlying decorations."), true); const editorFindRangeHighlight = registerColor('editor.findRangeHighlightBackground', { dark: '#3a3d4166', light: '#b4b4b44d', hc: null }, localize('findRangeHighlight', "Color of the range limiting the search. The color must not be opaque so as not to hide underlying decorations."), true); const editorFindMatchBorder = registerColor('editor.findMatchBorder', { light: null, dark: null, hc: activeContrastBorder }, localize('editorFindMatchBorder', "Border color of the current search match.")); const editorFindMatchHighlightBorder = registerColor('editor.findMatchHighlightBorder', { light: null, dark: null, hc: activeContrastBorder }, localize('findMatchHighlightBorder', "Border color of the other search matches.")); const editorFindRangeHighlightBorder = registerColor('editor.findRangeHighlightBorder', { dark: null, light: null, hc: transparent(activeContrastBorder, 0.4) }, localize('findRangeHighlightBorder', "Border color of the range limiting the search. The color must not be opaque so as not to hide underlying decorations."), true); /** * Search Editor query match colors. * * Distinct from normal editor find match to allow for better differentiation */ registerColor('searchEditor.findMatchBackground', { light: transparent(editorFindMatchHighlight, 0.66), dark: transparent(editorFindMatchHighlight, 0.66), hc: editorFindMatchHighlight }, localize('searchEditor.queryMatch', "Color of the Search Editor query matches.")); registerColor('searchEditor.findMatchBorder', { light: transparent(editorFindMatchHighlightBorder, 0.66), dark: transparent(editorFindMatchHighlightBorder, 0.66), hc: editorFindMatchHighlightBorder }, localize('searchEditor.editorFindMatchBorder', "Border color of the Search Editor query matches.")); /** * Editor hover */ const editorHoverHighlight = registerColor('editor.hoverHighlightBackground', { light: '#ADD6FF26', dark: '#264f7840', hc: '#ADD6FF26' }, localize('hoverHighlight', 'Highlight below the word for which a hover is shown. The color must not be opaque so as not to hide underlying decorations.'), true); const editorHoverBackground = registerColor('editorHoverWidget.background', { light: editorWidgetBackground, dark: editorWidgetBackground, hc: editorWidgetBackground }, localize('hoverBackground', 'Background color of the editor hover.')); const editorHoverForeground = registerColor('editorHoverWidget.foreground', { light: editorWidgetForeground, dark: editorWidgetForeground, hc: editorWidgetForeground }, localize('hoverForeground', 'Foreground color of the editor hover.')); const editorHoverBorder = registerColor('editorHoverWidget.border', { light: editorWidgetBorder, dark: editorWidgetBorder, hc: editorWidgetBorder }, localize('hoverBorder', 'Border color of the editor hover.')); const editorHoverStatusBarBackground = registerColor('editorHoverWidget.statusBarBackground', { dark: lighten(editorHoverBackground, 0.2), light: darken(editorHoverBackground, 0.05), hc: editorWidgetBackground }, localize('statusBarBackground', "Background color of the editor hover status bar.")); /** * Editor link colors */ const editorActiveLinkForeground = registerColor('editorLink.activeForeground', { dark: '#4E94CE', light: Color$3.blue, hc: Color$3.cyan }, localize('activeLinkForeground', 'Color of active links.')); /** * Inline hints */ const editorInlayHintForeground = registerColor('editorInlayHint.foreground', { dark: transparent(badgeForeground, .8), light: transparent(badgeForeground, .8), hc: badgeForeground }, localize('editorInlayHintForeground', 'Foreground color of inline hints')); const editorInlayHintBackground = registerColor('editorInlayHint.background', { dark: transparent(badgeBackground, .6), light: transparent(badgeBackground, .3), hc: badgeBackground }, localize('editorInlayHintBackground', 'Background color of inline hints')); const editorInlayHintTypeForeground = registerColor('editorInlayHint.typeForeground', { dark: editorInlayHintForeground, light: editorInlayHintForeground, hc: editorInlayHintForeground }, localize('editorInlayHintForegroundTypes', 'Foreground color of inline hints for types')); const editorInlayHintTypeBackground = registerColor('editorInlayHint.typeBackground', { dark: editorInlayHintBackground, light: editorInlayHintBackground, hc: editorInlayHintBackground }, localize('editorInlayHintBackgroundTypes', 'Background color of inline hints for types')); const editorInlayHintParameterForeground = registerColor('editorInlayHint.parameterForeground', { dark: editorInlayHintForeground, light: editorInlayHintForeground, hc: editorInlayHintForeground }, localize('editorInlayHintForegroundParameter', 'Foreground color of inline hints for parameters')); const editorInlayHintParameterBackground = registerColor('editorInlayHint.parameterBackground', { dark: editorInlayHintBackground, light: editorInlayHintBackground, hc: editorInlayHintBackground }, localize('editorInlayHintBackgroundParameter', 'Background color of inline hints for parameters')); /** * Editor lighbulb icon colors */ const editorLightBulbForeground = registerColor('editorLightBulb.foreground', { dark: '#FFCC00', light: '#DDB100', hc: '#FFCC00' }, localize('editorLightBulbForeground', "The color used for the lightbulb actions icon.")); const editorLightBulbAutoFixForeground = registerColor('editorLightBulbAutoFix.foreground', { dark: '#75BEFF', light: '#007ACC', hc: '#75BEFF' }, localize('editorLightBulbAutoFixForeground', "The color used for the lightbulb auto fix actions icon.")); /** * Diff Editor Colors */ const defaultInsertColor = new Color$3(new RGBA(155, 185, 85, 0.2)); const defaultRemoveColor = new Color$3(new RGBA(255, 0, 0, 0.2)); const diffInserted = registerColor('diffEditor.insertedTextBackground', { dark: defaultInsertColor, light: defaultInsertColor, hc: null }, localize('diffEditorInserted', 'Background color for text that got inserted. The color must not be opaque so as not to hide underlying decorations.'), true); const diffRemoved = registerColor('diffEditor.removedTextBackground', { dark: defaultRemoveColor, light: defaultRemoveColor, hc: null }, localize('diffEditorRemoved', 'Background color for text that got removed. The color must not be opaque so as not to hide underlying decorations.'), true); const diffInsertedOutline = registerColor('diffEditor.insertedTextBorder', { dark: null, light: null, hc: '#33ff2eff' }, localize('diffEditorInsertedOutline', 'Outline color for the text that got inserted.')); const diffRemovedOutline = registerColor('diffEditor.removedTextBorder', { dark: null, light: null, hc: '#FF008F' }, localize('diffEditorRemovedOutline', 'Outline color for text that got removed.')); const diffBorder = registerColor('diffEditor.border', { dark: null, light: null, hc: contrastBorder }, localize('diffEditorBorder', 'Border color between the two text editors.')); const diffDiagonalFill = registerColor('diffEditor.diagonalFill', { dark: '#cccccc33', light: '#22222233', hc: null }, localize('diffDiagonalFill', "Color of the diff editor's diagonal fill. The diagonal fill is used in side-by-side diff views.")); /** * List and tree colors */ const listFocusBackground = registerColor('list.focusBackground', { dark: null, light: null, hc: null }, localize('listFocusBackground', "List/Tree background color for the focused item when the list/tree is active. An active list/tree has keyboard focus, an inactive does not.")); const listFocusForeground = registerColor('list.focusForeground', { dark: null, light: null, hc: null }, localize('listFocusForeground', "List/Tree foreground color for the focused item when the list/tree is active. An active list/tree has keyboard focus, an inactive does not.")); const listFocusOutline = registerColor('list.focusOutline', { dark: focusBorder, light: focusBorder, hc: activeContrastBorder }, localize('listFocusOutline', "List/Tree outline color for the focused item when the list/tree is active. An active list/tree has keyboard focus, an inactive does not.")); const listActiveSelectionBackground = registerColor('list.activeSelectionBackground', { dark: '#094771', light: '#0060C0', hc: null }, localize('listActiveSelectionBackground', "List/Tree background color for the selected item when the list/tree is active. An active list/tree has keyboard focus, an inactive does not.")); const listActiveSelectionForeground = registerColor('list.activeSelectionForeground', { dark: Color$3.white, light: Color$3.white, hc: null }, localize('listActiveSelectionForeground', "List/Tree foreground color for the selected item when the list/tree is active. An active list/tree has keyboard focus, an inactive does not.")); const listActiveSelectionIconForeground = registerColor('list.activeSelectionIconForeground', { dark: null, light: null, hc: null }, localize('listActiveSelectionIconForeground', "List/Tree icon foreground color for the selected item when the list/tree is active. An active list/tree has keyboard focus, an inactive does not.")); const listInactiveSelectionBackground = registerColor('list.inactiveSelectionBackground', { dark: '#37373D', light: '#E4E6F1', hc: null }, localize('listInactiveSelectionBackground', "List/Tree background color for the selected item when the list/tree is inactive. An active list/tree has keyboard focus, an inactive does not.")); const listInactiveSelectionForeground = registerColor('list.inactiveSelectionForeground', { dark: null, light: null, hc: null }, localize('listInactiveSelectionForeground', "List/Tree foreground color for the selected item when the list/tree is inactive. An active list/tree has keyboard focus, an inactive does not.")); const listInactiveSelectionIconForeground = registerColor('list.inactiveSelectionIconForeground', { dark: null, light: null, hc: null }, localize('listInactiveSelectionIconForeground', "List/Tree icon foreground color for the selected item when the list/tree is inactive. An active list/tree has keyboard focus, an inactive does not.")); const listInactiveFocusBackground = registerColor('list.inactiveFocusBackground', { dark: null, light: null, hc: null }, localize('listInactiveFocusBackground', "List/Tree background color for the focused item when the list/tree is inactive. An active list/tree has keyboard focus, an inactive does not.")); const listInactiveFocusOutline = registerColor('list.inactiveFocusOutline', { dark: null, light: null, hc: null }, localize('listInactiveFocusOutline', "List/Tree outline color for the focused item when the list/tree is inactive. An active list/tree has keyboard focus, an inactive does not.")); const listHoverBackground = registerColor('list.hoverBackground', { dark: '#2A2D2E', light: '#F0F0F0', hc: null }, localize('listHoverBackground', "List/Tree background when hovering over items using the mouse.")); const listHoverForeground = registerColor('list.hoverForeground', { dark: null, light: null, hc: null }, localize('listHoverForeground', "List/Tree foreground when hovering over items using the mouse.")); const listDropBackground = registerColor('list.dropBackground', { dark: '#062F4A', light: '#D6EBFF', hc: null }, localize('listDropBackground', "List/Tree drag and drop background when moving items around using the mouse.")); const listHighlightForeground = registerColor('list.highlightForeground', { dark: '#18A3FF', light: '#0066BF', hc: focusBorder }, localize('highlight', 'List/Tree foreground color of the match highlights when searching inside the list/tree.')); const listFocusHighlightForeground = registerColor('list.focusHighlightForeground', { dark: listHighlightForeground, light: ifDefinedThenElse(listActiveSelectionBackground, listHighlightForeground, '#9DDDFF'), hc: listHighlightForeground }, localize('listFocusHighlightForeground', 'List/Tree foreground color of the match highlights on actively focused items when searching inside the list/tree.')); registerColor('list.invalidItemForeground', { dark: '#B89500', light: '#B89500', hc: '#B89500' }, localize('invalidItemForeground', 'List/Tree foreground color for invalid items, for example an unresolved root in explorer.')); registerColor('list.errorForeground', { dark: '#F88070', light: '#B01011', hc: null }, localize('listErrorForeground', 'Foreground color of list items containing errors.')); registerColor('list.warningForeground', { dark: '#CCA700', light: '#855F00', hc: null }, localize('listWarningForeground', 'Foreground color of list items containing warnings.')); const listFilterWidgetBackground = registerColor('listFilterWidget.background', { light: '#efc1ad', dark: '#653723', hc: Color$3.black }, localize('listFilterWidgetBackground', 'Background color of the type filter widget in lists and trees.')); const listFilterWidgetOutline = registerColor('listFilterWidget.outline', { dark: Color$3.transparent, light: Color$3.transparent, hc: '#f38518' }, localize('listFilterWidgetOutline', 'Outline color of the type filter widget in lists and trees.')); const listFilterWidgetNoMatchesOutline = registerColor('listFilterWidget.noMatchesOutline', { dark: '#BE1100', light: '#BE1100', hc: contrastBorder }, localize('listFilterWidgetNoMatchesOutline', 'Outline color of the type filter widget in lists and trees, when there are no matches.')); registerColor('list.filterMatchBackground', { dark: editorFindMatchHighlight, light: editorFindMatchHighlight, hc: null }, localize('listFilterMatchHighlight', 'Background color of the filtered match.')); registerColor('list.filterMatchBorder', { dark: editorFindMatchHighlightBorder, light: editorFindMatchHighlightBorder, hc: contrastBorder }, localize('listFilterMatchHighlightBorder', 'Border color of the filtered match.')); const treeIndentGuidesStroke = registerColor('tree.indentGuidesStroke', { dark: '#585858', light: '#a9a9a9', hc: '#a9a9a9' }, localize('treeIndentGuidesStroke', "Tree stroke color for the indentation guides.")); const tableColumnsBorder = registerColor('tree.tableColumnsBorder', { dark: '#CCCCCC20', light: '#61616120', hc: null }, localize('tableColumnsBorder', "Table border color between columns.")); const tableOddRowsBackgroundColor = registerColor('tree.tableOddRowsBackground', { dark: transparent(foreground, 0.04), light: transparent(foreground, 0.04), hc: null }, localize('tableOddRowsBackgroundColor', "Background color for odd table rows.")); registerColor('list.deemphasizedForeground', { dark: '#8C8C8C', light: '#8E8E90', hc: '#A7A8A9' }, localize('listDeemphasizedForeground', "List/Tree foreground color for items that are deemphasized. ")); /** * Quick pick widget (dependent on List and tree colors) */ const _deprecatedQuickInputListFocusBackground = registerColor('quickInput.list.focusBackground', { dark: null, light: null, hc: null }, '', undefined, localize('quickInput.list.focusBackground deprecation', "Please use quickInputList.focusBackground instead")); const quickInputListFocusForeground = registerColor('quickInputList.focusForeground', { dark: listActiveSelectionForeground, light: listActiveSelectionForeground, hc: listActiveSelectionForeground }, localize('quickInput.listFocusForeground', "Quick picker foreground color for the focused item.")); const quickInputListFocusIconForeground = registerColor('quickInputList.focusIconForeground', { dark: listActiveSelectionIconForeground, light: listActiveSelectionIconForeground, hc: listActiveSelectionIconForeground }, localize('quickInput.listFocusIconForeground', "Quick picker icon foreground color for the focused item.")); const quickInputListFocusBackground = registerColor('quickInputList.focusBackground', { dark: oneOf(_deprecatedQuickInputListFocusBackground, listActiveSelectionBackground), light: oneOf(_deprecatedQuickInputListFocusBackground, listActiveSelectionBackground), hc: null }, localize('quickInput.listFocusBackground', "Quick picker background color for the focused item.")); /** * Menu colors */ const menuBorder = registerColor('menu.border', { dark: null, light: null, hc: contrastBorder }, localize('menuBorder', "Border color of menus.")); const menuForeground = registerColor('menu.foreground', { dark: selectForeground, light: foreground, hc: selectForeground }, localize('menuForeground', "Foreground color of menu items.")); const menuBackground = registerColor('menu.background', { dark: selectBackground, light: selectBackground, hc: selectBackground }, localize('menuBackground', "Background color of menu items.")); const menuSelectionForeground = registerColor('menu.selectionForeground', { dark: listActiveSelectionForeground, light: listActiveSelectionForeground, hc: listActiveSelectionForeground }, localize('menuSelectionForeground', "Foreground color of the selected menu item in menus.")); const menuSelectionBackground = registerColor('menu.selectionBackground', { dark: listActiveSelectionBackground, light: listActiveSelectionBackground, hc: listActiveSelectionBackground }, localize('menuSelectionBackground', "Background color of the selected menu item in menus.")); const menuSelectionBorder = registerColor('menu.selectionBorder', { dark: null, light: null, hc: activeContrastBorder }, localize('menuSelectionBorder', "Border color of the selected menu item in menus.")); const menuSeparatorBackground = registerColor('menu.separatorBackground', { dark: '#BBBBBB', light: '#888888', hc: contrastBorder }, localize('menuSeparatorBackground', "Color of a separator menu item in menus.")); /** * Toolbar colors */ const toolbarHoverBackground = registerColor('toolbar.hoverBackground', { dark: '#5a5d5e50', light: '#b8b8b850', hc: null }, localize('toolbarHoverBackground', "Toolbar background when hovering over actions using the mouse")); registerColor('toolbar.hoverOutline', { dark: null, light: null, hc: activeContrastBorder }, localize('toolbarHoverOutline', "Toolbar outline when hovering over actions using the mouse")); registerColor('toolbar.activeBackground', { dark: lighten(toolbarHoverBackground, 0.1), light: darken(toolbarHoverBackground, 0.1), hc: null }, localize('toolbarActiveBackground', "Toolbar background when holding the mouse over actions")); /** * Snippet placeholder colors */ registerColor('editor.snippetTabstopHighlightBackground', { dark: new Color$3(new RGBA(124, 124, 124, 0.3)), light: new Color$3(new RGBA(10, 50, 100, 0.2)), hc: new Color$3(new RGBA(124, 124, 124, 0.3)) }, localize('snippetTabstopHighlightBackground', "Highlight background color of a snippet tabstop.")); registerColor('editor.snippetTabstopHighlightBorder', { dark: null, light: null, hc: null }, localize('snippetTabstopHighlightBorder', "Highlight border color of a snippet tabstop.")); registerColor('editor.snippetFinalTabstopHighlightBackground', { dark: null, light: null, hc: null }, localize('snippetFinalTabstopHighlightBackground', "Highlight background color of the final tabstop of a snippet.")); registerColor('editor.snippetFinalTabstopHighlightBorder', { dark: '#525252', light: new Color$3(new RGBA(10, 50, 100, 0.5)), hc: '#525252' }, localize('snippetFinalTabstopHighlightBorder', "Highlight border color of the final tabstop of a snippet.")); /** * Breadcrumb colors */ registerColor('breadcrumb.foreground', { light: transparent(foreground, 0.8), dark: transparent(foreground, 0.8), hc: transparent(foreground, 0.8) }, localize('breadcrumbsFocusForeground', "Color of focused breadcrumb items.")); registerColor('breadcrumb.background', { light: editorBackground, dark: editorBackground, hc: editorBackground }, localize('breadcrumbsBackground', "Background color of breadcrumb items.")); registerColor('breadcrumb.focusForeground', { light: darken(foreground, 0.2), dark: lighten(foreground, 0.1), hc: lighten(foreground, 0.1) }, localize('breadcrumbsFocusForeground', "Color of focused breadcrumb items.")); registerColor('breadcrumb.activeSelectionForeground', { light: darken(foreground, 0.2), dark: lighten(foreground, 0.1), hc: lighten(foreground, 0.1) }, localize('breadcrumbsSelectedForegound', "Color of selected breadcrumb items.")); registerColor('breadcrumbPicker.background', { light: editorWidgetBackground, dark: editorWidgetBackground, hc: editorWidgetBackground }, localize('breadcrumbsSelectedBackground', "Background color of breadcrumb item picker.")); /** * Merge-conflict colors */ const headerTransparency = 0.5; const currentBaseColor = Color$3.fromHex('#40C8AE').transparent(headerTransparency); const incomingBaseColor = Color$3.fromHex('#40A6FF').transparent(headerTransparency); const commonBaseColor = Color$3.fromHex('#606060').transparent(0.4); const contentTransparency = 0.4; const rulerTransparency = 1; const mergeCurrentHeaderBackground = registerColor('merge.currentHeaderBackground', { dark: currentBaseColor, light: currentBaseColor, hc: null }, localize('mergeCurrentHeaderBackground', 'Current header background in inline merge-conflicts. The color must not be opaque so as not to hide underlying decorations.'), true); registerColor('merge.currentContentBackground', { dark: transparent(mergeCurrentHeaderBackground, contentTransparency), light: transparent(mergeCurrentHeaderBackground, contentTransparency), hc: transparent(mergeCurrentHeaderBackground, contentTransparency) }, localize('mergeCurrentContentBackground', 'Current content background in inline merge-conflicts. The color must not be opaque so as not to hide underlying decorations.'), true); const mergeIncomingHeaderBackground = registerColor('merge.incomingHeaderBackground', { dark: incomingBaseColor, light: incomingBaseColor, hc: null }, localize('mergeIncomingHeaderBackground', 'Incoming header background in inline merge-conflicts. The color must not be opaque so as not to hide underlying decorations.'), true); registerColor('merge.incomingContentBackground', { dark: transparent(mergeIncomingHeaderBackground, contentTransparency), light: transparent(mergeIncomingHeaderBackground, contentTransparency), hc: transparent(mergeIncomingHeaderBackground, contentTransparency) }, localize('mergeIncomingContentBackground', 'Incoming content background in inline merge-conflicts. The color must not be opaque so as not to hide underlying decorations.'), true); const mergeCommonHeaderBackground = registerColor('merge.commonHeaderBackground', { dark: commonBaseColor, light: commonBaseColor, hc: null }, localize('mergeCommonHeaderBackground', 'Common ancestor header background in inline merge-conflicts. The color must not be opaque so as not to hide underlying decorations.'), true); registerColor('merge.commonContentBackground', { dark: transparent(mergeCommonHeaderBackground, contentTransparency), light: transparent(mergeCommonHeaderBackground, contentTransparency), hc: transparent(mergeCommonHeaderBackground, contentTransparency) }, localize('mergeCommonContentBackground', 'Common ancestor content background in inline merge-conflicts. The color must not be opaque so as not to hide underlying decorations.'), true); const mergeBorder = registerColor('merge.border', { dark: null, light: null, hc: '#C3DF6F' }, localize('mergeBorder', 'Border color on headers and the splitter in inline merge-conflicts.')); registerColor('editorOverviewRuler.currentContentForeground', { dark: transparent(mergeCurrentHeaderBackground, rulerTransparency), light: transparent(mergeCurrentHeaderBackground, rulerTransparency), hc: mergeBorder }, localize('overviewRulerCurrentContentForeground', 'Current overview ruler foreground for inline merge-conflicts.')); registerColor('editorOverviewRuler.incomingContentForeground', { dark: transparent(mergeIncomingHeaderBackground, rulerTransparency), light: transparent(mergeIncomingHeaderBackground, rulerTransparency), hc: mergeBorder }, localize('overviewRulerIncomingContentForeground', 'Incoming overview ruler foreground for inline merge-conflicts.')); registerColor('editorOverviewRuler.commonContentForeground', { dark: transparent(mergeCommonHeaderBackground, rulerTransparency), light: transparent(mergeCommonHeaderBackground, rulerTransparency), hc: mergeBorder }, localize('overviewRulerCommonContentForeground', 'Common ancestor overview ruler foreground for inline merge-conflicts.')); const overviewRulerFindMatchForeground = registerColor('editorOverviewRuler.findMatchForeground', { dark: '#d186167e', light: '#d186167e', hc: '#AB5A00' }, localize('overviewRulerFindMatchForeground', 'Overview ruler marker color for find matches. The color must not be opaque so as not to hide underlying decorations.'), true); const overviewRulerSelectionHighlightForeground = registerColor('editorOverviewRuler.selectionHighlightForeground', { dark: '#A0A0A0CC', light: '#A0A0A0CC', hc: '#A0A0A0CC' }, localize('overviewRulerSelectionHighlightForeground', 'Overview ruler marker color for selection highlights. The color must not be opaque so as not to hide underlying decorations.'), true); const minimapFindMatch = registerColor('minimap.findMatchHighlight', { light: '#d18616', dark: '#d18616', hc: '#AB5A00' }, localize('minimapFindMatchHighlight', 'Minimap marker color for find matches.'), true); const minimapSelectionOccurrenceHighlight = registerColor('minimap.selectionOccurrenceHighlight', { light: '#c9c9c9', dark: '#676767', hc: '#ffffff' }, localize('minimapSelectionOccurrenceHighlight', 'Minimap marker color for repeating editor selections.'), true); const minimapSelection = registerColor('minimap.selectionHighlight', { light: '#ADD6FF', dark: '#264F78', hc: '#ffffff' }, localize('minimapSelectionHighlight', 'Minimap marker color for the editor selection.'), true); const minimapError = registerColor('minimap.errorHighlight', { dark: new Color$3(new RGBA(255, 18, 18, 0.7)), light: new Color$3(new RGBA(255, 18, 18, 0.7)), hc: new Color$3(new RGBA(255, 50, 50, 1)) }, localize('minimapError', 'Minimap marker color for errors.')); const minimapWarning = registerColor('minimap.warningHighlight', { dark: editorWarningForeground, light: editorWarningForeground, hc: editorWarningBorder }, localize('overviewRuleWarning', 'Minimap marker color for warnings.')); const minimapBackground = registerColor('minimap.background', { dark: null, light: null, hc: null }, localize('minimapBackground', "Minimap background color.")); const minimapForegroundOpacity = registerColor('minimap.foregroundOpacity', { dark: Color$3.fromHex('#000f'), light: Color$3.fromHex('#000f'), hc: Color$3.fromHex('#000f') }, localize('minimapForegroundOpacity', 'Opacity of foreground elements rendered in the minimap. For example, "#000000c0" will render the elements with 75% opacity.')); const minimapSliderBackground = registerColor('minimapSlider.background', { light: transparent(scrollbarSliderBackground, 0.5), dark: transparent(scrollbarSliderBackground, 0.5), hc: transparent(scrollbarSliderBackground, 0.5) }, localize('minimapSliderBackground', "Minimap slider background color.")); const minimapSliderHoverBackground = registerColor('minimapSlider.hoverBackground', { light: transparent(scrollbarSliderHoverBackground, 0.5), dark: transparent(scrollbarSliderHoverBackground, 0.5), hc: transparent(scrollbarSliderHoverBackground, 0.5) }, localize('minimapSliderHoverBackground', "Minimap slider background color when hovering.")); const minimapSliderActiveBackground = registerColor('minimapSlider.activeBackground', { light: transparent(scrollbarSliderActiveBackground, 0.5), dark: transparent(scrollbarSliderActiveBackground, 0.5), hc: transparent(scrollbarSliderActiveBackground, 0.5) }, localize('minimapSliderActiveBackground', "Minimap slider background color when clicked on.")); const problemsErrorIconForeground = registerColor('problemsErrorIcon.foreground', { dark: editorErrorForeground, light: editorErrorForeground, hc: editorErrorForeground }, localize('problemsErrorIconForeground', "The color used for the problems error icon.")); const problemsWarningIconForeground = registerColor('problemsWarningIcon.foreground', { dark: editorWarningForeground, light: editorWarningForeground, hc: editorWarningForeground }, localize('problemsWarningIconForeground', "The color used for the problems warning icon.")); const problemsInfoIconForeground = registerColor('problemsInfoIcon.foreground', { dark: editorInfoForeground, light: editorInfoForeground, hc: editorInfoForeground }, localize('problemsInfoIconForeground', "The color used for the problems info icon.")); /** * Chart colors */ registerColor('charts.foreground', { dark: foreground, light: foreground, hc: foreground }, localize('chartsForeground', "The foreground color used in charts.")); registerColor('charts.lines', { dark: transparent(foreground, .5), light: transparent(foreground, .5), hc: transparent(foreground, .5) }, localize('chartsLines', "The color used for horizontal lines in charts.")); registerColor('charts.red', { dark: editorErrorForeground, light: editorErrorForeground, hc: editorErrorForeground }, localize('chartsRed', "The red color used in chart visualizations.")); registerColor('charts.blue', { dark: editorInfoForeground, light: editorInfoForeground, hc: editorInfoForeground }, localize('chartsBlue', "The blue color used in chart visualizations.")); registerColor('charts.yellow', { dark: editorWarningForeground, light: editorWarningForeground, hc: editorWarningForeground }, localize('chartsYellow', "The yellow color used in chart visualizations.")); registerColor('charts.orange', { dark: minimapFindMatch, light: minimapFindMatch, hc: minimapFindMatch }, localize('chartsOrange', "The orange color used in chart visualizations.")); registerColor('charts.green', { dark: '#89D185', light: '#388A34', hc: '#89D185' }, localize('chartsGreen', "The green color used in chart visualizations.")); registerColor('charts.purple', { dark: '#B180D7', light: '#652D90', hc: '#B180D7' }, localize('chartsPurple', "The purple color used in chart visualizations.")); // ----- color functions function executeTransform(transform, theme) { var _a, _b, _c; switch (transform.op) { case 0 /* Darken */: return (_a = resolveColorValue(transform.value, theme)) === null || _a === void 0 ? void 0 : _a.darken(transform.factor); case 1 /* Lighten */: return (_b = resolveColorValue(transform.value, theme)) === null || _b === void 0 ? void 0 : _b.lighten(transform.factor); case 2 /* Transparent */: return (_c = resolveColorValue(transform.value, theme)) === null || _c === void 0 ? void 0 : _c.transparent(transform.factor); case 3 /* OneOf */: for (const candidate of transform.values) { const color = resolveColorValue(candidate, theme); if (color) { return color; } } return undefined; case 5 /* IfDefinedThenElse */: return resolveColorValue(theme.defines(transform.if) ? transform.then : transform.else, theme); case 4 /* LessProminent */: { const from = resolveColorValue(transform.value, theme); if (!from) { return undefined; } const backgroundColor = resolveColorValue(transform.background, theme); if (!backgroundColor) { return from.transparent(transform.factor * transform.transparency); } return from.isDarkerThan(backgroundColor) ? Color$3.getLighterColor(from, backgroundColor, transform.factor).transparent(transform.transparency) : Color$3.getDarkerColor(from, backgroundColor, transform.factor).transparent(transform.transparency); } default: throw assertNever(); } } function darken(colorValue, factor) { return { op: 0 /* Darken */, value: colorValue, factor }; } function lighten(colorValue, factor) { return { op: 1 /* Lighten */, value: colorValue, factor }; } function transparent(colorValue, factor) { return { op: 2 /* Transparent */, value: colorValue, factor }; } function oneOf(...colorValues) { return { op: 3 /* OneOf */, values: colorValues }; } function ifDefinedThenElse(ifArg, thenArg, elseArg) { return { op: 5 /* IfDefinedThenElse */, if: ifArg, then: thenArg, else: elseArg }; } function lessProminent(colorValue, backgroundColorValue, factor, transparency) { return { op: 4 /* LessProminent */, value: colorValue, background: backgroundColorValue, factor, transparency }; } // ----- implementation /** * @param colorValue Resolve a color value in the context of a theme */ function resolveColorValue(colorValue, theme) { if (colorValue === null) { return undefined; } else if (typeof colorValue === 'string') { if (colorValue[0] === '#') { return Color$3.fromHex(colorValue); } return theme.getColor(colorValue); } else if (colorValue instanceof Color$3) { return colorValue; } else if (typeof colorValue === 'object') { return executeTransform(colorValue, theme); } return undefined; } const workbenchColorsSchemaId = 'vscode://schemas/workbench-colors'; let schemaRegistry$1 = Registry.as(Extensions$5.JSONContribution); schemaRegistry$1.registerSchema(workbenchColorsSchemaId, colorRegistry$1.getColorSchema()); const delayer$1 = new RunOnceScheduler(() => schemaRegistry$1.notifySchemaChanged(workbenchColorsSchemaId), 200); colorRegistry$1.onDidChangeSchema(() => { if (!delayer$1.isScheduled()) { delayer$1.schedule(); } }); // setTimeout(_ => console.log(colorRegistry.toString()), 5000); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Coordinates relative to the whole document (e.g. mouse event's pageX and pageY) */ class PageCoordinates { constructor(x, y) { this.x = x; this.y = y; this._pageCoordinatesBrand = undefined; } toClientCoordinates() { return new ClientCoordinates(this.x - StandardWindow.scrollX, this.y - StandardWindow.scrollY); } } /** * Coordinates within the application's client area (i.e. origin is document's scroll position). * * For example, clicking in the top-left corner of the client area will * always result in a mouse event with a client.x value of 0, regardless * of whether the page is scrolled horizontally. */ class ClientCoordinates { constructor(clientX, clientY) { this.clientX = clientX; this.clientY = clientY; this._clientCoordinatesBrand = undefined; } toPageCoordinates() { return new PageCoordinates(this.clientX + StandardWindow.scrollX, this.clientY + StandardWindow.scrollY); } } /** * The position of the editor in the page. */ class EditorPagePosition { constructor(x, y, width, height) { this.x = x; this.y = y; this.width = width; this.height = height; this._editorPagePositionBrand = undefined; } } /** * Coordinates relative to the the (top;left) of the editor that can be used safely with other internal editor metrics. * **NOTE**: This position is obtained by taking page coordinates and transforming them relative to the * editor's (top;left) position in a way in which scale transformations are taken into account. * **NOTE**: These coordinates could be negative if the mouse position is outside the editor. */ class CoordinatesRelativeToEditor { constructor(x, y) { this.x = x; this.y = y; this._positionRelativeToEditorBrand = undefined; } } function createEditorPagePosition(editorViewDomNode) { const editorPos = getDomNodePagePosition(editorViewDomNode); return new EditorPagePosition(editorPos.left, editorPos.top, editorPos.width, editorPos.height); } function createCoordinatesRelativeToEditor(editorViewDomNode, editorPagePosition, pos) { // The editor's page position is read from the DOM using getBoundingClientRect(). // // getBoundingClientRect() returns the actual dimensions, while offsetWidth and offsetHeight // reflect the unscaled size. We can use this difference to detect a transform:scale() // and we will apply the transformation in inverse to get mouse coordinates that make sense inside the editor. // // This could be expanded to cover rotation as well maybe by walking the DOM up from `editorViewDomNode` // and computing the effective transformation matrix using getComputedStyle(element).transform. // const scaleX = editorPagePosition.width / editorViewDomNode.offsetWidth; const scaleY = editorPagePosition.height / editorViewDomNode.offsetHeight; // Adjust mouse offsets if editor appears to be scaled via transforms const relativeX = (pos.x - editorPagePosition.x) / scaleX; const relativeY = (pos.y - editorPagePosition.y) / scaleY; return new CoordinatesRelativeToEditor(relativeX, relativeY); } class EditorMouseEvent extends StandardMouseEvent { constructor(e, editorViewDomNode) { super(e); this._editorMouseEventBrand = undefined; this.pos = new PageCoordinates(this.posx, this.posy); this.editorPos = createEditorPagePosition(editorViewDomNode); this.relativePos = createCoordinatesRelativeToEditor(editorViewDomNode, this.editorPos, this.pos); } } class EditorMouseEventFactory { constructor(editorViewDomNode) { this._editorViewDomNode = editorViewDomNode; } _create(e) { return new EditorMouseEvent(e, this._editorViewDomNode); } onContextMenu(target, callback) { return addDisposableListener(target, 'contextmenu', (e) => { callback(this._create(e)); }); } onMouseUp(target, callback) { return addDisposableListener(target, 'mouseup', (e) => { callback(this._create(e)); }); } onMouseDown(target, callback) { return addDisposableListener(target, 'mousedown', (e) => { callback(this._create(e)); }); } onMouseLeave(target, callback) { return addDisposableNonBubblingMouseOutListener(target, (e) => { callback(this._create(e)); }); } onMouseMoveThrottled(target, callback, merger, minimumTimeMs) { const myMerger = (lastEvent, currentEvent) => { return merger(lastEvent, this._create(currentEvent)); }; return addDisposableThrottledListener(target, 'mousemove', callback, myMerger, minimumTimeMs); } } class EditorPointerEventFactory { constructor(editorViewDomNode) { this._editorViewDomNode = editorViewDomNode; } _create(e) { return new EditorMouseEvent(e, this._editorViewDomNode); } onPointerUp(target, callback) { return addDisposableListener(target, 'pointerup', (e) => { callback(this._create(e)); }); } onPointerDown(target, callback) { return addDisposableListener(target, 'pointerdown', (e) => { callback(this._create(e)); }); } onPointerLeave(target, callback) { return addDisposableNonBubblingPointerOutListener(target, (e) => { callback(this._create(e)); }); } onPointerMoveThrottled(target, callback, merger, minimumTimeMs) { const myMerger = (lastEvent, currentEvent) => { return merger(lastEvent, this._create(currentEvent)); }; return addDisposableThrottledListener(target, 'pointermove', callback, myMerger, minimumTimeMs); } } class GlobalEditorMouseMoveMonitor extends Disposable { constructor(editorViewDomNode) { super(); this._editorViewDomNode = editorViewDomNode; this._globalMouseMoveMonitor = this._register(new GlobalMouseMoveMonitor()); this._keydownListener = null; } startMonitoring(initialElement, initialButtons, merger, mouseMoveCallback, onStopCallback) { // Add a <> keydown event listener that will cancel the monitoring // if something other than a modifier key is pressed this._keydownListener = addStandardDisposableListener(document, 'keydown', (e) => { const kb = e.toKeybinding(); if (kb.isModifierKey()) { // Allow modifier keys return; } this._globalMouseMoveMonitor.stopMonitoring(true, e.browserEvent); }, true); const myMerger = (lastEvent, currentEvent) => { return merger(lastEvent, new EditorMouseEvent(currentEvent, this._editorViewDomNode)); }; this._globalMouseMoveMonitor.startMonitoring(initialElement, initialButtons, myMerger, mouseMoveCallback, (e) => { this._keydownListener.dispose(); onStopCallback(e); }); } stopMonitoring() { this._globalMouseMoveMonitor.stopMonitoring(true); } } /** * A helper to create dynamic css rules, bound to a class name. * Rules are reused. * Reference counting and delayed garbage collection ensure that no rules leak. */ class DynamicCssRules { constructor(_editor) { this._editor = _editor; this._instanceId = ++DynamicCssRules._idPool; this._counter = 0; this._rules = new Map(); // We delay garbage collection so that hanging rules can be reused. this._garbageCollectionScheduler = new RunOnceScheduler(() => this.garbageCollect(), 1000); } createClassNameRef(options) { const rule = this.getOrCreateRule(options); rule.increaseRefCount(); return { className: rule.className, dispose: () => { rule.decreaseRefCount(); this._garbageCollectionScheduler.schedule(); } }; } getOrCreateRule(properties) { const key = this.computeUniqueKey(properties); let existingRule = this._rules.get(key); if (!existingRule) { const counter = this._counter++; existingRule = new RefCountedCssRule(key, `dyn-rule-${this._instanceId}-${counter}`, isInShadowDOM(this._editor.getContainerDomNode()) ? this._editor.getContainerDomNode() : undefined, properties); this._rules.set(key, existingRule); } return existingRule; } computeUniqueKey(properties) { return JSON.stringify(properties); } garbageCollect() { for (const rule of this._rules.values()) { if (!rule.hasReferences()) { this._rules.delete(rule.key); rule.dispose(); } } } } DynamicCssRules._idPool = 0; class RefCountedCssRule { constructor(key, className, _containerElement, properties) { this.key = key; this.className = className; this.properties = properties; this._referenceCount = 0; this._styleElement = createStyleSheet(_containerElement); this._styleElement.textContent = this.getCssText(this.className, this.properties); } getCssText(className, properties) { let str = `.${className} {`; for (const prop in properties) { const value = properties[prop]; let cssValue; if (typeof value === 'object') { cssValue = `var(${asCssVariableName(value.id)})`; } else { cssValue = value; } const cssPropName = camelToDashes(prop); str += `\n\t${cssPropName}: ${cssValue};`; } str += `\n}`; return str; } dispose() { this._styleElement.remove(); } increaseRefCount() { this._referenceCount++; } decreaseRefCount() { this._referenceCount--; } hasReferences() { return this._referenceCount > 0; } } function camelToDashes(str) { return str.replace(/(^[A-Z])/, ([first]) => first.toLowerCase()) .replace(/([A-Z])/g, ([letter]) => `-${letter.toLowerCase()}`); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class ViewEventHandler extends Disposable { constructor() { super(); this._shouldRender = true; } shouldRender() { return this._shouldRender; } forceShouldRender() { this._shouldRender = true; } setShouldRender() { this._shouldRender = true; } onDidRender() { this._shouldRender = false; } // --- begin event handlers onCompositionStart(e) { return false; } onCompositionEnd(e) { return false; } onConfigurationChanged(e) { return false; } onCursorStateChanged(e) { return false; } onDecorationsChanged(e) { return false; } onFlushed(e) { return false; } onFocusChanged(e) { return false; } onLanguageConfigurationChanged(e) { return false; } onLineMappingChanged(e) { return false; } onLinesChanged(e) { return false; } onLinesDeleted(e) { return false; } onLinesInserted(e) { return false; } onRevealRangeRequest(e) { return false; } onScrollChanged(e) { return false; } onThemeChanged(e) { return false; } onTokensChanged(e) { return false; } onTokensColorsChanged(e) { return false; } onZonesChanged(e) { return false; } // --- end event handlers handleEvents(events) { let shouldRender = false; for (let i = 0, len = events.length; i < len; i++) { const e = events[i]; switch (e.type) { case 0 /* ViewCompositionStart */: if (this.onCompositionStart(e)) { shouldRender = true; } break; case 1 /* ViewCompositionEnd */: if (this.onCompositionEnd(e)) { shouldRender = true; } break; case 2 /* ViewConfigurationChanged */: if (this.onConfigurationChanged(e)) { shouldRender = true; } break; case 3 /* ViewCursorStateChanged */: if (this.onCursorStateChanged(e)) { shouldRender = true; } break; case 4 /* ViewDecorationsChanged */: if (this.onDecorationsChanged(e)) { shouldRender = true; } break; case 5 /* ViewFlushed */: if (this.onFlushed(e)) { shouldRender = true; } break; case 6 /* ViewFocusChanged */: if (this.onFocusChanged(e)) { shouldRender = true; } break; case 7 /* ViewLanguageConfigurationChanged */: if (this.onLanguageConfigurationChanged(e)) { shouldRender = true; } break; case 8 /* ViewLineMappingChanged */: if (this.onLineMappingChanged(e)) { shouldRender = true; } break; case 9 /* ViewLinesChanged */: if (this.onLinesChanged(e)) { shouldRender = true; } break; case 10 /* ViewLinesDeleted */: if (this.onLinesDeleted(e)) { shouldRender = true; } break; case 11 /* ViewLinesInserted */: if (this.onLinesInserted(e)) { shouldRender = true; } break; case 12 /* ViewRevealRangeRequest */: if (this.onRevealRangeRequest(e)) { shouldRender = true; } break; case 13 /* ViewScrollChanged */: if (this.onScrollChanged(e)) { shouldRender = true; } break; case 15 /* ViewTokensChanged */: if (this.onTokensChanged(e)) { shouldRender = true; } break; case 14 /* ViewThemeChanged */: if (this.onThemeChanged(e)) { shouldRender = true; } break; case 16 /* ViewTokensColorsChanged */: if (this.onTokensColorsChanged(e)) { shouldRender = true; } break; case 17 /* ViewZonesChanged */: if (this.onZonesChanged(e)) { shouldRender = true; } break; default: console.info('View received unknown event: '); console.info(e); } } if (shouldRender) { this._shouldRender = true; } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class ViewPart extends ViewEventHandler { constructor(context) { super(); this._context = context; this._context.addEventHandler(this); } dispose() { this._context.removeEventHandler(this); super.dispose(); } } class PartFingerprints { static write(target, partId) { target.setAttribute('data-mprt', String(partId)); } static read(target) { const r = target.getAttribute('data-mprt'); if (r === null) { return 0 /* None */; } return parseInt(r, 10); } static collect(child, stopAt) { const result = []; let resultLen = 0; while (child && child !== document.body) { if (child === stopAt) { break; } if (child.nodeType === child.ELEMENT_NODE) { result[resultLen++] = this.read(child); } child = child.parentElement; } const r = new Uint8Array(resultLen); for (let i = 0; i < resultLen; i++) { r[i] = result[resultLen - i - 1]; } return r; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class RestrictedRenderingContext { constructor(viewLayout, viewportData) { this._restrictedRenderingContextBrand = undefined; this._viewLayout = viewLayout; this.viewportData = viewportData; this.scrollWidth = this._viewLayout.getScrollWidth(); this.scrollHeight = this._viewLayout.getScrollHeight(); this.visibleRange = this.viewportData.visibleRange; this.bigNumbersDelta = this.viewportData.bigNumbersDelta; const vInfo = this._viewLayout.getCurrentViewport(); this.scrollTop = vInfo.top; this.scrollLeft = vInfo.left; this.viewportWidth = vInfo.width; this.viewportHeight = vInfo.height; } getScrolledTopFromAbsoluteTop(absoluteTop) { return absoluteTop - this.scrollTop; } getVerticalOffsetForLineNumber(lineNumber) { return this._viewLayout.getVerticalOffsetForLineNumber(lineNumber); } getDecorationsInViewport() { return this.viewportData.getDecorationsInViewport(); } } class RenderingContext extends RestrictedRenderingContext { constructor(viewLayout, viewportData, viewLines) { super(viewLayout, viewportData); this._renderingContextBrand = undefined; this._viewLines = viewLines; } linesVisibleRangesForRange(range, includeNewLines) { return this._viewLines.linesVisibleRangesForRange(range, includeNewLines); } visibleRangeForPosition(position) { return this._viewLines.visibleRangeForPosition(position); } } class LineVisibleRanges { constructor(outsideRenderedLine, lineNumber, ranges) { this.outsideRenderedLine = outsideRenderedLine; this.lineNumber = lineNumber; this.ranges = ranges; } } class HorizontalRange { constructor(left, width) { this._horizontalRangeBrand = undefined; this.left = Math.round(left); this.width = Math.round(width); } static from(ranges) { const result = new Array(ranges.length); for (let i = 0, len = ranges.length; i < len; i++) { const range = ranges[i]; result[i] = new HorizontalRange(range.left, range.width); } return result; } toString() { return `[${this.left},${this.width}]`; } } class FloatHorizontalRange { constructor(left, width) { this._floatHorizontalRangeBrand = undefined; this.left = left; this.width = width; } toString() { return `[${this.left},${this.width}]`; } static compare(a, b) { return a.left - b.left; } } class HorizontalPosition { constructor(outsideRenderedLine, left) { this.outsideRenderedLine = outsideRenderedLine; this.originalLeft = left; this.left = Math.round(this.originalLeft); } } class VisibleRanges { constructor(outsideRenderedLine, ranges) { this.outsideRenderedLine = outsideRenderedLine; this.ranges = ranges; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class RangeUtil { static _createRange() { if (!this._handyReadyRange) { this._handyReadyRange = document.createRange(); } return this._handyReadyRange; } static _detachRange(range, endNode) { // Move range out of the span node, IE doesn't like having many ranges in // the same spot and will act badly for lines containing dashes ('-') range.selectNodeContents(endNode); } static _readClientRects(startElement, startOffset, endElement, endOffset, endNode) { const range = this._createRange(); try { range.setStart(startElement, startOffset); range.setEnd(endElement, endOffset); return range.getClientRects(); } catch (e) { // This is life ... return null; } finally { this._detachRange(range, endNode); } } static _mergeAdjacentRanges(ranges) { if (ranges.length === 1) { // There is nothing to merge return ranges; } ranges.sort(FloatHorizontalRange.compare); const result = []; let resultLen = 0; let prev = ranges[0]; for (let i = 1, len = ranges.length; i < len; i++) { const range = ranges[i]; if (prev.left + prev.width + 0.9 /* account for browser's rounding errors*/ >= range.left) { prev.width = Math.max(prev.width, range.left + range.width - prev.left); } else { result[resultLen++] = prev; prev = range; } } result[resultLen++] = prev; return result; } static _createHorizontalRangesFromClientRects(clientRects, clientRectDeltaLeft, clientRectScale) { if (!clientRects || clientRects.length === 0) { return null; } // We go through FloatHorizontalRange because it has been observed in bi-di text // that the clientRects are not coming in sorted from the browser const result = []; for (let i = 0, len = clientRects.length; i < len; i++) { const clientRect = clientRects[i]; result[i] = new FloatHorizontalRange(Math.max(0, (clientRect.left - clientRectDeltaLeft) / clientRectScale), clientRect.width / clientRectScale); } return this._mergeAdjacentRanges(result); } static readHorizontalRanges(domNode, startChildIndex, startOffset, endChildIndex, endOffset, clientRectDeltaLeft, clientRectScale, endNode) { // Panic check const min = 0; const max = domNode.children.length - 1; if (min > max) { return null; } startChildIndex = Math.min(max, Math.max(min, startChildIndex)); endChildIndex = Math.min(max, Math.max(min, endChildIndex)); if (startChildIndex === endChildIndex && startOffset === endOffset && startOffset === 0 && !domNode.children[startChildIndex].firstChild) { // We must find the position at the beginning of a // To cover cases of empty s, avoid using a range and use the 's bounding box const clientRects = domNode.children[startChildIndex].getClientRects(); return this._createHorizontalRangesFromClientRects(clientRects, clientRectDeltaLeft, clientRectScale); } // If crossing over to a span only to select offset 0, then use the previous span's maximum offset // Chrome is buggy and doesn't handle 0 offsets well sometimes. if (startChildIndex !== endChildIndex) { if (endChildIndex > 0 && endOffset === 0) { endChildIndex--; endOffset = 1073741824 /* MAX_SAFE_SMALL_INTEGER */; } } let startElement = domNode.children[startChildIndex].firstChild; let endElement = domNode.children[endChildIndex].firstChild; if (!startElement || !endElement) { // When having an empty (without any text content), try to move to the previous if (!startElement && startOffset === 0 && startChildIndex > 0) { startElement = domNode.children[startChildIndex - 1].firstChild; startOffset = 1073741824 /* MAX_SAFE_SMALL_INTEGER */; } if (!endElement && endOffset === 0 && endChildIndex > 0) { endElement = domNode.children[endChildIndex - 1].firstChild; endOffset = 1073741824 /* MAX_SAFE_SMALL_INTEGER */; } } if (!startElement || !endElement) { return null; } startOffset = Math.min(startElement.textContent.length, Math.max(0, startOffset)); endOffset = Math.min(endElement.textContent.length, Math.max(0, endOffset)); const clientRects = this._readClientRects(startElement, startOffset, endElement, endOffset, endNode); return this._createHorizontalRangesFromClientRects(clientRects, clientRectDeltaLeft, clientRectScale); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const canUseFastRenderedViewLine = (function () { if (isNative) { // In VSCode we know very well when the zoom level changes return true; } if (isLinux || isFirefox || isSafari) { // On Linux, it appears that zooming affects char widths (in pixels), which is unexpected. // -- // Even though we read character widths correctly, having read them at a specific zoom level // does not mean they are the same at the current zoom level. // -- // This could be improved if we ever figure out how to get an event when browsers zoom, // but until then we have to stick with reading client rects. // -- // The same has been observed with Firefox on Windows7 // -- // The same has been oversved with Safari return false; } return true; })(); let monospaceAssumptionsAreValid = true; class DomReadingContext { constructor(domNode, endNode) { this._domNode = domNode; this._clientRectDeltaLeft = 0; this._clientRectScale = 1; this._clientRectRead = false; this.endNode = endNode; } readClientRect() { if (!this._clientRectRead) { this._clientRectRead = true; const rect = this._domNode.getBoundingClientRect(); this._clientRectDeltaLeft = rect.left; this._clientRectScale = rect.width / this._domNode.offsetWidth; } } get clientRectDeltaLeft() { if (!this._clientRectRead) { this.readClientRect(); } return this._clientRectDeltaLeft; } get clientRectScale() { if (!this._clientRectRead) { this.readClientRect(); } return this._clientRectScale; } } class ViewLineOptions { constructor(config, themeType) { this.themeType = themeType; const options = config.options; const fontInfo = options.get(44 /* fontInfo */); this.renderWhitespace = options.get(88 /* renderWhitespace */); this.renderControlCharacters = options.get(83 /* renderControlCharacters */); this.spaceWidth = fontInfo.spaceWidth; this.middotWidth = fontInfo.middotWidth; this.wsmiddotWidth = fontInfo.wsmiddotWidth; this.useMonospaceOptimizations = (fontInfo.isMonospace && !options.get(29 /* disableMonospaceOptimizations */)); this.canUseHalfwidthRightwardsArrow = fontInfo.canUseHalfwidthRightwardsArrow; this.lineHeight = options.get(59 /* lineHeight */); this.stopRenderingLineAfter = options.get(105 /* stopRenderingLineAfter */); this.fontLigatures = options.get(45 /* fontLigatures */); } equals(other) { return (this.themeType === other.themeType && this.renderWhitespace === other.renderWhitespace && this.renderControlCharacters === other.renderControlCharacters && this.spaceWidth === other.spaceWidth && this.middotWidth === other.middotWidth && this.wsmiddotWidth === other.wsmiddotWidth && this.useMonospaceOptimizations === other.useMonospaceOptimizations && this.canUseHalfwidthRightwardsArrow === other.canUseHalfwidthRightwardsArrow && this.lineHeight === other.lineHeight && this.stopRenderingLineAfter === other.stopRenderingLineAfter && this.fontLigatures === other.fontLigatures); } } class ViewLine { constructor(options) { this._options = options; this._isMaybeInvalid = true; this._renderedViewLine = null; } // --- begin IVisibleLineData getDomNode() { if (this._renderedViewLine && this._renderedViewLine.domNode) { return this._renderedViewLine.domNode.domNode; } return null; } setDomNode(domNode) { if (this._renderedViewLine) { this._renderedViewLine.domNode = createFastDomNode(domNode); } else { throw new Error('I have no rendered view line to set the dom node to...'); } } onContentChanged() { this._isMaybeInvalid = true; } onTokensChanged() { this._isMaybeInvalid = true; } onDecorationsChanged() { this._isMaybeInvalid = true; } onOptionsChanged(newOptions) { this._isMaybeInvalid = true; this._options = newOptions; } onSelectionChanged() { if (this._options.themeType === ColorScheme.HIGH_CONTRAST || this._options.renderWhitespace === 'selection') { this._isMaybeInvalid = true; return true; } return false; } renderLine(lineNumber, deltaTop, viewportData, sb) { if (this._isMaybeInvalid === false) { // it appears that nothing relevant has changed return false; } this._isMaybeInvalid = false; const lineData = viewportData.getViewLineRenderingData(lineNumber); const options = this._options; const actualInlineDecorations = LineDecoration.filter(lineData.inlineDecorations, lineNumber, lineData.minColumn, lineData.maxColumn); // Only send selection information when needed for rendering whitespace let selectionsOnLine = null; if (options.themeType === ColorScheme.HIGH_CONTRAST || this._options.renderWhitespace === 'selection') { const selections = viewportData.selections; for (const selection of selections) { if (selection.endLineNumber < lineNumber || selection.startLineNumber > lineNumber) { // Selection does not intersect line continue; } const startColumn = (selection.startLineNumber === lineNumber ? selection.startColumn : lineData.minColumn); const endColumn = (selection.endLineNumber === lineNumber ? selection.endColumn : lineData.maxColumn); if (startColumn < endColumn) { if (options.themeType === ColorScheme.HIGH_CONTRAST || this._options.renderWhitespace !== 'selection') { actualInlineDecorations.push(new LineDecoration(startColumn, endColumn, 'inline-selected-text', 0 /* Regular */)); } else { if (!selectionsOnLine) { selectionsOnLine = []; } selectionsOnLine.push(new LineRange(startColumn - 1, endColumn - 1)); } } } } const renderLineInput = new RenderLineInput(options.useMonospaceOptimizations, options.canUseHalfwidthRightwardsArrow, lineData.content, lineData.continuesWithWrappedLine, lineData.isBasicASCII, lineData.containsRTL, lineData.minColumn - 1, lineData.tokens, actualInlineDecorations, lineData.tabSize, lineData.startVisibleColumn, options.spaceWidth, options.middotWidth, options.wsmiddotWidth, options.stopRenderingLineAfter, options.renderWhitespace, options.renderControlCharacters, options.fontLigatures !== EditorFontLigatures.OFF, selectionsOnLine); if (this._renderedViewLine && this._renderedViewLine.input.equals(renderLineInput)) { // no need to do anything, we have the same render input return false; } sb.appendASCIIString('
'); const output = renderViewLine(renderLineInput, sb); sb.appendASCIIString('
'); let renderedViewLine = null; if (monospaceAssumptionsAreValid && canUseFastRenderedViewLine && lineData.isBasicASCII && options.useMonospaceOptimizations && output.containsForeignElements === 0 /* None */) { if (lineData.content.length < 300 && renderLineInput.lineTokens.getCount() < 100) { // Browser rounding errors have been observed in Chrome and IE, so using the fast // view line only for short lines. Please test before removing the length check... // --- // Another rounding error has been observed on Linux in VSCode, where width // rounding errors add up to an observable large number... // --- // Also see another example of rounding errors on Windows in // https://github.com/microsoft/vscode/issues/33178 renderedViewLine = new FastRenderedViewLine(this._renderedViewLine ? this._renderedViewLine.domNode : null, renderLineInput, output.characterMapping); } } if (!renderedViewLine) { renderedViewLine = createRenderedLine(this._renderedViewLine ? this._renderedViewLine.domNode : null, renderLineInput, output.characterMapping, output.containsRTL, output.containsForeignElements); } this._renderedViewLine = renderedViewLine; return true; } layoutLine(lineNumber, deltaTop) { if (this._renderedViewLine && this._renderedViewLine.domNode) { this._renderedViewLine.domNode.setTop(deltaTop); this._renderedViewLine.domNode.setHeight(this._options.lineHeight); } } // --- end IVisibleLineData getWidth() { if (!this._renderedViewLine) { return 0; } return this._renderedViewLine.getWidth(); } getWidthIsFast() { if (!this._renderedViewLine) { return true; } return this._renderedViewLine.getWidthIsFast(); } needsMonospaceFontCheck() { if (!this._renderedViewLine) { return false; } return (this._renderedViewLine instanceof FastRenderedViewLine); } monospaceAssumptionsAreValid() { if (!this._renderedViewLine) { return monospaceAssumptionsAreValid; } if (this._renderedViewLine instanceof FastRenderedViewLine) { return this._renderedViewLine.monospaceAssumptionsAreValid(); } return monospaceAssumptionsAreValid; } onMonospaceAssumptionsInvalidated() { if (this._renderedViewLine && this._renderedViewLine instanceof FastRenderedViewLine) { this._renderedViewLine = this._renderedViewLine.toSlowRenderedLine(); } } getVisibleRangesForRange(lineNumber, startColumn, endColumn, context) { if (!this._renderedViewLine) { return null; } startColumn = Math.min(this._renderedViewLine.input.lineContent.length + 1, Math.max(1, startColumn)); endColumn = Math.min(this._renderedViewLine.input.lineContent.length + 1, Math.max(1, endColumn)); const stopRenderingLineAfter = this._renderedViewLine.input.stopRenderingLineAfter; let outsideRenderedLine = false; if (stopRenderingLineAfter !== -1 && startColumn > stopRenderingLineAfter + 1 && endColumn > stopRenderingLineAfter + 1) { // This range is obviously not visible outsideRenderedLine = true; } if (stopRenderingLineAfter !== -1 && startColumn > stopRenderingLineAfter + 1) { startColumn = stopRenderingLineAfter + 1; } if (stopRenderingLineAfter !== -1 && endColumn > stopRenderingLineAfter + 1) { endColumn = stopRenderingLineAfter + 1; } const horizontalRanges = this._renderedViewLine.getVisibleRangesForRange(lineNumber, startColumn, endColumn, context); if (horizontalRanges && horizontalRanges.length > 0) { return new VisibleRanges(outsideRenderedLine, horizontalRanges); } return null; } getColumnOfNodeOffset(lineNumber, spanNode, offset) { if (!this._renderedViewLine) { return 1; } return this._renderedViewLine.getColumnOfNodeOffset(lineNumber, spanNode, offset); } } ViewLine.CLASS_NAME = 'view-line'; /** * A rendered line which is guaranteed to contain only regular ASCII and is rendered with a monospace font. */ class FastRenderedViewLine { constructor(domNode, renderLineInput, characterMapping) { this.domNode = domNode; this.input = renderLineInput; this._characterMapping = characterMapping; this._charWidth = renderLineInput.spaceWidth; } getWidth() { return Math.round(this._getCharPosition(this._characterMapping.length)); } getWidthIsFast() { return true; } monospaceAssumptionsAreValid() { if (!this.domNode) { return monospaceAssumptionsAreValid; } const expectedWidth = this.getWidth(); const actualWidth = this.domNode.domNode.firstChild.offsetWidth; if (Math.abs(expectedWidth - actualWidth) >= 2) { // more than 2px off console.warn(`monospace assumptions have been violated, therefore disabling monospace optimizations!`); monospaceAssumptionsAreValid = false; } return monospaceAssumptionsAreValid; } toSlowRenderedLine() { return createRenderedLine(this.domNode, this.input, this._characterMapping, false, 0 /* None */); } getVisibleRangesForRange(lineNumber, startColumn, endColumn, context) { const startPosition = this._getCharPosition(startColumn); const endPosition = this._getCharPosition(endColumn); return [new FloatHorizontalRange(startPosition, endPosition - startPosition)]; } _getCharPosition(column) { const charOffset = this._characterMapping.getAbsoluteOffset(column); return this._charWidth * charOffset; } getColumnOfNodeOffset(lineNumber, spanNode, offset) { const spanNodeTextContentLength = spanNode.textContent.length; let spanIndex = -1; while (spanNode) { spanNode = spanNode.previousSibling; spanIndex++; } return this._characterMapping.getColumn(new DomPosition(spanIndex, offset), spanNodeTextContentLength); } } /** * Every time we render a line, we save what we have rendered in an instance of this class. */ class RenderedViewLine { constructor(domNode, renderLineInput, characterMapping, containsRTL, containsForeignElements) { this.domNode = domNode; this.input = renderLineInput; this._characterMapping = characterMapping; this._isWhitespaceOnly = /^\s*$/.test(renderLineInput.lineContent); this._containsForeignElements = containsForeignElements; this._cachedWidth = -1; this._pixelOffsetCache = null; if (!containsRTL || this._characterMapping.length === 0 /* the line is empty */) { this._pixelOffsetCache = new Float32Array(Math.max(2, this._characterMapping.length + 1)); for (let column = 0, len = this._characterMapping.length; column <= len; column++) { this._pixelOffsetCache[column] = -1; } } } // --- Reading from the DOM methods _getReadingTarget(myDomNode) { return myDomNode.domNode.firstChild; } /** * Width of the line in pixels */ getWidth() { if (!this.domNode) { return 0; } if (this._cachedWidth === -1) { this._cachedWidth = this._getReadingTarget(this.domNode).offsetWidth; } return this._cachedWidth; } getWidthIsFast() { if (this._cachedWidth === -1) { return false; } return true; } /** * Visible ranges for a model range */ getVisibleRangesForRange(lineNumber, startColumn, endColumn, context) { if (!this.domNode) { return null; } if (this._pixelOffsetCache !== null) { // the text is LTR const startOffset = this._readPixelOffset(this.domNode, lineNumber, startColumn, context); if (startOffset === -1) { return null; } const endOffset = this._readPixelOffset(this.domNode, lineNumber, endColumn, context); if (endOffset === -1) { return null; } return [new FloatHorizontalRange(startOffset, endOffset - startOffset)]; } return this._readVisibleRangesForRange(this.domNode, lineNumber, startColumn, endColumn, context); } _readVisibleRangesForRange(domNode, lineNumber, startColumn, endColumn, context) { if (startColumn === endColumn) { const pixelOffset = this._readPixelOffset(domNode, lineNumber, startColumn, context); if (pixelOffset === -1) { return null; } else { return [new FloatHorizontalRange(pixelOffset, 0)]; } } else { return this._readRawVisibleRangesForRange(domNode, startColumn, endColumn, context); } } _readPixelOffset(domNode, lineNumber, column, context) { if (this._characterMapping.length === 0) { // This line has no content if (this._containsForeignElements === 0 /* None */) { // We can assume the line is really empty return 0; } if (this._containsForeignElements === 2 /* After */) { // We have foreign elements after the (empty) line return 0; } if (this._containsForeignElements === 1 /* Before */) { // We have foreign elements before the (empty) line return this.getWidth(); } // We have foreign elements before & after the (empty) line const readingTarget = this._getReadingTarget(domNode); if (readingTarget.firstChild) { return readingTarget.firstChild.offsetWidth; } else { return 0; } } if (this._pixelOffsetCache !== null) { // the text is LTR const cachedPixelOffset = this._pixelOffsetCache[column]; if (cachedPixelOffset !== -1) { return cachedPixelOffset; } const result = this._actualReadPixelOffset(domNode, lineNumber, column, context); this._pixelOffsetCache[column] = result; return result; } return this._actualReadPixelOffset(domNode, lineNumber, column, context); } _actualReadPixelOffset(domNode, lineNumber, column, context) { if (this._characterMapping.length === 0) { // This line has no content const r = RangeUtil.readHorizontalRanges(this._getReadingTarget(domNode), 0, 0, 0, 0, context.clientRectDeltaLeft, context.clientRectScale, context.endNode); if (!r || r.length === 0) { return -1; } return r[0].left; } if (column === this._characterMapping.length && this._isWhitespaceOnly && this._containsForeignElements === 0 /* None */) { // This branch helps in the case of whitespace only lines which have a width set return this.getWidth(); } const domPosition = this._characterMapping.getDomPosition(column); const r = RangeUtil.readHorizontalRanges(this._getReadingTarget(domNode), domPosition.partIndex, domPosition.charIndex, domPosition.partIndex, domPosition.charIndex, context.clientRectDeltaLeft, context.clientRectScale, context.endNode); if (!r || r.length === 0) { return -1; } const result = r[0].left; if (this.input.isBasicASCII) { const charOffset = this._characterMapping.getAbsoluteOffset(column); const expectedResult = Math.round(this.input.spaceWidth * charOffset); if (Math.abs(expectedResult - result) <= 1) { return expectedResult; } } return result; } _readRawVisibleRangesForRange(domNode, startColumn, endColumn, context) { if (startColumn === 1 && endColumn === this._characterMapping.length) { // This branch helps IE with bidi text & gives a performance boost to other browsers when reading visible ranges for an entire line return [new FloatHorizontalRange(0, this.getWidth())]; } const startDomPosition = this._characterMapping.getDomPosition(startColumn); const endDomPosition = this._characterMapping.getDomPosition(endColumn); return RangeUtil.readHorizontalRanges(this._getReadingTarget(domNode), startDomPosition.partIndex, startDomPosition.charIndex, endDomPosition.partIndex, endDomPosition.charIndex, context.clientRectDeltaLeft, context.clientRectScale, context.endNode); } /** * Returns the column for the text found at a specific offset inside a rendered dom node */ getColumnOfNodeOffset(lineNumber, spanNode, offset) { const spanNodeTextContentLength = spanNode.textContent.length; let spanIndex = -1; while (spanNode) { spanNode = spanNode.previousSibling; spanIndex++; } return this._characterMapping.getColumn(new DomPosition(spanIndex, offset), spanNodeTextContentLength); } } class WebKitRenderedViewLine extends RenderedViewLine { _readVisibleRangesForRange(domNode, lineNumber, startColumn, endColumn, context) { const output = super._readVisibleRangesForRange(domNode, lineNumber, startColumn, endColumn, context); if (!output || output.length === 0 || startColumn === endColumn || (startColumn === 1 && endColumn === this._characterMapping.length)) { return output; } // WebKit is buggy and returns an expanded range (to contain words in some cases) // The last client rect is enlarged (I think) if (!this.input.containsRTL) { // This is an attempt to patch things up // Find position of last column const endPixelOffset = this._readPixelOffset(domNode, lineNumber, endColumn, context); if (endPixelOffset !== -1) { const lastRange = output[output.length - 1]; if (lastRange.left < endPixelOffset) { // Trim down the width of the last visible range to not go after the last column's position lastRange.width = endPixelOffset - lastRange.left; } } } return output; } } const createRenderedLine = (function () { if (isWebKit) { return createWebKitRenderedLine; } return createNormalRenderedLine; })(); function createWebKitRenderedLine(domNode, renderLineInput, characterMapping, containsRTL, containsForeignElements) { return new WebKitRenderedViewLine(domNode, renderLineInput, characterMapping, containsRTL, containsForeignElements); } function createNormalRenderedLine(domNode, renderLineInput, characterMapping, containsRTL, containsForeignElements) { return new RenderedViewLine(domNode, renderLineInput, characterMapping, containsRTL, containsForeignElements); } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * A column in a position is the gap between two adjacent characters. The methods here * work with a concept called "visible column". A visible column is a very rough approximation * of the horizontal screen position of a column. For example, using a tab size of 4: * ```txt * |||T|ext * | | | \---- column = 4, visible column = 9 * | | \------ column = 3, visible column = 8 * | \------------ column = 2, visible column = 4 * \------------------ column = 1, visible column = 0 * ``` * * **NOTE**: Visual columns do not work well for RTL text or variable-width fonts or characters. * * **NOTE**: These methods work and make sense both on the model and on the view model. */ class CursorColumns { static _nextVisibleColumn(codePoint, visibleColumn, tabSize) { if (codePoint === 9 /* Tab */) { return CursorColumns.nextRenderTabStop(visibleColumn, tabSize); } if (isFullWidthCharacter(codePoint) || isEmojiImprecise(codePoint)) { return visibleColumn + 2; } return visibleColumn + 1; } /** * Returns a visible column from a column. * @see {@link CursorColumns} */ static visibleColumnFromColumn(lineContent, column, tabSize) { const textLen = Math.min(column - 1, lineContent.length); const text = lineContent.substring(0, textLen); const iterator = new GraphemeIterator(text); let result = 0; while (!iterator.eol()) { const codePoint = getNextCodePoint(text, textLen, iterator.offset); iterator.nextGraphemeLength(); result = this._nextVisibleColumn(codePoint, result, tabSize); } return result; } /** * Returns a column from a visible column. * @see {@link CursorColumns} */ static columnFromVisibleColumn(lineContent, visibleColumn, tabSize) { if (visibleColumn <= 0) { return 1; } const lineContentLength = lineContent.length; const iterator = new GraphemeIterator(lineContent); let beforeVisibleColumn = 0; let beforeColumn = 1; while (!iterator.eol()) { const codePoint = getNextCodePoint(lineContent, lineContentLength, iterator.offset); iterator.nextGraphemeLength(); const afterVisibleColumn = this._nextVisibleColumn(codePoint, beforeVisibleColumn, tabSize); const afterColumn = iterator.offset + 1; if (afterVisibleColumn >= visibleColumn) { const beforeDelta = visibleColumn - beforeVisibleColumn; const afterDelta = afterVisibleColumn - visibleColumn; if (afterDelta < beforeDelta) { return afterColumn; } else { return beforeColumn; } } beforeVisibleColumn = afterVisibleColumn; beforeColumn = afterColumn; } // walked the entire string return lineContentLength + 1; } /** * ATTENTION: This works with 0-based columns (as oposed to the regular 1-based columns) * @see {@link CursorColumns} */ static nextRenderTabStop(visibleColumn, tabSize) { return visibleColumn + tabSize - visibleColumn % tabSize; } /** * ATTENTION: This works with 0-based columns (as oposed to the regular 1-based columns) * @see {@link CursorColumns} */ static nextIndentTabStop(visibleColumn, indentSize) { return visibleColumn + indentSize - visibleColumn % indentSize; } /** * ATTENTION: This works with 0-based columns (as opposed to the regular 1-based columns) * @see {@link CursorColumns} */ static prevRenderTabStop(column, tabSize) { return Math.max(0, column - 1 - (column - 1) % tabSize); } /** * ATTENTION: This works with 0-based columns (as opposed to the regular 1-based columns) * @see {@link CursorColumns} */ static prevIndentTabStop(column, indentSize) { return Math.max(0, column - 1 - (column - 1) % indentSize); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class AtomicTabMoveOperations { /** * Get the visible column at the position. If we get to a non-whitespace character first * or past the end of string then return -1. * * **Note** `position` and the return value are 0-based. */ static whitespaceVisibleColumn(lineContent, position, tabSize) { const lineLength = lineContent.length; let visibleColumn = 0; let prevTabStopPosition = -1; let prevTabStopVisibleColumn = -1; for (let i = 0; i < lineLength; i++) { if (i === position) { return [prevTabStopPosition, prevTabStopVisibleColumn, visibleColumn]; } if (visibleColumn % tabSize === 0) { prevTabStopPosition = i; prevTabStopVisibleColumn = visibleColumn; } const chCode = lineContent.charCodeAt(i); switch (chCode) { case 32 /* Space */: visibleColumn += 1; break; case 9 /* Tab */: // Skip to the next multiple of tabSize. visibleColumn = CursorColumns.nextRenderTabStop(visibleColumn, tabSize); break; default: return [-1, -1, -1]; } } if (position === lineLength) { return [prevTabStopPosition, prevTabStopVisibleColumn, visibleColumn]; } return [-1, -1, -1]; } /** * Return the position that should result from a move left, right or to the * nearest tab, if atomic tabs are enabled. Left and right are used for the * arrow key movements, nearest is used for mouse selection. It returns * -1 if atomic tabs are not relevant and you should fall back to normal * behaviour. * * **Note**: `position` and the return value are 0-based. */ static atomicPosition(lineContent, position, tabSize, direction) { const lineLength = lineContent.length; // Get the 0-based visible column corresponding to the position, or return // -1 if it is not in the initial whitespace. const [prevTabStopPosition, prevTabStopVisibleColumn, visibleColumn] = AtomicTabMoveOperations.whitespaceVisibleColumn(lineContent, position, tabSize); if (visibleColumn === -1) { return -1; } // Is the output left or right of the current position. The case for nearest // where it is the same as the current position is handled in the switch. let left; switch (direction) { case 0 /* Left */: left = true; break; case 1 /* Right */: left = false; break; case 2 /* Nearest */: // The code below assumes the output position is either left or right // of the input position. If it is the same, return immediately. if (visibleColumn % tabSize === 0) { return position; } // Go to the nearest indentation. left = visibleColumn % tabSize <= (tabSize / 2); break; } // If going left, we can just use the info about the last tab stop position and // last tab stop visible column that we computed in the first walk over the whitespace. if (left) { if (prevTabStopPosition === -1) { return -1; } // If the direction is left, we need to keep scanning right to ensure // that targetVisibleColumn + tabSize is before non-whitespace. // This is so that when we press left at the end of a partial // indentation it only goes one character. For example ' foo' with // tabSize 4, should jump from position 6 to position 5, not 4. let currentVisibleColumn = prevTabStopVisibleColumn; for (let i = prevTabStopPosition; i < lineLength; ++i) { if (currentVisibleColumn === prevTabStopVisibleColumn + tabSize) { // It is a full indentation. return prevTabStopPosition; } const chCode = lineContent.charCodeAt(i); switch (chCode) { case 32 /* Space */: currentVisibleColumn += 1; break; case 9 /* Tab */: currentVisibleColumn = CursorColumns.nextRenderTabStop(currentVisibleColumn, tabSize); break; default: return -1; } } if (currentVisibleColumn === prevTabStopVisibleColumn + tabSize) { return prevTabStopPosition; } // It must have been a partial indentation. return -1; } // We are going right. const targetVisibleColumn = CursorColumns.nextRenderTabStop(visibleColumn, tabSize); // We can just continue from where whitespaceVisibleColumn got to. let currentVisibleColumn = visibleColumn; for (let i = position; i < lineLength; i++) { if (currentVisibleColumn === targetVisibleColumn) { return i; } const chCode = lineContent.charCodeAt(i); switch (chCode) { case 32 /* Space */: currentVisibleColumn += 1; break; case 9 /* Tab */: currentVisibleColumn = CursorColumns.nextRenderTabStop(currentVisibleColumn, tabSize); break; default: return -1; } } // This condition handles when the target column is at the end of the line. if (currentVisibleColumn === targetVisibleColumn) { return lineLength; } return -1; } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class UnknownHitTestResult { constructor(hitTarget = null) { this.hitTarget = hitTarget; this.type = 0 /* Unknown */; } } class ContentHitTestResult { constructor(position, spanNode, injectedText) { this.position = position; this.spanNode = spanNode; this.injectedText = injectedText; this.type = 1 /* Content */; } } var HitTestResult; (function (HitTestResult) { function createFromDOMInfo(ctx, spanNode, offset) { const position = ctx.getPositionFromDOMInfo(spanNode, offset); if (position) { return new ContentHitTestResult(position, spanNode, null); } return new UnknownHitTestResult(spanNode); } HitTestResult.createFromDOMInfo = createFromDOMInfo; })(HitTestResult || (HitTestResult = {})); class PointerHandlerLastRenderData { constructor(lastViewCursorsRenderData, lastTextareaPosition) { this.lastViewCursorsRenderData = lastViewCursorsRenderData; this.lastTextareaPosition = lastTextareaPosition; } } class MouseTarget { static _deduceRage(position, range = null) { if (!range && position) { return new Range$5(position.lineNumber, position.column, position.lineNumber, position.column); } return range !== null && range !== void 0 ? range : null; } static createUnknown(element, mouseColumn, position) { return { type: 0 /* UNKNOWN */, element, mouseColumn, position, range: this._deduceRage(position) }; } static createTextarea(element, mouseColumn) { return { type: 1 /* TEXTAREA */, element, mouseColumn, position: null, range: null }; } static createMargin(type, element, mouseColumn, position, range, detail) { return { type, element, mouseColumn, position, range, detail }; } static createViewZone(type, element, mouseColumn, position, detail) { return { type, element, mouseColumn, position, range: this._deduceRage(position), detail }; } static createContentText(element, mouseColumn, position, range, detail) { return { type: 6 /* CONTENT_TEXT */, element, mouseColumn, position, range: this._deduceRage(position, range), detail }; } static createContentEmpty(element, mouseColumn, position, detail) { return { type: 7 /* CONTENT_EMPTY */, element, mouseColumn, position, range: this._deduceRage(position), detail }; } static createContentWidget(element, mouseColumn, detail) { return { type: 9 /* CONTENT_WIDGET */, element, mouseColumn, position: null, range: null, detail }; } static createScrollbar(element, mouseColumn, position) { return { type: 11 /* SCROLLBAR */, element, mouseColumn, position, range: this._deduceRage(position) }; } static createOverlayWidget(element, mouseColumn, detail) { return { type: 12 /* OVERLAY_WIDGET */, element, mouseColumn, position: null, range: null, detail }; } static createOutsideEditor(mouseColumn, position) { return { type: 13 /* OUTSIDE_EDITOR */, element: null, mouseColumn, position, range: this._deduceRage(position) }; } static _typeToString(type) { if (type === 1 /* TEXTAREA */) { return 'TEXTAREA'; } if (type === 2 /* GUTTER_GLYPH_MARGIN */) { return 'GUTTER_GLYPH_MARGIN'; } if (type === 3 /* GUTTER_LINE_NUMBERS */) { return 'GUTTER_LINE_NUMBERS'; } if (type === 4 /* GUTTER_LINE_DECORATIONS */) { return 'GUTTER_LINE_DECORATIONS'; } if (type === 5 /* GUTTER_VIEW_ZONE */) { return 'GUTTER_VIEW_ZONE'; } if (type === 6 /* CONTENT_TEXT */) { return 'CONTENT_TEXT'; } if (type === 7 /* CONTENT_EMPTY */) { return 'CONTENT_EMPTY'; } if (type === 8 /* CONTENT_VIEW_ZONE */) { return 'CONTENT_VIEW_ZONE'; } if (type === 9 /* CONTENT_WIDGET */) { return 'CONTENT_WIDGET'; } if (type === 10 /* OVERVIEW_RULER */) { return 'OVERVIEW_RULER'; } if (type === 11 /* SCROLLBAR */) { return 'SCROLLBAR'; } if (type === 12 /* OVERLAY_WIDGET */) { return 'OVERLAY_WIDGET'; } return 'UNKNOWN'; } static toString(target) { return this._typeToString(target.type) + ': ' + target.position + ' - ' + target.range + ' - ' + JSON.stringify(target.detail); } } class ElementPath { static isTextArea(path) { return (path.length === 2 && path[0] === 3 /* OverflowGuard */ && path[1] === 6 /* TextArea */); } static isChildOfViewLines(path) { return (path.length >= 4 && path[0] === 3 /* OverflowGuard */ && path[3] === 7 /* ViewLines */); } static isStrictChildOfViewLines(path) { return (path.length > 4 && path[0] === 3 /* OverflowGuard */ && path[3] === 7 /* ViewLines */); } static isChildOfScrollableElement(path) { return (path.length >= 2 && path[0] === 3 /* OverflowGuard */ && path[1] === 5 /* ScrollableElement */); } static isChildOfMinimap(path) { return (path.length >= 2 && path[0] === 3 /* OverflowGuard */ && path[1] === 8 /* Minimap */); } static isChildOfContentWidgets(path) { return (path.length >= 4 && path[0] === 3 /* OverflowGuard */ && path[3] === 1 /* ContentWidgets */); } static isChildOfOverflowingContentWidgets(path) { return (path.length >= 1 && path[0] === 2 /* OverflowingContentWidgets */); } static isChildOfOverlayWidgets(path) { return (path.length >= 2 && path[0] === 3 /* OverflowGuard */ && path[1] === 4 /* OverlayWidgets */); } } class HitTestContext { constructor(context, viewHelper, lastRenderData) { this.model = context.model; const options = context.configuration.options; this.layoutInfo = options.get(131 /* layoutInfo */); this.viewDomNode = viewHelper.viewDomNode; this.lineHeight = options.get(59 /* lineHeight */); this.stickyTabStops = options.get(104 /* stickyTabStops */); this.typicalHalfwidthCharacterWidth = options.get(44 /* fontInfo */).typicalHalfwidthCharacterWidth; this.lastRenderData = lastRenderData; this._context = context; this._viewHelper = viewHelper; } getZoneAtCoord(mouseVerticalOffset) { return HitTestContext.getZoneAtCoord(this._context, mouseVerticalOffset); } static getZoneAtCoord(context, mouseVerticalOffset) { // The target is either a view zone or the empty space after the last view-line const viewZoneWhitespace = context.viewLayout.getWhitespaceAtVerticalOffset(mouseVerticalOffset); if (viewZoneWhitespace) { const viewZoneMiddle = viewZoneWhitespace.verticalOffset + viewZoneWhitespace.height / 2; const lineCount = context.model.getLineCount(); let positionBefore = null; let position; let positionAfter = null; if (viewZoneWhitespace.afterLineNumber !== lineCount) { // There are more lines after this view zone positionAfter = new Position$4(viewZoneWhitespace.afterLineNumber + 1, 1); } if (viewZoneWhitespace.afterLineNumber > 0) { // There are more lines above this view zone positionBefore = new Position$4(viewZoneWhitespace.afterLineNumber, context.model.getLineMaxColumn(viewZoneWhitespace.afterLineNumber)); } if (positionAfter === null) { position = positionBefore; } else if (positionBefore === null) { position = positionAfter; } else if (mouseVerticalOffset < viewZoneMiddle) { position = positionBefore; } else { position = positionAfter; } return { viewZoneId: viewZoneWhitespace.id, afterLineNumber: viewZoneWhitespace.afterLineNumber, positionBefore: positionBefore, positionAfter: positionAfter, position: position }; } return null; } getFullLineRangeAtCoord(mouseVerticalOffset) { if (this._context.viewLayout.isAfterLines(mouseVerticalOffset)) { // Below the last line const lineNumber = this._context.model.getLineCount(); const maxLineColumn = this._context.model.getLineMaxColumn(lineNumber); return { range: new Range$5(lineNumber, maxLineColumn, lineNumber, maxLineColumn), isAfterLines: true }; } const lineNumber = this._context.viewLayout.getLineNumberAtVerticalOffset(mouseVerticalOffset); const maxLineColumn = this._context.model.getLineMaxColumn(lineNumber); return { range: new Range$5(lineNumber, 1, lineNumber, maxLineColumn), isAfterLines: false }; } getLineNumberAtVerticalOffset(mouseVerticalOffset) { return this._context.viewLayout.getLineNumberAtVerticalOffset(mouseVerticalOffset); } isAfterLines(mouseVerticalOffset) { return this._context.viewLayout.isAfterLines(mouseVerticalOffset); } isInTopPadding(mouseVerticalOffset) { return this._context.viewLayout.isInTopPadding(mouseVerticalOffset); } isInBottomPadding(mouseVerticalOffset) { return this._context.viewLayout.isInBottomPadding(mouseVerticalOffset); } getVerticalOffsetForLineNumber(lineNumber) { return this._context.viewLayout.getVerticalOffsetForLineNumber(lineNumber); } findAttribute(element, attr) { return HitTestContext._findAttribute(element, attr, this._viewHelper.viewDomNode); } static _findAttribute(element, attr, stopAt) { while (element && element !== document.body) { if (element.hasAttribute && element.hasAttribute(attr)) { return element.getAttribute(attr); } if (element === stopAt) { return null; } element = element.parentNode; } return null; } getLineWidth(lineNumber) { return this._viewHelper.getLineWidth(lineNumber); } visibleRangeForPosition(lineNumber, column) { return this._viewHelper.visibleRangeForPosition(lineNumber, column); } getPositionFromDOMInfo(spanNode, offset) { return this._viewHelper.getPositionFromDOMInfo(spanNode, offset); } getCurrentScrollTop() { return this._context.viewLayout.getCurrentScrollTop(); } getCurrentScrollLeft() { return this._context.viewLayout.getCurrentScrollLeft(); } } class BareHitTestRequest { constructor(ctx, editorPos, pos, relativePos) { this.editorPos = editorPos; this.pos = pos; this.relativePos = relativePos; this.mouseVerticalOffset = Math.max(0, ctx.getCurrentScrollTop() + this.relativePos.y); this.mouseContentHorizontalOffset = ctx.getCurrentScrollLeft() + this.relativePos.x - ctx.layoutInfo.contentLeft; this.isInMarginArea = (this.relativePos.x < ctx.layoutInfo.contentLeft && this.relativePos.x >= ctx.layoutInfo.glyphMarginLeft); this.isInContentArea = !this.isInMarginArea; this.mouseColumn = Math.max(0, MouseTargetFactory._getMouseColumn(this.mouseContentHorizontalOffset, ctx.typicalHalfwidthCharacterWidth)); } } class HitTestRequest extends BareHitTestRequest { constructor(ctx, editorPos, pos, relativePos, target) { super(ctx, editorPos, pos, relativePos); this._ctx = ctx; if (target) { this.target = target; this.targetPath = PartFingerprints.collect(target, ctx.viewDomNode); } else { this.target = null; this.targetPath = new Uint8Array(0); } } toString() { return `pos(${this.pos.x},${this.pos.y}), editorPos(${this.editorPos.x},${this.editorPos.y}), relativePos(${this.relativePos.x},${this.relativePos.y}), mouseVerticalOffset: ${this.mouseVerticalOffset}, mouseContentHorizontalOffset: ${this.mouseContentHorizontalOffset}\n\ttarget: ${this.target ? this.target.outerHTML : null}`; } _getMouseColumn(position = null) { if (position && position.column < this._ctx.model.getLineMaxColumn(position.lineNumber)) { // Most likely, the line contains foreign decorations... return CursorColumns.visibleColumnFromColumn(this._ctx.model.getLineContent(position.lineNumber), position.column, this._ctx.model.getTextModelOptions().tabSize) + 1; } return this.mouseColumn; } fulfillUnknown(position = null) { return MouseTarget.createUnknown(this.target, this._getMouseColumn(position), position); } fulfillTextarea() { return MouseTarget.createTextarea(this.target, this._getMouseColumn()); } fulfillMargin(type, position, range, detail) { return MouseTarget.createMargin(type, this.target, this._getMouseColumn(position), position, range, detail); } fulfillViewZone(type, position, detail) { return MouseTarget.createViewZone(type, this.target, this._getMouseColumn(position), position, detail); } fulfillContentText(position, range, detail) { return MouseTarget.createContentText(this.target, this._getMouseColumn(position), position, range, detail); } fulfillContentEmpty(position, detail) { return MouseTarget.createContentEmpty(this.target, this._getMouseColumn(position), position, detail); } fulfillContentWidget(detail) { return MouseTarget.createContentWidget(this.target, this._getMouseColumn(), detail); } fulfillScrollbar(position) { return MouseTarget.createScrollbar(this.target, this._getMouseColumn(position), position); } fulfillOverlayWidget(detail) { return MouseTarget.createOverlayWidget(this.target, this._getMouseColumn(), detail); } withTarget(target) { return new HitTestRequest(this._ctx, this.editorPos, this.pos, this.relativePos, target); } } const EMPTY_CONTENT_AFTER_LINES = { isAfterLines: true }; function createEmptyContentDataInLines(horizontalDistanceToText) { return { isAfterLines: false, horizontalDistanceToText: horizontalDistanceToText }; } class MouseTargetFactory { constructor(context, viewHelper) { this._context = context; this._viewHelper = viewHelper; } mouseTargetIsWidget(e) { const t = e.target; const path = PartFingerprints.collect(t, this._viewHelper.viewDomNode); // Is it a content widget? if (ElementPath.isChildOfContentWidgets(path) || ElementPath.isChildOfOverflowingContentWidgets(path)) { return true; } // Is it an overlay widget? if (ElementPath.isChildOfOverlayWidgets(path)) { return true; } return false; } createMouseTarget(lastRenderData, editorPos, pos, relativePos, target) { const ctx = new HitTestContext(this._context, this._viewHelper, lastRenderData); const request = new HitTestRequest(ctx, editorPos, pos, relativePos, target); try { const r = MouseTargetFactory._createMouseTarget(ctx, request, false); // console.log(MouseTarget.toString(r)); return r; } catch (err) { // console.log(err); return request.fulfillUnknown(); } } static _createMouseTarget(ctx, request, domHitTestExecuted) { // console.log(`${domHitTestExecuted ? '=>' : ''}CAME IN REQUEST: ${request}`); // First ensure the request has a target if (request.target === null) { if (domHitTestExecuted) { // Still no target... and we have already executed hit test... return request.fulfillUnknown(); } const hitTestResult = MouseTargetFactory._doHitTest(ctx, request); if (hitTestResult.type === 1 /* Content */) { return MouseTargetFactory.createMouseTargetFromHitTestPosition(ctx, request, hitTestResult.spanNode, hitTestResult.position, hitTestResult.injectedText); } return this._createMouseTarget(ctx, request.withTarget(hitTestResult.hitTarget), true); } // we know for a fact that request.target is not null const resolvedRequest = request; let result = null; result = result || MouseTargetFactory._hitTestContentWidget(ctx, resolvedRequest); result = result || MouseTargetFactory._hitTestOverlayWidget(ctx, resolvedRequest); result = result || MouseTargetFactory._hitTestMinimap(ctx, resolvedRequest); result = result || MouseTargetFactory._hitTestScrollbarSlider(ctx, resolvedRequest); result = result || MouseTargetFactory._hitTestViewZone(ctx, resolvedRequest); result = result || MouseTargetFactory._hitTestMargin(ctx, resolvedRequest); result = result || MouseTargetFactory._hitTestViewCursor(ctx, resolvedRequest); result = result || MouseTargetFactory._hitTestTextArea(ctx, resolvedRequest); result = result || MouseTargetFactory._hitTestViewLines(ctx, resolvedRequest, domHitTestExecuted); result = result || MouseTargetFactory._hitTestScrollbar(ctx, resolvedRequest); return (result || request.fulfillUnknown()); } static _hitTestContentWidget(ctx, request) { // Is it a content widget? if (ElementPath.isChildOfContentWidgets(request.targetPath) || ElementPath.isChildOfOverflowingContentWidgets(request.targetPath)) { const widgetId = ctx.findAttribute(request.target, 'widgetId'); if (widgetId) { return request.fulfillContentWidget(widgetId); } else { return request.fulfillUnknown(); } } return null; } static _hitTestOverlayWidget(ctx, request) { // Is it an overlay widget? if (ElementPath.isChildOfOverlayWidgets(request.targetPath)) { const widgetId = ctx.findAttribute(request.target, 'widgetId'); if (widgetId) { return request.fulfillOverlayWidget(widgetId); } else { return request.fulfillUnknown(); } } return null; } static _hitTestViewCursor(ctx, request) { if (request.target) { // Check if we've hit a painted cursor const lastViewCursorsRenderData = ctx.lastRenderData.lastViewCursorsRenderData; for (const d of lastViewCursorsRenderData) { if (request.target === d.domNode) { return request.fulfillContentText(d.position, null, { mightBeForeignElement: false, injectedText: null }); } } } if (request.isInContentArea) { // Edge has a bug when hit-testing the exact position of a cursor, // instead of returning the correct dom node, it returns the // first or last rendered view line dom node, therefore help it out // and first check if we are on top of a cursor const lastViewCursorsRenderData = ctx.lastRenderData.lastViewCursorsRenderData; const mouseContentHorizontalOffset = request.mouseContentHorizontalOffset; const mouseVerticalOffset = request.mouseVerticalOffset; for (const d of lastViewCursorsRenderData) { if (mouseContentHorizontalOffset < d.contentLeft) { // mouse position is to the left of the cursor continue; } if (mouseContentHorizontalOffset > d.contentLeft + d.width) { // mouse position is to the right of the cursor continue; } const cursorVerticalOffset = ctx.getVerticalOffsetForLineNumber(d.position.lineNumber); if (cursorVerticalOffset <= mouseVerticalOffset && mouseVerticalOffset <= cursorVerticalOffset + d.height) { return request.fulfillContentText(d.position, null, { mightBeForeignElement: false, injectedText: null }); } } } return null; } static _hitTestViewZone(ctx, request) { const viewZoneData = ctx.getZoneAtCoord(request.mouseVerticalOffset); if (viewZoneData) { const mouseTargetType = (request.isInContentArea ? 8 /* CONTENT_VIEW_ZONE */ : 5 /* GUTTER_VIEW_ZONE */); return request.fulfillViewZone(mouseTargetType, viewZoneData.position, viewZoneData); } return null; } static _hitTestTextArea(ctx, request) { // Is it the textarea? if (ElementPath.isTextArea(request.targetPath)) { if (ctx.lastRenderData.lastTextareaPosition) { return request.fulfillContentText(ctx.lastRenderData.lastTextareaPosition, null, { mightBeForeignElement: false, injectedText: null }); } return request.fulfillTextarea(); } return null; } static _hitTestMargin(ctx, request) { if (request.isInMarginArea) { const res = ctx.getFullLineRangeAtCoord(request.mouseVerticalOffset); const pos = res.range.getStartPosition(); let offset = Math.abs(request.relativePos.x); const detail = { isAfterLines: res.isAfterLines, glyphMarginLeft: ctx.layoutInfo.glyphMarginLeft, glyphMarginWidth: ctx.layoutInfo.glyphMarginWidth, lineNumbersWidth: ctx.layoutInfo.lineNumbersWidth, offsetX: offset }; offset -= ctx.layoutInfo.glyphMarginLeft; if (offset <= ctx.layoutInfo.glyphMarginWidth) { // On the glyph margin return request.fulfillMargin(2 /* GUTTER_GLYPH_MARGIN */, pos, res.range, detail); } offset -= ctx.layoutInfo.glyphMarginWidth; if (offset <= ctx.layoutInfo.lineNumbersWidth) { // On the line numbers return request.fulfillMargin(3 /* GUTTER_LINE_NUMBERS */, pos, res.range, detail); } offset -= ctx.layoutInfo.lineNumbersWidth; // On the line decorations return request.fulfillMargin(4 /* GUTTER_LINE_DECORATIONS */, pos, res.range, detail); } return null; } static _hitTestViewLines(ctx, request, domHitTestExecuted) { if (!ElementPath.isChildOfViewLines(request.targetPath)) { return null; } if (ctx.isInTopPadding(request.mouseVerticalOffset)) { return request.fulfillContentEmpty(new Position$4(1, 1), EMPTY_CONTENT_AFTER_LINES); } // Check if it is below any lines and any view zones if (ctx.isAfterLines(request.mouseVerticalOffset) || ctx.isInBottomPadding(request.mouseVerticalOffset)) { // This most likely indicates it happened after the last view-line const lineCount = ctx.model.getLineCount(); const maxLineColumn = ctx.model.getLineMaxColumn(lineCount); return request.fulfillContentEmpty(new Position$4(lineCount, maxLineColumn), EMPTY_CONTENT_AFTER_LINES); } if (domHitTestExecuted) { // Check if we are hitting a view-line (can happen in the case of inline decorations on empty lines) // See https://github.com/microsoft/vscode/issues/46942 if (ElementPath.isStrictChildOfViewLines(request.targetPath)) { const lineNumber = ctx.getLineNumberAtVerticalOffset(request.mouseVerticalOffset); if (ctx.model.getLineLength(lineNumber) === 0) { const lineWidth = ctx.getLineWidth(lineNumber); const detail = createEmptyContentDataInLines(request.mouseContentHorizontalOffset - lineWidth); return request.fulfillContentEmpty(new Position$4(lineNumber, 1), detail); } const lineWidth = ctx.getLineWidth(lineNumber); if (request.mouseContentHorizontalOffset >= lineWidth) { const detail = createEmptyContentDataInLines(request.mouseContentHorizontalOffset - lineWidth); const pos = new Position$4(lineNumber, ctx.model.getLineMaxColumn(lineNumber)); return request.fulfillContentEmpty(pos, detail); } } // We have already executed hit test... return request.fulfillUnknown(); } const hitTestResult = MouseTargetFactory._doHitTest(ctx, request); if (hitTestResult.type === 1 /* Content */) { return MouseTargetFactory.createMouseTargetFromHitTestPosition(ctx, request, hitTestResult.spanNode, hitTestResult.position, hitTestResult.injectedText); } return this._createMouseTarget(ctx, request.withTarget(hitTestResult.hitTarget), true); } static _hitTestMinimap(ctx, request) { if (ElementPath.isChildOfMinimap(request.targetPath)) { const possibleLineNumber = ctx.getLineNumberAtVerticalOffset(request.mouseVerticalOffset); const maxColumn = ctx.model.getLineMaxColumn(possibleLineNumber); return request.fulfillScrollbar(new Position$4(possibleLineNumber, maxColumn)); } return null; } static _hitTestScrollbarSlider(ctx, request) { if (ElementPath.isChildOfScrollableElement(request.targetPath)) { if (request.target && request.target.nodeType === 1) { const className = request.target.className; if (className && /\b(slider|scrollbar)\b/.test(className)) { const possibleLineNumber = ctx.getLineNumberAtVerticalOffset(request.mouseVerticalOffset); const maxColumn = ctx.model.getLineMaxColumn(possibleLineNumber); return request.fulfillScrollbar(new Position$4(possibleLineNumber, maxColumn)); } } } return null; } static _hitTestScrollbar(ctx, request) { // Is it the overview ruler? // Is it a child of the scrollable element? if (ElementPath.isChildOfScrollableElement(request.targetPath)) { const possibleLineNumber = ctx.getLineNumberAtVerticalOffset(request.mouseVerticalOffset); const maxColumn = ctx.model.getLineMaxColumn(possibleLineNumber); return request.fulfillScrollbar(new Position$4(possibleLineNumber, maxColumn)); } return null; } getMouseColumn(relativePos) { const options = this._context.configuration.options; const layoutInfo = options.get(131 /* layoutInfo */); const mouseContentHorizontalOffset = this._context.viewLayout.getCurrentScrollLeft() + relativePos.x - layoutInfo.contentLeft; return MouseTargetFactory._getMouseColumn(mouseContentHorizontalOffset, options.get(44 /* fontInfo */).typicalHalfwidthCharacterWidth); } static _getMouseColumn(mouseContentHorizontalOffset, typicalHalfwidthCharacterWidth) { if (mouseContentHorizontalOffset < 0) { return 1; } const chars = Math.round(mouseContentHorizontalOffset / typicalHalfwidthCharacterWidth); return (chars + 1); } static createMouseTargetFromHitTestPosition(ctx, request, spanNode, pos, injectedText) { const lineNumber = pos.lineNumber; const column = pos.column; const lineWidth = ctx.getLineWidth(lineNumber); if (request.mouseContentHorizontalOffset > lineWidth) { const detail = createEmptyContentDataInLines(request.mouseContentHorizontalOffset - lineWidth); return request.fulfillContentEmpty(pos, detail); } const visibleRange = ctx.visibleRangeForPosition(lineNumber, column); if (!visibleRange) { return request.fulfillUnknown(pos); } const columnHorizontalOffset = visibleRange.left; if (request.mouseContentHorizontalOffset === columnHorizontalOffset) { return request.fulfillContentText(pos, null, { mightBeForeignElement: !!injectedText, injectedText }); } const points = []; points.push({ offset: visibleRange.left, column: column }); if (column > 1) { const visibleRange = ctx.visibleRangeForPosition(lineNumber, column - 1); if (visibleRange) { points.push({ offset: visibleRange.left, column: column - 1 }); } } const lineMaxColumn = ctx.model.getLineMaxColumn(lineNumber); if (column < lineMaxColumn) { const visibleRange = ctx.visibleRangeForPosition(lineNumber, column + 1); if (visibleRange) { points.push({ offset: visibleRange.left, column: column + 1 }); } } points.sort((a, b) => a.offset - b.offset); const mouseCoordinates = request.pos.toClientCoordinates(); const spanNodeClientRect = spanNode.getBoundingClientRect(); const mouseIsOverSpanNode = (spanNodeClientRect.left <= mouseCoordinates.clientX && mouseCoordinates.clientX <= spanNodeClientRect.right); for (let i = 1; i < points.length; i++) { const prev = points[i - 1]; const curr = points[i]; if (prev.offset <= request.mouseContentHorizontalOffset && request.mouseContentHorizontalOffset <= curr.offset) { const rng = new Range$5(lineNumber, prev.column, lineNumber, curr.column); return request.fulfillContentText(pos, rng, { mightBeForeignElement: !mouseIsOverSpanNode || !!injectedText, injectedText }); } } return request.fulfillContentText(pos, null, { mightBeForeignElement: !mouseIsOverSpanNode || !!injectedText, injectedText }); } /** * Most probably WebKit browsers and Edge */ static _doHitTestWithCaretRangeFromPoint(ctx, request) { // In Chrome, especially on Linux it is possible to click between lines, // so try to adjust the `hity` below so that it lands in the center of a line const lineNumber = ctx.getLineNumberAtVerticalOffset(request.mouseVerticalOffset); const lineVerticalOffset = ctx.getVerticalOffsetForLineNumber(lineNumber); const lineCenteredVerticalOffset = lineVerticalOffset + Math.floor(ctx.lineHeight / 2); let adjustedPageY = request.pos.y + (lineCenteredVerticalOffset - request.mouseVerticalOffset); if (adjustedPageY <= request.editorPos.y) { adjustedPageY = request.editorPos.y + 1; } if (adjustedPageY >= request.editorPos.y + request.editorPos.height) { adjustedPageY = request.editorPos.y + request.editorPos.height - 1; } const adjustedPage = new PageCoordinates(request.pos.x, adjustedPageY); const r = this._actualDoHitTestWithCaretRangeFromPoint(ctx, adjustedPage.toClientCoordinates()); if (r.type === 1 /* Content */) { return r; } // Also try to hit test without the adjustment (for the edge cases that we are near the top or bottom) return this._actualDoHitTestWithCaretRangeFromPoint(ctx, request.pos.toClientCoordinates()); } static _actualDoHitTestWithCaretRangeFromPoint(ctx, coords) { const shadowRoot = getShadowRoot(ctx.viewDomNode); let range; if (shadowRoot) { if (typeof shadowRoot.caretRangeFromPoint === 'undefined') { range = shadowCaretRangeFromPoint(shadowRoot, coords.clientX, coords.clientY); } else { range = shadowRoot.caretRangeFromPoint(coords.clientX, coords.clientY); } } else { range = document.caretRangeFromPoint(coords.clientX, coords.clientY); } if (!range || !range.startContainer) { return new UnknownHitTestResult(); } // Chrome always hits a TEXT_NODE, while Edge sometimes hits a token span const startContainer = range.startContainer; if (startContainer.nodeType === startContainer.TEXT_NODE) { // startContainer is expected to be the token text const parent1 = startContainer.parentNode; // expected to be the token span const parent2 = parent1 ? parent1.parentNode : null; // expected to be the view line container span const parent3 = parent2 ? parent2.parentNode : null; // expected to be the view line div const parent3ClassName = parent3 && parent3.nodeType === parent3.ELEMENT_NODE ? parent3.className : null; if (parent3ClassName === ViewLine.CLASS_NAME) { return HitTestResult.createFromDOMInfo(ctx, parent1, range.startOffset); } else { return new UnknownHitTestResult(startContainer.parentNode); } } else if (startContainer.nodeType === startContainer.ELEMENT_NODE) { // startContainer is expected to be the token span const parent1 = startContainer.parentNode; // expected to be the view line container span const parent2 = parent1 ? parent1.parentNode : null; // expected to be the view line div const parent2ClassName = parent2 && parent2.nodeType === parent2.ELEMENT_NODE ? parent2.className : null; if (parent2ClassName === ViewLine.CLASS_NAME) { return HitTestResult.createFromDOMInfo(ctx, startContainer, startContainer.textContent.length); } else { return new UnknownHitTestResult(startContainer); } } return new UnknownHitTestResult(); } /** * Most probably Gecko */ static _doHitTestWithCaretPositionFromPoint(ctx, coords) { const hitResult = document.caretPositionFromPoint(coords.clientX, coords.clientY); if (hitResult.offsetNode.nodeType === hitResult.offsetNode.TEXT_NODE) { // offsetNode is expected to be the token text const parent1 = hitResult.offsetNode.parentNode; // expected to be the token span const parent2 = parent1 ? parent1.parentNode : null; // expected to be the view line container span const parent3 = parent2 ? parent2.parentNode : null; // expected to be the view line div const parent3ClassName = parent3 && parent3.nodeType === parent3.ELEMENT_NODE ? parent3.className : null; if (parent3ClassName === ViewLine.CLASS_NAME) { return HitTestResult.createFromDOMInfo(ctx, hitResult.offsetNode.parentNode, hitResult.offset); } else { return new UnknownHitTestResult(hitResult.offsetNode.parentNode); } } // For inline decorations, Gecko sometimes returns the `` of the line and the offset is the `` with the inline decoration // Some other times, it returns the `` with the inline decoration if (hitResult.offsetNode.nodeType === hitResult.offsetNode.ELEMENT_NODE) { const parent1 = hitResult.offsetNode.parentNode; const parent1ClassName = parent1 && parent1.nodeType === parent1.ELEMENT_NODE ? parent1.className : null; const parent2 = parent1 ? parent1.parentNode : null; const parent2ClassName = parent2 && parent2.nodeType === parent2.ELEMENT_NODE ? parent2.className : null; if (parent1ClassName === ViewLine.CLASS_NAME) { // it returned the `` of the line and the offset is the `` with the inline decoration const tokenSpan = hitResult.offsetNode.childNodes[Math.min(hitResult.offset, hitResult.offsetNode.childNodes.length - 1)]; if (tokenSpan) { return HitTestResult.createFromDOMInfo(ctx, tokenSpan, 0); } } else if (parent2ClassName === ViewLine.CLASS_NAME) { // it returned the `` with the inline decoration return HitTestResult.createFromDOMInfo(ctx, hitResult.offsetNode, 0); } } return new UnknownHitTestResult(hitResult.offsetNode); } static _snapToSoftTabBoundary(position, viewModel) { const lineContent = viewModel.getLineContent(position.lineNumber); const { tabSize } = viewModel.getTextModelOptions(); const newPosition = AtomicTabMoveOperations.atomicPosition(lineContent, position.column - 1, tabSize, 2 /* Nearest */); if (newPosition !== -1) { return new Position$4(position.lineNumber, newPosition + 1); } return position; } static _doHitTest(ctx, request) { let result = new UnknownHitTestResult(); if (typeof document.caretRangeFromPoint === 'function') { result = this._doHitTestWithCaretRangeFromPoint(ctx, request); } else if (document.caretPositionFromPoint) { result = this._doHitTestWithCaretPositionFromPoint(ctx, request.pos.toClientCoordinates()); } if (result.type === 1 /* Content */) { const injectedText = ctx.model.getInjectedTextAt(result.position); const normalizedPosition = ctx.model.normalizePosition(result.position, 2 /* None */); if (injectedText || !normalizedPosition.equals(result.position)) { result = new ContentHitTestResult(normalizedPosition, result.spanNode, injectedText); } } // Snap to the nearest soft tab boundary if atomic soft tabs are enabled. if (result.type === 1 /* Content */ && ctx.stickyTabStops) { result = new ContentHitTestResult(this._snapToSoftTabBoundary(result.position, ctx.model), result.spanNode, result.injectedText); } return result; } } function shadowCaretRangeFromPoint(shadowRoot, x, y) { const range = document.createRange(); // Get the element under the point let el = shadowRoot.elementFromPoint(x, y); if (el !== null) { // Get the last child of the element until its firstChild is a text node // This assumes that the pointer is on the right of the line, out of the tokens // and that we want to get the offset of the last token of the line while (el && el.firstChild && el.firstChild.nodeType !== el.firstChild.TEXT_NODE && el.lastChild && el.lastChild.firstChild) { el = el.lastChild; } // Grab its rect const rect = el.getBoundingClientRect(); // And its font const font = window.getComputedStyle(el, null).getPropertyValue('font'); // And also its txt content const text = el.innerText; // Position the pixel cursor at the left of the element let pixelCursor = rect.left; let offset = 0; let step; // If the point is on the right of the box put the cursor after the last character if (x > rect.left + rect.width) { offset = text.length; } else { const charWidthReader = CharWidthReader.getInstance(); // Goes through all the characters of the innerText, and checks if the x of the point // belongs to the character. for (let i = 0; i < text.length + 1; i++) { // The step is half the width of the character step = charWidthReader.getCharWidth(text.charAt(i), font) / 2; // Move to the center of the character pixelCursor += step; // If the x of the point is smaller that the position of the cursor, the point is over that character if (x < pixelCursor) { offset = i; break; } // Move between the current character and the next pixelCursor += step; } } // Creates a range with the text node of the element and set the offset found range.setStart(el.firstChild, offset); range.setEnd(el.firstChild, offset); } return range; } class CharWidthReader { constructor() { this._cache = {}; this._canvas = document.createElement('canvas'); } static getInstance() { if (!CharWidthReader._INSTANCE) { CharWidthReader._INSTANCE = new CharWidthReader(); } return CharWidthReader._INSTANCE; } getCharWidth(char, font) { const cacheKey = char + font; if (this._cache[cacheKey]) { return this._cache[cacheKey]; } const context = this._canvas.getContext('2d'); context.font = font; const metrics = context.measureText(char); const width = metrics.width; this._cache[cacheKey] = width; return width; } } CharWidthReader._INSTANCE = null; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Merges mouse events when mouse move events are throttled */ function createMouseMoveEventMerger(mouseTargetFactory) { return function (lastEvent, currentEvent) { let targetIsWidget = false; if (mouseTargetFactory) { targetIsWidget = mouseTargetFactory.mouseTargetIsWidget(currentEvent); } if (!targetIsWidget) { currentEvent.preventDefault(); } return currentEvent; }; } class MouseHandler extends ViewEventHandler { constructor(context, viewController, viewHelper) { super(); this._context = context; this.viewController = viewController; this.viewHelper = viewHelper; this.mouseTargetFactory = new MouseTargetFactory(this._context, viewHelper); this._mouseDownOperation = this._register(new MouseDownOperation(this._context, this.viewController, this.viewHelper, (e, testEventTarget) => this._createMouseTarget(e, testEventTarget), (e) => this._getMouseColumn(e))); this.lastMouseLeaveTime = -1; this._height = this._context.configuration.options.get(131 /* layoutInfo */).height; const mouseEvents = new EditorMouseEventFactory(this.viewHelper.viewDomNode); this._register(mouseEvents.onContextMenu(this.viewHelper.viewDomNode, (e) => this._onContextMenu(e, true))); this._register(mouseEvents.onMouseMoveThrottled(this.viewHelper.viewDomNode, (e) => this._onMouseMove(e), createMouseMoveEventMerger(this.mouseTargetFactory), MouseHandler.MOUSE_MOVE_MINIMUM_TIME)); this._register(mouseEvents.onMouseUp(this.viewHelper.viewDomNode, (e) => this._onMouseUp(e))); this._register(mouseEvents.onMouseLeave(this.viewHelper.viewDomNode, (e) => this._onMouseLeave(e))); this._register(mouseEvents.onMouseDown(this.viewHelper.viewDomNode, (e) => this._onMouseDown(e))); const onMouseWheel = (browserEvent) => { this.viewController.emitMouseWheel(browserEvent); if (!this._context.configuration.options.get(68 /* mouseWheelZoom */)) { return; } const e = new StandardWheelEvent(browserEvent); const doMouseWheelZoom = (isMacintosh // on macOS we support cmd + two fingers scroll (`metaKey` set) // and also the two fingers pinch gesture (`ctrKey` set) ? ((browserEvent.metaKey || browserEvent.ctrlKey) && !browserEvent.shiftKey && !browserEvent.altKey) : (browserEvent.ctrlKey && !browserEvent.metaKey && !browserEvent.shiftKey && !browserEvent.altKey)); if (doMouseWheelZoom) { const zoomLevel = EditorZoom.getZoomLevel(); const delta = e.deltaY > 0 ? 1 : -1; EditorZoom.setZoomLevel(zoomLevel + delta); e.preventDefault(); e.stopPropagation(); } }; this._register(addDisposableListener(this.viewHelper.viewDomNode, EventType$1.MOUSE_WHEEL, onMouseWheel, { capture: true, passive: false })); this._context.addEventHandler(this); } dispose() { this._context.removeEventHandler(this); super.dispose(); } // --- begin event handlers onConfigurationChanged(e) { if (e.hasChanged(131 /* layoutInfo */)) { // layout change const height = this._context.configuration.options.get(131 /* layoutInfo */).height; if (this._height !== height) { this._height = height; this._mouseDownOperation.onHeightChanged(); } } return false; } onCursorStateChanged(e) { this._mouseDownOperation.onCursorStateChanged(e); return false; } onFocusChanged(e) { return false; } onScrollChanged(e) { this._mouseDownOperation.onScrollChanged(); return false; } // --- end event handlers getTargetAtClientPoint(clientX, clientY) { const clientPos = new ClientCoordinates(clientX, clientY); const pos = clientPos.toPageCoordinates(); const editorPos = createEditorPagePosition(this.viewHelper.viewDomNode); if (pos.y < editorPos.y || pos.y > editorPos.y + editorPos.height || pos.x < editorPos.x || pos.x > editorPos.x + editorPos.width) { return null; } const relativePos = createCoordinatesRelativeToEditor(this.viewHelper.viewDomNode, editorPos, pos); return this.mouseTargetFactory.createMouseTarget(this.viewHelper.getLastRenderData(), editorPos, pos, relativePos, null); } _createMouseTarget(e, testEventTarget) { let target = e.target; if (!this.viewHelper.viewDomNode.contains(target)) { const shadowRoot = getShadowRoot(this.viewHelper.viewDomNode); if (shadowRoot) { target = shadowRoot.elementsFromPoint(e.posx, e.posy).find((el) => this.viewHelper.viewDomNode.contains(el)); } } return this.mouseTargetFactory.createMouseTarget(this.viewHelper.getLastRenderData(), e.editorPos, e.pos, e.relativePos, testEventTarget ? target : null); } _getMouseColumn(e) { return this.mouseTargetFactory.getMouseColumn(e.relativePos); } _onContextMenu(e, testEventTarget) { this.viewController.emitContextMenu({ event: e, target: this._createMouseTarget(e, testEventTarget) }); } _onMouseMove(e) { if (this._mouseDownOperation.isActive()) { // In selection/drag operation return; } const actualMouseMoveTime = e.timestamp; if (actualMouseMoveTime < this.lastMouseLeaveTime) { // Due to throttling, this event occurred before the mouse left the editor, therefore ignore it. return; } this.viewController.emitMouseMove({ event: e, target: this._createMouseTarget(e, true) }); } _onMouseLeave(e) { this.lastMouseLeaveTime = (new Date()).getTime(); this.viewController.emitMouseLeave({ event: e, target: null }); } _onMouseUp(e) { this.viewController.emitMouseUp({ event: e, target: this._createMouseTarget(e, true) }); } _onMouseDown(e) { const t = this._createMouseTarget(e, true); const targetIsContent = (t.type === 6 /* CONTENT_TEXT */ || t.type === 7 /* CONTENT_EMPTY */); const targetIsGutter = (t.type === 2 /* GUTTER_GLYPH_MARGIN */ || t.type === 3 /* GUTTER_LINE_NUMBERS */ || t.type === 4 /* GUTTER_LINE_DECORATIONS */); const targetIsLineNumbers = (t.type === 3 /* GUTTER_LINE_NUMBERS */); const selectOnLineNumbers = this._context.configuration.options.get(98 /* selectOnLineNumbers */); const targetIsViewZone = (t.type === 8 /* CONTENT_VIEW_ZONE */ || t.type === 5 /* GUTTER_VIEW_ZONE */); const targetIsWidget = (t.type === 9 /* CONTENT_WIDGET */); let shouldHandle = e.leftButton || e.middleButton; if (isMacintosh && e.leftButton && e.ctrlKey) { shouldHandle = false; } const focus = () => { e.preventDefault(); this.viewHelper.focusTextArea(); }; if (shouldHandle && (targetIsContent || (targetIsLineNumbers && selectOnLineNumbers))) { focus(); this._mouseDownOperation.start(t.type, e); } else if (targetIsGutter) { // Do not steal focus e.preventDefault(); } else if (targetIsViewZone) { const viewZoneData = t.detail; if (this.viewHelper.shouldSuppressMouseDownOnViewZone(viewZoneData.viewZoneId)) { focus(); this._mouseDownOperation.start(t.type, e); e.preventDefault(); } } else if (targetIsWidget && this.viewHelper.shouldSuppressMouseDownOnWidget(t.detail)) { focus(); e.preventDefault(); } this.viewController.emitMouseDown({ event: e, target: t }); } } MouseHandler.MOUSE_MOVE_MINIMUM_TIME = 100; // ms class MouseDownOperation extends Disposable { constructor(context, viewController, viewHelper, createMouseTarget, getMouseColumn) { super(); this._context = context; this._viewController = viewController; this._viewHelper = viewHelper; this._createMouseTarget = createMouseTarget; this._getMouseColumn = getMouseColumn; this._mouseMoveMonitor = this._register(new GlobalEditorMouseMoveMonitor(this._viewHelper.viewDomNode)); this._onScrollTimeout = this._register(new TimeoutTimer()); this._mouseState = new MouseDownState(); this._currentSelection = new Selection$1(1, 1, 1, 1); this._isActive = false; this._lastMouseEvent = null; } dispose() { super.dispose(); } isActive() { return this._isActive; } _onMouseDownThenMove(e) { this._lastMouseEvent = e; this._mouseState.setModifiers(e); const position = this._findMousePosition(e, true); if (!position) { // Ignoring because position is unknown return; } if (this._mouseState.isDragAndDrop) { this._viewController.emitMouseDrag({ event: e, target: position }); } else { this._dispatchMouse(position, true); } } start(targetType, e) { this._lastMouseEvent = e; this._mouseState.setStartedOnLineNumbers(targetType === 3 /* GUTTER_LINE_NUMBERS */); this._mouseState.setStartButtons(e); this._mouseState.setModifiers(e); const position = this._findMousePosition(e, true); if (!position || !position.position) { // Ignoring because position is unknown return; } this._mouseState.trySetCount(e.detail, position.position); // Overwrite the detail of the MouseEvent, as it will be sent out in an event and contributions might rely on it. e.detail = this._mouseState.count; const options = this._context.configuration.options; if (!options.get(81 /* readOnly */) && options.get(31 /* dragAndDrop */) && !options.get(18 /* columnSelection */) && !this._mouseState.altKey // we don't support multiple mouse && e.detail < 2 // only single click on a selection can work && !this._isActive // the mouse is not down yet && !this._currentSelection.isEmpty() // we don't drag single cursor && (position.type === 6 /* CONTENT_TEXT */) // single click on text && position.position && this._currentSelection.containsPosition(position.position) // single click on a selection ) { this._mouseState.isDragAndDrop = true; this._isActive = true; this._mouseMoveMonitor.startMonitoring(e.target, e.buttons, createMouseMoveEventMerger(null), (e) => this._onMouseDownThenMove(e), (browserEvent) => { const position = this._findMousePosition(this._lastMouseEvent, true); if (browserEvent && browserEvent instanceof KeyboardEvent) { // cancel this._viewController.emitMouseDropCanceled(); } else { this._viewController.emitMouseDrop({ event: this._lastMouseEvent, target: (position ? this._createMouseTarget(this._lastMouseEvent, true) : null) // Ignoring because position is unknown, e.g., Content View Zone }); } this._stop(); }); return; } this._mouseState.isDragAndDrop = false; this._dispatchMouse(position, e.shiftKey); if (!this._isActive) { this._isActive = true; this._mouseMoveMonitor.startMonitoring(e.target, e.buttons, createMouseMoveEventMerger(null), (e) => this._onMouseDownThenMove(e), () => this._stop()); } } _stop() { this._isActive = false; this._onScrollTimeout.cancel(); } onHeightChanged() { this._mouseMoveMonitor.stopMonitoring(); } onScrollChanged() { if (!this._isActive) { return; } this._onScrollTimeout.setIfNotSet(() => { if (!this._lastMouseEvent) { return; } const position = this._findMousePosition(this._lastMouseEvent, false); if (!position) { // Ignoring because position is unknown return; } if (this._mouseState.isDragAndDrop) { // Ignoring because users are dragging the text return; } this._dispatchMouse(position, true); }, 10); } onCursorStateChanged(e) { this._currentSelection = e.selections[0]; } _getPositionOutsideEditor(e) { const editorContent = e.editorPos; const model = this._context.model; const viewLayout = this._context.viewLayout; const mouseColumn = this._getMouseColumn(e); if (e.posy < editorContent.y) { const verticalOffset = Math.max(viewLayout.getCurrentScrollTop() - (editorContent.y - e.posy), 0); const viewZoneData = HitTestContext.getZoneAtCoord(this._context, verticalOffset); if (viewZoneData) { const newPosition = this._helpPositionJumpOverViewZone(viewZoneData); if (newPosition) { return MouseTarget.createOutsideEditor(mouseColumn, newPosition); } } const aboveLineNumber = viewLayout.getLineNumberAtVerticalOffset(verticalOffset); return MouseTarget.createOutsideEditor(mouseColumn, new Position$4(aboveLineNumber, 1)); } if (e.posy > editorContent.y + editorContent.height) { const verticalOffset = viewLayout.getCurrentScrollTop() + e.relativePos.y; const viewZoneData = HitTestContext.getZoneAtCoord(this._context, verticalOffset); if (viewZoneData) { const newPosition = this._helpPositionJumpOverViewZone(viewZoneData); if (newPosition) { return MouseTarget.createOutsideEditor(mouseColumn, newPosition); } } const belowLineNumber = viewLayout.getLineNumberAtVerticalOffset(verticalOffset); return MouseTarget.createOutsideEditor(mouseColumn, new Position$4(belowLineNumber, model.getLineMaxColumn(belowLineNumber))); } const possibleLineNumber = viewLayout.getLineNumberAtVerticalOffset(viewLayout.getCurrentScrollTop() + e.relativePos.y); if (e.posx < editorContent.x) { return MouseTarget.createOutsideEditor(mouseColumn, new Position$4(possibleLineNumber, 1)); } if (e.posx > editorContent.x + editorContent.width) { return MouseTarget.createOutsideEditor(mouseColumn, new Position$4(possibleLineNumber, model.getLineMaxColumn(possibleLineNumber))); } return null; } _findMousePosition(e, testEventTarget) { const positionOutsideEditor = this._getPositionOutsideEditor(e); if (positionOutsideEditor) { return positionOutsideEditor; } const t = this._createMouseTarget(e, testEventTarget); const hintedPosition = t.position; if (!hintedPosition) { return null; } if (t.type === 8 /* CONTENT_VIEW_ZONE */ || t.type === 5 /* GUTTER_VIEW_ZONE */) { const newPosition = this._helpPositionJumpOverViewZone(t.detail); if (newPosition) { return MouseTarget.createViewZone(t.type, t.element, t.mouseColumn, newPosition, t.detail); } } return t; } _helpPositionJumpOverViewZone(viewZoneData) { // Force position on view zones to go above or below depending on where selection started from const selectionStart = new Position$4(this._currentSelection.selectionStartLineNumber, this._currentSelection.selectionStartColumn); const positionBefore = viewZoneData.positionBefore; const positionAfter = viewZoneData.positionAfter; if (positionBefore && positionAfter) { if (positionBefore.isBefore(selectionStart)) { return positionBefore; } else { return positionAfter; } } return null; } _dispatchMouse(position, inSelectionMode) { if (!position.position) { return; } this._viewController.dispatchMouse({ position: position.position, mouseColumn: position.mouseColumn, startedOnLineNumbers: this._mouseState.startedOnLineNumbers, inSelectionMode: inSelectionMode, mouseDownCount: this._mouseState.count, altKey: this._mouseState.altKey, ctrlKey: this._mouseState.ctrlKey, metaKey: this._mouseState.metaKey, shiftKey: this._mouseState.shiftKey, leftButton: this._mouseState.leftButton, middleButton: this._mouseState.middleButton, }); } } class MouseDownState { constructor() { this._altKey = false; this._ctrlKey = false; this._metaKey = false; this._shiftKey = false; this._leftButton = false; this._middleButton = false; this._startedOnLineNumbers = false; this._lastMouseDownPosition = null; this._lastMouseDownPositionEqualCount = 0; this._lastMouseDownCount = 0; this._lastSetMouseDownCountTime = 0; this.isDragAndDrop = false; } get altKey() { return this._altKey; } get ctrlKey() { return this._ctrlKey; } get metaKey() { return this._metaKey; } get shiftKey() { return this._shiftKey; } get leftButton() { return this._leftButton; } get middleButton() { return this._middleButton; } get startedOnLineNumbers() { return this._startedOnLineNumbers; } get count() { return this._lastMouseDownCount; } setModifiers(source) { this._altKey = source.altKey; this._ctrlKey = source.ctrlKey; this._metaKey = source.metaKey; this._shiftKey = source.shiftKey; } setStartButtons(source) { this._leftButton = source.leftButton; this._middleButton = source.middleButton; } setStartedOnLineNumbers(startedOnLineNumbers) { this._startedOnLineNumbers = startedOnLineNumbers; } trySetCount(setMouseDownCount, newMouseDownPosition) { // a. Invalidate multiple clicking if too much time has passed (will be hit by IE because the detail field of mouse events contains garbage in IE10) const currentTime = (new Date()).getTime(); if (currentTime - this._lastSetMouseDownCountTime > MouseDownState.CLEAR_MOUSE_DOWN_COUNT_TIME) { setMouseDownCount = 1; } this._lastSetMouseDownCountTime = currentTime; // b. Ensure that we don't jump from single click to triple click in one go (will be hit by IE because the detail field of mouse events contains garbage in IE10) if (setMouseDownCount > this._lastMouseDownCount + 1) { setMouseDownCount = this._lastMouseDownCount + 1; } // c. Invalidate multiple clicking if the logical position is different if (this._lastMouseDownPosition && this._lastMouseDownPosition.equals(newMouseDownPosition)) { this._lastMouseDownPositionEqualCount++; } else { this._lastMouseDownPositionEqualCount = 1; } this._lastMouseDownPosition = newMouseDownPosition; // Finally set the lastMouseDownCount this._lastMouseDownCount = Math.min(setMouseDownCount, this._lastMouseDownPositionEqualCount); } } MouseDownState.CLEAR_MOUSE_DOWN_COUNT_TIME = 400; // ms var Mimes; (function (Mimes) { Mimes.text = 'text/plain'; Mimes.binary = 'application/octet-stream'; Mimes.unknown = 'application/unknown'; Mimes.markdown = 'text/markdown'; Mimes.latex = 'text/latex'; })(Mimes || (Mimes = {})); /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ class TextAreaState { constructor(value, selectionStart, selectionEnd, selectionStartPosition, selectionEndPosition) { this.value = value; this.selectionStart = selectionStart; this.selectionEnd = selectionEnd; this.selectionStartPosition = selectionStartPosition; this.selectionEndPosition = selectionEndPosition; } toString() { return `[ <${this.value}>, selectionStart: ${this.selectionStart}, selectionEnd: ${this.selectionEnd}]`; } static readFromTextArea(textArea) { return new TextAreaState(textArea.getValue(), textArea.getSelectionStart(), textArea.getSelectionEnd(), null, null); } collapseSelection() { return new TextAreaState(this.value, this.value.length, this.value.length, null, null); } writeToTextArea(reason, textArea, select) { textArea.setValue(reason, this.value); if (select) { textArea.setSelectionRange(reason, this.selectionStart, this.selectionEnd); } } deduceEditorPosition(offset) { if (offset <= this.selectionStart) { const str = this.value.substring(offset, this.selectionStart); return this._finishDeduceEditorPosition(this.selectionStartPosition, str, -1); } if (offset >= this.selectionEnd) { const str = this.value.substring(this.selectionEnd, offset); return this._finishDeduceEditorPosition(this.selectionEndPosition, str, 1); } const str1 = this.value.substring(this.selectionStart, offset); if (str1.indexOf(String.fromCharCode(8230)) === -1) { return this._finishDeduceEditorPosition(this.selectionStartPosition, str1, 1); } const str2 = this.value.substring(offset, this.selectionEnd); return this._finishDeduceEditorPosition(this.selectionEndPosition, str2, -1); } _finishDeduceEditorPosition(anchor, deltaText, signum) { let lineFeedCnt = 0; let lastLineFeedIndex = -1; while ((lastLineFeedIndex = deltaText.indexOf('\n', lastLineFeedIndex + 1)) !== -1) { lineFeedCnt++; } return [anchor, signum * deltaText.length, lineFeedCnt]; } static deduceInput(previousState, currentState, couldBeEmojiInput) { if (!previousState) { // This is the EMPTY state return { text: '', replacePrevCharCnt: 0, replaceNextCharCnt: 0, positionDelta: 0 }; } const prefixLength = Math.min(commonPrefixLength(previousState.value, currentState.value), previousState.selectionStart, currentState.selectionStart); const suffixLength = Math.min(commonSuffixLength(previousState.value, currentState.value), previousState.value.length - previousState.selectionEnd, currentState.value.length - currentState.selectionEnd); previousState.value.substring(prefixLength, previousState.value.length - suffixLength); const currentValue = currentState.value.substring(prefixLength, currentState.value.length - suffixLength); const previousSelectionStart = previousState.selectionStart - prefixLength; const previousSelectionEnd = previousState.selectionEnd - prefixLength; const currentSelectionStart = currentState.selectionStart - prefixLength; const currentSelectionEnd = currentState.selectionEnd - prefixLength; if (currentSelectionStart === currentSelectionEnd) { // no current selection const replacePreviousCharacters = (previousState.selectionStart - prefixLength); return { text: currentValue, replacePrevCharCnt: replacePreviousCharacters, replaceNextCharCnt: 0, positionDelta: 0 }; } // there is a current selection => composition case const replacePreviousCharacters = previousSelectionEnd - previousSelectionStart; return { text: currentValue, replacePrevCharCnt: replacePreviousCharacters, replaceNextCharCnt: 0, positionDelta: 0 }; } static deduceAndroidCompositionInput(previousState, currentState) { if (!previousState) { // This is the EMPTY state return { text: '', replacePrevCharCnt: 0, replaceNextCharCnt: 0, positionDelta: 0 }; } if (previousState.value === currentState.value) { return { text: '', replacePrevCharCnt: 0, replaceNextCharCnt: 0, positionDelta: currentState.selectionEnd - previousState.selectionEnd }; } const prefixLength = Math.min(commonPrefixLength(previousState.value, currentState.value), previousState.selectionEnd); const suffixLength = Math.min(commonSuffixLength(previousState.value, currentState.value), previousState.value.length - previousState.selectionEnd); const previousValue = previousState.value.substring(prefixLength, previousState.value.length - suffixLength); const currentValue = currentState.value.substring(prefixLength, currentState.value.length - suffixLength); previousState.selectionStart - prefixLength; const previousSelectionEnd = previousState.selectionEnd - prefixLength; currentState.selectionStart - prefixLength; const currentSelectionEnd = currentState.selectionEnd - prefixLength; return { text: currentValue, replacePrevCharCnt: previousSelectionEnd, replaceNextCharCnt: previousValue.length - previousSelectionEnd, positionDelta: currentSelectionEnd - currentValue.length }; } } TextAreaState.EMPTY = new TextAreaState('', 0, 0, null, null); class PagedScreenReaderStrategy { static _getPageOfLine(lineNumber, linesPerPage) { return Math.floor((lineNumber - 1) / linesPerPage); } static _getRangeForPage(page, linesPerPage) { const offset = page * linesPerPage; const startLineNumber = offset + 1; const endLineNumber = offset + linesPerPage; return new Range$5(startLineNumber, 1, endLineNumber + 1, 1); } static fromEditorSelection(previousState, model, selection, linesPerPage, trimLongText) { const selectionStartPage = PagedScreenReaderStrategy._getPageOfLine(selection.startLineNumber, linesPerPage); const selectionStartPageRange = PagedScreenReaderStrategy._getRangeForPage(selectionStartPage, linesPerPage); const selectionEndPage = PagedScreenReaderStrategy._getPageOfLine(selection.endLineNumber, linesPerPage); const selectionEndPageRange = PagedScreenReaderStrategy._getRangeForPage(selectionEndPage, linesPerPage); const pretextRange = selectionStartPageRange.intersectRanges(new Range$5(1, 1, selection.startLineNumber, selection.startColumn)); let pretext = model.getValueInRange(pretextRange, 1 /* LF */); const lastLine = model.getLineCount(); const lastLineMaxColumn = model.getLineMaxColumn(lastLine); const posttextRange = selectionEndPageRange.intersectRanges(new Range$5(selection.endLineNumber, selection.endColumn, lastLine, lastLineMaxColumn)); let posttext = model.getValueInRange(posttextRange, 1 /* LF */); let text; if (selectionStartPage === selectionEndPage || selectionStartPage + 1 === selectionEndPage) { // take full selection text = model.getValueInRange(selection, 1 /* LF */); } else { const selectionRange1 = selectionStartPageRange.intersectRanges(selection); const selectionRange2 = selectionEndPageRange.intersectRanges(selection); text = (model.getValueInRange(selectionRange1, 1 /* LF */) + String.fromCharCode(8230) + model.getValueInRange(selectionRange2, 1 /* LF */)); } // Chromium handles very poorly text even of a few thousand chars // Cut text to avoid stalling the entire UI if (trimLongText) { const LIMIT_CHARS = 500; if (pretext.length > LIMIT_CHARS) { pretext = pretext.substring(pretext.length - LIMIT_CHARS, pretext.length); } if (posttext.length > LIMIT_CHARS) { posttext = posttext.substring(0, LIMIT_CHARS); } if (text.length > 2 * LIMIT_CHARS) { text = text.substring(0, LIMIT_CHARS) + String.fromCharCode(8230) + text.substring(text.length - LIMIT_CHARS, text.length); } } return new TextAreaState(pretext + text + posttext, pretext.length, pretext.length + text.length, new Position$4(selection.startLineNumber, selection.startColumn), new Position$4(selection.endLineNumber, selection.endColumn)); } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var TextAreaSyntethicEvents; (function (TextAreaSyntethicEvents) { TextAreaSyntethicEvents.Tap = '-monaco-textarea-synthetic-tap'; })(TextAreaSyntethicEvents || (TextAreaSyntethicEvents = {})); const CopyOptions = { forceCopyWithSyntaxHighlighting: false }; /** * Every time we write to the clipboard, we record a bit of extra metadata here. * Every time we read from the cipboard, if the text matches our last written text, * we can fetch the previous metadata. */ class InMemoryClipboardMetadataManager { constructor() { this._lastState = null; } set(lastCopiedValue, data) { this._lastState = { lastCopiedValue, data }; } get(pastedText) { if (this._lastState && this._lastState.lastCopiedValue === pastedText) { // match! return this._lastState.data; } this._lastState = null; return null; } } InMemoryClipboardMetadataManager.INSTANCE = new InMemoryClipboardMetadataManager(); class CompositionContext { constructor() { this._lastTypeTextLength = 0; } handleCompositionUpdate(text) { text = text || ''; const typeInput = { text: text, replacePrevCharCnt: this._lastTypeTextLength, replaceNextCharCnt: 0, positionDelta: 0 }; this._lastTypeTextLength = text.length; return typeInput; } } /** * Writes screen reader content to the textarea and is able to analyze its input events to generate: * - onCut * - onPaste * - onType * * Composition events are generated for presentation purposes (composition input is reflected in onType). */ class TextAreaInput extends Disposable { constructor(_host, _textArea, _OS, _browser) { super(); this._host = _host; this._textArea = _textArea; this._OS = _OS; this._browser = _browser; this._onFocus = this._register(new Emitter$1()); this.onFocus = this._onFocus.event; this._onBlur = this._register(new Emitter$1()); this.onBlur = this._onBlur.event; this._onKeyDown = this._register(new Emitter$1()); this.onKeyDown = this._onKeyDown.event; this._onKeyUp = this._register(new Emitter$1()); this.onKeyUp = this._onKeyUp.event; this._onCut = this._register(new Emitter$1()); this.onCut = this._onCut.event; this._onPaste = this._register(new Emitter$1()); this.onPaste = this._onPaste.event; this._onType = this._register(new Emitter$1()); this.onType = this._onType.event; this._onCompositionStart = this._register(new Emitter$1()); this.onCompositionStart = this._onCompositionStart.event; this._onCompositionUpdate = this._register(new Emitter$1()); this.onCompositionUpdate = this._onCompositionUpdate.event; this._onCompositionEnd = this._register(new Emitter$1()); this.onCompositionEnd = this._onCompositionEnd.event; this._onSelectionChangeRequest = this._register(new Emitter$1()); this.onSelectionChangeRequest = this._onSelectionChangeRequest.event; this._asyncTriggerCut = this._register(new RunOnceScheduler(() => this._onCut.fire(), 0)); this._asyncFocusGainWriteScreenReaderContent = this._register(new RunOnceScheduler(() => this.writeScreenReaderContent('asyncFocusGain'), 0)); this._textAreaState = TextAreaState.EMPTY; this._selectionChangeListener = null; this.writeScreenReaderContent('ctor'); this._hasFocus = false; this._currentComposition = null; let lastKeyDown = null; this._register(this._textArea.onKeyDown((_e) => { const e = new StandardKeyboardEvent(_e); if (e.keyCode === 109 /* KEY_IN_COMPOSITION */ || (this._currentComposition && e.keyCode === 1 /* Backspace */)) { // Stop propagation for keyDown events if the IME is processing key input e.stopPropagation(); } if (e.equals(9 /* Escape */)) { // Prevent default always for `Esc`, otherwise it will generate a keypress // See https://msdn.microsoft.com/en-us/library/ie/ms536939(v=vs.85).aspx e.preventDefault(); } lastKeyDown = e; this._onKeyDown.fire(e); })); this._register(this._textArea.onKeyUp((_e) => { const e = new StandardKeyboardEvent(_e); this._onKeyUp.fire(e); })); this._register(this._textArea.onCompositionStart((e) => { const currentComposition = new CompositionContext(); if (this._currentComposition) { // simply reset the composition context this._currentComposition = currentComposition; return; } this._currentComposition = currentComposition; if (this._OS === 2 /* Macintosh */ && lastKeyDown && lastKeyDown.equals(109 /* KEY_IN_COMPOSITION */) && this._textAreaState.selectionStart === this._textAreaState.selectionEnd && this._textAreaState.selectionStart > 0 && this._textAreaState.value.substr(this._textAreaState.selectionStart - 1, 1) === e.data && (lastKeyDown.code === 'ArrowRight' || lastKeyDown.code === 'ArrowLeft')) { // Pretend the previous character was composed (in order to get it removed by subsequent compositionupdate events) currentComposition.handleCompositionUpdate('x'); this._onCompositionStart.fire({ data: e.data }); return; } if (this._browser.isAndroid) { // when tapping on the editor, Android enters composition mode to edit the current word // so we cannot clear the textarea on Android and we must pretend the current word was selected this._onCompositionStart.fire({ data: e.data }); return; } this._onCompositionStart.fire({ data: e.data }); })); this._register(this._textArea.onCompositionUpdate((e) => { const currentComposition = this._currentComposition; if (!currentComposition) { // should not be possible to receive a 'compositionupdate' without a 'compositionstart' return; } if (this._browser.isAndroid) { // On Android, the data sent with the composition update event is unusable. // For example, if the cursor is in the middle of a word like Mic|osoft // and Microsoft is chosen from the keyboard's suggestions, the e.data will contain "Microsoft". // This is not really usable because it doesn't tell us where the edit began and where it ended. const newState = TextAreaState.readFromTextArea(this._textArea); const typeInput = TextAreaState.deduceAndroidCompositionInput(this._textAreaState, newState); this._textAreaState = newState; this._onType.fire(typeInput); this._onCompositionUpdate.fire(e); return; } const typeInput = currentComposition.handleCompositionUpdate(e.data); this._textAreaState = TextAreaState.readFromTextArea(this._textArea); this._onType.fire(typeInput); this._onCompositionUpdate.fire(e); })); this._register(this._textArea.onCompositionEnd((e) => { const currentComposition = this._currentComposition; if (!currentComposition) { // https://github.com/microsoft/monaco-editor/issues/1663 // On iOS 13.2, Chinese system IME randomly trigger an additional compositionend event with empty data return; } this._currentComposition = null; if (this._browser.isAndroid) { // On Android, the data sent with the composition update event is unusable. // For example, if the cursor is in the middle of a word like Mic|osoft // and Microsoft is chosen from the keyboard's suggestions, the e.data will contain "Microsoft". // This is not really usable because it doesn't tell us where the edit began and where it ended. const newState = TextAreaState.readFromTextArea(this._textArea); const typeInput = TextAreaState.deduceAndroidCompositionInput(this._textAreaState, newState); this._textAreaState = newState; this._onType.fire(typeInput); this._onCompositionEnd.fire(); return; } const typeInput = currentComposition.handleCompositionUpdate(e.data); this._textAreaState = TextAreaState.readFromTextArea(this._textArea); this._onType.fire(typeInput); this._onCompositionEnd.fire(); })); this._register(this._textArea.onInput((e) => { // Pretend here we touched the text area, as the `input` event will most likely // result in a `selectionchange` event which we want to ignore this._textArea.setIgnoreSelectionChangeTime('received input event'); if (this._currentComposition) { return; } const newState = TextAreaState.readFromTextArea(this._textArea); const typeInput = TextAreaState.deduceInput(this._textAreaState, newState, /*couldBeEmojiInput*/ this._OS === 2 /* Macintosh */); if (typeInput.replacePrevCharCnt === 0 && typeInput.text.length === 1 && isHighSurrogate(typeInput.text.charCodeAt(0))) { // Ignore invalid input but keep it around for next time return; } this._textAreaState = newState; if (typeInput.text !== '' || typeInput.replacePrevCharCnt !== 0 || typeInput.replaceNextCharCnt !== 0 || typeInput.positionDelta !== 0) { this._onType.fire(typeInput); } })); // --- Clipboard operations this._register(this._textArea.onCut((e) => { // Pretend here we touched the text area, as the `cut` event will most likely // result in a `selectionchange` event which we want to ignore this._textArea.setIgnoreSelectionChangeTime('received cut event'); this._ensureClipboardGetsEditorSelection(e); this._asyncTriggerCut.schedule(); })); this._register(this._textArea.onCopy((e) => { this._ensureClipboardGetsEditorSelection(e); })); this._register(this._textArea.onPaste((e) => { // Pretend here we touched the text area, as the `paste` event will most likely // result in a `selectionchange` event which we want to ignore this._textArea.setIgnoreSelectionChangeTime('received paste event'); e.preventDefault(); if (!e.clipboardData) { return; } let [text, metadata] = ClipboardEventUtils.getTextData(e.clipboardData); if (!text) { return; } // try the in-memory store metadata = metadata || InMemoryClipboardMetadataManager.INSTANCE.get(text); this._onPaste.fire({ text: text, metadata: metadata }); })); this._register(this._textArea.onFocus(() => { const hadFocus = this._hasFocus; this._setHasFocus(true); if (this._browser.isSafari && !hadFocus && this._hasFocus) { // When "tabbing into" the textarea, immediately after dispatching the 'focus' event, // Safari will always move the selection at offset 0 in the textarea this._asyncFocusGainWriteScreenReaderContent.schedule(); } })); this._register(this._textArea.onBlur(() => { if (this._currentComposition) { // See https://github.com/microsoft/vscode/issues/112621 // where compositionend is not triggered when the editor // is taken off-dom during a composition // Clear the flag to be able to write to the textarea this._currentComposition = null; // Clear the textarea to avoid an unwanted cursor type this.writeScreenReaderContent('blurWithoutCompositionEnd'); // Fire artificial composition end this._onCompositionEnd.fire(); } this._setHasFocus(false); })); this._register(this._textArea.onSyntheticTap(() => { if (this._browser.isAndroid && this._currentComposition) { // on Android, tapping does not cancel the current composition, so the // textarea is stuck showing the old composition // Clear the flag to be able to write to the textarea this._currentComposition = null; // Clear the textarea to avoid an unwanted cursor type this.writeScreenReaderContent('tapWithoutCompositionEnd'); // Fire artificial composition end this._onCompositionEnd.fire(); } })); } _installSelectionChangeListener() { // See https://github.com/microsoft/vscode/issues/27216 and https://github.com/microsoft/vscode/issues/98256 // When using a Braille display, it is possible for users to reposition the // system caret. This is reflected in Chrome as a `selectionchange` event. // // The `selectionchange` event appears to be emitted under numerous other circumstances, // so it is quite a challenge to distinguish a `selectionchange` coming in from a user // using a Braille display from all the other cases. // // The problems with the `selectionchange` event are: // * the event is emitted when the textarea is focused programmatically -- textarea.focus() // * the event is emitted when the selection is changed in the textarea programmatically -- textarea.setSelectionRange(...) // * the event is emitted when the value of the textarea is changed programmatically -- textarea.value = '...' // * the event is emitted when tabbing into the textarea // * the event is emitted asynchronously (sometimes with a delay as high as a few tens of ms) // * the event sometimes comes in bursts for a single logical textarea operation // `selectionchange` events often come multiple times for a single logical change // so throttle multiple `selectionchange` events that burst in a short period of time. let previousSelectionChangeEventTime = 0; return addDisposableListener(document, 'selectionchange', (e) => { if (!this._hasFocus) { return; } if (this._currentComposition) { return; } if (!this._browser.isChrome) { // Support only for Chrome until testing happens on other browsers return; } const now = Date.now(); const delta1 = now - previousSelectionChangeEventTime; previousSelectionChangeEventTime = now; if (delta1 < 5) { // received another `selectionchange` event within 5ms of the previous `selectionchange` event // => ignore it return; } const delta2 = now - this._textArea.getIgnoreSelectionChangeTime(); this._textArea.resetSelectionChangeTime(); if (delta2 < 100) { // received a `selectionchange` event within 100ms since we touched the textarea // => ignore it, since we caused it return; } if (!this._textAreaState.selectionStartPosition || !this._textAreaState.selectionEndPosition) { // Cannot correlate a position in the textarea with a position in the editor... return; } const newValue = this._textArea.getValue(); if (this._textAreaState.value !== newValue) { // Cannot correlate a position in the textarea with a position in the editor... return; } const newSelectionStart = this._textArea.getSelectionStart(); const newSelectionEnd = this._textArea.getSelectionEnd(); if (this._textAreaState.selectionStart === newSelectionStart && this._textAreaState.selectionEnd === newSelectionEnd) { // Nothing to do... return; } const _newSelectionStartPosition = this._textAreaState.deduceEditorPosition(newSelectionStart); const newSelectionStartPosition = this._host.deduceModelPosition(_newSelectionStartPosition[0], _newSelectionStartPosition[1], _newSelectionStartPosition[2]); const _newSelectionEndPosition = this._textAreaState.deduceEditorPosition(newSelectionEnd); const newSelectionEndPosition = this._host.deduceModelPosition(_newSelectionEndPosition[0], _newSelectionEndPosition[1], _newSelectionEndPosition[2]); const newSelection = new Selection$1(newSelectionStartPosition.lineNumber, newSelectionStartPosition.column, newSelectionEndPosition.lineNumber, newSelectionEndPosition.column); this._onSelectionChangeRequest.fire(newSelection); }); } dispose() { super.dispose(); if (this._selectionChangeListener) { this._selectionChangeListener.dispose(); this._selectionChangeListener = null; } } focusTextArea() { // Setting this._hasFocus and writing the screen reader content // will result in a focus() and setSelectionRange() in the textarea this._setHasFocus(true); // If the editor is off DOM, focus cannot be really set, so let's double check that we have managed to set the focus this.refreshFocusState(); } isFocused() { return this._hasFocus; } refreshFocusState() { this._setHasFocus(this._textArea.hasFocus()); } _setHasFocus(newHasFocus) { if (this._hasFocus === newHasFocus) { // no change return; } this._hasFocus = newHasFocus; if (this._selectionChangeListener) { this._selectionChangeListener.dispose(); this._selectionChangeListener = null; } if (this._hasFocus) { this._selectionChangeListener = this._installSelectionChangeListener(); } if (this._hasFocus) { this.writeScreenReaderContent('focusgain'); } if (this._hasFocus) { this._onFocus.fire(); } else { this._onBlur.fire(); } } _setAndWriteTextAreaState(reason, textAreaState) { if (!this._hasFocus) { textAreaState = textAreaState.collapseSelection(); } textAreaState.writeToTextArea(reason, this._textArea, this._hasFocus); this._textAreaState = textAreaState; } writeScreenReaderContent(reason) { if (this._currentComposition) { // Do not write to the text area when doing composition return; } this._setAndWriteTextAreaState(reason, this._host.getScreenReaderContent(this._textAreaState)); } _ensureClipboardGetsEditorSelection(e) { const dataToCopy = this._host.getDataToCopy(); const storedMetadata = { version: 1, isFromEmptySelection: dataToCopy.isFromEmptySelection, multicursorText: dataToCopy.multicursorText, mode: dataToCopy.mode }; InMemoryClipboardMetadataManager.INSTANCE.set( // When writing "LINE\r\n" to the clipboard and then pasting, // Firefox pastes "LINE\n", so let's work around this quirk (this._browser.isFirefox ? dataToCopy.text.replace(/\r\n/g, '\n') : dataToCopy.text), storedMetadata); e.preventDefault(); if (e.clipboardData) { ClipboardEventUtils.setTextData(e.clipboardData, dataToCopy.text, dataToCopy.html, storedMetadata); } } } class ClipboardEventUtils { static getTextData(clipboardData) { const text = clipboardData.getData(Mimes.text); let metadata = null; const rawmetadata = clipboardData.getData('vscode-editor-data'); if (typeof rawmetadata === 'string') { try { metadata = JSON.parse(rawmetadata); if (metadata.version !== 1) { metadata = null; } } catch (err) { // no problem! } } return [text, metadata]; } static setTextData(clipboardData, text, html, metadata) { clipboardData.setData(Mimes.text, text); if (typeof html === 'string') { clipboardData.setData('text/html', html); } clipboardData.setData('vscode-editor-data', JSON.stringify(metadata)); } } class TextAreaWrapper extends Disposable { constructor(_actual) { super(); this._actual = _actual; this.onKeyDown = this._register(createEventEmitter(this._actual, 'keydown')).event; this.onKeyUp = this._register(createEventEmitter(this._actual, 'keyup')).event; this.onCompositionStart = this._register(createEventEmitter(this._actual, 'compositionstart')).event; this.onCompositionUpdate = this._register(createEventEmitter(this._actual, 'compositionupdate')).event; this.onCompositionEnd = this._register(createEventEmitter(this._actual, 'compositionend')).event; this.onInput = this._register(createEventEmitter(this._actual, 'input')).event; this.onCut = this._register(createEventEmitter(this._actual, 'cut')).event; this.onCopy = this._register(createEventEmitter(this._actual, 'copy')).event; this.onPaste = this._register(createEventEmitter(this._actual, 'paste')).event; this.onFocus = this._register(createEventEmitter(this._actual, 'focus')).event; this.onBlur = this._register(createEventEmitter(this._actual, 'blur')).event; this._onSyntheticTap = this._register(new Emitter$1()); this.onSyntheticTap = this._onSyntheticTap.event; this._ignoreSelectionChangeTime = 0; this._register(addDisposableListener(this._actual, TextAreaSyntethicEvents.Tap, () => this._onSyntheticTap.fire())); } hasFocus() { const shadowRoot = getShadowRoot(this._actual); if (shadowRoot) { return shadowRoot.activeElement === this._actual; } else if (isInDOM(this._actual)) { return document.activeElement === this._actual; } else { return false; } } setIgnoreSelectionChangeTime(reason) { this._ignoreSelectionChangeTime = Date.now(); } getIgnoreSelectionChangeTime() { return this._ignoreSelectionChangeTime; } resetSelectionChangeTime() { this._ignoreSelectionChangeTime = 0; } getValue() { // console.log('current value: ' + this._textArea.value); return this._actual.value; } setValue(reason, value) { const textArea = this._actual; if (textArea.value === value) { // No change return; } // console.log('reason: ' + reason + ', current value: ' + textArea.value + ' => new value: ' + value); this.setIgnoreSelectionChangeTime('setValue'); textArea.value = value; } getSelectionStart() { return this._actual.selectionDirection === 'backward' ? this._actual.selectionEnd : this._actual.selectionStart; } getSelectionEnd() { return this._actual.selectionDirection === 'backward' ? this._actual.selectionStart : this._actual.selectionEnd; } setSelectionRange(reason, selectionStart, selectionEnd) { const textArea = this._actual; let activeElement = null; const shadowRoot = getShadowRoot(textArea); if (shadowRoot) { activeElement = shadowRoot.activeElement; } else { activeElement = document.activeElement; } const currentIsFocused = (activeElement === textArea); const currentSelectionStart = textArea.selectionStart; const currentSelectionEnd = textArea.selectionEnd; if (currentIsFocused && currentSelectionStart === selectionStart && currentSelectionEnd === selectionEnd) { // No change // Firefox iframe bug https://github.com/microsoft/monaco-editor/issues/643#issuecomment-367871377 if (isFirefox && window.parent !== window) { textArea.focus(); } return; } // console.log('reason: ' + reason + ', setSelectionRange: ' + selectionStart + ' -> ' + selectionEnd); if (currentIsFocused) { // No need to focus, only need to change the selection range this.setIgnoreSelectionChangeTime('setSelectionRange'); textArea.setSelectionRange(selectionStart, selectionEnd); if (isFirefox && window.parent !== window) { textArea.focus(); } return; } // If the focus is outside the textarea, browsers will try really hard to reveal the textarea. // Here, we try to undo the browser's desperate reveal. try { const scrollState = saveParentsScrollTop(textArea); this.setIgnoreSelectionChangeTime('setSelectionRange'); textArea.focus(); textArea.setSelectionRange(selectionStart, selectionEnd); restoreParentsScrollTop(textArea, scrollState); } catch (e) { // Sometimes IE throws when setting selection (e.g. textarea is off-DOM) } } } /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Currently only tested on iOS 13/ iPadOS. */ class PointerEventHandler extends MouseHandler { constructor(context, viewController, viewHelper) { super(context, viewController, viewHelper); this._register(Gesture.addTarget(this.viewHelper.linesContentDomNode)); this._register(addDisposableListener(this.viewHelper.linesContentDomNode, EventType.Tap, (e) => this.onTap(e))); this._register(addDisposableListener(this.viewHelper.linesContentDomNode, EventType.Change, (e) => this.onChange(e))); this._register(addDisposableListener(this.viewHelper.linesContentDomNode, EventType.Contextmenu, (e) => this._onContextMenu(new EditorMouseEvent(e, this.viewHelper.viewDomNode), false))); this._lastPointerType = 'mouse'; this._register(addDisposableListener(this.viewHelper.linesContentDomNode, 'pointerdown', (e) => { const pointerType = e.pointerType; if (pointerType === 'mouse') { this._lastPointerType = 'mouse'; return; } else if (pointerType === 'touch') { this._lastPointerType = 'touch'; } else { this._lastPointerType = 'pen'; } })); // PonterEvents const pointerEvents = new EditorPointerEventFactory(this.viewHelper.viewDomNode); this._register(pointerEvents.onPointerMoveThrottled(this.viewHelper.viewDomNode, (e) => this._onMouseMove(e), createMouseMoveEventMerger(this.mouseTargetFactory), MouseHandler.MOUSE_MOVE_MINIMUM_TIME)); this._register(pointerEvents.onPointerUp(this.viewHelper.viewDomNode, (e) => this._onMouseUp(e))); this._register(pointerEvents.onPointerLeave(this.viewHelper.viewDomNode, (e) => this._onMouseLeave(e))); this._register(pointerEvents.onPointerDown(this.viewHelper.viewDomNode, (e) => this._onMouseDown(e))); } onTap(event) { if (!event.initialTarget || !this.viewHelper.linesContentDomNode.contains(event.initialTarget)) { return; } event.preventDefault(); this.viewHelper.focusTextArea(); const target = this._createMouseTarget(new EditorMouseEvent(event, this.viewHelper.viewDomNode), false); if (target.position) { // this.viewController.moveTo(target.position); this.viewController.dispatchMouse({ position: target.position, mouseColumn: target.position.column, startedOnLineNumbers: false, mouseDownCount: event.tapCount, inSelectionMode: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, leftButton: false, middleButton: false, }); } } onChange(e) { if (this._lastPointerType === 'touch') { this._context.model.deltaScrollNow(-e.translationX, -e.translationY); } } _onMouseDown(e) { if (e.browserEvent.pointerType === 'touch') { return; } super._onMouseDown(e); } } class TouchHandler extends MouseHandler { constructor(context, viewController, viewHelper) { super(context, viewController, viewHelper); this._register(Gesture.addTarget(this.viewHelper.linesContentDomNode)); this._register(addDisposableListener(this.viewHelper.linesContentDomNode, EventType.Tap, (e) => this.onTap(e))); this._register(addDisposableListener(this.viewHelper.linesContentDomNode, EventType.Change, (e) => this.onChange(e))); this._register(addDisposableListener(this.viewHelper.linesContentDomNode, EventType.Contextmenu, (e) => this._onContextMenu(new EditorMouseEvent(e, this.viewHelper.viewDomNode), false))); } onTap(event) { event.preventDefault(); this.viewHelper.focusTextArea(); const target = this._createMouseTarget(new EditorMouseEvent(event, this.viewHelper.viewDomNode), false); if (target.position) { // Send the tap event also to the