物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14976 lines
646 KiB

  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. // Avoid circular dependency on EventEmitter by implementing a subset of the interface.
  6. class ErrorHandler {
  7. constructor() {
  8. this.listeners = [];
  9. this.unexpectedErrorHandler = function (e) {
  10. setTimeout(() => {
  11. if (e.stack) {
  12. if (ErrorNoTelemetry.isErrorNoTelemetry(e)) {
  13. throw new ErrorNoTelemetry(e.message + '\n\n' + e.stack);
  14. }
  15. throw new Error(e.message + '\n\n' + e.stack);
  16. }
  17. throw e;
  18. }, 0);
  19. };
  20. }
  21. emit(e) {
  22. this.listeners.forEach((listener) => {
  23. listener(e);
  24. });
  25. }
  26. onUnexpectedError(e) {
  27. this.unexpectedErrorHandler(e);
  28. this.emit(e);
  29. }
  30. // For external errors, we don't want the listeners to be called
  31. onUnexpectedExternalError(e) {
  32. this.unexpectedErrorHandler(e);
  33. }
  34. }
  35. const errorHandler = new ErrorHandler();
  36. function onUnexpectedError(e) {
  37. // ignore errors from cancelled promises
  38. if (!isCancellationError(e)) {
  39. errorHandler.onUnexpectedError(e);
  40. }
  41. return undefined;
  42. }
  43. function transformErrorForSerialization(error) {
  44. if (error instanceof Error) {
  45. const { name, message } = error;
  46. const stack = error.stacktrace || error.stack;
  47. return {
  48. $isError: true,
  49. name,
  50. message,
  51. stack,
  52. noTelemetry: ErrorNoTelemetry.isErrorNoTelemetry(error)
  53. };
  54. }
  55. // return as is
  56. return error;
  57. }
  58. const canceledName = 'Canceled';
  59. /**
  60. * Checks if the given error is a promise in canceled state
  61. */
  62. function isCancellationError(error) {
  63. if (error instanceof CancellationError) {
  64. return true;
  65. }
  66. return error instanceof Error && error.name === canceledName && error.message === canceledName;
  67. }
  68. // !!!IMPORTANT!!!
  69. // Do NOT change this class because it is also used as an API-type.
  70. class CancellationError extends Error {
  71. constructor() {
  72. super(canceledName);
  73. this.name = this.message;
  74. }
  75. }
  76. /**
  77. * Error that when thrown won't be logged in telemetry as an unhandled error.
  78. */
  79. class ErrorNoTelemetry extends Error {
  80. constructor(msg) {
  81. super(msg);
  82. this.name = 'CodeExpectedError';
  83. }
  84. static fromError(err) {
  85. if (err instanceof ErrorNoTelemetry) {
  86. return err;
  87. }
  88. const result = new ErrorNoTelemetry();
  89. result.message = err.message;
  90. result.stack = err.stack;
  91. return result;
  92. }
  93. static isErrorNoTelemetry(err) {
  94. return err.name === 'CodeExpectedError';
  95. }
  96. }
  97. /**
  98. * This error indicates a bug.
  99. * Do not throw this for invalid user input.
  100. * Only catch this error to recover gracefully from bugs.
  101. */
  102. class BugIndicatingError extends Error {
  103. constructor(message) {
  104. super(message || 'An unexpected bug occurred.');
  105. Object.setPrototypeOf(this, BugIndicatingError.prototype);
  106. // Because we know for sure only buggy code throws this,
  107. // we definitely want to break here and fix the bug.
  108. // eslint-disable-next-line no-debugger
  109. // debugger;
  110. }
  111. }
  112. /*---------------------------------------------------------------------------------------------
  113. * Copyright (c) Microsoft Corporation. All rights reserved.
  114. * Licensed under the MIT License. See License.txt in the project root for license information.
  115. *--------------------------------------------------------------------------------------------*/
  116. /**
  117. * Given a function, returns a function that is only calling that function once.
  118. */
  119. function createSingleCallFunction(fn, fnDidRunCallback) {
  120. const _this = this;
  121. let didCall = false;
  122. let result;
  123. return function () {
  124. if (didCall) {
  125. return result;
  126. }
  127. didCall = true;
  128. {
  129. result = fn.apply(_this, arguments);
  130. }
  131. return result;
  132. };
  133. }
  134. /*---------------------------------------------------------------------------------------------
  135. * Copyright (c) Microsoft Corporation. All rights reserved.
  136. * Licensed under the MIT License. See License.txt in the project root for license information.
  137. *--------------------------------------------------------------------------------------------*/
  138. var Iterable;
  139. (function (Iterable) {
  140. function is(thing) {
  141. return thing && typeof thing === 'object' && typeof thing[Symbol.iterator] === 'function';
  142. }
  143. Iterable.is = is;
  144. const _empty = Object.freeze([]);
  145. function empty() {
  146. return _empty;
  147. }
  148. Iterable.empty = empty;
  149. function* single(element) {
  150. yield element;
  151. }
  152. Iterable.single = single;
  153. function wrap(iterableOrElement) {
  154. if (is(iterableOrElement)) {
  155. return iterableOrElement;
  156. }
  157. else {
  158. return single(iterableOrElement);
  159. }
  160. }
  161. Iterable.wrap = wrap;
  162. function from(iterable) {
  163. return iterable || _empty;
  164. }
  165. Iterable.from = from;
  166. function* reverse(array) {
  167. for (let i = array.length - 1; i >= 0; i--) {
  168. yield array[i];
  169. }
  170. }
  171. Iterable.reverse = reverse;
  172. function isEmpty(iterable) {
  173. return !iterable || iterable[Symbol.iterator]().next().done === true;
  174. }
  175. Iterable.isEmpty = isEmpty;
  176. function first(iterable) {
  177. return iterable[Symbol.iterator]().next().value;
  178. }
  179. Iterable.first = first;
  180. function some(iterable, predicate) {
  181. let i = 0;
  182. for (const element of iterable) {
  183. if (predicate(element, i++)) {
  184. return true;
  185. }
  186. }
  187. return false;
  188. }
  189. Iterable.some = some;
  190. function find(iterable, predicate) {
  191. for (const element of iterable) {
  192. if (predicate(element)) {
  193. return element;
  194. }
  195. }
  196. return undefined;
  197. }
  198. Iterable.find = find;
  199. function* filter(iterable, predicate) {
  200. for (const element of iterable) {
  201. if (predicate(element)) {
  202. yield element;
  203. }
  204. }
  205. }
  206. Iterable.filter = filter;
  207. function* map(iterable, fn) {
  208. let index = 0;
  209. for (const element of iterable) {
  210. yield fn(element, index++);
  211. }
  212. }
  213. Iterable.map = map;
  214. function* flatMap(iterable, fn) {
  215. let index = 0;
  216. for (const element of iterable) {
  217. yield* fn(element, index++);
  218. }
  219. }
  220. Iterable.flatMap = flatMap;
  221. function* concat(...iterables) {
  222. for (const iterable of iterables) {
  223. yield* iterable;
  224. }
  225. }
  226. Iterable.concat = concat;
  227. function reduce(iterable, reducer, initialValue) {
  228. let value = initialValue;
  229. for (const element of iterable) {
  230. value = reducer(value, element);
  231. }
  232. return value;
  233. }
  234. Iterable.reduce = reduce;
  235. /**
  236. * Returns an iterable slice of the array, with the same semantics as `array.slice()`.
  237. */
  238. function* slice(arr, from, to = arr.length) {
  239. if (from < 0) {
  240. from += arr.length;
  241. }
  242. if (to < 0) {
  243. to += arr.length;
  244. }
  245. else if (to > arr.length) {
  246. to = arr.length;
  247. }
  248. for (; from < to; from++) {
  249. yield arr[from];
  250. }
  251. }
  252. Iterable.slice = slice;
  253. /**
  254. * Consumes `atMost` elements from iterable and returns the consumed elements,
  255. * and an iterable for the rest of the elements.
  256. */
  257. function consume(iterable, atMost = Number.POSITIVE_INFINITY) {
  258. const consumed = [];
  259. if (atMost === 0) {
  260. return [consumed, iterable];
  261. }
  262. const iterator = iterable[Symbol.iterator]();
  263. for (let i = 0; i < atMost; i++) {
  264. const next = iterator.next();
  265. if (next.done) {
  266. return [consumed, Iterable.empty()];
  267. }
  268. consumed.push(next.value);
  269. }
  270. return [consumed, { [Symbol.iterator]() { return iterator; } }];
  271. }
  272. Iterable.consume = consume;
  273. async function asyncToArray(iterable) {
  274. const result = [];
  275. for await (const item of iterable) {
  276. result.push(item);
  277. }
  278. return Promise.resolve(result);
  279. }
  280. Iterable.asyncToArray = asyncToArray;
  281. })(Iterable || (Iterable = {}));
  282. function trackDisposable(x) {
  283. return x;
  284. }
  285. function setParentOfDisposable(child, parent) {
  286. }
  287. function dispose(arg) {
  288. if (Iterable.is(arg)) {
  289. const errors = [];
  290. for (const d of arg) {
  291. if (d) {
  292. try {
  293. d.dispose();
  294. }
  295. catch (e) {
  296. errors.push(e);
  297. }
  298. }
  299. }
  300. if (errors.length === 1) {
  301. throw errors[0];
  302. }
  303. else if (errors.length > 1) {
  304. throw new AggregateError(errors, 'Encountered errors while disposing of store');
  305. }
  306. return Array.isArray(arg) ? [] : arg;
  307. }
  308. else if (arg) {
  309. arg.dispose();
  310. return arg;
  311. }
  312. }
  313. /**
  314. * Combine multiple disposable values into a single {@link IDisposable}.
  315. */
  316. function combinedDisposable(...disposables) {
  317. const parent = toDisposable(() => dispose(disposables));
  318. return parent;
  319. }
  320. /**
  321. * Turn a function that implements dispose into an {@link IDisposable}.
  322. *
  323. * @param fn Clean up function, guaranteed to be called only **once**.
  324. */
  325. function toDisposable(fn) {
  326. const self = trackDisposable({
  327. dispose: createSingleCallFunction(() => {
  328. fn();
  329. })
  330. });
  331. return self;
  332. }
  333. /**
  334. * Manages a collection of disposable values.
  335. *
  336. * This is the preferred way to manage multiple disposables. A `DisposableStore` is safer to work with than an
  337. * `IDisposable[]` as it considers edge cases, such as registering the same value multiple times or adding an item to a
  338. * store that has already been disposed of.
  339. */
  340. class DisposableStore {
  341. static { this.DISABLE_DISPOSED_WARNING = false; }
  342. constructor() {
  343. this._toDispose = new Set();
  344. this._isDisposed = false;
  345. }
  346. /**
  347. * Dispose of all registered disposables and mark this object as disposed.
  348. *
  349. * Any future disposables added to this object will be disposed of on `add`.
  350. */
  351. dispose() {
  352. if (this._isDisposed) {
  353. return;
  354. }
  355. this._isDisposed = true;
  356. this.clear();
  357. }
  358. /**
  359. * @return `true` if this object has been disposed of.
  360. */
  361. get isDisposed() {
  362. return this._isDisposed;
  363. }
  364. /**
  365. * Dispose of all registered disposables but do not mark this object as disposed.
  366. */
  367. clear() {
  368. if (this._toDispose.size === 0) {
  369. return;
  370. }
  371. try {
  372. dispose(this._toDispose);
  373. }
  374. finally {
  375. this._toDispose.clear();
  376. }
  377. }
  378. /**
  379. * Add a new {@link IDisposable disposable} to the collection.
  380. */
  381. add(o) {
  382. if (!o) {
  383. return o;
  384. }
  385. if (o === this) {
  386. throw new Error('Cannot register a disposable on itself!');
  387. }
  388. if (this._isDisposed) {
  389. if (!DisposableStore.DISABLE_DISPOSED_WARNING) {
  390. 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);
  391. }
  392. }
  393. else {
  394. this._toDispose.add(o);
  395. }
  396. return o;
  397. }
  398. /**
  399. * Deletes the value from the store, but does not dispose it.
  400. */
  401. deleteAndLeak(o) {
  402. if (!o) {
  403. return;
  404. }
  405. if (this._toDispose.has(o)) {
  406. this._toDispose.delete(o);
  407. }
  408. }
  409. }
  410. /**
  411. * Abstract base class for a {@link IDisposable disposable} object.
  412. *
  413. * Subclasses can {@linkcode _register} disposables that will be automatically cleaned up when this object is disposed of.
  414. */
  415. class Disposable {
  416. /**
  417. * A disposable that does nothing when it is disposed of.
  418. *
  419. * TODO: This should not be a static property.
  420. */
  421. static { this.None = Object.freeze({ dispose() { } }); }
  422. constructor() {
  423. this._store = new DisposableStore();
  424. setParentOfDisposable(this._store);
  425. }
  426. dispose() {
  427. this._store.dispose();
  428. }
  429. /**
  430. * Adds `o` to the collection of disposables managed by this object.
  431. */
  432. _register(o) {
  433. if (o === this) {
  434. throw new Error('Cannot register a disposable on itself!');
  435. }
  436. return this._store.add(o);
  437. }
  438. }
  439. /*---------------------------------------------------------------------------------------------
  440. * Copyright (c) Microsoft Corporation. All rights reserved.
  441. * Licensed under the MIT License. See License.txt in the project root for license information.
  442. *--------------------------------------------------------------------------------------------*/
  443. class Node {
  444. static { this.Undefined = new Node(undefined); }
  445. constructor(element) {
  446. this.element = element;
  447. this.next = Node.Undefined;
  448. this.prev = Node.Undefined;
  449. }
  450. }
  451. class LinkedList {
  452. constructor() {
  453. this._first = Node.Undefined;
  454. this._last = Node.Undefined;
  455. this._size = 0;
  456. }
  457. get size() {
  458. return this._size;
  459. }
  460. isEmpty() {
  461. return this._first === Node.Undefined;
  462. }
  463. clear() {
  464. let node = this._first;
  465. while (node !== Node.Undefined) {
  466. const next = node.next;
  467. node.prev = Node.Undefined;
  468. node.next = Node.Undefined;
  469. node = next;
  470. }
  471. this._first = Node.Undefined;
  472. this._last = Node.Undefined;
  473. this._size = 0;
  474. }
  475. unshift(element) {
  476. return this._insert(element, false);
  477. }
  478. push(element) {
  479. return this._insert(element, true);
  480. }
  481. _insert(element, atTheEnd) {
  482. const newNode = new Node(element);
  483. if (this._first === Node.Undefined) {
  484. this._first = newNode;
  485. this._last = newNode;
  486. }
  487. else if (atTheEnd) {
  488. // push
  489. const oldLast = this._last;
  490. this._last = newNode;
  491. newNode.prev = oldLast;
  492. oldLast.next = newNode;
  493. }
  494. else {
  495. // unshift
  496. const oldFirst = this._first;
  497. this._first = newNode;
  498. newNode.next = oldFirst;
  499. oldFirst.prev = newNode;
  500. }
  501. this._size += 1;
  502. let didRemove = false;
  503. return () => {
  504. if (!didRemove) {
  505. didRemove = true;
  506. this._remove(newNode);
  507. }
  508. };
  509. }
  510. shift() {
  511. if (this._first === Node.Undefined) {
  512. return undefined;
  513. }
  514. else {
  515. const res = this._first.element;
  516. this._remove(this._first);
  517. return res;
  518. }
  519. }
  520. pop() {
  521. if (this._last === Node.Undefined) {
  522. return undefined;
  523. }
  524. else {
  525. const res = this._last.element;
  526. this._remove(this._last);
  527. return res;
  528. }
  529. }
  530. _remove(node) {
  531. if (node.prev !== Node.Undefined && node.next !== Node.Undefined) {
  532. // middle
  533. const anchor = node.prev;
  534. anchor.next = node.next;
  535. node.next.prev = anchor;
  536. }
  537. else if (node.prev === Node.Undefined && node.next === Node.Undefined) {
  538. // only node
  539. this._first = Node.Undefined;
  540. this._last = Node.Undefined;
  541. }
  542. else if (node.next === Node.Undefined) {
  543. // last
  544. this._last = this._last.prev;
  545. this._last.next = Node.Undefined;
  546. }
  547. else if (node.prev === Node.Undefined) {
  548. // first
  549. this._first = this._first.next;
  550. this._first.prev = Node.Undefined;
  551. }
  552. // done
  553. this._size -= 1;
  554. }
  555. *[Symbol.iterator]() {
  556. let node = this._first;
  557. while (node !== Node.Undefined) {
  558. yield node.element;
  559. node = node.next;
  560. }
  561. }
  562. }
  563. /*---------------------------------------------------------------------------------------------
  564. * Copyright (c) Microsoft Corporation. All rights reserved.
  565. * Licensed under the MIT License. See License.txt in the project root for license information.
  566. *--------------------------------------------------------------------------------------------*/
  567. const hasPerformanceNow = (globalThis.performance && typeof globalThis.performance.now === 'function');
  568. class StopWatch {
  569. static create(highResolution) {
  570. return new StopWatch(highResolution);
  571. }
  572. constructor(highResolution) {
  573. this._now = hasPerformanceNow && highResolution === false ? Date.now : globalThis.performance.now.bind(globalThis.performance);
  574. this._startTime = this._now();
  575. this._stopTime = -1;
  576. }
  577. stop() {
  578. this._stopTime = this._now();
  579. }
  580. reset() {
  581. this._startTime = this._now();
  582. this._stopTime = -1;
  583. }
  584. elapsed() {
  585. if (this._stopTime !== -1) {
  586. return this._stopTime - this._startTime;
  587. }
  588. return this._now() - this._startTime;
  589. }
  590. }
  591. var Event;
  592. (function (Event) {
  593. Event.None = () => Disposable.None;
  594. /**
  595. * Given an event, returns another event which debounces calls and defers the listeners to a later task via a shared
  596. * `setTimeout`. The event is converted into a signal (`Event<void>`) to avoid additional object creation as a
  597. * result of merging events and to try prevent race conditions that could arise when using related deferred and
  598. * non-deferred events.
  599. *
  600. * This is useful for deferring non-critical work (eg. general UI updates) to ensure it does not block critical work
  601. * (eg. latency of keypress to text rendered).
  602. *
  603. * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
  604. * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
  605. * returned event causes this utility to leak a listener on the original event.
  606. *
  607. * @param event The event source for the new event.
  608. * @param disposable A disposable store to add the new EventEmitter to.
  609. */
  610. function defer(event, disposable) {
  611. return debounce(event, () => void 0, 0, undefined, true, undefined, disposable);
  612. }
  613. Event.defer = defer;
  614. /**
  615. * Given an event, returns another event which only fires once.
  616. *
  617. * @param event The event source for the new event.
  618. */
  619. function once(event) {
  620. return (listener, thisArgs = null, disposables) => {
  621. // we need this, in case the event fires during the listener call
  622. let didFire = false;
  623. let result = undefined;
  624. result = event(e => {
  625. if (didFire) {
  626. return;
  627. }
  628. else if (result) {
  629. result.dispose();
  630. }
  631. else {
  632. didFire = true;
  633. }
  634. return listener.call(thisArgs, e);
  635. }, null, disposables);
  636. if (didFire) {
  637. result.dispose();
  638. }
  639. return result;
  640. };
  641. }
  642. Event.once = once;
  643. /**
  644. * Given an event, returns another event which only fires once, and only when the condition is met.
  645. *
  646. * @param event The event source for the new event.
  647. */
  648. function onceIf(event, condition) {
  649. return Event.once(Event.filter(event, condition));
  650. }
  651. Event.onceIf = onceIf;
  652. /**
  653. * Maps an event of one type into an event of another type using a mapping function, similar to how
  654. * `Array.prototype.map` works.
  655. *
  656. * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
  657. * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
  658. * returned event causes this utility to leak a listener on the original event.
  659. *
  660. * @param event The event source for the new event.
  661. * @param map The mapping function.
  662. * @param disposable A disposable store to add the new EventEmitter to.
  663. */
  664. function map(event, map, disposable) {
  665. return snapshot((listener, thisArgs = null, disposables) => event(i => listener.call(thisArgs, map(i)), null, disposables), disposable);
  666. }
  667. Event.map = map;
  668. /**
  669. * Wraps an event in another event that performs some function on the event object before firing.
  670. *
  671. * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
  672. * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
  673. * returned event causes this utility to leak a listener on the original event.
  674. *
  675. * @param event The event source for the new event.
  676. * @param each The function to perform on the event object.
  677. * @param disposable A disposable store to add the new EventEmitter to.
  678. */
  679. function forEach(event, each, disposable) {
  680. return snapshot((listener, thisArgs = null, disposables) => event(i => { each(i); listener.call(thisArgs, i); }, null, disposables), disposable);
  681. }
  682. Event.forEach = forEach;
  683. function filter(event, filter, disposable) {
  684. return snapshot((listener, thisArgs = null, disposables) => event(e => filter(e) && listener.call(thisArgs, e), null, disposables), disposable);
  685. }
  686. Event.filter = filter;
  687. /**
  688. * Given an event, returns the same event but typed as `Event<void>`.
  689. */
  690. function signal(event) {
  691. return event;
  692. }
  693. Event.signal = signal;
  694. function any(...events) {
  695. return (listener, thisArgs = null, disposables) => {
  696. const disposable = combinedDisposable(...events.map(event => event(e => listener.call(thisArgs, e))));
  697. return addAndReturnDisposable(disposable, disposables);
  698. };
  699. }
  700. Event.any = any;
  701. /**
  702. * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
  703. * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
  704. * returned event causes this utility to leak a listener on the original event.
  705. */
  706. function reduce(event, merge, initial, disposable) {
  707. let output = initial;
  708. return map(event, e => {
  709. output = merge(output, e);
  710. return output;
  711. }, disposable);
  712. }
  713. Event.reduce = reduce;
  714. function snapshot(event, disposable) {
  715. let listener;
  716. const options = {
  717. onWillAddFirstListener() {
  718. listener = event(emitter.fire, emitter);
  719. },
  720. onDidRemoveLastListener() {
  721. listener?.dispose();
  722. }
  723. };
  724. const emitter = new Emitter(options);
  725. disposable?.add(emitter);
  726. return emitter.event;
  727. }
  728. /**
  729. * Adds the IDisposable to the store if it's set, and returns it. Useful to
  730. * Event function implementation.
  731. */
  732. function addAndReturnDisposable(d, store) {
  733. if (store instanceof Array) {
  734. store.push(d);
  735. }
  736. else if (store) {
  737. store.add(d);
  738. }
  739. return d;
  740. }
  741. function debounce(event, merge, delay = 100, leading = false, flushOnListenerRemove = false, leakWarningThreshold, disposable) {
  742. let subscription;
  743. let output = undefined;
  744. let handle = undefined;
  745. let numDebouncedCalls = 0;
  746. let doFire;
  747. const options = {
  748. leakWarningThreshold,
  749. onWillAddFirstListener() {
  750. subscription = event(cur => {
  751. numDebouncedCalls++;
  752. output = merge(output, cur);
  753. if (leading && !handle) {
  754. emitter.fire(output);
  755. output = undefined;
  756. }
  757. doFire = () => {
  758. const _output = output;
  759. output = undefined;
  760. handle = undefined;
  761. if (!leading || numDebouncedCalls > 1) {
  762. emitter.fire(_output);
  763. }
  764. numDebouncedCalls = 0;
  765. };
  766. if (typeof delay === 'number') {
  767. clearTimeout(handle);
  768. handle = setTimeout(doFire, delay);
  769. }
  770. else {
  771. if (handle === undefined) {
  772. handle = 0;
  773. queueMicrotask(doFire);
  774. }
  775. }
  776. });
  777. },
  778. onWillRemoveListener() {
  779. if (flushOnListenerRemove && numDebouncedCalls > 0) {
  780. doFire?.();
  781. }
  782. },
  783. onDidRemoveLastListener() {
  784. doFire = undefined;
  785. subscription.dispose();
  786. }
  787. };
  788. const emitter = new Emitter(options);
  789. disposable?.add(emitter);
  790. return emitter.event;
  791. }
  792. Event.debounce = debounce;
  793. /**
  794. * Debounces an event, firing after some delay (default=0) with an array of all event original objects.
  795. *
  796. * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
  797. * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
  798. * returned event causes this utility to leak a listener on the original event.
  799. */
  800. function accumulate(event, delay = 0, disposable) {
  801. return Event.debounce(event, (last, e) => {
  802. if (!last) {
  803. return [e];
  804. }
  805. last.push(e);
  806. return last;
  807. }, delay, undefined, true, undefined, disposable);
  808. }
  809. Event.accumulate = accumulate;
  810. /**
  811. * Filters an event such that some condition is _not_ met more than once in a row, effectively ensuring duplicate
  812. * event objects from different sources do not fire the same event object.
  813. *
  814. * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
  815. * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
  816. * returned event causes this utility to leak a listener on the original event.
  817. *
  818. * @param event The event source for the new event.
  819. * @param equals The equality condition.
  820. * @param disposable A disposable store to add the new EventEmitter to.
  821. *
  822. * @example
  823. * ```
  824. * // Fire only one time when a single window is opened or focused
  825. * Event.latch(Event.any(onDidOpenWindow, onDidFocusWindow))
  826. * ```
  827. */
  828. function latch(event, equals = (a, b) => a === b, disposable) {
  829. let firstCall = true;
  830. let cache;
  831. return filter(event, value => {
  832. const shouldEmit = firstCall || !equals(value, cache);
  833. firstCall = false;
  834. cache = value;
  835. return shouldEmit;
  836. }, disposable);
  837. }
  838. Event.latch = latch;
  839. /**
  840. * Splits an event whose parameter is a union type into 2 separate events for each type in the union.
  841. *
  842. * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
  843. * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
  844. * returned event causes this utility to leak a listener on the original event.
  845. *
  846. * @example
  847. * ```
  848. * const event = new EventEmitter<number | undefined>().event;
  849. * const [numberEvent, undefinedEvent] = Event.split(event, isUndefined);
  850. * ```
  851. *
  852. * @param event The event source for the new event.
  853. * @param isT A function that determines what event is of the first type.
  854. * @param disposable A disposable store to add the new EventEmitter to.
  855. */
  856. function split(event, isT, disposable) {
  857. return [
  858. Event.filter(event, isT, disposable),
  859. Event.filter(event, e => !isT(e), disposable),
  860. ];
  861. }
  862. Event.split = split;
  863. /**
  864. * Buffers an event until it has a listener attached.
  865. *
  866. * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
  867. * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
  868. * returned event causes this utility to leak a listener on the original event.
  869. *
  870. * @param event The event source for the new event.
  871. * @param flushAfterTimeout Determines whether to flush the buffer after a timeout immediately or after a
  872. * `setTimeout` when the first event listener is added.
  873. * @param _buffer Internal: A source event array used for tests.
  874. *
  875. * @example
  876. * ```
  877. * // Start accumulating events, when the first listener is attached, flush
  878. * // the event after a timeout such that multiple listeners attached before
  879. * // the timeout would receive the event
  880. * this.onInstallExtension = Event.buffer(service.onInstallExtension, true);
  881. * ```
  882. */
  883. function buffer(event, flushAfterTimeout = false, _buffer = [], disposable) {
  884. let buffer = _buffer.slice();
  885. let listener = event(e => {
  886. if (buffer) {
  887. buffer.push(e);
  888. }
  889. else {
  890. emitter.fire(e);
  891. }
  892. });
  893. if (disposable) {
  894. disposable.add(listener);
  895. }
  896. const flush = () => {
  897. buffer?.forEach(e => emitter.fire(e));
  898. buffer = null;
  899. };
  900. const emitter = new Emitter({
  901. onWillAddFirstListener() {
  902. if (!listener) {
  903. listener = event(e => emitter.fire(e));
  904. if (disposable) {
  905. disposable.add(listener);
  906. }
  907. }
  908. },
  909. onDidAddFirstListener() {
  910. if (buffer) {
  911. if (flushAfterTimeout) {
  912. setTimeout(flush);
  913. }
  914. else {
  915. flush();
  916. }
  917. }
  918. },
  919. onDidRemoveLastListener() {
  920. if (listener) {
  921. listener.dispose();
  922. }
  923. listener = null;
  924. }
  925. });
  926. if (disposable) {
  927. disposable.add(emitter);
  928. }
  929. return emitter.event;
  930. }
  931. Event.buffer = buffer;
  932. /**
  933. * Wraps the event in an {@link IChainableEvent}, allowing a more functional programming style.
  934. *
  935. * @example
  936. * ```
  937. * // Normal
  938. * const onEnterPressNormal = Event.filter(
  939. * Event.map(onKeyPress.event, e => new StandardKeyboardEvent(e)),
  940. * e.keyCode === KeyCode.Enter
  941. * ).event;
  942. *
  943. * // Using chain
  944. * const onEnterPressChain = Event.chain(onKeyPress.event, $ => $
  945. * .map(e => new StandardKeyboardEvent(e))
  946. * .filter(e => e.keyCode === KeyCode.Enter)
  947. * );
  948. * ```
  949. */
  950. function chain(event, sythensize) {
  951. const fn = (listener, thisArgs, disposables) => {
  952. const cs = sythensize(new ChainableSynthesis());
  953. return event(function (value) {
  954. const result = cs.evaluate(value);
  955. if (result !== HaltChainable) {
  956. listener.call(thisArgs, result);
  957. }
  958. }, undefined, disposables);
  959. };
  960. return fn;
  961. }
  962. Event.chain = chain;
  963. const HaltChainable = Symbol('HaltChainable');
  964. class ChainableSynthesis {
  965. constructor() {
  966. this.steps = [];
  967. }
  968. map(fn) {
  969. this.steps.push(fn);
  970. return this;
  971. }
  972. forEach(fn) {
  973. this.steps.push(v => {
  974. fn(v);
  975. return v;
  976. });
  977. return this;
  978. }
  979. filter(fn) {
  980. this.steps.push(v => fn(v) ? v : HaltChainable);
  981. return this;
  982. }
  983. reduce(merge, initial) {
  984. let last = initial;
  985. this.steps.push(v => {
  986. last = merge(last, v);
  987. return last;
  988. });
  989. return this;
  990. }
  991. latch(equals = (a, b) => a === b) {
  992. let firstCall = true;
  993. let cache;
  994. this.steps.push(value => {
  995. const shouldEmit = firstCall || !equals(value, cache);
  996. firstCall = false;
  997. cache = value;
  998. return shouldEmit ? value : HaltChainable;
  999. });
  1000. return this;
  1001. }
  1002. evaluate(value) {
  1003. for (const step of this.steps) {
  1004. value = step(value);
  1005. if (value === HaltChainable) {
  1006. break;
  1007. }
  1008. }
  1009. return value;
  1010. }
  1011. }
  1012. /**
  1013. * Creates an {@link Event} from a node event emitter.
  1014. */
  1015. function fromNodeEventEmitter(emitter, eventName, map = id => id) {
  1016. const fn = (...args) => result.fire(map(...args));
  1017. const onFirstListenerAdd = () => emitter.on(eventName, fn);
  1018. const onLastListenerRemove = () => emitter.removeListener(eventName, fn);
  1019. const result = new Emitter({ onWillAddFirstListener: onFirstListenerAdd, onDidRemoveLastListener: onLastListenerRemove });
  1020. return result.event;
  1021. }
  1022. Event.fromNodeEventEmitter = fromNodeEventEmitter;
  1023. /**
  1024. * Creates an {@link Event} from a DOM event emitter.
  1025. */
  1026. function fromDOMEventEmitter(emitter, eventName, map = id => id) {
  1027. const fn = (...args) => result.fire(map(...args));
  1028. const onFirstListenerAdd = () => emitter.addEventListener(eventName, fn);
  1029. const onLastListenerRemove = () => emitter.removeEventListener(eventName, fn);
  1030. const result = new Emitter({ onWillAddFirstListener: onFirstListenerAdd, onDidRemoveLastListener: onLastListenerRemove });
  1031. return result.event;
  1032. }
  1033. Event.fromDOMEventEmitter = fromDOMEventEmitter;
  1034. /**
  1035. * Creates a promise out of an event, using the {@link Event.once} helper.
  1036. */
  1037. function toPromise(event) {
  1038. return new Promise(resolve => once(event)(resolve));
  1039. }
  1040. Event.toPromise = toPromise;
  1041. /**
  1042. * Creates an event out of a promise that fires once when the promise is
  1043. * resolved with the result of the promise or `undefined`.
  1044. */
  1045. function fromPromise(promise) {
  1046. const result = new Emitter();
  1047. promise.then(res => {
  1048. result.fire(res);
  1049. }, () => {
  1050. result.fire(undefined);
  1051. }).finally(() => {
  1052. result.dispose();
  1053. });
  1054. return result.event;
  1055. }
  1056. Event.fromPromise = fromPromise;
  1057. /**
  1058. * A convenience function for forwarding an event to another emitter which
  1059. * improves readability.
  1060. *
  1061. * This is similar to {@link Relay} but allows instantiating and forwarding
  1062. * on a single line and also allows for multiple source events.
  1063. * @param from The event to forward.
  1064. * @param to The emitter to forward the event to.
  1065. * @example
  1066. * Event.forward(event, emitter);
  1067. * // equivalent to
  1068. * event(e => emitter.fire(e));
  1069. * // equivalent to
  1070. * event(emitter.fire, emitter);
  1071. */
  1072. function forward(from, to) {
  1073. return from(e => to.fire(e));
  1074. }
  1075. Event.forward = forward;
  1076. function runAndSubscribe(event, handler, initial) {
  1077. handler(initial);
  1078. return event(e => handler(e));
  1079. }
  1080. Event.runAndSubscribe = runAndSubscribe;
  1081. class EmitterObserver {
  1082. constructor(_observable, store) {
  1083. this._observable = _observable;
  1084. this._counter = 0;
  1085. this._hasChanged = false;
  1086. const options = {
  1087. onWillAddFirstListener: () => {
  1088. _observable.addObserver(this);
  1089. // Communicate to the observable that we received its current value and would like to be notified about future changes.
  1090. this._observable.reportChanges();
  1091. },
  1092. onDidRemoveLastListener: () => {
  1093. _observable.removeObserver(this);
  1094. }
  1095. };
  1096. this.emitter = new Emitter(options);
  1097. if (store) {
  1098. store.add(this.emitter);
  1099. }
  1100. }
  1101. beginUpdate(_observable) {
  1102. // assert(_observable === this.obs);
  1103. this._counter++;
  1104. }
  1105. handlePossibleChange(_observable) {
  1106. // assert(_observable === this.obs);
  1107. }
  1108. handleChange(_observable, _change) {
  1109. // assert(_observable === this.obs);
  1110. this._hasChanged = true;
  1111. }
  1112. endUpdate(_observable) {
  1113. // assert(_observable === this.obs);
  1114. this._counter--;
  1115. if (this._counter === 0) {
  1116. this._observable.reportChanges();
  1117. if (this._hasChanged) {
  1118. this._hasChanged = false;
  1119. this.emitter.fire(this._observable.get());
  1120. }
  1121. }
  1122. }
  1123. }
  1124. /**
  1125. * Creates an event emitter that is fired when the observable changes.
  1126. * Each listeners subscribes to the emitter.
  1127. */
  1128. function fromObservable(obs, store) {
  1129. const observer = new EmitterObserver(obs, store);
  1130. return observer.emitter.event;
  1131. }
  1132. Event.fromObservable = fromObservable;
  1133. /**
  1134. * Each listener is attached to the observable directly.
  1135. */
  1136. function fromObservableLight(observable) {
  1137. return (listener, thisArgs, disposables) => {
  1138. let count = 0;
  1139. let didChange = false;
  1140. const observer = {
  1141. beginUpdate() {
  1142. count++;
  1143. },
  1144. endUpdate() {
  1145. count--;
  1146. if (count === 0) {
  1147. observable.reportChanges();
  1148. if (didChange) {
  1149. didChange = false;
  1150. listener.call(thisArgs);
  1151. }
  1152. }
  1153. },
  1154. handlePossibleChange() {
  1155. // noop
  1156. },
  1157. handleChange() {
  1158. didChange = true;
  1159. }
  1160. };
  1161. observable.addObserver(observer);
  1162. observable.reportChanges();
  1163. const disposable = {
  1164. dispose() {
  1165. observable.removeObserver(observer);
  1166. }
  1167. };
  1168. if (disposables instanceof DisposableStore) {
  1169. disposables.add(disposable);
  1170. }
  1171. else if (Array.isArray(disposables)) {
  1172. disposables.push(disposable);
  1173. }
  1174. return disposable;
  1175. };
  1176. }
  1177. Event.fromObservableLight = fromObservableLight;
  1178. })(Event || (Event = {}));
  1179. class EventProfiling {
  1180. static { this.all = new Set(); }
  1181. static { this._idPool = 0; }
  1182. constructor(name) {
  1183. this.listenerCount = 0;
  1184. this.invocationCount = 0;
  1185. this.elapsedOverall = 0;
  1186. this.durations = [];
  1187. this.name = `${name}_${EventProfiling._idPool++}`;
  1188. EventProfiling.all.add(this);
  1189. }
  1190. start(listenerCount) {
  1191. this._stopWatch = new StopWatch();
  1192. this.listenerCount = listenerCount;
  1193. }
  1194. stop() {
  1195. if (this._stopWatch) {
  1196. const elapsed = this._stopWatch.elapsed();
  1197. this.durations.push(elapsed);
  1198. this.elapsedOverall += elapsed;
  1199. this.invocationCount += 1;
  1200. this._stopWatch = undefined;
  1201. }
  1202. }
  1203. }
  1204. let _globalLeakWarningThreshold = -1;
  1205. class LeakageMonitor {
  1206. static { this._idPool = 1; }
  1207. constructor(_errorHandler, threshold, name = (LeakageMonitor._idPool++).toString(16).padStart(3, '0')) {
  1208. this._errorHandler = _errorHandler;
  1209. this.threshold = threshold;
  1210. this.name = name;
  1211. this._warnCountdown = 0;
  1212. }
  1213. dispose() {
  1214. this._stacks?.clear();
  1215. }
  1216. check(stack, listenerCount) {
  1217. const threshold = this.threshold;
  1218. if (threshold <= 0 || listenerCount < threshold) {
  1219. return undefined;
  1220. }
  1221. if (!this._stacks) {
  1222. this._stacks = new Map();
  1223. }
  1224. const count = (this._stacks.get(stack.value) || 0);
  1225. this._stacks.set(stack.value, count + 1);
  1226. this._warnCountdown -= 1;
  1227. if (this._warnCountdown <= 0) {
  1228. // only warn on first exceed and then every time the limit
  1229. // is exceeded by 50% again
  1230. this._warnCountdown = threshold * 0.5;
  1231. const [topStack, topCount] = this.getMostFrequentStack();
  1232. const message = `[${this.name}] potential listener LEAK detected, having ${listenerCount} listeners already. MOST frequent listener (${topCount}):`;
  1233. console.warn(message);
  1234. console.warn(topStack);
  1235. const error = new ListenerLeakError(message, topStack);
  1236. this._errorHandler(error);
  1237. }
  1238. return () => {
  1239. const count = (this._stacks.get(stack.value) || 0);
  1240. this._stacks.set(stack.value, count - 1);
  1241. };
  1242. }
  1243. getMostFrequentStack() {
  1244. if (!this._stacks) {
  1245. return undefined;
  1246. }
  1247. let topStack;
  1248. let topCount = 0;
  1249. for (const [stack, count] of this._stacks) {
  1250. if (!topStack || topCount < count) {
  1251. topStack = [stack, count];
  1252. topCount = count;
  1253. }
  1254. }
  1255. return topStack;
  1256. }
  1257. }
  1258. class Stacktrace {
  1259. static create() {
  1260. const err = new Error();
  1261. return new Stacktrace(err.stack ?? '');
  1262. }
  1263. constructor(value) {
  1264. this.value = value;
  1265. }
  1266. print() {
  1267. console.warn(this.value.split('\n').slice(2).join('\n'));
  1268. }
  1269. }
  1270. // error that is logged when going over the configured listener threshold
  1271. class ListenerLeakError extends Error {
  1272. constructor(message, stack) {
  1273. super(message);
  1274. this.name = 'ListenerLeakError';
  1275. this.stack = stack;
  1276. }
  1277. }
  1278. // SEVERE error that is logged when having gone way over the configured listener
  1279. // threshold so that the emitter refuses to accept more listeners
  1280. class ListenerRefusalError extends Error {
  1281. constructor(message, stack) {
  1282. super(message);
  1283. this.name = 'ListenerRefusalError';
  1284. this.stack = stack;
  1285. }
  1286. }
  1287. class UniqueContainer {
  1288. constructor(value) {
  1289. this.value = value;
  1290. }
  1291. }
  1292. const compactionThreshold = 2;
  1293. /**
  1294. * The Emitter can be used to expose an Event to the public
  1295. * to fire it from the insides.
  1296. * Sample:
  1297. class Document {
  1298. private readonly _onDidChange = new Emitter<(value:string)=>any>();
  1299. public onDidChange = this._onDidChange.event;
  1300. // getter-style
  1301. // get onDidChange(): Event<(value:string)=>any> {
  1302. // return this._onDidChange.event;
  1303. // }
  1304. private _doIt() {
  1305. //...
  1306. this._onDidChange.fire(value);
  1307. }
  1308. }
  1309. */
  1310. class Emitter {
  1311. constructor(options) {
  1312. this._size = 0;
  1313. this._options = options;
  1314. this._leakageMon = (this._options?.leakWarningThreshold)
  1315. ? new LeakageMonitor(options?.onListenerError ?? onUnexpectedError, this._options?.leakWarningThreshold ?? _globalLeakWarningThreshold) :
  1316. undefined;
  1317. this._perfMon = this._options?._profName ? new EventProfiling(this._options._profName) : undefined;
  1318. this._deliveryQueue = this._options?.deliveryQueue;
  1319. }
  1320. dispose() {
  1321. if (!this._disposed) {
  1322. this._disposed = true;
  1323. // It is bad to have listeners at the time of disposing an emitter, it is worst to have listeners keep the emitter
  1324. // alive via the reference that's embedded in their disposables. Therefore we loop over all remaining listeners and
  1325. // unset their subscriptions/disposables. Looping and blaming remaining listeners is done on next tick because the
  1326. // the following programming pattern is very popular:
  1327. //
  1328. // const someModel = this._disposables.add(new ModelObject()); // (1) create and register model
  1329. // this._disposables.add(someModel.onDidChange(() => { ... }); // (2) subscribe and register model-event listener
  1330. // ...later...
  1331. // this._disposables.dispose(); disposes (1) then (2): don't warn after (1) but after the "overall dispose" is done
  1332. if (this._deliveryQueue?.current === this) {
  1333. this._deliveryQueue.reset();
  1334. }
  1335. if (this._listeners) {
  1336. this._listeners = undefined;
  1337. this._size = 0;
  1338. }
  1339. this._options?.onDidRemoveLastListener?.();
  1340. this._leakageMon?.dispose();
  1341. }
  1342. }
  1343. /**
  1344. * For the public to allow to subscribe
  1345. * to events from this Emitter
  1346. */
  1347. get event() {
  1348. this._event ??= (callback, thisArgs, disposables) => {
  1349. if (this._leakageMon && this._size > this._leakageMon.threshold ** 2) {
  1350. const message = `[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;
  1351. console.warn(message);
  1352. const tuple = this._leakageMon.getMostFrequentStack() ?? ['UNKNOWN stack', -1];
  1353. const error = new ListenerRefusalError(`${message}. HINT: Stack shows most frequent listener (${tuple[1]}-times)`, tuple[0]);
  1354. const errorHandler = this._options?.onListenerError || onUnexpectedError;
  1355. errorHandler(error);
  1356. return Disposable.None;
  1357. }
  1358. if (this._disposed) {
  1359. // todo: should we warn if a listener is added to a disposed emitter? This happens often
  1360. return Disposable.None;
  1361. }
  1362. if (thisArgs) {
  1363. callback = callback.bind(thisArgs);
  1364. }
  1365. const contained = new UniqueContainer(callback);
  1366. let removeMonitor;
  1367. if (this._leakageMon && this._size >= Math.ceil(this._leakageMon.threshold * 0.2)) {
  1368. // check and record this emitter for potential leakage
  1369. contained.stack = Stacktrace.create();
  1370. removeMonitor = this._leakageMon.check(contained.stack, this._size + 1);
  1371. }
  1372. if (!this._listeners) {
  1373. this._options?.onWillAddFirstListener?.(this);
  1374. this._listeners = contained;
  1375. this._options?.onDidAddFirstListener?.(this);
  1376. }
  1377. else if (this._listeners instanceof UniqueContainer) {
  1378. this._deliveryQueue ??= new EventDeliveryQueuePrivate();
  1379. this._listeners = [this._listeners, contained];
  1380. }
  1381. else {
  1382. this._listeners.push(contained);
  1383. }
  1384. this._size++;
  1385. const result = toDisposable(() => {
  1386. removeMonitor?.();
  1387. this._removeListener(contained);
  1388. });
  1389. if (disposables instanceof DisposableStore) {
  1390. disposables.add(result);
  1391. }
  1392. else if (Array.isArray(disposables)) {
  1393. disposables.push(result);
  1394. }
  1395. return result;
  1396. };
  1397. return this._event;
  1398. }
  1399. _removeListener(listener) {
  1400. this._options?.onWillRemoveListener?.(this);
  1401. if (!this._listeners) {
  1402. return; // expected if a listener gets disposed
  1403. }
  1404. if (this._size === 1) {
  1405. this._listeners = undefined;
  1406. this._options?.onDidRemoveLastListener?.(this);
  1407. this._size = 0;
  1408. return;
  1409. }
  1410. // size > 1 which requires that listeners be a list:
  1411. const listeners = this._listeners;
  1412. const index = listeners.indexOf(listener);
  1413. if (index === -1) {
  1414. console.log('disposed?', this._disposed);
  1415. console.log('size?', this._size);
  1416. console.log('arr?', JSON.stringify(this._listeners));
  1417. throw new Error('Attempted to dispose unknown listener');
  1418. }
  1419. this._size--;
  1420. listeners[index] = undefined;
  1421. const adjustDeliveryQueue = this._deliveryQueue.current === this;
  1422. if (this._size * compactionThreshold <= listeners.length) {
  1423. let n = 0;
  1424. for (let i = 0; i < listeners.length; i++) {
  1425. if (listeners[i]) {
  1426. listeners[n++] = listeners[i];
  1427. }
  1428. else if (adjustDeliveryQueue) {
  1429. this._deliveryQueue.end--;
  1430. if (n < this._deliveryQueue.i) {
  1431. this._deliveryQueue.i--;
  1432. }
  1433. }
  1434. }
  1435. listeners.length = n;
  1436. }
  1437. }
  1438. _deliver(listener, value) {
  1439. if (!listener) {
  1440. return;
  1441. }
  1442. const errorHandler = this._options?.onListenerError || onUnexpectedError;
  1443. if (!errorHandler) {
  1444. listener.value(value);
  1445. return;
  1446. }
  1447. try {
  1448. listener.value(value);
  1449. }
  1450. catch (e) {
  1451. errorHandler(e);
  1452. }
  1453. }
  1454. /** Delivers items in the queue. Assumes the queue is ready to go. */
  1455. _deliverQueue(dq) {
  1456. const listeners = dq.current._listeners;
  1457. while (dq.i < dq.end) {
  1458. // important: dq.i is incremented before calling deliver() because it might reenter deliverQueue()
  1459. this._deliver(listeners[dq.i++], dq.value);
  1460. }
  1461. dq.reset();
  1462. }
  1463. /**
  1464. * To be kept private to fire an event to
  1465. * subscribers
  1466. */
  1467. fire(event) {
  1468. if (this._deliveryQueue?.current) {
  1469. this._deliverQueue(this._deliveryQueue);
  1470. this._perfMon?.stop(); // last fire() will have starting perfmon, stop it before starting the next dispatch
  1471. }
  1472. this._perfMon?.start(this._size);
  1473. if (!this._listeners) ;
  1474. else if (this._listeners instanceof UniqueContainer) {
  1475. this._deliver(this._listeners, event);
  1476. }
  1477. else {
  1478. const dq = this._deliveryQueue;
  1479. dq.enqueue(this, event, this._listeners.length);
  1480. this._deliverQueue(dq);
  1481. }
  1482. this._perfMon?.stop();
  1483. }
  1484. hasListeners() {
  1485. return this._size > 0;
  1486. }
  1487. }
  1488. class EventDeliveryQueuePrivate {
  1489. constructor() {
  1490. /**
  1491. * Index in current's listener list.
  1492. */
  1493. this.i = -1;
  1494. /**
  1495. * The last index in the listener's list to deliver.
  1496. */
  1497. this.end = 0;
  1498. }
  1499. enqueue(emitter, value, end) {
  1500. this.i = 0;
  1501. this.end = end;
  1502. this.current = emitter;
  1503. this.value = value;
  1504. }
  1505. reset() {
  1506. this.i = this.end; // force any current emission loop to stop, mainly for during dispose
  1507. this.current = undefined;
  1508. this.value = undefined;
  1509. }
  1510. }
  1511. /*---------------------------------------------------------------------------------------------
  1512. * Copyright (c) Microsoft Corporation. All rights reserved.
  1513. * Licensed under the MIT License. See License.txt in the project root for license information.
  1514. *--------------------------------------------------------------------------------------------*/
  1515. /*
  1516. * This module exists so that the AMD build of the monaco editor can replace this with an async loader plugin.
  1517. * If you add new functions to this module make sure that they are also provided in the AMD build of the monaco editor.
  1518. */
  1519. function getNLSMessages() {
  1520. return globalThis._VSCODE_NLS_MESSAGES;
  1521. }
  1522. function getNLSLanguage() {
  1523. return globalThis._VSCODE_NLS_LANGUAGE;
  1524. }
  1525. /*---------------------------------------------------------------------------------------------
  1526. * Copyright (c) Microsoft Corporation. All rights reserved.
  1527. * Licensed under the MIT License. See License.txt in the project root for license information.
  1528. *--------------------------------------------------------------------------------------------*/
  1529. // eslint-disable-next-line local/code-import-patterns
  1530. const isPseudo = getNLSLanguage() === 'pseudo' || (typeof document !== 'undefined' && document.location && document.location.hash.indexOf('pseudo=true') >= 0);
  1531. function _format$1(message, args) {
  1532. let result;
  1533. if (args.length === 0) {
  1534. result = message;
  1535. }
  1536. else {
  1537. result = message.replace(/\{(\d+)\}/g, (match, rest) => {
  1538. const index = rest[0];
  1539. const arg = args[index];
  1540. let result = match;
  1541. if (typeof arg === 'string') {
  1542. result = arg;
  1543. }
  1544. else if (typeof arg === 'number' || typeof arg === 'boolean' || arg === void 0 || arg === null) {
  1545. result = String(arg);
  1546. }
  1547. return result;
  1548. });
  1549. }
  1550. if (isPseudo) {
  1551. // FF3B and FF3D is the Unicode zenkaku representation for [ and ]
  1552. result = '\uFF3B' + result.replace(/[aouei]/g, '$&$&') + '\uFF3D';
  1553. }
  1554. return result;
  1555. }
  1556. /**
  1557. * @skipMangle
  1558. */
  1559. function localize(data /* | number when built */, message /* | null when built */, ...args) {
  1560. if (typeof data === 'number') {
  1561. return _format$1(lookupMessage(data, message), args);
  1562. }
  1563. return _format$1(message, args);
  1564. }
  1565. /**
  1566. * Only used when built: Looks up the message in the global NLS table.
  1567. * This table is being made available as a global through bootstrapping
  1568. * depending on the target context.
  1569. */
  1570. function lookupMessage(index, fallback) {
  1571. const message = getNLSMessages()?.[index];
  1572. if (typeof message !== 'string') {
  1573. if (typeof fallback === 'string') {
  1574. return fallback;
  1575. }
  1576. throw new Error(`!!! NLS MISSING: ${index} !!!`);
  1577. }
  1578. return message;
  1579. }
  1580. /*---------------------------------------------------------------------------------------------
  1581. * Copyright (c) Microsoft Corporation. All rights reserved.
  1582. * Licensed under the MIT License. See License.txt in the project root for license information.
  1583. *--------------------------------------------------------------------------------------------*/
  1584. const LANGUAGE_DEFAULT = 'en';
  1585. let _isWindows = false;
  1586. let _isMacintosh = false;
  1587. let _isLinux = false;
  1588. let _isNative = false;
  1589. let _isWeb = false;
  1590. let _locale = undefined;
  1591. let _language = LANGUAGE_DEFAULT;
  1592. let _platformLocale = LANGUAGE_DEFAULT;
  1593. let _translationsConfigFile = undefined;
  1594. let _userAgent = undefined;
  1595. const $globalThis = globalThis;
  1596. let nodeProcess = undefined;
  1597. if (typeof $globalThis.vscode !== 'undefined' && typeof $globalThis.vscode.process !== 'undefined') {
  1598. // Native environment (sandboxed)
  1599. nodeProcess = $globalThis.vscode.process;
  1600. }
  1601. else if (typeof process !== 'undefined' && typeof process?.versions?.node === 'string') {
  1602. // Native environment (non-sandboxed)
  1603. nodeProcess = process;
  1604. }
  1605. const isElectronProcess = typeof nodeProcess?.versions?.electron === 'string';
  1606. const isElectronRenderer = isElectronProcess && nodeProcess?.type === 'renderer';
  1607. // Native environment
  1608. if (typeof nodeProcess === 'object') {
  1609. _isWindows = (nodeProcess.platform === 'win32');
  1610. _isMacintosh = (nodeProcess.platform === 'darwin');
  1611. _isLinux = (nodeProcess.platform === 'linux');
  1612. _isLinux && !!nodeProcess.env['SNAP'] && !!nodeProcess.env['SNAP_REVISION'];
  1613. !!nodeProcess.env['CI'] || !!nodeProcess.env['BUILD_ARTIFACTSTAGINGDIRECTORY'];
  1614. _locale = LANGUAGE_DEFAULT;
  1615. _language = LANGUAGE_DEFAULT;
  1616. const rawNlsConfig = nodeProcess.env['VSCODE_NLS_CONFIG'];
  1617. if (rawNlsConfig) {
  1618. try {
  1619. const nlsConfig = JSON.parse(rawNlsConfig);
  1620. _locale = nlsConfig.userLocale;
  1621. _platformLocale = nlsConfig.osLocale;
  1622. _language = nlsConfig.resolvedLanguage || LANGUAGE_DEFAULT;
  1623. _translationsConfigFile = nlsConfig.languagePack?.translationsConfigFile;
  1624. }
  1625. catch (e) {
  1626. }
  1627. }
  1628. _isNative = true;
  1629. }
  1630. // Web environment
  1631. else if (typeof navigator === 'object' && !isElectronRenderer) {
  1632. _userAgent = navigator.userAgent;
  1633. _isWindows = _userAgent.indexOf('Windows') >= 0;
  1634. _isMacintosh = _userAgent.indexOf('Macintosh') >= 0;
  1635. (_userAgent.indexOf('Macintosh') >= 0 || _userAgent.indexOf('iPad') >= 0 || _userAgent.indexOf('iPhone') >= 0) && !!navigator.maxTouchPoints && navigator.maxTouchPoints > 0;
  1636. _isLinux = _userAgent.indexOf('Linux') >= 0;
  1637. _userAgent?.indexOf('Mobi') >= 0;
  1638. _isWeb = true;
  1639. _language = getNLSLanguage() || LANGUAGE_DEFAULT;
  1640. _locale = navigator.language.toLowerCase();
  1641. _platformLocale = _locale;
  1642. }
  1643. // Unknown environment
  1644. else {
  1645. console.error('Unable to resolve platform.');
  1646. }
  1647. const isWindows = _isWindows;
  1648. const isMacintosh = _isMacintosh;
  1649. const isNative = _isNative;
  1650. const isWeb = _isWeb;
  1651. const isWebWorker = (_isWeb && typeof $globalThis.importScripts === 'function');
  1652. const webWorkerOrigin = isWebWorker ? $globalThis.origin : undefined;
  1653. const userAgent = _userAgent;
  1654. const setTimeout0IsFaster = (typeof $globalThis.postMessage === 'function' && !$globalThis.importScripts);
  1655. /**
  1656. * See https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#:~:text=than%204%2C%20then-,set%20timeout%20to%204,-.
  1657. *
  1658. * Works similarly to `setTimeout(0)` but doesn't suffer from the 4ms artificial delay
  1659. * that browsers set when the nesting level is > 5.
  1660. */
  1661. (() => {
  1662. if (setTimeout0IsFaster) {
  1663. const pending = [];
  1664. $globalThis.addEventListener('message', (e) => {
  1665. if (e.data && e.data.vscodeScheduleAsyncWork) {
  1666. for (let i = 0, len = pending.length; i < len; i++) {
  1667. const candidate = pending[i];
  1668. if (candidate.id === e.data.vscodeScheduleAsyncWork) {
  1669. pending.splice(i, 1);
  1670. candidate.callback();
  1671. return;
  1672. }
  1673. }
  1674. }
  1675. });
  1676. let lastId = 0;
  1677. return (callback) => {
  1678. const myId = ++lastId;
  1679. pending.push({
  1680. id: myId,
  1681. callback: callback
  1682. });
  1683. $globalThis.postMessage({ vscodeScheduleAsyncWork: myId }, '*');
  1684. };
  1685. }
  1686. return (callback) => setTimeout(callback);
  1687. })();
  1688. const isChrome = !!(userAgent && userAgent.indexOf('Chrome') >= 0);
  1689. !!(userAgent && userAgent.indexOf('Firefox') >= 0);
  1690. !!(!isChrome && (userAgent && userAgent.indexOf('Safari') >= 0));
  1691. !!(userAgent && userAgent.indexOf('Edg/') >= 0);
  1692. !!(userAgent && userAgent.indexOf('Android') >= 0);
  1693. function identity(t) {
  1694. return t;
  1695. }
  1696. /**
  1697. * Uses a LRU cache to make a given parametrized function cached.
  1698. * Caches just the last key/value.
  1699. */
  1700. class LRUCachedFunction {
  1701. constructor(arg1, arg2) {
  1702. this.lastCache = undefined;
  1703. this.lastArgKey = undefined;
  1704. if (typeof arg1 === 'function') {
  1705. this._fn = arg1;
  1706. this._computeKey = identity;
  1707. }
  1708. else {
  1709. this._fn = arg2;
  1710. this._computeKey = arg1.getCacheKey;
  1711. }
  1712. }
  1713. get(arg) {
  1714. const key = this._computeKey(arg);
  1715. if (this.lastArgKey !== key) {
  1716. this.lastArgKey = key;
  1717. this.lastCache = this._fn(arg);
  1718. }
  1719. return this.lastCache;
  1720. }
  1721. }
  1722. /*---------------------------------------------------------------------------------------------
  1723. * Copyright (c) Microsoft Corporation. All rights reserved.
  1724. * Licensed under the MIT License. See License.txt in the project root for license information.
  1725. *--------------------------------------------------------------------------------------------*/
  1726. class Lazy {
  1727. constructor(executor) {
  1728. this.executor = executor;
  1729. this._didRun = false;
  1730. }
  1731. /**
  1732. * Get the wrapped value.
  1733. *
  1734. * This will force evaluation of the lazy value if it has not been resolved yet. Lazy values are only
  1735. * resolved once. `getValue` will re-throw exceptions that are hit while resolving the value
  1736. */
  1737. get value() {
  1738. if (!this._didRun) {
  1739. try {
  1740. this._value = this.executor();
  1741. }
  1742. catch (err) {
  1743. this._error = err;
  1744. }
  1745. finally {
  1746. this._didRun = true;
  1747. }
  1748. }
  1749. if (this._error) {
  1750. throw this._error;
  1751. }
  1752. return this._value;
  1753. }
  1754. /**
  1755. * Get the wrapped value without forcing evaluation.
  1756. */
  1757. get rawValue() { return this._value; }
  1758. }
  1759. /*---------------------------------------------------------------------------------------------
  1760. * Copyright (c) Microsoft Corporation. All rights reserved.
  1761. * Licensed under the MIT License. See License.txt in the project root for license information.
  1762. *--------------------------------------------------------------------------------------------*/
  1763. /**
  1764. * Escapes regular expression characters in a given string
  1765. */
  1766. function escapeRegExpCharacters(value) {
  1767. return value.replace(/[\\\{\}\*\+\?\|\^\$\.\[\]\(\)]/g, '\\$&');
  1768. }
  1769. function splitLines(str) {
  1770. return str.split(/\r\n|\r|\n/);
  1771. }
  1772. /**
  1773. * Returns first index of the string that is not whitespace.
  1774. * If string is empty or contains only whitespaces, returns -1
  1775. */
  1776. function firstNonWhitespaceIndex(str) {
  1777. for (let i = 0, len = str.length; i < len; i++) {
  1778. const chCode = str.charCodeAt(i);
  1779. if (chCode !== 32 /* CharCode.Space */ && chCode !== 9 /* CharCode.Tab */) {
  1780. return i;
  1781. }
  1782. }
  1783. return -1;
  1784. }
  1785. /**
  1786. * Returns last index of the string that is not whitespace.
  1787. * If string is empty or contains only whitespaces, returns -1
  1788. */
  1789. function lastNonWhitespaceIndex(str, startIndex = str.length - 1) {
  1790. for (let i = startIndex; i >= 0; i--) {
  1791. const chCode = str.charCodeAt(i);
  1792. if (chCode !== 32 /* CharCode.Space */ && chCode !== 9 /* CharCode.Tab */) {
  1793. return i;
  1794. }
  1795. }
  1796. return -1;
  1797. }
  1798. function isUpperAsciiLetter(code) {
  1799. return code >= 65 /* CharCode.A */ && code <= 90 /* CharCode.Z */;
  1800. }
  1801. /**
  1802. * See http://en.wikipedia.org/wiki/Surrogate_pair
  1803. */
  1804. function isHighSurrogate(charCode) {
  1805. return (0xD800 <= charCode && charCode <= 0xDBFF);
  1806. }
  1807. /**
  1808. * See http://en.wikipedia.org/wiki/Surrogate_pair
  1809. */
  1810. function isLowSurrogate(charCode) {
  1811. return (0xDC00 <= charCode && charCode <= 0xDFFF);
  1812. }
  1813. /**
  1814. * See http://en.wikipedia.org/wiki/Surrogate_pair
  1815. */
  1816. function computeCodePoint(highSurrogate, lowSurrogate) {
  1817. return ((highSurrogate - 0xD800) << 10) + (lowSurrogate - 0xDC00) + 0x10000;
  1818. }
  1819. /**
  1820. * get the code point that begins at offset `offset`
  1821. */
  1822. function getNextCodePoint(str, len, offset) {
  1823. const charCode = str.charCodeAt(offset);
  1824. if (isHighSurrogate(charCode) && offset + 1 < len) {
  1825. const nextCharCode = str.charCodeAt(offset + 1);
  1826. if (isLowSurrogate(nextCharCode)) {
  1827. return computeCodePoint(charCode, nextCharCode);
  1828. }
  1829. }
  1830. return charCode;
  1831. }
  1832. const IS_BASIC_ASCII = /^[\t\n\r\x20-\x7E]*$/;
  1833. /**
  1834. * Returns true if `str` contains only basic ASCII characters in the range 32 - 126 (including 32 and 126) or \n, \r, \t
  1835. */
  1836. function isBasicASCII(str) {
  1837. return IS_BASIC_ASCII.test(str);
  1838. }
  1839. class AmbiguousCharacters {
  1840. static { this.ambiguousCharacterData = new Lazy(() => {
  1841. // Generated using https://github.com/hediet/vscode-unicode-data
  1842. // Stored as key1, value1, key2, value2, ...
  1843. 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
  1844. }); }
  1845. static { this.cache = new LRUCachedFunction({ getCacheKey: JSON.stringify }, (locales) => {
  1846. function arrayToMap(arr) {
  1847. const result = new Map();
  1848. for (let i = 0; i < arr.length; i += 2) {
  1849. result.set(arr[i], arr[i + 1]);
  1850. }
  1851. return result;
  1852. }
  1853. function mergeMaps(map1, map2) {
  1854. const result = new Map(map1);
  1855. for (const [key, value] of map2) {
  1856. result.set(key, value);
  1857. }
  1858. return result;
  1859. }
  1860. function intersectMaps(map1, map2) {
  1861. if (!map1) {
  1862. return map2;
  1863. }
  1864. const result = new Map();
  1865. for (const [key, value] of map1) {
  1866. if (map2.has(key)) {
  1867. result.set(key, value);
  1868. }
  1869. }
  1870. return result;
  1871. }
  1872. const data = this.ambiguousCharacterData.value;
  1873. let filteredLocales = locales.filter((l) => !l.startsWith('_') && l in data);
  1874. if (filteredLocales.length === 0) {
  1875. filteredLocales = ['_default'];
  1876. }
  1877. let languageSpecificMap = undefined;
  1878. for (const locale of filteredLocales) {
  1879. const map = arrayToMap(data[locale]);
  1880. languageSpecificMap = intersectMaps(languageSpecificMap, map);
  1881. }
  1882. const commonMap = arrayToMap(data['_common']);
  1883. const map = mergeMaps(commonMap, languageSpecificMap);
  1884. return new AmbiguousCharacters(map);
  1885. }); }
  1886. static getInstance(locales) {
  1887. return AmbiguousCharacters.cache.get(Array.from(locales));
  1888. }
  1889. static { this._locales = new Lazy(() => Object.keys(AmbiguousCharacters.ambiguousCharacterData.value).filter((k) => !k.startsWith('_'))); }
  1890. static getLocales() {
  1891. return AmbiguousCharacters._locales.value;
  1892. }
  1893. constructor(confusableDictionary) {
  1894. this.confusableDictionary = confusableDictionary;
  1895. }
  1896. isAmbiguous(codePoint) {
  1897. return this.confusableDictionary.has(codePoint);
  1898. }
  1899. /**
  1900. * Returns the non basic ASCII code point that the given code point can be confused,
  1901. * or undefined if such code point does note exist.
  1902. */
  1903. getPrimaryConfusable(codePoint) {
  1904. return this.confusableDictionary.get(codePoint);
  1905. }
  1906. getConfusableCodePoints() {
  1907. return new Set(this.confusableDictionary.keys());
  1908. }
  1909. }
  1910. class InvisibleCharacters {
  1911. static getRawData() {
  1912. // Generated using https://github.com/hediet/vscode-unicode-data
  1913. 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]');
  1914. }
  1915. static { this._data = undefined; }
  1916. static getData() {
  1917. if (!this._data) {
  1918. this._data = new Set(InvisibleCharacters.getRawData());
  1919. }
  1920. return this._data;
  1921. }
  1922. static isInvisibleCharacter(codePoint) {
  1923. return InvisibleCharacters.getData().has(codePoint);
  1924. }
  1925. static get codePoints() {
  1926. return InvisibleCharacters.getData();
  1927. }
  1928. }
  1929. /*---------------------------------------------------------------------------------------------
  1930. * Copyright (c) Microsoft Corporation. All rights reserved.
  1931. * Licensed under the MIT License. See License.txt in the project root for license information.
  1932. *--------------------------------------------------------------------------------------------*/
  1933. let safeProcess;
  1934. // Native sandbox environment
  1935. const vscodeGlobal = globalThis.vscode;
  1936. if (typeof vscodeGlobal !== 'undefined' && typeof vscodeGlobal.process !== 'undefined') {
  1937. const sandboxProcess = vscodeGlobal.process;
  1938. safeProcess = {
  1939. get platform() { return sandboxProcess.platform; },
  1940. get arch() { return sandboxProcess.arch; },
  1941. get env() { return sandboxProcess.env; },
  1942. cwd() { return sandboxProcess.cwd(); }
  1943. };
  1944. }
  1945. // Native node.js environment
  1946. else if (typeof process !== 'undefined' && typeof process?.versions?.node === 'string') {
  1947. safeProcess = {
  1948. get platform() { return process.platform; },
  1949. get arch() { return process.arch; },
  1950. get env() { return process.env; },
  1951. cwd() { return process.env['VSCODE_CWD'] || process.cwd(); }
  1952. };
  1953. }
  1954. // Web environment
  1955. else {
  1956. safeProcess = {
  1957. // Supported
  1958. get platform() { return isWindows ? 'win32' : isMacintosh ? 'darwin' : 'linux'; },
  1959. get arch() { return undefined; /* arch is undefined in web */ },
  1960. // Unsupported
  1961. get env() { return {}; },
  1962. cwd() { return '/'; }
  1963. };
  1964. }
  1965. /**
  1966. * Provides safe access to the `cwd` property in node.js, sandboxed or web
  1967. * environments.
  1968. *
  1969. * Note: in web, this property is hardcoded to be `/`.
  1970. *
  1971. * @skipMangle
  1972. */
  1973. const cwd = safeProcess.cwd;
  1974. /**
  1975. * Provides safe access to the `env` property in node.js, sandboxed or web
  1976. * environments.
  1977. *
  1978. * Note: in web, this property is hardcoded to be `{}`.
  1979. */
  1980. const env = safeProcess.env;
  1981. /**
  1982. * Provides safe access to the `platform` property in node.js, sandboxed or web
  1983. * environments.
  1984. */
  1985. const platform = safeProcess.platform;
  1986. /*---------------------------------------------------------------------------------------------
  1987. * Copyright (c) Microsoft Corporation. All rights reserved.
  1988. * Licensed under the MIT License. See License.txt in the project root for license information.
  1989. *--------------------------------------------------------------------------------------------*/
  1990. // NOTE: VSCode's copy of nodejs path library to be usable in common (non-node) namespace
  1991. // Copied from: https://github.com/nodejs/node/commits/v20.9.0/lib/path.js
  1992. // Excluding: the change that adds primordials
  1993. // (https://github.com/nodejs/node/commit/187a862d221dec42fa9a5c4214e7034d9092792f and others)
  1994. /**
  1995. * Copyright Joyent, Inc. and other Node contributors.
  1996. *
  1997. * Permission is hereby granted, free of charge, to any person obtaining a
  1998. * copy of this software and associated documentation files (the
  1999. * "Software"), to deal in the Software without restriction, including
  2000. * without limitation the rights to use, copy, modify, merge, publish,
  2001. * distribute, sublicense, and/or sell copies of the Software, and to permit
  2002. * persons to whom the Software is furnished to do so, subject to the
  2003. * following conditions:
  2004. *
  2005. * The above copyright notice and this permission notice shall be included
  2006. * in all copies or substantial portions of the Software.
  2007. *
  2008. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2009. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2010. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2011. * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2012. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2013. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2014. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  2015. */
  2016. const CHAR_UPPERCASE_A = 65; /* A */
  2017. const CHAR_LOWERCASE_A = 97; /* a */
  2018. const CHAR_UPPERCASE_Z = 90; /* Z */
  2019. const CHAR_LOWERCASE_Z = 122; /* z */
  2020. const CHAR_DOT = 46; /* . */
  2021. const CHAR_FORWARD_SLASH = 47; /* / */
  2022. const CHAR_BACKWARD_SLASH = 92; /* \ */
  2023. const CHAR_COLON = 58; /* : */
  2024. const CHAR_QUESTION_MARK = 63; /* ? */
  2025. class ErrorInvalidArgType extends Error {
  2026. constructor(name, expected, actual) {
  2027. // determiner: 'must be' or 'must not be'
  2028. let determiner;
  2029. if (typeof expected === 'string' && expected.indexOf('not ') === 0) {
  2030. determiner = 'must not be';
  2031. expected = expected.replace(/^not /, '');
  2032. }
  2033. else {
  2034. determiner = 'must be';
  2035. }
  2036. const type = name.indexOf('.') !== -1 ? 'property' : 'argument';
  2037. let msg = `The "${name}" ${type} ${determiner} of type ${expected}`;
  2038. msg += `. Received type ${typeof actual}`;
  2039. super(msg);
  2040. this.code = 'ERR_INVALID_ARG_TYPE';
  2041. }
  2042. }
  2043. function validateObject(pathObject, name) {
  2044. if (pathObject === null || typeof pathObject !== 'object') {
  2045. throw new ErrorInvalidArgType(name, 'Object', pathObject);
  2046. }
  2047. }
  2048. function validateString(value, name) {
  2049. if (typeof value !== 'string') {
  2050. throw new ErrorInvalidArgType(name, 'string', value);
  2051. }
  2052. }
  2053. const platformIsWin32 = (platform === 'win32');
  2054. function isPathSeparator(code) {
  2055. return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
  2056. }
  2057. function isPosixPathSeparator(code) {
  2058. return code === CHAR_FORWARD_SLASH;
  2059. }
  2060. function isWindowsDeviceRoot(code) {
  2061. return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
  2062. (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
  2063. }
  2064. // Resolves . and .. elements in a path with directory names
  2065. function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
  2066. let res = '';
  2067. let lastSegmentLength = 0;
  2068. let lastSlash = -1;
  2069. let dots = 0;
  2070. let code = 0;
  2071. for (let i = 0; i <= path.length; ++i) {
  2072. if (i < path.length) {
  2073. code = path.charCodeAt(i);
  2074. }
  2075. else if (isPathSeparator(code)) {
  2076. break;
  2077. }
  2078. else {
  2079. code = CHAR_FORWARD_SLASH;
  2080. }
  2081. if (isPathSeparator(code)) {
  2082. if (lastSlash === i - 1 || dots === 1) ;
  2083. else if (dots === 2) {
  2084. if (res.length < 2 || lastSegmentLength !== 2 ||
  2085. res.charCodeAt(res.length - 1) !== CHAR_DOT ||
  2086. res.charCodeAt(res.length - 2) !== CHAR_DOT) {
  2087. if (res.length > 2) {
  2088. const lastSlashIndex = res.lastIndexOf(separator);
  2089. if (lastSlashIndex === -1) {
  2090. res = '';
  2091. lastSegmentLength = 0;
  2092. }
  2093. else {
  2094. res = res.slice(0, lastSlashIndex);
  2095. lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
  2096. }
  2097. lastSlash = i;
  2098. dots = 0;
  2099. continue;
  2100. }
  2101. else if (res.length !== 0) {
  2102. res = '';
  2103. lastSegmentLength = 0;
  2104. lastSlash = i;
  2105. dots = 0;
  2106. continue;
  2107. }
  2108. }
  2109. if (allowAboveRoot) {
  2110. res += res.length > 0 ? `${separator}..` : '..';
  2111. lastSegmentLength = 2;
  2112. }
  2113. }
  2114. else {
  2115. if (res.length > 0) {
  2116. res += `${separator}${path.slice(lastSlash + 1, i)}`;
  2117. }
  2118. else {
  2119. res = path.slice(lastSlash + 1, i);
  2120. }
  2121. lastSegmentLength = i - lastSlash - 1;
  2122. }
  2123. lastSlash = i;
  2124. dots = 0;
  2125. }
  2126. else if (code === CHAR_DOT && dots !== -1) {
  2127. ++dots;
  2128. }
  2129. else {
  2130. dots = -1;
  2131. }
  2132. }
  2133. return res;
  2134. }
  2135. function formatExt(ext) {
  2136. return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';
  2137. }
  2138. function _format(sep, pathObject) {
  2139. validateObject(pathObject, 'pathObject');
  2140. const dir = pathObject.dir || pathObject.root;
  2141. const base = pathObject.base ||
  2142. `${pathObject.name || ''}${formatExt(pathObject.ext)}`;
  2143. if (!dir) {
  2144. return base;
  2145. }
  2146. return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`;
  2147. }
  2148. const win32 = {
  2149. // path.resolve([from ...], to)
  2150. resolve(...pathSegments) {
  2151. let resolvedDevice = '';
  2152. let resolvedTail = '';
  2153. let resolvedAbsolute = false;
  2154. for (let i = pathSegments.length - 1; i >= -1; i--) {
  2155. let path;
  2156. if (i >= 0) {
  2157. path = pathSegments[i];
  2158. validateString(path, `paths[${i}]`);
  2159. // Skip empty entries
  2160. if (path.length === 0) {
  2161. continue;
  2162. }
  2163. }
  2164. else if (resolvedDevice.length === 0) {
  2165. path = cwd();
  2166. }
  2167. else {
  2168. // Windows has the concept of drive-specific current working
  2169. // directories. If we've resolved a drive letter but not yet an
  2170. // absolute path, get cwd for that drive, or the process cwd if
  2171. // the drive cwd is not available. We're sure the device is not
  2172. // a UNC path at this points, because UNC paths are always absolute.
  2173. path = env[`=${resolvedDevice}`] || cwd();
  2174. // Verify that a cwd was found and that it actually points
  2175. // to our drive. If not, default to the drive's root.
  2176. if (path === undefined ||
  2177. (path.slice(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() &&
  2178. path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) {
  2179. path = `${resolvedDevice}\\`;
  2180. }
  2181. }
  2182. const len = path.length;
  2183. let rootEnd = 0;
  2184. let device = '';
  2185. let isAbsolute = false;
  2186. const code = path.charCodeAt(0);
  2187. // Try to match a root
  2188. if (len === 1) {
  2189. if (isPathSeparator(code)) {
  2190. // `path` contains just a path separator
  2191. rootEnd = 1;
  2192. isAbsolute = true;
  2193. }
  2194. }
  2195. else if (isPathSeparator(code)) {
  2196. // Possible UNC root
  2197. // If we started with a separator, we know we at least have an
  2198. // absolute path of some kind (UNC or otherwise)
  2199. isAbsolute = true;
  2200. if (isPathSeparator(path.charCodeAt(1))) {
  2201. // Matched double path separator at beginning
  2202. let j = 2;
  2203. let last = j;
  2204. // Match 1 or more non-path separators
  2205. while (j < len && !isPathSeparator(path.charCodeAt(j))) {
  2206. j++;
  2207. }
  2208. if (j < len && j !== last) {
  2209. const firstPart = path.slice(last, j);
  2210. // Matched!
  2211. last = j;
  2212. // Match 1 or more path separators
  2213. while (j < len && isPathSeparator(path.charCodeAt(j))) {
  2214. j++;
  2215. }
  2216. if (j < len && j !== last) {
  2217. // Matched!
  2218. last = j;
  2219. // Match 1 or more non-path separators
  2220. while (j < len && !isPathSeparator(path.charCodeAt(j))) {
  2221. j++;
  2222. }
  2223. if (j === len || j !== last) {
  2224. // We matched a UNC root
  2225. device = `\\\\${firstPart}\\${path.slice(last, j)}`;
  2226. rootEnd = j;
  2227. }
  2228. }
  2229. }
  2230. }
  2231. else {
  2232. rootEnd = 1;
  2233. }
  2234. }
  2235. else if (isWindowsDeviceRoot(code) &&
  2236. path.charCodeAt(1) === CHAR_COLON) {
  2237. // Possible device root
  2238. device = path.slice(0, 2);
  2239. rootEnd = 2;
  2240. if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
  2241. // Treat separator following drive name as an absolute path
  2242. // indicator
  2243. isAbsolute = true;
  2244. rootEnd = 3;
  2245. }
  2246. }
  2247. if (device.length > 0) {
  2248. if (resolvedDevice.length > 0) {
  2249. if (device.toLowerCase() !== resolvedDevice.toLowerCase()) {
  2250. // This path points to another device so it is not applicable
  2251. continue;
  2252. }
  2253. }
  2254. else {
  2255. resolvedDevice = device;
  2256. }
  2257. }
  2258. if (resolvedAbsolute) {
  2259. if (resolvedDevice.length > 0) {
  2260. break;
  2261. }
  2262. }
  2263. else {
  2264. resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
  2265. resolvedAbsolute = isAbsolute;
  2266. if (isAbsolute && resolvedDevice.length > 0) {
  2267. break;
  2268. }
  2269. }
  2270. }
  2271. // At this point the path should be resolved to a full absolute path,
  2272. // but handle relative paths to be safe (might happen when process.cwd()
  2273. // fails)
  2274. // Normalize the tail path
  2275. resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparator);
  2276. return resolvedAbsolute ?
  2277. `${resolvedDevice}\\${resolvedTail}` :
  2278. `${resolvedDevice}${resolvedTail}` || '.';
  2279. },
  2280. normalize(path) {
  2281. validateString(path, 'path');
  2282. const len = path.length;
  2283. if (len === 0) {
  2284. return '.';
  2285. }
  2286. let rootEnd = 0;
  2287. let device;
  2288. let isAbsolute = false;
  2289. const code = path.charCodeAt(0);
  2290. // Try to match a root
  2291. if (len === 1) {
  2292. // `path` contains just a single char, exit early to avoid
  2293. // unnecessary work
  2294. return isPosixPathSeparator(code) ? '\\' : path;
  2295. }
  2296. if (isPathSeparator(code)) {
  2297. // Possible UNC root
  2298. // If we started with a separator, we know we at least have an absolute
  2299. // path of some kind (UNC or otherwise)
  2300. isAbsolute = true;
  2301. if (isPathSeparator(path.charCodeAt(1))) {
  2302. // Matched double path separator at beginning
  2303. let j = 2;
  2304. let last = j;
  2305. // Match 1 or more non-path separators
  2306. while (j < len && !isPathSeparator(path.charCodeAt(j))) {
  2307. j++;
  2308. }
  2309. if (j < len && j !== last) {
  2310. const firstPart = path.slice(last, j);
  2311. // Matched!
  2312. last = j;
  2313. // Match 1 or more path separators
  2314. while (j < len && isPathSeparator(path.charCodeAt(j))) {
  2315. j++;
  2316. }
  2317. if (j < len && j !== last) {
  2318. // Matched!
  2319. last = j;
  2320. // Match 1 or more non-path separators
  2321. while (j < len && !isPathSeparator(path.charCodeAt(j))) {
  2322. j++;
  2323. }
  2324. if (j === len) {
  2325. // We matched a UNC root only
  2326. // Return the normalized version of the UNC root since there
  2327. // is nothing left to process
  2328. return `\\\\${firstPart}\\${path.slice(last)}\\`;
  2329. }
  2330. if (j !== last) {
  2331. // We matched a UNC root with leftovers
  2332. device = `\\\\${firstPart}\\${path.slice(last, j)}`;
  2333. rootEnd = j;
  2334. }
  2335. }
  2336. }
  2337. }
  2338. else {
  2339. rootEnd = 1;
  2340. }
  2341. }
  2342. else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
  2343. // Possible device root
  2344. device = path.slice(0, 2);
  2345. rootEnd = 2;
  2346. if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
  2347. // Treat separator following drive name as an absolute path
  2348. // indicator
  2349. isAbsolute = true;
  2350. rootEnd = 3;
  2351. }
  2352. }
  2353. let tail = rootEnd < len ?
  2354. normalizeString(path.slice(rootEnd), !isAbsolute, '\\', isPathSeparator) :
  2355. '';
  2356. if (tail.length === 0 && !isAbsolute) {
  2357. tail = '.';
  2358. }
  2359. if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) {
  2360. tail += '\\';
  2361. }
  2362. if (device === undefined) {
  2363. return isAbsolute ? `\\${tail}` : tail;
  2364. }
  2365. return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
  2366. },
  2367. isAbsolute(path) {
  2368. validateString(path, 'path');
  2369. const len = path.length;
  2370. if (len === 0) {
  2371. return false;
  2372. }
  2373. const code = path.charCodeAt(0);
  2374. return isPathSeparator(code) ||
  2375. // Possible device root
  2376. (len > 2 &&
  2377. isWindowsDeviceRoot(code) &&
  2378. path.charCodeAt(1) === CHAR_COLON &&
  2379. isPathSeparator(path.charCodeAt(2)));
  2380. },
  2381. join(...paths) {
  2382. if (paths.length === 0) {
  2383. return '.';
  2384. }
  2385. let joined;
  2386. let firstPart;
  2387. for (let i = 0; i < paths.length; ++i) {
  2388. const arg = paths[i];
  2389. validateString(arg, 'path');
  2390. if (arg.length > 0) {
  2391. if (joined === undefined) {
  2392. joined = firstPart = arg;
  2393. }
  2394. else {
  2395. joined += `\\${arg}`;
  2396. }
  2397. }
  2398. }
  2399. if (joined === undefined) {
  2400. return '.';
  2401. }
  2402. // Make sure that the joined path doesn't start with two slashes, because
  2403. // normalize() will mistake it for a UNC path then.
  2404. //
  2405. // This step is skipped when it is very clear that the user actually
  2406. // intended to point at a UNC path. This is assumed when the first
  2407. // non-empty string arguments starts with exactly two slashes followed by
  2408. // at least one more non-slash character.
  2409. //
  2410. // Note that for normalize() to treat a path as a UNC path it needs to
  2411. // have at least 2 components, so we don't filter for that here.
  2412. // This means that the user can use join to construct UNC paths from
  2413. // a server name and a share name; for example:
  2414. // path.join('//server', 'share') -> '\\\\server\\share\\')
  2415. let needsReplace = true;
  2416. let slashCount = 0;
  2417. if (typeof firstPart === 'string' && isPathSeparator(firstPart.charCodeAt(0))) {
  2418. ++slashCount;
  2419. const firstLen = firstPart.length;
  2420. if (firstLen > 1 && isPathSeparator(firstPart.charCodeAt(1))) {
  2421. ++slashCount;
  2422. if (firstLen > 2) {
  2423. if (isPathSeparator(firstPart.charCodeAt(2))) {
  2424. ++slashCount;
  2425. }
  2426. else {
  2427. // We matched a UNC path in the first part
  2428. needsReplace = false;
  2429. }
  2430. }
  2431. }
  2432. }
  2433. if (needsReplace) {
  2434. // Find any more consecutive slashes we need to replace
  2435. while (slashCount < joined.length &&
  2436. isPathSeparator(joined.charCodeAt(slashCount))) {
  2437. slashCount++;
  2438. }
  2439. // Replace the slashes if needed
  2440. if (slashCount >= 2) {
  2441. joined = `\\${joined.slice(slashCount)}`;
  2442. }
  2443. }
  2444. return win32.normalize(joined);
  2445. },
  2446. // It will solve the relative path from `from` to `to`, for instance:
  2447. // from = 'C:\\orandea\\test\\aaa'
  2448. // to = 'C:\\orandea\\impl\\bbb'
  2449. // The output of the function should be: '..\\..\\impl\\bbb'
  2450. relative(from, to) {
  2451. validateString(from, 'from');
  2452. validateString(to, 'to');
  2453. if (from === to) {
  2454. return '';
  2455. }
  2456. const fromOrig = win32.resolve(from);
  2457. const toOrig = win32.resolve(to);
  2458. if (fromOrig === toOrig) {
  2459. return '';
  2460. }
  2461. from = fromOrig.toLowerCase();
  2462. to = toOrig.toLowerCase();
  2463. if (from === to) {
  2464. return '';
  2465. }
  2466. // Trim any leading backslashes
  2467. let fromStart = 0;
  2468. while (fromStart < from.length &&
  2469. from.charCodeAt(fromStart) === CHAR_BACKWARD_SLASH) {
  2470. fromStart++;
  2471. }
  2472. // Trim trailing backslashes (applicable to UNC paths only)
  2473. let fromEnd = from.length;
  2474. while (fromEnd - 1 > fromStart &&
  2475. from.charCodeAt(fromEnd - 1) === CHAR_BACKWARD_SLASH) {
  2476. fromEnd--;
  2477. }
  2478. const fromLen = fromEnd - fromStart;
  2479. // Trim any leading backslashes
  2480. let toStart = 0;
  2481. while (toStart < to.length &&
  2482. to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
  2483. toStart++;
  2484. }
  2485. // Trim trailing backslashes (applicable to UNC paths only)
  2486. let toEnd = to.length;
  2487. while (toEnd - 1 > toStart &&
  2488. to.charCodeAt(toEnd - 1) === CHAR_BACKWARD_SLASH) {
  2489. toEnd--;
  2490. }
  2491. const toLen = toEnd - toStart;
  2492. // Compare paths to find the longest common path from root
  2493. const length = fromLen < toLen ? fromLen : toLen;
  2494. let lastCommonSep = -1;
  2495. let i = 0;
  2496. for (; i < length; i++) {
  2497. const fromCode = from.charCodeAt(fromStart + i);
  2498. if (fromCode !== to.charCodeAt(toStart + i)) {
  2499. break;
  2500. }
  2501. else if (fromCode === CHAR_BACKWARD_SLASH) {
  2502. lastCommonSep = i;
  2503. }
  2504. }
  2505. // We found a mismatch before the first common path separator was seen, so
  2506. // return the original `to`.
  2507. if (i !== length) {
  2508. if (lastCommonSep === -1) {
  2509. return toOrig;
  2510. }
  2511. }
  2512. else {
  2513. if (toLen > length) {
  2514. if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
  2515. // We get here if `from` is the exact base path for `to`.
  2516. // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
  2517. return toOrig.slice(toStart + i + 1);
  2518. }
  2519. if (i === 2) {
  2520. // We get here if `from` is the device root.
  2521. // For example: from='C:\\'; to='C:\\foo'
  2522. return toOrig.slice(toStart + i);
  2523. }
  2524. }
  2525. if (fromLen > length) {
  2526. if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
  2527. // We get here if `to` is the exact base path for `from`.
  2528. // For example: from='C:\\foo\\bar'; to='C:\\foo'
  2529. lastCommonSep = i;
  2530. }
  2531. else if (i === 2) {
  2532. // We get here if `to` is the device root.
  2533. // For example: from='C:\\foo\\bar'; to='C:\\'
  2534. lastCommonSep = 3;
  2535. }
  2536. }
  2537. if (lastCommonSep === -1) {
  2538. lastCommonSep = 0;
  2539. }
  2540. }
  2541. let out = '';
  2542. // Generate the relative path based on the path difference between `to` and
  2543. // `from`
  2544. for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
  2545. if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
  2546. out += out.length === 0 ? '..' : '\\..';
  2547. }
  2548. }
  2549. toStart += lastCommonSep;
  2550. // Lastly, append the rest of the destination (`to`) path that comes after
  2551. // the common path parts
  2552. if (out.length > 0) {
  2553. return `${out}${toOrig.slice(toStart, toEnd)}`;
  2554. }
  2555. if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
  2556. ++toStart;
  2557. }
  2558. return toOrig.slice(toStart, toEnd);
  2559. },
  2560. toNamespacedPath(path) {
  2561. // Note: this will *probably* throw somewhere.
  2562. if (typeof path !== 'string' || path.length === 0) {
  2563. return path;
  2564. }
  2565. const resolvedPath = win32.resolve(path);
  2566. if (resolvedPath.length <= 2) {
  2567. return path;
  2568. }
  2569. if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
  2570. // Possible UNC root
  2571. if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
  2572. const code = resolvedPath.charCodeAt(2);
  2573. if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
  2574. // Matched non-long UNC root, convert the path to a long UNC path
  2575. return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
  2576. }
  2577. }
  2578. }
  2579. else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) &&
  2580. resolvedPath.charCodeAt(1) === CHAR_COLON &&
  2581. resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
  2582. // Matched device root, convert the path to a long UNC path
  2583. return `\\\\?\\${resolvedPath}`;
  2584. }
  2585. return path;
  2586. },
  2587. dirname(path) {
  2588. validateString(path, 'path');
  2589. const len = path.length;
  2590. if (len === 0) {
  2591. return '.';
  2592. }
  2593. let rootEnd = -1;
  2594. let offset = 0;
  2595. const code = path.charCodeAt(0);
  2596. if (len === 1) {
  2597. // `path` contains just a path separator, exit early to avoid
  2598. // unnecessary work or a dot.
  2599. return isPathSeparator(code) ? path : '.';
  2600. }
  2601. // Try to match a root
  2602. if (isPathSeparator(code)) {
  2603. // Possible UNC root
  2604. rootEnd = offset = 1;
  2605. if (isPathSeparator(path.charCodeAt(1))) {
  2606. // Matched double path separator at beginning
  2607. let j = 2;
  2608. let last = j;
  2609. // Match 1 or more non-path separators
  2610. while (j < len && !isPathSeparator(path.charCodeAt(j))) {
  2611. j++;
  2612. }
  2613. if (j < len && j !== last) {
  2614. // Matched!
  2615. last = j;
  2616. // Match 1 or more path separators
  2617. while (j < len && isPathSeparator(path.charCodeAt(j))) {
  2618. j++;
  2619. }
  2620. if (j < len && j !== last) {
  2621. // Matched!
  2622. last = j;
  2623. // Match 1 or more non-path separators
  2624. while (j < len && !isPathSeparator(path.charCodeAt(j))) {
  2625. j++;
  2626. }
  2627. if (j === len) {
  2628. // We matched a UNC root only
  2629. return path;
  2630. }
  2631. if (j !== last) {
  2632. // We matched a UNC root with leftovers
  2633. // Offset by 1 to include the separator after the UNC root to
  2634. // treat it as a "normal root" on top of a (UNC) root
  2635. rootEnd = offset = j + 1;
  2636. }
  2637. }
  2638. }
  2639. }
  2640. // Possible device root
  2641. }
  2642. else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
  2643. rootEnd = len > 2 && isPathSeparator(path.charCodeAt(2)) ? 3 : 2;
  2644. offset = rootEnd;
  2645. }
  2646. let end = -1;
  2647. let matchedSlash = true;
  2648. for (let i = len - 1; i >= offset; --i) {
  2649. if (isPathSeparator(path.charCodeAt(i))) {
  2650. if (!matchedSlash) {
  2651. end = i;
  2652. break;
  2653. }
  2654. }
  2655. else {
  2656. // We saw the first non-path separator
  2657. matchedSlash = false;
  2658. }
  2659. }
  2660. if (end === -1) {
  2661. if (rootEnd === -1) {
  2662. return '.';
  2663. }
  2664. end = rootEnd;
  2665. }
  2666. return path.slice(0, end);
  2667. },
  2668. basename(path, suffix) {
  2669. if (suffix !== undefined) {
  2670. validateString(suffix, 'suffix');
  2671. }
  2672. validateString(path, 'path');
  2673. let start = 0;
  2674. let end = -1;
  2675. let matchedSlash = true;
  2676. let i;
  2677. // Check for a drive letter prefix so as not to mistake the following
  2678. // path separator as an extra separator at the end of the path that can be
  2679. // disregarded
  2680. if (path.length >= 2 &&
  2681. isWindowsDeviceRoot(path.charCodeAt(0)) &&
  2682. path.charCodeAt(1) === CHAR_COLON) {
  2683. start = 2;
  2684. }
  2685. if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
  2686. if (suffix === path) {
  2687. return '';
  2688. }
  2689. let extIdx = suffix.length - 1;
  2690. let firstNonSlashEnd = -1;
  2691. for (i = path.length - 1; i >= start; --i) {
  2692. const code = path.charCodeAt(i);
  2693. if (isPathSeparator(code)) {
  2694. // If we reached a path separator that was not part of a set of path
  2695. // separators at the end of the string, stop now
  2696. if (!matchedSlash) {
  2697. start = i + 1;
  2698. break;
  2699. }
  2700. }
  2701. else {
  2702. if (firstNonSlashEnd === -1) {
  2703. // We saw the first non-path separator, remember this index in case
  2704. // we need it if the extension ends up not matching
  2705. matchedSlash = false;
  2706. firstNonSlashEnd = i + 1;
  2707. }
  2708. if (extIdx >= 0) {
  2709. // Try to match the explicit extension
  2710. if (code === suffix.charCodeAt(extIdx)) {
  2711. if (--extIdx === -1) {
  2712. // We matched the extension, so mark this as the end of our path
  2713. // component
  2714. end = i;
  2715. }
  2716. }
  2717. else {
  2718. // Extension does not match, so our result is the entire path
  2719. // component
  2720. extIdx = -1;
  2721. end = firstNonSlashEnd;
  2722. }
  2723. }
  2724. }
  2725. }
  2726. if (start === end) {
  2727. end = firstNonSlashEnd;
  2728. }
  2729. else if (end === -1) {
  2730. end = path.length;
  2731. }
  2732. return path.slice(start, end);
  2733. }
  2734. for (i = path.length - 1; i >= start; --i) {
  2735. if (isPathSeparator(path.charCodeAt(i))) {
  2736. // If we reached a path separator that was not part of a set of path
  2737. // separators at the end of the string, stop now
  2738. if (!matchedSlash) {
  2739. start = i + 1;
  2740. break;
  2741. }
  2742. }
  2743. else if (end === -1) {
  2744. // We saw the first non-path separator, mark this as the end of our
  2745. // path component
  2746. matchedSlash = false;
  2747. end = i + 1;
  2748. }
  2749. }
  2750. if (end === -1) {
  2751. return '';
  2752. }
  2753. return path.slice(start, end);
  2754. },
  2755. extname(path) {
  2756. validateString(path, 'path');
  2757. let start = 0;
  2758. let startDot = -1;
  2759. let startPart = 0;
  2760. let end = -1;
  2761. let matchedSlash = true;
  2762. // Track the state of characters (if any) we see before our first dot and
  2763. // after any path separator we find
  2764. let preDotState = 0;
  2765. // Check for a drive letter prefix so as not to mistake the following
  2766. // path separator as an extra separator at the end of the path that can be
  2767. // disregarded
  2768. if (path.length >= 2 &&
  2769. path.charCodeAt(1) === CHAR_COLON &&
  2770. isWindowsDeviceRoot(path.charCodeAt(0))) {
  2771. start = startPart = 2;
  2772. }
  2773. for (let i = path.length - 1; i >= start; --i) {
  2774. const code = path.charCodeAt(i);
  2775. if (isPathSeparator(code)) {
  2776. // If we reached a path separator that was not part of a set of path
  2777. // separators at the end of the string, stop now
  2778. if (!matchedSlash) {
  2779. startPart = i + 1;
  2780. break;
  2781. }
  2782. continue;
  2783. }
  2784. if (end === -1) {
  2785. // We saw the first non-path separator, mark this as the end of our
  2786. // extension
  2787. matchedSlash = false;
  2788. end = i + 1;
  2789. }
  2790. if (code === CHAR_DOT) {
  2791. // If this is our first dot, mark it as the start of our extension
  2792. if (startDot === -1) {
  2793. startDot = i;
  2794. }
  2795. else if (preDotState !== 1) {
  2796. preDotState = 1;
  2797. }
  2798. }
  2799. else if (startDot !== -1) {
  2800. // We saw a non-dot and non-path separator before our dot, so we should
  2801. // have a good chance at having a non-empty extension
  2802. preDotState = -1;
  2803. }
  2804. }
  2805. if (startDot === -1 ||
  2806. end === -1 ||
  2807. // We saw a non-dot character immediately before the dot
  2808. preDotState === 0 ||
  2809. // The (right-most) trimmed path component is exactly '..'
  2810. (preDotState === 1 &&
  2811. startDot === end - 1 &&
  2812. startDot === startPart + 1)) {
  2813. return '';
  2814. }
  2815. return path.slice(startDot, end);
  2816. },
  2817. format: _format.bind(null, '\\'),
  2818. parse(path) {
  2819. validateString(path, 'path');
  2820. const ret = { root: '', dir: '', base: '', ext: '', name: '' };
  2821. if (path.length === 0) {
  2822. return ret;
  2823. }
  2824. const len = path.length;
  2825. let rootEnd = 0;
  2826. let code = path.charCodeAt(0);
  2827. if (len === 1) {
  2828. if (isPathSeparator(code)) {
  2829. // `path` contains just a path separator, exit early to avoid
  2830. // unnecessary work
  2831. ret.root = ret.dir = path;
  2832. return ret;
  2833. }
  2834. ret.base = ret.name = path;
  2835. return ret;
  2836. }
  2837. // Try to match a root
  2838. if (isPathSeparator(code)) {
  2839. // Possible UNC root
  2840. rootEnd = 1;
  2841. if (isPathSeparator(path.charCodeAt(1))) {
  2842. // Matched double path separator at beginning
  2843. let j = 2;
  2844. let last = j;
  2845. // Match 1 or more non-path separators
  2846. while (j < len && !isPathSeparator(path.charCodeAt(j))) {
  2847. j++;
  2848. }
  2849. if (j < len && j !== last) {
  2850. // Matched!
  2851. last = j;
  2852. // Match 1 or more path separators
  2853. while (j < len && isPathSeparator(path.charCodeAt(j))) {
  2854. j++;
  2855. }
  2856. if (j < len && j !== last) {
  2857. // Matched!
  2858. last = j;
  2859. // Match 1 or more non-path separators
  2860. while (j < len && !isPathSeparator(path.charCodeAt(j))) {
  2861. j++;
  2862. }
  2863. if (j === len) {
  2864. // We matched a UNC root only
  2865. rootEnd = j;
  2866. }
  2867. else if (j !== last) {
  2868. // We matched a UNC root with leftovers
  2869. rootEnd = j + 1;
  2870. }
  2871. }
  2872. }
  2873. }
  2874. }
  2875. else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
  2876. // Possible device root
  2877. if (len <= 2) {
  2878. // `path` contains just a drive root, exit early to avoid
  2879. // unnecessary work
  2880. ret.root = ret.dir = path;
  2881. return ret;
  2882. }
  2883. rootEnd = 2;
  2884. if (isPathSeparator(path.charCodeAt(2))) {
  2885. if (len === 3) {
  2886. // `path` contains just a drive root, exit early to avoid
  2887. // unnecessary work
  2888. ret.root = ret.dir = path;
  2889. return ret;
  2890. }
  2891. rootEnd = 3;
  2892. }
  2893. }
  2894. if (rootEnd > 0) {
  2895. ret.root = path.slice(0, rootEnd);
  2896. }
  2897. let startDot = -1;
  2898. let startPart = rootEnd;
  2899. let end = -1;
  2900. let matchedSlash = true;
  2901. let i = path.length - 1;
  2902. // Track the state of characters (if any) we see before our first dot and
  2903. // after any path separator we find
  2904. let preDotState = 0;
  2905. // Get non-dir info
  2906. for (; i >= rootEnd; --i) {
  2907. code = path.charCodeAt(i);
  2908. if (isPathSeparator(code)) {
  2909. // If we reached a path separator that was not part of a set of path
  2910. // separators at the end of the string, stop now
  2911. if (!matchedSlash) {
  2912. startPart = i + 1;
  2913. break;
  2914. }
  2915. continue;
  2916. }
  2917. if (end === -1) {
  2918. // We saw the first non-path separator, mark this as the end of our
  2919. // extension
  2920. matchedSlash = false;
  2921. end = i + 1;
  2922. }
  2923. if (code === CHAR_DOT) {
  2924. // If this is our first dot, mark it as the start of our extension
  2925. if (startDot === -1) {
  2926. startDot = i;
  2927. }
  2928. else if (preDotState !== 1) {
  2929. preDotState = 1;
  2930. }
  2931. }
  2932. else if (startDot !== -1) {
  2933. // We saw a non-dot and non-path separator before our dot, so we should
  2934. // have a good chance at having a non-empty extension
  2935. preDotState = -1;
  2936. }
  2937. }
  2938. if (end !== -1) {
  2939. if (startDot === -1 ||
  2940. // We saw a non-dot character immediately before the dot
  2941. preDotState === 0 ||
  2942. // The (right-most) trimmed path component is exactly '..'
  2943. (preDotState === 1 &&
  2944. startDot === end - 1 &&
  2945. startDot === startPart + 1)) {
  2946. ret.base = ret.name = path.slice(startPart, end);
  2947. }
  2948. else {
  2949. ret.name = path.slice(startPart, startDot);
  2950. ret.base = path.slice(startPart, end);
  2951. ret.ext = path.slice(startDot, end);
  2952. }
  2953. }
  2954. // If the directory is the root, use the entire root as the `dir` including
  2955. // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
  2956. // trailing slash (`C:\abc\def` -> `C:\abc`).
  2957. if (startPart > 0 && startPart !== rootEnd) {
  2958. ret.dir = path.slice(0, startPart - 1);
  2959. }
  2960. else {
  2961. ret.dir = ret.root;
  2962. }
  2963. return ret;
  2964. },
  2965. sep: '\\',
  2966. delimiter: ';',
  2967. win32: null,
  2968. posix: null
  2969. };
  2970. const posixCwd = (() => {
  2971. if (platformIsWin32) {
  2972. // Converts Windows' backslash path separators to POSIX forward slashes
  2973. // and truncates any drive indicator
  2974. const regexp = /\\/g;
  2975. return () => {
  2976. const cwd$1 = cwd().replace(regexp, '/');
  2977. return cwd$1.slice(cwd$1.indexOf('/'));
  2978. };
  2979. }
  2980. // We're already on POSIX, no need for any transformations
  2981. return () => cwd();
  2982. })();
  2983. const posix = {
  2984. // path.resolve([from ...], to)
  2985. resolve(...pathSegments) {
  2986. let resolvedPath = '';
  2987. let resolvedAbsolute = false;
  2988. for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  2989. const path = i >= 0 ? pathSegments[i] : posixCwd();
  2990. validateString(path, `paths[${i}]`);
  2991. // Skip empty entries
  2992. if (path.length === 0) {
  2993. continue;
  2994. }
  2995. resolvedPath = `${path}/${resolvedPath}`;
  2996. resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
  2997. }
  2998. // At this point the path should be resolved to a full absolute path, but
  2999. // handle relative paths to be safe (might happen when process.cwd() fails)
  3000. // Normalize the path
  3001. resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
  3002. if (resolvedAbsolute) {
  3003. return `/${resolvedPath}`;
  3004. }
  3005. return resolvedPath.length > 0 ? resolvedPath : '.';
  3006. },
  3007. normalize(path) {
  3008. validateString(path, 'path');
  3009. if (path.length === 0) {
  3010. return '.';
  3011. }
  3012. const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
  3013. const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
  3014. // Normalize the path
  3015. path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);
  3016. if (path.length === 0) {
  3017. if (isAbsolute) {
  3018. return '/';
  3019. }
  3020. return trailingSeparator ? './' : '.';
  3021. }
  3022. if (trailingSeparator) {
  3023. path += '/';
  3024. }
  3025. return isAbsolute ? `/${path}` : path;
  3026. },
  3027. isAbsolute(path) {
  3028. validateString(path, 'path');
  3029. return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
  3030. },
  3031. join(...paths) {
  3032. if (paths.length === 0) {
  3033. return '.';
  3034. }
  3035. let joined;
  3036. for (let i = 0; i < paths.length; ++i) {
  3037. const arg = paths[i];
  3038. validateString(arg, 'path');
  3039. if (arg.length > 0) {
  3040. if (joined === undefined) {
  3041. joined = arg;
  3042. }
  3043. else {
  3044. joined += `/${arg}`;
  3045. }
  3046. }
  3047. }
  3048. if (joined === undefined) {
  3049. return '.';
  3050. }
  3051. return posix.normalize(joined);
  3052. },
  3053. relative(from, to) {
  3054. validateString(from, 'from');
  3055. validateString(to, 'to');
  3056. if (from === to) {
  3057. return '';
  3058. }
  3059. // Trim leading forward slashes.
  3060. from = posix.resolve(from);
  3061. to = posix.resolve(to);
  3062. if (from === to) {
  3063. return '';
  3064. }
  3065. const fromStart = 1;
  3066. const fromEnd = from.length;
  3067. const fromLen = fromEnd - fromStart;
  3068. const toStart = 1;
  3069. const toLen = to.length - toStart;
  3070. // Compare paths to find the longest common path from root
  3071. const length = (fromLen < toLen ? fromLen : toLen);
  3072. let lastCommonSep = -1;
  3073. let i = 0;
  3074. for (; i < length; i++) {
  3075. const fromCode = from.charCodeAt(fromStart + i);
  3076. if (fromCode !== to.charCodeAt(toStart + i)) {
  3077. break;
  3078. }
  3079. else if (fromCode === CHAR_FORWARD_SLASH) {
  3080. lastCommonSep = i;
  3081. }
  3082. }
  3083. if (i === length) {
  3084. if (toLen > length) {
  3085. if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
  3086. // We get here if `from` is the exact base path for `to`.
  3087. // For example: from='/foo/bar'; to='/foo/bar/baz'
  3088. return to.slice(toStart + i + 1);
  3089. }
  3090. if (i === 0) {
  3091. // We get here if `from` is the root
  3092. // For example: from='/'; to='/foo'
  3093. return to.slice(toStart + i);
  3094. }
  3095. }
  3096. else if (fromLen > length) {
  3097. if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
  3098. // We get here if `to` is the exact base path for `from`.
  3099. // For example: from='/foo/bar/baz'; to='/foo/bar'
  3100. lastCommonSep = i;
  3101. }
  3102. else if (i === 0) {
  3103. // We get here if `to` is the root.
  3104. // For example: from='/foo/bar'; to='/'
  3105. lastCommonSep = 0;
  3106. }
  3107. }
  3108. }
  3109. let out = '';
  3110. // Generate the relative path based on the path difference between `to`
  3111. // and `from`.
  3112. for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
  3113. if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
  3114. out += out.length === 0 ? '..' : '/..';
  3115. }
  3116. }
  3117. // Lastly, append the rest of the destination (`to`) path that comes after
  3118. // the common path parts.
  3119. return `${out}${to.slice(toStart + lastCommonSep)}`;
  3120. },
  3121. toNamespacedPath(path) {
  3122. // Non-op on posix systems
  3123. return path;
  3124. },
  3125. dirname(path) {
  3126. validateString(path, 'path');
  3127. if (path.length === 0) {
  3128. return '.';
  3129. }
  3130. const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
  3131. let end = -1;
  3132. let matchedSlash = true;
  3133. for (let i = path.length - 1; i >= 1; --i) {
  3134. if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
  3135. if (!matchedSlash) {
  3136. end = i;
  3137. break;
  3138. }
  3139. }
  3140. else {
  3141. // We saw the first non-path separator
  3142. matchedSlash = false;
  3143. }
  3144. }
  3145. if (end === -1) {
  3146. return hasRoot ? '/' : '.';
  3147. }
  3148. if (hasRoot && end === 1) {
  3149. return '//';
  3150. }
  3151. return path.slice(0, end);
  3152. },
  3153. basename(path, suffix) {
  3154. if (suffix !== undefined) {
  3155. validateString(suffix, 'ext');
  3156. }
  3157. validateString(path, 'path');
  3158. let start = 0;
  3159. let end = -1;
  3160. let matchedSlash = true;
  3161. let i;
  3162. if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
  3163. if (suffix === path) {
  3164. return '';
  3165. }
  3166. let extIdx = suffix.length - 1;
  3167. let firstNonSlashEnd = -1;
  3168. for (i = path.length - 1; i >= 0; --i) {
  3169. const code = path.charCodeAt(i);
  3170. if (code === CHAR_FORWARD_SLASH) {
  3171. // If we reached a path separator that was not part of a set of path
  3172. // separators at the end of the string, stop now
  3173. if (!matchedSlash) {
  3174. start = i + 1;
  3175. break;
  3176. }
  3177. }
  3178. else {
  3179. if (firstNonSlashEnd === -1) {
  3180. // We saw the first non-path separator, remember this index in case
  3181. // we need it if the extension ends up not matching
  3182. matchedSlash = false;
  3183. firstNonSlashEnd = i + 1;
  3184. }
  3185. if (extIdx >= 0) {
  3186. // Try to match the explicit extension
  3187. if (code === suffix.charCodeAt(extIdx)) {
  3188. if (--extIdx === -1) {
  3189. // We matched the extension, so mark this as the end of our path
  3190. // component
  3191. end = i;
  3192. }
  3193. }
  3194. else {
  3195. // Extension does not match, so our result is the entire path
  3196. // component
  3197. extIdx = -1;
  3198. end = firstNonSlashEnd;
  3199. }
  3200. }
  3201. }
  3202. }
  3203. if (start === end) {
  3204. end = firstNonSlashEnd;
  3205. }
  3206. else if (end === -1) {
  3207. end = path.length;
  3208. }
  3209. return path.slice(start, end);
  3210. }
  3211. for (i = path.length - 1; i >= 0; --i) {
  3212. if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
  3213. // If we reached a path separator that was not part of a set of path
  3214. // separators at the end of the string, stop now
  3215. if (!matchedSlash) {
  3216. start = i + 1;
  3217. break;
  3218. }
  3219. }
  3220. else if (end === -1) {
  3221. // We saw the first non-path separator, mark this as the end of our
  3222. // path component
  3223. matchedSlash = false;
  3224. end = i + 1;
  3225. }
  3226. }
  3227. if (end === -1) {
  3228. return '';
  3229. }
  3230. return path.slice(start, end);
  3231. },
  3232. extname(path) {
  3233. validateString(path, 'path');
  3234. let startDot = -1;
  3235. let startPart = 0;
  3236. let end = -1;
  3237. let matchedSlash = true;
  3238. // Track the state of characters (if any) we see before our first dot and
  3239. // after any path separator we find
  3240. let preDotState = 0;
  3241. for (let i = path.length - 1; i >= 0; --i) {
  3242. const code = path.charCodeAt(i);
  3243. if (code === CHAR_FORWARD_SLASH) {
  3244. // If we reached a path separator that was not part of a set of path
  3245. // separators at the end of the string, stop now
  3246. if (!matchedSlash) {
  3247. startPart = i + 1;
  3248. break;
  3249. }
  3250. continue;
  3251. }
  3252. if (end === -1) {
  3253. // We saw the first non-path separator, mark this as the end of our
  3254. // extension
  3255. matchedSlash = false;
  3256. end = i + 1;
  3257. }
  3258. if (code === CHAR_DOT) {
  3259. // If this is our first dot, mark it as the start of our extension
  3260. if (startDot === -1) {
  3261. startDot = i;
  3262. }
  3263. else if (preDotState !== 1) {
  3264. preDotState = 1;
  3265. }
  3266. }
  3267. else if (startDot !== -1) {
  3268. // We saw a non-dot and non-path separator before our dot, so we should
  3269. // have a good chance at having a non-empty extension
  3270. preDotState = -1;
  3271. }
  3272. }
  3273. if (startDot === -1 ||
  3274. end === -1 ||
  3275. // We saw a non-dot character immediately before the dot
  3276. preDotState === 0 ||
  3277. // The (right-most) trimmed path component is exactly '..'
  3278. (preDotState === 1 &&
  3279. startDot === end - 1 &&
  3280. startDot === startPart + 1)) {
  3281. return '';
  3282. }
  3283. return path.slice(startDot, end);
  3284. },
  3285. format: _format.bind(null, '/'),
  3286. parse(path) {
  3287. validateString(path, 'path');
  3288. const ret = { root: '', dir: '', base: '', ext: '', name: '' };
  3289. if (path.length === 0) {
  3290. return ret;
  3291. }
  3292. const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
  3293. let start;
  3294. if (isAbsolute) {
  3295. ret.root = '/';
  3296. start = 1;
  3297. }
  3298. else {
  3299. start = 0;
  3300. }
  3301. let startDot = -1;
  3302. let startPart = 0;
  3303. let end = -1;
  3304. let matchedSlash = true;
  3305. let i = path.length - 1;
  3306. // Track the state of characters (if any) we see before our first dot and
  3307. // after any path separator we find
  3308. let preDotState = 0;
  3309. // Get non-dir info
  3310. for (; i >= start; --i) {
  3311. const code = path.charCodeAt(i);
  3312. if (code === CHAR_FORWARD_SLASH) {
  3313. // If we reached a path separator that was not part of a set of path
  3314. // separators at the end of the string, stop now
  3315. if (!matchedSlash) {
  3316. startPart = i + 1;
  3317. break;
  3318. }
  3319. continue;
  3320. }
  3321. if (end === -1) {
  3322. // We saw the first non-path separator, mark this as the end of our
  3323. // extension
  3324. matchedSlash = false;
  3325. end = i + 1;
  3326. }
  3327. if (code === CHAR_DOT) {
  3328. // If this is our first dot, mark it as the start of our extension
  3329. if (startDot === -1) {
  3330. startDot = i;
  3331. }
  3332. else if (preDotState !== 1) {
  3333. preDotState = 1;
  3334. }
  3335. }
  3336. else if (startDot !== -1) {
  3337. // We saw a non-dot and non-path separator before our dot, so we should
  3338. // have a good chance at having a non-empty extension
  3339. preDotState = -1;
  3340. }
  3341. }
  3342. if (end !== -1) {
  3343. const start = startPart === 0 && isAbsolute ? 1 : startPart;
  3344. if (startDot === -1 ||
  3345. // We saw a non-dot character immediately before the dot
  3346. preDotState === 0 ||
  3347. // The (right-most) trimmed path component is exactly '..'
  3348. (preDotState === 1 &&
  3349. startDot === end - 1 &&
  3350. startDot === startPart + 1)) {
  3351. ret.base = ret.name = path.slice(start, end);
  3352. }
  3353. else {
  3354. ret.name = path.slice(start, startDot);
  3355. ret.base = path.slice(start, end);
  3356. ret.ext = path.slice(startDot, end);
  3357. }
  3358. }
  3359. if (startPart > 0) {
  3360. ret.dir = path.slice(0, startPart - 1);
  3361. }
  3362. else if (isAbsolute) {
  3363. ret.dir = '/';
  3364. }
  3365. return ret;
  3366. },
  3367. sep: '/',
  3368. delimiter: ':',
  3369. win32: null,
  3370. posix: null
  3371. };
  3372. posix.win32 = win32.win32 = win32;
  3373. posix.posix = win32.posix = posix;
  3374. (platformIsWin32 ? win32.normalize : posix.normalize);
  3375. const join = (platformIsWin32 ? win32.join : posix.join);
  3376. (platformIsWin32 ? win32.resolve : posix.resolve);
  3377. (platformIsWin32 ? win32.relative : posix.relative);
  3378. (platformIsWin32 ? win32.dirname : posix.dirname);
  3379. (platformIsWin32 ? win32.basename : posix.basename);
  3380. (platformIsWin32 ? win32.extname : posix.extname);
  3381. (platformIsWin32 ? win32.sep : posix.sep);
  3382. /*---------------------------------------------------------------------------------------------
  3383. * Copyright (c) Microsoft Corporation. All rights reserved.
  3384. * Licensed under the MIT License. See License.txt in the project root for license information.
  3385. *--------------------------------------------------------------------------------------------*/
  3386. const _schemePattern = /^\w[\w\d+.-]*$/;
  3387. const _singleSlashStart = /^\//;
  3388. const _doubleSlashStart = /^\/\//;
  3389. function _validateUri(ret, _strict) {
  3390. // scheme, must be set
  3391. if (!ret.scheme && _strict) {
  3392. throw new Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`);
  3393. }
  3394. // scheme, https://tools.ietf.org/html/rfc3986#section-3.1
  3395. // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  3396. if (ret.scheme && !_schemePattern.test(ret.scheme)) {
  3397. throw new Error('[UriError]: Scheme contains illegal characters.');
  3398. }
  3399. // path, http://tools.ietf.org/html/rfc3986#section-3.3
  3400. // If a URI contains an authority component, then the path component
  3401. // must either be empty or begin with a slash ("/") character. If a URI
  3402. // does not contain an authority component, then the path cannot begin
  3403. // with two slash characters ("//").
  3404. if (ret.path) {
  3405. if (ret.authority) {
  3406. if (!_singleSlashStart.test(ret.path)) {
  3407. 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');
  3408. }
  3409. }
  3410. else {
  3411. if (_doubleSlashStart.test(ret.path)) {
  3412. throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")');
  3413. }
  3414. }
  3415. }
  3416. }
  3417. // for a while we allowed uris *without* schemes and this is the migration
  3418. // for them, e.g. an uri without scheme and without strict-mode warns and falls
  3419. // back to the file-scheme. that should cause the least carnage and still be a
  3420. // clear warning
  3421. function _schemeFix(scheme, _strict) {
  3422. if (!scheme && !_strict) {
  3423. return 'file';
  3424. }
  3425. return scheme;
  3426. }
  3427. // implements a bit of https://tools.ietf.org/html/rfc3986#section-5
  3428. function _referenceResolution(scheme, path) {
  3429. // the slash-character is our 'default base' as we don't
  3430. // support constructing URIs relative to other URIs. This
  3431. // also means that we alter and potentially break paths.
  3432. // see https://tools.ietf.org/html/rfc3986#section-5.1.4
  3433. switch (scheme) {
  3434. case 'https':
  3435. case 'http':
  3436. case 'file':
  3437. if (!path) {
  3438. path = _slash;
  3439. }
  3440. else if (path[0] !== _slash) {
  3441. path = _slash + path;
  3442. }
  3443. break;
  3444. }
  3445. return path;
  3446. }
  3447. const _empty = '';
  3448. const _slash = '/';
  3449. const _regexp = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
  3450. /**
  3451. * Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986.
  3452. * This class is a simple parser which creates the basic component parts
  3453. * (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation
  3454. * and encoding.
  3455. *
  3456. * ```txt
  3457. * foo://example.com:8042/over/there?name=ferret#nose
  3458. * \_/ \______________/\_________/ \_________/ \__/
  3459. * | | | | |
  3460. * scheme authority path query fragment
  3461. * | _____________________|__
  3462. * / \ / \
  3463. * urn:example:animal:ferret:nose
  3464. * ```
  3465. */
  3466. class URI {
  3467. static isUri(thing) {
  3468. if (thing instanceof URI) {
  3469. return true;
  3470. }
  3471. if (!thing) {
  3472. return false;
  3473. }
  3474. return typeof thing.authority === 'string'
  3475. && typeof thing.fragment === 'string'
  3476. && typeof thing.path === 'string'
  3477. && typeof thing.query === 'string'
  3478. && typeof thing.scheme === 'string'
  3479. && typeof thing.fsPath === 'string'
  3480. && typeof thing.with === 'function'
  3481. && typeof thing.toString === 'function';
  3482. }
  3483. /**
  3484. * @internal
  3485. */
  3486. constructor(schemeOrData, authority, path, query, fragment, _strict = false) {
  3487. if (typeof schemeOrData === 'object') {
  3488. this.scheme = schemeOrData.scheme || _empty;
  3489. this.authority = schemeOrData.authority || _empty;
  3490. this.path = schemeOrData.path || _empty;
  3491. this.query = schemeOrData.query || _empty;
  3492. this.fragment = schemeOrData.fragment || _empty;
  3493. // no validation because it's this URI
  3494. // that creates uri components.
  3495. // _validateUri(this);
  3496. }
  3497. else {
  3498. this.scheme = _schemeFix(schemeOrData, _strict);
  3499. this.authority = authority || _empty;
  3500. this.path = _referenceResolution(this.scheme, path || _empty);
  3501. this.query = query || _empty;
  3502. this.fragment = fragment || _empty;
  3503. _validateUri(this, _strict);
  3504. }
  3505. }
  3506. // ---- filesystem path -----------------------
  3507. /**
  3508. * Returns a string representing the corresponding file system path of this URI.
  3509. * Will handle UNC paths, normalizes windows drive letters to lower-case, and uses the
  3510. * platform specific path separator.
  3511. *
  3512. * * Will *not* validate the path for invalid characters and semantics.
  3513. * * Will *not* look at the scheme of this URI.
  3514. * * The result shall *not* be used for display purposes but for accessing a file on disk.
  3515. *
  3516. *
  3517. * The *difference* to `URI#path` is the use of the platform specific separator and the handling
  3518. * of UNC paths. See the below sample of a file-uri with an authority (UNC path).
  3519. *
  3520. * ```ts
  3521. const u = URI.parse('file://server/c$/folder/file.txt')
  3522. u.authority === 'server'
  3523. u.path === '/shares/c$/file.txt'
  3524. u.fsPath === '\\server\c$\folder\file.txt'
  3525. ```
  3526. *
  3527. * Using `URI#path` to read a file (using fs-apis) would not be enough because parts of the path,
  3528. * namely the server name, would be missing. Therefore `URI#fsPath` exists - it's sugar to ease working
  3529. * with URIs that represent files on disk (`file` scheme).
  3530. */
  3531. get fsPath() {
  3532. // if (this.scheme !== 'file') {
  3533. // console.warn(`[UriError] calling fsPath with scheme ${this.scheme}`);
  3534. // }
  3535. return uriToFsPath(this, false);
  3536. }
  3537. // ---- modify to new -------------------------
  3538. with(change) {
  3539. if (!change) {
  3540. return this;
  3541. }
  3542. let { scheme, authority, path, query, fragment } = change;
  3543. if (scheme === undefined) {
  3544. scheme = this.scheme;
  3545. }
  3546. else if (scheme === null) {
  3547. scheme = _empty;
  3548. }
  3549. if (authority === undefined) {
  3550. authority = this.authority;
  3551. }
  3552. else if (authority === null) {
  3553. authority = _empty;
  3554. }
  3555. if (path === undefined) {
  3556. path = this.path;
  3557. }
  3558. else if (path === null) {
  3559. path = _empty;
  3560. }
  3561. if (query === undefined) {
  3562. query = this.query;
  3563. }
  3564. else if (query === null) {
  3565. query = _empty;
  3566. }
  3567. if (fragment === undefined) {
  3568. fragment = this.fragment;
  3569. }
  3570. else if (fragment === null) {
  3571. fragment = _empty;
  3572. }
  3573. if (scheme === this.scheme
  3574. && authority === this.authority
  3575. && path === this.path
  3576. && query === this.query
  3577. && fragment === this.fragment) {
  3578. return this;
  3579. }
  3580. return new Uri(scheme, authority, path, query, fragment);
  3581. }
  3582. // ---- parse & validate ------------------------
  3583. /**
  3584. * Creates a new URI from a string, e.g. `http://www.example.com/some/path`,
  3585. * `file:///usr/home`, or `scheme:with/path`.
  3586. *
  3587. * @param value A string which represents an URI (see `URI#toString`).
  3588. */
  3589. static parse(value, _strict = false) {
  3590. const match = _regexp.exec(value);
  3591. if (!match) {
  3592. return new Uri(_empty, _empty, _empty, _empty, _empty);
  3593. }
  3594. return new Uri(match[2] || _empty, percentDecode(match[4] || _empty), percentDecode(match[5] || _empty), percentDecode(match[7] || _empty), percentDecode(match[9] || _empty), _strict);
  3595. }
  3596. /**
  3597. * Creates a new URI from a file system path, e.g. `c:\my\files`,
  3598. * `/usr/home`, or `\\server\share\some\path`.
  3599. *
  3600. * The *difference* between `URI#parse` and `URI#file` is that the latter treats the argument
  3601. * as path, not as stringified-uri. E.g. `URI.file(path)` is **not the same as**
  3602. * `URI.parse('file://' + path)` because the path might contain characters that are
  3603. * interpreted (# and ?). See the following sample:
  3604. * ```ts
  3605. const good = URI.file('/coding/c#/project1');
  3606. good.scheme === 'file';
  3607. good.path === '/coding/c#/project1';
  3608. good.fragment === '';
  3609. const bad = URI.parse('file://' + '/coding/c#/project1');
  3610. bad.scheme === 'file';
  3611. bad.path === '/coding/c'; // path is now broken
  3612. bad.fragment === '/project1';
  3613. ```
  3614. *
  3615. * @param path A file system path (see `URI#fsPath`)
  3616. */
  3617. static file(path) {
  3618. let authority = _empty;
  3619. // normalize to fwd-slashes on windows,
  3620. // on other systems bwd-slashes are valid
  3621. // filename character, eg /f\oo/ba\r.txt
  3622. if (isWindows) {
  3623. path = path.replace(/\\/g, _slash);
  3624. }
  3625. // check for authority as used in UNC shares
  3626. // or use the path as given
  3627. if (path[0] === _slash && path[1] === _slash) {
  3628. const idx = path.indexOf(_slash, 2);
  3629. if (idx === -1) {
  3630. authority = path.substring(2);
  3631. path = _slash;
  3632. }
  3633. else {
  3634. authority = path.substring(2, idx);
  3635. path = path.substring(idx) || _slash;
  3636. }
  3637. }
  3638. return new Uri('file', authority, path, _empty, _empty);
  3639. }
  3640. /**
  3641. * Creates new URI from uri components.
  3642. *
  3643. * Unless `strict` is `true` the scheme is defaults to be `file`. This function performs
  3644. * validation and should be used for untrusted uri components retrieved from storage,
  3645. * user input, command arguments etc
  3646. */
  3647. static from(components, strict) {
  3648. const result = new Uri(components.scheme, components.authority, components.path, components.query, components.fragment, strict);
  3649. return result;
  3650. }
  3651. /**
  3652. * Join a URI path with path fragments and normalizes the resulting path.
  3653. *
  3654. * @param uri The input URI.
  3655. * @param pathFragment The path fragment to add to the URI path.
  3656. * @returns The resulting URI.
  3657. */
  3658. static joinPath(uri, ...pathFragment) {
  3659. if (!uri.path) {
  3660. throw new Error(`[UriError]: cannot call joinPath on URI without path`);
  3661. }
  3662. let newPath;
  3663. if (isWindows && uri.scheme === 'file') {
  3664. newPath = URI.file(win32.join(uriToFsPath(uri, true), ...pathFragment)).path;
  3665. }
  3666. else {
  3667. newPath = posix.join(uri.path, ...pathFragment);
  3668. }
  3669. return uri.with({ path: newPath });
  3670. }
  3671. // ---- printing/externalize ---------------------------
  3672. /**
  3673. * Creates a string representation for this URI. It's guaranteed that calling
  3674. * `URI.parse` with the result of this function creates an URI which is equal
  3675. * to this URI.
  3676. *
  3677. * * The result shall *not* be used for display purposes but for externalization or transport.
  3678. * * The result will be encoded using the percentage encoding and encoding happens mostly
  3679. * ignore the scheme-specific encoding rules.
  3680. *
  3681. * @param skipEncoding Do not encode the result, default is `false`
  3682. */
  3683. toString(skipEncoding = false) {
  3684. return _asFormatted(this, skipEncoding);
  3685. }
  3686. toJSON() {
  3687. return this;
  3688. }
  3689. static revive(data) {
  3690. if (!data) {
  3691. return data;
  3692. }
  3693. else if (data instanceof URI) {
  3694. return data;
  3695. }
  3696. else {
  3697. const result = new Uri(data);
  3698. result._formatted = data.external ?? null;
  3699. result._fsPath = data._sep === _pathSepMarker ? data.fsPath ?? null : null;
  3700. return result;
  3701. }
  3702. }
  3703. }
  3704. const _pathSepMarker = isWindows ? 1 : undefined;
  3705. // This class exists so that URI is compatible with vscode.Uri (API).
  3706. class Uri extends URI {
  3707. constructor() {
  3708. super(...arguments);
  3709. this._formatted = null;
  3710. this._fsPath = null;
  3711. }
  3712. get fsPath() {
  3713. if (!this._fsPath) {
  3714. this._fsPath = uriToFsPath(this, false);
  3715. }
  3716. return this._fsPath;
  3717. }
  3718. toString(skipEncoding = false) {
  3719. if (!skipEncoding) {
  3720. if (!this._formatted) {
  3721. this._formatted = _asFormatted(this, false);
  3722. }
  3723. return this._formatted;
  3724. }
  3725. else {
  3726. // we don't cache that
  3727. return _asFormatted(this, true);
  3728. }
  3729. }
  3730. toJSON() {
  3731. const res = {
  3732. $mid: 1 /* MarshalledId.Uri */
  3733. };
  3734. // cached state
  3735. if (this._fsPath) {
  3736. res.fsPath = this._fsPath;
  3737. res._sep = _pathSepMarker;
  3738. }
  3739. if (this._formatted) {
  3740. res.external = this._formatted;
  3741. }
  3742. //--- uri components
  3743. if (this.path) {
  3744. res.path = this.path;
  3745. }
  3746. // TODO
  3747. // this isn't correct and can violate the UriComponents contract but
  3748. // this is part of the vscode.Uri API and we shouldn't change how that
  3749. // works anymore
  3750. if (this.scheme) {
  3751. res.scheme = this.scheme;
  3752. }
  3753. if (this.authority) {
  3754. res.authority = this.authority;
  3755. }
  3756. if (this.query) {
  3757. res.query = this.query;
  3758. }
  3759. if (this.fragment) {
  3760. res.fragment = this.fragment;
  3761. }
  3762. return res;
  3763. }
  3764. }
  3765. // reserved characters: https://tools.ietf.org/html/rfc3986#section-2.2
  3766. const encodeTable = {
  3767. [58 /* CharCode.Colon */]: '%3A', // gen-delims
  3768. [47 /* CharCode.Slash */]: '%2F',
  3769. [63 /* CharCode.QuestionMark */]: '%3F',
  3770. [35 /* CharCode.Hash */]: '%23',
  3771. [91 /* CharCode.OpenSquareBracket */]: '%5B',
  3772. [93 /* CharCode.CloseSquareBracket */]: '%5D',
  3773. [64 /* CharCode.AtSign */]: '%40',
  3774. [33 /* CharCode.ExclamationMark */]: '%21', // sub-delims
  3775. [36 /* CharCode.DollarSign */]: '%24',
  3776. [38 /* CharCode.Ampersand */]: '%26',
  3777. [39 /* CharCode.SingleQuote */]: '%27',
  3778. [40 /* CharCode.OpenParen */]: '%28',
  3779. [41 /* CharCode.CloseParen */]: '%29',
  3780. [42 /* CharCode.Asterisk */]: '%2A',
  3781. [43 /* CharCode.Plus */]: '%2B',
  3782. [44 /* CharCode.Comma */]: '%2C',
  3783. [59 /* CharCode.Semicolon */]: '%3B',
  3784. [61 /* CharCode.Equals */]: '%3D',
  3785. [32 /* CharCode.Space */]: '%20',
  3786. };
  3787. function encodeURIComponentFast(uriComponent, isPath, isAuthority) {
  3788. let res = undefined;
  3789. let nativeEncodePos = -1;
  3790. for (let pos = 0; pos < uriComponent.length; pos++) {
  3791. const code = uriComponent.charCodeAt(pos);
  3792. // unreserved characters: https://tools.ietf.org/html/rfc3986#section-2.3
  3793. if ((code >= 97 /* CharCode.a */ && code <= 122 /* CharCode.z */)
  3794. || (code >= 65 /* CharCode.A */ && code <= 90 /* CharCode.Z */)
  3795. || (code >= 48 /* CharCode.Digit0 */ && code <= 57 /* CharCode.Digit9 */)
  3796. || code === 45 /* CharCode.Dash */
  3797. || code === 46 /* CharCode.Period */
  3798. || code === 95 /* CharCode.Underline */
  3799. || code === 126 /* CharCode.Tilde */
  3800. || (isPath && code === 47 /* CharCode.Slash */)
  3801. || (isAuthority && code === 91 /* CharCode.OpenSquareBracket */)
  3802. || (isAuthority && code === 93 /* CharCode.CloseSquareBracket */)
  3803. || (isAuthority && code === 58 /* CharCode.Colon */)) {
  3804. // check if we are delaying native encode
  3805. if (nativeEncodePos !== -1) {
  3806. res += encodeURIComponent(uriComponent.substring(nativeEncodePos, pos));
  3807. nativeEncodePos = -1;
  3808. }
  3809. // check if we write into a new string (by default we try to return the param)
  3810. if (res !== undefined) {
  3811. res += uriComponent.charAt(pos);
  3812. }
  3813. }
  3814. else {
  3815. // encoding needed, we need to allocate a new string
  3816. if (res === undefined) {
  3817. res = uriComponent.substr(0, pos);
  3818. }
  3819. // check with default table first
  3820. const escaped = encodeTable[code];
  3821. if (escaped !== undefined) {
  3822. // check if we are delaying native encode
  3823. if (nativeEncodePos !== -1) {
  3824. res += encodeURIComponent(uriComponent.substring(nativeEncodePos, pos));
  3825. nativeEncodePos = -1;
  3826. }
  3827. // append escaped variant to result
  3828. res += escaped;
  3829. }
  3830. else if (nativeEncodePos === -1) {
  3831. // use native encode only when needed
  3832. nativeEncodePos = pos;
  3833. }
  3834. }
  3835. }
  3836. if (nativeEncodePos !== -1) {
  3837. res += encodeURIComponent(uriComponent.substring(nativeEncodePos));
  3838. }
  3839. return res !== undefined ? res : uriComponent;
  3840. }
  3841. function encodeURIComponentMinimal(path) {
  3842. let res = undefined;
  3843. for (let pos = 0; pos < path.length; pos++) {
  3844. const code = path.charCodeAt(pos);
  3845. if (code === 35 /* CharCode.Hash */ || code === 63 /* CharCode.QuestionMark */) {
  3846. if (res === undefined) {
  3847. res = path.substr(0, pos);
  3848. }
  3849. res += encodeTable[code];
  3850. }
  3851. else {
  3852. if (res !== undefined) {
  3853. res += path[pos];
  3854. }
  3855. }
  3856. }
  3857. return res !== undefined ? res : path;
  3858. }
  3859. /**
  3860. * Compute `fsPath` for the given uri
  3861. */
  3862. function uriToFsPath(uri, keepDriveLetterCasing) {
  3863. let value;
  3864. if (uri.authority && uri.path.length > 1 && uri.scheme === 'file') {
  3865. // unc path: file://shares/c$/far/boo
  3866. value = `//${uri.authority}${uri.path}`;
  3867. }
  3868. else if (uri.path.charCodeAt(0) === 47 /* CharCode.Slash */
  3869. && (uri.path.charCodeAt(1) >= 65 /* CharCode.A */ && uri.path.charCodeAt(1) <= 90 /* CharCode.Z */ || uri.path.charCodeAt(1) >= 97 /* CharCode.a */ && uri.path.charCodeAt(1) <= 122 /* CharCode.z */)
  3870. && uri.path.charCodeAt(2) === 58 /* CharCode.Colon */) {
  3871. if (!keepDriveLetterCasing) {
  3872. // windows drive letter: file:///c:/far/boo
  3873. value = uri.path[1].toLowerCase() + uri.path.substr(2);
  3874. }
  3875. else {
  3876. value = uri.path.substr(1);
  3877. }
  3878. }
  3879. else {
  3880. // other path
  3881. value = uri.path;
  3882. }
  3883. if (isWindows) {
  3884. value = value.replace(/\//g, '\\');
  3885. }
  3886. return value;
  3887. }
  3888. /**
  3889. * Create the external version of a uri
  3890. */
  3891. function _asFormatted(uri, skipEncoding) {
  3892. const encoder = !skipEncoding
  3893. ? encodeURIComponentFast
  3894. : encodeURIComponentMinimal;
  3895. let res = '';
  3896. let { scheme, authority, path, query, fragment } = uri;
  3897. if (scheme) {
  3898. res += scheme;
  3899. res += ':';
  3900. }
  3901. if (authority || scheme === 'file') {
  3902. res += _slash;
  3903. res += _slash;
  3904. }
  3905. if (authority) {
  3906. let idx = authority.indexOf('@');
  3907. if (idx !== -1) {
  3908. // <user>@<auth>
  3909. const userinfo = authority.substr(0, idx);
  3910. authority = authority.substr(idx + 1);
  3911. idx = userinfo.lastIndexOf(':');
  3912. if (idx === -1) {
  3913. res += encoder(userinfo, false, false);
  3914. }
  3915. else {
  3916. // <user>:<pass>@<auth>
  3917. res += encoder(userinfo.substr(0, idx), false, false);
  3918. res += ':';
  3919. res += encoder(userinfo.substr(idx + 1), false, true);
  3920. }
  3921. res += '@';
  3922. }
  3923. authority = authority.toLowerCase();
  3924. idx = authority.lastIndexOf(':');
  3925. if (idx === -1) {
  3926. res += encoder(authority, false, true);
  3927. }
  3928. else {
  3929. // <auth>:<port>
  3930. res += encoder(authority.substr(0, idx), false, true);
  3931. res += authority.substr(idx);
  3932. }
  3933. }
  3934. if (path) {
  3935. // lower-case windows drive letters in /C:/fff or C:/fff
  3936. if (path.length >= 3 && path.charCodeAt(0) === 47 /* CharCode.Slash */ && path.charCodeAt(2) === 58 /* CharCode.Colon */) {
  3937. const code = path.charCodeAt(1);
  3938. if (code >= 65 /* CharCode.A */ && code <= 90 /* CharCode.Z */) {
  3939. path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3
  3940. }
  3941. }
  3942. else if (path.length >= 2 && path.charCodeAt(1) === 58 /* CharCode.Colon */) {
  3943. const code = path.charCodeAt(0);
  3944. if (code >= 65 /* CharCode.A */ && code <= 90 /* CharCode.Z */) {
  3945. path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
  3946. }
  3947. }
  3948. // encode the rest of the path
  3949. res += encoder(path, true, false);
  3950. }
  3951. if (query) {
  3952. res += '?';
  3953. res += encoder(query, false, false);
  3954. }
  3955. if (fragment) {
  3956. res += '#';
  3957. res += !skipEncoding ? encodeURIComponentFast(fragment, false, false) : fragment;
  3958. }
  3959. return res;
  3960. }
  3961. // --- decode
  3962. function decodeURIComponentGraceful(str) {
  3963. try {
  3964. return decodeURIComponent(str);
  3965. }
  3966. catch {
  3967. if (str.length > 3) {
  3968. return str.substr(0, 3) + decodeURIComponentGraceful(str.substr(3));
  3969. }
  3970. else {
  3971. return str;
  3972. }
  3973. }
  3974. }
  3975. const _rEncodedAsHex = /(%[0-9A-Za-z][0-9A-Za-z])+/g;
  3976. function percentDecode(str) {
  3977. if (!str.match(_rEncodedAsHex)) {
  3978. return str;
  3979. }
  3980. return str.replace(_rEncodedAsHex, (match) => decodeURIComponentGraceful(match));
  3981. }
  3982. /*---------------------------------------------------------------------------------------------
  3983. * Copyright (c) Microsoft Corporation. All rights reserved.
  3984. * Licensed under the MIT License. See License.txt in the project root for license information.
  3985. *--------------------------------------------------------------------------------------------*/
  3986. var Schemas;
  3987. (function (Schemas) {
  3988. /**
  3989. * A schema that is used for models that exist in memory
  3990. * only and that have no correspondence on a server or such.
  3991. */
  3992. Schemas.inMemory = 'inmemory';
  3993. /**
  3994. * A schema that is used for setting files
  3995. */
  3996. Schemas.vscode = 'vscode';
  3997. /**
  3998. * A schema that is used for internal private files
  3999. */
  4000. Schemas.internal = 'private';
  4001. /**
  4002. * A walk-through document.
  4003. */
  4004. Schemas.walkThrough = 'walkThrough';
  4005. /**
  4006. * An embedded code snippet.
  4007. */
  4008. Schemas.walkThroughSnippet = 'walkThroughSnippet';
  4009. Schemas.http = 'http';
  4010. Schemas.https = 'https';
  4011. Schemas.file = 'file';
  4012. Schemas.mailto = 'mailto';
  4013. Schemas.untitled = 'untitled';
  4014. Schemas.data = 'data';
  4015. Schemas.command = 'command';
  4016. Schemas.vscodeRemote = 'vscode-remote';
  4017. Schemas.vscodeRemoteResource = 'vscode-remote-resource';
  4018. Schemas.vscodeManagedRemoteResource = 'vscode-managed-remote-resource';
  4019. Schemas.vscodeUserData = 'vscode-userdata';
  4020. Schemas.vscodeCustomEditor = 'vscode-custom-editor';
  4021. Schemas.vscodeNotebookCell = 'vscode-notebook-cell';
  4022. Schemas.vscodeNotebookCellMetadata = 'vscode-notebook-cell-metadata';
  4023. Schemas.vscodeNotebookCellMetadataDiff = 'vscode-notebook-cell-metadata-diff';
  4024. Schemas.vscodeNotebookCellOutput = 'vscode-notebook-cell-output';
  4025. Schemas.vscodeNotebookCellOutputDiff = 'vscode-notebook-cell-output-diff';
  4026. Schemas.vscodeNotebookMetadata = 'vscode-notebook-metadata';
  4027. Schemas.vscodeInteractiveInput = 'vscode-interactive-input';
  4028. Schemas.vscodeSettings = 'vscode-settings';
  4029. Schemas.vscodeWorkspaceTrust = 'vscode-workspace-trust';
  4030. Schemas.vscodeTerminal = 'vscode-terminal';
  4031. /** Scheme used for code blocks in chat. */
  4032. Schemas.vscodeChatCodeBlock = 'vscode-chat-code-block';
  4033. /** Scheme used for LHS of code compare (aka diff) blocks in chat. */
  4034. Schemas.vscodeChatCodeCompareBlock = 'vscode-chat-code-compare-block';
  4035. /** Scheme used for the chat input editor. */
  4036. Schemas.vscodeChatSesssion = 'vscode-chat-editor';
  4037. /**
  4038. * Scheme used internally for webviews that aren't linked to a resource (i.e. not custom editors)
  4039. */
  4040. Schemas.webviewPanel = 'webview-panel';
  4041. /**
  4042. * Scheme used for loading the wrapper html and script in webviews.
  4043. */
  4044. Schemas.vscodeWebview = 'vscode-webview';
  4045. /**
  4046. * Scheme used for extension pages
  4047. */
  4048. Schemas.extension = 'extension';
  4049. /**
  4050. * Scheme used as a replacement of `file` scheme to load
  4051. * files with our custom protocol handler (desktop only).
  4052. */
  4053. Schemas.vscodeFileResource = 'vscode-file';
  4054. /**
  4055. * Scheme used for temporary resources
  4056. */
  4057. Schemas.tmp = 'tmp';
  4058. /**
  4059. * Scheme used vs live share
  4060. */
  4061. Schemas.vsls = 'vsls';
  4062. /**
  4063. * Scheme used for the Source Control commit input's text document
  4064. */
  4065. Schemas.vscodeSourceControl = 'vscode-scm';
  4066. /**
  4067. * Scheme used for input box for creating comments.
  4068. */
  4069. Schemas.commentsInput = 'comment';
  4070. /**
  4071. * Scheme used for special rendering of settings in the release notes
  4072. */
  4073. Schemas.codeSetting = 'code-setting';
  4074. /**
  4075. * Scheme used for output panel resources
  4076. */
  4077. Schemas.outputChannel = 'output';
  4078. })(Schemas || (Schemas = {}));
  4079. const connectionTokenQueryName = 'tkn';
  4080. class RemoteAuthoritiesImpl {
  4081. constructor() {
  4082. this._hosts = Object.create(null);
  4083. this._ports = Object.create(null);
  4084. this._connectionTokens = Object.create(null);
  4085. this._preferredWebSchema = 'http';
  4086. this._delegate = null;
  4087. this._serverRootPath = '/';
  4088. }
  4089. setPreferredWebSchema(schema) {
  4090. this._preferredWebSchema = schema;
  4091. }
  4092. get _remoteResourcesPath() {
  4093. return posix.join(this._serverRootPath, Schemas.vscodeRemoteResource);
  4094. }
  4095. rewrite(uri) {
  4096. if (this._delegate) {
  4097. try {
  4098. return this._delegate(uri);
  4099. }
  4100. catch (err) {
  4101. onUnexpectedError(err);
  4102. return uri;
  4103. }
  4104. }
  4105. const authority = uri.authority;
  4106. let host = this._hosts[authority];
  4107. if (host && host.indexOf(':') !== -1 && host.indexOf('[') === -1) {
  4108. host = `[${host}]`;
  4109. }
  4110. const port = this._ports[authority];
  4111. const connectionToken = this._connectionTokens[authority];
  4112. let query = `path=${encodeURIComponent(uri.path)}`;
  4113. if (typeof connectionToken === 'string') {
  4114. query += `&${connectionTokenQueryName}=${encodeURIComponent(connectionToken)}`;
  4115. }
  4116. return URI.from({
  4117. scheme: isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource,
  4118. authority: `${host}:${port}`,
  4119. path: this._remoteResourcesPath,
  4120. query
  4121. });
  4122. }
  4123. }
  4124. const RemoteAuthorities = new RemoteAuthoritiesImpl();
  4125. const VSCODE_AUTHORITY = 'vscode-app';
  4126. class FileAccessImpl {
  4127. static { this.FALLBACK_AUTHORITY = VSCODE_AUTHORITY; }
  4128. /**
  4129. * Returns a URI to use in contexts where the browser is responsible
  4130. * for loading (e.g. fetch()) or when used within the DOM.
  4131. *
  4132. * **Note:** use `dom.ts#asCSSUrl` whenever the URL is to be used in CSS context.
  4133. */
  4134. asBrowserUri(resourcePath) {
  4135. // ESM-comment-begin
  4136. // const uri = this.toUri(resourcePath, require);
  4137. // ESM-comment-end
  4138. // ESM-uncomment-begin
  4139. const uri = this.toUri(resourcePath);
  4140. // ESM-uncomment-end
  4141. return this.uriToBrowserUri(uri);
  4142. }
  4143. /**
  4144. * Returns a URI to use in contexts where the browser is responsible
  4145. * for loading (e.g. fetch()) or when used within the DOM.
  4146. *
  4147. * **Note:** use `dom.ts#asCSSUrl` whenever the URL is to be used in CSS context.
  4148. */
  4149. uriToBrowserUri(uri) {
  4150. // Handle remote URIs via `RemoteAuthorities`
  4151. if (uri.scheme === Schemas.vscodeRemote) {
  4152. return RemoteAuthorities.rewrite(uri);
  4153. }
  4154. // Convert to `vscode-file` resource..
  4155. if (
  4156. // ...only ever for `file` resources
  4157. uri.scheme === Schemas.file &&
  4158. (
  4159. // ...and we run in native environments
  4160. isNative ||
  4161. // ...or web worker extensions on desktop
  4162. (webWorkerOrigin === `${Schemas.vscodeFileResource}://${FileAccessImpl.FALLBACK_AUTHORITY}`))) {
  4163. return uri.with({
  4164. scheme: Schemas.vscodeFileResource,
  4165. // We need to provide an authority here so that it can serve
  4166. // as origin for network and loading matters in chromium.
  4167. // If the URI is not coming with an authority already, we
  4168. // add our own
  4169. authority: uri.authority || FileAccessImpl.FALLBACK_AUTHORITY,
  4170. query: null,
  4171. fragment: null
  4172. });
  4173. }
  4174. return uri;
  4175. }
  4176. toUri(uriOrModule, moduleIdToUrl) {
  4177. if (URI.isUri(uriOrModule)) {
  4178. return uriOrModule;
  4179. }
  4180. if (globalThis._VSCODE_FILE_ROOT) {
  4181. const rootUriOrPath = globalThis._VSCODE_FILE_ROOT;
  4182. // File URL (with scheme)
  4183. if (/^\w[\w\d+.-]*:\/\//.test(rootUriOrPath)) {
  4184. return URI.joinPath(URI.parse(rootUriOrPath, true), uriOrModule);
  4185. }
  4186. // File Path (no scheme)
  4187. const modulePath = join(rootUriOrPath, uriOrModule);
  4188. return URI.file(modulePath);
  4189. }
  4190. return URI.parse(moduleIdToUrl.toUrl(uriOrModule));
  4191. }
  4192. }
  4193. const FileAccess = new FileAccessImpl();
  4194. var COI;
  4195. (function (COI) {
  4196. const coiHeaders = new Map([
  4197. ['1', { 'Cross-Origin-Opener-Policy': 'same-origin' }],
  4198. ['2', { 'Cross-Origin-Embedder-Policy': 'require-corp' }],
  4199. ['3', { 'Cross-Origin-Opener-Policy': 'same-origin', 'Cross-Origin-Embedder-Policy': 'require-corp' }],
  4200. ]);
  4201. COI.CoopAndCoep = Object.freeze(coiHeaders.get('3'));
  4202. const coiSearchParamName = 'vscode-coi';
  4203. /**
  4204. * Extract desired headers from `vscode-coi` invocation
  4205. */
  4206. function getHeadersFromQuery(url) {
  4207. let params;
  4208. if (typeof url === 'string') {
  4209. params = new URL(url).searchParams;
  4210. }
  4211. else if (url instanceof URL) {
  4212. params = url.searchParams;
  4213. }
  4214. else if (URI.isUri(url)) {
  4215. params = new URL(url.toString(true)).searchParams;
  4216. }
  4217. const value = params?.get(coiSearchParamName);
  4218. if (!value) {
  4219. return undefined;
  4220. }
  4221. return coiHeaders.get(value);
  4222. }
  4223. COI.getHeadersFromQuery = getHeadersFromQuery;
  4224. /**
  4225. * Add the `vscode-coi` query attribute based on wanting `COOP` and `COEP`. Will be a noop when `crossOriginIsolated`
  4226. * isn't enabled the current context
  4227. */
  4228. function addSearchParam(urlOrSearch, coop, coep) {
  4229. if (!globalThis.crossOriginIsolated) {
  4230. // depends on the current context being COI
  4231. return;
  4232. }
  4233. const value = coop && coep ? '3' : coep ? '2' : '1';
  4234. if (urlOrSearch instanceof URLSearchParams) {
  4235. urlOrSearch.set(coiSearchParamName, value);
  4236. }
  4237. else {
  4238. urlOrSearch[coiSearchParamName] = value;
  4239. }
  4240. }
  4241. COI.addSearchParam = addSearchParam;
  4242. })(COI || (COI = {}));
  4243. /*---------------------------------------------------------------------------------------------
  4244. * Copyright (c) Microsoft Corporation. All rights reserved.
  4245. * Licensed under the MIT License. See License.txt in the project root for license information.
  4246. *--------------------------------------------------------------------------------------------*/
  4247. // ESM-uncomment-end
  4248. const DEFAULT_CHANNEL = 'default';
  4249. const INITIALIZE = '$initialize';
  4250. class RequestMessage {
  4251. constructor(vsWorker, req, channel, method, args) {
  4252. this.vsWorker = vsWorker;
  4253. this.req = req;
  4254. this.channel = channel;
  4255. this.method = method;
  4256. this.args = args;
  4257. this.type = 0 /* MessageType.Request */;
  4258. }
  4259. }
  4260. class ReplyMessage {
  4261. constructor(vsWorker, seq, res, err) {
  4262. this.vsWorker = vsWorker;
  4263. this.seq = seq;
  4264. this.res = res;
  4265. this.err = err;
  4266. this.type = 1 /* MessageType.Reply */;
  4267. }
  4268. }
  4269. class SubscribeEventMessage {
  4270. constructor(vsWorker, req, channel, eventName, arg) {
  4271. this.vsWorker = vsWorker;
  4272. this.req = req;
  4273. this.channel = channel;
  4274. this.eventName = eventName;
  4275. this.arg = arg;
  4276. this.type = 2 /* MessageType.SubscribeEvent */;
  4277. }
  4278. }
  4279. class EventMessage {
  4280. constructor(vsWorker, req, event) {
  4281. this.vsWorker = vsWorker;
  4282. this.req = req;
  4283. this.event = event;
  4284. this.type = 3 /* MessageType.Event */;
  4285. }
  4286. }
  4287. class UnsubscribeEventMessage {
  4288. constructor(vsWorker, req) {
  4289. this.vsWorker = vsWorker;
  4290. this.req = req;
  4291. this.type = 4 /* MessageType.UnsubscribeEvent */;
  4292. }
  4293. }
  4294. class SimpleWorkerProtocol {
  4295. constructor(handler) {
  4296. this._workerId = -1;
  4297. this._handler = handler;
  4298. this._lastSentReq = 0;
  4299. this._pendingReplies = Object.create(null);
  4300. this._pendingEmitters = new Map();
  4301. this._pendingEvents = new Map();
  4302. }
  4303. setWorkerId(workerId) {
  4304. this._workerId = workerId;
  4305. }
  4306. sendMessage(channel, method, args) {
  4307. const req = String(++this._lastSentReq);
  4308. return new Promise((resolve, reject) => {
  4309. this._pendingReplies[req] = {
  4310. resolve: resolve,
  4311. reject: reject
  4312. };
  4313. this._send(new RequestMessage(this._workerId, req, channel, method, args));
  4314. });
  4315. }
  4316. listen(channel, eventName, arg) {
  4317. let req = null;
  4318. const emitter = new Emitter({
  4319. onWillAddFirstListener: () => {
  4320. req = String(++this._lastSentReq);
  4321. this._pendingEmitters.set(req, emitter);
  4322. this._send(new SubscribeEventMessage(this._workerId, req, channel, eventName, arg));
  4323. },
  4324. onDidRemoveLastListener: () => {
  4325. this._pendingEmitters.delete(req);
  4326. this._send(new UnsubscribeEventMessage(this._workerId, req));
  4327. req = null;
  4328. }
  4329. });
  4330. return emitter.event;
  4331. }
  4332. handleMessage(message) {
  4333. if (!message || !message.vsWorker) {
  4334. return;
  4335. }
  4336. if (this._workerId !== -1 && message.vsWorker !== this._workerId) {
  4337. return;
  4338. }
  4339. this._handleMessage(message);
  4340. }
  4341. createProxyToRemoteChannel(channel, sendMessageBarrier) {
  4342. const handler = {
  4343. get: (target, name) => {
  4344. if (typeof name === 'string' && !target[name]) {
  4345. if (propertyIsDynamicEvent(name)) { // onDynamic...
  4346. target[name] = (arg) => {
  4347. return this.listen(channel, name, arg);
  4348. };
  4349. }
  4350. else if (propertyIsEvent(name)) { // on...
  4351. target[name] = this.listen(channel, name, undefined);
  4352. }
  4353. else if (name.charCodeAt(0) === 36 /* CharCode.DollarSign */) { // $...
  4354. target[name] = async (...myArgs) => {
  4355. await sendMessageBarrier?.();
  4356. return this.sendMessage(channel, name, myArgs);
  4357. };
  4358. }
  4359. }
  4360. return target[name];
  4361. }
  4362. };
  4363. return new Proxy(Object.create(null), handler);
  4364. }
  4365. _handleMessage(msg) {
  4366. switch (msg.type) {
  4367. case 1 /* MessageType.Reply */:
  4368. return this._handleReplyMessage(msg);
  4369. case 0 /* MessageType.Request */:
  4370. return this._handleRequestMessage(msg);
  4371. case 2 /* MessageType.SubscribeEvent */:
  4372. return this._handleSubscribeEventMessage(msg);
  4373. case 3 /* MessageType.Event */:
  4374. return this._handleEventMessage(msg);
  4375. case 4 /* MessageType.UnsubscribeEvent */:
  4376. return this._handleUnsubscribeEventMessage(msg);
  4377. }
  4378. }
  4379. _handleReplyMessage(replyMessage) {
  4380. if (!this._pendingReplies[replyMessage.seq]) {
  4381. console.warn('Got reply to unknown seq');
  4382. return;
  4383. }
  4384. const reply = this._pendingReplies[replyMessage.seq];
  4385. delete this._pendingReplies[replyMessage.seq];
  4386. if (replyMessage.err) {
  4387. let err = replyMessage.err;
  4388. if (replyMessage.err.$isError) {
  4389. err = new Error();
  4390. err.name = replyMessage.err.name;
  4391. err.message = replyMessage.err.message;
  4392. err.stack = replyMessage.err.stack;
  4393. }
  4394. reply.reject(err);
  4395. return;
  4396. }
  4397. reply.resolve(replyMessage.res);
  4398. }
  4399. _handleRequestMessage(requestMessage) {
  4400. const req = requestMessage.req;
  4401. const result = this._handler.handleMessage(requestMessage.channel, requestMessage.method, requestMessage.args);
  4402. result.then((r) => {
  4403. this._send(new ReplyMessage(this._workerId, req, r, undefined));
  4404. }, (e) => {
  4405. if (e.detail instanceof Error) {
  4406. // Loading errors have a detail property that points to the actual error
  4407. e.detail = transformErrorForSerialization(e.detail);
  4408. }
  4409. this._send(new ReplyMessage(this._workerId, req, undefined, transformErrorForSerialization(e)));
  4410. });
  4411. }
  4412. _handleSubscribeEventMessage(msg) {
  4413. const req = msg.req;
  4414. const disposable = this._handler.handleEvent(msg.channel, msg.eventName, msg.arg)((event) => {
  4415. this._send(new EventMessage(this._workerId, req, event));
  4416. });
  4417. this._pendingEvents.set(req, disposable);
  4418. }
  4419. _handleEventMessage(msg) {
  4420. if (!this._pendingEmitters.has(msg.req)) {
  4421. console.warn('Got event for unknown req');
  4422. return;
  4423. }
  4424. this._pendingEmitters.get(msg.req).fire(msg.event);
  4425. }
  4426. _handleUnsubscribeEventMessage(msg) {
  4427. if (!this._pendingEvents.has(msg.req)) {
  4428. console.warn('Got unsubscribe for unknown req');
  4429. return;
  4430. }
  4431. this._pendingEvents.get(msg.req).dispose();
  4432. this._pendingEvents.delete(msg.req);
  4433. }
  4434. _send(msg) {
  4435. const transfer = [];
  4436. if (msg.type === 0 /* MessageType.Request */) {
  4437. for (let i = 0; i < msg.args.length; i++) {
  4438. if (msg.args[i] instanceof ArrayBuffer) {
  4439. transfer.push(msg.args[i]);
  4440. }
  4441. }
  4442. }
  4443. else if (msg.type === 1 /* MessageType.Reply */) {
  4444. if (msg.res instanceof ArrayBuffer) {
  4445. transfer.push(msg.res);
  4446. }
  4447. }
  4448. this._handler.sendMessage(msg, transfer);
  4449. }
  4450. }
  4451. function propertyIsEvent(name) {
  4452. // Assume a property is an event if it has a form of "onSomething"
  4453. return name[0] === 'o' && name[1] === 'n' && isUpperAsciiLetter(name.charCodeAt(2));
  4454. }
  4455. function propertyIsDynamicEvent(name) {
  4456. // Assume a property is a dynamic event (a method that returns an event) if it has a form of "onDynamicSomething"
  4457. return /^onDynamic/.test(name) && isUpperAsciiLetter(name.charCodeAt(9));
  4458. }
  4459. /**
  4460. * Worker side
  4461. */
  4462. class SimpleWorkerServer {
  4463. constructor(postMessage, requestHandlerFactory) {
  4464. this._localChannels = new Map();
  4465. this._remoteChannels = new Map();
  4466. this._requestHandlerFactory = requestHandlerFactory;
  4467. this._requestHandler = null;
  4468. this._protocol = new SimpleWorkerProtocol({
  4469. sendMessage: (msg, transfer) => {
  4470. postMessage(msg, transfer);
  4471. },
  4472. handleMessage: (channel, method, args) => this._handleMessage(channel, method, args),
  4473. handleEvent: (channel, eventName, arg) => this._handleEvent(channel, eventName, arg)
  4474. });
  4475. }
  4476. onmessage(msg) {
  4477. this._protocol.handleMessage(msg);
  4478. }
  4479. _handleMessage(channel, method, args) {
  4480. if (channel === DEFAULT_CHANNEL && method === INITIALIZE) {
  4481. return this.initialize(args[0], args[1], args[2]);
  4482. }
  4483. const requestHandler = (channel === DEFAULT_CHANNEL ? this._requestHandler : this._localChannels.get(channel));
  4484. if (!requestHandler) {
  4485. return Promise.reject(new Error(`Missing channel ${channel} on worker thread`));
  4486. }
  4487. if (typeof requestHandler[method] !== 'function') {
  4488. return Promise.reject(new Error(`Missing method ${method} on worker thread channel ${channel}`));
  4489. }
  4490. try {
  4491. return Promise.resolve(requestHandler[method].apply(requestHandler, args));
  4492. }
  4493. catch (e) {
  4494. return Promise.reject(e);
  4495. }
  4496. }
  4497. _handleEvent(channel, eventName, arg) {
  4498. const requestHandler = (channel === DEFAULT_CHANNEL ? this._requestHandler : this._localChannels.get(channel));
  4499. if (!requestHandler) {
  4500. throw new Error(`Missing channel ${channel} on worker thread`);
  4501. }
  4502. if (propertyIsDynamicEvent(eventName)) {
  4503. const event = requestHandler[eventName].call(requestHandler, arg);
  4504. if (typeof event !== 'function') {
  4505. throw new Error(`Missing dynamic event ${eventName} on request handler.`);
  4506. }
  4507. return event;
  4508. }
  4509. if (propertyIsEvent(eventName)) {
  4510. const event = requestHandler[eventName];
  4511. if (typeof event !== 'function') {
  4512. throw new Error(`Missing event ${eventName} on request handler.`);
  4513. }
  4514. return event;
  4515. }
  4516. throw new Error(`Malformed event name ${eventName}`);
  4517. }
  4518. getChannel(channel) {
  4519. if (!this._remoteChannels.has(channel)) {
  4520. const inst = this._protocol.createProxyToRemoteChannel(channel);
  4521. this._remoteChannels.set(channel, inst);
  4522. }
  4523. return this._remoteChannels.get(channel);
  4524. }
  4525. async initialize(workerId, loaderConfig, moduleId) {
  4526. this._protocol.setWorkerId(workerId);
  4527. if (this._requestHandlerFactory) {
  4528. // static request handler
  4529. this._requestHandler = this._requestHandlerFactory(this);
  4530. return;
  4531. }
  4532. if (loaderConfig) {
  4533. // Remove 'baseUrl', handling it is beyond scope for now
  4534. if (typeof loaderConfig.baseUrl !== 'undefined') {
  4535. delete loaderConfig['baseUrl'];
  4536. }
  4537. if (typeof loaderConfig.paths !== 'undefined') {
  4538. if (typeof loaderConfig.paths.vs !== 'undefined') {
  4539. delete loaderConfig.paths['vs'];
  4540. }
  4541. }
  4542. if (typeof loaderConfig.trustedTypesPolicy !== 'undefined') {
  4543. // don't use, it has been destroyed during serialize
  4544. delete loaderConfig['trustedTypesPolicy'];
  4545. }
  4546. // Since this is in a web worker, enable catching errors
  4547. loaderConfig.catchError = true;
  4548. globalThis.require.config(loaderConfig);
  4549. }
  4550. {
  4551. const url = FileAccess.asBrowserUri(`${moduleId}.js`).toString(true);
  4552. return import(`${url}`).then((module) => {
  4553. this._requestHandler = module.create(this);
  4554. if (!this._requestHandler) {
  4555. throw new Error(`No RequestHandler!`);
  4556. }
  4557. });
  4558. }
  4559. }
  4560. }
  4561. /*---------------------------------------------------------------------------------------------
  4562. * Copyright (c) Microsoft Corporation. All rights reserved.
  4563. * Licensed under the MIT License. See License.txt in the project root for license information.
  4564. *--------------------------------------------------------------------------------------------*/
  4565. /**
  4566. * Represents information about a specific difference between two sequences.
  4567. */
  4568. class DiffChange {
  4569. /**
  4570. * Constructs a new DiffChange with the given sequence information
  4571. * and content.
  4572. */
  4573. constructor(originalStart, originalLength, modifiedStart, modifiedLength) {
  4574. //Debug.Assert(originalLength > 0 || modifiedLength > 0, "originalLength and modifiedLength cannot both be <= 0");
  4575. this.originalStart = originalStart;
  4576. this.originalLength = originalLength;
  4577. this.modifiedStart = modifiedStart;
  4578. this.modifiedLength = modifiedLength;
  4579. }
  4580. /**
  4581. * The end point (exclusive) of the change in the original sequence.
  4582. */
  4583. getOriginalEnd() {
  4584. return this.originalStart + this.originalLength;
  4585. }
  4586. /**
  4587. * The end point (exclusive) of the change in the modified sequence.
  4588. */
  4589. getModifiedEnd() {
  4590. return this.modifiedStart + this.modifiedLength;
  4591. }
  4592. }
  4593. /*---------------------------------------------------------------------------------------------
  4594. * Copyright (c) Microsoft Corporation. All rights reserved.
  4595. * Licensed under the MIT License. See License.txt in the project root for license information.
  4596. *--------------------------------------------------------------------------------------------*/
  4597. function numberHash(val, initialHashVal) {
  4598. return (((initialHashVal << 5) - initialHashVal) + val) | 0; // hashVal * 31 + ch, keep as int32
  4599. }
  4600. function stringHash(s, hashVal) {
  4601. hashVal = numberHash(149417, hashVal);
  4602. for (let i = 0, length = s.length; i < length; i++) {
  4603. hashVal = numberHash(s.charCodeAt(i), hashVal);
  4604. }
  4605. return hashVal;
  4606. }
  4607. function leftRotate(value, bits, totalBits = 32) {
  4608. // delta + bits = totalBits
  4609. const delta = totalBits - bits;
  4610. // All ones, expect `delta` zeros aligned to the right
  4611. const mask = ~((1 << delta) - 1);
  4612. // Join (value left-shifted `bits` bits) with (masked value right-shifted `delta` bits)
  4613. return ((value << bits) | ((mask & value) >>> delta)) >>> 0;
  4614. }
  4615. function fill(dest, index = 0, count = dest.byteLength, value = 0) {
  4616. for (let i = 0; i < count; i++) {
  4617. dest[index + i] = value;
  4618. }
  4619. }
  4620. function leftPad(value, length, char = '0') {
  4621. while (value.length < length) {
  4622. value = char + value;
  4623. }
  4624. return value;
  4625. }
  4626. function toHexString(bufferOrValue, bitsize = 32) {
  4627. if (bufferOrValue instanceof ArrayBuffer) {
  4628. return Array.from(new Uint8Array(bufferOrValue)).map(b => b.toString(16).padStart(2, '0')).join('');
  4629. }
  4630. return leftPad((bufferOrValue >>> 0).toString(16), bitsize / 4);
  4631. }
  4632. /**
  4633. * A SHA1 implementation that works with strings and does not allocate.
  4634. */
  4635. class StringSHA1 {
  4636. static { this._bigBlock32 = new DataView(new ArrayBuffer(320)); } // 80 * 4 = 320
  4637. constructor() {
  4638. this._h0 = 0x67452301;
  4639. this._h1 = 0xEFCDAB89;
  4640. this._h2 = 0x98BADCFE;
  4641. this._h3 = 0x10325476;
  4642. this._h4 = 0xC3D2E1F0;
  4643. this._buff = new Uint8Array(64 /* SHA1Constant.BLOCK_SIZE */ + 3 /* to fit any utf-8 */);
  4644. this._buffDV = new DataView(this._buff.buffer);
  4645. this._buffLen = 0;
  4646. this._totalLen = 0;
  4647. this._leftoverHighSurrogate = 0;
  4648. this._finished = false;
  4649. }
  4650. update(str) {
  4651. const strLen = str.length;
  4652. if (strLen === 0) {
  4653. return;
  4654. }
  4655. const buff = this._buff;
  4656. let buffLen = this._buffLen;
  4657. let leftoverHighSurrogate = this._leftoverHighSurrogate;
  4658. let charCode;
  4659. let offset;
  4660. if (leftoverHighSurrogate !== 0) {
  4661. charCode = leftoverHighSurrogate;
  4662. offset = -1;
  4663. leftoverHighSurrogate = 0;
  4664. }
  4665. else {
  4666. charCode = str.charCodeAt(0);
  4667. offset = 0;
  4668. }
  4669. while (true) {
  4670. let codePoint = charCode;
  4671. if (isHighSurrogate(charCode)) {
  4672. if (offset + 1 < strLen) {
  4673. const nextCharCode = str.charCodeAt(offset + 1);
  4674. if (isLowSurrogate(nextCharCode)) {
  4675. offset++;
  4676. codePoint = computeCodePoint(charCode, nextCharCode);
  4677. }
  4678. else {
  4679. // illegal => unicode replacement character
  4680. codePoint = 65533 /* SHA1Constant.UNICODE_REPLACEMENT */;
  4681. }
  4682. }
  4683. else {
  4684. // last character is a surrogate pair
  4685. leftoverHighSurrogate = charCode;
  4686. break;
  4687. }
  4688. }
  4689. else if (isLowSurrogate(charCode)) {
  4690. // illegal => unicode replacement character
  4691. codePoint = 65533 /* SHA1Constant.UNICODE_REPLACEMENT */;
  4692. }
  4693. buffLen = this._push(buff, buffLen, codePoint);
  4694. offset++;
  4695. if (offset < strLen) {
  4696. charCode = str.charCodeAt(offset);
  4697. }
  4698. else {
  4699. break;
  4700. }
  4701. }
  4702. this._buffLen = buffLen;
  4703. this._leftoverHighSurrogate = leftoverHighSurrogate;
  4704. }
  4705. _push(buff, buffLen, codePoint) {
  4706. if (codePoint < 0x0080) {
  4707. buff[buffLen++] = codePoint;
  4708. }
  4709. else if (codePoint < 0x0800) {
  4710. buff[buffLen++] = 0b11000000 | ((codePoint & 0b00000000000000000000011111000000) >>> 6);
  4711. buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
  4712. }
  4713. else if (codePoint < 0x10000) {
  4714. buff[buffLen++] = 0b11100000 | ((codePoint & 0b00000000000000001111000000000000) >>> 12);
  4715. buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000111111000000) >>> 6);
  4716. buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
  4717. }
  4718. else {
  4719. buff[buffLen++] = 0b11110000 | ((codePoint & 0b00000000000111000000000000000000) >>> 18);
  4720. buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000111111000000000000) >>> 12);
  4721. buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000111111000000) >>> 6);
  4722. buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
  4723. }
  4724. if (buffLen >= 64 /* SHA1Constant.BLOCK_SIZE */) {
  4725. this._step();
  4726. buffLen -= 64 /* SHA1Constant.BLOCK_SIZE */;
  4727. this._totalLen += 64 /* SHA1Constant.BLOCK_SIZE */;
  4728. // take last 3 in case of UTF8 overflow
  4729. buff[0] = buff[64 /* SHA1Constant.BLOCK_SIZE */ + 0];
  4730. buff[1] = buff[64 /* SHA1Constant.BLOCK_SIZE */ + 1];
  4731. buff[2] = buff[64 /* SHA1Constant.BLOCK_SIZE */ + 2];
  4732. }
  4733. return buffLen;
  4734. }
  4735. digest() {
  4736. if (!this._finished) {
  4737. this._finished = true;
  4738. if (this._leftoverHighSurrogate) {
  4739. // illegal => unicode replacement character
  4740. this._leftoverHighSurrogate = 0;
  4741. this._buffLen = this._push(this._buff, this._buffLen, 65533 /* SHA1Constant.UNICODE_REPLACEMENT */);
  4742. }
  4743. this._totalLen += this._buffLen;
  4744. this._wrapUp();
  4745. }
  4746. return toHexString(this._h0) + toHexString(this._h1) + toHexString(this._h2) + toHexString(this._h3) + toHexString(this._h4);
  4747. }
  4748. _wrapUp() {
  4749. this._buff[this._buffLen++] = 0x80;
  4750. fill(this._buff, this._buffLen);
  4751. if (this._buffLen > 56) {
  4752. this._step();
  4753. fill(this._buff);
  4754. }
  4755. // this will fit because the mantissa can cover up to 52 bits
  4756. const ml = 8 * this._totalLen;
  4757. this._buffDV.setUint32(56, Math.floor(ml / 4294967296), false);
  4758. this._buffDV.setUint32(60, ml % 4294967296, false);
  4759. this._step();
  4760. }
  4761. _step() {
  4762. const bigBlock32 = StringSHA1._bigBlock32;
  4763. const data = this._buffDV;
  4764. for (let j = 0; j < 64 /* 16*4 */; j += 4) {
  4765. bigBlock32.setUint32(j, data.getUint32(j, false), false);
  4766. }
  4767. for (let j = 64; j < 320 /* 80*4 */; j += 4) {
  4768. bigBlock32.setUint32(j, leftRotate((bigBlock32.getUint32(j - 12, false) ^ bigBlock32.getUint32(j - 32, false) ^ bigBlock32.getUint32(j - 56, false) ^ bigBlock32.getUint32(j - 64, false)), 1), false);
  4769. }
  4770. let a = this._h0;
  4771. let b = this._h1;
  4772. let c = this._h2;
  4773. let d = this._h3;
  4774. let e = this._h4;
  4775. let f, k;
  4776. let temp;
  4777. for (let j = 0; j < 80; j++) {
  4778. if (j < 20) {
  4779. f = (b & c) | ((~b) & d);
  4780. k = 0x5A827999;
  4781. }
  4782. else if (j < 40) {
  4783. f = b ^ c ^ d;
  4784. k = 0x6ED9EBA1;
  4785. }
  4786. else if (j < 60) {
  4787. f = (b & c) | (b & d) | (c & d);
  4788. k = 0x8F1BBCDC;
  4789. }
  4790. else {
  4791. f = b ^ c ^ d;
  4792. k = 0xCA62C1D6;
  4793. }
  4794. temp = (leftRotate(a, 5) + f + e + k + bigBlock32.getUint32(j * 4, false)) & 0xffffffff;
  4795. e = d;
  4796. d = c;
  4797. c = leftRotate(b, 30);
  4798. b = a;
  4799. a = temp;
  4800. }
  4801. this._h0 = (this._h0 + a) & 0xffffffff;
  4802. this._h1 = (this._h1 + b) & 0xffffffff;
  4803. this._h2 = (this._h2 + c) & 0xffffffff;
  4804. this._h3 = (this._h3 + d) & 0xffffffff;
  4805. this._h4 = (this._h4 + e) & 0xffffffff;
  4806. }
  4807. }
  4808. /*---------------------------------------------------------------------------------------------
  4809. * Copyright (c) Microsoft Corporation. All rights reserved.
  4810. * Licensed under the MIT License. See License.txt in the project root for license information.
  4811. *--------------------------------------------------------------------------------------------*/
  4812. class StringDiffSequence {
  4813. constructor(source) {
  4814. this.source = source;
  4815. }
  4816. getElements() {
  4817. const source = this.source;
  4818. const characters = new Int32Array(source.length);
  4819. for (let i = 0, len = source.length; i < len; i++) {
  4820. characters[i] = source.charCodeAt(i);
  4821. }
  4822. return characters;
  4823. }
  4824. }
  4825. function stringDiff(original, modified, pretty) {
  4826. return new LcsDiff(new StringDiffSequence(original), new StringDiffSequence(modified)).ComputeDiff(pretty).changes;
  4827. }
  4828. //
  4829. // The code below has been ported from a C# implementation in VS
  4830. //
  4831. class Debug {
  4832. static Assert(condition, message) {
  4833. if (!condition) {
  4834. throw new Error(message);
  4835. }
  4836. }
  4837. }
  4838. class MyArray {
  4839. /**
  4840. * Copies a range of elements from an Array starting at the specified source index and pastes
  4841. * them to another Array starting at the specified destination index. The length and the indexes
  4842. * are specified as 64-bit integers.
  4843. * sourceArray:
  4844. * The Array that contains the data to copy.
  4845. * sourceIndex:
  4846. * A 64-bit integer that represents the index in the sourceArray at which copying begins.
  4847. * destinationArray:
  4848. * The Array that receives the data.
  4849. * destinationIndex:
  4850. * A 64-bit integer that represents the index in the destinationArray at which storing begins.
  4851. * length:
  4852. * A 64-bit integer that represents the number of elements to copy.
  4853. */
  4854. static Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length) {
  4855. for (let i = 0; i < length; i++) {
  4856. destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i];
  4857. }
  4858. }
  4859. static Copy2(sourceArray, sourceIndex, destinationArray, destinationIndex, length) {
  4860. for (let i = 0; i < length; i++) {
  4861. destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i];
  4862. }
  4863. }
  4864. }
  4865. /**
  4866. * A utility class which helps to create the set of DiffChanges from
  4867. * a difference operation. This class accepts original DiffElements and
  4868. * modified DiffElements that are involved in a particular change. The
  4869. * MarkNextChange() method can be called to mark the separation between
  4870. * distinct changes. At the end, the Changes property can be called to retrieve
  4871. * the constructed changes.
  4872. */
  4873. class DiffChangeHelper {
  4874. /**
  4875. * Constructs a new DiffChangeHelper for the given DiffSequences.
  4876. */
  4877. constructor() {
  4878. this.m_changes = [];
  4879. this.m_originalStart = 1073741824 /* Constants.MAX_SAFE_SMALL_INTEGER */;
  4880. this.m_modifiedStart = 1073741824 /* Constants.MAX_SAFE_SMALL_INTEGER */;
  4881. this.m_originalCount = 0;
  4882. this.m_modifiedCount = 0;
  4883. }
  4884. /**
  4885. * Marks the beginning of the next change in the set of differences.
  4886. */
  4887. MarkNextChange() {
  4888. // Only add to the list if there is something to add
  4889. if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
  4890. // Add the new change to our list
  4891. this.m_changes.push(new DiffChange(this.m_originalStart, this.m_originalCount, this.m_modifiedStart, this.m_modifiedCount));
  4892. }
  4893. // Reset for the next change
  4894. this.m_originalCount = 0;
  4895. this.m_modifiedCount = 0;
  4896. this.m_originalStart = 1073741824 /* Constants.MAX_SAFE_SMALL_INTEGER */;
  4897. this.m_modifiedStart = 1073741824 /* Constants.MAX_SAFE_SMALL_INTEGER */;
  4898. }
  4899. /**
  4900. * Adds the original element at the given position to the elements
  4901. * affected by the current change. The modified index gives context
  4902. * to the change position with respect to the original sequence.
  4903. * @param originalIndex The index of the original element to add.
  4904. * @param modifiedIndex The index of the modified element that provides corresponding position in the modified sequence.
  4905. */
  4906. AddOriginalElement(originalIndex, modifiedIndex) {
  4907. // The 'true' start index is the smallest of the ones we've seen
  4908. this.m_originalStart = Math.min(this.m_originalStart, originalIndex);
  4909. this.m_modifiedStart = Math.min(this.m_modifiedStart, modifiedIndex);
  4910. this.m_originalCount++;
  4911. }
  4912. /**
  4913. * Adds the modified element at the given position to the elements
  4914. * affected by the current change. The original index gives context
  4915. * to the change position with respect to the modified sequence.
  4916. * @param originalIndex The index of the original element that provides corresponding position in the original sequence.
  4917. * @param modifiedIndex The index of the modified element to add.
  4918. */
  4919. AddModifiedElement(originalIndex, modifiedIndex) {
  4920. // The 'true' start index is the smallest of the ones we've seen
  4921. this.m_originalStart = Math.min(this.m_originalStart, originalIndex);
  4922. this.m_modifiedStart = Math.min(this.m_modifiedStart, modifiedIndex);
  4923. this.m_modifiedCount++;
  4924. }
  4925. /**
  4926. * Retrieves all of the changes marked by the class.
  4927. */
  4928. getChanges() {
  4929. if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
  4930. // Finish up on whatever is left
  4931. this.MarkNextChange();
  4932. }
  4933. return this.m_changes;
  4934. }
  4935. /**
  4936. * Retrieves all of the changes marked by the class in the reverse order
  4937. */
  4938. getReverseChanges() {
  4939. if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
  4940. // Finish up on whatever is left
  4941. this.MarkNextChange();
  4942. }
  4943. this.m_changes.reverse();
  4944. return this.m_changes;
  4945. }
  4946. }
  4947. /**
  4948. * An implementation of the difference algorithm described in
  4949. * "An O(ND) Difference Algorithm and its variations" by Eugene W. Myers
  4950. */
  4951. class LcsDiff {
  4952. /**
  4953. * Constructs the DiffFinder
  4954. */
  4955. constructor(originalSequence, modifiedSequence, continueProcessingPredicate = null) {
  4956. this.ContinueProcessingPredicate = continueProcessingPredicate;
  4957. this._originalSequence = originalSequence;
  4958. this._modifiedSequence = modifiedSequence;
  4959. const [originalStringElements, originalElementsOrHash, originalHasStrings] = LcsDiff._getElements(originalSequence);
  4960. const [modifiedStringElements, modifiedElementsOrHash, modifiedHasStrings] = LcsDiff._getElements(modifiedSequence);
  4961. this._hasStrings = (originalHasStrings && modifiedHasStrings);
  4962. this._originalStringElements = originalStringElements;
  4963. this._originalElementsOrHash = originalElementsOrHash;
  4964. this._modifiedStringElements = modifiedStringElements;
  4965. this._modifiedElementsOrHash = modifiedElementsOrHash;
  4966. this.m_forwardHistory = [];
  4967. this.m_reverseHistory = [];
  4968. }
  4969. static _isStringArray(arr) {
  4970. return (arr.length > 0 && typeof arr[0] === 'string');
  4971. }
  4972. static _getElements(sequence) {
  4973. const elements = sequence.getElements();
  4974. if (LcsDiff._isStringArray(elements)) {
  4975. const hashes = new Int32Array(elements.length);
  4976. for (let i = 0, len = elements.length; i < len; i++) {
  4977. hashes[i] = stringHash(elements[i], 0);
  4978. }
  4979. return [elements, hashes, true];
  4980. }
  4981. if (elements instanceof Int32Array) {
  4982. return [[], elements, false];
  4983. }
  4984. return [[], new Int32Array(elements), false];
  4985. }
  4986. ElementsAreEqual(originalIndex, newIndex) {
  4987. if (this._originalElementsOrHash[originalIndex] !== this._modifiedElementsOrHash[newIndex]) {
  4988. return false;
  4989. }
  4990. return (this._hasStrings ? this._originalStringElements[originalIndex] === this._modifiedStringElements[newIndex] : true);
  4991. }
  4992. ElementsAreStrictEqual(originalIndex, newIndex) {
  4993. if (!this.ElementsAreEqual(originalIndex, newIndex)) {
  4994. return false;
  4995. }
  4996. const originalElement = LcsDiff._getStrictElement(this._originalSequence, originalIndex);
  4997. const modifiedElement = LcsDiff._getStrictElement(this._modifiedSequence, newIndex);
  4998. return (originalElement === modifiedElement);
  4999. }
  5000. static _getStrictElement(sequence, index) {
  5001. if (typeof sequence.getStrictElement === 'function') {
  5002. return sequence.getStrictElement(index);
  5003. }
  5004. return null;
  5005. }
  5006. OriginalElementsAreEqual(index1, index2) {
  5007. if (this._originalElementsOrHash[index1] !== this._originalElementsOrHash[index2]) {
  5008. return false;
  5009. }
  5010. return (this._hasStrings ? this._originalStringElements[index1] === this._originalStringElements[index2] : true);
  5011. }
  5012. ModifiedElementsAreEqual(index1, index2) {
  5013. if (this._modifiedElementsOrHash[index1] !== this._modifiedElementsOrHash[index2]) {
  5014. return false;
  5015. }
  5016. return (this._hasStrings ? this._modifiedStringElements[index1] === this._modifiedStringElements[index2] : true);
  5017. }
  5018. ComputeDiff(pretty) {
  5019. return this._ComputeDiff(0, this._originalElementsOrHash.length - 1, 0, this._modifiedElementsOrHash.length - 1, pretty);
  5020. }
  5021. /**
  5022. * Computes the differences between the original and modified input
  5023. * sequences on the bounded range.
  5024. * @returns An array of the differences between the two input sequences.
  5025. */
  5026. _ComputeDiff(originalStart, originalEnd, modifiedStart, modifiedEnd, pretty) {
  5027. const quitEarlyArr = [false];
  5028. let changes = this.ComputeDiffRecursive(originalStart, originalEnd, modifiedStart, modifiedEnd, quitEarlyArr);
  5029. if (pretty) {
  5030. // We have to clean up the computed diff to be more intuitive
  5031. // but it turns out this cannot be done correctly until the entire set
  5032. // of diffs have been computed
  5033. changes = this.PrettifyChanges(changes);
  5034. }
  5035. return {
  5036. quitEarly: quitEarlyArr[0],
  5037. changes: changes
  5038. };
  5039. }
  5040. /**
  5041. * Private helper method which computes the differences on the bounded range
  5042. * recursively.
  5043. * @returns An array of the differences between the two input sequences.
  5044. */
  5045. ComputeDiffRecursive(originalStart, originalEnd, modifiedStart, modifiedEnd, quitEarlyArr) {
  5046. quitEarlyArr[0] = false;
  5047. // Find the start of the differences
  5048. while (originalStart <= originalEnd && modifiedStart <= modifiedEnd && this.ElementsAreEqual(originalStart, modifiedStart)) {
  5049. originalStart++;
  5050. modifiedStart++;
  5051. }
  5052. // Find the end of the differences
  5053. while (originalEnd >= originalStart && modifiedEnd >= modifiedStart && this.ElementsAreEqual(originalEnd, modifiedEnd)) {
  5054. originalEnd--;
  5055. modifiedEnd--;
  5056. }
  5057. // In the special case where we either have all insertions or all deletions or the sequences are identical
  5058. if (originalStart > originalEnd || modifiedStart > modifiedEnd) {
  5059. let changes;
  5060. if (modifiedStart <= modifiedEnd) {
  5061. Debug.Assert(originalStart === originalEnd + 1, 'originalStart should only be one more than originalEnd');
  5062. // All insertions
  5063. changes = [
  5064. new DiffChange(originalStart, 0, modifiedStart, modifiedEnd - modifiedStart + 1)
  5065. ];
  5066. }
  5067. else if (originalStart <= originalEnd) {
  5068. Debug.Assert(modifiedStart === modifiedEnd + 1, 'modifiedStart should only be one more than modifiedEnd');
  5069. // All deletions
  5070. changes = [
  5071. new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, 0)
  5072. ];
  5073. }
  5074. else {
  5075. Debug.Assert(originalStart === originalEnd + 1, 'originalStart should only be one more than originalEnd');
  5076. Debug.Assert(modifiedStart === modifiedEnd + 1, 'modifiedStart should only be one more than modifiedEnd');
  5077. // Identical sequences - No differences
  5078. changes = [];
  5079. }
  5080. return changes;
  5081. }
  5082. // This problem can be solved using the Divide-And-Conquer technique.
  5083. const midOriginalArr = [0];
  5084. const midModifiedArr = [0];
  5085. const result = this.ComputeRecursionPoint(originalStart, originalEnd, modifiedStart, modifiedEnd, midOriginalArr, midModifiedArr, quitEarlyArr);
  5086. const midOriginal = midOriginalArr[0];
  5087. const midModified = midModifiedArr[0];
  5088. if (result !== null) {
  5089. // Result is not-null when there was enough memory to compute the changes while
  5090. // searching for the recursion point
  5091. return result;
  5092. }
  5093. else if (!quitEarlyArr[0]) {
  5094. // We can break the problem down recursively by finding the changes in the
  5095. // First Half: (originalStart, modifiedStart) to (midOriginal, midModified)
  5096. // Second Half: (midOriginal + 1, minModified + 1) to (originalEnd, modifiedEnd)
  5097. // NOTE: ComputeDiff() is inclusive, therefore the second range starts on the next point
  5098. const leftChanges = this.ComputeDiffRecursive(originalStart, midOriginal, modifiedStart, midModified, quitEarlyArr);
  5099. let rightChanges = [];
  5100. if (!quitEarlyArr[0]) {
  5101. rightChanges = this.ComputeDiffRecursive(midOriginal + 1, originalEnd, midModified + 1, modifiedEnd, quitEarlyArr);
  5102. }
  5103. else {
  5104. // We didn't have time to finish the first half, so we don't have time to compute this half.
  5105. // Consider the entire rest of the sequence different.
  5106. rightChanges = [
  5107. new DiffChange(midOriginal + 1, originalEnd - (midOriginal + 1) + 1, midModified + 1, modifiedEnd - (midModified + 1) + 1)
  5108. ];
  5109. }
  5110. return this.ConcatenateChanges(leftChanges, rightChanges);
  5111. }
  5112. // If we hit here, we quit early, and so can't return anything meaningful
  5113. return [
  5114. new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, modifiedEnd - modifiedStart + 1)
  5115. ];
  5116. }
  5117. WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr) {
  5118. let forwardChanges = null;
  5119. let reverseChanges = null;
  5120. // First, walk backward through the forward diagonals history
  5121. let changeHelper = new DiffChangeHelper();
  5122. let diagonalMin = diagonalForwardStart;
  5123. let diagonalMax = diagonalForwardEnd;
  5124. let diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalForwardOffset;
  5125. let lastOriginalIndex = -1073741824 /* Constants.MIN_SAFE_SMALL_INTEGER */;
  5126. let historyIndex = this.m_forwardHistory.length - 1;
  5127. do {
  5128. // Get the diagonal index from the relative diagonal number
  5129. const diagonal = diagonalRelative + diagonalForwardBase;
  5130. // Figure out where we came from
  5131. if (diagonal === diagonalMin || (diagonal < diagonalMax && forwardPoints[diagonal - 1] < forwardPoints[diagonal + 1])) {
  5132. // Vertical line (the element is an insert)
  5133. originalIndex = forwardPoints[diagonal + 1];
  5134. modifiedIndex = originalIndex - diagonalRelative - diagonalForwardOffset;
  5135. if (originalIndex < lastOriginalIndex) {
  5136. changeHelper.MarkNextChange();
  5137. }
  5138. lastOriginalIndex = originalIndex;
  5139. changeHelper.AddModifiedElement(originalIndex + 1, modifiedIndex);
  5140. diagonalRelative = (diagonal + 1) - diagonalForwardBase; //Setup for the next iteration
  5141. }
  5142. else {
  5143. // Horizontal line (the element is a deletion)
  5144. originalIndex = forwardPoints[diagonal - 1] + 1;
  5145. modifiedIndex = originalIndex - diagonalRelative - diagonalForwardOffset;
  5146. if (originalIndex < lastOriginalIndex) {
  5147. changeHelper.MarkNextChange();
  5148. }
  5149. lastOriginalIndex = originalIndex - 1;
  5150. changeHelper.AddOriginalElement(originalIndex, modifiedIndex + 1);
  5151. diagonalRelative = (diagonal - 1) - diagonalForwardBase; //Setup for the next iteration
  5152. }
  5153. if (historyIndex >= 0) {
  5154. forwardPoints = this.m_forwardHistory[historyIndex];
  5155. diagonalForwardBase = forwardPoints[0]; //We stored this in the first spot
  5156. diagonalMin = 1;
  5157. diagonalMax = forwardPoints.length - 1;
  5158. }
  5159. } while (--historyIndex >= -1);
  5160. // Ironically, we get the forward changes as the reverse of the
  5161. // order we added them since we technically added them backwards
  5162. forwardChanges = changeHelper.getReverseChanges();
  5163. if (quitEarlyArr[0]) {
  5164. // TODO: Calculate a partial from the reverse diagonals.
  5165. // For now, just assume everything after the midOriginal/midModified point is a diff
  5166. let originalStartPoint = midOriginalArr[0] + 1;
  5167. let modifiedStartPoint = midModifiedArr[0] + 1;
  5168. if (forwardChanges !== null && forwardChanges.length > 0) {
  5169. const lastForwardChange = forwardChanges[forwardChanges.length - 1];
  5170. originalStartPoint = Math.max(originalStartPoint, lastForwardChange.getOriginalEnd());
  5171. modifiedStartPoint = Math.max(modifiedStartPoint, lastForwardChange.getModifiedEnd());
  5172. }
  5173. reverseChanges = [
  5174. new DiffChange(originalStartPoint, originalEnd - originalStartPoint + 1, modifiedStartPoint, modifiedEnd - modifiedStartPoint + 1)
  5175. ];
  5176. }
  5177. else {
  5178. // Now walk backward through the reverse diagonals history
  5179. changeHelper = new DiffChangeHelper();
  5180. diagonalMin = diagonalReverseStart;
  5181. diagonalMax = diagonalReverseEnd;
  5182. diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalReverseOffset;
  5183. lastOriginalIndex = 1073741824 /* Constants.MAX_SAFE_SMALL_INTEGER */;
  5184. historyIndex = (deltaIsEven) ? this.m_reverseHistory.length - 1 : this.m_reverseHistory.length - 2;
  5185. do {
  5186. // Get the diagonal index from the relative diagonal number
  5187. const diagonal = diagonalRelative + diagonalReverseBase;
  5188. // Figure out where we came from
  5189. if (diagonal === diagonalMin || (diagonal < diagonalMax && reversePoints[diagonal - 1] >= reversePoints[diagonal + 1])) {
  5190. // Horizontal line (the element is a deletion))
  5191. originalIndex = reversePoints[diagonal + 1] - 1;
  5192. modifiedIndex = originalIndex - diagonalRelative - diagonalReverseOffset;
  5193. if (originalIndex > lastOriginalIndex) {
  5194. changeHelper.MarkNextChange();
  5195. }
  5196. lastOriginalIndex = originalIndex + 1;
  5197. changeHelper.AddOriginalElement(originalIndex + 1, modifiedIndex + 1);
  5198. diagonalRelative = (diagonal + 1) - diagonalReverseBase; //Setup for the next iteration
  5199. }
  5200. else {
  5201. // Vertical line (the element is an insertion)
  5202. originalIndex = reversePoints[diagonal - 1];
  5203. modifiedIndex = originalIndex - diagonalRelative - diagonalReverseOffset;
  5204. if (originalIndex > lastOriginalIndex) {
  5205. changeHelper.MarkNextChange();
  5206. }
  5207. lastOriginalIndex = originalIndex;
  5208. changeHelper.AddModifiedElement(originalIndex + 1, modifiedIndex + 1);
  5209. diagonalRelative = (diagonal - 1) - diagonalReverseBase; //Setup for the next iteration
  5210. }
  5211. if (historyIndex >= 0) {
  5212. reversePoints = this.m_reverseHistory[historyIndex];
  5213. diagonalReverseBase = reversePoints[0]; //We stored this in the first spot
  5214. diagonalMin = 1;
  5215. diagonalMax = reversePoints.length - 1;
  5216. }
  5217. } while (--historyIndex >= -1);
  5218. // There are cases where the reverse history will find diffs that
  5219. // are correct, but not intuitive, so we need shift them.
  5220. reverseChanges = changeHelper.getChanges();
  5221. }
  5222. return this.ConcatenateChanges(forwardChanges, reverseChanges);
  5223. }
  5224. /**
  5225. * Given the range to compute the diff on, this method finds the point:
  5226. * (midOriginal, midModified)
  5227. * that exists in the middle of the LCS of the two sequences and
  5228. * is the point at which the LCS problem may be broken down recursively.
  5229. * This method will try to keep the LCS trace in memory. If the LCS recursion
  5230. * point is calculated and the full trace is available in memory, then this method
  5231. * will return the change list.
  5232. * @param originalStart The start bound of the original sequence range
  5233. * @param originalEnd The end bound of the original sequence range
  5234. * @param modifiedStart The start bound of the modified sequence range
  5235. * @param modifiedEnd The end bound of the modified sequence range
  5236. * @param midOriginal The middle point of the original sequence range
  5237. * @param midModified The middle point of the modified sequence range
  5238. * @returns The diff changes, if available, otherwise null
  5239. */
  5240. ComputeRecursionPoint(originalStart, originalEnd, modifiedStart, modifiedEnd, midOriginalArr, midModifiedArr, quitEarlyArr) {
  5241. let originalIndex = 0, modifiedIndex = 0;
  5242. let diagonalForwardStart = 0, diagonalForwardEnd = 0;
  5243. let diagonalReverseStart = 0, diagonalReverseEnd = 0;
  5244. // To traverse the edit graph and produce the proper LCS, our actual
  5245. // start position is just outside the given boundary
  5246. originalStart--;
  5247. modifiedStart--;
  5248. // We set these up to make the compiler happy, but they will
  5249. // be replaced before we return with the actual recursion point
  5250. midOriginalArr[0] = 0;
  5251. midModifiedArr[0] = 0;
  5252. // Clear out the history
  5253. this.m_forwardHistory = [];
  5254. this.m_reverseHistory = [];
  5255. // Each cell in the two arrays corresponds to a diagonal in the edit graph.
  5256. // The integer value in the cell represents the originalIndex of the furthest
  5257. // reaching point found so far that ends in that diagonal.
  5258. // The modifiedIndex can be computed mathematically from the originalIndex and the diagonal number.
  5259. const maxDifferences = (originalEnd - originalStart) + (modifiedEnd - modifiedStart);
  5260. const numDiagonals = maxDifferences + 1;
  5261. const forwardPoints = new Int32Array(numDiagonals);
  5262. const reversePoints = new Int32Array(numDiagonals);
  5263. // diagonalForwardBase: Index into forwardPoints of the diagonal which passes through (originalStart, modifiedStart)
  5264. // diagonalReverseBase: Index into reversePoints of the diagonal which passes through (originalEnd, modifiedEnd)
  5265. const diagonalForwardBase = (modifiedEnd - modifiedStart);
  5266. const diagonalReverseBase = (originalEnd - originalStart);
  5267. // diagonalForwardOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
  5268. // diagonal number (relative to diagonalForwardBase)
  5269. // diagonalReverseOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
  5270. // diagonal number (relative to diagonalReverseBase)
  5271. const diagonalForwardOffset = (originalStart - modifiedStart);
  5272. const diagonalReverseOffset = (originalEnd - modifiedEnd);
  5273. // delta: The difference between the end diagonal and the start diagonal. This is used to relate diagonal numbers
  5274. // relative to the start diagonal with diagonal numbers relative to the end diagonal.
  5275. // The Even/Oddn-ness of this delta is important for determining when we should check for overlap
  5276. const delta = diagonalReverseBase - diagonalForwardBase;
  5277. const deltaIsEven = (delta % 2 === 0);
  5278. // Here we set up the start and end points as the furthest points found so far
  5279. // in both the forward and reverse directions, respectively
  5280. forwardPoints[diagonalForwardBase] = originalStart;
  5281. reversePoints[diagonalReverseBase] = originalEnd;
  5282. // Remember if we quit early, and thus need to do a best-effort result instead of a real result.
  5283. quitEarlyArr[0] = false;
  5284. // A couple of points:
  5285. // --With this method, we iterate on the number of differences between the two sequences.
  5286. // The more differences there actually are, the longer this will take.
  5287. // --Also, as the number of differences increases, we have to search on diagonals further
  5288. // away from the reference diagonal (which is diagonalForwardBase for forward, diagonalReverseBase for reverse).
  5289. // --We extend on even diagonals (relative to the reference diagonal) only when numDifferences
  5290. // is even and odd diagonals only when numDifferences is odd.
  5291. for (let numDifferences = 1; numDifferences <= (maxDifferences / 2) + 1; numDifferences++) {
  5292. let furthestOriginalIndex = 0;
  5293. let furthestModifiedIndex = 0;
  5294. // Run the algorithm in the forward direction
  5295. diagonalForwardStart = this.ClipDiagonalBound(diagonalForwardBase - numDifferences, numDifferences, diagonalForwardBase, numDiagonals);
  5296. diagonalForwardEnd = this.ClipDiagonalBound(diagonalForwardBase + numDifferences, numDifferences, diagonalForwardBase, numDiagonals);
  5297. for (let diagonal = diagonalForwardStart; diagonal <= diagonalForwardEnd; diagonal += 2) {
  5298. // STEP 1: We extend the furthest reaching point in the present diagonal
  5299. // by looking at the diagonals above and below and picking the one whose point
  5300. // is further away from the start point (originalStart, modifiedStart)
  5301. if (diagonal === diagonalForwardStart || (diagonal < diagonalForwardEnd && forwardPoints[diagonal - 1] < forwardPoints[diagonal + 1])) {
  5302. originalIndex = forwardPoints[diagonal + 1];
  5303. }
  5304. else {
  5305. originalIndex = forwardPoints[diagonal - 1] + 1;
  5306. }
  5307. modifiedIndex = originalIndex - (diagonal - diagonalForwardBase) - diagonalForwardOffset;
  5308. // Save the current originalIndex so we can test for false overlap in step 3
  5309. const tempOriginalIndex = originalIndex;
  5310. // STEP 2: We can continue to extend the furthest reaching point in the present diagonal
  5311. // so long as the elements are equal.
  5312. while (originalIndex < originalEnd && modifiedIndex < modifiedEnd && this.ElementsAreEqual(originalIndex + 1, modifiedIndex + 1)) {
  5313. originalIndex++;
  5314. modifiedIndex++;
  5315. }
  5316. forwardPoints[diagonal] = originalIndex;
  5317. if (originalIndex + modifiedIndex > furthestOriginalIndex + furthestModifiedIndex) {
  5318. furthestOriginalIndex = originalIndex;
  5319. furthestModifiedIndex = modifiedIndex;
  5320. }
  5321. // STEP 3: If delta is odd (overlap first happens on forward when delta is odd)
  5322. // and diagonal is in the range of reverse diagonals computed for numDifferences-1
  5323. // (the previous iteration; we haven't computed reverse diagonals for numDifferences yet)
  5324. // then check for overlap.
  5325. if (!deltaIsEven && Math.abs(diagonal - diagonalReverseBase) <= (numDifferences - 1)) {
  5326. if (originalIndex >= reversePoints[diagonal]) {
  5327. midOriginalArr[0] = originalIndex;
  5328. midModifiedArr[0] = modifiedIndex;
  5329. if (tempOriginalIndex <= reversePoints[diagonal] && 1447 /* LocalConstants.MaxDifferencesHistory */ > 0 && numDifferences <= (1447 /* LocalConstants.MaxDifferencesHistory */ + 1)) {
  5330. // BINGO! We overlapped, and we have the full trace in memory!
  5331. return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr);
  5332. }
  5333. else {
  5334. // Either false overlap, or we didn't have enough memory for the full trace
  5335. // Just return the recursion point
  5336. return null;
  5337. }
  5338. }
  5339. }
  5340. }
  5341. // Check to see if we should be quitting early, before moving on to the next iteration.
  5342. const matchLengthOfLongest = ((furthestOriginalIndex - originalStart) + (furthestModifiedIndex - modifiedStart) - numDifferences) / 2;
  5343. if (this.ContinueProcessingPredicate !== null && !this.ContinueProcessingPredicate(furthestOriginalIndex, matchLengthOfLongest)) {
  5344. // We can't finish, so skip ahead to generating a result from what we have.
  5345. quitEarlyArr[0] = true;
  5346. // Use the furthest distance we got in the forward direction.
  5347. midOriginalArr[0] = furthestOriginalIndex;
  5348. midModifiedArr[0] = furthestModifiedIndex;
  5349. if (matchLengthOfLongest > 0 && 1447 /* LocalConstants.MaxDifferencesHistory */ > 0 && numDifferences <= (1447 /* LocalConstants.MaxDifferencesHistory */ + 1)) {
  5350. // Enough of the history is in memory to walk it backwards
  5351. return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr);
  5352. }
  5353. else {
  5354. // We didn't actually remember enough of the history.
  5355. //Since we are quitting the diff early, we need to shift back the originalStart and modified start
  5356. //back into the boundary limits since we decremented their value above beyond the boundary limit.
  5357. originalStart++;
  5358. modifiedStart++;
  5359. return [
  5360. new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, modifiedEnd - modifiedStart + 1)
  5361. ];
  5362. }
  5363. }
  5364. // Run the algorithm in the reverse direction
  5365. diagonalReverseStart = this.ClipDiagonalBound(diagonalReverseBase - numDifferences, numDifferences, diagonalReverseBase, numDiagonals);
  5366. diagonalReverseEnd = this.ClipDiagonalBound(diagonalReverseBase + numDifferences, numDifferences, diagonalReverseBase, numDiagonals);
  5367. for (let diagonal = diagonalReverseStart; diagonal <= diagonalReverseEnd; diagonal += 2) {
  5368. // STEP 1: We extend the furthest reaching point in the present diagonal
  5369. // by looking at the diagonals above and below and picking the one whose point
  5370. // is further away from the start point (originalEnd, modifiedEnd)
  5371. if (diagonal === diagonalReverseStart || (diagonal < diagonalReverseEnd && reversePoints[diagonal - 1] >= reversePoints[diagonal + 1])) {
  5372. originalIndex = reversePoints[diagonal + 1] - 1;
  5373. }
  5374. else {
  5375. originalIndex = reversePoints[diagonal - 1];
  5376. }
  5377. modifiedIndex = originalIndex - (diagonal - diagonalReverseBase) - diagonalReverseOffset;
  5378. // Save the current originalIndex so we can test for false overlap
  5379. const tempOriginalIndex = originalIndex;
  5380. // STEP 2: We can continue to extend the furthest reaching point in the present diagonal
  5381. // as long as the elements are equal.
  5382. while (originalIndex > originalStart && modifiedIndex > modifiedStart && this.ElementsAreEqual(originalIndex, modifiedIndex)) {
  5383. originalIndex--;
  5384. modifiedIndex--;
  5385. }
  5386. reversePoints[diagonal] = originalIndex;
  5387. // STEP 4: If delta is even (overlap first happens on reverse when delta is even)
  5388. // and diagonal is in the range of forward diagonals computed for numDifferences
  5389. // then check for overlap.
  5390. if (deltaIsEven && Math.abs(diagonal - diagonalForwardBase) <= numDifferences) {
  5391. if (originalIndex <= forwardPoints[diagonal]) {
  5392. midOriginalArr[0] = originalIndex;
  5393. midModifiedArr[0] = modifiedIndex;
  5394. if (tempOriginalIndex >= forwardPoints[diagonal] && 1447 /* LocalConstants.MaxDifferencesHistory */ > 0 && numDifferences <= (1447 /* LocalConstants.MaxDifferencesHistory */ + 1)) {
  5395. // BINGO! We overlapped, and we have the full trace in memory!
  5396. return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr);
  5397. }
  5398. else {
  5399. // Either false overlap, or we didn't have enough memory for the full trace
  5400. // Just return the recursion point
  5401. return null;
  5402. }
  5403. }
  5404. }
  5405. }
  5406. // Save current vectors to history before the next iteration
  5407. if (numDifferences <= 1447 /* LocalConstants.MaxDifferencesHistory */) {
  5408. // We are allocating space for one extra int, which we fill with
  5409. // the index of the diagonal base index
  5410. let temp = new Int32Array(diagonalForwardEnd - diagonalForwardStart + 2);
  5411. temp[0] = diagonalForwardBase - diagonalForwardStart + 1;
  5412. MyArray.Copy2(forwardPoints, diagonalForwardStart, temp, 1, diagonalForwardEnd - diagonalForwardStart + 1);
  5413. this.m_forwardHistory.push(temp);
  5414. temp = new Int32Array(diagonalReverseEnd - diagonalReverseStart + 2);
  5415. temp[0] = diagonalReverseBase - diagonalReverseStart + 1;
  5416. MyArray.Copy2(reversePoints, diagonalReverseStart, temp, 1, diagonalReverseEnd - diagonalReverseStart + 1);
  5417. this.m_reverseHistory.push(temp);
  5418. }
  5419. }
  5420. // If we got here, then we have the full trace in history. We just have to convert it to a change list
  5421. // NOTE: This part is a bit messy
  5422. return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr);
  5423. }
  5424. /**
  5425. * Shifts the given changes to provide a more intuitive diff.
  5426. * While the first element in a diff matches the first element after the diff,
  5427. * we shift the diff down.
  5428. *
  5429. * @param changes The list of changes to shift
  5430. * @returns The shifted changes
  5431. */
  5432. PrettifyChanges(changes) {
  5433. // Shift all the changes down first
  5434. for (let i = 0; i < changes.length; i++) {
  5435. const change = changes[i];
  5436. const originalStop = (i < changes.length - 1) ? changes[i + 1].originalStart : this._originalElementsOrHash.length;
  5437. const modifiedStop = (i < changes.length - 1) ? changes[i + 1].modifiedStart : this._modifiedElementsOrHash.length;
  5438. const checkOriginal = change.originalLength > 0;
  5439. const checkModified = change.modifiedLength > 0;
  5440. while (change.originalStart + change.originalLength < originalStop
  5441. && change.modifiedStart + change.modifiedLength < modifiedStop
  5442. && (!checkOriginal || this.OriginalElementsAreEqual(change.originalStart, change.originalStart + change.originalLength))
  5443. && (!checkModified || this.ModifiedElementsAreEqual(change.modifiedStart, change.modifiedStart + change.modifiedLength))) {
  5444. const startStrictEqual = this.ElementsAreStrictEqual(change.originalStart, change.modifiedStart);
  5445. const endStrictEqual = this.ElementsAreStrictEqual(change.originalStart + change.originalLength, change.modifiedStart + change.modifiedLength);
  5446. if (endStrictEqual && !startStrictEqual) {
  5447. // moving the change down would create an equal change, but the elements are not strict equal
  5448. break;
  5449. }
  5450. change.originalStart++;
  5451. change.modifiedStart++;
  5452. }
  5453. const mergedChangeArr = [null];
  5454. if (i < changes.length - 1 && this.ChangesOverlap(changes[i], changes[i + 1], mergedChangeArr)) {
  5455. changes[i] = mergedChangeArr[0];
  5456. changes.splice(i + 1, 1);
  5457. i--;
  5458. continue;
  5459. }
  5460. }
  5461. // Shift changes back up until we hit empty or whitespace-only lines
  5462. for (let i = changes.length - 1; i >= 0; i--) {
  5463. const change = changes[i];
  5464. let originalStop = 0;
  5465. let modifiedStop = 0;
  5466. if (i > 0) {
  5467. const prevChange = changes[i - 1];
  5468. originalStop = prevChange.originalStart + prevChange.originalLength;
  5469. modifiedStop = prevChange.modifiedStart + prevChange.modifiedLength;
  5470. }
  5471. const checkOriginal = change.originalLength > 0;
  5472. const checkModified = change.modifiedLength > 0;
  5473. let bestDelta = 0;
  5474. let bestScore = this._boundaryScore(change.originalStart, change.originalLength, change.modifiedStart, change.modifiedLength);
  5475. for (let delta = 1;; delta++) {
  5476. const originalStart = change.originalStart - delta;
  5477. const modifiedStart = change.modifiedStart - delta;
  5478. if (originalStart < originalStop || modifiedStart < modifiedStop) {
  5479. break;
  5480. }
  5481. if (checkOriginal && !this.OriginalElementsAreEqual(originalStart, originalStart + change.originalLength)) {
  5482. break;
  5483. }
  5484. if (checkModified && !this.ModifiedElementsAreEqual(modifiedStart, modifiedStart + change.modifiedLength)) {
  5485. break;
  5486. }
  5487. const touchingPreviousChange = (originalStart === originalStop && modifiedStart === modifiedStop);
  5488. const score = ((touchingPreviousChange ? 5 : 0)
  5489. + this._boundaryScore(originalStart, change.originalLength, modifiedStart, change.modifiedLength));
  5490. if (score > bestScore) {
  5491. bestScore = score;
  5492. bestDelta = delta;
  5493. }
  5494. }
  5495. change.originalStart -= bestDelta;
  5496. change.modifiedStart -= bestDelta;
  5497. const mergedChangeArr = [null];
  5498. if (i > 0 && this.ChangesOverlap(changes[i - 1], changes[i], mergedChangeArr)) {
  5499. changes[i - 1] = mergedChangeArr[0];
  5500. changes.splice(i, 1);
  5501. i++;
  5502. continue;
  5503. }
  5504. }
  5505. // There could be multiple longest common substrings.
  5506. // Give preference to the ones containing longer lines
  5507. if (this._hasStrings) {
  5508. for (let i = 1, len = changes.length; i < len; i++) {
  5509. const aChange = changes[i - 1];
  5510. const bChange = changes[i];
  5511. const matchedLength = bChange.originalStart - aChange.originalStart - aChange.originalLength;
  5512. const aOriginalStart = aChange.originalStart;
  5513. const bOriginalEnd = bChange.originalStart + bChange.originalLength;
  5514. const abOriginalLength = bOriginalEnd - aOriginalStart;
  5515. const aModifiedStart = aChange.modifiedStart;
  5516. const bModifiedEnd = bChange.modifiedStart + bChange.modifiedLength;
  5517. const abModifiedLength = bModifiedEnd - aModifiedStart;
  5518. // Avoid wasting a lot of time with these searches
  5519. if (matchedLength < 5 && abOriginalLength < 20 && abModifiedLength < 20) {
  5520. const t = this._findBetterContiguousSequence(aOriginalStart, abOriginalLength, aModifiedStart, abModifiedLength, matchedLength);
  5521. if (t) {
  5522. const [originalMatchStart, modifiedMatchStart] = t;
  5523. if (originalMatchStart !== aChange.originalStart + aChange.originalLength || modifiedMatchStart !== aChange.modifiedStart + aChange.modifiedLength) {
  5524. // switch to another sequence that has a better score
  5525. aChange.originalLength = originalMatchStart - aChange.originalStart;
  5526. aChange.modifiedLength = modifiedMatchStart - aChange.modifiedStart;
  5527. bChange.originalStart = originalMatchStart + matchedLength;
  5528. bChange.modifiedStart = modifiedMatchStart + matchedLength;
  5529. bChange.originalLength = bOriginalEnd - bChange.originalStart;
  5530. bChange.modifiedLength = bModifiedEnd - bChange.modifiedStart;
  5531. }
  5532. }
  5533. }
  5534. }
  5535. }
  5536. return changes;
  5537. }
  5538. _findBetterContiguousSequence(originalStart, originalLength, modifiedStart, modifiedLength, desiredLength) {
  5539. if (originalLength < desiredLength || modifiedLength < desiredLength) {
  5540. return null;
  5541. }
  5542. const originalMax = originalStart + originalLength - desiredLength + 1;
  5543. const modifiedMax = modifiedStart + modifiedLength - desiredLength + 1;
  5544. let bestScore = 0;
  5545. let bestOriginalStart = 0;
  5546. let bestModifiedStart = 0;
  5547. for (let i = originalStart; i < originalMax; i++) {
  5548. for (let j = modifiedStart; j < modifiedMax; j++) {
  5549. const score = this._contiguousSequenceScore(i, j, desiredLength);
  5550. if (score > 0 && score > bestScore) {
  5551. bestScore = score;
  5552. bestOriginalStart = i;
  5553. bestModifiedStart = j;
  5554. }
  5555. }
  5556. }
  5557. if (bestScore > 0) {
  5558. return [bestOriginalStart, bestModifiedStart];
  5559. }
  5560. return null;
  5561. }
  5562. _contiguousSequenceScore(originalStart, modifiedStart, length) {
  5563. let score = 0;
  5564. for (let l = 0; l < length; l++) {
  5565. if (!this.ElementsAreEqual(originalStart + l, modifiedStart + l)) {
  5566. return 0;
  5567. }
  5568. score += this._originalStringElements[originalStart + l].length;
  5569. }
  5570. return score;
  5571. }
  5572. _OriginalIsBoundary(index) {
  5573. if (index <= 0 || index >= this._originalElementsOrHash.length - 1) {
  5574. return true;
  5575. }
  5576. return (this._hasStrings && /^\s*$/.test(this._originalStringElements[index]));
  5577. }
  5578. _OriginalRegionIsBoundary(originalStart, originalLength) {
  5579. if (this._OriginalIsBoundary(originalStart) || this._OriginalIsBoundary(originalStart - 1)) {
  5580. return true;
  5581. }
  5582. if (originalLength > 0) {
  5583. const originalEnd = originalStart + originalLength;
  5584. if (this._OriginalIsBoundary(originalEnd - 1) || this._OriginalIsBoundary(originalEnd)) {
  5585. return true;
  5586. }
  5587. }
  5588. return false;
  5589. }
  5590. _ModifiedIsBoundary(index) {
  5591. if (index <= 0 || index >= this._modifiedElementsOrHash.length - 1) {
  5592. return true;
  5593. }
  5594. return (this._hasStrings && /^\s*$/.test(this._modifiedStringElements[index]));
  5595. }
  5596. _ModifiedRegionIsBoundary(modifiedStart, modifiedLength) {
  5597. if (this._ModifiedIsBoundary(modifiedStart) || this._ModifiedIsBoundary(modifiedStart - 1)) {
  5598. return true;
  5599. }
  5600. if (modifiedLength > 0) {
  5601. const modifiedEnd = modifiedStart + modifiedLength;
  5602. if (this._ModifiedIsBoundary(modifiedEnd - 1) || this._ModifiedIsBoundary(modifiedEnd)) {
  5603. return true;
  5604. }
  5605. }
  5606. return false;
  5607. }
  5608. _boundaryScore(originalStart, originalLength, modifiedStart, modifiedLength) {
  5609. const originalScore = (this._OriginalRegionIsBoundary(originalStart, originalLength) ? 1 : 0);
  5610. const modifiedScore = (this._ModifiedRegionIsBoundary(modifiedStart, modifiedLength) ? 1 : 0);
  5611. return (originalScore + modifiedScore);
  5612. }
  5613. /**
  5614. * Concatenates the two input DiffChange lists and returns the resulting
  5615. * list.
  5616. * @param The left changes
  5617. * @param The right changes
  5618. * @returns The concatenated list
  5619. */
  5620. ConcatenateChanges(left, right) {
  5621. const mergedChangeArr = [];
  5622. if (left.length === 0 || right.length === 0) {
  5623. return (right.length > 0) ? right : left;
  5624. }
  5625. else if (this.ChangesOverlap(left[left.length - 1], right[0], mergedChangeArr)) {
  5626. // Since we break the problem down recursively, it is possible that we
  5627. // might recurse in the middle of a change thereby splitting it into
  5628. // two changes. Here in the combining stage, we detect and fuse those
  5629. // changes back together
  5630. const result = new Array(left.length + right.length - 1);
  5631. MyArray.Copy(left, 0, result, 0, left.length - 1);
  5632. result[left.length - 1] = mergedChangeArr[0];
  5633. MyArray.Copy(right, 1, result, left.length, right.length - 1);
  5634. return result;
  5635. }
  5636. else {
  5637. const result = new Array(left.length + right.length);
  5638. MyArray.Copy(left, 0, result, 0, left.length);
  5639. MyArray.Copy(right, 0, result, left.length, right.length);
  5640. return result;
  5641. }
  5642. }
  5643. /**
  5644. * Returns true if the two changes overlap and can be merged into a single
  5645. * change
  5646. * @param left The left change
  5647. * @param right The right change
  5648. * @param mergedChange The merged change if the two overlap, null otherwise
  5649. * @returns True if the two changes overlap
  5650. */
  5651. ChangesOverlap(left, right, mergedChangeArr) {
  5652. Debug.Assert(left.originalStart <= right.originalStart, 'Left change is not less than or equal to right change');
  5653. Debug.Assert(left.modifiedStart <= right.modifiedStart, 'Left change is not less than or equal to right change');
  5654. if (left.originalStart + left.originalLength >= right.originalStart || left.modifiedStart + left.modifiedLength >= right.modifiedStart) {
  5655. const originalStart = left.originalStart;
  5656. let originalLength = left.originalLength;
  5657. const modifiedStart = left.modifiedStart;
  5658. let modifiedLength = left.modifiedLength;
  5659. if (left.originalStart + left.originalLength >= right.originalStart) {
  5660. originalLength = right.originalStart + right.originalLength - left.originalStart;
  5661. }
  5662. if (left.modifiedStart + left.modifiedLength >= right.modifiedStart) {
  5663. modifiedLength = right.modifiedStart + right.modifiedLength - left.modifiedStart;
  5664. }
  5665. mergedChangeArr[0] = new DiffChange(originalStart, originalLength, modifiedStart, modifiedLength);
  5666. return true;
  5667. }
  5668. else {
  5669. mergedChangeArr[0] = null;
  5670. return false;
  5671. }
  5672. }
  5673. /**
  5674. * Helper method used to clip a diagonal index to the range of valid
  5675. * diagonals. This also decides whether or not the diagonal index,
  5676. * if it exceeds the boundary, should be clipped to the boundary or clipped
  5677. * one inside the boundary depending on the Even/Odd status of the boundary
  5678. * and numDifferences.
  5679. * @param diagonal The index of the diagonal to clip.
  5680. * @param numDifferences The current number of differences being iterated upon.
  5681. * @param diagonalBaseIndex The base reference diagonal.
  5682. * @param numDiagonals The total number of diagonals.
  5683. * @returns The clipped diagonal index.
  5684. */
  5685. ClipDiagonalBound(diagonal, numDifferences, diagonalBaseIndex, numDiagonals) {
  5686. if (diagonal >= 0 && diagonal < numDiagonals) {
  5687. // Nothing to clip, its in range
  5688. return diagonal;
  5689. }
  5690. // diagonalsBelow: The number of diagonals below the reference diagonal
  5691. // diagonalsAbove: The number of diagonals above the reference diagonal
  5692. const diagonalsBelow = diagonalBaseIndex;
  5693. const diagonalsAbove = numDiagonals - diagonalBaseIndex - 1;
  5694. const diffEven = (numDifferences % 2 === 0);
  5695. if (diagonal < 0) {
  5696. const lowerBoundEven = (diagonalsBelow % 2 === 0);
  5697. return (diffEven === lowerBoundEven) ? 0 : 1;
  5698. }
  5699. else {
  5700. const upperBoundEven = (diagonalsAbove % 2 === 0);
  5701. return (diffEven === upperBoundEven) ? numDiagonals - 1 : numDiagonals - 2;
  5702. }
  5703. }
  5704. }
  5705. /*---------------------------------------------------------------------------------------------
  5706. * Copyright (c) Microsoft Corporation. All rights reserved.
  5707. * Licensed under the MIT License. See License.txt in the project root for license information.
  5708. *--------------------------------------------------------------------------------------------*/
  5709. /**
  5710. * A position in the editor.
  5711. */
  5712. class Position {
  5713. constructor(lineNumber, column) {
  5714. this.lineNumber = lineNumber;
  5715. this.column = column;
  5716. }
  5717. /**
  5718. * Create a new position from this position.
  5719. *
  5720. * @param newLineNumber new line number
  5721. * @param newColumn new column
  5722. */
  5723. with(newLineNumber = this.lineNumber, newColumn = this.column) {
  5724. if (newLineNumber === this.lineNumber && newColumn === this.column) {
  5725. return this;
  5726. }
  5727. else {
  5728. return new Position(newLineNumber, newColumn);
  5729. }
  5730. }
  5731. /**
  5732. * Derive a new position from this position.
  5733. *
  5734. * @param deltaLineNumber line number delta
  5735. * @param deltaColumn column delta
  5736. */
  5737. delta(deltaLineNumber = 0, deltaColumn = 0) {
  5738. return this.with(this.lineNumber + deltaLineNumber, this.column + deltaColumn);
  5739. }
  5740. /**
  5741. * Test if this position equals other position
  5742. */
  5743. equals(other) {
  5744. return Position.equals(this, other);
  5745. }
  5746. /**
  5747. * Test if position `a` equals position `b`
  5748. */
  5749. static equals(a, b) {
  5750. if (!a && !b) {
  5751. return true;
  5752. }
  5753. return (!!a &&
  5754. !!b &&
  5755. a.lineNumber === b.lineNumber &&
  5756. a.column === b.column);
  5757. }
  5758. /**
  5759. * Test if this position is before other position.
  5760. * If the two positions are equal, the result will be false.
  5761. */
  5762. isBefore(other) {
  5763. return Position.isBefore(this, other);
  5764. }
  5765. /**
  5766. * Test if position `a` is before position `b`.
  5767. * If the two positions are equal, the result will be false.
  5768. */
  5769. static isBefore(a, b) {
  5770. if (a.lineNumber < b.lineNumber) {
  5771. return true;
  5772. }
  5773. if (b.lineNumber < a.lineNumber) {
  5774. return false;
  5775. }
  5776. return a.column < b.column;
  5777. }
  5778. /**
  5779. * Test if this position is before other position.
  5780. * If the two positions are equal, the result will be true.
  5781. */
  5782. isBeforeOrEqual(other) {
  5783. return Position.isBeforeOrEqual(this, other);
  5784. }
  5785. /**
  5786. * Test if position `a` is before position `b`.
  5787. * If the two positions are equal, the result will be true.
  5788. */
  5789. static isBeforeOrEqual(a, b) {
  5790. if (a.lineNumber < b.lineNumber) {
  5791. return true;
  5792. }
  5793. if (b.lineNumber < a.lineNumber) {
  5794. return false;
  5795. }
  5796. return a.column <= b.column;
  5797. }
  5798. /**
  5799. * A function that compares positions, useful for sorting
  5800. */
  5801. static compare(a, b) {
  5802. const aLineNumber = a.lineNumber | 0;
  5803. const bLineNumber = b.lineNumber | 0;
  5804. if (aLineNumber === bLineNumber) {
  5805. const aColumn = a.column | 0;
  5806. const bColumn = b.column | 0;
  5807. return aColumn - bColumn;
  5808. }
  5809. return aLineNumber - bLineNumber;
  5810. }
  5811. /**
  5812. * Clone this position.
  5813. */
  5814. clone() {
  5815. return new Position(this.lineNumber, this.column);
  5816. }
  5817. /**
  5818. * Convert to a human-readable representation.
  5819. */
  5820. toString() {
  5821. return '(' + this.lineNumber + ',' + this.column + ')';
  5822. }
  5823. // ---
  5824. /**
  5825. * Create a `Position` from an `IPosition`.
  5826. */
  5827. static lift(pos) {
  5828. return new Position(pos.lineNumber, pos.column);
  5829. }
  5830. /**
  5831. * Test if `obj` is an `IPosition`.
  5832. */
  5833. static isIPosition(obj) {
  5834. return (obj
  5835. && (typeof obj.lineNumber === 'number')
  5836. && (typeof obj.column === 'number'));
  5837. }
  5838. toJSON() {
  5839. return {
  5840. lineNumber: this.lineNumber,
  5841. column: this.column
  5842. };
  5843. }
  5844. }
  5845. /*---------------------------------------------------------------------------------------------
  5846. * Copyright (c) Microsoft Corporation. All rights reserved.
  5847. * Licensed under the MIT License. See License.txt in the project root for license information.
  5848. *--------------------------------------------------------------------------------------------*/
  5849. /**
  5850. * A range in the editor. (startLineNumber,startColumn) is <= (endLineNumber,endColumn)
  5851. */
  5852. class Range {
  5853. constructor(startLineNumber, startColumn, endLineNumber, endColumn) {
  5854. if ((startLineNumber > endLineNumber) || (startLineNumber === endLineNumber && startColumn > endColumn)) {
  5855. this.startLineNumber = endLineNumber;
  5856. this.startColumn = endColumn;
  5857. this.endLineNumber = startLineNumber;
  5858. this.endColumn = startColumn;
  5859. }
  5860. else {
  5861. this.startLineNumber = startLineNumber;
  5862. this.startColumn = startColumn;
  5863. this.endLineNumber = endLineNumber;
  5864. this.endColumn = endColumn;
  5865. }
  5866. }
  5867. /**
  5868. * Test if this range is empty.
  5869. */
  5870. isEmpty() {
  5871. return Range.isEmpty(this);
  5872. }
  5873. /**
  5874. * Test if `range` is empty.
  5875. */
  5876. static isEmpty(range) {
  5877. return (range.startLineNumber === range.endLineNumber && range.startColumn === range.endColumn);
  5878. }
  5879. /**
  5880. * Test if position is in this range. If the position is at the edges, will return true.
  5881. */
  5882. containsPosition(position) {
  5883. return Range.containsPosition(this, position);
  5884. }
  5885. /**
  5886. * Test if `position` is in `range`. If the position is at the edges, will return true.
  5887. */
  5888. static containsPosition(range, position) {
  5889. if (position.lineNumber < range.startLineNumber || position.lineNumber > range.endLineNumber) {
  5890. return false;
  5891. }
  5892. if (position.lineNumber === range.startLineNumber && position.column < range.startColumn) {
  5893. return false;
  5894. }
  5895. if (position.lineNumber === range.endLineNumber && position.column > range.endColumn) {
  5896. return false;
  5897. }
  5898. return true;
  5899. }
  5900. /**
  5901. * Test if `position` is in `range`. If the position is at the edges, will return false.
  5902. * @internal
  5903. */
  5904. static strictContainsPosition(range, position) {
  5905. if (position.lineNumber < range.startLineNumber || position.lineNumber > range.endLineNumber) {
  5906. return false;
  5907. }
  5908. if (position.lineNumber === range.startLineNumber && position.column <= range.startColumn) {
  5909. return false;
  5910. }
  5911. if (position.lineNumber === range.endLineNumber && position.column >= range.endColumn) {
  5912. return false;
  5913. }
  5914. return true;
  5915. }
  5916. /**
  5917. * Test if range is in this range. If the range is equal to this range, will return true.
  5918. */
  5919. containsRange(range) {
  5920. return Range.containsRange(this, range);
  5921. }
  5922. /**
  5923. * Test if `otherRange` is in `range`. If the ranges are equal, will return true.
  5924. */
  5925. static containsRange(range, otherRange) {
  5926. if (otherRange.startLineNumber < range.startLineNumber || otherRange.endLineNumber < range.startLineNumber) {
  5927. return false;
  5928. }
  5929. if (otherRange.startLineNumber > range.endLineNumber || otherRange.endLineNumber > range.endLineNumber) {
  5930. return false;
  5931. }
  5932. if (otherRange.startLineNumber === range.startLineNumber && otherRange.startColumn < range.startColumn) {
  5933. return false;
  5934. }
  5935. if (otherRange.endLineNumber === range.endLineNumber && otherRange.endColumn > range.endColumn) {
  5936. return false;
  5937. }
  5938. return true;
  5939. }
  5940. /**
  5941. * Test if `range` is strictly in this range. `range` must start after and end before this range for the result to be true.
  5942. */
  5943. strictContainsRange(range) {
  5944. return Range.strictContainsRange(this, range);
  5945. }
  5946. /**
  5947. * Test if `otherRange` is strictly in `range` (must start after, and end before). If the ranges are equal, will return false.
  5948. */
  5949. static strictContainsRange(range, otherRange) {
  5950. if (otherRange.startLineNumber < range.startLineNumber || otherRange.endLineNumber < range.startLineNumber) {
  5951. return false;
  5952. }
  5953. if (otherRange.startLineNumber > range.endLineNumber || otherRange.endLineNumber > range.endLineNumber) {
  5954. return false;
  5955. }
  5956. if (otherRange.startLineNumber === range.startLineNumber && otherRange.startColumn <= range.startColumn) {
  5957. return false;
  5958. }
  5959. if (otherRange.endLineNumber === range.endLineNumber && otherRange.endColumn >= range.endColumn) {
  5960. return false;
  5961. }
  5962. return true;
  5963. }
  5964. /**
  5965. * A reunion of the two ranges.
  5966. * The smallest position will be used as the start point, and the largest one as the end point.
  5967. */
  5968. plusRange(range) {
  5969. return Range.plusRange(this, range);
  5970. }
  5971. /**
  5972. * A reunion of the two ranges.
  5973. * The smallest position will be used as the start point, and the largest one as the end point.
  5974. */
  5975. static plusRange(a, b) {
  5976. let startLineNumber;
  5977. let startColumn;
  5978. let endLineNumber;
  5979. let endColumn;
  5980. if (b.startLineNumber < a.startLineNumber) {
  5981. startLineNumber = b.startLineNumber;
  5982. startColumn = b.startColumn;
  5983. }
  5984. else if (b.startLineNumber === a.startLineNumber) {
  5985. startLineNumber = b.startLineNumber;
  5986. startColumn = Math.min(b.startColumn, a.startColumn);
  5987. }
  5988. else {
  5989. startLineNumber = a.startLineNumber;
  5990. startColumn = a.startColumn;
  5991. }
  5992. if (b.endLineNumber > a.endLineNumber) {
  5993. endLineNumber = b.endLineNumber;
  5994. endColumn = b.endColumn;
  5995. }
  5996. else if (b.endLineNumber === a.endLineNumber) {
  5997. endLineNumber = b.endLineNumber;
  5998. endColumn = Math.max(b.endColumn, a.endColumn);
  5999. }
  6000. else {
  6001. endLineNumber = a.endLineNumber;
  6002. endColumn = a.endColumn;
  6003. }
  6004. return new Range(startLineNumber, startColumn, endLineNumber, endColumn);
  6005. }
  6006. /**
  6007. * A intersection of the two ranges.
  6008. */
  6009. intersectRanges(range) {
  6010. return Range.intersectRanges(this, range);
  6011. }
  6012. /**
  6013. * A intersection of the two ranges.
  6014. */
  6015. static intersectRanges(a, b) {
  6016. let resultStartLineNumber = a.startLineNumber;
  6017. let resultStartColumn = a.startColumn;
  6018. let resultEndLineNumber = a.endLineNumber;
  6019. let resultEndColumn = a.endColumn;
  6020. const otherStartLineNumber = b.startLineNumber;
  6021. const otherStartColumn = b.startColumn;
  6022. const otherEndLineNumber = b.endLineNumber;
  6023. const otherEndColumn = b.endColumn;
  6024. if (resultStartLineNumber < otherStartLineNumber) {
  6025. resultStartLineNumber = otherStartLineNumber;
  6026. resultStartColumn = otherStartColumn;
  6027. }
  6028. else if (resultStartLineNumber === otherStartLineNumber) {
  6029. resultStartColumn = Math.max(resultStartColumn, otherStartColumn);
  6030. }
  6031. if (resultEndLineNumber > otherEndLineNumber) {
  6032. resultEndLineNumber = otherEndLineNumber;
  6033. resultEndColumn = otherEndColumn;
  6034. }
  6035. else if (resultEndLineNumber === otherEndLineNumber) {
  6036. resultEndColumn = Math.min(resultEndColumn, otherEndColumn);
  6037. }
  6038. // Check if selection is now empty
  6039. if (resultStartLineNumber > resultEndLineNumber) {
  6040. return null;
  6041. }
  6042. if (resultStartLineNumber === resultEndLineNumber && resultStartColumn > resultEndColumn) {
  6043. return null;
  6044. }
  6045. return new Range(resultStartLineNumber, resultStartColumn, resultEndLineNumber, resultEndColumn);
  6046. }
  6047. /**
  6048. * Test if this range equals other.
  6049. */
  6050. equalsRange(other) {
  6051. return Range.equalsRange(this, other);
  6052. }
  6053. /**
  6054. * Test if range `a` equals `b`.
  6055. */
  6056. static equalsRange(a, b) {
  6057. if (!a && !b) {
  6058. return true;
  6059. }
  6060. return (!!a &&
  6061. !!b &&
  6062. a.startLineNumber === b.startLineNumber &&
  6063. a.startColumn === b.startColumn &&
  6064. a.endLineNumber === b.endLineNumber &&
  6065. a.endColumn === b.endColumn);
  6066. }
  6067. /**
  6068. * Return the end position (which will be after or equal to the start position)
  6069. */
  6070. getEndPosition() {
  6071. return Range.getEndPosition(this);
  6072. }
  6073. /**
  6074. * Return the end position (which will be after or equal to the start position)
  6075. */
  6076. static getEndPosition(range) {
  6077. return new Position(range.endLineNumber, range.endColumn);
  6078. }
  6079. /**
  6080. * Return the start position (which will be before or equal to the end position)
  6081. */
  6082. getStartPosition() {
  6083. return Range.getStartPosition(this);
  6084. }
  6085. /**
  6086. * Return the start position (which will be before or equal to the end position)
  6087. */
  6088. static getStartPosition(range) {
  6089. return new Position(range.startLineNumber, range.startColumn);
  6090. }
  6091. /**
  6092. * Transform to a user presentable string representation.
  6093. */
  6094. toString() {
  6095. return '[' + this.startLineNumber + ',' + this.startColumn + ' -> ' + this.endLineNumber + ',' + this.endColumn + ']';
  6096. }
  6097. /**
  6098. * Create a new range using this range's start position, and using endLineNumber and endColumn as the end position.
  6099. */
  6100. setEndPosition(endLineNumber, endColumn) {
  6101. return new Range(this.startLineNumber, this.startColumn, endLineNumber, endColumn);
  6102. }
  6103. /**
  6104. * Create a new range using this range's end position, and using startLineNumber and startColumn as the start position.
  6105. */
  6106. setStartPosition(startLineNumber, startColumn) {
  6107. return new Range(startLineNumber, startColumn, this.endLineNumber, this.endColumn);
  6108. }
  6109. /**
  6110. * Create a new empty range using this range's start position.
  6111. */
  6112. collapseToStart() {
  6113. return Range.collapseToStart(this);
  6114. }
  6115. /**
  6116. * Create a new empty range using this range's start position.
  6117. */
  6118. static collapseToStart(range) {
  6119. return new Range(range.startLineNumber, range.startColumn, range.startLineNumber, range.startColumn);
  6120. }
  6121. /**
  6122. * Create a new empty range using this range's end position.
  6123. */
  6124. collapseToEnd() {
  6125. return Range.collapseToEnd(this);
  6126. }
  6127. /**
  6128. * Create a new empty range using this range's end position.
  6129. */
  6130. static collapseToEnd(range) {
  6131. return new Range(range.endLineNumber, range.endColumn, range.endLineNumber, range.endColumn);
  6132. }
  6133. /**
  6134. * Moves the range by the given amount of lines.
  6135. */
  6136. delta(lineCount) {
  6137. return new Range(this.startLineNumber + lineCount, this.startColumn, this.endLineNumber + lineCount, this.endColumn);
  6138. }
  6139. // ---
  6140. static fromPositions(start, end = start) {
  6141. return new Range(start.lineNumber, start.column, end.lineNumber, end.column);
  6142. }
  6143. static lift(range) {
  6144. if (!range) {
  6145. return null;
  6146. }
  6147. return new Range(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn);
  6148. }
  6149. /**
  6150. * Test if `obj` is an `IRange`.
  6151. */
  6152. static isIRange(obj) {
  6153. return (obj
  6154. && (typeof obj.startLineNumber === 'number')
  6155. && (typeof obj.startColumn === 'number')
  6156. && (typeof obj.endLineNumber === 'number')
  6157. && (typeof obj.endColumn === 'number'));
  6158. }
  6159. /**
  6160. * Test if the two ranges are touching in any way.
  6161. */
  6162. static areIntersectingOrTouching(a, b) {
  6163. // Check if `a` is before `b`
  6164. if (a.endLineNumber < b.startLineNumber || (a.endLineNumber === b.startLineNumber && a.endColumn < b.startColumn)) {
  6165. return false;
  6166. }
  6167. // Check if `b` is before `a`
  6168. if (b.endLineNumber < a.startLineNumber || (b.endLineNumber === a.startLineNumber && b.endColumn < a.startColumn)) {
  6169. return false;
  6170. }
  6171. // These ranges must intersect
  6172. return true;
  6173. }
  6174. /**
  6175. * Test if the two ranges are intersecting. If the ranges are touching it returns true.
  6176. */
  6177. static areIntersecting(a, b) {
  6178. // Check if `a` is before `b`
  6179. if (a.endLineNumber < b.startLineNumber || (a.endLineNumber === b.startLineNumber && a.endColumn <= b.startColumn)) {
  6180. return false;
  6181. }
  6182. // Check if `b` is before `a`
  6183. if (b.endLineNumber < a.startLineNumber || (b.endLineNumber === a.startLineNumber && b.endColumn <= a.startColumn)) {
  6184. return false;
  6185. }
  6186. // These ranges must intersect
  6187. return true;
  6188. }
  6189. /**
  6190. * A function that compares ranges, useful for sorting ranges
  6191. * It will first compare ranges on the startPosition and then on the endPosition
  6192. */
  6193. static compareRangesUsingStarts(a, b) {
  6194. if (a && b) {
  6195. const aStartLineNumber = a.startLineNumber | 0;
  6196. const bStartLineNumber = b.startLineNumber | 0;
  6197. if (aStartLineNumber === bStartLineNumber) {
  6198. const aStartColumn = a.startColumn | 0;
  6199. const bStartColumn = b.startColumn | 0;
  6200. if (aStartColumn === bStartColumn) {
  6201. const aEndLineNumber = a.endLineNumber | 0;
  6202. const bEndLineNumber = b.endLineNumber | 0;
  6203. if (aEndLineNumber === bEndLineNumber) {
  6204. const aEndColumn = a.endColumn | 0;
  6205. const bEndColumn = b.endColumn | 0;
  6206. return aEndColumn - bEndColumn;
  6207. }
  6208. return aEndLineNumber - bEndLineNumber;
  6209. }
  6210. return aStartColumn - bStartColumn;
  6211. }
  6212. return aStartLineNumber - bStartLineNumber;
  6213. }
  6214. const aExists = (a ? 1 : 0);
  6215. const bExists = (b ? 1 : 0);
  6216. return aExists - bExists;
  6217. }
  6218. /**
  6219. * A function that compares ranges, useful for sorting ranges
  6220. * It will first compare ranges on the endPosition and then on the startPosition
  6221. */
  6222. static compareRangesUsingEnds(a, b) {
  6223. if (a.endLineNumber === b.endLineNumber) {
  6224. if (a.endColumn === b.endColumn) {
  6225. if (a.startLineNumber === b.startLineNumber) {
  6226. return a.startColumn - b.startColumn;
  6227. }
  6228. return a.startLineNumber - b.startLineNumber;
  6229. }
  6230. return a.endColumn - b.endColumn;
  6231. }
  6232. return a.endLineNumber - b.endLineNumber;
  6233. }
  6234. /**
  6235. * Test if the range spans multiple lines.
  6236. */
  6237. static spansMultipleLines(range) {
  6238. return range.endLineNumber > range.startLineNumber;
  6239. }
  6240. toJSON() {
  6241. return this;
  6242. }
  6243. }
  6244. /*---------------------------------------------------------------------------------------------
  6245. * Copyright (c) Microsoft Corporation. All rights reserved.
  6246. * Licensed under the MIT License. See License.txt in the project root for license information.
  6247. *--------------------------------------------------------------------------------------------*/
  6248. function toUint8(v) {
  6249. if (v < 0) {
  6250. return 0;
  6251. }
  6252. if (v > 255 /* Constants.MAX_UINT_8 */) {
  6253. return 255 /* Constants.MAX_UINT_8 */;
  6254. }
  6255. return v | 0;
  6256. }
  6257. function toUint32(v) {
  6258. if (v < 0) {
  6259. return 0;
  6260. }
  6261. if (v > 4294967295 /* Constants.MAX_UINT_32 */) {
  6262. return 4294967295 /* Constants.MAX_UINT_32 */;
  6263. }
  6264. return v | 0;
  6265. }
  6266. /*---------------------------------------------------------------------------------------------
  6267. * Copyright (c) Microsoft Corporation. All rights reserved.
  6268. * Licensed under the MIT License. See License.txt in the project root for license information.
  6269. *--------------------------------------------------------------------------------------------*/
  6270. /**
  6271. * A fast character classifier that uses a compact array for ASCII values.
  6272. */
  6273. class CharacterClassifier {
  6274. constructor(_defaultValue) {
  6275. const defaultValue = toUint8(_defaultValue);
  6276. this._defaultValue = defaultValue;
  6277. this._asciiMap = CharacterClassifier._createAsciiMap(defaultValue);
  6278. this._map = new Map();
  6279. }
  6280. static _createAsciiMap(defaultValue) {
  6281. const asciiMap = new Uint8Array(256);
  6282. asciiMap.fill(defaultValue);
  6283. return asciiMap;
  6284. }
  6285. set(charCode, _value) {
  6286. const value = toUint8(_value);
  6287. if (charCode >= 0 && charCode < 256) {
  6288. this._asciiMap[charCode] = value;
  6289. }
  6290. else {
  6291. this._map.set(charCode, value);
  6292. }
  6293. }
  6294. get(charCode) {
  6295. if (charCode >= 0 && charCode < 256) {
  6296. return this._asciiMap[charCode];
  6297. }
  6298. else {
  6299. return (this._map.get(charCode) || this._defaultValue);
  6300. }
  6301. }
  6302. clear() {
  6303. this._asciiMap.fill(this._defaultValue);
  6304. this._map.clear();
  6305. }
  6306. }
  6307. /*---------------------------------------------------------------------------------------------
  6308. * Copyright (c) Microsoft Corporation. All rights reserved.
  6309. * Licensed under the MIT License. See License.txt in the project root for license information.
  6310. *--------------------------------------------------------------------------------------------*/
  6311. class Uint8Matrix {
  6312. constructor(rows, cols, defaultValue) {
  6313. const data = new Uint8Array(rows * cols);
  6314. for (let i = 0, len = rows * cols; i < len; i++) {
  6315. data[i] = defaultValue;
  6316. }
  6317. this._data = data;
  6318. this.rows = rows;
  6319. this.cols = cols;
  6320. }
  6321. get(row, col) {
  6322. return this._data[row * this.cols + col];
  6323. }
  6324. set(row, col, value) {
  6325. this._data[row * this.cols + col] = value;
  6326. }
  6327. }
  6328. class StateMachine {
  6329. constructor(edges) {
  6330. let maxCharCode = 0;
  6331. let maxState = 0 /* State.Invalid */;
  6332. for (let i = 0, len = edges.length; i < len; i++) {
  6333. const [from, chCode, to] = edges[i];
  6334. if (chCode > maxCharCode) {
  6335. maxCharCode = chCode;
  6336. }
  6337. if (from > maxState) {
  6338. maxState = from;
  6339. }
  6340. if (to > maxState) {
  6341. maxState = to;
  6342. }
  6343. }
  6344. maxCharCode++;
  6345. maxState++;
  6346. const states = new Uint8Matrix(maxState, maxCharCode, 0 /* State.Invalid */);
  6347. for (let i = 0, len = edges.length; i < len; i++) {
  6348. const [from, chCode, to] = edges[i];
  6349. states.set(from, chCode, to);
  6350. }
  6351. this._states = states;
  6352. this._maxCharCode = maxCharCode;
  6353. }
  6354. nextState(currentState, chCode) {
  6355. if (chCode < 0 || chCode >= this._maxCharCode) {
  6356. return 0 /* State.Invalid */;
  6357. }
  6358. return this._states.get(currentState, chCode);
  6359. }
  6360. }
  6361. // State machine for http:// or https:// or file://
  6362. let _stateMachine = null;
  6363. function getStateMachine() {
  6364. if (_stateMachine === null) {
  6365. _stateMachine = new StateMachine([
  6366. [1 /* State.Start */, 104 /* CharCode.h */, 2 /* State.H */],
  6367. [1 /* State.Start */, 72 /* CharCode.H */, 2 /* State.H */],
  6368. [1 /* State.Start */, 102 /* CharCode.f */, 6 /* State.F */],
  6369. [1 /* State.Start */, 70 /* CharCode.F */, 6 /* State.F */],
  6370. [2 /* State.H */, 116 /* CharCode.t */, 3 /* State.HT */],
  6371. [2 /* State.H */, 84 /* CharCode.T */, 3 /* State.HT */],
  6372. [3 /* State.HT */, 116 /* CharCode.t */, 4 /* State.HTT */],
  6373. [3 /* State.HT */, 84 /* CharCode.T */, 4 /* State.HTT */],
  6374. [4 /* State.HTT */, 112 /* CharCode.p */, 5 /* State.HTTP */],
  6375. [4 /* State.HTT */, 80 /* CharCode.P */, 5 /* State.HTTP */],
  6376. [5 /* State.HTTP */, 115 /* CharCode.s */, 9 /* State.BeforeColon */],
  6377. [5 /* State.HTTP */, 83 /* CharCode.S */, 9 /* State.BeforeColon */],
  6378. [5 /* State.HTTP */, 58 /* CharCode.Colon */, 10 /* State.AfterColon */],
  6379. [6 /* State.F */, 105 /* CharCode.i */, 7 /* State.FI */],
  6380. [6 /* State.F */, 73 /* CharCode.I */, 7 /* State.FI */],
  6381. [7 /* State.FI */, 108 /* CharCode.l */, 8 /* State.FIL */],
  6382. [7 /* State.FI */, 76 /* CharCode.L */, 8 /* State.FIL */],
  6383. [8 /* State.FIL */, 101 /* CharCode.e */, 9 /* State.BeforeColon */],
  6384. [8 /* State.FIL */, 69 /* CharCode.E */, 9 /* State.BeforeColon */],
  6385. [9 /* State.BeforeColon */, 58 /* CharCode.Colon */, 10 /* State.AfterColon */],
  6386. [10 /* State.AfterColon */, 47 /* CharCode.Slash */, 11 /* State.AlmostThere */],
  6387. [11 /* State.AlmostThere */, 47 /* CharCode.Slash */, 12 /* State.End */],
  6388. ]);
  6389. }
  6390. return _stateMachine;
  6391. }
  6392. let _classifier = null;
  6393. function getClassifier() {
  6394. if (_classifier === null) {
  6395. _classifier = new CharacterClassifier(0 /* CharacterClass.None */);
  6396. // allow-any-unicode-next-line
  6397. const FORCE_TERMINATION_CHARACTERS = ' \t<>\'\"、。。、,.:;‘〈「『〔([{「」}])〕』」〉’`~…';
  6398. for (let i = 0; i < FORCE_TERMINATION_CHARACTERS.length; i++) {
  6399. _classifier.set(FORCE_TERMINATION_CHARACTERS.charCodeAt(i), 1 /* CharacterClass.ForceTermination */);
  6400. }
  6401. const CANNOT_END_WITH_CHARACTERS = '.,;:';
  6402. for (let i = 0; i < CANNOT_END_WITH_CHARACTERS.length; i++) {
  6403. _classifier.set(CANNOT_END_WITH_CHARACTERS.charCodeAt(i), 2 /* CharacterClass.CannotEndIn */);
  6404. }
  6405. }
  6406. return _classifier;
  6407. }
  6408. class LinkComputer {
  6409. static _createLink(classifier, line, lineNumber, linkBeginIndex, linkEndIndex) {
  6410. // Do not allow to end link in certain characters...
  6411. let lastIncludedCharIndex = linkEndIndex - 1;
  6412. do {
  6413. const chCode = line.charCodeAt(lastIncludedCharIndex);
  6414. const chClass = classifier.get(chCode);
  6415. if (chClass !== 2 /* CharacterClass.CannotEndIn */) {
  6416. break;
  6417. }
  6418. lastIncludedCharIndex--;
  6419. } while (lastIncludedCharIndex > linkBeginIndex);
  6420. // Handle links enclosed in parens, square brackets and curlys.
  6421. if (linkBeginIndex > 0) {
  6422. const charCodeBeforeLink = line.charCodeAt(linkBeginIndex - 1);
  6423. const lastCharCodeInLink = line.charCodeAt(lastIncludedCharIndex);
  6424. if ((charCodeBeforeLink === 40 /* CharCode.OpenParen */ && lastCharCodeInLink === 41 /* CharCode.CloseParen */)
  6425. || (charCodeBeforeLink === 91 /* CharCode.OpenSquareBracket */ && lastCharCodeInLink === 93 /* CharCode.CloseSquareBracket */)
  6426. || (charCodeBeforeLink === 123 /* CharCode.OpenCurlyBrace */ && lastCharCodeInLink === 125 /* CharCode.CloseCurlyBrace */)) {
  6427. // Do not end in ) if ( is before the link start
  6428. // Do not end in ] if [ is before the link start
  6429. // Do not end in } if { is before the link start
  6430. lastIncludedCharIndex--;
  6431. }
  6432. }
  6433. return {
  6434. range: {
  6435. startLineNumber: lineNumber,
  6436. startColumn: linkBeginIndex + 1,
  6437. endLineNumber: lineNumber,
  6438. endColumn: lastIncludedCharIndex + 2
  6439. },
  6440. url: line.substring(linkBeginIndex, lastIncludedCharIndex + 1)
  6441. };
  6442. }
  6443. static computeLinks(model, stateMachine = getStateMachine()) {
  6444. const classifier = getClassifier();
  6445. const result = [];
  6446. for (let i = 1, lineCount = model.getLineCount(); i <= lineCount; i++) {
  6447. const line = model.getLineContent(i);
  6448. const len = line.length;
  6449. let j = 0;
  6450. let linkBeginIndex = 0;
  6451. let linkBeginChCode = 0;
  6452. let state = 1 /* State.Start */;
  6453. let hasOpenParens = false;
  6454. let hasOpenSquareBracket = false;
  6455. let inSquareBrackets = false;
  6456. let hasOpenCurlyBracket = false;
  6457. while (j < len) {
  6458. let resetStateMachine = false;
  6459. const chCode = line.charCodeAt(j);
  6460. if (state === 13 /* State.Accept */) {
  6461. let chClass;
  6462. switch (chCode) {
  6463. case 40 /* CharCode.OpenParen */:
  6464. hasOpenParens = true;
  6465. chClass = 0 /* CharacterClass.None */;
  6466. break;
  6467. case 41 /* CharCode.CloseParen */:
  6468. chClass = (hasOpenParens ? 0 /* CharacterClass.None */ : 1 /* CharacterClass.ForceTermination */);
  6469. break;
  6470. case 91 /* CharCode.OpenSquareBracket */:
  6471. inSquareBrackets = true;
  6472. hasOpenSquareBracket = true;
  6473. chClass = 0 /* CharacterClass.None */;
  6474. break;
  6475. case 93 /* CharCode.CloseSquareBracket */:
  6476. inSquareBrackets = false;
  6477. chClass = (hasOpenSquareBracket ? 0 /* CharacterClass.None */ : 1 /* CharacterClass.ForceTermination */);
  6478. break;
  6479. case 123 /* CharCode.OpenCurlyBrace */:
  6480. hasOpenCurlyBracket = true;
  6481. chClass = 0 /* CharacterClass.None */;
  6482. break;
  6483. case 125 /* CharCode.CloseCurlyBrace */:
  6484. chClass = (hasOpenCurlyBracket ? 0 /* CharacterClass.None */ : 1 /* CharacterClass.ForceTermination */);
  6485. break;
  6486. // The following three rules make it that ' or " or ` are allowed inside links
  6487. // only if the link is wrapped by some other quote character
  6488. case 39 /* CharCode.SingleQuote */:
  6489. case 34 /* CharCode.DoubleQuote */:
  6490. case 96 /* CharCode.BackTick */:
  6491. if (linkBeginChCode === chCode) {
  6492. chClass = 1 /* CharacterClass.ForceTermination */;
  6493. }
  6494. else if (linkBeginChCode === 39 /* CharCode.SingleQuote */ || linkBeginChCode === 34 /* CharCode.DoubleQuote */ || linkBeginChCode === 96 /* CharCode.BackTick */) {
  6495. chClass = 0 /* CharacterClass.None */;
  6496. }
  6497. else {
  6498. chClass = 1 /* CharacterClass.ForceTermination */;
  6499. }
  6500. break;
  6501. case 42 /* CharCode.Asterisk */:
  6502. // `*` terminates a link if the link began with `*`
  6503. chClass = (linkBeginChCode === 42 /* CharCode.Asterisk */) ? 1 /* CharacterClass.ForceTermination */ : 0 /* CharacterClass.None */;
  6504. break;
  6505. case 124 /* CharCode.Pipe */:
  6506. // `|` terminates a link if the link began with `|`
  6507. chClass = (linkBeginChCode === 124 /* CharCode.Pipe */) ? 1 /* CharacterClass.ForceTermination */ : 0 /* CharacterClass.None */;
  6508. break;
  6509. case 32 /* CharCode.Space */:
  6510. // ` ` allow space in between [ and ]
  6511. chClass = (inSquareBrackets ? 0 /* CharacterClass.None */ : 1 /* CharacterClass.ForceTermination */);
  6512. break;
  6513. default:
  6514. chClass = classifier.get(chCode);
  6515. }
  6516. // Check if character terminates link
  6517. if (chClass === 1 /* CharacterClass.ForceTermination */) {
  6518. result.push(LinkComputer._createLink(classifier, line, i, linkBeginIndex, j));
  6519. resetStateMachine = true;
  6520. }
  6521. }
  6522. else if (state === 12 /* State.End */) {
  6523. let chClass;
  6524. if (chCode === 91 /* CharCode.OpenSquareBracket */) {
  6525. // Allow for the authority part to contain ipv6 addresses which contain [ and ]
  6526. hasOpenSquareBracket = true;
  6527. chClass = 0 /* CharacterClass.None */;
  6528. }
  6529. else {
  6530. chClass = classifier.get(chCode);
  6531. }
  6532. // Check if character terminates link
  6533. if (chClass === 1 /* CharacterClass.ForceTermination */) {
  6534. resetStateMachine = true;
  6535. }
  6536. else {
  6537. state = 13 /* State.Accept */;
  6538. }
  6539. }
  6540. else {
  6541. state = stateMachine.nextState(state, chCode);
  6542. if (state === 0 /* State.Invalid */) {
  6543. resetStateMachine = true;
  6544. }
  6545. }
  6546. if (resetStateMachine) {
  6547. state = 1 /* State.Start */;
  6548. hasOpenParens = false;
  6549. hasOpenSquareBracket = false;
  6550. hasOpenCurlyBracket = false;
  6551. // Record where the link started
  6552. linkBeginIndex = j + 1;
  6553. linkBeginChCode = chCode;
  6554. }
  6555. j++;
  6556. }
  6557. if (state === 13 /* State.Accept */) {
  6558. result.push(LinkComputer._createLink(classifier, line, i, linkBeginIndex, len));
  6559. }
  6560. }
  6561. return result;
  6562. }
  6563. }
  6564. /**
  6565. * Returns an array of all links contains in the provided
  6566. * document. *Note* that this operation is computational
  6567. * expensive and should not run in the UI thread.
  6568. */
  6569. function computeLinks(model) {
  6570. if (!model || typeof model.getLineCount !== 'function' || typeof model.getLineContent !== 'function') {
  6571. // Unknown caller!
  6572. return [];
  6573. }
  6574. return LinkComputer.computeLinks(model);
  6575. }
  6576. /*---------------------------------------------------------------------------------------------
  6577. * Copyright (c) Microsoft Corporation. All rights reserved.
  6578. * Licensed under the MIT License. See License.txt in the project root for license information.
  6579. *--------------------------------------------------------------------------------------------*/
  6580. class BasicInplaceReplace {
  6581. constructor() {
  6582. this._defaultValueSet = [
  6583. ['true', 'false'],
  6584. ['True', 'False'],
  6585. ['Private', 'Public', 'Friend', 'ReadOnly', 'Partial', 'Protected', 'WriteOnly'],
  6586. ['public', 'protected', 'private'],
  6587. ];
  6588. }
  6589. static { this.INSTANCE = new BasicInplaceReplace(); }
  6590. navigateValueSet(range1, text1, range2, text2, up) {
  6591. if (range1 && text1) {
  6592. const result = this.doNavigateValueSet(text1, up);
  6593. if (result) {
  6594. return {
  6595. range: range1,
  6596. value: result
  6597. };
  6598. }
  6599. }
  6600. if (range2 && text2) {
  6601. const result = this.doNavigateValueSet(text2, up);
  6602. if (result) {
  6603. return {
  6604. range: range2,
  6605. value: result
  6606. };
  6607. }
  6608. }
  6609. return null;
  6610. }
  6611. doNavigateValueSet(text, up) {
  6612. const numberResult = this.numberReplace(text, up);
  6613. if (numberResult !== null) {
  6614. return numberResult;
  6615. }
  6616. return this.textReplace(text, up);
  6617. }
  6618. numberReplace(value, up) {
  6619. const precision = Math.pow(10, value.length - (value.lastIndexOf('.') + 1));
  6620. let n1 = Number(value);
  6621. const n2 = parseFloat(value);
  6622. if (!isNaN(n1) && !isNaN(n2) && n1 === n2) {
  6623. if (n1 === 0 && !up) {
  6624. return null; // don't do negative
  6625. // } else if(n1 === 9 && up) {
  6626. // return null; // don't insert 10 into a number
  6627. }
  6628. else {
  6629. n1 = Math.floor(n1 * precision);
  6630. n1 += up ? precision : -precision;
  6631. return String(n1 / precision);
  6632. }
  6633. }
  6634. return null;
  6635. }
  6636. textReplace(value, up) {
  6637. return this.valueSetsReplace(this._defaultValueSet, value, up);
  6638. }
  6639. valueSetsReplace(valueSets, value, up) {
  6640. let result = null;
  6641. for (let i = 0, len = valueSets.length; result === null && i < len; i++) {
  6642. result = this.valueSetReplace(valueSets[i], value, up);
  6643. }
  6644. return result;
  6645. }
  6646. valueSetReplace(valueSet, value, up) {
  6647. let idx = valueSet.indexOf(value);
  6648. if (idx >= 0) {
  6649. idx += up ? +1 : -1;
  6650. if (idx < 0) {
  6651. idx = valueSet.length - 1;
  6652. }
  6653. else {
  6654. idx %= valueSet.length;
  6655. }
  6656. return valueSet[idx];
  6657. }
  6658. return null;
  6659. }
  6660. }
  6661. /*---------------------------------------------------------------------------------------------
  6662. * Copyright (c) Microsoft Corporation. All rights reserved.
  6663. * Licensed under the MIT License. See License.txt in the project root for license information.
  6664. *--------------------------------------------------------------------------------------------*/
  6665. const shortcutEvent = Object.freeze(function (callback, context) {
  6666. const handle = setTimeout(callback.bind(context), 0);
  6667. return { dispose() { clearTimeout(handle); } };
  6668. });
  6669. var CancellationToken;
  6670. (function (CancellationToken) {
  6671. function isCancellationToken(thing) {
  6672. if (thing === CancellationToken.None || thing === CancellationToken.Cancelled) {
  6673. return true;
  6674. }
  6675. if (thing instanceof MutableToken) {
  6676. return true;
  6677. }
  6678. if (!thing || typeof thing !== 'object') {
  6679. return false;
  6680. }
  6681. return typeof thing.isCancellationRequested === 'boolean'
  6682. && typeof thing.onCancellationRequested === 'function';
  6683. }
  6684. CancellationToken.isCancellationToken = isCancellationToken;
  6685. CancellationToken.None = Object.freeze({
  6686. isCancellationRequested: false,
  6687. onCancellationRequested: Event.None
  6688. });
  6689. CancellationToken.Cancelled = Object.freeze({
  6690. isCancellationRequested: true,
  6691. onCancellationRequested: shortcutEvent
  6692. });
  6693. })(CancellationToken || (CancellationToken = {}));
  6694. class MutableToken {
  6695. constructor() {
  6696. this._isCancelled = false;
  6697. this._emitter = null;
  6698. }
  6699. cancel() {
  6700. if (!this._isCancelled) {
  6701. this._isCancelled = true;
  6702. if (this._emitter) {
  6703. this._emitter.fire(undefined);
  6704. this.dispose();
  6705. }
  6706. }
  6707. }
  6708. get isCancellationRequested() {
  6709. return this._isCancelled;
  6710. }
  6711. get onCancellationRequested() {
  6712. if (this._isCancelled) {
  6713. return shortcutEvent;
  6714. }
  6715. if (!this._emitter) {
  6716. this._emitter = new Emitter();
  6717. }
  6718. return this._emitter.event;
  6719. }
  6720. dispose() {
  6721. if (this._emitter) {
  6722. this._emitter.dispose();
  6723. this._emitter = null;
  6724. }
  6725. }
  6726. }
  6727. class CancellationTokenSource {
  6728. constructor(parent) {
  6729. this._token = undefined;
  6730. this._parentListener = undefined;
  6731. this._parentListener = parent && parent.onCancellationRequested(this.cancel, this);
  6732. }
  6733. get token() {
  6734. if (!this._token) {
  6735. // be lazy and create the token only when
  6736. // actually needed
  6737. this._token = new MutableToken();
  6738. }
  6739. return this._token;
  6740. }
  6741. cancel() {
  6742. if (!this._token) {
  6743. // save an object by returning the default
  6744. // cancelled token when cancellation happens
  6745. // before someone asks for the token
  6746. this._token = CancellationToken.Cancelled;
  6747. }
  6748. else if (this._token instanceof MutableToken) {
  6749. // actually cancel
  6750. this._token.cancel();
  6751. }
  6752. }
  6753. dispose(cancel = false) {
  6754. if (cancel) {
  6755. this.cancel();
  6756. }
  6757. this._parentListener?.dispose();
  6758. if (!this._token) {
  6759. // ensure to initialize with an empty token if we had none
  6760. this._token = CancellationToken.None;
  6761. }
  6762. else if (this._token instanceof MutableToken) {
  6763. // actually dispose
  6764. this._token.dispose();
  6765. }
  6766. }
  6767. }
  6768. /*---------------------------------------------------------------------------------------------
  6769. * Copyright (c) Microsoft Corporation. All rights reserved.
  6770. * Licensed under the MIT License. See License.txt in the project root for license information.
  6771. *--------------------------------------------------------------------------------------------*/
  6772. class KeyCodeStrMap {
  6773. constructor() {
  6774. this._keyCodeToStr = [];
  6775. this._strToKeyCode = Object.create(null);
  6776. }
  6777. define(keyCode, str) {
  6778. this._keyCodeToStr[keyCode] = str;
  6779. this._strToKeyCode[str.toLowerCase()] = keyCode;
  6780. }
  6781. keyCodeToStr(keyCode) {
  6782. return this._keyCodeToStr[keyCode];
  6783. }
  6784. strToKeyCode(str) {
  6785. return this._strToKeyCode[str.toLowerCase()] || 0 /* KeyCode.Unknown */;
  6786. }
  6787. }
  6788. const uiMap = new KeyCodeStrMap();
  6789. const userSettingsUSMap = new KeyCodeStrMap();
  6790. const userSettingsGeneralMap = new KeyCodeStrMap();
  6791. const EVENT_KEY_CODE_MAP = new Array(230);
  6792. const scanCodeStrToInt = Object.create(null);
  6793. const scanCodeLowerCaseStrToInt = Object.create(null);
  6794. (function () {
  6795. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
  6796. // See https://github.com/microsoft/node-native-keymap/blob/88c0b0e5/deps/chromium/keyboard_codes_win.h
  6797. const empty = '';
  6798. const mappings = [
  6799. // immutable, scanCode, scanCodeStr, keyCode, keyCodeStr, eventKeyCode, vkey, usUserSettingsLabel, generalUserSettingsLabel
  6800. [1, 0 /* ScanCode.None */, 'None', 0 /* KeyCode.Unknown */, 'unknown', 0, 'VK_UNKNOWN', empty, empty],
  6801. [1, 1 /* ScanCode.Hyper */, 'Hyper', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6802. [1, 2 /* ScanCode.Super */, 'Super', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6803. [1, 3 /* ScanCode.Fn */, 'Fn', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6804. [1, 4 /* ScanCode.FnLock */, 'FnLock', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6805. [1, 5 /* ScanCode.Suspend */, 'Suspend', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6806. [1, 6 /* ScanCode.Resume */, 'Resume', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6807. [1, 7 /* ScanCode.Turbo */, 'Turbo', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6808. [1, 8 /* ScanCode.Sleep */, 'Sleep', 0 /* KeyCode.Unknown */, empty, 0, 'VK_SLEEP', empty, empty],
  6809. [1, 9 /* ScanCode.WakeUp */, 'WakeUp', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6810. [0, 10 /* ScanCode.KeyA */, 'KeyA', 31 /* KeyCode.KeyA */, 'A', 65, 'VK_A', empty, empty],
  6811. [0, 11 /* ScanCode.KeyB */, 'KeyB', 32 /* KeyCode.KeyB */, 'B', 66, 'VK_B', empty, empty],
  6812. [0, 12 /* ScanCode.KeyC */, 'KeyC', 33 /* KeyCode.KeyC */, 'C', 67, 'VK_C', empty, empty],
  6813. [0, 13 /* ScanCode.KeyD */, 'KeyD', 34 /* KeyCode.KeyD */, 'D', 68, 'VK_D', empty, empty],
  6814. [0, 14 /* ScanCode.KeyE */, 'KeyE', 35 /* KeyCode.KeyE */, 'E', 69, 'VK_E', empty, empty],
  6815. [0, 15 /* ScanCode.KeyF */, 'KeyF', 36 /* KeyCode.KeyF */, 'F', 70, 'VK_F', empty, empty],
  6816. [0, 16 /* ScanCode.KeyG */, 'KeyG', 37 /* KeyCode.KeyG */, 'G', 71, 'VK_G', empty, empty],
  6817. [0, 17 /* ScanCode.KeyH */, 'KeyH', 38 /* KeyCode.KeyH */, 'H', 72, 'VK_H', empty, empty],
  6818. [0, 18 /* ScanCode.KeyI */, 'KeyI', 39 /* KeyCode.KeyI */, 'I', 73, 'VK_I', empty, empty],
  6819. [0, 19 /* ScanCode.KeyJ */, 'KeyJ', 40 /* KeyCode.KeyJ */, 'J', 74, 'VK_J', empty, empty],
  6820. [0, 20 /* ScanCode.KeyK */, 'KeyK', 41 /* KeyCode.KeyK */, 'K', 75, 'VK_K', empty, empty],
  6821. [0, 21 /* ScanCode.KeyL */, 'KeyL', 42 /* KeyCode.KeyL */, 'L', 76, 'VK_L', empty, empty],
  6822. [0, 22 /* ScanCode.KeyM */, 'KeyM', 43 /* KeyCode.KeyM */, 'M', 77, 'VK_M', empty, empty],
  6823. [0, 23 /* ScanCode.KeyN */, 'KeyN', 44 /* KeyCode.KeyN */, 'N', 78, 'VK_N', empty, empty],
  6824. [0, 24 /* ScanCode.KeyO */, 'KeyO', 45 /* KeyCode.KeyO */, 'O', 79, 'VK_O', empty, empty],
  6825. [0, 25 /* ScanCode.KeyP */, 'KeyP', 46 /* KeyCode.KeyP */, 'P', 80, 'VK_P', empty, empty],
  6826. [0, 26 /* ScanCode.KeyQ */, 'KeyQ', 47 /* KeyCode.KeyQ */, 'Q', 81, 'VK_Q', empty, empty],
  6827. [0, 27 /* ScanCode.KeyR */, 'KeyR', 48 /* KeyCode.KeyR */, 'R', 82, 'VK_R', empty, empty],
  6828. [0, 28 /* ScanCode.KeyS */, 'KeyS', 49 /* KeyCode.KeyS */, 'S', 83, 'VK_S', empty, empty],
  6829. [0, 29 /* ScanCode.KeyT */, 'KeyT', 50 /* KeyCode.KeyT */, 'T', 84, 'VK_T', empty, empty],
  6830. [0, 30 /* ScanCode.KeyU */, 'KeyU', 51 /* KeyCode.KeyU */, 'U', 85, 'VK_U', empty, empty],
  6831. [0, 31 /* ScanCode.KeyV */, 'KeyV', 52 /* KeyCode.KeyV */, 'V', 86, 'VK_V', empty, empty],
  6832. [0, 32 /* ScanCode.KeyW */, 'KeyW', 53 /* KeyCode.KeyW */, 'W', 87, 'VK_W', empty, empty],
  6833. [0, 33 /* ScanCode.KeyX */, 'KeyX', 54 /* KeyCode.KeyX */, 'X', 88, 'VK_X', empty, empty],
  6834. [0, 34 /* ScanCode.KeyY */, 'KeyY', 55 /* KeyCode.KeyY */, 'Y', 89, 'VK_Y', empty, empty],
  6835. [0, 35 /* ScanCode.KeyZ */, 'KeyZ', 56 /* KeyCode.KeyZ */, 'Z', 90, 'VK_Z', empty, empty],
  6836. [0, 36 /* ScanCode.Digit1 */, 'Digit1', 22 /* KeyCode.Digit1 */, '1', 49, 'VK_1', empty, empty],
  6837. [0, 37 /* ScanCode.Digit2 */, 'Digit2', 23 /* KeyCode.Digit2 */, '2', 50, 'VK_2', empty, empty],
  6838. [0, 38 /* ScanCode.Digit3 */, 'Digit3', 24 /* KeyCode.Digit3 */, '3', 51, 'VK_3', empty, empty],
  6839. [0, 39 /* ScanCode.Digit4 */, 'Digit4', 25 /* KeyCode.Digit4 */, '4', 52, 'VK_4', empty, empty],
  6840. [0, 40 /* ScanCode.Digit5 */, 'Digit5', 26 /* KeyCode.Digit5 */, '5', 53, 'VK_5', empty, empty],
  6841. [0, 41 /* ScanCode.Digit6 */, 'Digit6', 27 /* KeyCode.Digit6 */, '6', 54, 'VK_6', empty, empty],
  6842. [0, 42 /* ScanCode.Digit7 */, 'Digit7', 28 /* KeyCode.Digit7 */, '7', 55, 'VK_7', empty, empty],
  6843. [0, 43 /* ScanCode.Digit8 */, 'Digit8', 29 /* KeyCode.Digit8 */, '8', 56, 'VK_8', empty, empty],
  6844. [0, 44 /* ScanCode.Digit9 */, 'Digit9', 30 /* KeyCode.Digit9 */, '9', 57, 'VK_9', empty, empty],
  6845. [0, 45 /* ScanCode.Digit0 */, 'Digit0', 21 /* KeyCode.Digit0 */, '0', 48, 'VK_0', empty, empty],
  6846. [1, 46 /* ScanCode.Enter */, 'Enter', 3 /* KeyCode.Enter */, 'Enter', 13, 'VK_RETURN', empty, empty],
  6847. [1, 47 /* ScanCode.Escape */, 'Escape', 9 /* KeyCode.Escape */, 'Escape', 27, 'VK_ESCAPE', empty, empty],
  6848. [1, 48 /* ScanCode.Backspace */, 'Backspace', 1 /* KeyCode.Backspace */, 'Backspace', 8, 'VK_BACK', empty, empty],
  6849. [1, 49 /* ScanCode.Tab */, 'Tab', 2 /* KeyCode.Tab */, 'Tab', 9, 'VK_TAB', empty, empty],
  6850. [1, 50 /* ScanCode.Space */, 'Space', 10 /* KeyCode.Space */, 'Space', 32, 'VK_SPACE', empty, empty],
  6851. [0, 51 /* ScanCode.Minus */, 'Minus', 88 /* KeyCode.Minus */, '-', 189, 'VK_OEM_MINUS', '-', 'OEM_MINUS'],
  6852. [0, 52 /* ScanCode.Equal */, 'Equal', 86 /* KeyCode.Equal */, '=', 187, 'VK_OEM_PLUS', '=', 'OEM_PLUS'],
  6853. [0, 53 /* ScanCode.BracketLeft */, 'BracketLeft', 92 /* KeyCode.BracketLeft */, '[', 219, 'VK_OEM_4', '[', 'OEM_4'],
  6854. [0, 54 /* ScanCode.BracketRight */, 'BracketRight', 94 /* KeyCode.BracketRight */, ']', 221, 'VK_OEM_6', ']', 'OEM_6'],
  6855. [0, 55 /* ScanCode.Backslash */, 'Backslash', 93 /* KeyCode.Backslash */, '\\', 220, 'VK_OEM_5', '\\', 'OEM_5'],
  6856. [0, 56 /* ScanCode.IntlHash */, 'IntlHash', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty], // has been dropped from the w3c spec
  6857. [0, 57 /* ScanCode.Semicolon */, 'Semicolon', 85 /* KeyCode.Semicolon */, ';', 186, 'VK_OEM_1', ';', 'OEM_1'],
  6858. [0, 58 /* ScanCode.Quote */, 'Quote', 95 /* KeyCode.Quote */, '\'', 222, 'VK_OEM_7', '\'', 'OEM_7'],
  6859. [0, 59 /* ScanCode.Backquote */, 'Backquote', 91 /* KeyCode.Backquote */, '`', 192, 'VK_OEM_3', '`', 'OEM_3'],
  6860. [0, 60 /* ScanCode.Comma */, 'Comma', 87 /* KeyCode.Comma */, ',', 188, 'VK_OEM_COMMA', ',', 'OEM_COMMA'],
  6861. [0, 61 /* ScanCode.Period */, 'Period', 89 /* KeyCode.Period */, '.', 190, 'VK_OEM_PERIOD', '.', 'OEM_PERIOD'],
  6862. [0, 62 /* ScanCode.Slash */, 'Slash', 90 /* KeyCode.Slash */, '/', 191, 'VK_OEM_2', '/', 'OEM_2'],
  6863. [1, 63 /* ScanCode.CapsLock */, 'CapsLock', 8 /* KeyCode.CapsLock */, 'CapsLock', 20, 'VK_CAPITAL', empty, empty],
  6864. [1, 64 /* ScanCode.F1 */, 'F1', 59 /* KeyCode.F1 */, 'F1', 112, 'VK_F1', empty, empty],
  6865. [1, 65 /* ScanCode.F2 */, 'F2', 60 /* KeyCode.F2 */, 'F2', 113, 'VK_F2', empty, empty],
  6866. [1, 66 /* ScanCode.F3 */, 'F3', 61 /* KeyCode.F3 */, 'F3', 114, 'VK_F3', empty, empty],
  6867. [1, 67 /* ScanCode.F4 */, 'F4', 62 /* KeyCode.F4 */, 'F4', 115, 'VK_F4', empty, empty],
  6868. [1, 68 /* ScanCode.F5 */, 'F5', 63 /* KeyCode.F5 */, 'F5', 116, 'VK_F5', empty, empty],
  6869. [1, 69 /* ScanCode.F6 */, 'F6', 64 /* KeyCode.F6 */, 'F6', 117, 'VK_F6', empty, empty],
  6870. [1, 70 /* ScanCode.F7 */, 'F7', 65 /* KeyCode.F7 */, 'F7', 118, 'VK_F7', empty, empty],
  6871. [1, 71 /* ScanCode.F8 */, 'F8', 66 /* KeyCode.F8 */, 'F8', 119, 'VK_F8', empty, empty],
  6872. [1, 72 /* ScanCode.F9 */, 'F9', 67 /* KeyCode.F9 */, 'F9', 120, 'VK_F9', empty, empty],
  6873. [1, 73 /* ScanCode.F10 */, 'F10', 68 /* KeyCode.F10 */, 'F10', 121, 'VK_F10', empty, empty],
  6874. [1, 74 /* ScanCode.F11 */, 'F11', 69 /* KeyCode.F11 */, 'F11', 122, 'VK_F11', empty, empty],
  6875. [1, 75 /* ScanCode.F12 */, 'F12', 70 /* KeyCode.F12 */, 'F12', 123, 'VK_F12', empty, empty],
  6876. [1, 76 /* ScanCode.PrintScreen */, 'PrintScreen', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6877. [1, 77 /* ScanCode.ScrollLock */, 'ScrollLock', 84 /* KeyCode.ScrollLock */, 'ScrollLock', 145, 'VK_SCROLL', empty, empty],
  6878. [1, 78 /* ScanCode.Pause */, 'Pause', 7 /* KeyCode.PauseBreak */, 'PauseBreak', 19, 'VK_PAUSE', empty, empty],
  6879. [1, 79 /* ScanCode.Insert */, 'Insert', 19 /* KeyCode.Insert */, 'Insert', 45, 'VK_INSERT', empty, empty],
  6880. [1, 80 /* ScanCode.Home */, 'Home', 14 /* KeyCode.Home */, 'Home', 36, 'VK_HOME', empty, empty],
  6881. [1, 81 /* ScanCode.PageUp */, 'PageUp', 11 /* KeyCode.PageUp */, 'PageUp', 33, 'VK_PRIOR', empty, empty],
  6882. [1, 82 /* ScanCode.Delete */, 'Delete', 20 /* KeyCode.Delete */, 'Delete', 46, 'VK_DELETE', empty, empty],
  6883. [1, 83 /* ScanCode.End */, 'End', 13 /* KeyCode.End */, 'End', 35, 'VK_END', empty, empty],
  6884. [1, 84 /* ScanCode.PageDown */, 'PageDown', 12 /* KeyCode.PageDown */, 'PageDown', 34, 'VK_NEXT', empty, empty],
  6885. [1, 85 /* ScanCode.ArrowRight */, 'ArrowRight', 17 /* KeyCode.RightArrow */, 'RightArrow', 39, 'VK_RIGHT', 'Right', empty],
  6886. [1, 86 /* ScanCode.ArrowLeft */, 'ArrowLeft', 15 /* KeyCode.LeftArrow */, 'LeftArrow', 37, 'VK_LEFT', 'Left', empty],
  6887. [1, 87 /* ScanCode.ArrowDown */, 'ArrowDown', 18 /* KeyCode.DownArrow */, 'DownArrow', 40, 'VK_DOWN', 'Down', empty],
  6888. [1, 88 /* ScanCode.ArrowUp */, 'ArrowUp', 16 /* KeyCode.UpArrow */, 'UpArrow', 38, 'VK_UP', 'Up', empty],
  6889. [1, 89 /* ScanCode.NumLock */, 'NumLock', 83 /* KeyCode.NumLock */, 'NumLock', 144, 'VK_NUMLOCK', empty, empty],
  6890. [1, 90 /* ScanCode.NumpadDivide */, 'NumpadDivide', 113 /* KeyCode.NumpadDivide */, 'NumPad_Divide', 111, 'VK_DIVIDE', empty, empty],
  6891. [1, 91 /* ScanCode.NumpadMultiply */, 'NumpadMultiply', 108 /* KeyCode.NumpadMultiply */, 'NumPad_Multiply', 106, 'VK_MULTIPLY', empty, empty],
  6892. [1, 92 /* ScanCode.NumpadSubtract */, 'NumpadSubtract', 111 /* KeyCode.NumpadSubtract */, 'NumPad_Subtract', 109, 'VK_SUBTRACT', empty, empty],
  6893. [1, 93 /* ScanCode.NumpadAdd */, 'NumpadAdd', 109 /* KeyCode.NumpadAdd */, 'NumPad_Add', 107, 'VK_ADD', empty, empty],
  6894. [1, 94 /* ScanCode.NumpadEnter */, 'NumpadEnter', 3 /* KeyCode.Enter */, empty, 0, empty, empty, empty],
  6895. [1, 95 /* ScanCode.Numpad1 */, 'Numpad1', 99 /* KeyCode.Numpad1 */, 'NumPad1', 97, 'VK_NUMPAD1', empty, empty],
  6896. [1, 96 /* ScanCode.Numpad2 */, 'Numpad2', 100 /* KeyCode.Numpad2 */, 'NumPad2', 98, 'VK_NUMPAD2', empty, empty],
  6897. [1, 97 /* ScanCode.Numpad3 */, 'Numpad3', 101 /* KeyCode.Numpad3 */, 'NumPad3', 99, 'VK_NUMPAD3', empty, empty],
  6898. [1, 98 /* ScanCode.Numpad4 */, 'Numpad4', 102 /* KeyCode.Numpad4 */, 'NumPad4', 100, 'VK_NUMPAD4', empty, empty],
  6899. [1, 99 /* ScanCode.Numpad5 */, 'Numpad5', 103 /* KeyCode.Numpad5 */, 'NumPad5', 101, 'VK_NUMPAD5', empty, empty],
  6900. [1, 100 /* ScanCode.Numpad6 */, 'Numpad6', 104 /* KeyCode.Numpad6 */, 'NumPad6', 102, 'VK_NUMPAD6', empty, empty],
  6901. [1, 101 /* ScanCode.Numpad7 */, 'Numpad7', 105 /* KeyCode.Numpad7 */, 'NumPad7', 103, 'VK_NUMPAD7', empty, empty],
  6902. [1, 102 /* ScanCode.Numpad8 */, 'Numpad8', 106 /* KeyCode.Numpad8 */, 'NumPad8', 104, 'VK_NUMPAD8', empty, empty],
  6903. [1, 103 /* ScanCode.Numpad9 */, 'Numpad9', 107 /* KeyCode.Numpad9 */, 'NumPad9', 105, 'VK_NUMPAD9', empty, empty],
  6904. [1, 104 /* ScanCode.Numpad0 */, 'Numpad0', 98 /* KeyCode.Numpad0 */, 'NumPad0', 96, 'VK_NUMPAD0', empty, empty],
  6905. [1, 105 /* ScanCode.NumpadDecimal */, 'NumpadDecimal', 112 /* KeyCode.NumpadDecimal */, 'NumPad_Decimal', 110, 'VK_DECIMAL', empty, empty],
  6906. [0, 106 /* ScanCode.IntlBackslash */, 'IntlBackslash', 97 /* KeyCode.IntlBackslash */, 'OEM_102', 226, 'VK_OEM_102', empty, empty],
  6907. [1, 107 /* ScanCode.ContextMenu */, 'ContextMenu', 58 /* KeyCode.ContextMenu */, 'ContextMenu', 93, empty, empty, empty],
  6908. [1, 108 /* ScanCode.Power */, 'Power', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6909. [1, 109 /* ScanCode.NumpadEqual */, 'NumpadEqual', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6910. [1, 110 /* ScanCode.F13 */, 'F13', 71 /* KeyCode.F13 */, 'F13', 124, 'VK_F13', empty, empty],
  6911. [1, 111 /* ScanCode.F14 */, 'F14', 72 /* KeyCode.F14 */, 'F14', 125, 'VK_F14', empty, empty],
  6912. [1, 112 /* ScanCode.F15 */, 'F15', 73 /* KeyCode.F15 */, 'F15', 126, 'VK_F15', empty, empty],
  6913. [1, 113 /* ScanCode.F16 */, 'F16', 74 /* KeyCode.F16 */, 'F16', 127, 'VK_F16', empty, empty],
  6914. [1, 114 /* ScanCode.F17 */, 'F17', 75 /* KeyCode.F17 */, 'F17', 128, 'VK_F17', empty, empty],
  6915. [1, 115 /* ScanCode.F18 */, 'F18', 76 /* KeyCode.F18 */, 'F18', 129, 'VK_F18', empty, empty],
  6916. [1, 116 /* ScanCode.F19 */, 'F19', 77 /* KeyCode.F19 */, 'F19', 130, 'VK_F19', empty, empty],
  6917. [1, 117 /* ScanCode.F20 */, 'F20', 78 /* KeyCode.F20 */, 'F20', 131, 'VK_F20', empty, empty],
  6918. [1, 118 /* ScanCode.F21 */, 'F21', 79 /* KeyCode.F21 */, 'F21', 132, 'VK_F21', empty, empty],
  6919. [1, 119 /* ScanCode.F22 */, 'F22', 80 /* KeyCode.F22 */, 'F22', 133, 'VK_F22', empty, empty],
  6920. [1, 120 /* ScanCode.F23 */, 'F23', 81 /* KeyCode.F23 */, 'F23', 134, 'VK_F23', empty, empty],
  6921. [1, 121 /* ScanCode.F24 */, 'F24', 82 /* KeyCode.F24 */, 'F24', 135, 'VK_F24', empty, empty],
  6922. [1, 122 /* ScanCode.Open */, 'Open', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6923. [1, 123 /* ScanCode.Help */, 'Help', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6924. [1, 124 /* ScanCode.Select */, 'Select', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6925. [1, 125 /* ScanCode.Again */, 'Again', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6926. [1, 126 /* ScanCode.Undo */, 'Undo', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6927. [1, 127 /* ScanCode.Cut */, 'Cut', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6928. [1, 128 /* ScanCode.Copy */, 'Copy', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6929. [1, 129 /* ScanCode.Paste */, 'Paste', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6930. [1, 130 /* ScanCode.Find */, 'Find', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6931. [1, 131 /* ScanCode.AudioVolumeMute */, 'AudioVolumeMute', 117 /* KeyCode.AudioVolumeMute */, 'AudioVolumeMute', 173, 'VK_VOLUME_MUTE', empty, empty],
  6932. [1, 132 /* ScanCode.AudioVolumeUp */, 'AudioVolumeUp', 118 /* KeyCode.AudioVolumeUp */, 'AudioVolumeUp', 175, 'VK_VOLUME_UP', empty, empty],
  6933. [1, 133 /* ScanCode.AudioVolumeDown */, 'AudioVolumeDown', 119 /* KeyCode.AudioVolumeDown */, 'AudioVolumeDown', 174, 'VK_VOLUME_DOWN', empty, empty],
  6934. [1, 134 /* ScanCode.NumpadComma */, 'NumpadComma', 110 /* KeyCode.NUMPAD_SEPARATOR */, 'NumPad_Separator', 108, 'VK_SEPARATOR', empty, empty],
  6935. [0, 135 /* ScanCode.IntlRo */, 'IntlRo', 115 /* KeyCode.ABNT_C1 */, 'ABNT_C1', 193, 'VK_ABNT_C1', empty, empty],
  6936. [1, 136 /* ScanCode.KanaMode */, 'KanaMode', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6937. [0, 137 /* ScanCode.IntlYen */, 'IntlYen', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6938. [1, 138 /* ScanCode.Convert */, 'Convert', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6939. [1, 139 /* ScanCode.NonConvert */, 'NonConvert', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6940. [1, 140 /* ScanCode.Lang1 */, 'Lang1', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6941. [1, 141 /* ScanCode.Lang2 */, 'Lang2', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6942. [1, 142 /* ScanCode.Lang3 */, 'Lang3', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6943. [1, 143 /* ScanCode.Lang4 */, 'Lang4', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6944. [1, 144 /* ScanCode.Lang5 */, 'Lang5', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6945. [1, 145 /* ScanCode.Abort */, 'Abort', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6946. [1, 146 /* ScanCode.Props */, 'Props', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6947. [1, 147 /* ScanCode.NumpadParenLeft */, 'NumpadParenLeft', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6948. [1, 148 /* ScanCode.NumpadParenRight */, 'NumpadParenRight', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6949. [1, 149 /* ScanCode.NumpadBackspace */, 'NumpadBackspace', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6950. [1, 150 /* ScanCode.NumpadMemoryStore */, 'NumpadMemoryStore', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6951. [1, 151 /* ScanCode.NumpadMemoryRecall */, 'NumpadMemoryRecall', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6952. [1, 152 /* ScanCode.NumpadMemoryClear */, 'NumpadMemoryClear', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6953. [1, 153 /* ScanCode.NumpadMemoryAdd */, 'NumpadMemoryAdd', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6954. [1, 154 /* ScanCode.NumpadMemorySubtract */, 'NumpadMemorySubtract', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6955. [1, 155 /* ScanCode.NumpadClear */, 'NumpadClear', 131 /* KeyCode.Clear */, 'Clear', 12, 'VK_CLEAR', empty, empty],
  6956. [1, 156 /* ScanCode.NumpadClearEntry */, 'NumpadClearEntry', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6957. [1, 0 /* ScanCode.None */, empty, 5 /* KeyCode.Ctrl */, 'Ctrl', 17, 'VK_CONTROL', empty, empty],
  6958. [1, 0 /* ScanCode.None */, empty, 4 /* KeyCode.Shift */, 'Shift', 16, 'VK_SHIFT', empty, empty],
  6959. [1, 0 /* ScanCode.None */, empty, 6 /* KeyCode.Alt */, 'Alt', 18, 'VK_MENU', empty, empty],
  6960. [1, 0 /* ScanCode.None */, empty, 57 /* KeyCode.Meta */, 'Meta', 91, 'VK_COMMAND', empty, empty],
  6961. [1, 157 /* ScanCode.ControlLeft */, 'ControlLeft', 5 /* KeyCode.Ctrl */, empty, 0, 'VK_LCONTROL', empty, empty],
  6962. [1, 158 /* ScanCode.ShiftLeft */, 'ShiftLeft', 4 /* KeyCode.Shift */, empty, 0, 'VK_LSHIFT', empty, empty],
  6963. [1, 159 /* ScanCode.AltLeft */, 'AltLeft', 6 /* KeyCode.Alt */, empty, 0, 'VK_LMENU', empty, empty],
  6964. [1, 160 /* ScanCode.MetaLeft */, 'MetaLeft', 57 /* KeyCode.Meta */, empty, 0, 'VK_LWIN', empty, empty],
  6965. [1, 161 /* ScanCode.ControlRight */, 'ControlRight', 5 /* KeyCode.Ctrl */, empty, 0, 'VK_RCONTROL', empty, empty],
  6966. [1, 162 /* ScanCode.ShiftRight */, 'ShiftRight', 4 /* KeyCode.Shift */, empty, 0, 'VK_RSHIFT', empty, empty],
  6967. [1, 163 /* ScanCode.AltRight */, 'AltRight', 6 /* KeyCode.Alt */, empty, 0, 'VK_RMENU', empty, empty],
  6968. [1, 164 /* ScanCode.MetaRight */, 'MetaRight', 57 /* KeyCode.Meta */, empty, 0, 'VK_RWIN', empty, empty],
  6969. [1, 165 /* ScanCode.BrightnessUp */, 'BrightnessUp', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6970. [1, 166 /* ScanCode.BrightnessDown */, 'BrightnessDown', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6971. [1, 167 /* ScanCode.MediaPlay */, 'MediaPlay', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6972. [1, 168 /* ScanCode.MediaRecord */, 'MediaRecord', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6973. [1, 169 /* ScanCode.MediaFastForward */, 'MediaFastForward', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6974. [1, 170 /* ScanCode.MediaRewind */, 'MediaRewind', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6975. [1, 171 /* ScanCode.MediaTrackNext */, 'MediaTrackNext', 124 /* KeyCode.MediaTrackNext */, 'MediaTrackNext', 176, 'VK_MEDIA_NEXT_TRACK', empty, empty],
  6976. [1, 172 /* ScanCode.MediaTrackPrevious */, 'MediaTrackPrevious', 125 /* KeyCode.MediaTrackPrevious */, 'MediaTrackPrevious', 177, 'VK_MEDIA_PREV_TRACK', empty, empty],
  6977. [1, 173 /* ScanCode.MediaStop */, 'MediaStop', 126 /* KeyCode.MediaStop */, 'MediaStop', 178, 'VK_MEDIA_STOP', empty, empty],
  6978. [1, 174 /* ScanCode.Eject */, 'Eject', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6979. [1, 175 /* ScanCode.MediaPlayPause */, 'MediaPlayPause', 127 /* KeyCode.MediaPlayPause */, 'MediaPlayPause', 179, 'VK_MEDIA_PLAY_PAUSE', empty, empty],
  6980. [1, 176 /* ScanCode.MediaSelect */, 'MediaSelect', 128 /* KeyCode.LaunchMediaPlayer */, 'LaunchMediaPlayer', 181, 'VK_MEDIA_LAUNCH_MEDIA_SELECT', empty, empty],
  6981. [1, 177 /* ScanCode.LaunchMail */, 'LaunchMail', 129 /* KeyCode.LaunchMail */, 'LaunchMail', 180, 'VK_MEDIA_LAUNCH_MAIL', empty, empty],
  6982. [1, 178 /* ScanCode.LaunchApp2 */, 'LaunchApp2', 130 /* KeyCode.LaunchApp2 */, 'LaunchApp2', 183, 'VK_MEDIA_LAUNCH_APP2', empty, empty],
  6983. [1, 179 /* ScanCode.LaunchApp1 */, 'LaunchApp1', 0 /* KeyCode.Unknown */, empty, 0, 'VK_MEDIA_LAUNCH_APP1', empty, empty],
  6984. [1, 180 /* ScanCode.SelectTask */, 'SelectTask', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6985. [1, 181 /* ScanCode.LaunchScreenSaver */, 'LaunchScreenSaver', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6986. [1, 182 /* ScanCode.BrowserSearch */, 'BrowserSearch', 120 /* KeyCode.BrowserSearch */, 'BrowserSearch', 170, 'VK_BROWSER_SEARCH', empty, empty],
  6987. [1, 183 /* ScanCode.BrowserHome */, 'BrowserHome', 121 /* KeyCode.BrowserHome */, 'BrowserHome', 172, 'VK_BROWSER_HOME', empty, empty],
  6988. [1, 184 /* ScanCode.BrowserBack */, 'BrowserBack', 122 /* KeyCode.BrowserBack */, 'BrowserBack', 166, 'VK_BROWSER_BACK', empty, empty],
  6989. [1, 185 /* ScanCode.BrowserForward */, 'BrowserForward', 123 /* KeyCode.BrowserForward */, 'BrowserForward', 167, 'VK_BROWSER_FORWARD', empty, empty],
  6990. [1, 186 /* ScanCode.BrowserStop */, 'BrowserStop', 0 /* KeyCode.Unknown */, empty, 0, 'VK_BROWSER_STOP', empty, empty],
  6991. [1, 187 /* ScanCode.BrowserRefresh */, 'BrowserRefresh', 0 /* KeyCode.Unknown */, empty, 0, 'VK_BROWSER_REFRESH', empty, empty],
  6992. [1, 188 /* ScanCode.BrowserFavorites */, 'BrowserFavorites', 0 /* KeyCode.Unknown */, empty, 0, 'VK_BROWSER_FAVORITES', empty, empty],
  6993. [1, 189 /* ScanCode.ZoomToggle */, 'ZoomToggle', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6994. [1, 190 /* ScanCode.MailReply */, 'MailReply', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6995. [1, 191 /* ScanCode.MailForward */, 'MailForward', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6996. [1, 192 /* ScanCode.MailSend */, 'MailSend', 0 /* KeyCode.Unknown */, empty, 0, empty, empty, empty],
  6997. // See https://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html
  6998. // If an Input Method Editor is processing key input and the event is keydown, return 229.
  6999. [1, 0 /* ScanCode.None */, empty, 114 /* KeyCode.KEY_IN_COMPOSITION */, 'KeyInComposition', 229, empty, empty, empty],
  7000. [1, 0 /* ScanCode.None */, empty, 116 /* KeyCode.ABNT_C2 */, 'ABNT_C2', 194, 'VK_ABNT_C2', empty, empty],
  7001. [1, 0 /* ScanCode.None */, empty, 96 /* KeyCode.OEM_8 */, 'OEM_8', 223, 'VK_OEM_8', empty, empty],
  7002. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_KANA', empty, empty],
  7003. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_HANGUL', empty, empty],
  7004. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_JUNJA', empty, empty],
  7005. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_FINAL', empty, empty],
  7006. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_HANJA', empty, empty],
  7007. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_KANJI', empty, empty],
  7008. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_CONVERT', empty, empty],
  7009. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_NONCONVERT', empty, empty],
  7010. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_ACCEPT', empty, empty],
  7011. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_MODECHANGE', empty, empty],
  7012. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_SELECT', empty, empty],
  7013. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_PRINT', empty, empty],
  7014. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_EXECUTE', empty, empty],
  7015. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_SNAPSHOT', empty, empty],
  7016. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_HELP', empty, empty],
  7017. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_APPS', empty, empty],
  7018. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_PROCESSKEY', empty, empty],
  7019. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_PACKET', empty, empty],
  7020. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_DBE_SBCSCHAR', empty, empty],
  7021. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_DBE_DBCSCHAR', empty, empty],
  7022. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_ATTN', empty, empty],
  7023. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_CRSEL', empty, empty],
  7024. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_EXSEL', empty, empty],
  7025. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_EREOF', empty, empty],
  7026. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_PLAY', empty, empty],
  7027. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_ZOOM', empty, empty],
  7028. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_NONAME', empty, empty],
  7029. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_PA1', empty, empty],
  7030. [1, 0 /* ScanCode.None */, empty, 0 /* KeyCode.Unknown */, empty, 0, 'VK_OEM_CLEAR', empty, empty],
  7031. ];
  7032. const seenKeyCode = [];
  7033. const seenScanCode = [];
  7034. for (const mapping of mappings) {
  7035. const [immutable, scanCode, scanCodeStr, keyCode, keyCodeStr, eventKeyCode, vkey, usUserSettingsLabel, generalUserSettingsLabel] = mapping;
  7036. if (!seenScanCode[scanCode]) {
  7037. seenScanCode[scanCode] = true;
  7038. scanCodeStrToInt[scanCodeStr] = scanCode;
  7039. scanCodeLowerCaseStrToInt[scanCodeStr.toLowerCase()] = scanCode;
  7040. }
  7041. if (!seenKeyCode[keyCode]) {
  7042. seenKeyCode[keyCode] = true;
  7043. if (!keyCodeStr) {
  7044. throw new Error(`String representation missing for key code ${keyCode} around scan code ${scanCodeStr}`);
  7045. }
  7046. uiMap.define(keyCode, keyCodeStr);
  7047. userSettingsUSMap.define(keyCode, usUserSettingsLabel || keyCodeStr);
  7048. userSettingsGeneralMap.define(keyCode, generalUserSettingsLabel || usUserSettingsLabel || keyCodeStr);
  7049. }
  7050. if (eventKeyCode) {
  7051. EVENT_KEY_CODE_MAP[eventKeyCode] = keyCode;
  7052. }
  7053. }
  7054. })();
  7055. var KeyCodeUtils;
  7056. (function (KeyCodeUtils) {
  7057. function toString(keyCode) {
  7058. return uiMap.keyCodeToStr(keyCode);
  7059. }
  7060. KeyCodeUtils.toString = toString;
  7061. function fromString(key) {
  7062. return uiMap.strToKeyCode(key);
  7063. }
  7064. KeyCodeUtils.fromString = fromString;
  7065. function toUserSettingsUS(keyCode) {
  7066. return userSettingsUSMap.keyCodeToStr(keyCode);
  7067. }
  7068. KeyCodeUtils.toUserSettingsUS = toUserSettingsUS;
  7069. function toUserSettingsGeneral(keyCode) {
  7070. return userSettingsGeneralMap.keyCodeToStr(keyCode);
  7071. }
  7072. KeyCodeUtils.toUserSettingsGeneral = toUserSettingsGeneral;
  7073. function fromUserSettings(key) {
  7074. return userSettingsUSMap.strToKeyCode(key) || userSettingsGeneralMap.strToKeyCode(key);
  7075. }
  7076. KeyCodeUtils.fromUserSettings = fromUserSettings;
  7077. function toElectronAccelerator(keyCode) {
  7078. if (keyCode >= 98 /* KeyCode.Numpad0 */ && keyCode <= 113 /* KeyCode.NumpadDivide */) {
  7079. // [Electron Accelerators] Electron is able to parse numpad keys, but unfortunately it
  7080. // renders them just as regular keys in menus. For example, num0 is rendered as "0",
  7081. // numdiv is rendered as "/", numsub is rendered as "-".
  7082. //
  7083. // This can lead to incredible confusion, as it makes numpad based keybindings indistinguishable
  7084. // from keybindings based on regular keys.
  7085. //
  7086. // We therefore need to fall back to custom rendering for numpad keys.
  7087. return null;
  7088. }
  7089. switch (keyCode) {
  7090. case 16 /* KeyCode.UpArrow */:
  7091. return 'Up';
  7092. case 18 /* KeyCode.DownArrow */:
  7093. return 'Down';
  7094. case 15 /* KeyCode.LeftArrow */:
  7095. return 'Left';
  7096. case 17 /* KeyCode.RightArrow */:
  7097. return 'Right';
  7098. }
  7099. return uiMap.keyCodeToStr(keyCode);
  7100. }
  7101. KeyCodeUtils.toElectronAccelerator = toElectronAccelerator;
  7102. })(KeyCodeUtils || (KeyCodeUtils = {}));
  7103. function KeyChord(firstPart, secondPart) {
  7104. const chordPart = ((secondPart & 0x0000FFFF) << 16) >>> 0;
  7105. return (firstPart | chordPart) >>> 0;
  7106. }
  7107. /*---------------------------------------------------------------------------------------------
  7108. * Copyright (c) Microsoft Corporation. All rights reserved.
  7109. * Licensed under the MIT License. See License.txt in the project root for license information.
  7110. *--------------------------------------------------------------------------------------------*/
  7111. /**
  7112. * A selection in the editor.
  7113. * The selection is a range that has an orientation.
  7114. */
  7115. class Selection extends Range {
  7116. constructor(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn) {
  7117. super(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn);
  7118. this.selectionStartLineNumber = selectionStartLineNumber;
  7119. this.selectionStartColumn = selectionStartColumn;
  7120. this.positionLineNumber = positionLineNumber;
  7121. this.positionColumn = positionColumn;
  7122. }
  7123. /**
  7124. * Transform to a human-readable representation.
  7125. */
  7126. toString() {
  7127. return '[' + this.selectionStartLineNumber + ',' + this.selectionStartColumn + ' -> ' + this.positionLineNumber + ',' + this.positionColumn + ']';
  7128. }
  7129. /**
  7130. * Test if equals other selection.
  7131. */
  7132. equalsSelection(other) {
  7133. return (Selection.selectionsEqual(this, other));
  7134. }
  7135. /**
  7136. * Test if the two selections are equal.
  7137. */
  7138. static selectionsEqual(a, b) {
  7139. return (a.selectionStartLineNumber === b.selectionStartLineNumber &&
  7140. a.selectionStartColumn === b.selectionStartColumn &&
  7141. a.positionLineNumber === b.positionLineNumber &&
  7142. a.positionColumn === b.positionColumn);
  7143. }
  7144. /**
  7145. * Get directions (LTR or RTL).
  7146. */
  7147. getDirection() {
  7148. if (this.selectionStartLineNumber === this.startLineNumber && this.selectionStartColumn === this.startColumn) {
  7149. return 0 /* SelectionDirection.LTR */;
  7150. }
  7151. return 1 /* SelectionDirection.RTL */;
  7152. }
  7153. /**
  7154. * Create a new selection with a different `positionLineNumber` and `positionColumn`.
  7155. */
  7156. setEndPosition(endLineNumber, endColumn) {
  7157. if (this.getDirection() === 0 /* SelectionDirection.LTR */) {
  7158. return new Selection(this.startLineNumber, this.startColumn, endLineNumber, endColumn);
  7159. }
  7160. return new Selection(endLineNumber, endColumn, this.startLineNumber, this.startColumn);
  7161. }
  7162. /**
  7163. * Get the position at `positionLineNumber` and `positionColumn`.
  7164. */
  7165. getPosition() {
  7166. return new Position(this.positionLineNumber, this.positionColumn);
  7167. }
  7168. /**
  7169. * Get the position at the start of the selection.
  7170. */
  7171. getSelectionStart() {
  7172. return new Position(this.selectionStartLineNumber, this.selectionStartColumn);
  7173. }
  7174. /**
  7175. * Create a new selection with a different `selectionStartLineNumber` and `selectionStartColumn`.
  7176. */
  7177. setStartPosition(startLineNumber, startColumn) {
  7178. if (this.getDirection() === 0 /* SelectionDirection.LTR */) {
  7179. return new Selection(startLineNumber, startColumn, this.endLineNumber, this.endColumn);
  7180. }
  7181. return new Selection(this.endLineNumber, this.endColumn, startLineNumber, startColumn);
  7182. }
  7183. // ----
  7184. /**
  7185. * Create a `Selection` from one or two positions
  7186. */
  7187. static fromPositions(start, end = start) {
  7188. return new Selection(start.lineNumber, start.column, end.lineNumber, end.column);
  7189. }
  7190. /**
  7191. * Creates a `Selection` from a range, given a direction.
  7192. */
  7193. static fromRange(range, direction) {
  7194. if (direction === 0 /* SelectionDirection.LTR */) {
  7195. return new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn);
  7196. }
  7197. else {
  7198. return new Selection(range.endLineNumber, range.endColumn, range.startLineNumber, range.startColumn);
  7199. }
  7200. }
  7201. /**
  7202. * Create a `Selection` from an `ISelection`.
  7203. */
  7204. static liftSelection(sel) {
  7205. return new Selection(sel.selectionStartLineNumber, sel.selectionStartColumn, sel.positionLineNumber, sel.positionColumn);
  7206. }
  7207. /**
  7208. * `a` equals `b`.
  7209. */
  7210. static selectionsArrEqual(a, b) {
  7211. if (a && !b || !a && b) {
  7212. return false;
  7213. }
  7214. if (!a && !b) {
  7215. return true;
  7216. }
  7217. if (a.length !== b.length) {
  7218. return false;
  7219. }
  7220. for (let i = 0, len = a.length; i < len; i++) {
  7221. if (!this.selectionsEqual(a[i], b[i])) {
  7222. return false;
  7223. }
  7224. }
  7225. return true;
  7226. }
  7227. /**
  7228. * Test if `obj` is an `ISelection`.
  7229. */
  7230. static isISelection(obj) {
  7231. return (obj
  7232. && (typeof obj.selectionStartLineNumber === 'number')
  7233. && (typeof obj.selectionStartColumn === 'number')
  7234. && (typeof obj.positionLineNumber === 'number')
  7235. && (typeof obj.positionColumn === 'number'));
  7236. }
  7237. /**
  7238. * Create with a direction.
  7239. */
  7240. static createWithDirection(startLineNumber, startColumn, endLineNumber, endColumn, direction) {
  7241. if (direction === 0 /* SelectionDirection.LTR */) {
  7242. return new Selection(startLineNumber, startColumn, endLineNumber, endColumn);
  7243. }
  7244. return new Selection(endLineNumber, endColumn, startLineNumber, startColumn);
  7245. }
  7246. }
  7247. /*---------------------------------------------------------------------------------------------
  7248. * Copyright (c) Microsoft Corporation. All rights reserved.
  7249. * Licensed under the MIT License. See License.txt in the project root for license information.
  7250. *--------------------------------------------------------------------------------------------*/
  7251. /**
  7252. * @returns whether the provided parameter is a JavaScript String or not.
  7253. */
  7254. function isString(str) {
  7255. return (typeof str === 'string');
  7256. }
  7257. const _codiconFontCharacters = Object.create(null);
  7258. function register(id, fontCharacter) {
  7259. if (isString(fontCharacter)) {
  7260. const val = _codiconFontCharacters[fontCharacter];
  7261. if (val === undefined) {
  7262. throw new Error(`${id} references an unknown codicon: ${fontCharacter}`);
  7263. }
  7264. fontCharacter = val;
  7265. }
  7266. _codiconFontCharacters[id] = fontCharacter;
  7267. return { id };
  7268. }
  7269. /*---------------------------------------------------------------------------------------------
  7270. * Copyright (c) Microsoft Corporation. All rights reserved.
  7271. * Licensed under the MIT License. See License.txt in the project root for license information.
  7272. *--------------------------------------------------------------------------------------------*/
  7273. // This file is automatically generated by (microsoft/vscode-codicons)/scripts/export-to-ts.js
  7274. // Please don't edit it, as your changes will be overwritten.
  7275. // Instead, add mappings to codiconsDerived in codicons.ts.
  7276. const codiconsLibrary = {
  7277. add: register('add', 0xea60),
  7278. plus: register('plus', 0xea60),
  7279. gistNew: register('gist-new', 0xea60),
  7280. repoCreate: register('repo-create', 0xea60),
  7281. lightbulb: register('lightbulb', 0xea61),
  7282. lightBulb: register('light-bulb', 0xea61),
  7283. repo: register('repo', 0xea62),
  7284. repoDelete: register('repo-delete', 0xea62),
  7285. gistFork: register('gist-fork', 0xea63),
  7286. repoForked: register('repo-forked', 0xea63),
  7287. gitPullRequest: register('git-pull-request', 0xea64),
  7288. gitPullRequestAbandoned: register('git-pull-request-abandoned', 0xea64),
  7289. recordKeys: register('record-keys', 0xea65),
  7290. keyboard: register('keyboard', 0xea65),
  7291. tag: register('tag', 0xea66),
  7292. gitPullRequestLabel: register('git-pull-request-label', 0xea66),
  7293. tagAdd: register('tag-add', 0xea66),
  7294. tagRemove: register('tag-remove', 0xea66),
  7295. person: register('person', 0xea67),
  7296. personFollow: register('person-follow', 0xea67),
  7297. personOutline: register('person-outline', 0xea67),
  7298. personFilled: register('person-filled', 0xea67),
  7299. gitBranch: register('git-branch', 0xea68),
  7300. gitBranchCreate: register('git-branch-create', 0xea68),
  7301. gitBranchDelete: register('git-branch-delete', 0xea68),
  7302. sourceControl: register('source-control', 0xea68),
  7303. mirror: register('mirror', 0xea69),
  7304. mirrorPublic: register('mirror-public', 0xea69),
  7305. star: register('star', 0xea6a),
  7306. starAdd: register('star-add', 0xea6a),
  7307. starDelete: register('star-delete', 0xea6a),
  7308. starEmpty: register('star-empty', 0xea6a),
  7309. comment: register('comment', 0xea6b),
  7310. commentAdd: register('comment-add', 0xea6b),
  7311. alert: register('alert', 0xea6c),
  7312. warning: register('warning', 0xea6c),
  7313. search: register('search', 0xea6d),
  7314. searchSave: register('search-save', 0xea6d),
  7315. logOut: register('log-out', 0xea6e),
  7316. signOut: register('sign-out', 0xea6e),
  7317. logIn: register('log-in', 0xea6f),
  7318. signIn: register('sign-in', 0xea6f),
  7319. eye: register('eye', 0xea70),
  7320. eyeUnwatch: register('eye-unwatch', 0xea70),
  7321. eyeWatch: register('eye-watch', 0xea70),
  7322. circleFilled: register('circle-filled', 0xea71),
  7323. primitiveDot: register('primitive-dot', 0xea71),
  7324. closeDirty: register('close-dirty', 0xea71),
  7325. debugBreakpoint: register('debug-breakpoint', 0xea71),
  7326. debugBreakpointDisabled: register('debug-breakpoint-disabled', 0xea71),
  7327. debugHint: register('debug-hint', 0xea71),
  7328. terminalDecorationSuccess: register('terminal-decoration-success', 0xea71),
  7329. primitiveSquare: register('primitive-square', 0xea72),
  7330. edit: register('edit', 0xea73),
  7331. pencil: register('pencil', 0xea73),
  7332. info: register('info', 0xea74),
  7333. issueOpened: register('issue-opened', 0xea74),
  7334. gistPrivate: register('gist-private', 0xea75),
  7335. gitForkPrivate: register('git-fork-private', 0xea75),
  7336. lock: register('lock', 0xea75),
  7337. mirrorPrivate: register('mirror-private', 0xea75),
  7338. close: register('close', 0xea76),
  7339. removeClose: register('remove-close', 0xea76),
  7340. x: register('x', 0xea76),
  7341. repoSync: register('repo-sync', 0xea77),
  7342. sync: register('sync', 0xea77),
  7343. clone: register('clone', 0xea78),
  7344. desktopDownload: register('desktop-download', 0xea78),
  7345. beaker: register('beaker', 0xea79),
  7346. microscope: register('microscope', 0xea79),
  7347. vm: register('vm', 0xea7a),
  7348. deviceDesktop: register('device-desktop', 0xea7a),
  7349. file: register('file', 0xea7b),
  7350. fileText: register('file-text', 0xea7b),
  7351. more: register('more', 0xea7c),
  7352. ellipsis: register('ellipsis', 0xea7c),
  7353. kebabHorizontal: register('kebab-horizontal', 0xea7c),
  7354. mailReply: register('mail-reply', 0xea7d),
  7355. reply: register('reply', 0xea7d),
  7356. organization: register('organization', 0xea7e),
  7357. organizationFilled: register('organization-filled', 0xea7e),
  7358. organizationOutline: register('organization-outline', 0xea7e),
  7359. newFile: register('new-file', 0xea7f),
  7360. fileAdd: register('file-add', 0xea7f),
  7361. newFolder: register('new-folder', 0xea80),
  7362. fileDirectoryCreate: register('file-directory-create', 0xea80),
  7363. trash: register('trash', 0xea81),
  7364. trashcan: register('trashcan', 0xea81),
  7365. history: register('history', 0xea82),
  7366. clock: register('clock', 0xea82),
  7367. folder: register('folder', 0xea83),
  7368. fileDirectory: register('file-directory', 0xea83),
  7369. symbolFolder: register('symbol-folder', 0xea83),
  7370. logoGithub: register('logo-github', 0xea84),
  7371. markGithub: register('mark-github', 0xea84),
  7372. github: register('github', 0xea84),
  7373. terminal: register('terminal', 0xea85),
  7374. console: register('console', 0xea85),
  7375. repl: register('repl', 0xea85),
  7376. zap: register('zap', 0xea86),
  7377. symbolEvent: register('symbol-event', 0xea86),
  7378. error: register('error', 0xea87),
  7379. stop: register('stop', 0xea87),
  7380. variable: register('variable', 0xea88),
  7381. symbolVariable: register('symbol-variable', 0xea88),
  7382. array: register('array', 0xea8a),
  7383. symbolArray: register('symbol-array', 0xea8a),
  7384. symbolModule: register('symbol-module', 0xea8b),
  7385. symbolPackage: register('symbol-package', 0xea8b),
  7386. symbolNamespace: register('symbol-namespace', 0xea8b),
  7387. symbolObject: register('symbol-object', 0xea8b),
  7388. symbolMethod: register('symbol-method', 0xea8c),
  7389. symbolFunction: register('symbol-function', 0xea8c),
  7390. symbolConstructor: register('symbol-constructor', 0xea8c),
  7391. symbolBoolean: register('symbol-boolean', 0xea8f),
  7392. symbolNull: register('symbol-null', 0xea8f),
  7393. symbolNumeric: register('symbol-numeric', 0xea90),
  7394. symbolNumber: register('symbol-number', 0xea90),
  7395. symbolStructure: register('symbol-structure', 0xea91),
  7396. symbolStruct: register('symbol-struct', 0xea91),
  7397. symbolParameter: register('symbol-parameter', 0xea92),
  7398. symbolTypeParameter: register('symbol-type-parameter', 0xea92),
  7399. symbolKey: register('symbol-key', 0xea93),
  7400. symbolText: register('symbol-text', 0xea93),
  7401. symbolReference: register('symbol-reference', 0xea94),
  7402. goToFile: register('go-to-file', 0xea94),
  7403. symbolEnum: register('symbol-enum', 0xea95),
  7404. symbolValue: register('symbol-value', 0xea95),
  7405. symbolRuler: register('symbol-ruler', 0xea96),
  7406. symbolUnit: register('symbol-unit', 0xea96),
  7407. activateBreakpoints: register('activate-breakpoints', 0xea97),
  7408. archive: register('archive', 0xea98),
  7409. arrowBoth: register('arrow-both', 0xea99),
  7410. arrowDown: register('arrow-down', 0xea9a),
  7411. arrowLeft: register('arrow-left', 0xea9b),
  7412. arrowRight: register('arrow-right', 0xea9c),
  7413. arrowSmallDown: register('arrow-small-down', 0xea9d),
  7414. arrowSmallLeft: register('arrow-small-left', 0xea9e),
  7415. arrowSmallRight: register('arrow-small-right', 0xea9f),
  7416. arrowSmallUp: register('arrow-small-up', 0xeaa0),
  7417. arrowUp: register('arrow-up', 0xeaa1),
  7418. bell: register('bell', 0xeaa2),
  7419. bold: register('bold', 0xeaa3),
  7420. book: register('book', 0xeaa4),
  7421. bookmark: register('bookmark', 0xeaa5),
  7422. debugBreakpointConditionalUnverified: register('debug-breakpoint-conditional-unverified', 0xeaa6),
  7423. debugBreakpointConditional: register('debug-breakpoint-conditional', 0xeaa7),
  7424. debugBreakpointConditionalDisabled: register('debug-breakpoint-conditional-disabled', 0xeaa7),
  7425. debugBreakpointDataUnverified: register('debug-breakpoint-data-unverified', 0xeaa8),
  7426. debugBreakpointData: register('debug-breakpoint-data', 0xeaa9),
  7427. debugBreakpointDataDisabled: register('debug-breakpoint-data-disabled', 0xeaa9),
  7428. debugBreakpointLogUnverified: register('debug-breakpoint-log-unverified', 0xeaaa),
  7429. debugBreakpointLog: register('debug-breakpoint-log', 0xeaab),
  7430. debugBreakpointLogDisabled: register('debug-breakpoint-log-disabled', 0xeaab),
  7431. briefcase: register('briefcase', 0xeaac),
  7432. broadcast: register('broadcast', 0xeaad),
  7433. browser: register('browser', 0xeaae),
  7434. bug: register('bug', 0xeaaf),
  7435. calendar: register('calendar', 0xeab0),
  7436. caseSensitive: register('case-sensitive', 0xeab1),
  7437. check: register('check', 0xeab2),
  7438. checklist: register('checklist', 0xeab3),
  7439. chevronDown: register('chevron-down', 0xeab4),
  7440. chevronLeft: register('chevron-left', 0xeab5),
  7441. chevronRight: register('chevron-right', 0xeab6),
  7442. chevronUp: register('chevron-up', 0xeab7),
  7443. chromeClose: register('chrome-close', 0xeab8),
  7444. chromeMaximize: register('chrome-maximize', 0xeab9),
  7445. chromeMinimize: register('chrome-minimize', 0xeaba),
  7446. chromeRestore: register('chrome-restore', 0xeabb),
  7447. circleOutline: register('circle-outline', 0xeabc),
  7448. circle: register('circle', 0xeabc),
  7449. debugBreakpointUnverified: register('debug-breakpoint-unverified', 0xeabc),
  7450. terminalDecorationIncomplete: register('terminal-decoration-incomplete', 0xeabc),
  7451. circleSlash: register('circle-slash', 0xeabd),
  7452. circuitBoard: register('circuit-board', 0xeabe),
  7453. clearAll: register('clear-all', 0xeabf),
  7454. clippy: register('clippy', 0xeac0),
  7455. closeAll: register('close-all', 0xeac1),
  7456. cloudDownload: register('cloud-download', 0xeac2),
  7457. cloudUpload: register('cloud-upload', 0xeac3),
  7458. code: register('code', 0xeac4),
  7459. collapseAll: register('collapse-all', 0xeac5),
  7460. colorMode: register('color-mode', 0xeac6),
  7461. commentDiscussion: register('comment-discussion', 0xeac7),
  7462. creditCard: register('credit-card', 0xeac9),
  7463. dash: register('dash', 0xeacc),
  7464. dashboard: register('dashboard', 0xeacd),
  7465. database: register('database', 0xeace),
  7466. debugContinue: register('debug-continue', 0xeacf),
  7467. debugDisconnect: register('debug-disconnect', 0xead0),
  7468. debugPause: register('debug-pause', 0xead1),
  7469. debugRestart: register('debug-restart', 0xead2),
  7470. debugStart: register('debug-start', 0xead3),
  7471. debugStepInto: register('debug-step-into', 0xead4),
  7472. debugStepOut: register('debug-step-out', 0xead5),
  7473. debugStepOver: register('debug-step-over', 0xead6),
  7474. debugStop: register('debug-stop', 0xead7),
  7475. debug: register('debug', 0xead8),
  7476. deviceCameraVideo: register('device-camera-video', 0xead9),
  7477. deviceCamera: register('device-camera', 0xeada),
  7478. deviceMobile: register('device-mobile', 0xeadb),
  7479. diffAdded: register('diff-added', 0xeadc),
  7480. diffIgnored: register('diff-ignored', 0xeadd),
  7481. diffModified: register('diff-modified', 0xeade),
  7482. diffRemoved: register('diff-removed', 0xeadf),
  7483. diffRenamed: register('diff-renamed', 0xeae0),
  7484. diff: register('diff', 0xeae1),
  7485. diffSidebyside: register('diff-sidebyside', 0xeae1),
  7486. discard: register('discard', 0xeae2),
  7487. editorLayout: register('editor-layout', 0xeae3),
  7488. emptyWindow: register('empty-window', 0xeae4),
  7489. exclude: register('exclude', 0xeae5),
  7490. extensions: register('extensions', 0xeae6),
  7491. eyeClosed: register('eye-closed', 0xeae7),
  7492. fileBinary: register('file-binary', 0xeae8),
  7493. fileCode: register('file-code', 0xeae9),
  7494. fileMedia: register('file-media', 0xeaea),
  7495. filePdf: register('file-pdf', 0xeaeb),
  7496. fileSubmodule: register('file-submodule', 0xeaec),
  7497. fileSymlinkDirectory: register('file-symlink-directory', 0xeaed),
  7498. fileSymlinkFile: register('file-symlink-file', 0xeaee),
  7499. fileZip: register('file-zip', 0xeaef),
  7500. files: register('files', 0xeaf0),
  7501. filter: register('filter', 0xeaf1),
  7502. flame: register('flame', 0xeaf2),
  7503. foldDown: register('fold-down', 0xeaf3),
  7504. foldUp: register('fold-up', 0xeaf4),
  7505. fold: register('fold', 0xeaf5),
  7506. folderActive: register('folder-active', 0xeaf6),
  7507. folderOpened: register('folder-opened', 0xeaf7),
  7508. gear: register('gear', 0xeaf8),
  7509. gift: register('gift', 0xeaf9),
  7510. gistSecret: register('gist-secret', 0xeafa),
  7511. gist: register('gist', 0xeafb),
  7512. gitCommit: register('git-commit', 0xeafc),
  7513. gitCompare: register('git-compare', 0xeafd),
  7514. compareChanges: register('compare-changes', 0xeafd),
  7515. gitMerge: register('git-merge', 0xeafe),
  7516. githubAction: register('github-action', 0xeaff),
  7517. githubAlt: register('github-alt', 0xeb00),
  7518. globe: register('globe', 0xeb01),
  7519. grabber: register('grabber', 0xeb02),
  7520. graph: register('graph', 0xeb03),
  7521. gripper: register('gripper', 0xeb04),
  7522. heart: register('heart', 0xeb05),
  7523. home: register('home', 0xeb06),
  7524. horizontalRule: register('horizontal-rule', 0xeb07),
  7525. hubot: register('hubot', 0xeb08),
  7526. inbox: register('inbox', 0xeb09),
  7527. issueReopened: register('issue-reopened', 0xeb0b),
  7528. issues: register('issues', 0xeb0c),
  7529. italic: register('italic', 0xeb0d),
  7530. jersey: register('jersey', 0xeb0e),
  7531. json: register('json', 0xeb0f),
  7532. kebabVertical: register('kebab-vertical', 0xeb10),
  7533. key: register('key', 0xeb11),
  7534. law: register('law', 0xeb12),
  7535. lightbulbAutofix: register('lightbulb-autofix', 0xeb13),
  7536. linkExternal: register('link-external', 0xeb14),
  7537. link: register('link', 0xeb15),
  7538. listOrdered: register('list-ordered', 0xeb16),
  7539. listUnordered: register('list-unordered', 0xeb17),
  7540. liveShare: register('live-share', 0xeb18),
  7541. loading: register('loading', 0xeb19),
  7542. location: register('location', 0xeb1a),
  7543. mailRead: register('mail-read', 0xeb1b),
  7544. mail: register('mail', 0xeb1c),
  7545. markdown: register('markdown', 0xeb1d),
  7546. megaphone: register('megaphone', 0xeb1e),
  7547. mention: register('mention', 0xeb1f),
  7548. milestone: register('milestone', 0xeb20),
  7549. gitPullRequestMilestone: register('git-pull-request-milestone', 0xeb20),
  7550. mortarBoard: register('mortar-board', 0xeb21),
  7551. move: register('move', 0xeb22),
  7552. multipleWindows: register('multiple-windows', 0xeb23),
  7553. mute: register('mute', 0xeb24),
  7554. noNewline: register('no-newline', 0xeb25),
  7555. note: register('note', 0xeb26),
  7556. octoface: register('octoface', 0xeb27),
  7557. openPreview: register('open-preview', 0xeb28),
  7558. package: register('package', 0xeb29),
  7559. paintcan: register('paintcan', 0xeb2a),
  7560. pin: register('pin', 0xeb2b),
  7561. play: register('play', 0xeb2c),
  7562. run: register('run', 0xeb2c),
  7563. plug: register('plug', 0xeb2d),
  7564. preserveCase: register('preserve-case', 0xeb2e),
  7565. preview: register('preview', 0xeb2f),
  7566. project: register('project', 0xeb30),
  7567. pulse: register('pulse', 0xeb31),
  7568. question: register('question', 0xeb32),
  7569. quote: register('quote', 0xeb33),
  7570. radioTower: register('radio-tower', 0xeb34),
  7571. reactions: register('reactions', 0xeb35),
  7572. references: register('references', 0xeb36),
  7573. refresh: register('refresh', 0xeb37),
  7574. regex: register('regex', 0xeb38),
  7575. remoteExplorer: register('remote-explorer', 0xeb39),
  7576. remote: register('remote', 0xeb3a),
  7577. remove: register('remove', 0xeb3b),
  7578. replaceAll: register('replace-all', 0xeb3c),
  7579. replace: register('replace', 0xeb3d),
  7580. repoClone: register('repo-clone', 0xeb3e),
  7581. repoForcePush: register('repo-force-push', 0xeb3f),
  7582. repoPull: register('repo-pull', 0xeb40),
  7583. repoPush: register('repo-push', 0xeb41),
  7584. report: register('report', 0xeb42),
  7585. requestChanges: register('request-changes', 0xeb43),
  7586. rocket: register('rocket', 0xeb44),
  7587. rootFolderOpened: register('root-folder-opened', 0xeb45),
  7588. rootFolder: register('root-folder', 0xeb46),
  7589. rss: register('rss', 0xeb47),
  7590. ruby: register('ruby', 0xeb48),
  7591. saveAll: register('save-all', 0xeb49),
  7592. saveAs: register('save-as', 0xeb4a),
  7593. save: register('save', 0xeb4b),
  7594. screenFull: register('screen-full', 0xeb4c),
  7595. screenNormal: register('screen-normal', 0xeb4d),
  7596. searchStop: register('search-stop', 0xeb4e),
  7597. server: register('server', 0xeb50),
  7598. settingsGear: register('settings-gear', 0xeb51),
  7599. settings: register('settings', 0xeb52),
  7600. shield: register('shield', 0xeb53),
  7601. smiley: register('smiley', 0xeb54),
  7602. sortPrecedence: register('sort-precedence', 0xeb55),
  7603. splitHorizontal: register('split-horizontal', 0xeb56),
  7604. splitVertical: register('split-vertical', 0xeb57),
  7605. squirrel: register('squirrel', 0xeb58),
  7606. starFull: register('star-full', 0xeb59),
  7607. starHalf: register('star-half', 0xeb5a),
  7608. symbolClass: register('symbol-class', 0xeb5b),
  7609. symbolColor: register('symbol-color', 0xeb5c),
  7610. symbolConstant: register('symbol-constant', 0xeb5d),
  7611. symbolEnumMember: register('symbol-enum-member', 0xeb5e),
  7612. symbolField: register('symbol-field', 0xeb5f),
  7613. symbolFile: register('symbol-file', 0xeb60),
  7614. symbolInterface: register('symbol-interface', 0xeb61),
  7615. symbolKeyword: register('symbol-keyword', 0xeb62),
  7616. symbolMisc: register('symbol-misc', 0xeb63),
  7617. symbolOperator: register('symbol-operator', 0xeb64),
  7618. symbolProperty: register('symbol-property', 0xeb65),
  7619. wrench: register('wrench', 0xeb65),
  7620. wrenchSubaction: register('wrench-subaction', 0xeb65),
  7621. symbolSnippet: register('symbol-snippet', 0xeb66),
  7622. tasklist: register('tasklist', 0xeb67),
  7623. telescope: register('telescope', 0xeb68),
  7624. textSize: register('text-size', 0xeb69),
  7625. threeBars: register('three-bars', 0xeb6a),
  7626. thumbsdown: register('thumbsdown', 0xeb6b),
  7627. thumbsup: register('thumbsup', 0xeb6c),
  7628. tools: register('tools', 0xeb6d),
  7629. triangleDown: register('triangle-down', 0xeb6e),
  7630. triangleLeft: register('triangle-left', 0xeb6f),
  7631. triangleRight: register('triangle-right', 0xeb70),
  7632. triangleUp: register('triangle-up', 0xeb71),
  7633. twitter: register('twitter', 0xeb72),
  7634. unfold: register('unfold', 0xeb73),
  7635. unlock: register('unlock', 0xeb74),
  7636. unmute: register('unmute', 0xeb75),
  7637. unverified: register('unverified', 0xeb76),
  7638. verified: register('verified', 0xeb77),
  7639. versions: register('versions', 0xeb78),
  7640. vmActive: register('vm-active', 0xeb79),
  7641. vmOutline: register('vm-outline', 0xeb7a),
  7642. vmRunning: register('vm-running', 0xeb7b),
  7643. watch: register('watch', 0xeb7c),
  7644. whitespace: register('whitespace', 0xeb7d),
  7645. wholeWord: register('whole-word', 0xeb7e),
  7646. window: register('window', 0xeb7f),
  7647. wordWrap: register('word-wrap', 0xeb80),
  7648. zoomIn: register('zoom-in', 0xeb81),
  7649. zoomOut: register('zoom-out', 0xeb82),
  7650. listFilter: register('list-filter', 0xeb83),
  7651. listFlat: register('list-flat', 0xeb84),
  7652. listSelection: register('list-selection', 0xeb85),
  7653. selection: register('selection', 0xeb85),
  7654. listTree: register('list-tree', 0xeb86),
  7655. debugBreakpointFunctionUnverified: register('debug-breakpoint-function-unverified', 0xeb87),
  7656. debugBreakpointFunction: register('debug-breakpoint-function', 0xeb88),
  7657. debugBreakpointFunctionDisabled: register('debug-breakpoint-function-disabled', 0xeb88),
  7658. debugStackframeActive: register('debug-stackframe-active', 0xeb89),
  7659. circleSmallFilled: register('circle-small-filled', 0xeb8a),
  7660. debugStackframeDot: register('debug-stackframe-dot', 0xeb8a),
  7661. terminalDecorationMark: register('terminal-decoration-mark', 0xeb8a),
  7662. debugStackframe: register('debug-stackframe', 0xeb8b),
  7663. debugStackframeFocused: register('debug-stackframe-focused', 0xeb8b),
  7664. debugBreakpointUnsupported: register('debug-breakpoint-unsupported', 0xeb8c),
  7665. symbolString: register('symbol-string', 0xeb8d),
  7666. debugReverseContinue: register('debug-reverse-continue', 0xeb8e),
  7667. debugStepBack: register('debug-step-back', 0xeb8f),
  7668. debugRestartFrame: register('debug-restart-frame', 0xeb90),
  7669. debugAlt: register('debug-alt', 0xeb91),
  7670. callIncoming: register('call-incoming', 0xeb92),
  7671. callOutgoing: register('call-outgoing', 0xeb93),
  7672. menu: register('menu', 0xeb94),
  7673. expandAll: register('expand-all', 0xeb95),
  7674. feedback: register('feedback', 0xeb96),
  7675. gitPullRequestReviewer: register('git-pull-request-reviewer', 0xeb96),
  7676. groupByRefType: register('group-by-ref-type', 0xeb97),
  7677. ungroupByRefType: register('ungroup-by-ref-type', 0xeb98),
  7678. account: register('account', 0xeb99),
  7679. gitPullRequestAssignee: register('git-pull-request-assignee', 0xeb99),
  7680. bellDot: register('bell-dot', 0xeb9a),
  7681. debugConsole: register('debug-console', 0xeb9b),
  7682. library: register('library', 0xeb9c),
  7683. output: register('output', 0xeb9d),
  7684. runAll: register('run-all', 0xeb9e),
  7685. syncIgnored: register('sync-ignored', 0xeb9f),
  7686. pinned: register('pinned', 0xeba0),
  7687. githubInverted: register('github-inverted', 0xeba1),
  7688. serverProcess: register('server-process', 0xeba2),
  7689. serverEnvironment: register('server-environment', 0xeba3),
  7690. pass: register('pass', 0xeba4),
  7691. issueClosed: register('issue-closed', 0xeba4),
  7692. stopCircle: register('stop-circle', 0xeba5),
  7693. playCircle: register('play-circle', 0xeba6),
  7694. record: register('record', 0xeba7),
  7695. debugAltSmall: register('debug-alt-small', 0xeba8),
  7696. vmConnect: register('vm-connect', 0xeba9),
  7697. cloud: register('cloud', 0xebaa),
  7698. merge: register('merge', 0xebab),
  7699. export: register('export', 0xebac),
  7700. graphLeft: register('graph-left', 0xebad),
  7701. magnet: register('magnet', 0xebae),
  7702. notebook: register('notebook', 0xebaf),
  7703. redo: register('redo', 0xebb0),
  7704. checkAll: register('check-all', 0xebb1),
  7705. pinnedDirty: register('pinned-dirty', 0xebb2),
  7706. passFilled: register('pass-filled', 0xebb3),
  7707. circleLargeFilled: register('circle-large-filled', 0xebb4),
  7708. circleLarge: register('circle-large', 0xebb5),
  7709. circleLargeOutline: register('circle-large-outline', 0xebb5),
  7710. combine: register('combine', 0xebb6),
  7711. gather: register('gather', 0xebb6),
  7712. table: register('table', 0xebb7),
  7713. variableGroup: register('variable-group', 0xebb8),
  7714. typeHierarchy: register('type-hierarchy', 0xebb9),
  7715. typeHierarchySub: register('type-hierarchy-sub', 0xebba),
  7716. typeHierarchySuper: register('type-hierarchy-super', 0xebbb),
  7717. gitPullRequestCreate: register('git-pull-request-create', 0xebbc),
  7718. runAbove: register('run-above', 0xebbd),
  7719. runBelow: register('run-below', 0xebbe),
  7720. notebookTemplate: register('notebook-template', 0xebbf),
  7721. debugRerun: register('debug-rerun', 0xebc0),
  7722. workspaceTrusted: register('workspace-trusted', 0xebc1),
  7723. workspaceUntrusted: register('workspace-untrusted', 0xebc2),
  7724. workspaceUnknown: register('workspace-unknown', 0xebc3),
  7725. terminalCmd: register('terminal-cmd', 0xebc4),
  7726. terminalDebian: register('terminal-debian', 0xebc5),
  7727. terminalLinux: register('terminal-linux', 0xebc6),
  7728. terminalPowershell: register('terminal-powershell', 0xebc7),
  7729. terminalTmux: register('terminal-tmux', 0xebc8),
  7730. terminalUbuntu: register('terminal-ubuntu', 0xebc9),
  7731. terminalBash: register('terminal-bash', 0xebca),
  7732. arrowSwap: register('arrow-swap', 0xebcb),
  7733. copy: register('copy', 0xebcc),
  7734. personAdd: register('person-add', 0xebcd),
  7735. filterFilled: register('filter-filled', 0xebce),
  7736. wand: register('wand', 0xebcf),
  7737. debugLineByLine: register('debug-line-by-line', 0xebd0),
  7738. inspect: register('inspect', 0xebd1),
  7739. layers: register('layers', 0xebd2),
  7740. layersDot: register('layers-dot', 0xebd3),
  7741. layersActive: register('layers-active', 0xebd4),
  7742. compass: register('compass', 0xebd5),
  7743. compassDot: register('compass-dot', 0xebd6),
  7744. compassActive: register('compass-active', 0xebd7),
  7745. azure: register('azure', 0xebd8),
  7746. issueDraft: register('issue-draft', 0xebd9),
  7747. gitPullRequestClosed: register('git-pull-request-closed', 0xebda),
  7748. gitPullRequestDraft: register('git-pull-request-draft', 0xebdb),
  7749. debugAll: register('debug-all', 0xebdc),
  7750. debugCoverage: register('debug-coverage', 0xebdd),
  7751. runErrors: register('run-errors', 0xebde),
  7752. folderLibrary: register('folder-library', 0xebdf),
  7753. debugContinueSmall: register('debug-continue-small', 0xebe0),
  7754. beakerStop: register('beaker-stop', 0xebe1),
  7755. graphLine: register('graph-line', 0xebe2),
  7756. graphScatter: register('graph-scatter', 0xebe3),
  7757. pieChart: register('pie-chart', 0xebe4),
  7758. bracket: register('bracket', 0xeb0f),
  7759. bracketDot: register('bracket-dot', 0xebe5),
  7760. bracketError: register('bracket-error', 0xebe6),
  7761. lockSmall: register('lock-small', 0xebe7),
  7762. azureDevops: register('azure-devops', 0xebe8),
  7763. verifiedFilled: register('verified-filled', 0xebe9),
  7764. newline: register('newline', 0xebea),
  7765. layout: register('layout', 0xebeb),
  7766. layoutActivitybarLeft: register('layout-activitybar-left', 0xebec),
  7767. layoutActivitybarRight: register('layout-activitybar-right', 0xebed),
  7768. layoutPanelLeft: register('layout-panel-left', 0xebee),
  7769. layoutPanelCenter: register('layout-panel-center', 0xebef),
  7770. layoutPanelJustify: register('layout-panel-justify', 0xebf0),
  7771. layoutPanelRight: register('layout-panel-right', 0xebf1),
  7772. layoutPanel: register('layout-panel', 0xebf2),
  7773. layoutSidebarLeft: register('layout-sidebar-left', 0xebf3),
  7774. layoutSidebarRight: register('layout-sidebar-right', 0xebf4),
  7775. layoutStatusbar: register('layout-statusbar', 0xebf5),
  7776. layoutMenubar: register('layout-menubar', 0xebf6),
  7777. layoutCentered: register('layout-centered', 0xebf7),
  7778. target: register('target', 0xebf8),
  7779. indent: register('indent', 0xebf9),
  7780. recordSmall: register('record-small', 0xebfa),
  7781. errorSmall: register('error-small', 0xebfb),
  7782. terminalDecorationError: register('terminal-decoration-error', 0xebfb),
  7783. arrowCircleDown: register('arrow-circle-down', 0xebfc),
  7784. arrowCircleLeft: register('arrow-circle-left', 0xebfd),
  7785. arrowCircleRight: register('arrow-circle-right', 0xebfe),
  7786. arrowCircleUp: register('arrow-circle-up', 0xebff),
  7787. layoutSidebarRightOff: register('layout-sidebar-right-off', 0xec00),
  7788. layoutPanelOff: register('layout-panel-off', 0xec01),
  7789. layoutSidebarLeftOff: register('layout-sidebar-left-off', 0xec02),
  7790. blank: register('blank', 0xec03),
  7791. heartFilled: register('heart-filled', 0xec04),
  7792. map: register('map', 0xec05),
  7793. mapHorizontal: register('map-horizontal', 0xec05),
  7794. foldHorizontal: register('fold-horizontal', 0xec05),
  7795. mapFilled: register('map-filled', 0xec06),
  7796. mapHorizontalFilled: register('map-horizontal-filled', 0xec06),
  7797. foldHorizontalFilled: register('fold-horizontal-filled', 0xec06),
  7798. circleSmall: register('circle-small', 0xec07),
  7799. bellSlash: register('bell-slash', 0xec08),
  7800. bellSlashDot: register('bell-slash-dot', 0xec09),
  7801. commentUnresolved: register('comment-unresolved', 0xec0a),
  7802. gitPullRequestGoToChanges: register('git-pull-request-go-to-changes', 0xec0b),
  7803. gitPullRequestNewChanges: register('git-pull-request-new-changes', 0xec0c),
  7804. searchFuzzy: register('search-fuzzy', 0xec0d),
  7805. commentDraft: register('comment-draft', 0xec0e),
  7806. send: register('send', 0xec0f),
  7807. sparkle: register('sparkle', 0xec10),
  7808. insert: register('insert', 0xec11),
  7809. mic: register('mic', 0xec12),
  7810. thumbsdownFilled: register('thumbsdown-filled', 0xec13),
  7811. thumbsupFilled: register('thumbsup-filled', 0xec14),
  7812. coffee: register('coffee', 0xec15),
  7813. snake: register('snake', 0xec16),
  7814. game: register('game', 0xec17),
  7815. vr: register('vr', 0xec18),
  7816. chip: register('chip', 0xec19),
  7817. piano: register('piano', 0xec1a),
  7818. music: register('music', 0xec1b),
  7819. micFilled: register('mic-filled', 0xec1c),
  7820. repoFetch: register('repo-fetch', 0xec1d),
  7821. copilot: register('copilot', 0xec1e),
  7822. lightbulbSparkle: register('lightbulb-sparkle', 0xec1f),
  7823. robot: register('robot', 0xec20),
  7824. sparkleFilled: register('sparkle-filled', 0xec21),
  7825. diffSingle: register('diff-single', 0xec22),
  7826. diffMultiple: register('diff-multiple', 0xec23),
  7827. surroundWith: register('surround-with', 0xec24),
  7828. share: register('share', 0xec25),
  7829. gitStash: register('git-stash', 0xec26),
  7830. gitStashApply: register('git-stash-apply', 0xec27),
  7831. gitStashPop: register('git-stash-pop', 0xec28),
  7832. vscode: register('vscode', 0xec29),
  7833. vscodeInsiders: register('vscode-insiders', 0xec2a),
  7834. codeOss: register('code-oss', 0xec2b),
  7835. runCoverage: register('run-coverage', 0xec2c),
  7836. runAllCoverage: register('run-all-coverage', 0xec2d),
  7837. coverage: register('coverage', 0xec2e),
  7838. githubProject: register('github-project', 0xec2f),
  7839. mapVertical: register('map-vertical', 0xec30),
  7840. foldVertical: register('fold-vertical', 0xec30),
  7841. mapVerticalFilled: register('map-vertical-filled', 0xec31),
  7842. foldVerticalFilled: register('fold-vertical-filled', 0xec31),
  7843. goToSearch: register('go-to-search', 0xec32),
  7844. percentage: register('percentage', 0xec33),
  7845. sortPercentage: register('sort-percentage', 0xec33),
  7846. attach: register('attach', 0xec34),
  7847. };
  7848. /**
  7849. * Derived icons, that could become separate icons.
  7850. * These mappings should be moved into the mapping file in the vscode-codicons repo at some point.
  7851. */
  7852. const codiconsDerived = {
  7853. dialogError: register('dialog-error', 'error'),
  7854. dialogWarning: register('dialog-warning', 'warning'),
  7855. dialogInfo: register('dialog-info', 'info'),
  7856. dialogClose: register('dialog-close', 'close'),
  7857. treeItemExpanded: register('tree-item-expanded', 'chevron-down'), // collapsed is done with rotation
  7858. treeFilterOnTypeOn: register('tree-filter-on-type-on', 'list-filter'),
  7859. treeFilterOnTypeOff: register('tree-filter-on-type-off', 'list-selection'),
  7860. treeFilterClear: register('tree-filter-clear', 'close'),
  7861. treeItemLoading: register('tree-item-loading', 'loading'),
  7862. menuSelection: register('menu-selection', 'check'),
  7863. menuSubmenu: register('menu-submenu', 'chevron-right'),
  7864. menuBarMore: register('menubar-more', 'more'),
  7865. scrollbarButtonLeft: register('scrollbar-button-left', 'triangle-left'),
  7866. scrollbarButtonRight: register('scrollbar-button-right', 'triangle-right'),
  7867. scrollbarButtonUp: register('scrollbar-button-up', 'triangle-up'),
  7868. scrollbarButtonDown: register('scrollbar-button-down', 'triangle-down'),
  7869. toolBarMore: register('toolbar-more', 'more'),
  7870. quickInputBack: register('quick-input-back', 'arrow-left'),
  7871. dropDownButton: register('drop-down-button', 0xeab4),
  7872. symbolCustomColor: register('symbol-customcolor', 0xeb5c),
  7873. exportIcon: register('export', 0xebac),
  7874. workspaceUnspecified: register('workspace-unspecified', 0xebc3),
  7875. newLine: register('newline', 0xebea),
  7876. thumbsDownFilled: register('thumbsdown-filled', 0xec13),
  7877. thumbsUpFilled: register('thumbsup-filled', 0xec14),
  7878. gitFetch: register('git-fetch', 0xec1d),
  7879. lightbulbSparkleAutofix: register('lightbulb-sparkle-autofix', 0xec1f),
  7880. debugBreakpointPending: register('debug-breakpoint-pending', 0xebd9),
  7881. };
  7882. /**
  7883. * The Codicon library is a set of default icons that are built-in in VS Code.
  7884. *
  7885. * In the product (outside of base) Codicons should only be used as defaults. In order to have all icons in VS Code
  7886. * themeable, component should define new, UI component specific icons using `iconRegistry.registerIcon`.
  7887. * In that call a Codicon can be named as default.
  7888. */
  7889. const Codicon = {
  7890. ...codiconsLibrary,
  7891. ...codiconsDerived
  7892. };
  7893. /*---------------------------------------------------------------------------------------------
  7894. * Copyright (c) Microsoft Corporation. All rights reserved.
  7895. * Licensed under the MIT License. See License.txt in the project root for license information.
  7896. *--------------------------------------------------------------------------------------------*/
  7897. class TokenizationRegistry {
  7898. constructor() {
  7899. this._tokenizationSupports = new Map();
  7900. this._factories = new Map();
  7901. this._onDidChange = new Emitter();
  7902. this.onDidChange = this._onDidChange.event;
  7903. this._colorMap = null;
  7904. }
  7905. handleChange(languageIds) {
  7906. this._onDidChange.fire({
  7907. changedLanguages: languageIds,
  7908. changedColorMap: false
  7909. });
  7910. }
  7911. register(languageId, support) {
  7912. this._tokenizationSupports.set(languageId, support);
  7913. this.handleChange([languageId]);
  7914. return toDisposable(() => {
  7915. if (this._tokenizationSupports.get(languageId) !== support) {
  7916. return;
  7917. }
  7918. this._tokenizationSupports.delete(languageId);
  7919. this.handleChange([languageId]);
  7920. });
  7921. }
  7922. get(languageId) {
  7923. return this._tokenizationSupports.get(languageId) || null;
  7924. }
  7925. registerFactory(languageId, factory) {
  7926. this._factories.get(languageId)?.dispose();
  7927. const myData = new TokenizationSupportFactoryData(this, languageId, factory);
  7928. this._factories.set(languageId, myData);
  7929. return toDisposable(() => {
  7930. const v = this._factories.get(languageId);
  7931. if (!v || v !== myData) {
  7932. return;
  7933. }
  7934. this._factories.delete(languageId);
  7935. v.dispose();
  7936. });
  7937. }
  7938. async getOrCreate(languageId) {
  7939. // check first if the support is already set
  7940. const tokenizationSupport = this.get(languageId);
  7941. if (tokenizationSupport) {
  7942. return tokenizationSupport;
  7943. }
  7944. const factory = this._factories.get(languageId);
  7945. if (!factory || factory.isResolved) {
  7946. // no factory or factory.resolve already finished
  7947. return null;
  7948. }
  7949. await factory.resolve();
  7950. return this.get(languageId);
  7951. }
  7952. isResolved(languageId) {
  7953. const tokenizationSupport = this.get(languageId);
  7954. if (tokenizationSupport) {
  7955. return true;
  7956. }
  7957. const factory = this._factories.get(languageId);
  7958. if (!factory || factory.isResolved) {
  7959. return true;
  7960. }
  7961. return false;
  7962. }
  7963. setColorMap(colorMap) {
  7964. this._colorMap = colorMap;
  7965. this._onDidChange.fire({
  7966. changedLanguages: Array.from(this._tokenizationSupports.keys()),
  7967. changedColorMap: true
  7968. });
  7969. }
  7970. getColorMap() {
  7971. return this._colorMap;
  7972. }
  7973. getDefaultBackground() {
  7974. if (this._colorMap && this._colorMap.length > 2 /* ColorId.DefaultBackground */) {
  7975. return this._colorMap[2 /* ColorId.DefaultBackground */];
  7976. }
  7977. return null;
  7978. }
  7979. }
  7980. class TokenizationSupportFactoryData extends Disposable {
  7981. get isResolved() {
  7982. return this._isResolved;
  7983. }
  7984. constructor(_registry, _languageId, _factory) {
  7985. super();
  7986. this._registry = _registry;
  7987. this._languageId = _languageId;
  7988. this._factory = _factory;
  7989. this._isDisposed = false;
  7990. this._resolvePromise = null;
  7991. this._isResolved = false;
  7992. }
  7993. dispose() {
  7994. this._isDisposed = true;
  7995. super.dispose();
  7996. }
  7997. async resolve() {
  7998. if (!this._resolvePromise) {
  7999. this._resolvePromise = this._create();
  8000. }
  8001. return this._resolvePromise;
  8002. }
  8003. async _create() {
  8004. const value = await this._factory.tokenizationSupport;
  8005. this._isResolved = true;
  8006. if (value && !this._isDisposed) {
  8007. this._register(this._registry.register(this._languageId, value));
  8008. }
  8009. }
  8010. }
  8011. class Token {
  8012. constructor(offset, type, language) {
  8013. this.offset = offset;
  8014. this.type = type;
  8015. this.language = language;
  8016. this._tokenBrand = undefined;
  8017. }
  8018. toString() {
  8019. return '(' + this.offset + ', ' + this.type + ')';
  8020. }
  8021. }
  8022. var HoverVerbosityAction$1;
  8023. (function (HoverVerbosityAction) {
  8024. /**
  8025. * Increase the verbosity of the hover
  8026. */
  8027. HoverVerbosityAction[HoverVerbosityAction["Increase"] = 0] = "Increase";
  8028. /**
  8029. * Decrease the verbosity of the hover
  8030. */
  8031. HoverVerbosityAction[HoverVerbosityAction["Decrease"] = 1] = "Decrease";
  8032. })(HoverVerbosityAction$1 || (HoverVerbosityAction$1 = {}));
  8033. /**
  8034. * @internal
  8035. */
  8036. var CompletionItemKinds;
  8037. (function (CompletionItemKinds) {
  8038. const byKind = new Map();
  8039. byKind.set(0 /* CompletionItemKind.Method */, Codicon.symbolMethod);
  8040. byKind.set(1 /* CompletionItemKind.Function */, Codicon.symbolFunction);
  8041. byKind.set(2 /* CompletionItemKind.Constructor */, Codicon.symbolConstructor);
  8042. byKind.set(3 /* CompletionItemKind.Field */, Codicon.symbolField);
  8043. byKind.set(4 /* CompletionItemKind.Variable */, Codicon.symbolVariable);
  8044. byKind.set(5 /* CompletionItemKind.Class */, Codicon.symbolClass);
  8045. byKind.set(6 /* CompletionItemKind.Struct */, Codicon.symbolStruct);
  8046. byKind.set(7 /* CompletionItemKind.Interface */, Codicon.symbolInterface);
  8047. byKind.set(8 /* CompletionItemKind.Module */, Codicon.symbolModule);
  8048. byKind.set(9 /* CompletionItemKind.Property */, Codicon.symbolProperty);
  8049. byKind.set(10 /* CompletionItemKind.Event */, Codicon.symbolEvent);
  8050. byKind.set(11 /* CompletionItemKind.Operator */, Codicon.symbolOperator);
  8051. byKind.set(12 /* CompletionItemKind.Unit */, Codicon.symbolUnit);
  8052. byKind.set(13 /* CompletionItemKind.Value */, Codicon.symbolValue);
  8053. byKind.set(15 /* CompletionItemKind.Enum */, Codicon.symbolEnum);
  8054. byKind.set(14 /* CompletionItemKind.Constant */, Codicon.symbolConstant);
  8055. byKind.set(15 /* CompletionItemKind.Enum */, Codicon.symbolEnum);
  8056. byKind.set(16 /* CompletionItemKind.EnumMember */, Codicon.symbolEnumMember);
  8057. byKind.set(17 /* CompletionItemKind.Keyword */, Codicon.symbolKeyword);
  8058. byKind.set(27 /* CompletionItemKind.Snippet */, Codicon.symbolSnippet);
  8059. byKind.set(18 /* CompletionItemKind.Text */, Codicon.symbolText);
  8060. byKind.set(19 /* CompletionItemKind.Color */, Codicon.symbolColor);
  8061. byKind.set(20 /* CompletionItemKind.File */, Codicon.symbolFile);
  8062. byKind.set(21 /* CompletionItemKind.Reference */, Codicon.symbolReference);
  8063. byKind.set(22 /* CompletionItemKind.Customcolor */, Codicon.symbolCustomColor);
  8064. byKind.set(23 /* CompletionItemKind.Folder */, Codicon.symbolFolder);
  8065. byKind.set(24 /* CompletionItemKind.TypeParameter */, Codicon.symbolTypeParameter);
  8066. byKind.set(25 /* CompletionItemKind.User */, Codicon.account);
  8067. byKind.set(26 /* CompletionItemKind.Issue */, Codicon.issues);
  8068. /**
  8069. * @internal
  8070. */
  8071. function toIcon(kind) {
  8072. let codicon = byKind.get(kind);
  8073. if (!codicon) {
  8074. console.info('No codicon found for CompletionItemKind ' + kind);
  8075. codicon = Codicon.symbolProperty;
  8076. }
  8077. return codicon;
  8078. }
  8079. CompletionItemKinds.toIcon = toIcon;
  8080. const data = new Map();
  8081. data.set('method', 0 /* CompletionItemKind.Method */);
  8082. data.set('function', 1 /* CompletionItemKind.Function */);
  8083. data.set('constructor', 2 /* CompletionItemKind.Constructor */);
  8084. data.set('field', 3 /* CompletionItemKind.Field */);
  8085. data.set('variable', 4 /* CompletionItemKind.Variable */);
  8086. data.set('class', 5 /* CompletionItemKind.Class */);
  8087. data.set('struct', 6 /* CompletionItemKind.Struct */);
  8088. data.set('interface', 7 /* CompletionItemKind.Interface */);
  8089. data.set('module', 8 /* CompletionItemKind.Module */);
  8090. data.set('property', 9 /* CompletionItemKind.Property */);
  8091. data.set('event', 10 /* CompletionItemKind.Event */);
  8092. data.set('operator', 11 /* CompletionItemKind.Operator */);
  8093. data.set('unit', 12 /* CompletionItemKind.Unit */);
  8094. data.set('value', 13 /* CompletionItemKind.Value */);
  8095. data.set('constant', 14 /* CompletionItemKind.Constant */);
  8096. data.set('enum', 15 /* CompletionItemKind.Enum */);
  8097. data.set('enum-member', 16 /* CompletionItemKind.EnumMember */);
  8098. data.set('enumMember', 16 /* CompletionItemKind.EnumMember */);
  8099. data.set('keyword', 17 /* CompletionItemKind.Keyword */);
  8100. data.set('snippet', 27 /* CompletionItemKind.Snippet */);
  8101. data.set('text', 18 /* CompletionItemKind.Text */);
  8102. data.set('color', 19 /* CompletionItemKind.Color */);
  8103. data.set('file', 20 /* CompletionItemKind.File */);
  8104. data.set('reference', 21 /* CompletionItemKind.Reference */);
  8105. data.set('customcolor', 22 /* CompletionItemKind.Customcolor */);
  8106. data.set('folder', 23 /* CompletionItemKind.Folder */);
  8107. data.set('type-parameter', 24 /* CompletionItemKind.TypeParameter */);
  8108. data.set('typeParameter', 24 /* CompletionItemKind.TypeParameter */);
  8109. data.set('account', 25 /* CompletionItemKind.User */);
  8110. data.set('issue', 26 /* CompletionItemKind.Issue */);
  8111. /**
  8112. * @internal
  8113. */
  8114. function fromString(value, strict) {
  8115. let res = data.get(value);
  8116. if (typeof res === 'undefined' && !strict) {
  8117. res = 9 /* CompletionItemKind.Property */;
  8118. }
  8119. return res;
  8120. }
  8121. CompletionItemKinds.fromString = fromString;
  8122. })(CompletionItemKinds || (CompletionItemKinds = {}));
  8123. /**
  8124. * How an {@link InlineCompletionsProvider inline completion provider} was triggered.
  8125. */
  8126. var InlineCompletionTriggerKind$1;
  8127. (function (InlineCompletionTriggerKind) {
  8128. /**
  8129. * Completion was triggered automatically while editing.
  8130. * It is sufficient to return a single completion item in this case.
  8131. */
  8132. InlineCompletionTriggerKind[InlineCompletionTriggerKind["Automatic"] = 0] = "Automatic";
  8133. /**
  8134. * Completion was triggered explicitly by a user gesture.
  8135. * Return multiple completion items to enable cycling through them.
  8136. */
  8137. InlineCompletionTriggerKind[InlineCompletionTriggerKind["Explicit"] = 1] = "Explicit";
  8138. })(InlineCompletionTriggerKind$1 || (InlineCompletionTriggerKind$1 = {}));
  8139. /**
  8140. * @internal
  8141. */
  8142. var DocumentPasteTriggerKind;
  8143. (function (DocumentPasteTriggerKind) {
  8144. DocumentPasteTriggerKind[DocumentPasteTriggerKind["Automatic"] = 0] = "Automatic";
  8145. DocumentPasteTriggerKind[DocumentPasteTriggerKind["PasteAs"] = 1] = "PasteAs";
  8146. })(DocumentPasteTriggerKind || (DocumentPasteTriggerKind = {}));
  8147. var SignatureHelpTriggerKind$1;
  8148. (function (SignatureHelpTriggerKind) {
  8149. SignatureHelpTriggerKind[SignatureHelpTriggerKind["Invoke"] = 1] = "Invoke";
  8150. SignatureHelpTriggerKind[SignatureHelpTriggerKind["TriggerCharacter"] = 2] = "TriggerCharacter";
  8151. SignatureHelpTriggerKind[SignatureHelpTriggerKind["ContentChange"] = 3] = "ContentChange";
  8152. })(SignatureHelpTriggerKind$1 || (SignatureHelpTriggerKind$1 = {}));
  8153. /**
  8154. * A document highlight kind.
  8155. */
  8156. var DocumentHighlightKind$1;
  8157. (function (DocumentHighlightKind) {
  8158. /**
  8159. * A textual occurrence.
  8160. */
  8161. DocumentHighlightKind[DocumentHighlightKind["Text"] = 0] = "Text";
  8162. /**
  8163. * Read-access of a symbol, like reading a variable.
  8164. */
  8165. DocumentHighlightKind[DocumentHighlightKind["Read"] = 1] = "Read";
  8166. /**
  8167. * Write-access of a symbol, like writing to a variable.
  8168. */
  8169. DocumentHighlightKind[DocumentHighlightKind["Write"] = 2] = "Write";
  8170. })(DocumentHighlightKind$1 || (DocumentHighlightKind$1 = {}));
  8171. /**
  8172. * @internal
  8173. */
  8174. ({
  8175. [17 /* SymbolKind.Array */]: localize('Array', "array"),
  8176. [16 /* SymbolKind.Boolean */]: localize('Boolean', "boolean"),
  8177. [4 /* SymbolKind.Class */]: localize('Class', "class"),
  8178. [13 /* SymbolKind.Constant */]: localize('Constant', "constant"),
  8179. [8 /* SymbolKind.Constructor */]: localize('Constructor', "constructor"),
  8180. [9 /* SymbolKind.Enum */]: localize('Enum', "enumeration"),
  8181. [21 /* SymbolKind.EnumMember */]: localize('EnumMember', "enumeration member"),
  8182. [23 /* SymbolKind.Event */]: localize('Event', "event"),
  8183. [7 /* SymbolKind.Field */]: localize('Field', "field"),
  8184. [0 /* SymbolKind.File */]: localize('File', "file"),
  8185. [11 /* SymbolKind.Function */]: localize('Function', "function"),
  8186. [10 /* SymbolKind.Interface */]: localize('Interface', "interface"),
  8187. [19 /* SymbolKind.Key */]: localize('Key', "key"),
  8188. [5 /* SymbolKind.Method */]: localize('Method', "method"),
  8189. [1 /* SymbolKind.Module */]: localize('Module', "module"),
  8190. [2 /* SymbolKind.Namespace */]: localize('Namespace', "namespace"),
  8191. [20 /* SymbolKind.Null */]: localize('Null', "null"),
  8192. [15 /* SymbolKind.Number */]: localize('Number', "number"),
  8193. [18 /* SymbolKind.Object */]: localize('Object', "object"),
  8194. [24 /* SymbolKind.Operator */]: localize('Operator', "operator"),
  8195. [3 /* SymbolKind.Package */]: localize('Package', "package"),
  8196. [6 /* SymbolKind.Property */]: localize('Property', "property"),
  8197. [14 /* SymbolKind.String */]: localize('String', "string"),
  8198. [22 /* SymbolKind.Struct */]: localize('Struct', "struct"),
  8199. [25 /* SymbolKind.TypeParameter */]: localize('TypeParameter', "type parameter"),
  8200. [12 /* SymbolKind.Variable */]: localize('Variable', "variable"),
  8201. });
  8202. /**
  8203. * @internal
  8204. */
  8205. var SymbolKinds;
  8206. (function (SymbolKinds) {
  8207. const byKind = new Map();
  8208. byKind.set(0 /* SymbolKind.File */, Codicon.symbolFile);
  8209. byKind.set(1 /* SymbolKind.Module */, Codicon.symbolModule);
  8210. byKind.set(2 /* SymbolKind.Namespace */, Codicon.symbolNamespace);
  8211. byKind.set(3 /* SymbolKind.Package */, Codicon.symbolPackage);
  8212. byKind.set(4 /* SymbolKind.Class */, Codicon.symbolClass);
  8213. byKind.set(5 /* SymbolKind.Method */, Codicon.symbolMethod);
  8214. byKind.set(6 /* SymbolKind.Property */, Codicon.symbolProperty);
  8215. byKind.set(7 /* SymbolKind.Field */, Codicon.symbolField);
  8216. byKind.set(8 /* SymbolKind.Constructor */, Codicon.symbolConstructor);
  8217. byKind.set(9 /* SymbolKind.Enum */, Codicon.symbolEnum);
  8218. byKind.set(10 /* SymbolKind.Interface */, Codicon.symbolInterface);
  8219. byKind.set(11 /* SymbolKind.Function */, Codicon.symbolFunction);
  8220. byKind.set(12 /* SymbolKind.Variable */, Codicon.symbolVariable);
  8221. byKind.set(13 /* SymbolKind.Constant */, Codicon.symbolConstant);
  8222. byKind.set(14 /* SymbolKind.String */, Codicon.symbolString);
  8223. byKind.set(15 /* SymbolKind.Number */, Codicon.symbolNumber);
  8224. byKind.set(16 /* SymbolKind.Boolean */, Codicon.symbolBoolean);
  8225. byKind.set(17 /* SymbolKind.Array */, Codicon.symbolArray);
  8226. byKind.set(18 /* SymbolKind.Object */, Codicon.symbolObject);
  8227. byKind.set(19 /* SymbolKind.Key */, Codicon.symbolKey);
  8228. byKind.set(20 /* SymbolKind.Null */, Codicon.symbolNull);
  8229. byKind.set(21 /* SymbolKind.EnumMember */, Codicon.symbolEnumMember);
  8230. byKind.set(22 /* SymbolKind.Struct */, Codicon.symbolStruct);
  8231. byKind.set(23 /* SymbolKind.Event */, Codicon.symbolEvent);
  8232. byKind.set(24 /* SymbolKind.Operator */, Codicon.symbolOperator);
  8233. byKind.set(25 /* SymbolKind.TypeParameter */, Codicon.symbolTypeParameter);
  8234. /**
  8235. * @internal
  8236. */
  8237. function toIcon(kind) {
  8238. let icon = byKind.get(kind);
  8239. if (!icon) {
  8240. console.info('No codicon found for SymbolKind ' + kind);
  8241. icon = Codicon.symbolProperty;
  8242. }
  8243. return icon;
  8244. }
  8245. SymbolKinds.toIcon = toIcon;
  8246. })(SymbolKinds || (SymbolKinds = {}));
  8247. class FoldingRangeKind {
  8248. /**
  8249. * Kind for folding range representing a comment. The value of the kind is 'comment'.
  8250. */
  8251. static { this.Comment = new FoldingRangeKind('comment'); }
  8252. /**
  8253. * Kind for folding range representing a import. The value of the kind is 'imports'.
  8254. */
  8255. static { this.Imports = new FoldingRangeKind('imports'); }
  8256. /**
  8257. * Kind for folding range representing regions (for example marked by `#region`, `#endregion`).
  8258. * The value of the kind is 'region'.
  8259. */
  8260. static { this.Region = new FoldingRangeKind('region'); }
  8261. /**
  8262. * Returns a {@link FoldingRangeKind} for the given value.
  8263. *
  8264. * @param value of the kind.
  8265. */
  8266. static fromValue(value) {
  8267. switch (value) {
  8268. case 'comment': return FoldingRangeKind.Comment;
  8269. case 'imports': return FoldingRangeKind.Imports;
  8270. case 'region': return FoldingRangeKind.Region;
  8271. }
  8272. return new FoldingRangeKind(value);
  8273. }
  8274. /**
  8275. * Creates a new {@link FoldingRangeKind}.
  8276. *
  8277. * @param value of the kind.
  8278. */
  8279. constructor(value) {
  8280. this.value = value;
  8281. }
  8282. }
  8283. var NewSymbolNameTag$1;
  8284. (function (NewSymbolNameTag) {
  8285. NewSymbolNameTag[NewSymbolNameTag["AIGenerated"] = 1] = "AIGenerated";
  8286. })(NewSymbolNameTag$1 || (NewSymbolNameTag$1 = {}));
  8287. var NewSymbolNameTriggerKind$1;
  8288. (function (NewSymbolNameTriggerKind) {
  8289. NewSymbolNameTriggerKind[NewSymbolNameTriggerKind["Invoke"] = 0] = "Invoke";
  8290. NewSymbolNameTriggerKind[NewSymbolNameTriggerKind["Automatic"] = 1] = "Automatic";
  8291. })(NewSymbolNameTriggerKind$1 || (NewSymbolNameTriggerKind$1 = {}));
  8292. /**
  8293. * @internal
  8294. */
  8295. var Command;
  8296. (function (Command) {
  8297. /**
  8298. * @internal
  8299. */
  8300. function is(obj) {
  8301. if (!obj || typeof obj !== 'object') {
  8302. return false;
  8303. }
  8304. return typeof obj.id === 'string' &&
  8305. typeof obj.title === 'string';
  8306. }
  8307. Command.is = is;
  8308. })(Command || (Command = {}));
  8309. var InlayHintKind$1;
  8310. (function (InlayHintKind) {
  8311. InlayHintKind[InlayHintKind["Type"] = 1] = "Type";
  8312. InlayHintKind[InlayHintKind["Parameter"] = 2] = "Parameter";
  8313. })(InlayHintKind$1 || (InlayHintKind$1 = {}));
  8314. /**
  8315. * @internal
  8316. */
  8317. new TokenizationRegistry();
  8318. /**
  8319. * @internal
  8320. */
  8321. new TokenizationRegistry();
  8322. var InlineEditTriggerKind$1;
  8323. (function (InlineEditTriggerKind) {
  8324. InlineEditTriggerKind[InlineEditTriggerKind["Invoke"] = 0] = "Invoke";
  8325. InlineEditTriggerKind[InlineEditTriggerKind["Automatic"] = 1] = "Automatic";
  8326. })(InlineEditTriggerKind$1 || (InlineEditTriggerKind$1 = {}));
  8327. /*---------------------------------------------------------------------------------------------
  8328. * Copyright (c) Microsoft Corporation. All rights reserved.
  8329. * Licensed under the MIT License. See License.txt in the project root for license information.
  8330. *--------------------------------------------------------------------------------------------*/
  8331. // THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY.
  8332. var AccessibilitySupport;
  8333. (function (AccessibilitySupport) {
  8334. /**
  8335. * This should be the browser case where it is not known if a screen reader is attached or no.
  8336. */
  8337. AccessibilitySupport[AccessibilitySupport["Unknown"] = 0] = "Unknown";
  8338. AccessibilitySupport[AccessibilitySupport["Disabled"] = 1] = "Disabled";
  8339. AccessibilitySupport[AccessibilitySupport["Enabled"] = 2] = "Enabled";
  8340. })(AccessibilitySupport || (AccessibilitySupport = {}));
  8341. var CodeActionTriggerType;
  8342. (function (CodeActionTriggerType) {
  8343. CodeActionTriggerType[CodeActionTriggerType["Invoke"] = 1] = "Invoke";
  8344. CodeActionTriggerType[CodeActionTriggerType["Auto"] = 2] = "Auto";
  8345. })(CodeActionTriggerType || (CodeActionTriggerType = {}));
  8346. var CompletionItemInsertTextRule;
  8347. (function (CompletionItemInsertTextRule) {
  8348. CompletionItemInsertTextRule[CompletionItemInsertTextRule["None"] = 0] = "None";
  8349. /**
  8350. * Adjust whitespace/indentation of multiline insert texts to
  8351. * match the current line indentation.
  8352. */
  8353. CompletionItemInsertTextRule[CompletionItemInsertTextRule["KeepWhitespace"] = 1] = "KeepWhitespace";
  8354. /**
  8355. * `insertText` is a snippet.
  8356. */
  8357. CompletionItemInsertTextRule[CompletionItemInsertTextRule["InsertAsSnippet"] = 4] = "InsertAsSnippet";
  8358. })(CompletionItemInsertTextRule || (CompletionItemInsertTextRule = {}));
  8359. var CompletionItemKind;
  8360. (function (CompletionItemKind) {
  8361. CompletionItemKind[CompletionItemKind["Method"] = 0] = "Method";
  8362. CompletionItemKind[CompletionItemKind["Function"] = 1] = "Function";
  8363. CompletionItemKind[CompletionItemKind["Constructor"] = 2] = "Constructor";
  8364. CompletionItemKind[CompletionItemKind["Field"] = 3] = "Field";
  8365. CompletionItemKind[CompletionItemKind["Variable"] = 4] = "Variable";
  8366. CompletionItemKind[CompletionItemKind["Class"] = 5] = "Class";
  8367. CompletionItemKind[CompletionItemKind["Struct"] = 6] = "Struct";
  8368. CompletionItemKind[CompletionItemKind["Interface"] = 7] = "Interface";
  8369. CompletionItemKind[CompletionItemKind["Module"] = 8] = "Module";
  8370. CompletionItemKind[CompletionItemKind["Property"] = 9] = "Property";
  8371. CompletionItemKind[CompletionItemKind["Event"] = 10] = "Event";
  8372. CompletionItemKind[CompletionItemKind["Operator"] = 11] = "Operator";
  8373. CompletionItemKind[CompletionItemKind["Unit"] = 12] = "Unit";
  8374. CompletionItemKind[CompletionItemKind["Value"] = 13] = "Value";
  8375. CompletionItemKind[CompletionItemKind["Constant"] = 14] = "Constant";
  8376. CompletionItemKind[CompletionItemKind["Enum"] = 15] = "Enum";
  8377. CompletionItemKind[CompletionItemKind["EnumMember"] = 16] = "EnumMember";
  8378. CompletionItemKind[CompletionItemKind["Keyword"] = 17] = "Keyword";
  8379. CompletionItemKind[CompletionItemKind["Text"] = 18] = "Text";
  8380. CompletionItemKind[CompletionItemKind["Color"] = 19] = "Color";
  8381. CompletionItemKind[CompletionItemKind["File"] = 20] = "File";
  8382. CompletionItemKind[CompletionItemKind["Reference"] = 21] = "Reference";
  8383. CompletionItemKind[CompletionItemKind["Customcolor"] = 22] = "Customcolor";
  8384. CompletionItemKind[CompletionItemKind["Folder"] = 23] = "Folder";
  8385. CompletionItemKind[CompletionItemKind["TypeParameter"] = 24] = "TypeParameter";
  8386. CompletionItemKind[CompletionItemKind["User"] = 25] = "User";
  8387. CompletionItemKind[CompletionItemKind["Issue"] = 26] = "Issue";
  8388. CompletionItemKind[CompletionItemKind["Snippet"] = 27] = "Snippet";
  8389. })(CompletionItemKind || (CompletionItemKind = {}));
  8390. var CompletionItemTag;
  8391. (function (CompletionItemTag) {
  8392. CompletionItemTag[CompletionItemTag["Deprecated"] = 1] = "Deprecated";
  8393. })(CompletionItemTag || (CompletionItemTag = {}));
  8394. /**
  8395. * How a suggest provider was triggered.
  8396. */
  8397. var CompletionTriggerKind;
  8398. (function (CompletionTriggerKind) {
  8399. CompletionTriggerKind[CompletionTriggerKind["Invoke"] = 0] = "Invoke";
  8400. CompletionTriggerKind[CompletionTriggerKind["TriggerCharacter"] = 1] = "TriggerCharacter";
  8401. CompletionTriggerKind[CompletionTriggerKind["TriggerForIncompleteCompletions"] = 2] = "TriggerForIncompleteCompletions";
  8402. })(CompletionTriggerKind || (CompletionTriggerKind = {}));
  8403. /**
  8404. * A positioning preference for rendering content widgets.
  8405. */
  8406. var ContentWidgetPositionPreference;
  8407. (function (ContentWidgetPositionPreference) {
  8408. /**
  8409. * Place the content widget exactly at a position
  8410. */
  8411. ContentWidgetPositionPreference[ContentWidgetPositionPreference["EXACT"] = 0] = "EXACT";
  8412. /**
  8413. * Place the content widget above a position
  8414. */
  8415. ContentWidgetPositionPreference[ContentWidgetPositionPreference["ABOVE"] = 1] = "ABOVE";
  8416. /**
  8417. * Place the content widget below a position
  8418. */
  8419. ContentWidgetPositionPreference[ContentWidgetPositionPreference["BELOW"] = 2] = "BELOW";
  8420. })(ContentWidgetPositionPreference || (ContentWidgetPositionPreference = {}));
  8421. /**
  8422. * Describes the reason the cursor has changed its position.
  8423. */
  8424. var CursorChangeReason;
  8425. (function (CursorChangeReason) {
  8426. /**
  8427. * Unknown or not set.
  8428. */
  8429. CursorChangeReason[CursorChangeReason["NotSet"] = 0] = "NotSet";
  8430. /**
  8431. * A `model.setValue()` was called.
  8432. */
  8433. CursorChangeReason[CursorChangeReason["ContentFlush"] = 1] = "ContentFlush";
  8434. /**
  8435. * The `model` has been changed outside of this cursor and the cursor recovers its position from associated markers.
  8436. */
  8437. CursorChangeReason[CursorChangeReason["RecoverFromMarkers"] = 2] = "RecoverFromMarkers";
  8438. /**
  8439. * There was an explicit user gesture.
  8440. */
  8441. CursorChangeReason[CursorChangeReason["Explicit"] = 3] = "Explicit";
  8442. /**
  8443. * There was a Paste.
  8444. */
  8445. CursorChangeReason[CursorChangeReason["Paste"] = 4] = "Paste";
  8446. /**
  8447. * There was an Undo.
  8448. */
  8449. CursorChangeReason[CursorChangeReason["Undo"] = 5] = "Undo";
  8450. /**
  8451. * There was a Redo.
  8452. */
  8453. CursorChangeReason[CursorChangeReason["Redo"] = 6] = "Redo";
  8454. })(CursorChangeReason || (CursorChangeReason = {}));
  8455. /**
  8456. * The default end of line to use when instantiating models.
  8457. */
  8458. var DefaultEndOfLine;
  8459. (function (DefaultEndOfLine) {
  8460. /**
  8461. * Use line feed (\n) as the end of line character.
  8462. */
  8463. DefaultEndOfLine[DefaultEndOfLine["LF"] = 1] = "LF";
  8464. /**
  8465. * Use carriage return and line feed (\r\n) as the end of line character.
  8466. */
  8467. DefaultEndOfLine[DefaultEndOfLine["CRLF"] = 2] = "CRLF";
  8468. })(DefaultEndOfLine || (DefaultEndOfLine = {}));
  8469. /**
  8470. * A document highlight kind.
  8471. */
  8472. var DocumentHighlightKind;
  8473. (function (DocumentHighlightKind) {
  8474. /**
  8475. * A textual occurrence.
  8476. */
  8477. DocumentHighlightKind[DocumentHighlightKind["Text"] = 0] = "Text";
  8478. /**
  8479. * Read-access of a symbol, like reading a variable.
  8480. */
  8481. DocumentHighlightKind[DocumentHighlightKind["Read"] = 1] = "Read";
  8482. /**
  8483. * Write-access of a symbol, like writing to a variable.
  8484. */
  8485. DocumentHighlightKind[DocumentHighlightKind["Write"] = 2] = "Write";
  8486. })(DocumentHighlightKind || (DocumentHighlightKind = {}));
  8487. /**
  8488. * Configuration options for auto indentation in the editor
  8489. */
  8490. var EditorAutoIndentStrategy;
  8491. (function (EditorAutoIndentStrategy) {
  8492. EditorAutoIndentStrategy[EditorAutoIndentStrategy["None"] = 0] = "None";
  8493. EditorAutoIndentStrategy[EditorAutoIndentStrategy["Keep"] = 1] = "Keep";
  8494. EditorAutoIndentStrategy[EditorAutoIndentStrategy["Brackets"] = 2] = "Brackets";
  8495. EditorAutoIndentStrategy[EditorAutoIndentStrategy["Advanced"] = 3] = "Advanced";
  8496. EditorAutoIndentStrategy[EditorAutoIndentStrategy["Full"] = 4] = "Full";
  8497. })(EditorAutoIndentStrategy || (EditorAutoIndentStrategy = {}));
  8498. var EditorOption;
  8499. (function (EditorOption) {
  8500. EditorOption[EditorOption["acceptSuggestionOnCommitCharacter"] = 0] = "acceptSuggestionOnCommitCharacter";
  8501. EditorOption[EditorOption["acceptSuggestionOnEnter"] = 1] = "acceptSuggestionOnEnter";
  8502. EditorOption[EditorOption["accessibilitySupport"] = 2] = "accessibilitySupport";
  8503. EditorOption[EditorOption["accessibilityPageSize"] = 3] = "accessibilityPageSize";
  8504. EditorOption[EditorOption["ariaLabel"] = 4] = "ariaLabel";
  8505. EditorOption[EditorOption["ariaRequired"] = 5] = "ariaRequired";
  8506. EditorOption[EditorOption["autoClosingBrackets"] = 6] = "autoClosingBrackets";
  8507. EditorOption[EditorOption["autoClosingComments"] = 7] = "autoClosingComments";
  8508. EditorOption[EditorOption["screenReaderAnnounceInlineSuggestion"] = 8] = "screenReaderAnnounceInlineSuggestion";
  8509. EditorOption[EditorOption["autoClosingDelete"] = 9] = "autoClosingDelete";
  8510. EditorOption[EditorOption["autoClosingOvertype"] = 10] = "autoClosingOvertype";
  8511. EditorOption[EditorOption["autoClosingQuotes"] = 11] = "autoClosingQuotes";
  8512. EditorOption[EditorOption["autoIndent"] = 12] = "autoIndent";
  8513. EditorOption[EditorOption["automaticLayout"] = 13] = "automaticLayout";
  8514. EditorOption[EditorOption["autoSurround"] = 14] = "autoSurround";
  8515. EditorOption[EditorOption["bracketPairColorization"] = 15] = "bracketPairColorization";
  8516. EditorOption[EditorOption["guides"] = 16] = "guides";
  8517. EditorOption[EditorOption["codeLens"] = 17] = "codeLens";
  8518. EditorOption[EditorOption["codeLensFontFamily"] = 18] = "codeLensFontFamily";
  8519. EditorOption[EditorOption["codeLensFontSize"] = 19] = "codeLensFontSize";
  8520. EditorOption[EditorOption["colorDecorators"] = 20] = "colorDecorators";
  8521. EditorOption[EditorOption["colorDecoratorsLimit"] = 21] = "colorDecoratorsLimit";
  8522. EditorOption[EditorOption["columnSelection"] = 22] = "columnSelection";
  8523. EditorOption[EditorOption["comments"] = 23] = "comments";
  8524. EditorOption[EditorOption["contextmenu"] = 24] = "contextmenu";
  8525. EditorOption[EditorOption["copyWithSyntaxHighlighting"] = 25] = "copyWithSyntaxHighlighting";
  8526. EditorOption[EditorOption["cursorBlinking"] = 26] = "cursorBlinking";
  8527. EditorOption[EditorOption["cursorSmoothCaretAnimation"] = 27] = "cursorSmoothCaretAnimation";
  8528. EditorOption[EditorOption["cursorStyle"] = 28] = "cursorStyle";
  8529. EditorOption[EditorOption["cursorSurroundingLines"] = 29] = "cursorSurroundingLines";
  8530. EditorOption[EditorOption["cursorSurroundingLinesStyle"] = 30] = "cursorSurroundingLinesStyle";
  8531. EditorOption[EditorOption["cursorWidth"] = 31] = "cursorWidth";
  8532. EditorOption[EditorOption["disableLayerHinting"] = 32] = "disableLayerHinting";
  8533. EditorOption[EditorOption["disableMonospaceOptimizations"] = 33] = "disableMonospaceOptimizations";
  8534. EditorOption[EditorOption["domReadOnly"] = 34] = "domReadOnly";
  8535. EditorOption[EditorOption["dragAndDrop"] = 35] = "dragAndDrop";
  8536. EditorOption[EditorOption["dropIntoEditor"] = 36] = "dropIntoEditor";
  8537. EditorOption[EditorOption["emptySelectionClipboard"] = 37] = "emptySelectionClipboard";
  8538. EditorOption[EditorOption["experimentalWhitespaceRendering"] = 38] = "experimentalWhitespaceRendering";
  8539. EditorOption[EditorOption["extraEditorClassName"] = 39] = "extraEditorClassName";
  8540. EditorOption[EditorOption["fastScrollSensitivity"] = 40] = "fastScrollSensitivity";
  8541. EditorOption[EditorOption["find"] = 41] = "find";
  8542. EditorOption[EditorOption["fixedOverflowWidgets"] = 42] = "fixedOverflowWidgets";
  8543. EditorOption[EditorOption["folding"] = 43] = "folding";
  8544. EditorOption[EditorOption["foldingStrategy"] = 44] = "foldingStrategy";
  8545. EditorOption[EditorOption["foldingHighlight"] = 45] = "foldingHighlight";
  8546. EditorOption[EditorOption["foldingImportsByDefault"] = 46] = "foldingImportsByDefault";
  8547. EditorOption[EditorOption["foldingMaximumRegions"] = 47] = "foldingMaximumRegions";
  8548. EditorOption[EditorOption["unfoldOnClickAfterEndOfLine"] = 48] = "unfoldOnClickAfterEndOfLine";
  8549. EditorOption[EditorOption["fontFamily"] = 49] = "fontFamily";
  8550. EditorOption[EditorOption["fontInfo"] = 50] = "fontInfo";
  8551. EditorOption[EditorOption["fontLigatures"] = 51] = "fontLigatures";
  8552. EditorOption[EditorOption["fontSize"] = 52] = "fontSize";
  8553. EditorOption[EditorOption["fontWeight"] = 53] = "fontWeight";
  8554. EditorOption[EditorOption["fontVariations"] = 54] = "fontVariations";
  8555. EditorOption[EditorOption["formatOnPaste"] = 55] = "formatOnPaste";
  8556. EditorOption[EditorOption["formatOnType"] = 56] = "formatOnType";
  8557. EditorOption[EditorOption["glyphMargin"] = 57] = "glyphMargin";
  8558. EditorOption[EditorOption["gotoLocation"] = 58] = "gotoLocation";
  8559. EditorOption[EditorOption["hideCursorInOverviewRuler"] = 59] = "hideCursorInOverviewRuler";
  8560. EditorOption[EditorOption["hover"] = 60] = "hover";
  8561. EditorOption[EditorOption["inDiffEditor"] = 61] = "inDiffEditor";
  8562. EditorOption[EditorOption["inlineSuggest"] = 62] = "inlineSuggest";
  8563. EditorOption[EditorOption["inlineEdit"] = 63] = "inlineEdit";
  8564. EditorOption[EditorOption["letterSpacing"] = 64] = "letterSpacing";
  8565. EditorOption[EditorOption["lightbulb"] = 65] = "lightbulb";
  8566. EditorOption[EditorOption["lineDecorationsWidth"] = 66] = "lineDecorationsWidth";
  8567. EditorOption[EditorOption["lineHeight"] = 67] = "lineHeight";
  8568. EditorOption[EditorOption["lineNumbers"] = 68] = "lineNumbers";
  8569. EditorOption[EditorOption["lineNumbersMinChars"] = 69] = "lineNumbersMinChars";
  8570. EditorOption[EditorOption["linkedEditing"] = 70] = "linkedEditing";
  8571. EditorOption[EditorOption["links"] = 71] = "links";
  8572. EditorOption[EditorOption["matchBrackets"] = 72] = "matchBrackets";
  8573. EditorOption[EditorOption["minimap"] = 73] = "minimap";
  8574. EditorOption[EditorOption["mouseStyle"] = 74] = "mouseStyle";
  8575. EditorOption[EditorOption["mouseWheelScrollSensitivity"] = 75] = "mouseWheelScrollSensitivity";
  8576. EditorOption[EditorOption["mouseWheelZoom"] = 76] = "mouseWheelZoom";
  8577. EditorOption[EditorOption["multiCursorMergeOverlapping"] = 77] = "multiCursorMergeOverlapping";
  8578. EditorOption[EditorOption["multiCursorModifier"] = 78] = "multiCursorModifier";
  8579. EditorOption[EditorOption["multiCursorPaste"] = 79] = "multiCursorPaste";
  8580. EditorOption[EditorOption["multiCursorLimit"] = 80] = "multiCursorLimit";
  8581. EditorOption[EditorOption["occurrencesHighlight"] = 81] = "occurrencesHighlight";
  8582. EditorOption[EditorOption["overviewRulerBorder"] = 82] = "overviewRulerBorder";
  8583. EditorOption[EditorOption["overviewRulerLanes"] = 83] = "overviewRulerLanes";
  8584. EditorOption[EditorOption["padding"] = 84] = "padding";
  8585. EditorOption[EditorOption["pasteAs"] = 85] = "pasteAs";
  8586. EditorOption[EditorOption["parameterHints"] = 86] = "parameterHints";
  8587. EditorOption[EditorOption["peekWidgetDefaultFocus"] = 87] = "peekWidgetDefaultFocus";
  8588. EditorOption[EditorOption["placeholder"] = 88] = "placeholder";
  8589. EditorOption[EditorOption["definitionLinkOpensInPeek"] = 89] = "definitionLinkOpensInPeek";
  8590. EditorOption[EditorOption["quickSuggestions"] = 90] = "quickSuggestions";
  8591. EditorOption[EditorOption["quickSuggestionsDelay"] = 91] = "quickSuggestionsDelay";
  8592. EditorOption[EditorOption["readOnly"] = 92] = "readOnly";
  8593. EditorOption[EditorOption["readOnlyMessage"] = 93] = "readOnlyMessage";
  8594. EditorOption[EditorOption["renameOnType"] = 94] = "renameOnType";
  8595. EditorOption[EditorOption["renderControlCharacters"] = 95] = "renderControlCharacters";
  8596. EditorOption[EditorOption["renderFinalNewline"] = 96] = "renderFinalNewline";
  8597. EditorOption[EditorOption["renderLineHighlight"] = 97] = "renderLineHighlight";
  8598. EditorOption[EditorOption["renderLineHighlightOnlyWhenFocus"] = 98] = "renderLineHighlightOnlyWhenFocus";
  8599. EditorOption[EditorOption["renderValidationDecorations"] = 99] = "renderValidationDecorations";
  8600. EditorOption[EditorOption["renderWhitespace"] = 100] = "renderWhitespace";
  8601. EditorOption[EditorOption["revealHorizontalRightPadding"] = 101] = "revealHorizontalRightPadding";
  8602. EditorOption[EditorOption["roundedSelection"] = 102] = "roundedSelection";
  8603. EditorOption[EditorOption["rulers"] = 103] = "rulers";
  8604. EditorOption[EditorOption["scrollbar"] = 104] = "scrollbar";
  8605. EditorOption[EditorOption["scrollBeyondLastColumn"] = 105] = "scrollBeyondLastColumn";
  8606. EditorOption[EditorOption["scrollBeyondLastLine"] = 106] = "scrollBeyondLastLine";
  8607. EditorOption[EditorOption["scrollPredominantAxis"] = 107] = "scrollPredominantAxis";
  8608. EditorOption[EditorOption["selectionClipboard"] = 108] = "selectionClipboard";
  8609. EditorOption[EditorOption["selectionHighlight"] = 109] = "selectionHighlight";
  8610. EditorOption[EditorOption["selectOnLineNumbers"] = 110] = "selectOnLineNumbers";
  8611. EditorOption[EditorOption["showFoldingControls"] = 111] = "showFoldingControls";
  8612. EditorOption[EditorOption["showUnused"] = 112] = "showUnused";
  8613. EditorOption[EditorOption["snippetSuggestions"] = 113] = "snippetSuggestions";
  8614. EditorOption[EditorOption["smartSelect"] = 114] = "smartSelect";
  8615. EditorOption[EditorOption["smoothScrolling"] = 115] = "smoothScrolling";
  8616. EditorOption[EditorOption["stickyScroll"] = 116] = "stickyScroll";
  8617. EditorOption[EditorOption["stickyTabStops"] = 117] = "stickyTabStops";
  8618. EditorOption[EditorOption["stopRenderingLineAfter"] = 118] = "stopRenderingLineAfter";
  8619. EditorOption[EditorOption["suggest"] = 119] = "suggest";
  8620. EditorOption[EditorOption["suggestFontSize"] = 120] = "suggestFontSize";
  8621. EditorOption[EditorOption["suggestLineHeight"] = 121] = "suggestLineHeight";
  8622. EditorOption[EditorOption["suggestOnTriggerCharacters"] = 122] = "suggestOnTriggerCharacters";
  8623. EditorOption[EditorOption["suggestSelection"] = 123] = "suggestSelection";
  8624. EditorOption[EditorOption["tabCompletion"] = 124] = "tabCompletion";
  8625. EditorOption[EditorOption["tabIndex"] = 125] = "tabIndex";
  8626. EditorOption[EditorOption["unicodeHighlighting"] = 126] = "unicodeHighlighting";
  8627. EditorOption[EditorOption["unusualLineTerminators"] = 127] = "unusualLineTerminators";
  8628. EditorOption[EditorOption["useShadowDOM"] = 128] = "useShadowDOM";
  8629. EditorOption[EditorOption["useTabStops"] = 129] = "useTabStops";
  8630. EditorOption[EditorOption["wordBreak"] = 130] = "wordBreak";
  8631. EditorOption[EditorOption["wordSegmenterLocales"] = 131] = "wordSegmenterLocales";
  8632. EditorOption[EditorOption["wordSeparators"] = 132] = "wordSeparators";
  8633. EditorOption[EditorOption["wordWrap"] = 133] = "wordWrap";
  8634. EditorOption[EditorOption["wordWrapBreakAfterCharacters"] = 134] = "wordWrapBreakAfterCharacters";
  8635. EditorOption[EditorOption["wordWrapBreakBeforeCharacters"] = 135] = "wordWrapBreakBeforeCharacters";
  8636. EditorOption[EditorOption["wordWrapColumn"] = 136] = "wordWrapColumn";
  8637. EditorOption[EditorOption["wordWrapOverride1"] = 137] = "wordWrapOverride1";
  8638. EditorOption[EditorOption["wordWrapOverride2"] = 138] = "wordWrapOverride2";
  8639. EditorOption[EditorOption["wrappingIndent"] = 139] = "wrappingIndent";
  8640. EditorOption[EditorOption["wrappingStrategy"] = 140] = "wrappingStrategy";
  8641. EditorOption[EditorOption["showDeprecated"] = 141] = "showDeprecated";
  8642. EditorOption[EditorOption["inlayHints"] = 142] = "inlayHints";
  8643. EditorOption[EditorOption["editorClassName"] = 143] = "editorClassName";
  8644. EditorOption[EditorOption["pixelRatio"] = 144] = "pixelRatio";
  8645. EditorOption[EditorOption["tabFocusMode"] = 145] = "tabFocusMode";
  8646. EditorOption[EditorOption["layoutInfo"] = 146] = "layoutInfo";
  8647. EditorOption[EditorOption["wrappingInfo"] = 147] = "wrappingInfo";
  8648. EditorOption[EditorOption["defaultColorDecorators"] = 148] = "defaultColorDecorators";
  8649. EditorOption[EditorOption["colorDecoratorsActivatedOn"] = 149] = "colorDecoratorsActivatedOn";
  8650. EditorOption[EditorOption["inlineCompletionsAccessibilityVerbose"] = 150] = "inlineCompletionsAccessibilityVerbose";
  8651. })(EditorOption || (EditorOption = {}));
  8652. /**
  8653. * End of line character preference.
  8654. */
  8655. var EndOfLinePreference;
  8656. (function (EndOfLinePreference) {
  8657. /**
  8658. * Use the end of line character identified in the text buffer.
  8659. */
  8660. EndOfLinePreference[EndOfLinePreference["TextDefined"] = 0] = "TextDefined";
  8661. /**
  8662. * Use line feed (\n) as the end of line character.
  8663. */
  8664. EndOfLinePreference[EndOfLinePreference["LF"] = 1] = "LF";
  8665. /**
  8666. * Use carriage return and line feed (\r\n) as the end of line character.
  8667. */
  8668. EndOfLinePreference[EndOfLinePreference["CRLF"] = 2] = "CRLF";
  8669. })(EndOfLinePreference || (EndOfLinePreference = {}));
  8670. /**
  8671. * End of line character preference.
  8672. */
  8673. var EndOfLineSequence;
  8674. (function (EndOfLineSequence) {
  8675. /**
  8676. * Use line feed (\n) as the end of line character.
  8677. */
  8678. EndOfLineSequence[EndOfLineSequence["LF"] = 0] = "LF";
  8679. /**
  8680. * Use carriage return and line feed (\r\n) as the end of line character.
  8681. */
  8682. EndOfLineSequence[EndOfLineSequence["CRLF"] = 1] = "CRLF";
  8683. })(EndOfLineSequence || (EndOfLineSequence = {}));
  8684. /**
  8685. * Vertical Lane in the glyph margin of the editor.
  8686. */
  8687. var GlyphMarginLane$1;
  8688. (function (GlyphMarginLane) {
  8689. GlyphMarginLane[GlyphMarginLane["Left"] = 1] = "Left";
  8690. GlyphMarginLane[GlyphMarginLane["Center"] = 2] = "Center";
  8691. GlyphMarginLane[GlyphMarginLane["Right"] = 3] = "Right";
  8692. })(GlyphMarginLane$1 || (GlyphMarginLane$1 = {}));
  8693. var HoverVerbosityAction;
  8694. (function (HoverVerbosityAction) {
  8695. /**
  8696. * Increase the verbosity of the hover
  8697. */
  8698. HoverVerbosityAction[HoverVerbosityAction["Increase"] = 0] = "Increase";
  8699. /**
  8700. * Decrease the verbosity of the hover
  8701. */
  8702. HoverVerbosityAction[HoverVerbosityAction["Decrease"] = 1] = "Decrease";
  8703. })(HoverVerbosityAction || (HoverVerbosityAction = {}));
  8704. /**
  8705. * Describes what to do with the indentation when pressing Enter.
  8706. */
  8707. var IndentAction;
  8708. (function (IndentAction) {
  8709. /**
  8710. * Insert new line and copy the previous line's indentation.
  8711. */
  8712. IndentAction[IndentAction["None"] = 0] = "None";
  8713. /**
  8714. * Insert new line and indent once (relative to the previous line's indentation).
  8715. */
  8716. IndentAction[IndentAction["Indent"] = 1] = "Indent";
  8717. /**
  8718. * Insert two new lines:
  8719. * - the first one indented which will hold the cursor
  8720. * - the second one at the same indentation level
  8721. */
  8722. IndentAction[IndentAction["IndentOutdent"] = 2] = "IndentOutdent";
  8723. /**
  8724. * Insert new line and outdent once (relative to the previous line's indentation).
  8725. */
  8726. IndentAction[IndentAction["Outdent"] = 3] = "Outdent";
  8727. })(IndentAction || (IndentAction = {}));
  8728. var InjectedTextCursorStops$1;
  8729. (function (InjectedTextCursorStops) {
  8730. InjectedTextCursorStops[InjectedTextCursorStops["Both"] = 0] = "Both";
  8731. InjectedTextCursorStops[InjectedTextCursorStops["Right"] = 1] = "Right";
  8732. InjectedTextCursorStops[InjectedTextCursorStops["Left"] = 2] = "Left";
  8733. InjectedTextCursorStops[InjectedTextCursorStops["None"] = 3] = "None";
  8734. })(InjectedTextCursorStops$1 || (InjectedTextCursorStops$1 = {}));
  8735. var InlayHintKind;
  8736. (function (InlayHintKind) {
  8737. InlayHintKind[InlayHintKind["Type"] = 1] = "Type";
  8738. InlayHintKind[InlayHintKind["Parameter"] = 2] = "Parameter";
  8739. })(InlayHintKind || (InlayHintKind = {}));
  8740. /**
  8741. * How an {@link InlineCompletionsProvider inline completion provider} was triggered.
  8742. */
  8743. var InlineCompletionTriggerKind;
  8744. (function (InlineCompletionTriggerKind) {
  8745. /**
  8746. * Completion was triggered automatically while editing.
  8747. * It is sufficient to return a single completion item in this case.
  8748. */
  8749. InlineCompletionTriggerKind[InlineCompletionTriggerKind["Automatic"] = 0] = "Automatic";
  8750. /**
  8751. * Completion was triggered explicitly by a user gesture.
  8752. * Return multiple completion items to enable cycling through them.
  8753. */
  8754. InlineCompletionTriggerKind[InlineCompletionTriggerKind["Explicit"] = 1] = "Explicit";
  8755. })(InlineCompletionTriggerKind || (InlineCompletionTriggerKind = {}));
  8756. var InlineEditTriggerKind;
  8757. (function (InlineEditTriggerKind) {
  8758. InlineEditTriggerKind[InlineEditTriggerKind["Invoke"] = 0] = "Invoke";
  8759. InlineEditTriggerKind[InlineEditTriggerKind["Automatic"] = 1] = "Automatic";
  8760. })(InlineEditTriggerKind || (InlineEditTriggerKind = {}));
  8761. /**
  8762. * Virtual Key Codes, the value does not hold any inherent meaning.
  8763. * Inspired somewhat from https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
  8764. * But these are "more general", as they should work across browsers & OS`s.
  8765. */
  8766. var KeyCode;
  8767. (function (KeyCode) {
  8768. KeyCode[KeyCode["DependsOnKbLayout"] = -1] = "DependsOnKbLayout";
  8769. /**
  8770. * Placed first to cover the 0 value of the enum.
  8771. */
  8772. KeyCode[KeyCode["Unknown"] = 0] = "Unknown";
  8773. KeyCode[KeyCode["Backspace"] = 1] = "Backspace";
  8774. KeyCode[KeyCode["Tab"] = 2] = "Tab";
  8775. KeyCode[KeyCode["Enter"] = 3] = "Enter";
  8776. KeyCode[KeyCode["Shift"] = 4] = "Shift";
  8777. KeyCode[KeyCode["Ctrl"] = 5] = "Ctrl";
  8778. KeyCode[KeyCode["Alt"] = 6] = "Alt";
  8779. KeyCode[KeyCode["PauseBreak"] = 7] = "PauseBreak";
  8780. KeyCode[KeyCode["CapsLock"] = 8] = "CapsLock";
  8781. KeyCode[KeyCode["Escape"] = 9] = "Escape";
  8782. KeyCode[KeyCode["Space"] = 10] = "Space";
  8783. KeyCode[KeyCode["PageUp"] = 11] = "PageUp";
  8784. KeyCode[KeyCode["PageDown"] = 12] = "PageDown";
  8785. KeyCode[KeyCode["End"] = 13] = "End";
  8786. KeyCode[KeyCode["Home"] = 14] = "Home";
  8787. KeyCode[KeyCode["LeftArrow"] = 15] = "LeftArrow";
  8788. KeyCode[KeyCode["UpArrow"] = 16] = "UpArrow";
  8789. KeyCode[KeyCode["RightArrow"] = 17] = "RightArrow";
  8790. KeyCode[KeyCode["DownArrow"] = 18] = "DownArrow";
  8791. KeyCode[KeyCode["Insert"] = 19] = "Insert";
  8792. KeyCode[KeyCode["Delete"] = 20] = "Delete";
  8793. KeyCode[KeyCode["Digit0"] = 21] = "Digit0";
  8794. KeyCode[KeyCode["Digit1"] = 22] = "Digit1";
  8795. KeyCode[KeyCode["Digit2"] = 23] = "Digit2";
  8796. KeyCode[KeyCode["Digit3"] = 24] = "Digit3";
  8797. KeyCode[KeyCode["Digit4"] = 25] = "Digit4";
  8798. KeyCode[KeyCode["Digit5"] = 26] = "Digit5";
  8799. KeyCode[KeyCode["Digit6"] = 27] = "Digit6";
  8800. KeyCode[KeyCode["Digit7"] = 28] = "Digit7";
  8801. KeyCode[KeyCode["Digit8"] = 29] = "Digit8";
  8802. KeyCode[KeyCode["Digit9"] = 30] = "Digit9";
  8803. KeyCode[KeyCode["KeyA"] = 31] = "KeyA";
  8804. KeyCode[KeyCode["KeyB"] = 32] = "KeyB";
  8805. KeyCode[KeyCode["KeyC"] = 33] = "KeyC";
  8806. KeyCode[KeyCode["KeyD"] = 34] = "KeyD";
  8807. KeyCode[KeyCode["KeyE"] = 35] = "KeyE";
  8808. KeyCode[KeyCode["KeyF"] = 36] = "KeyF";
  8809. KeyCode[KeyCode["KeyG"] = 37] = "KeyG";
  8810. KeyCode[KeyCode["KeyH"] = 38] = "KeyH";
  8811. KeyCode[KeyCode["KeyI"] = 39] = "KeyI";
  8812. KeyCode[KeyCode["KeyJ"] = 40] = "KeyJ";
  8813. KeyCode[KeyCode["KeyK"] = 41] = "KeyK";
  8814. KeyCode[KeyCode["KeyL"] = 42] = "KeyL";
  8815. KeyCode[KeyCode["KeyM"] = 43] = "KeyM";
  8816. KeyCode[KeyCode["KeyN"] = 44] = "KeyN";
  8817. KeyCode[KeyCode["KeyO"] = 45] = "KeyO";
  8818. KeyCode[KeyCode["KeyP"] = 46] = "KeyP";
  8819. KeyCode[KeyCode["KeyQ"] = 47] = "KeyQ";
  8820. KeyCode[KeyCode["KeyR"] = 48] = "KeyR";
  8821. KeyCode[KeyCode["KeyS"] = 49] = "KeyS";
  8822. KeyCode[KeyCode["KeyT"] = 50] = "KeyT";
  8823. KeyCode[KeyCode["KeyU"] = 51] = "KeyU";
  8824. KeyCode[KeyCode["KeyV"] = 52] = "KeyV";
  8825. KeyCode[KeyCode["KeyW"] = 53] = "KeyW";
  8826. KeyCode[KeyCode["KeyX"] = 54] = "KeyX";
  8827. KeyCode[KeyCode["KeyY"] = 55] = "KeyY";
  8828. KeyCode[KeyCode["KeyZ"] = 56] = "KeyZ";
  8829. KeyCode[KeyCode["Meta"] = 57] = "Meta";
  8830. KeyCode[KeyCode["ContextMenu"] = 58] = "ContextMenu";
  8831. KeyCode[KeyCode["F1"] = 59] = "F1";
  8832. KeyCode[KeyCode["F2"] = 60] = "F2";
  8833. KeyCode[KeyCode["F3"] = 61] = "F3";
  8834. KeyCode[KeyCode["F4"] = 62] = "F4";
  8835. KeyCode[KeyCode["F5"] = 63] = "F5";
  8836. KeyCode[KeyCode["F6"] = 64] = "F6";
  8837. KeyCode[KeyCode["F7"] = 65] = "F7";
  8838. KeyCode[KeyCode["F8"] = 66] = "F8";
  8839. KeyCode[KeyCode["F9"] = 67] = "F9";
  8840. KeyCode[KeyCode["F10"] = 68] = "F10";
  8841. KeyCode[KeyCode["F11"] = 69] = "F11";
  8842. KeyCode[KeyCode["F12"] = 70] = "F12";
  8843. KeyCode[KeyCode["F13"] = 71] = "F13";
  8844. KeyCode[KeyCode["F14"] = 72] = "F14";
  8845. KeyCode[KeyCode["F15"] = 73] = "F15";
  8846. KeyCode[KeyCode["F16"] = 74] = "F16";
  8847. KeyCode[KeyCode["F17"] = 75] = "F17";
  8848. KeyCode[KeyCode["F18"] = 76] = "F18";
  8849. KeyCode[KeyCode["F19"] = 77] = "F19";
  8850. KeyCode[KeyCode["F20"] = 78] = "F20";
  8851. KeyCode[KeyCode["F21"] = 79] = "F21";
  8852. KeyCode[KeyCode["F22"] = 80] = "F22";
  8853. KeyCode[KeyCode["F23"] = 81] = "F23";
  8854. KeyCode[KeyCode["F24"] = 82] = "F24";
  8855. KeyCode[KeyCode["NumLock"] = 83] = "NumLock";
  8856. KeyCode[KeyCode["ScrollLock"] = 84] = "ScrollLock";
  8857. /**
  8858. * Used for miscellaneous characters; it can vary by keyboard.
  8859. * For the US standard keyboard, the ';:' key
  8860. */
  8861. KeyCode[KeyCode["Semicolon"] = 85] = "Semicolon";
  8862. /**
  8863. * For any country/region, the '+' key
  8864. * For the US standard keyboard, the '=+' key
  8865. */
  8866. KeyCode[KeyCode["Equal"] = 86] = "Equal";
  8867. /**
  8868. * For any country/region, the ',' key
  8869. * For the US standard keyboard, the ',<' key
  8870. */
  8871. KeyCode[KeyCode["Comma"] = 87] = "Comma";
  8872. /**
  8873. * For any country/region, the '-' key
  8874. * For the US standard keyboard, the '-_' key
  8875. */
  8876. KeyCode[KeyCode["Minus"] = 88] = "Minus";
  8877. /**
  8878. * For any country/region, the '.' key
  8879. * For the US standard keyboard, the '.>' key
  8880. */
  8881. KeyCode[KeyCode["Period"] = 89] = "Period";
  8882. /**
  8883. * Used for miscellaneous characters; it can vary by keyboard.
  8884. * For the US standard keyboard, the '/?' key
  8885. */
  8886. KeyCode[KeyCode["Slash"] = 90] = "Slash";
  8887. /**
  8888. * Used for miscellaneous characters; it can vary by keyboard.
  8889. * For the US standard keyboard, the '`~' key
  8890. */
  8891. KeyCode[KeyCode["Backquote"] = 91] = "Backquote";
  8892. /**
  8893. * Used for miscellaneous characters; it can vary by keyboard.
  8894. * For the US standard keyboard, the '[{' key
  8895. */
  8896. KeyCode[KeyCode["BracketLeft"] = 92] = "BracketLeft";
  8897. /**
  8898. * Used for miscellaneous characters; it can vary by keyboard.
  8899. * For the US standard keyboard, the '\|' key
  8900. */
  8901. KeyCode[KeyCode["Backslash"] = 93] = "Backslash";
  8902. /**
  8903. * Used for miscellaneous characters; it can vary by keyboard.
  8904. * For the US standard keyboard, the ']}' key
  8905. */
  8906. KeyCode[KeyCode["BracketRight"] = 94] = "BracketRight";
  8907. /**
  8908. * Used for miscellaneous characters; it can vary by keyboard.
  8909. * For the US standard keyboard, the ''"' key
  8910. */
  8911. KeyCode[KeyCode["Quote"] = 95] = "Quote";
  8912. /**
  8913. * Used for miscellaneous characters; it can vary by keyboard.
  8914. */
  8915. KeyCode[KeyCode["OEM_8"] = 96] = "OEM_8";
  8916. /**
  8917. * Either the angle bracket key or the backslash key on the RT 102-key keyboard.
  8918. */
  8919. KeyCode[KeyCode["IntlBackslash"] = 97] = "IntlBackslash";
  8920. KeyCode[KeyCode["Numpad0"] = 98] = "Numpad0";
  8921. KeyCode[KeyCode["Numpad1"] = 99] = "Numpad1";
  8922. KeyCode[KeyCode["Numpad2"] = 100] = "Numpad2";
  8923. KeyCode[KeyCode["Numpad3"] = 101] = "Numpad3";
  8924. KeyCode[KeyCode["Numpad4"] = 102] = "Numpad4";
  8925. KeyCode[KeyCode["Numpad5"] = 103] = "Numpad5";
  8926. KeyCode[KeyCode["Numpad6"] = 104] = "Numpad6";
  8927. KeyCode[KeyCode["Numpad7"] = 105] = "Numpad7";
  8928. KeyCode[KeyCode["Numpad8"] = 106] = "Numpad8";
  8929. KeyCode[KeyCode["Numpad9"] = 107] = "Numpad9";
  8930. KeyCode[KeyCode["NumpadMultiply"] = 108] = "NumpadMultiply";
  8931. KeyCode[KeyCode["NumpadAdd"] = 109] = "NumpadAdd";
  8932. KeyCode[KeyCode["NUMPAD_SEPARATOR"] = 110] = "NUMPAD_SEPARATOR";
  8933. KeyCode[KeyCode["NumpadSubtract"] = 111] = "NumpadSubtract";
  8934. KeyCode[KeyCode["NumpadDecimal"] = 112] = "NumpadDecimal";
  8935. KeyCode[KeyCode["NumpadDivide"] = 113] = "NumpadDivide";
  8936. /**
  8937. * Cover all key codes when IME is processing input.
  8938. */
  8939. KeyCode[KeyCode["KEY_IN_COMPOSITION"] = 114] = "KEY_IN_COMPOSITION";
  8940. KeyCode[KeyCode["ABNT_C1"] = 115] = "ABNT_C1";
  8941. KeyCode[KeyCode["ABNT_C2"] = 116] = "ABNT_C2";
  8942. KeyCode[KeyCode["AudioVolumeMute"] = 117] = "AudioVolumeMute";
  8943. KeyCode[KeyCode["AudioVolumeUp"] = 118] = "AudioVolumeUp";
  8944. KeyCode[KeyCode["AudioVolumeDown"] = 119] = "AudioVolumeDown";
  8945. KeyCode[KeyCode["BrowserSearch"] = 120] = "BrowserSearch";
  8946. KeyCode[KeyCode["BrowserHome"] = 121] = "BrowserHome";
  8947. KeyCode[KeyCode["BrowserBack"] = 122] = "BrowserBack";
  8948. KeyCode[KeyCode["BrowserForward"] = 123] = "BrowserForward";
  8949. KeyCode[KeyCode["MediaTrackNext"] = 124] = "MediaTrackNext";
  8950. KeyCode[KeyCode["MediaTrackPrevious"] = 125] = "MediaTrackPrevious";
  8951. KeyCode[KeyCode["MediaStop"] = 126] = "MediaStop";
  8952. KeyCode[KeyCode["MediaPlayPause"] = 127] = "MediaPlayPause";
  8953. KeyCode[KeyCode["LaunchMediaPlayer"] = 128] = "LaunchMediaPlayer";
  8954. KeyCode[KeyCode["LaunchMail"] = 129] = "LaunchMail";
  8955. KeyCode[KeyCode["LaunchApp2"] = 130] = "LaunchApp2";
  8956. /**
  8957. * VK_CLEAR, 0x0C, CLEAR key
  8958. */
  8959. KeyCode[KeyCode["Clear"] = 131] = "Clear";
  8960. /**
  8961. * Placed last to cover the length of the enum.
  8962. * Please do not depend on this value!
  8963. */
  8964. KeyCode[KeyCode["MAX_VALUE"] = 132] = "MAX_VALUE";
  8965. })(KeyCode || (KeyCode = {}));
  8966. var MarkerSeverity;
  8967. (function (MarkerSeverity) {
  8968. MarkerSeverity[MarkerSeverity["Hint"] = 1] = "Hint";
  8969. MarkerSeverity[MarkerSeverity["Info"] = 2] = "Info";
  8970. MarkerSeverity[MarkerSeverity["Warning"] = 4] = "Warning";
  8971. MarkerSeverity[MarkerSeverity["Error"] = 8] = "Error";
  8972. })(MarkerSeverity || (MarkerSeverity = {}));
  8973. var MarkerTag;
  8974. (function (MarkerTag) {
  8975. MarkerTag[MarkerTag["Unnecessary"] = 1] = "Unnecessary";
  8976. MarkerTag[MarkerTag["Deprecated"] = 2] = "Deprecated";
  8977. })(MarkerTag || (MarkerTag = {}));
  8978. /**
  8979. * Position in the minimap to render the decoration.
  8980. */
  8981. var MinimapPosition;
  8982. (function (MinimapPosition) {
  8983. MinimapPosition[MinimapPosition["Inline"] = 1] = "Inline";
  8984. MinimapPosition[MinimapPosition["Gutter"] = 2] = "Gutter";
  8985. })(MinimapPosition || (MinimapPosition = {}));
  8986. /**
  8987. * Section header style.
  8988. */
  8989. var MinimapSectionHeaderStyle;
  8990. (function (MinimapSectionHeaderStyle) {
  8991. MinimapSectionHeaderStyle[MinimapSectionHeaderStyle["Normal"] = 1] = "Normal";
  8992. MinimapSectionHeaderStyle[MinimapSectionHeaderStyle["Underlined"] = 2] = "Underlined";
  8993. })(MinimapSectionHeaderStyle || (MinimapSectionHeaderStyle = {}));
  8994. /**
  8995. * Type of hit element with the mouse in the editor.
  8996. */
  8997. var MouseTargetType;
  8998. (function (MouseTargetType) {
  8999. /**
  9000. * Mouse is on top of an unknown element.
  9001. */
  9002. MouseTargetType[MouseTargetType["UNKNOWN"] = 0] = "UNKNOWN";
  9003. /**
  9004. * Mouse is on top of the textarea used for input.
  9005. */
  9006. MouseTargetType[MouseTargetType["TEXTAREA"] = 1] = "TEXTAREA";
  9007. /**
  9008. * Mouse is on top of the glyph margin
  9009. */
  9010. MouseTargetType[MouseTargetType["GUTTER_GLYPH_MARGIN"] = 2] = "GUTTER_GLYPH_MARGIN";
  9011. /**
  9012. * Mouse is on top of the line numbers
  9013. */
  9014. MouseTargetType[MouseTargetType["GUTTER_LINE_NUMBERS"] = 3] = "GUTTER_LINE_NUMBERS";
  9015. /**
  9016. * Mouse is on top of the line decorations
  9017. */
  9018. MouseTargetType[MouseTargetType["GUTTER_LINE_DECORATIONS"] = 4] = "GUTTER_LINE_DECORATIONS";
  9019. /**
  9020. * Mouse is on top of the whitespace left in the gutter by a view zone.
  9021. */
  9022. MouseTargetType[MouseTargetType["GUTTER_VIEW_ZONE"] = 5] = "GUTTER_VIEW_ZONE";
  9023. /**
  9024. * Mouse is on top of text in the content.
  9025. */
  9026. MouseTargetType[MouseTargetType["CONTENT_TEXT"] = 6] = "CONTENT_TEXT";
  9027. /**
  9028. * Mouse is on top of empty space in the content (e.g. after line text or below last line)
  9029. */
  9030. MouseTargetType[MouseTargetType["CONTENT_EMPTY"] = 7] = "CONTENT_EMPTY";
  9031. /**
  9032. * Mouse is on top of a view zone in the content.
  9033. */
  9034. MouseTargetType[MouseTargetType["CONTENT_VIEW_ZONE"] = 8] = "CONTENT_VIEW_ZONE";
  9035. /**
  9036. * Mouse is on top of a content widget.
  9037. */
  9038. MouseTargetType[MouseTargetType["CONTENT_WIDGET"] = 9] = "CONTENT_WIDGET";
  9039. /**
  9040. * Mouse is on top of the decorations overview ruler.
  9041. */
  9042. MouseTargetType[MouseTargetType["OVERVIEW_RULER"] = 10] = "OVERVIEW_RULER";
  9043. /**
  9044. * Mouse is on top of a scrollbar.
  9045. */
  9046. MouseTargetType[MouseTargetType["SCROLLBAR"] = 11] = "SCROLLBAR";
  9047. /**
  9048. * Mouse is on top of an overlay widget.
  9049. */
  9050. MouseTargetType[MouseTargetType["OVERLAY_WIDGET"] = 12] = "OVERLAY_WIDGET";
  9051. /**
  9052. * Mouse is outside of the editor.
  9053. */
  9054. MouseTargetType[MouseTargetType["OUTSIDE_EDITOR"] = 13] = "OUTSIDE_EDITOR";
  9055. })(MouseTargetType || (MouseTargetType = {}));
  9056. var NewSymbolNameTag;
  9057. (function (NewSymbolNameTag) {
  9058. NewSymbolNameTag[NewSymbolNameTag["AIGenerated"] = 1] = "AIGenerated";
  9059. })(NewSymbolNameTag || (NewSymbolNameTag = {}));
  9060. var NewSymbolNameTriggerKind;
  9061. (function (NewSymbolNameTriggerKind) {
  9062. NewSymbolNameTriggerKind[NewSymbolNameTriggerKind["Invoke"] = 0] = "Invoke";
  9063. NewSymbolNameTriggerKind[NewSymbolNameTriggerKind["Automatic"] = 1] = "Automatic";
  9064. })(NewSymbolNameTriggerKind || (NewSymbolNameTriggerKind = {}));
  9065. /**
  9066. * A positioning preference for rendering overlay widgets.
  9067. */
  9068. var OverlayWidgetPositionPreference;
  9069. (function (OverlayWidgetPositionPreference) {
  9070. /**
  9071. * Position the overlay widget in the top right corner
  9072. */
  9073. OverlayWidgetPositionPreference[OverlayWidgetPositionPreference["TOP_RIGHT_CORNER"] = 0] = "TOP_RIGHT_CORNER";
  9074. /**
  9075. * Position the overlay widget in the bottom right corner
  9076. */
  9077. OverlayWidgetPositionPreference[OverlayWidgetPositionPreference["BOTTOM_RIGHT_CORNER"] = 1] = "BOTTOM_RIGHT_CORNER";
  9078. /**
  9079. * Position the overlay widget in the top center
  9080. */
  9081. OverlayWidgetPositionPreference[OverlayWidgetPositionPreference["TOP_CENTER"] = 2] = "TOP_CENTER";
  9082. })(OverlayWidgetPositionPreference || (OverlayWidgetPositionPreference = {}));
  9083. /**
  9084. * Vertical Lane in the overview ruler of the editor.
  9085. */
  9086. var OverviewRulerLane$1;
  9087. (function (OverviewRulerLane) {
  9088. OverviewRulerLane[OverviewRulerLane["Left"] = 1] = "Left";
  9089. OverviewRulerLane[OverviewRulerLane["Center"] = 2] = "Center";
  9090. OverviewRulerLane[OverviewRulerLane["Right"] = 4] = "Right";
  9091. OverviewRulerLane[OverviewRulerLane["Full"] = 7] = "Full";
  9092. })(OverviewRulerLane$1 || (OverviewRulerLane$1 = {}));
  9093. /**
  9094. * How a partial acceptance was triggered.
  9095. */
  9096. var PartialAcceptTriggerKind;
  9097. (function (PartialAcceptTriggerKind) {
  9098. PartialAcceptTriggerKind[PartialAcceptTriggerKind["Word"] = 0] = "Word";
  9099. PartialAcceptTriggerKind[PartialAcceptTriggerKind["Line"] = 1] = "Line";
  9100. PartialAcceptTriggerKind[PartialAcceptTriggerKind["Suggest"] = 2] = "Suggest";
  9101. })(PartialAcceptTriggerKind || (PartialAcceptTriggerKind = {}));
  9102. var PositionAffinity;
  9103. (function (PositionAffinity) {
  9104. /**
  9105. * Prefers the left most position.
  9106. */
  9107. PositionAffinity[PositionAffinity["Left"] = 0] = "Left";
  9108. /**
  9109. * Prefers the right most position.
  9110. */
  9111. PositionAffinity[PositionAffinity["Right"] = 1] = "Right";
  9112. /**
  9113. * No preference.
  9114. */
  9115. PositionAffinity[PositionAffinity["None"] = 2] = "None";
  9116. /**
  9117. * If the given position is on injected text, prefers the position left of it.
  9118. */
  9119. PositionAffinity[PositionAffinity["LeftOfInjectedText"] = 3] = "LeftOfInjectedText";
  9120. /**
  9121. * If the given position is on injected text, prefers the position right of it.
  9122. */
  9123. PositionAffinity[PositionAffinity["RightOfInjectedText"] = 4] = "RightOfInjectedText";
  9124. })(PositionAffinity || (PositionAffinity = {}));
  9125. var RenderLineNumbersType;
  9126. (function (RenderLineNumbersType) {
  9127. RenderLineNumbersType[RenderLineNumbersType["Off"] = 0] = "Off";
  9128. RenderLineNumbersType[RenderLineNumbersType["On"] = 1] = "On";
  9129. RenderLineNumbersType[RenderLineNumbersType["Relative"] = 2] = "Relative";
  9130. RenderLineNumbersType[RenderLineNumbersType["Interval"] = 3] = "Interval";
  9131. RenderLineNumbersType[RenderLineNumbersType["Custom"] = 4] = "Custom";
  9132. })(RenderLineNumbersType || (RenderLineNumbersType = {}));
  9133. var RenderMinimap;
  9134. (function (RenderMinimap) {
  9135. RenderMinimap[RenderMinimap["None"] = 0] = "None";
  9136. RenderMinimap[RenderMinimap["Text"] = 1] = "Text";
  9137. RenderMinimap[RenderMinimap["Blocks"] = 2] = "Blocks";
  9138. })(RenderMinimap || (RenderMinimap = {}));
  9139. var ScrollType;
  9140. (function (ScrollType) {
  9141. ScrollType[ScrollType["Smooth"] = 0] = "Smooth";
  9142. ScrollType[ScrollType["Immediate"] = 1] = "Immediate";
  9143. })(ScrollType || (ScrollType = {}));
  9144. var ScrollbarVisibility;
  9145. (function (ScrollbarVisibility) {
  9146. ScrollbarVisibility[ScrollbarVisibility["Auto"] = 1] = "Auto";
  9147. ScrollbarVisibility[ScrollbarVisibility["Hidden"] = 2] = "Hidden";
  9148. ScrollbarVisibility[ScrollbarVisibility["Visible"] = 3] = "Visible";
  9149. })(ScrollbarVisibility || (ScrollbarVisibility = {}));
  9150. /**
  9151. * The direction of a selection.
  9152. */
  9153. var SelectionDirection;
  9154. (function (SelectionDirection) {
  9155. /**
  9156. * The selection starts above where it ends.
  9157. */
  9158. SelectionDirection[SelectionDirection["LTR"] = 0] = "LTR";
  9159. /**
  9160. * The selection starts below where it ends.
  9161. */
  9162. SelectionDirection[SelectionDirection["RTL"] = 1] = "RTL";
  9163. })(SelectionDirection || (SelectionDirection = {}));
  9164. var ShowLightbulbIconMode;
  9165. (function (ShowLightbulbIconMode) {
  9166. ShowLightbulbIconMode["Off"] = "off";
  9167. ShowLightbulbIconMode["OnCode"] = "onCode";
  9168. ShowLightbulbIconMode["On"] = "on";
  9169. })(ShowLightbulbIconMode || (ShowLightbulbIconMode = {}));
  9170. var SignatureHelpTriggerKind;
  9171. (function (SignatureHelpTriggerKind) {
  9172. SignatureHelpTriggerKind[SignatureHelpTriggerKind["Invoke"] = 1] = "Invoke";
  9173. SignatureHelpTriggerKind[SignatureHelpTriggerKind["TriggerCharacter"] = 2] = "TriggerCharacter";
  9174. SignatureHelpTriggerKind[SignatureHelpTriggerKind["ContentChange"] = 3] = "ContentChange";
  9175. })(SignatureHelpTriggerKind || (SignatureHelpTriggerKind = {}));
  9176. /**
  9177. * A symbol kind.
  9178. */
  9179. var SymbolKind;
  9180. (function (SymbolKind) {
  9181. SymbolKind[SymbolKind["File"] = 0] = "File";
  9182. SymbolKind[SymbolKind["Module"] = 1] = "Module";
  9183. SymbolKind[SymbolKind["Namespace"] = 2] = "Namespace";
  9184. SymbolKind[SymbolKind["Package"] = 3] = "Package";
  9185. SymbolKind[SymbolKind["Class"] = 4] = "Class";
  9186. SymbolKind[SymbolKind["Method"] = 5] = "Method";
  9187. SymbolKind[SymbolKind["Property"] = 6] = "Property";
  9188. SymbolKind[SymbolKind["Field"] = 7] = "Field";
  9189. SymbolKind[SymbolKind["Constructor"] = 8] = "Constructor";
  9190. SymbolKind[SymbolKind["Enum"] = 9] = "Enum";
  9191. SymbolKind[SymbolKind["Interface"] = 10] = "Interface";
  9192. SymbolKind[SymbolKind["Function"] = 11] = "Function";
  9193. SymbolKind[SymbolKind["Variable"] = 12] = "Variable";
  9194. SymbolKind[SymbolKind["Constant"] = 13] = "Constant";
  9195. SymbolKind[SymbolKind["String"] = 14] = "String";
  9196. SymbolKind[SymbolKind["Number"] = 15] = "Number";
  9197. SymbolKind[SymbolKind["Boolean"] = 16] = "Boolean";
  9198. SymbolKind[SymbolKind["Array"] = 17] = "Array";
  9199. SymbolKind[SymbolKind["Object"] = 18] = "Object";
  9200. SymbolKind[SymbolKind["Key"] = 19] = "Key";
  9201. SymbolKind[SymbolKind["Null"] = 20] = "Null";
  9202. SymbolKind[SymbolKind["EnumMember"] = 21] = "EnumMember";
  9203. SymbolKind[SymbolKind["Struct"] = 22] = "Struct";
  9204. SymbolKind[SymbolKind["Event"] = 23] = "Event";
  9205. SymbolKind[SymbolKind["Operator"] = 24] = "Operator";
  9206. SymbolKind[SymbolKind["TypeParameter"] = 25] = "TypeParameter";
  9207. })(SymbolKind || (SymbolKind = {}));
  9208. var SymbolTag;
  9209. (function (SymbolTag) {
  9210. SymbolTag[SymbolTag["Deprecated"] = 1] = "Deprecated";
  9211. })(SymbolTag || (SymbolTag = {}));
  9212. /**
  9213. * The kind of animation in which the editor's cursor should be rendered.
  9214. */
  9215. var TextEditorCursorBlinkingStyle;
  9216. (function (TextEditorCursorBlinkingStyle) {
  9217. /**
  9218. * Hidden
  9219. */
  9220. TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Hidden"] = 0] = "Hidden";
  9221. /**
  9222. * Blinking
  9223. */
  9224. TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Blink"] = 1] = "Blink";
  9225. /**
  9226. * Blinking with smooth fading
  9227. */
  9228. TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Smooth"] = 2] = "Smooth";
  9229. /**
  9230. * Blinking with prolonged filled state and smooth fading
  9231. */
  9232. TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Phase"] = 3] = "Phase";
  9233. /**
  9234. * Expand collapse animation on the y axis
  9235. */
  9236. TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Expand"] = 4] = "Expand";
  9237. /**
  9238. * No-Blinking
  9239. */
  9240. TextEditorCursorBlinkingStyle[TextEditorCursorBlinkingStyle["Solid"] = 5] = "Solid";
  9241. })(TextEditorCursorBlinkingStyle || (TextEditorCursorBlinkingStyle = {}));
  9242. /**
  9243. * The style in which the editor's cursor should be rendered.
  9244. */
  9245. var TextEditorCursorStyle;
  9246. (function (TextEditorCursorStyle) {
  9247. /**
  9248. * As a vertical line (sitting between two characters).
  9249. */
  9250. TextEditorCursorStyle[TextEditorCursorStyle["Line"] = 1] = "Line";
  9251. /**
  9252. * As a block (sitting on top of a character).
  9253. */
  9254. TextEditorCursorStyle[TextEditorCursorStyle["Block"] = 2] = "Block";
  9255. /**
  9256. * As a horizontal line (sitting under a character).
  9257. */
  9258. TextEditorCursorStyle[TextEditorCursorStyle["Underline"] = 3] = "Underline";
  9259. /**
  9260. * As a thin vertical line (sitting between two characters).
  9261. */
  9262. TextEditorCursorStyle[TextEditorCursorStyle["LineThin"] = 4] = "LineThin";
  9263. /**
  9264. * As an outlined block (sitting on top of a character).
  9265. */
  9266. TextEditorCursorStyle[TextEditorCursorStyle["BlockOutline"] = 5] = "BlockOutline";
  9267. /**
  9268. * As a thin horizontal line (sitting under a character).
  9269. */
  9270. TextEditorCursorStyle[TextEditorCursorStyle["UnderlineThin"] = 6] = "UnderlineThin";
  9271. })(TextEditorCursorStyle || (TextEditorCursorStyle = {}));
  9272. /**
  9273. * Describes the behavior of decorations when typing/editing near their edges.
  9274. * Note: Please do not edit the values, as they very carefully match `DecorationRangeBehavior`
  9275. */
  9276. var TrackedRangeStickiness;
  9277. (function (TrackedRangeStickiness) {
  9278. TrackedRangeStickiness[TrackedRangeStickiness["AlwaysGrowsWhenTypingAtEdges"] = 0] = "AlwaysGrowsWhenTypingAtEdges";
  9279. TrackedRangeStickiness[TrackedRangeStickiness["NeverGrowsWhenTypingAtEdges"] = 1] = "NeverGrowsWhenTypingAtEdges";
  9280. TrackedRangeStickiness[TrackedRangeStickiness["GrowsOnlyWhenTypingBefore"] = 2] = "GrowsOnlyWhenTypingBefore";
  9281. TrackedRangeStickiness[TrackedRangeStickiness["GrowsOnlyWhenTypingAfter"] = 3] = "GrowsOnlyWhenTypingAfter";
  9282. })(TrackedRangeStickiness || (TrackedRangeStickiness = {}));
  9283. /**
  9284. * Describes how to indent wrapped lines.
  9285. */
  9286. var WrappingIndent;
  9287. (function (WrappingIndent) {
  9288. /**
  9289. * No indentation => wrapped lines begin at column 1.
  9290. */
  9291. WrappingIndent[WrappingIndent["None"] = 0] = "None";
  9292. /**
  9293. * Same => wrapped lines get the same indentation as the parent.
  9294. */
  9295. WrappingIndent[WrappingIndent["Same"] = 1] = "Same";
  9296. /**
  9297. * Indent => wrapped lines get +1 indentation toward the parent.
  9298. */
  9299. WrappingIndent[WrappingIndent["Indent"] = 2] = "Indent";
  9300. /**
  9301. * DeepIndent => wrapped lines get +2 indentation toward the parent.
  9302. */
  9303. WrappingIndent[WrappingIndent["DeepIndent"] = 3] = "DeepIndent";
  9304. })(WrappingIndent || (WrappingIndent = {}));
  9305. /*---------------------------------------------------------------------------------------------
  9306. * Copyright (c) Microsoft Corporation. All rights reserved.
  9307. * Licensed under the MIT License. See License.txt in the project root for license information.
  9308. *--------------------------------------------------------------------------------------------*/
  9309. class KeyMod {
  9310. static { this.CtrlCmd = 2048 /* ConstKeyMod.CtrlCmd */; }
  9311. static { this.Shift = 1024 /* ConstKeyMod.Shift */; }
  9312. static { this.Alt = 512 /* ConstKeyMod.Alt */; }
  9313. static { this.WinCtrl = 256 /* ConstKeyMod.WinCtrl */; }
  9314. static chord(firstPart, secondPart) {
  9315. return KeyChord(firstPart, secondPart);
  9316. }
  9317. }
  9318. function createMonacoBaseAPI() {
  9319. return {
  9320. editor: undefined, // undefined override expected here
  9321. languages: undefined, // undefined override expected here
  9322. CancellationTokenSource: CancellationTokenSource,
  9323. Emitter: Emitter,
  9324. KeyCode: KeyCode,
  9325. KeyMod: KeyMod,
  9326. Position: Position,
  9327. Range: Range,
  9328. Selection: Selection,
  9329. SelectionDirection: SelectionDirection,
  9330. MarkerSeverity: MarkerSeverity,
  9331. MarkerTag: MarkerTag,
  9332. Uri: URI,
  9333. Token: Token
  9334. };
  9335. }
  9336. /*---------------------------------------------------------------------------------------------
  9337. * Copyright (c) Microsoft Corporation. All rights reserved.
  9338. * Licensed under the MIT License. See License.txt in the project root for license information.
  9339. *--------------------------------------------------------------------------------------------*/
  9340. class EditorWorkerHost {
  9341. static { this.CHANNEL_NAME = 'editorWorkerHost'; }
  9342. static getChannel(workerServer) {
  9343. return workerServer.getChannel(EditorWorkerHost.CHANNEL_NAME);
  9344. }
  9345. static setChannel(workerClient, obj) {
  9346. workerClient.setChannel(EditorWorkerHost.CHANNEL_NAME, obj);
  9347. }
  9348. }
  9349. /*---------------------------------------------------------------------------------------------
  9350. * Copyright (c) Microsoft Corporation. All rights reserved.
  9351. * Licensed under the MIT License. See License.txt in the project root for license information.
  9352. *--------------------------------------------------------------------------------------------*/
  9353. var _b;
  9354. class LinkedMap {
  9355. constructor() {
  9356. this[_b] = 'LinkedMap';
  9357. this._map = new Map();
  9358. this._head = undefined;
  9359. this._tail = undefined;
  9360. this._size = 0;
  9361. this._state = 0;
  9362. }
  9363. clear() {
  9364. this._map.clear();
  9365. this._head = undefined;
  9366. this._tail = undefined;
  9367. this._size = 0;
  9368. this._state++;
  9369. }
  9370. isEmpty() {
  9371. return !this._head && !this._tail;
  9372. }
  9373. get size() {
  9374. return this._size;
  9375. }
  9376. get first() {
  9377. return this._head?.value;
  9378. }
  9379. get last() {
  9380. return this._tail?.value;
  9381. }
  9382. has(key) {
  9383. return this._map.has(key);
  9384. }
  9385. get(key, touch = 0 /* Touch.None */) {
  9386. const item = this._map.get(key);
  9387. if (!item) {
  9388. return undefined;
  9389. }
  9390. if (touch !== 0 /* Touch.None */) {
  9391. this.touch(item, touch);
  9392. }
  9393. return item.value;
  9394. }
  9395. set(key, value, touch = 0 /* Touch.None */) {
  9396. let item = this._map.get(key);
  9397. if (item) {
  9398. item.value = value;
  9399. if (touch !== 0 /* Touch.None */) {
  9400. this.touch(item, touch);
  9401. }
  9402. }
  9403. else {
  9404. item = { key, value, next: undefined, previous: undefined };
  9405. switch (touch) {
  9406. case 0 /* Touch.None */:
  9407. this.addItemLast(item);
  9408. break;
  9409. case 1 /* Touch.AsOld */:
  9410. this.addItemFirst(item);
  9411. break;
  9412. case 2 /* Touch.AsNew */:
  9413. this.addItemLast(item);
  9414. break;
  9415. default:
  9416. this.addItemLast(item);
  9417. break;
  9418. }
  9419. this._map.set(key, item);
  9420. this._size++;
  9421. }
  9422. return this;
  9423. }
  9424. delete(key) {
  9425. return !!this.remove(key);
  9426. }
  9427. remove(key) {
  9428. const item = this._map.get(key);
  9429. if (!item) {
  9430. return undefined;
  9431. }
  9432. this._map.delete(key);
  9433. this.removeItem(item);
  9434. this._size--;
  9435. return item.value;
  9436. }
  9437. shift() {
  9438. if (!this._head && !this._tail) {
  9439. return undefined;
  9440. }
  9441. if (!this._head || !this._tail) {
  9442. throw new Error('Invalid list');
  9443. }
  9444. const item = this._head;
  9445. this._map.delete(item.key);
  9446. this.removeItem(item);
  9447. this._size--;
  9448. return item.value;
  9449. }
  9450. forEach(callbackfn, thisArg) {
  9451. const state = this._state;
  9452. let current = this._head;
  9453. while (current) {
  9454. if (thisArg) {
  9455. callbackfn.bind(thisArg)(current.value, current.key, this);
  9456. }
  9457. else {
  9458. callbackfn(current.value, current.key, this);
  9459. }
  9460. if (this._state !== state) {
  9461. throw new Error(`LinkedMap got modified during iteration.`);
  9462. }
  9463. current = current.next;
  9464. }
  9465. }
  9466. keys() {
  9467. const map = this;
  9468. const state = this._state;
  9469. let current = this._head;
  9470. const iterator = {
  9471. [Symbol.iterator]() {
  9472. return iterator;
  9473. },
  9474. next() {
  9475. if (map._state !== state) {
  9476. throw new Error(`LinkedMap got modified during iteration.`);
  9477. }
  9478. if (current) {
  9479. const result = { value: current.key, done: false };
  9480. current = current.next;
  9481. return result;
  9482. }
  9483. else {
  9484. return { value: undefined, done: true };
  9485. }
  9486. }
  9487. };
  9488. return iterator;
  9489. }
  9490. values() {
  9491. const map = this;
  9492. const state = this._state;
  9493. let current = this._head;
  9494. const iterator = {
  9495. [Symbol.iterator]() {
  9496. return iterator;
  9497. },
  9498. next() {
  9499. if (map._state !== state) {
  9500. throw new Error(`LinkedMap got modified during iteration.`);
  9501. }
  9502. if (current) {
  9503. const result = { value: current.value, done: false };
  9504. current = current.next;
  9505. return result;
  9506. }
  9507. else {
  9508. return { value: undefined, done: true };
  9509. }
  9510. }
  9511. };
  9512. return iterator;
  9513. }
  9514. entries() {
  9515. const map = this;
  9516. const state = this._state;
  9517. let current = this._head;
  9518. const iterator = {
  9519. [Symbol.iterator]() {
  9520. return iterator;
  9521. },
  9522. next() {
  9523. if (map._state !== state) {
  9524. throw new Error(`LinkedMap got modified during iteration.`);
  9525. }
  9526. if (current) {
  9527. const result = { value: [current.key, current.value], done: false };
  9528. current = current.next;
  9529. return result;
  9530. }
  9531. else {
  9532. return { value: undefined, done: true };
  9533. }
  9534. }
  9535. };
  9536. return iterator;
  9537. }
  9538. [(_b = Symbol.toStringTag, Symbol.iterator)]() {
  9539. return this.entries();
  9540. }
  9541. trimOld(newSize) {
  9542. if (newSize >= this.size) {
  9543. return;
  9544. }
  9545. if (newSize === 0) {
  9546. this.clear();
  9547. return;
  9548. }
  9549. let current = this._head;
  9550. let currentSize = this.size;
  9551. while (current && currentSize > newSize) {
  9552. this._map.delete(current.key);
  9553. current = current.next;
  9554. currentSize--;
  9555. }
  9556. this._head = current;
  9557. this._size = currentSize;
  9558. if (current) {
  9559. current.previous = undefined;
  9560. }
  9561. this._state++;
  9562. }
  9563. trimNew(newSize) {
  9564. if (newSize >= this.size) {
  9565. return;
  9566. }
  9567. if (newSize === 0) {
  9568. this.clear();
  9569. return;
  9570. }
  9571. let current = this._tail;
  9572. let currentSize = this.size;
  9573. while (current && currentSize > newSize) {
  9574. this._map.delete(current.key);
  9575. current = current.previous;
  9576. currentSize--;
  9577. }
  9578. this._tail = current;
  9579. this._size = currentSize;
  9580. if (current) {
  9581. current.next = undefined;
  9582. }
  9583. this._state++;
  9584. }
  9585. addItemFirst(item) {
  9586. // First time Insert
  9587. if (!this._head && !this._tail) {
  9588. this._tail = item;
  9589. }
  9590. else if (!this._head) {
  9591. throw new Error('Invalid list');
  9592. }
  9593. else {
  9594. item.next = this._head;
  9595. this._head.previous = item;
  9596. }
  9597. this._head = item;
  9598. this._state++;
  9599. }
  9600. addItemLast(item) {
  9601. // First time Insert
  9602. if (!this._head && !this._tail) {
  9603. this._head = item;
  9604. }
  9605. else if (!this._tail) {
  9606. throw new Error('Invalid list');
  9607. }
  9608. else {
  9609. item.previous = this._tail;
  9610. this._tail.next = item;
  9611. }
  9612. this._tail = item;
  9613. this._state++;
  9614. }
  9615. removeItem(item) {
  9616. if (item === this._head && item === this._tail) {
  9617. this._head = undefined;
  9618. this._tail = undefined;
  9619. }
  9620. else if (item === this._head) {
  9621. // This can only happen if size === 1 which is handled
  9622. // by the case above.
  9623. if (!item.next) {
  9624. throw new Error('Invalid list');
  9625. }
  9626. item.next.previous = undefined;
  9627. this._head = item.next;
  9628. }
  9629. else if (item === this._tail) {
  9630. // This can only happen if size === 1 which is handled
  9631. // by the case above.
  9632. if (!item.previous) {
  9633. throw new Error('Invalid list');
  9634. }
  9635. item.previous.next = undefined;
  9636. this._tail = item.previous;
  9637. }
  9638. else {
  9639. const next = item.next;
  9640. const previous = item.previous;
  9641. if (!next || !previous) {
  9642. throw new Error('Invalid list');
  9643. }
  9644. next.previous = previous;
  9645. previous.next = next;
  9646. }
  9647. item.next = undefined;
  9648. item.previous = undefined;
  9649. this._state++;
  9650. }
  9651. touch(item, touch) {
  9652. if (!this._head || !this._tail) {
  9653. throw new Error('Invalid list');
  9654. }
  9655. if ((touch !== 1 /* Touch.AsOld */ && touch !== 2 /* Touch.AsNew */)) {
  9656. return;
  9657. }
  9658. if (touch === 1 /* Touch.AsOld */) {
  9659. if (item === this._head) {
  9660. return;
  9661. }
  9662. const next = item.next;
  9663. const previous = item.previous;
  9664. // Unlink the item
  9665. if (item === this._tail) {
  9666. // previous must be defined since item was not head but is tail
  9667. // So there are more than on item in the map
  9668. previous.next = undefined;
  9669. this._tail = previous;
  9670. }
  9671. else {
  9672. // Both next and previous are not undefined since item was neither head nor tail.
  9673. next.previous = previous;
  9674. previous.next = next;
  9675. }
  9676. // Insert the node at head
  9677. item.previous = undefined;
  9678. item.next = this._head;
  9679. this._head.previous = item;
  9680. this._head = item;
  9681. this._state++;
  9682. }
  9683. else if (touch === 2 /* Touch.AsNew */) {
  9684. if (item === this._tail) {
  9685. return;
  9686. }
  9687. const next = item.next;
  9688. const previous = item.previous;
  9689. // Unlink the item.
  9690. if (item === this._head) {
  9691. // next must be defined since item was not tail but is head
  9692. // So there are more than on item in the map
  9693. next.previous = undefined;
  9694. this._head = next;
  9695. }
  9696. else {
  9697. // Both next and previous are not undefined since item was neither head nor tail.
  9698. next.previous = previous;
  9699. previous.next = next;
  9700. }
  9701. item.next = undefined;
  9702. item.previous = this._tail;
  9703. this._tail.next = item;
  9704. this._tail = item;
  9705. this._state++;
  9706. }
  9707. }
  9708. toJSON() {
  9709. const data = [];
  9710. this.forEach((value, key) => {
  9711. data.push([key, value]);
  9712. });
  9713. return data;
  9714. }
  9715. fromJSON(data) {
  9716. this.clear();
  9717. for (const [key, value] of data) {
  9718. this.set(key, value);
  9719. }
  9720. }
  9721. }
  9722. class Cache extends LinkedMap {
  9723. constructor(limit, ratio = 1) {
  9724. super();
  9725. this._limit = limit;
  9726. this._ratio = Math.min(Math.max(0, ratio), 1);
  9727. }
  9728. get limit() {
  9729. return this._limit;
  9730. }
  9731. set limit(limit) {
  9732. this._limit = limit;
  9733. this.checkTrim();
  9734. }
  9735. get(key, touch = 2 /* Touch.AsNew */) {
  9736. return super.get(key, touch);
  9737. }
  9738. peek(key) {
  9739. return super.get(key, 0 /* Touch.None */);
  9740. }
  9741. set(key, value) {
  9742. super.set(key, value, 2 /* Touch.AsNew */);
  9743. return this;
  9744. }
  9745. checkTrim() {
  9746. if (this.size > this._limit) {
  9747. this.trim(Math.round(this._limit * this._ratio));
  9748. }
  9749. }
  9750. }
  9751. class LRUCache extends Cache {
  9752. constructor(limit, ratio = 1) {
  9753. super(limit, ratio);
  9754. }
  9755. trim(newSize) {
  9756. this.trimOld(newSize);
  9757. }
  9758. set(key, value) {
  9759. super.set(key, value);
  9760. this.checkTrim();
  9761. return this;
  9762. }
  9763. }
  9764. class SetMap {
  9765. constructor() {
  9766. this.map = new Map();
  9767. }
  9768. add(key, value) {
  9769. let values = this.map.get(key);
  9770. if (!values) {
  9771. values = new Set();
  9772. this.map.set(key, values);
  9773. }
  9774. values.add(value);
  9775. }
  9776. delete(key, value) {
  9777. const values = this.map.get(key);
  9778. if (!values) {
  9779. return;
  9780. }
  9781. values.delete(value);
  9782. if (values.size === 0) {
  9783. this.map.delete(key);
  9784. }
  9785. }
  9786. forEach(key, fn) {
  9787. const values = this.map.get(key);
  9788. if (!values) {
  9789. return;
  9790. }
  9791. values.forEach(fn);
  9792. }
  9793. get(key) {
  9794. const values = this.map.get(key);
  9795. if (!values) {
  9796. return new Set();
  9797. }
  9798. return values;
  9799. }
  9800. }
  9801. /*---------------------------------------------------------------------------------------------
  9802. * Copyright (c) Microsoft Corporation. All rights reserved.
  9803. * Licensed under the MIT License. See License.txt in the project root for license information.
  9804. *--------------------------------------------------------------------------------------------*/
  9805. new LRUCache(10);
  9806. /*---------------------------------------------------------------------------------------------
  9807. * Copyright (c) Microsoft Corporation. All rights reserved.
  9808. * Licensed under the MIT License. See License.txt in the project root for license information.
  9809. *--------------------------------------------------------------------------------------------*/
  9810. function getAllPropertyNames(obj) {
  9811. let res = [];
  9812. while (Object.prototype !== obj) {
  9813. res = res.concat(Object.getOwnPropertyNames(obj));
  9814. obj = Object.getPrototypeOf(obj);
  9815. }
  9816. return res;
  9817. }
  9818. function getAllMethodNames(obj) {
  9819. const methods = [];
  9820. for (const prop of getAllPropertyNames(obj)) {
  9821. if (typeof obj[prop] === 'function') {
  9822. methods.push(prop);
  9823. }
  9824. }
  9825. return methods;
  9826. }
  9827. function createProxyObject(methodNames, invoke) {
  9828. const createProxyMethod = (method) => {
  9829. return function () {
  9830. const args = Array.prototype.slice.call(arguments, 0);
  9831. return invoke(method, args);
  9832. };
  9833. };
  9834. const result = {};
  9835. for (const methodName of methodNames) {
  9836. result[methodName] = createProxyMethod(methodName);
  9837. }
  9838. return result;
  9839. }
  9840. /*---------------------------------------------------------------------------------------------
  9841. * Copyright (c) Microsoft Corporation. All rights reserved.
  9842. * Licensed under the MIT License. See License.txt in the project root for license information.
  9843. *--------------------------------------------------------------------------------------------*/
  9844. /**
  9845. * Vertical Lane in the overview ruler of the editor.
  9846. */
  9847. var OverviewRulerLane;
  9848. (function (OverviewRulerLane) {
  9849. OverviewRulerLane[OverviewRulerLane["Left"] = 1] = "Left";
  9850. OverviewRulerLane[OverviewRulerLane["Center"] = 2] = "Center";
  9851. OverviewRulerLane[OverviewRulerLane["Right"] = 4] = "Right";
  9852. OverviewRulerLane[OverviewRulerLane["Full"] = 7] = "Full";
  9853. })(OverviewRulerLane || (OverviewRulerLane = {}));
  9854. /**
  9855. * Vertical Lane in the glyph margin of the editor.
  9856. */
  9857. var GlyphMarginLane;
  9858. (function (GlyphMarginLane) {
  9859. GlyphMarginLane[GlyphMarginLane["Left"] = 1] = "Left";
  9860. GlyphMarginLane[GlyphMarginLane["Center"] = 2] = "Center";
  9861. GlyphMarginLane[GlyphMarginLane["Right"] = 3] = "Right";
  9862. })(GlyphMarginLane || (GlyphMarginLane = {}));
  9863. var InjectedTextCursorStops;
  9864. (function (InjectedTextCursorStops) {
  9865. InjectedTextCursorStops[InjectedTextCursorStops["Both"] = 0] = "Both";
  9866. InjectedTextCursorStops[InjectedTextCursorStops["Right"] = 1] = "Right";
  9867. InjectedTextCursorStops[InjectedTextCursorStops["Left"] = 2] = "Left";
  9868. InjectedTextCursorStops[InjectedTextCursorStops["None"] = 3] = "None";
  9869. })(InjectedTextCursorStops || (InjectedTextCursorStops = {}));
  9870. /*---------------------------------------------------------------------------------------------
  9871. * Copyright (c) Microsoft Corporation. All rights reserved.
  9872. * Licensed under the MIT License. See License.txt in the project root for license information.
  9873. *--------------------------------------------------------------------------------------------*/
  9874. function leftIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength) {
  9875. if (matchStartIndex === 0) {
  9876. // Match starts at start of string
  9877. return true;
  9878. }
  9879. const charBefore = text.charCodeAt(matchStartIndex - 1);
  9880. if (wordSeparators.get(charBefore) !== 0 /* WordCharacterClass.Regular */) {
  9881. // The character before the match is a word separator
  9882. return true;
  9883. }
  9884. if (charBefore === 13 /* CharCode.CarriageReturn */ || charBefore === 10 /* CharCode.LineFeed */) {
  9885. // The character before the match is line break or carriage return.
  9886. return true;
  9887. }
  9888. if (matchLength > 0) {
  9889. const firstCharInMatch = text.charCodeAt(matchStartIndex);
  9890. if (wordSeparators.get(firstCharInMatch) !== 0 /* WordCharacterClass.Regular */) {
  9891. // The first character inside the match is a word separator
  9892. return true;
  9893. }
  9894. }
  9895. return false;
  9896. }
  9897. function rightIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength) {
  9898. if (matchStartIndex + matchLength === textLength) {
  9899. // Match ends at end of string
  9900. return true;
  9901. }
  9902. const charAfter = text.charCodeAt(matchStartIndex + matchLength);
  9903. if (wordSeparators.get(charAfter) !== 0 /* WordCharacterClass.Regular */) {
  9904. // The character after the match is a word separator
  9905. return true;
  9906. }
  9907. if (charAfter === 13 /* CharCode.CarriageReturn */ || charAfter === 10 /* CharCode.LineFeed */) {
  9908. // The character after the match is line break or carriage return.
  9909. return true;
  9910. }
  9911. if (matchLength > 0) {
  9912. const lastCharInMatch = text.charCodeAt(matchStartIndex + matchLength - 1);
  9913. if (wordSeparators.get(lastCharInMatch) !== 0 /* WordCharacterClass.Regular */) {
  9914. // The last character in the match is a word separator
  9915. return true;
  9916. }
  9917. }
  9918. return false;
  9919. }
  9920. function isValidMatch(wordSeparators, text, textLength, matchStartIndex, matchLength) {
  9921. return (leftIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength)
  9922. && rightIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength));
  9923. }
  9924. class Searcher {
  9925. constructor(wordSeparators, searchRegex) {
  9926. this._wordSeparators = wordSeparators;
  9927. this._searchRegex = searchRegex;
  9928. this._prevMatchStartIndex = -1;
  9929. this._prevMatchLength = 0;
  9930. }
  9931. reset(lastIndex) {
  9932. this._searchRegex.lastIndex = lastIndex;
  9933. this._prevMatchStartIndex = -1;
  9934. this._prevMatchLength = 0;
  9935. }
  9936. next(text) {
  9937. const textLength = text.length;
  9938. let m;
  9939. do {
  9940. if (this._prevMatchStartIndex + this._prevMatchLength === textLength) {
  9941. // Reached the end of the line
  9942. return null;
  9943. }
  9944. m = this._searchRegex.exec(text);
  9945. if (!m) {
  9946. return null;
  9947. }
  9948. const matchStartIndex = m.index;
  9949. const matchLength = m[0].length;
  9950. if (matchStartIndex === this._prevMatchStartIndex && matchLength === this._prevMatchLength) {
  9951. if (matchLength === 0) {
  9952. // the search result is an empty string and won't advance `regex.lastIndex`, so `regex.exec` will stuck here
  9953. // we attempt to recover from that by advancing by two if surrogate pair found and by one otherwise
  9954. if (getNextCodePoint(text, textLength, this._searchRegex.lastIndex) > 0xFFFF) {
  9955. this._searchRegex.lastIndex += 2;
  9956. }
  9957. else {
  9958. this._searchRegex.lastIndex += 1;
  9959. }
  9960. continue;
  9961. }
  9962. // Exit early if the regex matches the same range twice
  9963. return null;
  9964. }
  9965. this._prevMatchStartIndex = matchStartIndex;
  9966. this._prevMatchLength = matchLength;
  9967. if (!this._wordSeparators || isValidMatch(this._wordSeparators, text, textLength, matchStartIndex, matchLength)) {
  9968. return m;
  9969. }
  9970. } while (m);
  9971. return null;
  9972. }
  9973. }
  9974. /*---------------------------------------------------------------------------------------------
  9975. * Copyright (c) Microsoft Corporation. All rights reserved.
  9976. * Licensed under the MIT License. See License.txt in the project root for license information.
  9977. *--------------------------------------------------------------------------------------------*/
  9978. function assertNever(value, message = 'Unreachable') {
  9979. throw new Error(message);
  9980. }
  9981. /**
  9982. * condition must be side-effect free!
  9983. */
  9984. function assertFn(condition) {
  9985. if (!condition()) {
  9986. // eslint-disable-next-line no-debugger
  9987. debugger;
  9988. // Reevaluate `condition` again to make debugging easier
  9989. condition();
  9990. onUnexpectedError(new BugIndicatingError('Assertion Failed'));
  9991. }
  9992. }
  9993. function checkAdjacentItems(items, predicate) {
  9994. let i = 0;
  9995. while (i < items.length - 1) {
  9996. const a = items[i];
  9997. const b = items[i + 1];
  9998. if (!predicate(a, b)) {
  9999. return false;
  10000. }
  10001. i++;
  10002. }
  10003. return true;
  10004. }
  10005. /*---------------------------------------------------------------------------------------------
  10006. * Copyright (c) Microsoft Corporation. All rights reserved.
  10007. * Licensed under the MIT License. See License.txt in the project root for license information.
  10008. *--------------------------------------------------------------------------------------------*/
  10009. const USUAL_WORD_SEPARATORS = '`~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?';
  10010. /**
  10011. * Create a word definition regular expression based on default word separators.
  10012. * Optionally provide allowed separators that should be included in words.
  10013. *
  10014. * The default would look like this:
  10015. * /(-?\d*\.\d\w*)|([^\`\~\!\@\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g
  10016. */
  10017. function createWordRegExp(allowInWords = '') {
  10018. let source = '(-?\\d*\\.\\d\\w*)|([^';
  10019. for (const sep of USUAL_WORD_SEPARATORS) {
  10020. if (allowInWords.indexOf(sep) >= 0) {
  10021. continue;
  10022. }
  10023. source += '\\' + sep;
  10024. }
  10025. source += '\\s]+)';
  10026. return new RegExp(source, 'g');
  10027. }
  10028. // catches numbers (including floating numbers) in the first group, and alphanum in the second
  10029. const DEFAULT_WORD_REGEXP = createWordRegExp();
  10030. function ensureValidWordDefinition(wordDefinition) {
  10031. let result = DEFAULT_WORD_REGEXP;
  10032. if (wordDefinition && (wordDefinition instanceof RegExp)) {
  10033. if (!wordDefinition.global) {
  10034. let flags = 'g';
  10035. if (wordDefinition.ignoreCase) {
  10036. flags += 'i';
  10037. }
  10038. if (wordDefinition.multiline) {
  10039. flags += 'm';
  10040. }
  10041. if (wordDefinition.unicode) {
  10042. flags += 'u';
  10043. }
  10044. result = new RegExp(wordDefinition.source, flags);
  10045. }
  10046. else {
  10047. result = wordDefinition;
  10048. }
  10049. }
  10050. result.lastIndex = 0;
  10051. return result;
  10052. }
  10053. const _defaultConfig = new LinkedList();
  10054. _defaultConfig.unshift({
  10055. maxLen: 1000,
  10056. windowSize: 15,
  10057. timeBudget: 150
  10058. });
  10059. function getWordAtText(column, wordDefinition, text, textOffset, config) {
  10060. // Ensure the regex has the 'g' flag, otherwise this will loop forever
  10061. wordDefinition = ensureValidWordDefinition(wordDefinition);
  10062. if (!config) {
  10063. config = Iterable.first(_defaultConfig);
  10064. }
  10065. if (text.length > config.maxLen) {
  10066. // don't throw strings that long at the regexp
  10067. // but use a sub-string in which a word must occur
  10068. let start = column - config.maxLen / 2;
  10069. if (start < 0) {
  10070. start = 0;
  10071. }
  10072. else {
  10073. textOffset += start;
  10074. }
  10075. text = text.substring(start, column + config.maxLen / 2);
  10076. return getWordAtText(column, wordDefinition, text, textOffset, config);
  10077. }
  10078. const t1 = Date.now();
  10079. const pos = column - 1 - textOffset;
  10080. let prevRegexIndex = -1;
  10081. let match = null;
  10082. for (let i = 1;; i++) {
  10083. // check time budget
  10084. if (Date.now() - t1 >= config.timeBudget) {
  10085. break;
  10086. }
  10087. // reset the index at which the regexp should start matching, also know where it
  10088. // should stop so that subsequent search don't repeat previous searches
  10089. const regexIndex = pos - config.windowSize * i;
  10090. wordDefinition.lastIndex = Math.max(0, regexIndex);
  10091. const thisMatch = _findRegexMatchEnclosingPosition(wordDefinition, text, pos, prevRegexIndex);
  10092. if (!thisMatch && match) {
  10093. // stop: we have something
  10094. break;
  10095. }
  10096. match = thisMatch;
  10097. // stop: searched at start
  10098. if (regexIndex <= 0) {
  10099. break;
  10100. }
  10101. prevRegexIndex = regexIndex;
  10102. }
  10103. if (match) {
  10104. const result = {
  10105. word: match[0],
  10106. startColumn: textOffset + 1 + match.index,
  10107. endColumn: textOffset + 1 + match.index + match[0].length
  10108. };
  10109. wordDefinition.lastIndex = 0;
  10110. return result;
  10111. }
  10112. return null;
  10113. }
  10114. function _findRegexMatchEnclosingPosition(wordDefinition, text, pos, stopPos) {
  10115. let match;
  10116. while (match = wordDefinition.exec(text)) {
  10117. const matchIndex = match.index || 0;
  10118. if (matchIndex <= pos && wordDefinition.lastIndex >= pos) {
  10119. return match;
  10120. }
  10121. else if (stopPos > 0 && matchIndex > stopPos) {
  10122. return null;
  10123. }
  10124. }
  10125. return null;
  10126. }
  10127. /*---------------------------------------------------------------------------------------------
  10128. * Copyright (c) Microsoft Corporation. All rights reserved.
  10129. * Licensed under the MIT License. See License.txt in the project root for license information.
  10130. *--------------------------------------------------------------------------------------------*/
  10131. class UnicodeTextModelHighlighter {
  10132. static computeUnicodeHighlights(model, options, range) {
  10133. const startLine = range ? range.startLineNumber : 1;
  10134. const endLine = range ? range.endLineNumber : model.getLineCount();
  10135. const codePointHighlighter = new CodePointHighlighter(options);
  10136. const candidates = codePointHighlighter.getCandidateCodePoints();
  10137. let regex;
  10138. if (candidates === 'allNonBasicAscii') {
  10139. regex = new RegExp('[^\\t\\n\\r\\x20-\\x7E]', 'g');
  10140. }
  10141. else {
  10142. regex = new RegExp(`${buildRegExpCharClassExpr(Array.from(candidates))}`, 'g');
  10143. }
  10144. const searcher = new Searcher(null, regex);
  10145. const ranges = [];
  10146. let hasMore = false;
  10147. let m;
  10148. let ambiguousCharacterCount = 0;
  10149. let invisibleCharacterCount = 0;
  10150. let nonBasicAsciiCharacterCount = 0;
  10151. forLoop: for (let lineNumber = startLine, lineCount = endLine; lineNumber <= lineCount; lineNumber++) {
  10152. const lineContent = model.getLineContent(lineNumber);
  10153. const lineLength = lineContent.length;
  10154. // Reset regex to search from the beginning
  10155. searcher.reset(0);
  10156. do {
  10157. m = searcher.next(lineContent);
  10158. if (m) {
  10159. let startIndex = m.index;
  10160. let endIndex = m.index + m[0].length;
  10161. // Extend range to entire code point
  10162. if (startIndex > 0) {
  10163. const charCodeBefore = lineContent.charCodeAt(startIndex - 1);
  10164. if (isHighSurrogate(charCodeBefore)) {
  10165. startIndex--;
  10166. }
  10167. }
  10168. if (endIndex + 1 < lineLength) {
  10169. const charCodeBefore = lineContent.charCodeAt(endIndex - 1);
  10170. if (isHighSurrogate(charCodeBefore)) {
  10171. endIndex++;
  10172. }
  10173. }
  10174. const str = lineContent.substring(startIndex, endIndex);
  10175. let word = getWordAtText(startIndex + 1, DEFAULT_WORD_REGEXP, lineContent, 0);
  10176. if (word && word.endColumn <= startIndex + 1) {
  10177. // The word does not include the problematic character, ignore the word
  10178. word = null;
  10179. }
  10180. const highlightReason = codePointHighlighter.shouldHighlightNonBasicASCII(str, word ? word.word : null);
  10181. if (highlightReason !== 0 /* SimpleHighlightReason.None */) {
  10182. if (highlightReason === 3 /* SimpleHighlightReason.Ambiguous */) {
  10183. ambiguousCharacterCount++;
  10184. }
  10185. else if (highlightReason === 2 /* SimpleHighlightReason.Invisible */) {
  10186. invisibleCharacterCount++;
  10187. }
  10188. else if (highlightReason === 1 /* SimpleHighlightReason.NonBasicASCII */) {
  10189. nonBasicAsciiCharacterCount++;
  10190. }
  10191. else {
  10192. assertNever();
  10193. }
  10194. const MAX_RESULT_LENGTH = 1000;
  10195. if (ranges.length >= MAX_RESULT_LENGTH) {
  10196. hasMore = true;
  10197. break forLoop;
  10198. }
  10199. ranges.push(new Range(lineNumber, startIndex + 1, lineNumber, endIndex + 1));
  10200. }
  10201. }
  10202. } while (m);
  10203. }
  10204. return {
  10205. ranges,
  10206. hasMore,
  10207. ambiguousCharacterCount,
  10208. invisibleCharacterCount,
  10209. nonBasicAsciiCharacterCount
  10210. };
  10211. }
  10212. static computeUnicodeHighlightReason(char, options) {
  10213. const codePointHighlighter = new CodePointHighlighter(options);
  10214. const reason = codePointHighlighter.shouldHighlightNonBasicASCII(char, null);
  10215. switch (reason) {
  10216. case 0 /* SimpleHighlightReason.None */:
  10217. return null;
  10218. case 2 /* SimpleHighlightReason.Invisible */:
  10219. return { kind: 1 /* UnicodeHighlighterReasonKind.Invisible */ };
  10220. case 3 /* SimpleHighlightReason.Ambiguous */: {
  10221. const codePoint = char.codePointAt(0);
  10222. const primaryConfusable = codePointHighlighter.ambiguousCharacters.getPrimaryConfusable(codePoint);
  10223. const notAmbiguousInLocales = AmbiguousCharacters.getLocales().filter((l) => !AmbiguousCharacters.getInstance(new Set([...options.allowedLocales, l])).isAmbiguous(codePoint));
  10224. return { kind: 0 /* UnicodeHighlighterReasonKind.Ambiguous */, confusableWith: String.fromCodePoint(primaryConfusable), notAmbiguousInLocales };
  10225. }
  10226. case 1 /* SimpleHighlightReason.NonBasicASCII */:
  10227. return { kind: 2 /* UnicodeHighlighterReasonKind.NonBasicAscii */ };
  10228. }
  10229. }
  10230. }
  10231. function buildRegExpCharClassExpr(codePoints, flags) {
  10232. const src = `[${escapeRegExpCharacters(codePoints.map((i) => String.fromCodePoint(i)).join(''))}]`;
  10233. return src;
  10234. }
  10235. class CodePointHighlighter {
  10236. constructor(options) {
  10237. this.options = options;
  10238. this.allowedCodePoints = new Set(options.allowedCodePoints);
  10239. this.ambiguousCharacters = AmbiguousCharacters.getInstance(new Set(options.allowedLocales));
  10240. }
  10241. getCandidateCodePoints() {
  10242. if (this.options.nonBasicASCII) {
  10243. return 'allNonBasicAscii';
  10244. }
  10245. const set = new Set();
  10246. if (this.options.invisibleCharacters) {
  10247. for (const cp of InvisibleCharacters.codePoints) {
  10248. if (!isAllowedInvisibleCharacter(String.fromCodePoint(cp))) {
  10249. set.add(cp);
  10250. }
  10251. }
  10252. }
  10253. if (this.options.ambiguousCharacters) {
  10254. for (const cp of this.ambiguousCharacters.getConfusableCodePoints()) {
  10255. set.add(cp);
  10256. }
  10257. }
  10258. for (const cp of this.allowedCodePoints) {
  10259. set.delete(cp);
  10260. }
  10261. return set;
  10262. }
  10263. shouldHighlightNonBasicASCII(character, wordContext) {
  10264. const codePoint = character.codePointAt(0);
  10265. if (this.allowedCodePoints.has(codePoint)) {
  10266. return 0 /* SimpleHighlightReason.None */;
  10267. }
  10268. if (this.options.nonBasicASCII) {
  10269. return 1 /* SimpleHighlightReason.NonBasicASCII */;
  10270. }
  10271. let hasBasicASCIICharacters = false;
  10272. let hasNonConfusableNonBasicAsciiCharacter = false;
  10273. if (wordContext) {
  10274. for (const char of wordContext) {
  10275. const codePoint = char.codePointAt(0);
  10276. const isBasicASCII$1 = isBasicASCII(char);
  10277. hasBasicASCIICharacters = hasBasicASCIICharacters || isBasicASCII$1;
  10278. if (!isBasicASCII$1 &&
  10279. !this.ambiguousCharacters.isAmbiguous(codePoint) &&
  10280. !InvisibleCharacters.isInvisibleCharacter(codePoint)) {
  10281. hasNonConfusableNonBasicAsciiCharacter = true;
  10282. }
  10283. }
  10284. }
  10285. if (
  10286. /* Don't allow mixing weird looking characters with ASCII */ !hasBasicASCIICharacters &&
  10287. /* Is there an obviously weird looking character? */ hasNonConfusableNonBasicAsciiCharacter) {
  10288. return 0 /* SimpleHighlightReason.None */;
  10289. }
  10290. if (this.options.invisibleCharacters) {
  10291. // TODO check for emojis
  10292. if (!isAllowedInvisibleCharacter(character) && InvisibleCharacters.isInvisibleCharacter(codePoint)) {
  10293. return 2 /* SimpleHighlightReason.Invisible */;
  10294. }
  10295. }
  10296. if (this.options.ambiguousCharacters) {
  10297. if (this.ambiguousCharacters.isAmbiguous(codePoint)) {
  10298. return 3 /* SimpleHighlightReason.Ambiguous */;
  10299. }
  10300. }
  10301. return 0 /* SimpleHighlightReason.None */;
  10302. }
  10303. }
  10304. function isAllowedInvisibleCharacter(character) {
  10305. return character === ' ' || character === '\n' || character === '\t';
  10306. }
  10307. /*---------------------------------------------------------------------------------------------
  10308. * Copyright (c) Microsoft Corporation. All rights reserved.
  10309. * Licensed under the MIT License. See License.txt in the project root for license information.
  10310. *--------------------------------------------------------------------------------------------*/
  10311. class LinesDiff {
  10312. constructor(changes,
  10313. /**
  10314. * Sorted by original line ranges.
  10315. * The original line ranges and the modified line ranges must be disjoint (but can be touching).
  10316. */
  10317. moves,
  10318. /**
  10319. * Indicates if the time out was reached.
  10320. * In that case, the diffs might be an approximation and the user should be asked to rerun the diff with more time.
  10321. */
  10322. hitTimeout) {
  10323. this.changes = changes;
  10324. this.moves = moves;
  10325. this.hitTimeout = hitTimeout;
  10326. }
  10327. }
  10328. class MovedText {
  10329. constructor(lineRangeMapping, changes) {
  10330. this.lineRangeMapping = lineRangeMapping;
  10331. this.changes = changes;
  10332. }
  10333. }
  10334. /*---------------------------------------------------------------------------------------------
  10335. * Copyright (c) Microsoft Corporation. All rights reserved.
  10336. * Licensed under the MIT License. See License.txt in the project root for license information.
  10337. *--------------------------------------------------------------------------------------------*/
  10338. /**
  10339. * A range of offsets (0-based).
  10340. */
  10341. class OffsetRange {
  10342. static addRange(range, sortedRanges) {
  10343. let i = 0;
  10344. while (i < sortedRanges.length && sortedRanges[i].endExclusive < range.start) {
  10345. i++;
  10346. }
  10347. let j = i;
  10348. while (j < sortedRanges.length && sortedRanges[j].start <= range.endExclusive) {
  10349. j++;
  10350. }
  10351. if (i === j) {
  10352. sortedRanges.splice(i, 0, range);
  10353. }
  10354. else {
  10355. const start = Math.min(range.start, sortedRanges[i].start);
  10356. const end = Math.max(range.endExclusive, sortedRanges[j - 1].endExclusive);
  10357. sortedRanges.splice(i, j - i, new OffsetRange(start, end));
  10358. }
  10359. }
  10360. static tryCreate(start, endExclusive) {
  10361. if (start > endExclusive) {
  10362. return undefined;
  10363. }
  10364. return new OffsetRange(start, endExclusive);
  10365. }
  10366. static ofLength(length) {
  10367. return new OffsetRange(0, length);
  10368. }
  10369. static ofStartAndLength(start, length) {
  10370. return new OffsetRange(start, start + length);
  10371. }
  10372. constructor(start, endExclusive) {
  10373. this.start = start;
  10374. this.endExclusive = endExclusive;
  10375. if (start > endExclusive) {
  10376. throw new BugIndicatingError(`Invalid range: ${this.toString()}`);
  10377. }
  10378. }
  10379. get isEmpty() {
  10380. return this.start === this.endExclusive;
  10381. }
  10382. delta(offset) {
  10383. return new OffsetRange(this.start + offset, this.endExclusive + offset);
  10384. }
  10385. deltaStart(offset) {
  10386. return new OffsetRange(this.start + offset, this.endExclusive);
  10387. }
  10388. deltaEnd(offset) {
  10389. return new OffsetRange(this.start, this.endExclusive + offset);
  10390. }
  10391. get length() {
  10392. return this.endExclusive - this.start;
  10393. }
  10394. toString() {
  10395. return `[${this.start}, ${this.endExclusive})`;
  10396. }
  10397. contains(offset) {
  10398. return this.start <= offset && offset < this.endExclusive;
  10399. }
  10400. /**
  10401. * for all numbers n: range1.contains(n) or range2.contains(n) => range1.join(range2).contains(n)
  10402. * The joined range is the smallest range that contains both ranges.
  10403. */
  10404. join(other) {
  10405. return new OffsetRange(Math.min(this.start, other.start), Math.max(this.endExclusive, other.endExclusive));
  10406. }
  10407. /**
  10408. * for all numbers n: range1.contains(n) and range2.contains(n) <=> range1.intersect(range2).contains(n)
  10409. *
  10410. * The resulting range is empty if the ranges do not intersect, but touch.
  10411. * If the ranges don't even touch, the result is undefined.
  10412. */
  10413. intersect(other) {
  10414. const start = Math.max(this.start, other.start);
  10415. const end = Math.min(this.endExclusive, other.endExclusive);
  10416. if (start <= end) {
  10417. return new OffsetRange(start, end);
  10418. }
  10419. return undefined;
  10420. }
  10421. intersects(other) {
  10422. const start = Math.max(this.start, other.start);
  10423. const end = Math.min(this.endExclusive, other.endExclusive);
  10424. return start < end;
  10425. }
  10426. isBefore(other) {
  10427. return this.endExclusive <= other.start;
  10428. }
  10429. isAfter(other) {
  10430. return this.start >= other.endExclusive;
  10431. }
  10432. slice(arr) {
  10433. return arr.slice(this.start, this.endExclusive);
  10434. }
  10435. substring(str) {
  10436. return str.substring(this.start, this.endExclusive);
  10437. }
  10438. /**
  10439. * Returns the given value if it is contained in this instance, otherwise the closest value that is contained.
  10440. * The range must not be empty.
  10441. */
  10442. clip(value) {
  10443. if (this.isEmpty) {
  10444. throw new BugIndicatingError(`Invalid clipping range: ${this.toString()}`);
  10445. }
  10446. return Math.max(this.start, Math.min(this.endExclusive - 1, value));
  10447. }
  10448. /**
  10449. * Returns `r := value + k * length` such that `r` is contained in this range.
  10450. * The range must not be empty.
  10451. *
  10452. * E.g. `[5, 10).clipCyclic(10) === 5`, `[5, 10).clipCyclic(11) === 6` and `[5, 10).clipCyclic(4) === 9`.
  10453. */
  10454. clipCyclic(value) {
  10455. if (this.isEmpty) {
  10456. throw new BugIndicatingError(`Invalid clipping range: ${this.toString()}`);
  10457. }
  10458. if (value < this.start) {
  10459. return this.endExclusive - ((this.start - value) % this.length);
  10460. }
  10461. if (value >= this.endExclusive) {
  10462. return this.start + ((value - this.start) % this.length);
  10463. }
  10464. return value;
  10465. }
  10466. forEach(f) {
  10467. for (let i = this.start; i < this.endExclusive; i++) {
  10468. f(i);
  10469. }
  10470. }
  10471. }
  10472. /*---------------------------------------------------------------------------------------------
  10473. * Copyright (c) Microsoft Corporation. All rights reserved.
  10474. * Licensed under the MIT License. See License.txt in the project root for license information.
  10475. *--------------------------------------------------------------------------------------------*/
  10476. /**
  10477. * Finds the last item where predicate is true using binary search.
  10478. * `predicate` must be monotonous, i.e. `arr.map(predicate)` must be like `[true, ..., true, false, ..., false]`!
  10479. *
  10480. * @returns `undefined` if no item matches, otherwise the last item that matches the predicate.
  10481. */
  10482. function findLastMonotonous(array, predicate) {
  10483. const idx = findLastIdxMonotonous(array, predicate);
  10484. return idx === -1 ? undefined : array[idx];
  10485. }
  10486. /**
  10487. * Finds the last item where predicate is true using binary search.
  10488. * `predicate` must be monotonous, i.e. `arr.map(predicate)` must be like `[true, ..., true, false, ..., false]`!
  10489. *
  10490. * @returns `startIdx - 1` if predicate is false for all items, otherwise the index of the last item that matches the predicate.
  10491. */
  10492. function findLastIdxMonotonous(array, predicate, startIdx = 0, endIdxEx = array.length) {
  10493. let i = startIdx;
  10494. let j = endIdxEx;
  10495. while (i < j) {
  10496. const k = Math.floor((i + j) / 2);
  10497. if (predicate(array[k])) {
  10498. i = k + 1;
  10499. }
  10500. else {
  10501. j = k;
  10502. }
  10503. }
  10504. return i - 1;
  10505. }
  10506. /**
  10507. * Finds the first item where predicate is true using binary search.
  10508. * `predicate` must be monotonous, i.e. `arr.map(predicate)` must be like `[false, ..., false, true, ..., true]`!
  10509. *
  10510. * @returns `undefined` if no item matches, otherwise the first item that matches the predicate.
  10511. */
  10512. function findFirstMonotonous(array, predicate) {
  10513. const idx = findFirstIdxMonotonousOrArrLen(array, predicate);
  10514. return idx === array.length ? undefined : array[idx];
  10515. }
  10516. /**
  10517. * Finds the first item where predicate is true using binary search.
  10518. * `predicate` must be monotonous, i.e. `arr.map(predicate)` must be like `[false, ..., false, true, ..., true]`!
  10519. *
  10520. * @returns `endIdxEx` if predicate is false for all items, otherwise the index of the first item that matches the predicate.
  10521. */
  10522. function findFirstIdxMonotonousOrArrLen(array, predicate, startIdx = 0, endIdxEx = array.length) {
  10523. let i = startIdx;
  10524. let j = endIdxEx;
  10525. while (i < j) {
  10526. const k = Math.floor((i + j) / 2);
  10527. if (predicate(array[k])) {
  10528. j = k;
  10529. }
  10530. else {
  10531. i = k + 1;
  10532. }
  10533. }
  10534. return i;
  10535. }
  10536. /**
  10537. * Use this when
  10538. * * You have a sorted array
  10539. * * You query this array with a monotonous predicate to find the last item that has a certain property.
  10540. * * You query this array multiple times with monotonous predicates that get weaker and weaker.
  10541. */
  10542. class MonotonousArray {
  10543. static { this.assertInvariants = false; }
  10544. constructor(_array) {
  10545. this._array = _array;
  10546. this._findLastMonotonousLastIdx = 0;
  10547. }
  10548. /**
  10549. * The predicate must be monotonous, i.e. `arr.map(predicate)` must be like `[true, ..., true, false, ..., false]`!
  10550. * For subsequent calls, current predicate must be weaker than (or equal to) the previous predicate, i.e. more entries must be `true`.
  10551. */
  10552. findLastMonotonous(predicate) {
  10553. if (MonotonousArray.assertInvariants) {
  10554. if (this._prevFindLastPredicate) {
  10555. for (const item of this._array) {
  10556. if (this._prevFindLastPredicate(item) && !predicate(item)) {
  10557. throw new Error('MonotonousArray: current predicate must be weaker than (or equal to) the previous predicate.');
  10558. }
  10559. }
  10560. }
  10561. this._prevFindLastPredicate = predicate;
  10562. }
  10563. const idx = findLastIdxMonotonous(this._array, predicate, this._findLastMonotonousLastIdx);
  10564. this._findLastMonotonousLastIdx = idx + 1;
  10565. return idx === -1 ? undefined : this._array[idx];
  10566. }
  10567. }
  10568. /*---------------------------------------------------------------------------------------------
  10569. * Copyright (c) Microsoft Corporation. All rights reserved.
  10570. * Licensed under the MIT License. See License.txt in the project root for license information.
  10571. *--------------------------------------------------------------------------------------------*/
  10572. /**
  10573. * A range of lines (1-based).
  10574. */
  10575. class LineRange {
  10576. static fromRangeInclusive(range) {
  10577. return new LineRange(range.startLineNumber, range.endLineNumber + 1);
  10578. }
  10579. /**
  10580. * @param lineRanges An array of sorted line ranges.
  10581. */
  10582. static joinMany(lineRanges) {
  10583. if (lineRanges.length === 0) {
  10584. return [];
  10585. }
  10586. let result = new LineRangeSet(lineRanges[0].slice());
  10587. for (let i = 1; i < lineRanges.length; i++) {
  10588. result = result.getUnion(new LineRangeSet(lineRanges[i].slice()));
  10589. }
  10590. return result.ranges;
  10591. }
  10592. static join(lineRanges) {
  10593. if (lineRanges.length === 0) {
  10594. throw new BugIndicatingError('lineRanges cannot be empty');
  10595. }
  10596. let startLineNumber = lineRanges[0].startLineNumber;
  10597. let endLineNumberExclusive = lineRanges[0].endLineNumberExclusive;
  10598. for (let i = 1; i < lineRanges.length; i++) {
  10599. startLineNumber = Math.min(startLineNumber, lineRanges[i].startLineNumber);
  10600. endLineNumberExclusive = Math.max(endLineNumberExclusive, lineRanges[i].endLineNumberExclusive);
  10601. }
  10602. return new LineRange(startLineNumber, endLineNumberExclusive);
  10603. }
  10604. static ofLength(startLineNumber, length) {
  10605. return new LineRange(startLineNumber, startLineNumber + length);
  10606. }
  10607. /**
  10608. * @internal
  10609. */
  10610. static deserialize(lineRange) {
  10611. return new LineRange(lineRange[0], lineRange[1]);
  10612. }
  10613. constructor(startLineNumber, endLineNumberExclusive) {
  10614. if (startLineNumber > endLineNumberExclusive) {
  10615. throw new BugIndicatingError(`startLineNumber ${startLineNumber} cannot be after endLineNumberExclusive ${endLineNumberExclusive}`);
  10616. }
  10617. this.startLineNumber = startLineNumber;
  10618. this.endLineNumberExclusive = endLineNumberExclusive;
  10619. }
  10620. /**
  10621. * Indicates if this line range contains the given line number.
  10622. */
  10623. contains(lineNumber) {
  10624. return this.startLineNumber <= lineNumber && lineNumber < this.endLineNumberExclusive;
  10625. }
  10626. /**
  10627. * Indicates if this line range is empty.
  10628. */
  10629. get isEmpty() {
  10630. return this.startLineNumber === this.endLineNumberExclusive;
  10631. }
  10632. /**
  10633. * Moves this line range by the given offset of line numbers.
  10634. */
  10635. delta(offset) {
  10636. return new LineRange(this.startLineNumber + offset, this.endLineNumberExclusive + offset);
  10637. }
  10638. deltaLength(offset) {
  10639. return new LineRange(this.startLineNumber, this.endLineNumberExclusive + offset);
  10640. }
  10641. /**
  10642. * The number of lines this line range spans.
  10643. */
  10644. get length() {
  10645. return this.endLineNumberExclusive - this.startLineNumber;
  10646. }
  10647. /**
  10648. * Creates a line range that combines this and the given line range.
  10649. */
  10650. join(other) {
  10651. return new LineRange(Math.min(this.startLineNumber, other.startLineNumber), Math.max(this.endLineNumberExclusive, other.endLineNumberExclusive));
  10652. }
  10653. toString() {
  10654. return `[${this.startLineNumber},${this.endLineNumberExclusive})`;
  10655. }
  10656. /**
  10657. * The resulting range is empty if the ranges do not intersect, but touch.
  10658. * If the ranges don't even touch, the result is undefined.
  10659. */
  10660. intersect(other) {
  10661. const startLineNumber = Math.max(this.startLineNumber, other.startLineNumber);
  10662. const endLineNumberExclusive = Math.min(this.endLineNumberExclusive, other.endLineNumberExclusive);
  10663. if (startLineNumber <= endLineNumberExclusive) {
  10664. return new LineRange(startLineNumber, endLineNumberExclusive);
  10665. }
  10666. return undefined;
  10667. }
  10668. intersectsStrict(other) {
  10669. return this.startLineNumber < other.endLineNumberExclusive && other.startLineNumber < this.endLineNumberExclusive;
  10670. }
  10671. overlapOrTouch(other) {
  10672. return this.startLineNumber <= other.endLineNumberExclusive && other.startLineNumber <= this.endLineNumberExclusive;
  10673. }
  10674. equals(b) {
  10675. return this.startLineNumber === b.startLineNumber && this.endLineNumberExclusive === b.endLineNumberExclusive;
  10676. }
  10677. toInclusiveRange() {
  10678. if (this.isEmpty) {
  10679. return null;
  10680. }
  10681. return new Range(this.startLineNumber, 1, this.endLineNumberExclusive - 1, Number.MAX_SAFE_INTEGER);
  10682. }
  10683. /**
  10684. * @deprecated Using this function is discouraged because it might lead to bugs: The end position is not guaranteed to be a valid position!
  10685. */
  10686. toExclusiveRange() {
  10687. return new Range(this.startLineNumber, 1, this.endLineNumberExclusive, 1);
  10688. }
  10689. mapToLineArray(f) {
  10690. const result = [];
  10691. for (let lineNumber = this.startLineNumber; lineNumber < this.endLineNumberExclusive; lineNumber++) {
  10692. result.push(f(lineNumber));
  10693. }
  10694. return result;
  10695. }
  10696. forEach(f) {
  10697. for (let lineNumber = this.startLineNumber; lineNumber < this.endLineNumberExclusive; lineNumber++) {
  10698. f(lineNumber);
  10699. }
  10700. }
  10701. /**
  10702. * @internal
  10703. */
  10704. serialize() {
  10705. return [this.startLineNumber, this.endLineNumberExclusive];
  10706. }
  10707. includes(lineNumber) {
  10708. return this.startLineNumber <= lineNumber && lineNumber < this.endLineNumberExclusive;
  10709. }
  10710. /**
  10711. * Converts this 1-based line range to a 0-based offset range (subtracts 1!).
  10712. * @internal
  10713. */
  10714. toOffsetRange() {
  10715. return new OffsetRange(this.startLineNumber - 1, this.endLineNumberExclusive - 1);
  10716. }
  10717. }
  10718. class LineRangeSet {
  10719. constructor(
  10720. /**
  10721. * Sorted by start line number.
  10722. * No two line ranges are touching or intersecting.
  10723. */
  10724. _normalizedRanges = []) {
  10725. this._normalizedRanges = _normalizedRanges;
  10726. }
  10727. get ranges() {
  10728. return this._normalizedRanges;
  10729. }
  10730. addRange(range) {
  10731. if (range.length === 0) {
  10732. return;
  10733. }
  10734. // Idea: Find joinRange such that:
  10735. // replaceRange = _normalizedRanges.replaceRange(joinRange, range.joinAll(joinRange.map(idx => this._normalizedRanges[idx])))
  10736. // idx of first element that touches range or that is after range
  10737. const joinRangeStartIdx = findFirstIdxMonotonousOrArrLen(this._normalizedRanges, r => r.endLineNumberExclusive >= range.startLineNumber);
  10738. // idx of element after { last element that touches range or that is before range }
  10739. const joinRangeEndIdxExclusive = findLastIdxMonotonous(this._normalizedRanges, r => r.startLineNumber <= range.endLineNumberExclusive) + 1;
  10740. if (joinRangeStartIdx === joinRangeEndIdxExclusive) {
  10741. // If there is no element that touches range, then joinRangeStartIdx === joinRangeEndIdxExclusive and that value is the index of the element after range
  10742. this._normalizedRanges.splice(joinRangeStartIdx, 0, range);
  10743. }
  10744. else if (joinRangeStartIdx === joinRangeEndIdxExclusive - 1) {
  10745. // Else, there is an element that touches range and in this case it is both the first and last element. Thus we can replace it
  10746. const joinRange = this._normalizedRanges[joinRangeStartIdx];
  10747. this._normalizedRanges[joinRangeStartIdx] = joinRange.join(range);
  10748. }
  10749. else {
  10750. // First and last element are different - we need to replace the entire range
  10751. const joinRange = this._normalizedRanges[joinRangeStartIdx].join(this._normalizedRanges[joinRangeEndIdxExclusive - 1]).join(range);
  10752. this._normalizedRanges.splice(joinRangeStartIdx, joinRangeEndIdxExclusive - joinRangeStartIdx, joinRange);
  10753. }
  10754. }
  10755. contains(lineNumber) {
  10756. const rangeThatStartsBeforeEnd = findLastMonotonous(this._normalizedRanges, r => r.startLineNumber <= lineNumber);
  10757. return !!rangeThatStartsBeforeEnd && rangeThatStartsBeforeEnd.endLineNumberExclusive > lineNumber;
  10758. }
  10759. intersects(range) {
  10760. const rangeThatStartsBeforeEnd = findLastMonotonous(this._normalizedRanges, r => r.startLineNumber < range.endLineNumberExclusive);
  10761. return !!rangeThatStartsBeforeEnd && rangeThatStartsBeforeEnd.endLineNumberExclusive > range.startLineNumber;
  10762. }
  10763. getUnion(other) {
  10764. if (this._normalizedRanges.length === 0) {
  10765. return other;
  10766. }
  10767. if (other._normalizedRanges.length === 0) {
  10768. return this;
  10769. }
  10770. const result = [];
  10771. let i1 = 0;
  10772. let i2 = 0;
  10773. let current = null;
  10774. while (i1 < this._normalizedRanges.length || i2 < other._normalizedRanges.length) {
  10775. let next = null;
  10776. if (i1 < this._normalizedRanges.length && i2 < other._normalizedRanges.length) {
  10777. const lineRange1 = this._normalizedRanges[i1];
  10778. const lineRange2 = other._normalizedRanges[i2];
  10779. if (lineRange1.startLineNumber < lineRange2.startLineNumber) {
  10780. next = lineRange1;
  10781. i1++;
  10782. }
  10783. else {
  10784. next = lineRange2;
  10785. i2++;
  10786. }
  10787. }
  10788. else if (i1 < this._normalizedRanges.length) {
  10789. next = this._normalizedRanges[i1];
  10790. i1++;
  10791. }
  10792. else {
  10793. next = other._normalizedRanges[i2];
  10794. i2++;
  10795. }
  10796. if (current === null) {
  10797. current = next;
  10798. }
  10799. else {
  10800. if (current.endLineNumberExclusive >= next.startLineNumber) {
  10801. // merge
  10802. current = new LineRange(current.startLineNumber, Math.max(current.endLineNumberExclusive, next.endLineNumberExclusive));
  10803. }
  10804. else {
  10805. // push
  10806. result.push(current);
  10807. current = next;
  10808. }
  10809. }
  10810. }
  10811. if (current !== null) {
  10812. result.push(current);
  10813. }
  10814. return new LineRangeSet(result);
  10815. }
  10816. /**
  10817. * Subtracts all ranges in this set from `range` and returns the result.
  10818. */
  10819. subtractFrom(range) {
  10820. // idx of first element that touches range or that is after range
  10821. const joinRangeStartIdx = findFirstIdxMonotonousOrArrLen(this._normalizedRanges, r => r.endLineNumberExclusive >= range.startLineNumber);
  10822. // idx of element after { last element that touches range or that is before range }
  10823. const joinRangeEndIdxExclusive = findLastIdxMonotonous(this._normalizedRanges, r => r.startLineNumber <= range.endLineNumberExclusive) + 1;
  10824. if (joinRangeStartIdx === joinRangeEndIdxExclusive) {
  10825. return new LineRangeSet([range]);
  10826. }
  10827. const result = [];
  10828. let startLineNumber = range.startLineNumber;
  10829. for (let i = joinRangeStartIdx; i < joinRangeEndIdxExclusive; i++) {
  10830. const r = this._normalizedRanges[i];
  10831. if (r.startLineNumber > startLineNumber) {
  10832. result.push(new LineRange(startLineNumber, r.startLineNumber));
  10833. }
  10834. startLineNumber = r.endLineNumberExclusive;
  10835. }
  10836. if (startLineNumber < range.endLineNumberExclusive) {
  10837. result.push(new LineRange(startLineNumber, range.endLineNumberExclusive));
  10838. }
  10839. return new LineRangeSet(result);
  10840. }
  10841. toString() {
  10842. return this._normalizedRanges.map(r => r.toString()).join(', ');
  10843. }
  10844. getIntersection(other) {
  10845. const result = [];
  10846. let i1 = 0;
  10847. let i2 = 0;
  10848. while (i1 < this._normalizedRanges.length && i2 < other._normalizedRanges.length) {
  10849. const r1 = this._normalizedRanges[i1];
  10850. const r2 = other._normalizedRanges[i2];
  10851. const i = r1.intersect(r2);
  10852. if (i && !i.isEmpty) {
  10853. result.push(i);
  10854. }
  10855. if (r1.endLineNumberExclusive < r2.endLineNumberExclusive) {
  10856. i1++;
  10857. }
  10858. else {
  10859. i2++;
  10860. }
  10861. }
  10862. return new LineRangeSet(result);
  10863. }
  10864. getWithDelta(value) {
  10865. return new LineRangeSet(this._normalizedRanges.map(r => r.delta(value)));
  10866. }
  10867. }
  10868. /*---------------------------------------------------------------------------------------------
  10869. * Copyright (c) Microsoft Corporation. All rights reserved.
  10870. * Licensed under the MIT License. See License.txt in the project root for license information.
  10871. *--------------------------------------------------------------------------------------------*/
  10872. /**
  10873. * Represents a non-negative length of text in terms of line and column count.
  10874. */
  10875. class TextLength {
  10876. static { this.zero = new TextLength(0, 0); }
  10877. static betweenPositions(position1, position2) {
  10878. if (position1.lineNumber === position2.lineNumber) {
  10879. return new TextLength(0, position2.column - position1.column);
  10880. }
  10881. else {
  10882. return new TextLength(position2.lineNumber - position1.lineNumber, position2.column - 1);
  10883. }
  10884. }
  10885. static ofRange(range) {
  10886. return TextLength.betweenPositions(range.getStartPosition(), range.getEndPosition());
  10887. }
  10888. static ofText(text) {
  10889. let line = 0;
  10890. let column = 0;
  10891. for (const c of text) {
  10892. if (c === '\n') {
  10893. line++;
  10894. column = 0;
  10895. }
  10896. else {
  10897. column++;
  10898. }
  10899. }
  10900. return new TextLength(line, column);
  10901. }
  10902. constructor(lineCount, columnCount) {
  10903. this.lineCount = lineCount;
  10904. this.columnCount = columnCount;
  10905. }
  10906. isGreaterThanOrEqualTo(other) {
  10907. if (this.lineCount !== other.lineCount) {
  10908. return this.lineCount > other.lineCount;
  10909. }
  10910. return this.columnCount >= other.columnCount;
  10911. }
  10912. createRange(startPosition) {
  10913. if (this.lineCount === 0) {
  10914. return new Range(startPosition.lineNumber, startPosition.column, startPosition.lineNumber, startPosition.column + this.columnCount);
  10915. }
  10916. else {
  10917. return new Range(startPosition.lineNumber, startPosition.column, startPosition.lineNumber + this.lineCount, this.columnCount + 1);
  10918. }
  10919. }
  10920. addToPosition(position) {
  10921. if (this.lineCount === 0) {
  10922. return new Position(position.lineNumber, position.column + this.columnCount);
  10923. }
  10924. else {
  10925. return new Position(position.lineNumber + this.lineCount, this.columnCount + 1);
  10926. }
  10927. }
  10928. toString() {
  10929. return `${this.lineCount},${this.columnCount}`;
  10930. }
  10931. }
  10932. /*---------------------------------------------------------------------------------------------
  10933. * Copyright (c) Microsoft Corporation. All rights reserved.
  10934. * Licensed under the MIT License. See License.txt in the project root for license information.
  10935. *--------------------------------------------------------------------------------------------*/
  10936. class SingleTextEdit {
  10937. constructor(range, text) {
  10938. this.range = range;
  10939. this.text = text;
  10940. }
  10941. toSingleEditOperation() {
  10942. return {
  10943. range: this.range,
  10944. text: this.text,
  10945. };
  10946. }
  10947. }
  10948. /*---------------------------------------------------------------------------------------------
  10949. * Copyright (c) Microsoft Corporation. All rights reserved.
  10950. * Licensed under the MIT License. See License.txt in the project root for license information.
  10951. *--------------------------------------------------------------------------------------------*/
  10952. /**
  10953. * Maps a line range in the original text model to a line range in the modified text model.
  10954. */
  10955. class LineRangeMapping {
  10956. static inverse(mapping, originalLineCount, modifiedLineCount) {
  10957. const result = [];
  10958. let lastOriginalEndLineNumber = 1;
  10959. let lastModifiedEndLineNumber = 1;
  10960. for (const m of mapping) {
  10961. const r = new LineRangeMapping(new LineRange(lastOriginalEndLineNumber, m.original.startLineNumber), new LineRange(lastModifiedEndLineNumber, m.modified.startLineNumber));
  10962. if (!r.modified.isEmpty) {
  10963. result.push(r);
  10964. }
  10965. lastOriginalEndLineNumber = m.original.endLineNumberExclusive;
  10966. lastModifiedEndLineNumber = m.modified.endLineNumberExclusive;
  10967. }
  10968. const r = new LineRangeMapping(new LineRange(lastOriginalEndLineNumber, originalLineCount + 1), new LineRange(lastModifiedEndLineNumber, modifiedLineCount + 1));
  10969. if (!r.modified.isEmpty) {
  10970. result.push(r);
  10971. }
  10972. return result;
  10973. }
  10974. static clip(mapping, originalRange, modifiedRange) {
  10975. const result = [];
  10976. for (const m of mapping) {
  10977. const original = m.original.intersect(originalRange);
  10978. const modified = m.modified.intersect(modifiedRange);
  10979. if (original && !original.isEmpty && modified && !modified.isEmpty) {
  10980. result.push(new LineRangeMapping(original, modified));
  10981. }
  10982. }
  10983. return result;
  10984. }
  10985. constructor(originalRange, modifiedRange) {
  10986. this.original = originalRange;
  10987. this.modified = modifiedRange;
  10988. }
  10989. toString() {
  10990. return `{${this.original.toString()}->${this.modified.toString()}}`;
  10991. }
  10992. flip() {
  10993. return new LineRangeMapping(this.modified, this.original);
  10994. }
  10995. join(other) {
  10996. return new LineRangeMapping(this.original.join(other.original), this.modified.join(other.modified));
  10997. }
  10998. /**
  10999. * This method assumes that the LineRangeMapping describes a valid diff!
  11000. * I.e. if one range is empty, the other range cannot be the entire document.
  11001. * It avoids various problems when the line range points to non-existing line-numbers.
  11002. */
  11003. toRangeMapping() {
  11004. const origInclusiveRange = this.original.toInclusiveRange();
  11005. const modInclusiveRange = this.modified.toInclusiveRange();
  11006. if (origInclusiveRange && modInclusiveRange) {
  11007. return new RangeMapping(origInclusiveRange, modInclusiveRange);
  11008. }
  11009. else if (this.original.startLineNumber === 1 || this.modified.startLineNumber === 1) {
  11010. if (!(this.modified.startLineNumber === 1 && this.original.startLineNumber === 1)) {
  11011. // If one line range starts at 1, the other one must start at 1 as well.
  11012. throw new BugIndicatingError('not a valid diff');
  11013. }
  11014. // Because one range is empty and both ranges start at line 1, none of the ranges can cover all lines.
  11015. // Thus, `endLineNumberExclusive` is a valid line number.
  11016. return new RangeMapping(new Range(this.original.startLineNumber, 1, this.original.endLineNumberExclusive, 1), new Range(this.modified.startLineNumber, 1, this.modified.endLineNumberExclusive, 1));
  11017. }
  11018. else {
  11019. // We can assume here that both startLineNumbers are greater than 1.
  11020. return new RangeMapping(new Range(this.original.startLineNumber - 1, Number.MAX_SAFE_INTEGER, this.original.endLineNumberExclusive - 1, Number.MAX_SAFE_INTEGER), new Range(this.modified.startLineNumber - 1, Number.MAX_SAFE_INTEGER, this.modified.endLineNumberExclusive - 1, Number.MAX_SAFE_INTEGER));
  11021. }
  11022. }
  11023. /**
  11024. * This method assumes that the LineRangeMapping describes a valid diff!
  11025. * I.e. if one range is empty, the other range cannot be the entire document.
  11026. * It avoids various problems when the line range points to non-existing line-numbers.
  11027. */
  11028. toRangeMapping2(original, modified) {
  11029. if (isValidLineNumber(this.original.endLineNumberExclusive, original)
  11030. && isValidLineNumber(this.modified.endLineNumberExclusive, modified)) {
  11031. return new RangeMapping(new Range(this.original.startLineNumber, 1, this.original.endLineNumberExclusive, 1), new Range(this.modified.startLineNumber, 1, this.modified.endLineNumberExclusive, 1));
  11032. }
  11033. if (!this.original.isEmpty && !this.modified.isEmpty) {
  11034. return new RangeMapping(Range.fromPositions(new Position(this.original.startLineNumber, 1), normalizePosition(new Position(this.original.endLineNumberExclusive - 1, Number.MAX_SAFE_INTEGER), original)), Range.fromPositions(new Position(this.modified.startLineNumber, 1), normalizePosition(new Position(this.modified.endLineNumberExclusive - 1, Number.MAX_SAFE_INTEGER), modified)));
  11035. }
  11036. if (this.original.startLineNumber > 1 && this.modified.startLineNumber > 1) {
  11037. return new RangeMapping(Range.fromPositions(normalizePosition(new Position(this.original.startLineNumber - 1, Number.MAX_SAFE_INTEGER), original), normalizePosition(new Position(this.original.endLineNumberExclusive - 1, Number.MAX_SAFE_INTEGER), original)), Range.fromPositions(normalizePosition(new Position(this.modified.startLineNumber - 1, Number.MAX_SAFE_INTEGER), modified), normalizePosition(new Position(this.modified.endLineNumberExclusive - 1, Number.MAX_SAFE_INTEGER), modified)));
  11038. }
  11039. // Situation now: one range is empty and one range touches the last line and one range starts at line 1.
  11040. // I don't think this can happen.
  11041. throw new BugIndicatingError();
  11042. }
  11043. }
  11044. function normalizePosition(position, content) {
  11045. if (position.lineNumber < 1) {
  11046. return new Position(1, 1);
  11047. }
  11048. if (position.lineNumber > content.length) {
  11049. return new Position(content.length, content[content.length - 1].length + 1);
  11050. }
  11051. const line = content[position.lineNumber - 1];
  11052. if (position.column > line.length + 1) {
  11053. return new Position(position.lineNumber, line.length + 1);
  11054. }
  11055. return position;
  11056. }
  11057. function isValidLineNumber(lineNumber, lines) {
  11058. return lineNumber >= 1 && lineNumber <= lines.length;
  11059. }
  11060. /**
  11061. * Maps a line range in the original text model to a line range in the modified text model.
  11062. * Also contains inner range mappings.
  11063. */
  11064. class DetailedLineRangeMapping extends LineRangeMapping {
  11065. static fromRangeMappings(rangeMappings) {
  11066. const originalRange = LineRange.join(rangeMappings.map(r => LineRange.fromRangeInclusive(r.originalRange)));
  11067. const modifiedRange = LineRange.join(rangeMappings.map(r => LineRange.fromRangeInclusive(r.modifiedRange)));
  11068. return new DetailedLineRangeMapping(originalRange, modifiedRange, rangeMappings);
  11069. }
  11070. constructor(originalRange, modifiedRange, innerChanges) {
  11071. super(originalRange, modifiedRange);
  11072. this.innerChanges = innerChanges;
  11073. }
  11074. flip() {
  11075. return new DetailedLineRangeMapping(this.modified, this.original, this.innerChanges?.map(c => c.flip()));
  11076. }
  11077. withInnerChangesFromLineRanges() {
  11078. return new DetailedLineRangeMapping(this.original, this.modified, [this.toRangeMapping()]);
  11079. }
  11080. }
  11081. /**
  11082. * Maps a range in the original text model to a range in the modified text model.
  11083. */
  11084. class RangeMapping {
  11085. static assertSorted(rangeMappings) {
  11086. for (let i = 1; i < rangeMappings.length; i++) {
  11087. const previous = rangeMappings[i - 1];
  11088. const current = rangeMappings[i];
  11089. if (!(previous.originalRange.getEndPosition().isBeforeOrEqual(current.originalRange.getStartPosition())
  11090. && previous.modifiedRange.getEndPosition().isBeforeOrEqual(current.modifiedRange.getStartPosition()))) {
  11091. throw new BugIndicatingError('Range mappings must be sorted');
  11092. }
  11093. }
  11094. }
  11095. constructor(originalRange, modifiedRange) {
  11096. this.originalRange = originalRange;
  11097. this.modifiedRange = modifiedRange;
  11098. }
  11099. toString() {
  11100. return `{${this.originalRange.toString()}->${this.modifiedRange.toString()}}`;
  11101. }
  11102. flip() {
  11103. return new RangeMapping(this.modifiedRange, this.originalRange);
  11104. }
  11105. /**
  11106. * Creates a single text edit that describes the change from the original to the modified text.
  11107. */
  11108. toTextEdit(modified) {
  11109. const newText = modified.getValueOfRange(this.modifiedRange);
  11110. return new SingleTextEdit(this.originalRange, newText);
  11111. }
  11112. }
  11113. /*---------------------------------------------------------------------------------------------
  11114. * Copyright (c) Microsoft Corporation. All rights reserved.
  11115. * Licensed under the MIT License. See License.txt in the project root for license information.
  11116. *--------------------------------------------------------------------------------------------*/
  11117. const MINIMUM_MATCHING_CHARACTER_LENGTH = 3;
  11118. class LegacyLinesDiffComputer {
  11119. computeDiff(originalLines, modifiedLines, options) {
  11120. const diffComputer = new DiffComputer(originalLines, modifiedLines, {
  11121. maxComputationTime: options.maxComputationTimeMs,
  11122. shouldIgnoreTrimWhitespace: options.ignoreTrimWhitespace,
  11123. shouldComputeCharChanges: true,
  11124. shouldMakePrettyDiff: true,
  11125. shouldPostProcessCharChanges: true,
  11126. });
  11127. const result = diffComputer.computeDiff();
  11128. const changes = [];
  11129. let lastChange = null;
  11130. for (const c of result.changes) {
  11131. let originalRange;
  11132. if (c.originalEndLineNumber === 0) {
  11133. // Insertion
  11134. originalRange = new LineRange(c.originalStartLineNumber + 1, c.originalStartLineNumber + 1);
  11135. }
  11136. else {
  11137. originalRange = new LineRange(c.originalStartLineNumber, c.originalEndLineNumber + 1);
  11138. }
  11139. let modifiedRange;
  11140. if (c.modifiedEndLineNumber === 0) {
  11141. // Deletion
  11142. modifiedRange = new LineRange(c.modifiedStartLineNumber + 1, c.modifiedStartLineNumber + 1);
  11143. }
  11144. else {
  11145. modifiedRange = new LineRange(c.modifiedStartLineNumber, c.modifiedEndLineNumber + 1);
  11146. }
  11147. let change = new DetailedLineRangeMapping(originalRange, modifiedRange, c.charChanges?.map(c => new RangeMapping(new Range(c.originalStartLineNumber, c.originalStartColumn, c.originalEndLineNumber, c.originalEndColumn), new Range(c.modifiedStartLineNumber, c.modifiedStartColumn, c.modifiedEndLineNumber, c.modifiedEndColumn))));
  11148. if (lastChange) {
  11149. if (lastChange.modified.endLineNumberExclusive === change.modified.startLineNumber
  11150. || lastChange.original.endLineNumberExclusive === change.original.startLineNumber) {
  11151. // join touching diffs. Probably moving diffs up/down in the algorithm causes touching diffs.
  11152. change = new DetailedLineRangeMapping(lastChange.original.join(change.original), lastChange.modified.join(change.modified), lastChange.innerChanges && change.innerChanges ?
  11153. lastChange.innerChanges.concat(change.innerChanges) : undefined);
  11154. changes.pop();
  11155. }
  11156. }
  11157. changes.push(change);
  11158. lastChange = change;
  11159. }
  11160. assertFn(() => {
  11161. return checkAdjacentItems(changes, (m1, m2) => m2.original.startLineNumber - m1.original.endLineNumberExclusive === m2.modified.startLineNumber - m1.modified.endLineNumberExclusive &&
  11162. // There has to be an unchanged line in between (otherwise both diffs should have been joined)
  11163. m1.original.endLineNumberExclusive < m2.original.startLineNumber &&
  11164. m1.modified.endLineNumberExclusive < m2.modified.startLineNumber);
  11165. });
  11166. return new LinesDiff(changes, [], result.quitEarly);
  11167. }
  11168. }
  11169. function computeDiff(originalSequence, modifiedSequence, continueProcessingPredicate, pretty) {
  11170. const diffAlgo = new LcsDiff(originalSequence, modifiedSequence, continueProcessingPredicate);
  11171. return diffAlgo.ComputeDiff(pretty);
  11172. }
  11173. let LineSequence$1 = class LineSequence {
  11174. constructor(lines) {
  11175. const startColumns = [];
  11176. const endColumns = [];
  11177. for (let i = 0, length = lines.length; i < length; i++) {
  11178. startColumns[i] = getFirstNonBlankColumn(lines[i], 1);
  11179. endColumns[i] = getLastNonBlankColumn(lines[i], 1);
  11180. }
  11181. this.lines = lines;
  11182. this._startColumns = startColumns;
  11183. this._endColumns = endColumns;
  11184. }
  11185. getElements() {
  11186. const elements = [];
  11187. for (let i = 0, len = this.lines.length; i < len; i++) {
  11188. elements[i] = this.lines[i].substring(this._startColumns[i] - 1, this._endColumns[i] - 1);
  11189. }
  11190. return elements;
  11191. }
  11192. getStrictElement(index) {
  11193. return this.lines[index];
  11194. }
  11195. getStartLineNumber(i) {
  11196. return i + 1;
  11197. }
  11198. getEndLineNumber(i) {
  11199. return i + 1;
  11200. }
  11201. createCharSequence(shouldIgnoreTrimWhitespace, startIndex, endIndex) {
  11202. const charCodes = [];
  11203. const lineNumbers = [];
  11204. const columns = [];
  11205. let len = 0;
  11206. for (let index = startIndex; index <= endIndex; index++) {
  11207. const lineContent = this.lines[index];
  11208. const startColumn = (shouldIgnoreTrimWhitespace ? this._startColumns[index] : 1);
  11209. const endColumn = (shouldIgnoreTrimWhitespace ? this._endColumns[index] : lineContent.length + 1);
  11210. for (let col = startColumn; col < endColumn; col++) {
  11211. charCodes[len] = lineContent.charCodeAt(col - 1);
  11212. lineNumbers[len] = index + 1;
  11213. columns[len] = col;
  11214. len++;
  11215. }
  11216. if (!shouldIgnoreTrimWhitespace && index < endIndex) {
  11217. // Add \n if trim whitespace is not ignored
  11218. charCodes[len] = 10 /* CharCode.LineFeed */;
  11219. lineNumbers[len] = index + 1;
  11220. columns[len] = lineContent.length + 1;
  11221. len++;
  11222. }
  11223. }
  11224. return new CharSequence(charCodes, lineNumbers, columns);
  11225. }
  11226. };
  11227. class CharSequence {
  11228. constructor(charCodes, lineNumbers, columns) {
  11229. this._charCodes = charCodes;
  11230. this._lineNumbers = lineNumbers;
  11231. this._columns = columns;
  11232. }
  11233. toString() {
  11234. return ('[' + this._charCodes.map((s, idx) => (s === 10 /* CharCode.LineFeed */ ? '\\n' : String.fromCharCode(s)) + `-(${this._lineNumbers[idx]},${this._columns[idx]})`).join(', ') + ']');
  11235. }
  11236. _assertIndex(index, arr) {
  11237. if (index < 0 || index >= arr.length) {
  11238. throw new Error(`Illegal index`);
  11239. }
  11240. }
  11241. getElements() {
  11242. return this._charCodes;
  11243. }
  11244. getStartLineNumber(i) {
  11245. if (i > 0 && i === this._lineNumbers.length) {
  11246. // the start line number of the element after the last element
  11247. // is the end line number of the last element
  11248. return this.getEndLineNumber(i - 1);
  11249. }
  11250. this._assertIndex(i, this._lineNumbers);
  11251. return this._lineNumbers[i];
  11252. }
  11253. getEndLineNumber(i) {
  11254. if (i === -1) {
  11255. // the end line number of the element before the first element
  11256. // is the start line number of the first element
  11257. return this.getStartLineNumber(i + 1);
  11258. }
  11259. this._assertIndex(i, this._lineNumbers);
  11260. if (this._charCodes[i] === 10 /* CharCode.LineFeed */) {
  11261. return this._lineNumbers[i] + 1;
  11262. }
  11263. return this._lineNumbers[i];
  11264. }
  11265. getStartColumn(i) {
  11266. if (i > 0 && i === this._columns.length) {
  11267. // the start column of the element after the last element
  11268. // is the end column of the last element
  11269. return this.getEndColumn(i - 1);
  11270. }
  11271. this._assertIndex(i, this._columns);
  11272. return this._columns[i];
  11273. }
  11274. getEndColumn(i) {
  11275. if (i === -1) {
  11276. // the end column of the element before the first element
  11277. // is the start column of the first element
  11278. return this.getStartColumn(i + 1);
  11279. }
  11280. this._assertIndex(i, this._columns);
  11281. if (this._charCodes[i] === 10 /* CharCode.LineFeed */) {
  11282. return 1;
  11283. }
  11284. return this._columns[i] + 1;
  11285. }
  11286. }
  11287. class CharChange {
  11288. constructor(originalStartLineNumber, originalStartColumn, originalEndLineNumber, originalEndColumn, modifiedStartLineNumber, modifiedStartColumn, modifiedEndLineNumber, modifiedEndColumn) {
  11289. this.originalStartLineNumber = originalStartLineNumber;
  11290. this.originalStartColumn = originalStartColumn;
  11291. this.originalEndLineNumber = originalEndLineNumber;
  11292. this.originalEndColumn = originalEndColumn;
  11293. this.modifiedStartLineNumber = modifiedStartLineNumber;
  11294. this.modifiedStartColumn = modifiedStartColumn;
  11295. this.modifiedEndLineNumber = modifiedEndLineNumber;
  11296. this.modifiedEndColumn = modifiedEndColumn;
  11297. }
  11298. static createFromDiffChange(diffChange, originalCharSequence, modifiedCharSequence) {
  11299. const originalStartLineNumber = originalCharSequence.getStartLineNumber(diffChange.originalStart);
  11300. const originalStartColumn = originalCharSequence.getStartColumn(diffChange.originalStart);
  11301. const originalEndLineNumber = originalCharSequence.getEndLineNumber(diffChange.originalStart + diffChange.originalLength - 1);
  11302. const originalEndColumn = originalCharSequence.getEndColumn(diffChange.originalStart + diffChange.originalLength - 1);
  11303. const modifiedStartLineNumber = modifiedCharSequence.getStartLineNumber(diffChange.modifiedStart);
  11304. const modifiedStartColumn = modifiedCharSequence.getStartColumn(diffChange.modifiedStart);
  11305. const modifiedEndLineNumber = modifiedCharSequence.getEndLineNumber(diffChange.modifiedStart + diffChange.modifiedLength - 1);
  11306. const modifiedEndColumn = modifiedCharSequence.getEndColumn(diffChange.modifiedStart + diffChange.modifiedLength - 1);
  11307. return new CharChange(originalStartLineNumber, originalStartColumn, originalEndLineNumber, originalEndColumn, modifiedStartLineNumber, modifiedStartColumn, modifiedEndLineNumber, modifiedEndColumn);
  11308. }
  11309. }
  11310. function postProcessCharChanges(rawChanges) {
  11311. if (rawChanges.length <= 1) {
  11312. return rawChanges;
  11313. }
  11314. const result = [rawChanges[0]];
  11315. let prevChange = result[0];
  11316. for (let i = 1, len = rawChanges.length; i < len; i++) {
  11317. const currChange = rawChanges[i];
  11318. const originalMatchingLength = currChange.originalStart - (prevChange.originalStart + prevChange.originalLength);
  11319. const modifiedMatchingLength = currChange.modifiedStart - (prevChange.modifiedStart + prevChange.modifiedLength);
  11320. // Both of the above should be equal, but the continueProcessingPredicate may prevent this from being true
  11321. const matchingLength = Math.min(originalMatchingLength, modifiedMatchingLength);
  11322. if (matchingLength < MINIMUM_MATCHING_CHARACTER_LENGTH) {
  11323. // Merge the current change into the previous one
  11324. prevChange.originalLength = (currChange.originalStart + currChange.originalLength) - prevChange.originalStart;
  11325. prevChange.modifiedLength = (currChange.modifiedStart + currChange.modifiedLength) - prevChange.modifiedStart;
  11326. }
  11327. else {
  11328. // Add the current change
  11329. result.push(currChange);
  11330. prevChange = currChange;
  11331. }
  11332. }
  11333. return result;
  11334. }
  11335. class LineChange {
  11336. constructor(originalStartLineNumber, originalEndLineNumber, modifiedStartLineNumber, modifiedEndLineNumber, charChanges) {
  11337. this.originalStartLineNumber = originalStartLineNumber;
  11338. this.originalEndLineNumber = originalEndLineNumber;
  11339. this.modifiedStartLineNumber = modifiedStartLineNumber;
  11340. this.modifiedEndLineNumber = modifiedEndLineNumber;
  11341. this.charChanges = charChanges;
  11342. }
  11343. static createFromDiffResult(shouldIgnoreTrimWhitespace, diffChange, originalLineSequence, modifiedLineSequence, continueCharDiff, shouldComputeCharChanges, shouldPostProcessCharChanges) {
  11344. let originalStartLineNumber;
  11345. let originalEndLineNumber;
  11346. let modifiedStartLineNumber;
  11347. let modifiedEndLineNumber;
  11348. let charChanges = undefined;
  11349. if (diffChange.originalLength === 0) {
  11350. originalStartLineNumber = originalLineSequence.getStartLineNumber(diffChange.originalStart) - 1;
  11351. originalEndLineNumber = 0;
  11352. }
  11353. else {
  11354. originalStartLineNumber = originalLineSequence.getStartLineNumber(diffChange.originalStart);
  11355. originalEndLineNumber = originalLineSequence.getEndLineNumber(diffChange.originalStart + diffChange.originalLength - 1);
  11356. }
  11357. if (diffChange.modifiedLength === 0) {
  11358. modifiedStartLineNumber = modifiedLineSequence.getStartLineNumber(diffChange.modifiedStart) - 1;
  11359. modifiedEndLineNumber = 0;
  11360. }
  11361. else {
  11362. modifiedStartLineNumber = modifiedLineSequence.getStartLineNumber(diffChange.modifiedStart);
  11363. modifiedEndLineNumber = modifiedLineSequence.getEndLineNumber(diffChange.modifiedStart + diffChange.modifiedLength - 1);
  11364. }
  11365. if (shouldComputeCharChanges && diffChange.originalLength > 0 && diffChange.originalLength < 20 && diffChange.modifiedLength > 0 && diffChange.modifiedLength < 20 && continueCharDiff()) {
  11366. // Compute character changes for diff chunks of at most 20 lines...
  11367. const originalCharSequence = originalLineSequence.createCharSequence(shouldIgnoreTrimWhitespace, diffChange.originalStart, diffChange.originalStart + diffChange.originalLength - 1);
  11368. const modifiedCharSequence = modifiedLineSequence.createCharSequence(shouldIgnoreTrimWhitespace, diffChange.modifiedStart, diffChange.modifiedStart + diffChange.modifiedLength - 1);
  11369. if (originalCharSequence.getElements().length > 0 && modifiedCharSequence.getElements().length > 0) {
  11370. let rawChanges = computeDiff(originalCharSequence, modifiedCharSequence, continueCharDiff, true).changes;
  11371. if (shouldPostProcessCharChanges) {
  11372. rawChanges = postProcessCharChanges(rawChanges);
  11373. }
  11374. charChanges = [];
  11375. for (let i = 0, length = rawChanges.length; i < length; i++) {
  11376. charChanges.push(CharChange.createFromDiffChange(rawChanges[i], originalCharSequence, modifiedCharSequence));
  11377. }
  11378. }
  11379. }
  11380. return new LineChange(originalStartLineNumber, originalEndLineNumber, modifiedStartLineNumber, modifiedEndLineNumber, charChanges);
  11381. }
  11382. }
  11383. class DiffComputer {
  11384. constructor(originalLines, modifiedLines, opts) {
  11385. this.shouldComputeCharChanges = opts.shouldComputeCharChanges;
  11386. this.shouldPostProcessCharChanges = opts.shouldPostProcessCharChanges;
  11387. this.shouldIgnoreTrimWhitespace = opts.shouldIgnoreTrimWhitespace;
  11388. this.shouldMakePrettyDiff = opts.shouldMakePrettyDiff;
  11389. this.originalLines = originalLines;
  11390. this.modifiedLines = modifiedLines;
  11391. this.original = new LineSequence$1(originalLines);
  11392. this.modified = new LineSequence$1(modifiedLines);
  11393. this.continueLineDiff = createContinueProcessingPredicate(opts.maxComputationTime);
  11394. this.continueCharDiff = createContinueProcessingPredicate(opts.maxComputationTime === 0 ? 0 : Math.min(opts.maxComputationTime, 5000)); // never run after 5s for character changes...
  11395. }
  11396. computeDiff() {
  11397. if (this.original.lines.length === 1 && this.original.lines[0].length === 0) {
  11398. // empty original => fast path
  11399. if (this.modified.lines.length === 1 && this.modified.lines[0].length === 0) {
  11400. return {
  11401. quitEarly: false,
  11402. changes: []
  11403. };
  11404. }
  11405. return {
  11406. quitEarly: false,
  11407. changes: [{
  11408. originalStartLineNumber: 1,
  11409. originalEndLineNumber: 1,
  11410. modifiedStartLineNumber: 1,
  11411. modifiedEndLineNumber: this.modified.lines.length,
  11412. charChanges: undefined
  11413. }]
  11414. };
  11415. }
  11416. if (this.modified.lines.length === 1 && this.modified.lines[0].length === 0) {
  11417. // empty modified => fast path
  11418. return {
  11419. quitEarly: false,
  11420. changes: [{
  11421. originalStartLineNumber: 1,
  11422. originalEndLineNumber: this.original.lines.length,
  11423. modifiedStartLineNumber: 1,
  11424. modifiedEndLineNumber: 1,
  11425. charChanges: undefined
  11426. }]
  11427. };
  11428. }
  11429. const diffResult = computeDiff(this.original, this.modified, this.continueLineDiff, this.shouldMakePrettyDiff);
  11430. const rawChanges = diffResult.changes;
  11431. const quitEarly = diffResult.quitEarly;
  11432. // The diff is always computed with ignoring trim whitespace
  11433. // This ensures we get the prettiest diff
  11434. if (this.shouldIgnoreTrimWhitespace) {
  11435. const lineChanges = [];
  11436. for (let i = 0, length = rawChanges.length; i < length; i++) {
  11437. lineChanges.push(LineChange.createFromDiffResult(this.shouldIgnoreTrimWhitespace, rawChanges[i], this.original, this.modified, this.continueCharDiff, this.shouldComputeCharChanges, this.shouldPostProcessCharChanges));
  11438. }
  11439. return {
  11440. quitEarly: quitEarly,
  11441. changes: lineChanges
  11442. };
  11443. }
  11444. // Need to post-process and introduce changes where the trim whitespace is different
  11445. // Note that we are looping starting at -1 to also cover the lines before the first change
  11446. const result = [];
  11447. let originalLineIndex = 0;
  11448. let modifiedLineIndex = 0;
  11449. for (let i = -1 /* !!!! */, len = rawChanges.length; i < len; i++) {
  11450. const nextChange = (i + 1 < len ? rawChanges[i + 1] : null);
  11451. const originalStop = (nextChange ? nextChange.originalStart : this.originalLines.length);
  11452. const modifiedStop = (nextChange ? nextChange.modifiedStart : this.modifiedLines.length);
  11453. while (originalLineIndex < originalStop && modifiedLineIndex < modifiedStop) {
  11454. const originalLine = this.originalLines[originalLineIndex];
  11455. const modifiedLine = this.modifiedLines[modifiedLineIndex];
  11456. if (originalLine !== modifiedLine) {
  11457. // These lines differ only in trim whitespace
  11458. // Check the leading whitespace
  11459. {
  11460. let originalStartColumn = getFirstNonBlankColumn(originalLine, 1);
  11461. let modifiedStartColumn = getFirstNonBlankColumn(modifiedLine, 1);
  11462. while (originalStartColumn > 1 && modifiedStartColumn > 1) {
  11463. const originalChar = originalLine.charCodeAt(originalStartColumn - 2);
  11464. const modifiedChar = modifiedLine.charCodeAt(modifiedStartColumn - 2);
  11465. if (originalChar !== modifiedChar) {
  11466. break;
  11467. }
  11468. originalStartColumn--;
  11469. modifiedStartColumn--;
  11470. }
  11471. if (originalStartColumn > 1 || modifiedStartColumn > 1) {
  11472. this._pushTrimWhitespaceCharChange(result, originalLineIndex + 1, 1, originalStartColumn, modifiedLineIndex + 1, 1, modifiedStartColumn);
  11473. }
  11474. }
  11475. // Check the trailing whitespace
  11476. {
  11477. let originalEndColumn = getLastNonBlankColumn(originalLine, 1);
  11478. let modifiedEndColumn = getLastNonBlankColumn(modifiedLine, 1);
  11479. const originalMaxColumn = originalLine.length + 1;
  11480. const modifiedMaxColumn = modifiedLine.length + 1;
  11481. while (originalEndColumn < originalMaxColumn && modifiedEndColumn < modifiedMaxColumn) {
  11482. const originalChar = originalLine.charCodeAt(originalEndColumn - 1);
  11483. const modifiedChar = originalLine.charCodeAt(modifiedEndColumn - 1);
  11484. if (originalChar !== modifiedChar) {
  11485. break;
  11486. }
  11487. originalEndColumn++;
  11488. modifiedEndColumn++;
  11489. }
  11490. if (originalEndColumn < originalMaxColumn || modifiedEndColumn < modifiedMaxColumn) {
  11491. this._pushTrimWhitespaceCharChange(result, originalLineIndex + 1, originalEndColumn, originalMaxColumn, modifiedLineIndex + 1, modifiedEndColumn, modifiedMaxColumn);
  11492. }
  11493. }
  11494. }
  11495. originalLineIndex++;
  11496. modifiedLineIndex++;
  11497. }
  11498. if (nextChange) {
  11499. // Emit the actual change
  11500. result.push(LineChange.createFromDiffResult(this.shouldIgnoreTrimWhitespace, nextChange, this.original, this.modified, this.continueCharDiff, this.shouldComputeCharChanges, this.shouldPostProcessCharChanges));
  11501. originalLineIndex += nextChange.originalLength;
  11502. modifiedLineIndex += nextChange.modifiedLength;
  11503. }
  11504. }
  11505. return {
  11506. quitEarly: quitEarly,
  11507. changes: result
  11508. };
  11509. }
  11510. _pushTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn) {
  11511. if (this._mergeTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn)) {
  11512. // Merged into previous
  11513. return;
  11514. }
  11515. let charChanges = undefined;
  11516. if (this.shouldComputeCharChanges) {
  11517. charChanges = [new CharChange(originalLineNumber, originalStartColumn, originalLineNumber, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedLineNumber, modifiedEndColumn)];
  11518. }
  11519. result.push(new LineChange(originalLineNumber, originalLineNumber, modifiedLineNumber, modifiedLineNumber, charChanges));
  11520. }
  11521. _mergeTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn) {
  11522. const len = result.length;
  11523. if (len === 0) {
  11524. return false;
  11525. }
  11526. const prevChange = result[len - 1];
  11527. if (prevChange.originalEndLineNumber === 0 || prevChange.modifiedEndLineNumber === 0) {
  11528. // Don't merge with inserts/deletes
  11529. return false;
  11530. }
  11531. if (prevChange.originalEndLineNumber === originalLineNumber && prevChange.modifiedEndLineNumber === modifiedLineNumber) {
  11532. if (this.shouldComputeCharChanges && prevChange.charChanges) {
  11533. prevChange.charChanges.push(new CharChange(originalLineNumber, originalStartColumn, originalLineNumber, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedLineNumber, modifiedEndColumn));
  11534. }
  11535. return true;
  11536. }
  11537. if (prevChange.originalEndLineNumber + 1 === originalLineNumber && prevChange.modifiedEndLineNumber + 1 === modifiedLineNumber) {
  11538. prevChange.originalEndLineNumber = originalLineNumber;
  11539. prevChange.modifiedEndLineNumber = modifiedLineNumber;
  11540. if (this.shouldComputeCharChanges && prevChange.charChanges) {
  11541. prevChange.charChanges.push(new CharChange(originalLineNumber, originalStartColumn, originalLineNumber, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedLineNumber, modifiedEndColumn));
  11542. }
  11543. return true;
  11544. }
  11545. return false;
  11546. }
  11547. }
  11548. function getFirstNonBlankColumn(txt, defaultValue) {
  11549. const r = firstNonWhitespaceIndex(txt);
  11550. if (r === -1) {
  11551. return defaultValue;
  11552. }
  11553. return r + 1;
  11554. }
  11555. function getLastNonBlankColumn(txt, defaultValue) {
  11556. const r = lastNonWhitespaceIndex(txt);
  11557. if (r === -1) {
  11558. return defaultValue;
  11559. }
  11560. return r + 2;
  11561. }
  11562. function createContinueProcessingPredicate(maximumRuntime) {
  11563. if (maximumRuntime === 0) {
  11564. return () => true;
  11565. }
  11566. const startTime = Date.now();
  11567. return () => {
  11568. return Date.now() - startTime < maximumRuntime;
  11569. };
  11570. }
  11571. /**
  11572. * Returns the last element of an array.
  11573. * @param array The array.
  11574. * @param n Which element from the end (default is zero).
  11575. */
  11576. function equals(one, other, itemEquals = (a, b) => a === b) {
  11577. if (one === other) {
  11578. return true;
  11579. }
  11580. if (!one || !other) {
  11581. return false;
  11582. }
  11583. if (one.length !== other.length) {
  11584. return false;
  11585. }
  11586. for (let i = 0, len = one.length; i < len; i++) {
  11587. if (!itemEquals(one[i], other[i])) {
  11588. return false;
  11589. }
  11590. }
  11591. return true;
  11592. }
  11593. /**
  11594. * Splits the given items into a list of (non-empty) groups.
  11595. * `shouldBeGrouped` is used to decide if two consecutive items should be in the same group.
  11596. * The order of the items is preserved.
  11597. */
  11598. function* groupAdjacentBy(items, shouldBeGrouped) {
  11599. let currentGroup;
  11600. let last;
  11601. for (const item of items) {
  11602. if (last !== undefined && shouldBeGrouped(last, item)) {
  11603. currentGroup.push(item);
  11604. }
  11605. else {
  11606. if (currentGroup) {
  11607. yield currentGroup;
  11608. }
  11609. currentGroup = [item];
  11610. }
  11611. last = item;
  11612. }
  11613. if (currentGroup) {
  11614. yield currentGroup;
  11615. }
  11616. }
  11617. function forEachAdjacent(arr, f) {
  11618. for (let i = 0; i <= arr.length; i++) {
  11619. f(i === 0 ? undefined : arr[i - 1], i === arr.length ? undefined : arr[i]);
  11620. }
  11621. }
  11622. function forEachWithNeighbors(arr, f) {
  11623. for (let i = 0; i < arr.length; i++) {
  11624. f(i === 0 ? undefined : arr[i - 1], arr[i], i + 1 === arr.length ? undefined : arr[i + 1]);
  11625. }
  11626. }
  11627. function pushMany(arr, items) {
  11628. for (const item of items) {
  11629. arr.push(item);
  11630. }
  11631. }
  11632. var CompareResult;
  11633. (function (CompareResult) {
  11634. function isLessThan(result) {
  11635. return result < 0;
  11636. }
  11637. CompareResult.isLessThan = isLessThan;
  11638. function isLessThanOrEqual(result) {
  11639. return result <= 0;
  11640. }
  11641. CompareResult.isLessThanOrEqual = isLessThanOrEqual;
  11642. function isGreaterThan(result) {
  11643. return result > 0;
  11644. }
  11645. CompareResult.isGreaterThan = isGreaterThan;
  11646. function isNeitherLessOrGreaterThan(result) {
  11647. return result === 0;
  11648. }
  11649. CompareResult.isNeitherLessOrGreaterThan = isNeitherLessOrGreaterThan;
  11650. CompareResult.greaterThan = 1;
  11651. CompareResult.lessThan = -1;
  11652. CompareResult.neitherLessOrGreaterThan = 0;
  11653. })(CompareResult || (CompareResult = {}));
  11654. function compareBy(selector, comparator) {
  11655. return (a, b) => comparator(selector(a), selector(b));
  11656. }
  11657. /**
  11658. * The natural order on numbers.
  11659. */
  11660. const numberComparator = (a, b) => a - b;
  11661. function reverseOrder(comparator) {
  11662. return (a, b) => -comparator(a, b);
  11663. }
  11664. /**
  11665. * This class is faster than an iterator and array for lazy computed data.
  11666. */
  11667. class CallbackIterable {
  11668. static { this.empty = new CallbackIterable(_callback => { }); }
  11669. constructor(
  11670. /**
  11671. * Calls the callback for every item.
  11672. * Stops when the callback returns false.
  11673. */
  11674. iterate) {
  11675. this.iterate = iterate;
  11676. }
  11677. toArray() {
  11678. const result = [];
  11679. this.iterate(item => { result.push(item); return true; });
  11680. return result;
  11681. }
  11682. filter(predicate) {
  11683. return new CallbackIterable(cb => this.iterate(item => predicate(item) ? cb(item) : true));
  11684. }
  11685. map(mapFn) {
  11686. return new CallbackIterable(cb => this.iterate(item => cb(mapFn(item))));
  11687. }
  11688. findLast(predicate) {
  11689. let result;
  11690. this.iterate(item => {
  11691. if (predicate(item)) {
  11692. result = item;
  11693. }
  11694. return true;
  11695. });
  11696. return result;
  11697. }
  11698. findLastMaxBy(comparator) {
  11699. let result;
  11700. let first = true;
  11701. this.iterate(item => {
  11702. if (first || CompareResult.isGreaterThan(comparator(item, result))) {
  11703. first = false;
  11704. result = item;
  11705. }
  11706. return true;
  11707. });
  11708. return result;
  11709. }
  11710. }
  11711. /*---------------------------------------------------------------------------------------------
  11712. * Copyright (c) Microsoft Corporation. All rights reserved.
  11713. * Licensed under the MIT License. See License.txt in the project root for license information.
  11714. *--------------------------------------------------------------------------------------------*/
  11715. class DiffAlgorithmResult {
  11716. static trivial(seq1, seq2) {
  11717. return new DiffAlgorithmResult([new SequenceDiff(OffsetRange.ofLength(seq1.length), OffsetRange.ofLength(seq2.length))], false);
  11718. }
  11719. static trivialTimedOut(seq1, seq2) {
  11720. return new DiffAlgorithmResult([new SequenceDiff(OffsetRange.ofLength(seq1.length), OffsetRange.ofLength(seq2.length))], true);
  11721. }
  11722. constructor(diffs,
  11723. /**
  11724. * Indicates if the time out was reached.
  11725. * In that case, the diffs might be an approximation and the user should be asked to rerun the diff with more time.
  11726. */
  11727. hitTimeout) {
  11728. this.diffs = diffs;
  11729. this.hitTimeout = hitTimeout;
  11730. }
  11731. }
  11732. class SequenceDiff {
  11733. static invert(sequenceDiffs, doc1Length) {
  11734. const result = [];
  11735. forEachAdjacent(sequenceDiffs, (a, b) => {
  11736. result.push(SequenceDiff.fromOffsetPairs(a ? a.getEndExclusives() : OffsetPair.zero, b ? b.getStarts() : new OffsetPair(doc1Length, (a ? a.seq2Range.endExclusive - a.seq1Range.endExclusive : 0) + doc1Length)));
  11737. });
  11738. return result;
  11739. }
  11740. static fromOffsetPairs(start, endExclusive) {
  11741. return new SequenceDiff(new OffsetRange(start.offset1, endExclusive.offset1), new OffsetRange(start.offset2, endExclusive.offset2));
  11742. }
  11743. static assertSorted(sequenceDiffs) {
  11744. let last = undefined;
  11745. for (const cur of sequenceDiffs) {
  11746. if (last) {
  11747. if (!(last.seq1Range.endExclusive <= cur.seq1Range.start && last.seq2Range.endExclusive <= cur.seq2Range.start)) {
  11748. throw new BugIndicatingError('Sequence diffs must be sorted');
  11749. }
  11750. }
  11751. last = cur;
  11752. }
  11753. }
  11754. constructor(seq1Range, seq2Range) {
  11755. this.seq1Range = seq1Range;
  11756. this.seq2Range = seq2Range;
  11757. }
  11758. swap() {
  11759. return new SequenceDiff(this.seq2Range, this.seq1Range);
  11760. }
  11761. toString() {
  11762. return `${this.seq1Range} <-> ${this.seq2Range}`;
  11763. }
  11764. join(other) {
  11765. return new SequenceDiff(this.seq1Range.join(other.seq1Range), this.seq2Range.join(other.seq2Range));
  11766. }
  11767. delta(offset) {
  11768. if (offset === 0) {
  11769. return this;
  11770. }
  11771. return new SequenceDiff(this.seq1Range.delta(offset), this.seq2Range.delta(offset));
  11772. }
  11773. deltaStart(offset) {
  11774. if (offset === 0) {
  11775. return this;
  11776. }
  11777. return new SequenceDiff(this.seq1Range.deltaStart(offset), this.seq2Range.deltaStart(offset));
  11778. }
  11779. deltaEnd(offset) {
  11780. if (offset === 0) {
  11781. return this;
  11782. }
  11783. return new SequenceDiff(this.seq1Range.deltaEnd(offset), this.seq2Range.deltaEnd(offset));
  11784. }
  11785. intersect(other) {
  11786. const i1 = this.seq1Range.intersect(other.seq1Range);
  11787. const i2 = this.seq2Range.intersect(other.seq2Range);
  11788. if (!i1 || !i2) {
  11789. return undefined;
  11790. }
  11791. return new SequenceDiff(i1, i2);
  11792. }
  11793. getStarts() {
  11794. return new OffsetPair(this.seq1Range.start, this.seq2Range.start);
  11795. }
  11796. getEndExclusives() {
  11797. return new OffsetPair(this.seq1Range.endExclusive, this.seq2Range.endExclusive);
  11798. }
  11799. }
  11800. class OffsetPair {
  11801. static { this.zero = new OffsetPair(0, 0); }
  11802. static { this.max = new OffsetPair(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER); }
  11803. constructor(offset1, offset2) {
  11804. this.offset1 = offset1;
  11805. this.offset2 = offset2;
  11806. }
  11807. toString() {
  11808. return `${this.offset1} <-> ${this.offset2}`;
  11809. }
  11810. delta(offset) {
  11811. if (offset === 0) {
  11812. return this;
  11813. }
  11814. return new OffsetPair(this.offset1 + offset, this.offset2 + offset);
  11815. }
  11816. equals(other) {
  11817. return this.offset1 === other.offset1 && this.offset2 === other.offset2;
  11818. }
  11819. }
  11820. class InfiniteTimeout {
  11821. static { this.instance = new InfiniteTimeout(); }
  11822. isValid() {
  11823. return true;
  11824. }
  11825. }
  11826. class DateTimeout {
  11827. constructor(timeout) {
  11828. this.timeout = timeout;
  11829. this.startTime = Date.now();
  11830. this.valid = true;
  11831. if (timeout <= 0) {
  11832. throw new BugIndicatingError('timeout must be positive');
  11833. }
  11834. }
  11835. // Recommendation: Set a log-point `{this.disable()}` in the body
  11836. isValid() {
  11837. const valid = Date.now() - this.startTime < this.timeout;
  11838. if (!valid && this.valid) {
  11839. this.valid = false; // timeout reached
  11840. // eslint-disable-next-line no-debugger
  11841. debugger; // WARNING: Most likely debugging caused the timeout. Call `this.disable()` to continue without timing out.
  11842. }
  11843. return this.valid;
  11844. }
  11845. }
  11846. /*---------------------------------------------------------------------------------------------
  11847. * Copyright (c) Microsoft Corporation. All rights reserved.
  11848. * Licensed under the MIT License. See License.txt in the project root for license information.
  11849. *--------------------------------------------------------------------------------------------*/
  11850. class Array2D {
  11851. constructor(width, height) {
  11852. this.width = width;
  11853. this.height = height;
  11854. this.array = [];
  11855. this.array = new Array(width * height);
  11856. }
  11857. get(x, y) {
  11858. return this.array[x + y * this.width];
  11859. }
  11860. set(x, y, value) {
  11861. this.array[x + y * this.width] = value;
  11862. }
  11863. }
  11864. function isSpace(charCode) {
  11865. return charCode === 32 /* CharCode.Space */ || charCode === 9 /* CharCode.Tab */;
  11866. }
  11867. class LineRangeFragment {
  11868. static { this.chrKeys = new Map(); }
  11869. static getKey(chr) {
  11870. let key = this.chrKeys.get(chr);
  11871. if (key === undefined) {
  11872. key = this.chrKeys.size;
  11873. this.chrKeys.set(chr, key);
  11874. }
  11875. return key;
  11876. }
  11877. constructor(range, lines, source) {
  11878. this.range = range;
  11879. this.lines = lines;
  11880. this.source = source;
  11881. this.histogram = [];
  11882. let counter = 0;
  11883. for (let i = range.startLineNumber - 1; i < range.endLineNumberExclusive - 1; i++) {
  11884. const line = lines[i];
  11885. for (let j = 0; j < line.length; j++) {
  11886. counter++;
  11887. const chr = line[j];
  11888. const key = LineRangeFragment.getKey(chr);
  11889. this.histogram[key] = (this.histogram[key] || 0) + 1;
  11890. }
  11891. counter++;
  11892. const key = LineRangeFragment.getKey('\n');
  11893. this.histogram[key] = (this.histogram[key] || 0) + 1;
  11894. }
  11895. this.totalCount = counter;
  11896. }
  11897. computeSimilarity(other) {
  11898. let sumDifferences = 0;
  11899. const maxLength = Math.max(this.histogram.length, other.histogram.length);
  11900. for (let i = 0; i < maxLength; i++) {
  11901. sumDifferences += Math.abs((this.histogram[i] ?? 0) - (other.histogram[i] ?? 0));
  11902. }
  11903. return 1 - (sumDifferences / (this.totalCount + other.totalCount));
  11904. }
  11905. }
  11906. /*---------------------------------------------------------------------------------------------
  11907. * Copyright (c) Microsoft Corporation. All rights reserved.
  11908. * Licensed under the MIT License. See License.txt in the project root for license information.
  11909. *--------------------------------------------------------------------------------------------*/
  11910. /**
  11911. * A O(MN) diffing algorithm that supports a score function.
  11912. * The algorithm can be improved by processing the 2d array diagonally.
  11913. */
  11914. class DynamicProgrammingDiffing {
  11915. compute(sequence1, sequence2, timeout = InfiniteTimeout.instance, equalityScore) {
  11916. if (sequence1.length === 0 || sequence2.length === 0) {
  11917. return DiffAlgorithmResult.trivial(sequence1, sequence2);
  11918. }
  11919. /**
  11920. * lcsLengths.get(i, j): Length of the longest common subsequence of sequence1.substring(0, i + 1) and sequence2.substring(0, j + 1).
  11921. */
  11922. const lcsLengths = new Array2D(sequence1.length, sequence2.length);
  11923. const directions = new Array2D(sequence1.length, sequence2.length);
  11924. const lengths = new Array2D(sequence1.length, sequence2.length);
  11925. // ==== Initializing lcsLengths ====
  11926. for (let s1 = 0; s1 < sequence1.length; s1++) {
  11927. for (let s2 = 0; s2 < sequence2.length; s2++) {
  11928. if (!timeout.isValid()) {
  11929. return DiffAlgorithmResult.trivialTimedOut(sequence1, sequence2);
  11930. }
  11931. const horizontalLen = s1 === 0 ? 0 : lcsLengths.get(s1 - 1, s2);
  11932. const verticalLen = s2 === 0 ? 0 : lcsLengths.get(s1, s2 - 1);
  11933. let extendedSeqScore;
  11934. if (sequence1.getElement(s1) === sequence2.getElement(s2)) {
  11935. if (s1 === 0 || s2 === 0) {
  11936. extendedSeqScore = 0;
  11937. }
  11938. else {
  11939. extendedSeqScore = lcsLengths.get(s1 - 1, s2 - 1);
  11940. }
  11941. if (s1 > 0 && s2 > 0 && directions.get(s1 - 1, s2 - 1) === 3) {
  11942. // Prefer consecutive diagonals
  11943. extendedSeqScore += lengths.get(s1 - 1, s2 - 1);
  11944. }
  11945. extendedSeqScore += (equalityScore ? equalityScore(s1, s2) : 1);
  11946. }
  11947. else {
  11948. extendedSeqScore = -1;
  11949. }
  11950. const newValue = Math.max(horizontalLen, verticalLen, extendedSeqScore);
  11951. if (newValue === extendedSeqScore) {
  11952. // Prefer diagonals
  11953. const prevLen = s1 > 0 && s2 > 0 ? lengths.get(s1 - 1, s2 - 1) : 0;
  11954. lengths.set(s1, s2, prevLen + 1);
  11955. directions.set(s1, s2, 3);
  11956. }
  11957. else if (newValue === horizontalLen) {
  11958. lengths.set(s1, s2, 0);
  11959. directions.set(s1, s2, 1);
  11960. }
  11961. else if (newValue === verticalLen) {
  11962. lengths.set(s1, s2, 0);
  11963. directions.set(s1, s2, 2);
  11964. }
  11965. lcsLengths.set(s1, s2, newValue);
  11966. }
  11967. }
  11968. // ==== Backtracking ====
  11969. const result = [];
  11970. let lastAligningPosS1 = sequence1.length;
  11971. let lastAligningPosS2 = sequence2.length;
  11972. function reportDecreasingAligningPositions(s1, s2) {
  11973. if (s1 + 1 !== lastAligningPosS1 || s2 + 1 !== lastAligningPosS2) {
  11974. result.push(new SequenceDiff(new OffsetRange(s1 + 1, lastAligningPosS1), new OffsetRange(s2 + 1, lastAligningPosS2)));
  11975. }
  11976. lastAligningPosS1 = s1;
  11977. lastAligningPosS2 = s2;
  11978. }
  11979. let s1 = sequence1.length - 1;
  11980. let s2 = sequence2.length - 1;
  11981. while (s1 >= 0 && s2 >= 0) {
  11982. if (directions.get(s1, s2) === 3) {
  11983. reportDecreasingAligningPositions(s1, s2);
  11984. s1--;
  11985. s2--;
  11986. }
  11987. else {
  11988. if (directions.get(s1, s2) === 1) {
  11989. s1--;
  11990. }
  11991. else {
  11992. s2--;
  11993. }
  11994. }
  11995. }
  11996. reportDecreasingAligningPositions(-1, -1);
  11997. result.reverse();
  11998. return new DiffAlgorithmResult(result, false);
  11999. }
  12000. }
  12001. /*---------------------------------------------------------------------------------------------
  12002. * Copyright (c) Microsoft Corporation. All rights reserved.
  12003. * Licensed under the MIT License. See License.txt in the project root for license information.
  12004. *--------------------------------------------------------------------------------------------*/
  12005. /**
  12006. * An O(ND) diff algorithm that has a quadratic space worst-case complexity.
  12007. */
  12008. class MyersDiffAlgorithm {
  12009. compute(seq1, seq2, timeout = InfiniteTimeout.instance) {
  12010. // These are common special cases.
  12011. // The early return improves performance dramatically.
  12012. if (seq1.length === 0 || seq2.length === 0) {
  12013. return DiffAlgorithmResult.trivial(seq1, seq2);
  12014. }
  12015. const seqX = seq1; // Text on the x axis
  12016. const seqY = seq2; // Text on the y axis
  12017. function getXAfterSnake(x, y) {
  12018. while (x < seqX.length && y < seqY.length && seqX.getElement(x) === seqY.getElement(y)) {
  12019. x++;
  12020. y++;
  12021. }
  12022. return x;
  12023. }
  12024. let d = 0;
  12025. // V[k]: X value of longest d-line that ends in diagonal k.
  12026. // d-line: path from (0,0) to (x,y) that uses exactly d non-diagonals.
  12027. // diagonal k: Set of points (x,y) with x-y = k.
  12028. // k=1 -> (1,0),(2,1)
  12029. const V = new FastInt32Array();
  12030. V.set(0, getXAfterSnake(0, 0));
  12031. const paths = new FastArrayNegativeIndices();
  12032. paths.set(0, V.get(0) === 0 ? null : new SnakePath(null, 0, 0, V.get(0)));
  12033. let k = 0;
  12034. loop: while (true) {
  12035. d++;
  12036. if (!timeout.isValid()) {
  12037. return DiffAlgorithmResult.trivialTimedOut(seqX, seqY);
  12038. }
  12039. // The paper has `for (k = -d; k <= d; k += 2)`, but we can ignore diagonals that cannot influence the result.
  12040. const lowerBound = -Math.min(d, seqY.length + (d % 2));
  12041. const upperBound = Math.min(d, seqX.length + (d % 2));
  12042. for (k = lowerBound; k <= upperBound; k += 2) {
  12043. // We can use the X values of (d-1)-lines to compute X value of the longest d-lines.
  12044. const maxXofDLineTop = k === upperBound ? -1 : V.get(k + 1); // We take a vertical non-diagonal (add a symbol in seqX)
  12045. const maxXofDLineLeft = k === lowerBound ? -1 : V.get(k - 1) + 1; // We take a horizontal non-diagonal (+1 x) (delete a symbol in seqX)
  12046. const x = Math.min(Math.max(maxXofDLineTop, maxXofDLineLeft), seqX.length);
  12047. const y = x - k;
  12048. if (x > seqX.length || y > seqY.length) {
  12049. // This diagonal is irrelevant for the result.
  12050. // TODO: Don't pay the cost for this in the next iteration.
  12051. continue;
  12052. }
  12053. const newMaxX = getXAfterSnake(x, y);
  12054. V.set(k, newMaxX);
  12055. const lastPath = x === maxXofDLineTop ? paths.get(k + 1) : paths.get(k - 1);
  12056. paths.set(k, newMaxX !== x ? new SnakePath(lastPath, x, y, newMaxX - x) : lastPath);
  12057. if (V.get(k) === seqX.length && V.get(k) - k === seqY.length) {
  12058. break loop;
  12059. }
  12060. }
  12061. }
  12062. let path = paths.get(k);
  12063. const result = [];
  12064. let lastAligningPosS1 = seqX.length;
  12065. let lastAligningPosS2 = seqY.length;
  12066. while (true) {
  12067. const endX = path ? path.x + path.length : 0;
  12068. const endY = path ? path.y + path.length : 0;
  12069. if (endX !== lastAligningPosS1 || endY !== lastAligningPosS2) {
  12070. result.push(new SequenceDiff(new OffsetRange(endX, lastAligningPosS1), new OffsetRange(endY, lastAligningPosS2)));
  12071. }
  12072. if (!path) {
  12073. break;
  12074. }
  12075. lastAligningPosS1 = path.x;
  12076. lastAligningPosS2 = path.y;
  12077. path = path.prev;
  12078. }
  12079. result.reverse();
  12080. return new DiffAlgorithmResult(result, false);
  12081. }
  12082. }
  12083. class SnakePath {
  12084. constructor(prev, x, y, length) {
  12085. this.prev = prev;
  12086. this.x = x;
  12087. this.y = y;
  12088. this.length = length;
  12089. }
  12090. }
  12091. /**
  12092. * An array that supports fast negative indices.
  12093. */
  12094. class FastInt32Array {
  12095. constructor() {
  12096. this.positiveArr = new Int32Array(10);
  12097. this.negativeArr = new Int32Array(10);
  12098. }
  12099. get(idx) {
  12100. if (idx < 0) {
  12101. idx = -idx - 1;
  12102. return this.negativeArr[idx];
  12103. }
  12104. else {
  12105. return this.positiveArr[idx];
  12106. }
  12107. }
  12108. set(idx, value) {
  12109. if (idx < 0) {
  12110. idx = -idx - 1;
  12111. if (idx >= this.negativeArr.length) {
  12112. const arr = this.negativeArr;
  12113. this.negativeArr = new Int32Array(arr.length * 2);
  12114. this.negativeArr.set(arr);
  12115. }
  12116. this.negativeArr[idx] = value;
  12117. }
  12118. else {
  12119. if (idx >= this.positiveArr.length) {
  12120. const arr = this.positiveArr;
  12121. this.positiveArr = new Int32Array(arr.length * 2);
  12122. this.positiveArr.set(arr);
  12123. }
  12124. this.positiveArr[idx] = value;
  12125. }
  12126. }
  12127. }
  12128. /**
  12129. * An array that supports fast negative indices.
  12130. */
  12131. class FastArrayNegativeIndices {
  12132. constructor() {
  12133. this.positiveArr = [];
  12134. this.negativeArr = [];
  12135. }
  12136. get(idx) {
  12137. if (idx < 0) {
  12138. idx = -idx - 1;
  12139. return this.negativeArr[idx];
  12140. }
  12141. else {
  12142. return this.positiveArr[idx];
  12143. }
  12144. }
  12145. set(idx, value) {
  12146. if (idx < 0) {
  12147. idx = -idx - 1;
  12148. this.negativeArr[idx] = value;
  12149. }
  12150. else {
  12151. this.positiveArr[idx] = value;
  12152. }
  12153. }
  12154. }
  12155. /*---------------------------------------------------------------------------------------------
  12156. * Copyright (c) Microsoft Corporation. All rights reserved.
  12157. * Licensed under the MIT License. See License.txt in the project root for license information.
  12158. *--------------------------------------------------------------------------------------------*/
  12159. class LinesSliceCharSequence {
  12160. constructor(lines, range, considerWhitespaceChanges) {
  12161. this.lines = lines;
  12162. this.range = range;
  12163. this.considerWhitespaceChanges = considerWhitespaceChanges;
  12164. this.elements = [];
  12165. this.firstElementOffsetByLineIdx = [];
  12166. this.lineStartOffsets = [];
  12167. this.trimmedWsLengthsByLineIdx = [];
  12168. this.firstElementOffsetByLineIdx.push(0);
  12169. for (let lineNumber = this.range.startLineNumber; lineNumber <= this.range.endLineNumber; lineNumber++) {
  12170. let line = lines[lineNumber - 1];
  12171. let lineStartOffset = 0;
  12172. if (lineNumber === this.range.startLineNumber && this.range.startColumn > 1) {
  12173. lineStartOffset = this.range.startColumn - 1;
  12174. line = line.substring(lineStartOffset);
  12175. }
  12176. this.lineStartOffsets.push(lineStartOffset);
  12177. let trimmedWsLength = 0;
  12178. if (!considerWhitespaceChanges) {
  12179. const trimmedStartLine = line.trimStart();
  12180. trimmedWsLength = line.length - trimmedStartLine.length;
  12181. line = trimmedStartLine.trimEnd();
  12182. }
  12183. this.trimmedWsLengthsByLineIdx.push(trimmedWsLength);
  12184. const lineLength = lineNumber === this.range.endLineNumber ? Math.min(this.range.endColumn - 1 - lineStartOffset - trimmedWsLength, line.length) : line.length;
  12185. for (let i = 0; i < lineLength; i++) {
  12186. this.elements.push(line.charCodeAt(i));
  12187. }
  12188. if (lineNumber < this.range.endLineNumber) {
  12189. this.elements.push('\n'.charCodeAt(0));
  12190. this.firstElementOffsetByLineIdx.push(this.elements.length);
  12191. }
  12192. }
  12193. }
  12194. toString() {
  12195. return `Slice: "${this.text}"`;
  12196. }
  12197. get text() {
  12198. return this.getText(new OffsetRange(0, this.length));
  12199. }
  12200. getText(range) {
  12201. return this.elements.slice(range.start, range.endExclusive).map(e => String.fromCharCode(e)).join('');
  12202. }
  12203. getElement(offset) {
  12204. return this.elements[offset];
  12205. }
  12206. get length() {
  12207. return this.elements.length;
  12208. }
  12209. getBoundaryScore(length) {
  12210. // a b c , d e f
  12211. // 11 0 0 12 15 6 13 0 0 11
  12212. const prevCategory = getCategory(length > 0 ? this.elements[length - 1] : -1);
  12213. const nextCategory = getCategory(length < this.elements.length ? this.elements[length] : -1);
  12214. if (prevCategory === 7 /* CharBoundaryCategory.LineBreakCR */ && nextCategory === 8 /* CharBoundaryCategory.LineBreakLF */) {
  12215. // don't break between \r and \n
  12216. return 0;
  12217. }
  12218. if (prevCategory === 8 /* CharBoundaryCategory.LineBreakLF */) {
  12219. // prefer the linebreak before the change
  12220. return 150;
  12221. }
  12222. let score = 0;
  12223. if (prevCategory !== nextCategory) {
  12224. score += 10;
  12225. if (prevCategory === 0 /* CharBoundaryCategory.WordLower */ && nextCategory === 1 /* CharBoundaryCategory.WordUpper */) {
  12226. score += 1;
  12227. }
  12228. }
  12229. score += getCategoryBoundaryScore(prevCategory);
  12230. score += getCategoryBoundaryScore(nextCategory);
  12231. return score;
  12232. }
  12233. translateOffset(offset, preference = 'right') {
  12234. // find smallest i, so that lineBreakOffsets[i] <= offset using binary search
  12235. const i = findLastIdxMonotonous(this.firstElementOffsetByLineIdx, (value) => value <= offset);
  12236. const lineOffset = offset - this.firstElementOffsetByLineIdx[i];
  12237. return new Position(this.range.startLineNumber + i, 1 + this.lineStartOffsets[i] + lineOffset + ((lineOffset === 0 && preference === 'left') ? 0 : this.trimmedWsLengthsByLineIdx[i]));
  12238. }
  12239. translateRange(range) {
  12240. const pos1 = this.translateOffset(range.start, 'right');
  12241. const pos2 = this.translateOffset(range.endExclusive, 'left');
  12242. if (pos2.isBefore(pos1)) {
  12243. return Range.fromPositions(pos2, pos2);
  12244. }
  12245. return Range.fromPositions(pos1, pos2);
  12246. }
  12247. /**
  12248. * Finds the word that contains the character at the given offset
  12249. */
  12250. findWordContaining(offset) {
  12251. if (offset < 0 || offset >= this.elements.length) {
  12252. return undefined;
  12253. }
  12254. if (!isWordChar(this.elements[offset])) {
  12255. return undefined;
  12256. }
  12257. // find start
  12258. let start = offset;
  12259. while (start > 0 && isWordChar(this.elements[start - 1])) {
  12260. start--;
  12261. }
  12262. // find end
  12263. let end = offset;
  12264. while (end < this.elements.length && isWordChar(this.elements[end])) {
  12265. end++;
  12266. }
  12267. return new OffsetRange(start, end);
  12268. }
  12269. countLinesIn(range) {
  12270. return this.translateOffset(range.endExclusive).lineNumber - this.translateOffset(range.start).lineNumber;
  12271. }
  12272. isStronglyEqual(offset1, offset2) {
  12273. return this.elements[offset1] === this.elements[offset2];
  12274. }
  12275. extendToFullLines(range) {
  12276. const start = findLastMonotonous(this.firstElementOffsetByLineIdx, x => x <= range.start) ?? 0;
  12277. const end = findFirstMonotonous(this.firstElementOffsetByLineIdx, x => range.endExclusive <= x) ?? this.elements.length;
  12278. return new OffsetRange(start, end);
  12279. }
  12280. }
  12281. function isWordChar(charCode) {
  12282. return charCode >= 97 /* CharCode.a */ && charCode <= 122 /* CharCode.z */
  12283. || charCode >= 65 /* CharCode.A */ && charCode <= 90 /* CharCode.Z */
  12284. || charCode >= 48 /* CharCode.Digit0 */ && charCode <= 57 /* CharCode.Digit9 */;
  12285. }
  12286. const score = {
  12287. [0 /* CharBoundaryCategory.WordLower */]: 0,
  12288. [1 /* CharBoundaryCategory.WordUpper */]: 0,
  12289. [2 /* CharBoundaryCategory.WordNumber */]: 0,
  12290. [3 /* CharBoundaryCategory.End */]: 10,
  12291. [4 /* CharBoundaryCategory.Other */]: 2,
  12292. [5 /* CharBoundaryCategory.Separator */]: 30,
  12293. [6 /* CharBoundaryCategory.Space */]: 3,
  12294. [7 /* CharBoundaryCategory.LineBreakCR */]: 10,
  12295. [8 /* CharBoundaryCategory.LineBreakLF */]: 10,
  12296. };
  12297. function getCategoryBoundaryScore(category) {
  12298. return score[category];
  12299. }
  12300. function getCategory(charCode) {
  12301. if (charCode === 10 /* CharCode.LineFeed */) {
  12302. return 8 /* CharBoundaryCategory.LineBreakLF */;
  12303. }
  12304. else if (charCode === 13 /* CharCode.CarriageReturn */) {
  12305. return 7 /* CharBoundaryCategory.LineBreakCR */;
  12306. }
  12307. else if (isSpace(charCode)) {
  12308. return 6 /* CharBoundaryCategory.Space */;
  12309. }
  12310. else if (charCode >= 97 /* CharCode.a */ && charCode <= 122 /* CharCode.z */) {
  12311. return 0 /* CharBoundaryCategory.WordLower */;
  12312. }
  12313. else if (charCode >= 65 /* CharCode.A */ && charCode <= 90 /* CharCode.Z */) {
  12314. return 1 /* CharBoundaryCategory.WordUpper */;
  12315. }
  12316. else if (charCode >= 48 /* CharCode.Digit0 */ && charCode <= 57 /* CharCode.Digit9 */) {
  12317. return 2 /* CharBoundaryCategory.WordNumber */;
  12318. }
  12319. else if (charCode === -1) {
  12320. return 3 /* CharBoundaryCategory.End */;
  12321. }
  12322. else if (charCode === 44 /* CharCode.Comma */ || charCode === 59 /* CharCode.Semicolon */) {
  12323. return 5 /* CharBoundaryCategory.Separator */;
  12324. }
  12325. else {
  12326. return 4 /* CharBoundaryCategory.Other */;
  12327. }
  12328. }
  12329. /*---------------------------------------------------------------------------------------------
  12330. * Copyright (c) Microsoft Corporation. All rights reserved.
  12331. * Licensed under the MIT License. See License.txt in the project root for license information.
  12332. *--------------------------------------------------------------------------------------------*/
  12333. function computeMovedLines(changes, originalLines, modifiedLines, hashedOriginalLines, hashedModifiedLines, timeout) {
  12334. let { moves, excludedChanges } = computeMovesFromSimpleDeletionsToSimpleInsertions(changes, originalLines, modifiedLines, timeout);
  12335. if (!timeout.isValid()) {
  12336. return [];
  12337. }
  12338. const filteredChanges = changes.filter(c => !excludedChanges.has(c));
  12339. const unchangedMoves = computeUnchangedMoves(filteredChanges, hashedOriginalLines, hashedModifiedLines, originalLines, modifiedLines, timeout);
  12340. pushMany(moves, unchangedMoves);
  12341. moves = joinCloseConsecutiveMoves(moves);
  12342. // Ignore too short moves
  12343. moves = moves.filter(current => {
  12344. const lines = current.original.toOffsetRange().slice(originalLines).map(l => l.trim());
  12345. const originalText = lines.join('\n');
  12346. return originalText.length >= 15 && countWhere(lines, l => l.length >= 2) >= 2;
  12347. });
  12348. moves = removeMovesInSameDiff(changes, moves);
  12349. return moves;
  12350. }
  12351. function countWhere(arr, predicate) {
  12352. let count = 0;
  12353. for (const t of arr) {
  12354. if (predicate(t)) {
  12355. count++;
  12356. }
  12357. }
  12358. return count;
  12359. }
  12360. function computeMovesFromSimpleDeletionsToSimpleInsertions(changes, originalLines, modifiedLines, timeout) {
  12361. const moves = [];
  12362. const deletions = changes
  12363. .filter(c => c.modified.isEmpty && c.original.length >= 3)
  12364. .map(d => new LineRangeFragment(d.original, originalLines, d));
  12365. const insertions = new Set(changes
  12366. .filter(c => c.original.isEmpty && c.modified.length >= 3)
  12367. .map(d => new LineRangeFragment(d.modified, modifiedLines, d)));
  12368. const excludedChanges = new Set();
  12369. for (const deletion of deletions) {
  12370. let highestSimilarity = -1;
  12371. let best;
  12372. for (const insertion of insertions) {
  12373. const similarity = deletion.computeSimilarity(insertion);
  12374. if (similarity > highestSimilarity) {
  12375. highestSimilarity = similarity;
  12376. best = insertion;
  12377. }
  12378. }
  12379. if (highestSimilarity > 0.90 && best) {
  12380. insertions.delete(best);
  12381. moves.push(new LineRangeMapping(deletion.range, best.range));
  12382. excludedChanges.add(deletion.source);
  12383. excludedChanges.add(best.source);
  12384. }
  12385. if (!timeout.isValid()) {
  12386. return { moves, excludedChanges };
  12387. }
  12388. }
  12389. return { moves, excludedChanges };
  12390. }
  12391. function computeUnchangedMoves(changes, hashedOriginalLines, hashedModifiedLines, originalLines, modifiedLines, timeout) {
  12392. const moves = [];
  12393. const original3LineHashes = new SetMap();
  12394. for (const change of changes) {
  12395. for (let i = change.original.startLineNumber; i < change.original.endLineNumberExclusive - 2; i++) {
  12396. const key = `${hashedOriginalLines[i - 1]}:${hashedOriginalLines[i + 1 - 1]}:${hashedOriginalLines[i + 2 - 1]}`;
  12397. original3LineHashes.add(key, { range: new LineRange(i, i + 3) });
  12398. }
  12399. }
  12400. const possibleMappings = [];
  12401. changes.sort(compareBy(c => c.modified.startLineNumber, numberComparator));
  12402. for (const change of changes) {
  12403. let lastMappings = [];
  12404. for (let i = change.modified.startLineNumber; i < change.modified.endLineNumberExclusive - 2; i++) {
  12405. const key = `${hashedModifiedLines[i - 1]}:${hashedModifiedLines[i + 1 - 1]}:${hashedModifiedLines[i + 2 - 1]}`;
  12406. const currentModifiedRange = new LineRange(i, i + 3);
  12407. const nextMappings = [];
  12408. original3LineHashes.forEach(key, ({ range }) => {
  12409. for (const lastMapping of lastMappings) {
  12410. // does this match extend some last match?
  12411. if (lastMapping.originalLineRange.endLineNumberExclusive + 1 === range.endLineNumberExclusive &&
  12412. lastMapping.modifiedLineRange.endLineNumberExclusive + 1 === currentModifiedRange.endLineNumberExclusive) {
  12413. lastMapping.originalLineRange = new LineRange(lastMapping.originalLineRange.startLineNumber, range.endLineNumberExclusive);
  12414. lastMapping.modifiedLineRange = new LineRange(lastMapping.modifiedLineRange.startLineNumber, currentModifiedRange.endLineNumberExclusive);
  12415. nextMappings.push(lastMapping);
  12416. return;
  12417. }
  12418. }
  12419. const mapping = {
  12420. modifiedLineRange: currentModifiedRange,
  12421. originalLineRange: range,
  12422. };
  12423. possibleMappings.push(mapping);
  12424. nextMappings.push(mapping);
  12425. });
  12426. lastMappings = nextMappings;
  12427. }
  12428. if (!timeout.isValid()) {
  12429. return [];
  12430. }
  12431. }
  12432. possibleMappings.sort(reverseOrder(compareBy(m => m.modifiedLineRange.length, numberComparator)));
  12433. const modifiedSet = new LineRangeSet();
  12434. const originalSet = new LineRangeSet();
  12435. for (const mapping of possibleMappings) {
  12436. const diffOrigToMod = mapping.modifiedLineRange.startLineNumber - mapping.originalLineRange.startLineNumber;
  12437. const modifiedSections = modifiedSet.subtractFrom(mapping.modifiedLineRange);
  12438. const originalTranslatedSections = originalSet.subtractFrom(mapping.originalLineRange).getWithDelta(diffOrigToMod);
  12439. const modifiedIntersectedSections = modifiedSections.getIntersection(originalTranslatedSections);
  12440. for (const s of modifiedIntersectedSections.ranges) {
  12441. if (s.length < 3) {
  12442. continue;
  12443. }
  12444. const modifiedLineRange = s;
  12445. const originalLineRange = s.delta(-diffOrigToMod);
  12446. moves.push(new LineRangeMapping(originalLineRange, modifiedLineRange));
  12447. modifiedSet.addRange(modifiedLineRange);
  12448. originalSet.addRange(originalLineRange);
  12449. }
  12450. }
  12451. moves.sort(compareBy(m => m.original.startLineNumber, numberComparator));
  12452. const monotonousChanges = new MonotonousArray(changes);
  12453. for (let i = 0; i < moves.length; i++) {
  12454. const move = moves[i];
  12455. const firstTouchingChangeOrig = monotonousChanges.findLastMonotonous(c => c.original.startLineNumber <= move.original.startLineNumber);
  12456. const firstTouchingChangeMod = findLastMonotonous(changes, c => c.modified.startLineNumber <= move.modified.startLineNumber);
  12457. const linesAbove = Math.max(move.original.startLineNumber - firstTouchingChangeOrig.original.startLineNumber, move.modified.startLineNumber - firstTouchingChangeMod.modified.startLineNumber);
  12458. const lastTouchingChangeOrig = monotonousChanges.findLastMonotonous(c => c.original.startLineNumber < move.original.endLineNumberExclusive);
  12459. const lastTouchingChangeMod = findLastMonotonous(changes, c => c.modified.startLineNumber < move.modified.endLineNumberExclusive);
  12460. const linesBelow = Math.max(lastTouchingChangeOrig.original.endLineNumberExclusive - move.original.endLineNumberExclusive, lastTouchingChangeMod.modified.endLineNumberExclusive - move.modified.endLineNumberExclusive);
  12461. let extendToTop;
  12462. for (extendToTop = 0; extendToTop < linesAbove; extendToTop++) {
  12463. const origLine = move.original.startLineNumber - extendToTop - 1;
  12464. const modLine = move.modified.startLineNumber - extendToTop - 1;
  12465. if (origLine > originalLines.length || modLine > modifiedLines.length) {
  12466. break;
  12467. }
  12468. if (modifiedSet.contains(modLine) || originalSet.contains(origLine)) {
  12469. break;
  12470. }
  12471. if (!areLinesSimilar(originalLines[origLine - 1], modifiedLines[modLine - 1], timeout)) {
  12472. break;
  12473. }
  12474. }
  12475. if (extendToTop > 0) {
  12476. originalSet.addRange(new LineRange(move.original.startLineNumber - extendToTop, move.original.startLineNumber));
  12477. modifiedSet.addRange(new LineRange(move.modified.startLineNumber - extendToTop, move.modified.startLineNumber));
  12478. }
  12479. let extendToBottom;
  12480. for (extendToBottom = 0; extendToBottom < linesBelow; extendToBottom++) {
  12481. const origLine = move.original.endLineNumberExclusive + extendToBottom;
  12482. const modLine = move.modified.endLineNumberExclusive + extendToBottom;
  12483. if (origLine > originalLines.length || modLine > modifiedLines.length) {
  12484. break;
  12485. }
  12486. if (modifiedSet.contains(modLine) || originalSet.contains(origLine)) {
  12487. break;
  12488. }
  12489. if (!areLinesSimilar(originalLines[origLine - 1], modifiedLines[modLine - 1], timeout)) {
  12490. break;
  12491. }
  12492. }
  12493. if (extendToBottom > 0) {
  12494. originalSet.addRange(new LineRange(move.original.endLineNumberExclusive, move.original.endLineNumberExclusive + extendToBottom));
  12495. modifiedSet.addRange(new LineRange(move.modified.endLineNumberExclusive, move.modified.endLineNumberExclusive + extendToBottom));
  12496. }
  12497. if (extendToTop > 0 || extendToBottom > 0) {
  12498. moves[i] = new LineRangeMapping(new LineRange(move.original.startLineNumber - extendToTop, move.original.endLineNumberExclusive + extendToBottom), new LineRange(move.modified.startLineNumber - extendToTop, move.modified.endLineNumberExclusive + extendToBottom));
  12499. }
  12500. }
  12501. return moves;
  12502. }
  12503. function areLinesSimilar(line1, line2, timeout) {
  12504. if (line1.trim() === line2.trim()) {
  12505. return true;
  12506. }
  12507. if (line1.length > 300 && line2.length > 300) {
  12508. return false;
  12509. }
  12510. const myersDiffingAlgorithm = new MyersDiffAlgorithm();
  12511. const result = myersDiffingAlgorithm.compute(new LinesSliceCharSequence([line1], new Range(1, 1, 1, line1.length), false), new LinesSliceCharSequence([line2], new Range(1, 1, 1, line2.length), false), timeout);
  12512. let commonNonSpaceCharCount = 0;
  12513. const inverted = SequenceDiff.invert(result.diffs, line1.length);
  12514. for (const seq of inverted) {
  12515. seq.seq1Range.forEach(idx => {
  12516. if (!isSpace(line1.charCodeAt(idx))) {
  12517. commonNonSpaceCharCount++;
  12518. }
  12519. });
  12520. }
  12521. function countNonWsChars(str) {
  12522. let count = 0;
  12523. for (let i = 0; i < line1.length; i++) {
  12524. if (!isSpace(str.charCodeAt(i))) {
  12525. count++;
  12526. }
  12527. }
  12528. return count;
  12529. }
  12530. const longerLineLength = countNonWsChars(line1.length > line2.length ? line1 : line2);
  12531. const r = commonNonSpaceCharCount / longerLineLength > 0.6 && longerLineLength > 10;
  12532. return r;
  12533. }
  12534. function joinCloseConsecutiveMoves(moves) {
  12535. if (moves.length === 0) {
  12536. return moves;
  12537. }
  12538. moves.sort(compareBy(m => m.original.startLineNumber, numberComparator));
  12539. const result = [moves[0]];
  12540. for (let i = 1; i < moves.length; i++) {
  12541. const last = result[result.length - 1];
  12542. const current = moves[i];
  12543. const originalDist = current.original.startLineNumber - last.original.endLineNumberExclusive;
  12544. const modifiedDist = current.modified.startLineNumber - last.modified.endLineNumberExclusive;
  12545. const currentMoveAfterLast = originalDist >= 0 && modifiedDist >= 0;
  12546. if (currentMoveAfterLast && originalDist + modifiedDist <= 2) {
  12547. result[result.length - 1] = last.join(current);
  12548. continue;
  12549. }
  12550. result.push(current);
  12551. }
  12552. return result;
  12553. }
  12554. function removeMovesInSameDiff(changes, moves) {
  12555. const changesMonotonous = new MonotonousArray(changes);
  12556. moves = moves.filter(m => {
  12557. const diffBeforeEndOfMoveOriginal = changesMonotonous.findLastMonotonous(c => c.original.startLineNumber < m.original.endLineNumberExclusive)
  12558. || new LineRangeMapping(new LineRange(1, 1), new LineRange(1, 1));
  12559. const diffBeforeEndOfMoveModified = findLastMonotonous(changes, c => c.modified.startLineNumber < m.modified.endLineNumberExclusive);
  12560. const differentDiffs = diffBeforeEndOfMoveOriginal !== diffBeforeEndOfMoveModified;
  12561. return differentDiffs;
  12562. });
  12563. return moves;
  12564. }
  12565. /*---------------------------------------------------------------------------------------------
  12566. * Copyright (c) Microsoft Corporation. All rights reserved.
  12567. * Licensed under the MIT License. See License.txt in the project root for license information.
  12568. *--------------------------------------------------------------------------------------------*/
  12569. function optimizeSequenceDiffs(sequence1, sequence2, sequenceDiffs) {
  12570. let result = sequenceDiffs;
  12571. result = joinSequenceDiffsByShifting(sequence1, sequence2, result);
  12572. // Sometimes, calling this function twice improves the result.
  12573. // Uncomment the second invocation and run the tests to see the difference.
  12574. result = joinSequenceDiffsByShifting(sequence1, sequence2, result);
  12575. result = shiftSequenceDiffs(sequence1, sequence2, result);
  12576. return result;
  12577. }
  12578. /**
  12579. * This function fixes issues like this:
  12580. * ```
  12581. * import { Baz, Bar } from "foo";
  12582. * ```
  12583. * <->
  12584. * ```
  12585. * import { Baz, Bar, Foo } from "foo";
  12586. * ```
  12587. * Computed diff: [ {Add "," after Bar}, {Add "Foo " after space} }
  12588. * Improved diff: [{Add ", Foo" after Bar}]
  12589. */
  12590. function joinSequenceDiffsByShifting(sequence1, sequence2, sequenceDiffs) {
  12591. if (sequenceDiffs.length === 0) {
  12592. return sequenceDiffs;
  12593. }
  12594. const result = [];
  12595. result.push(sequenceDiffs[0]);
  12596. // First move them all to the left as much as possible and join them if possible
  12597. for (let i = 1; i < sequenceDiffs.length; i++) {
  12598. const prevResult = result[result.length - 1];
  12599. let cur = sequenceDiffs[i];
  12600. if (cur.seq1Range.isEmpty || cur.seq2Range.isEmpty) {
  12601. const length = cur.seq1Range.start - prevResult.seq1Range.endExclusive;
  12602. let d;
  12603. for (d = 1; d <= length; d++) {
  12604. if (sequence1.getElement(cur.seq1Range.start - d) !== sequence1.getElement(cur.seq1Range.endExclusive - d) ||
  12605. sequence2.getElement(cur.seq2Range.start - d) !== sequence2.getElement(cur.seq2Range.endExclusive - d)) {
  12606. break;
  12607. }
  12608. }
  12609. d--;
  12610. if (d === length) {
  12611. // Merge previous and current diff
  12612. result[result.length - 1] = new SequenceDiff(new OffsetRange(prevResult.seq1Range.start, cur.seq1Range.endExclusive - length), new OffsetRange(prevResult.seq2Range.start, cur.seq2Range.endExclusive - length));
  12613. continue;
  12614. }
  12615. cur = cur.delta(-d);
  12616. }
  12617. result.push(cur);
  12618. }
  12619. const result2 = [];
  12620. // Then move them all to the right and join them again if possible
  12621. for (let i = 0; i < result.length - 1; i++) {
  12622. const nextResult = result[i + 1];
  12623. let cur = result[i];
  12624. if (cur.seq1Range.isEmpty || cur.seq2Range.isEmpty) {
  12625. const length = nextResult.seq1Range.start - cur.seq1Range.endExclusive;
  12626. let d;
  12627. for (d = 0; d < length; d++) {
  12628. if (!sequence1.isStronglyEqual(cur.seq1Range.start + d, cur.seq1Range.endExclusive + d) ||
  12629. !sequence2.isStronglyEqual(cur.seq2Range.start + d, cur.seq2Range.endExclusive + d)) {
  12630. break;
  12631. }
  12632. }
  12633. if (d === length) {
  12634. // Merge previous and current diff, write to result!
  12635. result[i + 1] = new SequenceDiff(new OffsetRange(cur.seq1Range.start + length, nextResult.seq1Range.endExclusive), new OffsetRange(cur.seq2Range.start + length, nextResult.seq2Range.endExclusive));
  12636. continue;
  12637. }
  12638. if (d > 0) {
  12639. cur = cur.delta(d);
  12640. }
  12641. }
  12642. result2.push(cur);
  12643. }
  12644. if (result.length > 0) {
  12645. result2.push(result[result.length - 1]);
  12646. }
  12647. return result2;
  12648. }
  12649. // align character level diffs at whitespace characters
  12650. // import { IBar } from "foo";
  12651. // import { I[Arr, I]Bar } from "foo";
  12652. // ->
  12653. // import { [IArr, ]IBar } from "foo";
  12654. // import { ITransaction, observableValue, transaction } from 'vs/base/common/observable';
  12655. // import { ITransaction, observable[FromEvent, observable]Value, transaction } from 'vs/base/common/observable';
  12656. // ->
  12657. // import { ITransaction, [observableFromEvent, ]observableValue, transaction } from 'vs/base/common/observable';
  12658. // collectBrackets(level + 1, levelPerBracketType);
  12659. // collectBrackets(level + 1, levelPerBracket[ + 1, levelPerBracket]Type);
  12660. // ->
  12661. // collectBrackets(level + 1, [levelPerBracket + 1, ]levelPerBracketType);
  12662. function shiftSequenceDiffs(sequence1, sequence2, sequenceDiffs) {
  12663. if (!sequence1.getBoundaryScore || !sequence2.getBoundaryScore) {
  12664. return sequenceDiffs;
  12665. }
  12666. for (let i = 0; i < sequenceDiffs.length; i++) {
  12667. const prevDiff = (i > 0 ? sequenceDiffs[i - 1] : undefined);
  12668. const diff = sequenceDiffs[i];
  12669. const nextDiff = (i + 1 < sequenceDiffs.length ? sequenceDiffs[i + 1] : undefined);
  12670. const seq1ValidRange = new OffsetRange(prevDiff ? prevDiff.seq1Range.endExclusive + 1 : 0, nextDiff ? nextDiff.seq1Range.start - 1 : sequence1.length);
  12671. const seq2ValidRange = new OffsetRange(prevDiff ? prevDiff.seq2Range.endExclusive + 1 : 0, nextDiff ? nextDiff.seq2Range.start - 1 : sequence2.length);
  12672. if (diff.seq1Range.isEmpty) {
  12673. sequenceDiffs[i] = shiftDiffToBetterPosition(diff, sequence1, sequence2, seq1ValidRange, seq2ValidRange);
  12674. }
  12675. else if (diff.seq2Range.isEmpty) {
  12676. sequenceDiffs[i] = shiftDiffToBetterPosition(diff.swap(), sequence2, sequence1, seq2ValidRange, seq1ValidRange).swap();
  12677. }
  12678. }
  12679. return sequenceDiffs;
  12680. }
  12681. function shiftDiffToBetterPosition(diff, sequence1, sequence2, seq1ValidRange, seq2ValidRange) {
  12682. const maxShiftLimit = 100; // To prevent performance issues
  12683. // don't touch previous or next!
  12684. let deltaBefore = 1;
  12685. while (diff.seq1Range.start - deltaBefore >= seq1ValidRange.start &&
  12686. diff.seq2Range.start - deltaBefore >= seq2ValidRange.start &&
  12687. sequence2.isStronglyEqual(diff.seq2Range.start - deltaBefore, diff.seq2Range.endExclusive - deltaBefore) && deltaBefore < maxShiftLimit) {
  12688. deltaBefore++;
  12689. }
  12690. deltaBefore--;
  12691. let deltaAfter = 0;
  12692. while (diff.seq1Range.start + deltaAfter < seq1ValidRange.endExclusive &&
  12693. diff.seq2Range.endExclusive + deltaAfter < seq2ValidRange.endExclusive &&
  12694. sequence2.isStronglyEqual(diff.seq2Range.start + deltaAfter, diff.seq2Range.endExclusive + deltaAfter) && deltaAfter < maxShiftLimit) {
  12695. deltaAfter++;
  12696. }
  12697. if (deltaBefore === 0 && deltaAfter === 0) {
  12698. return diff;
  12699. }
  12700. // Visualize `[sequence1.text, diff.seq1Range.start + deltaAfter]`
  12701. // and `[sequence2.text, diff.seq2Range.start + deltaAfter, diff.seq2Range.endExclusive + deltaAfter]`
  12702. let bestDelta = 0;
  12703. let bestScore = -1;
  12704. // find best scored delta
  12705. for (let delta = -deltaBefore; delta <= deltaAfter; delta++) {
  12706. const seq2OffsetStart = diff.seq2Range.start + delta;
  12707. const seq2OffsetEndExclusive = diff.seq2Range.endExclusive + delta;
  12708. const seq1Offset = diff.seq1Range.start + delta;
  12709. const score = sequence1.getBoundaryScore(seq1Offset) + sequence2.getBoundaryScore(seq2OffsetStart) + sequence2.getBoundaryScore(seq2OffsetEndExclusive);
  12710. if (score > bestScore) {
  12711. bestScore = score;
  12712. bestDelta = delta;
  12713. }
  12714. }
  12715. return diff.delta(bestDelta);
  12716. }
  12717. function removeShortMatches(sequence1, sequence2, sequenceDiffs) {
  12718. const result = [];
  12719. for (const s of sequenceDiffs) {
  12720. const last = result[result.length - 1];
  12721. if (!last) {
  12722. result.push(s);
  12723. continue;
  12724. }
  12725. if (s.seq1Range.start - last.seq1Range.endExclusive <= 2 || s.seq2Range.start - last.seq2Range.endExclusive <= 2) {
  12726. result[result.length - 1] = new SequenceDiff(last.seq1Range.join(s.seq1Range), last.seq2Range.join(s.seq2Range));
  12727. }
  12728. else {
  12729. result.push(s);
  12730. }
  12731. }
  12732. return result;
  12733. }
  12734. function extendDiffsToEntireWordIfAppropriate(sequence1, sequence2, sequenceDiffs) {
  12735. const equalMappings = SequenceDiff.invert(sequenceDiffs, sequence1.length);
  12736. const additional = [];
  12737. let lastPoint = new OffsetPair(0, 0);
  12738. function scanWord(pair, equalMapping) {
  12739. if (pair.offset1 < lastPoint.offset1 || pair.offset2 < lastPoint.offset2) {
  12740. return;
  12741. }
  12742. const w1 = sequence1.findWordContaining(pair.offset1);
  12743. const w2 = sequence2.findWordContaining(pair.offset2);
  12744. if (!w1 || !w2) {
  12745. return;
  12746. }
  12747. let w = new SequenceDiff(w1, w2);
  12748. const equalPart = w.intersect(equalMapping);
  12749. let equalChars1 = equalPart.seq1Range.length;
  12750. let equalChars2 = equalPart.seq2Range.length;
  12751. // The words do not touch previous equals mappings, as we would have processed them already.
  12752. // But they might touch the next ones.
  12753. while (equalMappings.length > 0) {
  12754. const next = equalMappings[0];
  12755. const intersects = next.seq1Range.intersects(w.seq1Range) || next.seq2Range.intersects(w.seq2Range);
  12756. if (!intersects) {
  12757. break;
  12758. }
  12759. const v1 = sequence1.findWordContaining(next.seq1Range.start);
  12760. const v2 = sequence2.findWordContaining(next.seq2Range.start);
  12761. // Because there is an intersection, we know that the words are not empty.
  12762. const v = new SequenceDiff(v1, v2);
  12763. const equalPart = v.intersect(next);
  12764. equalChars1 += equalPart.seq1Range.length;
  12765. equalChars2 += equalPart.seq2Range.length;
  12766. w = w.join(v);
  12767. if (w.seq1Range.endExclusive >= next.seq1Range.endExclusive) {
  12768. // The word extends beyond the next equal mapping.
  12769. equalMappings.shift();
  12770. }
  12771. else {
  12772. break;
  12773. }
  12774. }
  12775. if (equalChars1 + equalChars2 < (w.seq1Range.length + w.seq2Range.length) * 2 / 3) {
  12776. additional.push(w);
  12777. }
  12778. lastPoint = w.getEndExclusives();
  12779. }
  12780. while (equalMappings.length > 0) {
  12781. const next = equalMappings.shift();
  12782. if (next.seq1Range.isEmpty) {
  12783. continue;
  12784. }
  12785. scanWord(next.getStarts(), next);
  12786. // The equal parts are not empty, so -1 gives us a character that is equal in both parts.
  12787. scanWord(next.getEndExclusives().delta(-1), next);
  12788. }
  12789. const merged = mergeSequenceDiffs(sequenceDiffs, additional);
  12790. return merged;
  12791. }
  12792. function mergeSequenceDiffs(sequenceDiffs1, sequenceDiffs2) {
  12793. const result = [];
  12794. while (sequenceDiffs1.length > 0 || sequenceDiffs2.length > 0) {
  12795. const sd1 = sequenceDiffs1[0];
  12796. const sd2 = sequenceDiffs2[0];
  12797. let next;
  12798. if (sd1 && (!sd2 || sd1.seq1Range.start < sd2.seq1Range.start)) {
  12799. next = sequenceDiffs1.shift();
  12800. }
  12801. else {
  12802. next = sequenceDiffs2.shift();
  12803. }
  12804. if (result.length > 0 && result[result.length - 1].seq1Range.endExclusive >= next.seq1Range.start) {
  12805. result[result.length - 1] = result[result.length - 1].join(next);
  12806. }
  12807. else {
  12808. result.push(next);
  12809. }
  12810. }
  12811. return result;
  12812. }
  12813. function removeVeryShortMatchingLinesBetweenDiffs(sequence1, _sequence2, sequenceDiffs) {
  12814. let diffs = sequenceDiffs;
  12815. if (diffs.length === 0) {
  12816. return diffs;
  12817. }
  12818. let counter = 0;
  12819. let shouldRepeat;
  12820. do {
  12821. shouldRepeat = false;
  12822. const result = [
  12823. diffs[0]
  12824. ];
  12825. for (let i = 1; i < diffs.length; i++) {
  12826. const cur = diffs[i];
  12827. const lastResult = result[result.length - 1];
  12828. function shouldJoinDiffs(before, after) {
  12829. const unchangedRange = new OffsetRange(lastResult.seq1Range.endExclusive, cur.seq1Range.start);
  12830. const unchangedText = sequence1.getText(unchangedRange);
  12831. const unchangedTextWithoutWs = unchangedText.replace(/\s/g, '');
  12832. if (unchangedTextWithoutWs.length <= 4
  12833. && (before.seq1Range.length + before.seq2Range.length > 5 || after.seq1Range.length + after.seq2Range.length > 5)) {
  12834. return true;
  12835. }
  12836. return false;
  12837. }
  12838. const shouldJoin = shouldJoinDiffs(lastResult, cur);
  12839. if (shouldJoin) {
  12840. shouldRepeat = true;
  12841. result[result.length - 1] = result[result.length - 1].join(cur);
  12842. }
  12843. else {
  12844. result.push(cur);
  12845. }
  12846. }
  12847. diffs = result;
  12848. } while (counter++ < 10 && shouldRepeat);
  12849. return diffs;
  12850. }
  12851. function removeVeryShortMatchingTextBetweenLongDiffs(sequence1, sequence2, sequenceDiffs) {
  12852. let diffs = sequenceDiffs;
  12853. if (diffs.length === 0) {
  12854. return diffs;
  12855. }
  12856. let counter = 0;
  12857. let shouldRepeat;
  12858. do {
  12859. shouldRepeat = false;
  12860. const result = [
  12861. diffs[0]
  12862. ];
  12863. for (let i = 1; i < diffs.length; i++) {
  12864. const cur = diffs[i];
  12865. const lastResult = result[result.length - 1];
  12866. function shouldJoinDiffs(before, after) {
  12867. const unchangedRange = new OffsetRange(lastResult.seq1Range.endExclusive, cur.seq1Range.start);
  12868. const unchangedLineCount = sequence1.countLinesIn(unchangedRange);
  12869. if (unchangedLineCount > 5 || unchangedRange.length > 500) {
  12870. return false;
  12871. }
  12872. const unchangedText = sequence1.getText(unchangedRange).trim();
  12873. if (unchangedText.length > 20 || unchangedText.split(/\r\n|\r|\n/).length > 1) {
  12874. return false;
  12875. }
  12876. const beforeLineCount1 = sequence1.countLinesIn(before.seq1Range);
  12877. const beforeSeq1Length = before.seq1Range.length;
  12878. const beforeLineCount2 = sequence2.countLinesIn(before.seq2Range);
  12879. const beforeSeq2Length = before.seq2Range.length;
  12880. const afterLineCount1 = sequence1.countLinesIn(after.seq1Range);
  12881. const afterSeq1Length = after.seq1Range.length;
  12882. const afterLineCount2 = sequence2.countLinesIn(after.seq2Range);
  12883. const afterSeq2Length = after.seq2Range.length;
  12884. // TODO: Maybe a neural net can be used to derive the result from these numbers
  12885. const max = 2 * 40 + 50;
  12886. function cap(v) {
  12887. return Math.min(v, max);
  12888. }
  12889. if (Math.pow(Math.pow(cap(beforeLineCount1 * 40 + beforeSeq1Length), 1.5) + Math.pow(cap(beforeLineCount2 * 40 + beforeSeq2Length), 1.5), 1.5)
  12890. + Math.pow(Math.pow(cap(afterLineCount1 * 40 + afterSeq1Length), 1.5) + Math.pow(cap(afterLineCount2 * 40 + afterSeq2Length), 1.5), 1.5) > ((max ** 1.5) ** 1.5) * 1.3) {
  12891. return true;
  12892. }
  12893. return false;
  12894. }
  12895. const shouldJoin = shouldJoinDiffs(lastResult, cur);
  12896. if (shouldJoin) {
  12897. shouldRepeat = true;
  12898. result[result.length - 1] = result[result.length - 1].join(cur);
  12899. }
  12900. else {
  12901. result.push(cur);
  12902. }
  12903. }
  12904. diffs = result;
  12905. } while (counter++ < 10 && shouldRepeat);
  12906. const newDiffs = [];
  12907. // Remove short suffixes/prefixes
  12908. forEachWithNeighbors(diffs, (prev, cur, next) => {
  12909. let newDiff = cur;
  12910. function shouldMarkAsChanged(text) {
  12911. return text.length > 0 && text.trim().length <= 3 && cur.seq1Range.length + cur.seq2Range.length > 100;
  12912. }
  12913. const fullRange1 = sequence1.extendToFullLines(cur.seq1Range);
  12914. const prefix = sequence1.getText(new OffsetRange(fullRange1.start, cur.seq1Range.start));
  12915. if (shouldMarkAsChanged(prefix)) {
  12916. newDiff = newDiff.deltaStart(-prefix.length);
  12917. }
  12918. const suffix = sequence1.getText(new OffsetRange(cur.seq1Range.endExclusive, fullRange1.endExclusive));
  12919. if (shouldMarkAsChanged(suffix)) {
  12920. newDiff = newDiff.deltaEnd(suffix.length);
  12921. }
  12922. const availableSpace = SequenceDiff.fromOffsetPairs(prev ? prev.getEndExclusives() : OffsetPair.zero, next ? next.getStarts() : OffsetPair.max);
  12923. const result = newDiff.intersect(availableSpace);
  12924. if (newDiffs.length > 0 && result.getStarts().equals(newDiffs[newDiffs.length - 1].getEndExclusives())) {
  12925. newDiffs[newDiffs.length - 1] = newDiffs[newDiffs.length - 1].join(result);
  12926. }
  12927. else {
  12928. newDiffs.push(result);
  12929. }
  12930. });
  12931. return newDiffs;
  12932. }
  12933. /*---------------------------------------------------------------------------------------------
  12934. * Copyright (c) Microsoft Corporation. All rights reserved.
  12935. * Licensed under the MIT License. See License.txt in the project root for license information.
  12936. *--------------------------------------------------------------------------------------------*/
  12937. class LineSequence {
  12938. constructor(trimmedHash, lines) {
  12939. this.trimmedHash = trimmedHash;
  12940. this.lines = lines;
  12941. }
  12942. getElement(offset) {
  12943. return this.trimmedHash[offset];
  12944. }
  12945. get length() {
  12946. return this.trimmedHash.length;
  12947. }
  12948. getBoundaryScore(length) {
  12949. const indentationBefore = length === 0 ? 0 : getIndentation(this.lines[length - 1]);
  12950. const indentationAfter = length === this.lines.length ? 0 : getIndentation(this.lines[length]);
  12951. return 1000 - (indentationBefore + indentationAfter);
  12952. }
  12953. getText(range) {
  12954. return this.lines.slice(range.start, range.endExclusive).join('\n');
  12955. }
  12956. isStronglyEqual(offset1, offset2) {
  12957. return this.lines[offset1] === this.lines[offset2];
  12958. }
  12959. }
  12960. function getIndentation(str) {
  12961. let i = 0;
  12962. while (i < str.length && (str.charCodeAt(i) === 32 /* CharCode.Space */ || str.charCodeAt(i) === 9 /* CharCode.Tab */)) {
  12963. i++;
  12964. }
  12965. return i;
  12966. }
  12967. /*---------------------------------------------------------------------------------------------
  12968. * Copyright (c) Microsoft Corporation. All rights reserved.
  12969. * Licensed under the MIT License. See License.txt in the project root for license information.
  12970. *--------------------------------------------------------------------------------------------*/
  12971. class DefaultLinesDiffComputer {
  12972. constructor() {
  12973. this.dynamicProgrammingDiffing = new DynamicProgrammingDiffing();
  12974. this.myersDiffingAlgorithm = new MyersDiffAlgorithm();
  12975. }
  12976. computeDiff(originalLines, modifiedLines, options) {
  12977. if (originalLines.length <= 1 && equals(originalLines, modifiedLines, (a, b) => a === b)) {
  12978. return new LinesDiff([], [], false);
  12979. }
  12980. if (originalLines.length === 1 && originalLines[0].length === 0 || modifiedLines.length === 1 && modifiedLines[0].length === 0) {
  12981. return new LinesDiff([
  12982. new DetailedLineRangeMapping(new LineRange(1, originalLines.length + 1), new LineRange(1, modifiedLines.length + 1), [
  12983. new RangeMapping(new Range(1, 1, originalLines.length, originalLines[originalLines.length - 1].length + 1), new Range(1, 1, modifiedLines.length, modifiedLines[modifiedLines.length - 1].length + 1))
  12984. ])
  12985. ], [], false);
  12986. }
  12987. const timeout = options.maxComputationTimeMs === 0 ? InfiniteTimeout.instance : new DateTimeout(options.maxComputationTimeMs);
  12988. const considerWhitespaceChanges = !options.ignoreTrimWhitespace;
  12989. const perfectHashes = new Map();
  12990. function getOrCreateHash(text) {
  12991. let hash = perfectHashes.get(text);
  12992. if (hash === undefined) {
  12993. hash = perfectHashes.size;
  12994. perfectHashes.set(text, hash);
  12995. }
  12996. return hash;
  12997. }
  12998. const originalLinesHashes = originalLines.map((l) => getOrCreateHash(l.trim()));
  12999. const modifiedLinesHashes = modifiedLines.map((l) => getOrCreateHash(l.trim()));
  13000. const sequence1 = new LineSequence(originalLinesHashes, originalLines);
  13001. const sequence2 = new LineSequence(modifiedLinesHashes, modifiedLines);
  13002. const lineAlignmentResult = (() => {
  13003. if (sequence1.length + sequence2.length < 1700) {
  13004. // Use the improved algorithm for small files
  13005. return this.dynamicProgrammingDiffing.compute(sequence1, sequence2, timeout, (offset1, offset2) => originalLines[offset1] === modifiedLines[offset2]
  13006. ? modifiedLines[offset2].length === 0
  13007. ? 0.1
  13008. : 1 + Math.log(1 + modifiedLines[offset2].length)
  13009. : 0.99);
  13010. }
  13011. return this.myersDiffingAlgorithm.compute(sequence1, sequence2, timeout);
  13012. })();
  13013. let lineAlignments = lineAlignmentResult.diffs;
  13014. let hitTimeout = lineAlignmentResult.hitTimeout;
  13015. lineAlignments = optimizeSequenceDiffs(sequence1, sequence2, lineAlignments);
  13016. lineAlignments = removeVeryShortMatchingLinesBetweenDiffs(sequence1, sequence2, lineAlignments);
  13017. const alignments = [];
  13018. const scanForWhitespaceChanges = (equalLinesCount) => {
  13019. if (!considerWhitespaceChanges) {
  13020. return;
  13021. }
  13022. for (let i = 0; i < equalLinesCount; i++) {
  13023. const seq1Offset = seq1LastStart + i;
  13024. const seq2Offset = seq2LastStart + i;
  13025. if (originalLines[seq1Offset] !== modifiedLines[seq2Offset]) {
  13026. // This is because of whitespace changes, diff these lines
  13027. const characterDiffs = this.refineDiff(originalLines, modifiedLines, new SequenceDiff(new OffsetRange(seq1Offset, seq1Offset + 1), new OffsetRange(seq2Offset, seq2Offset + 1)), timeout, considerWhitespaceChanges);
  13028. for (const a of characterDiffs.mappings) {
  13029. alignments.push(a);
  13030. }
  13031. if (characterDiffs.hitTimeout) {
  13032. hitTimeout = true;
  13033. }
  13034. }
  13035. }
  13036. };
  13037. let seq1LastStart = 0;
  13038. let seq2LastStart = 0;
  13039. for (const diff of lineAlignments) {
  13040. assertFn(() => diff.seq1Range.start - seq1LastStart === diff.seq2Range.start - seq2LastStart);
  13041. const equalLinesCount = diff.seq1Range.start - seq1LastStart;
  13042. scanForWhitespaceChanges(equalLinesCount);
  13043. seq1LastStart = diff.seq1Range.endExclusive;
  13044. seq2LastStart = diff.seq2Range.endExclusive;
  13045. const characterDiffs = this.refineDiff(originalLines, modifiedLines, diff, timeout, considerWhitespaceChanges);
  13046. if (characterDiffs.hitTimeout) {
  13047. hitTimeout = true;
  13048. }
  13049. for (const a of characterDiffs.mappings) {
  13050. alignments.push(a);
  13051. }
  13052. }
  13053. scanForWhitespaceChanges(originalLines.length - seq1LastStart);
  13054. const changes = lineRangeMappingFromRangeMappings(alignments, originalLines, modifiedLines);
  13055. let moves = [];
  13056. if (options.computeMoves) {
  13057. moves = this.computeMoves(changes, originalLines, modifiedLines, originalLinesHashes, modifiedLinesHashes, timeout, considerWhitespaceChanges);
  13058. }
  13059. // Make sure all ranges are valid
  13060. assertFn(() => {
  13061. function validatePosition(pos, lines) {
  13062. if (pos.lineNumber < 1 || pos.lineNumber > lines.length) {
  13063. return false;
  13064. }
  13065. const line = lines[pos.lineNumber - 1];
  13066. if (pos.column < 1 || pos.column > line.length + 1) {
  13067. return false;
  13068. }
  13069. return true;
  13070. }
  13071. function validateRange(range, lines) {
  13072. if (range.startLineNumber < 1 || range.startLineNumber > lines.length + 1) {
  13073. return false;
  13074. }
  13075. if (range.endLineNumberExclusive < 1 || range.endLineNumberExclusive > lines.length + 1) {
  13076. return false;
  13077. }
  13078. return true;
  13079. }
  13080. for (const c of changes) {
  13081. if (!c.innerChanges) {
  13082. return false;
  13083. }
  13084. for (const ic of c.innerChanges) {
  13085. const valid = validatePosition(ic.modifiedRange.getStartPosition(), modifiedLines) && validatePosition(ic.modifiedRange.getEndPosition(), modifiedLines) &&
  13086. validatePosition(ic.originalRange.getStartPosition(), originalLines) && validatePosition(ic.originalRange.getEndPosition(), originalLines);
  13087. if (!valid) {
  13088. return false;
  13089. }
  13090. }
  13091. if (!validateRange(c.modified, modifiedLines) || !validateRange(c.original, originalLines)) {
  13092. return false;
  13093. }
  13094. }
  13095. return true;
  13096. });
  13097. return new LinesDiff(changes, moves, hitTimeout);
  13098. }
  13099. computeMoves(changes, originalLines, modifiedLines, hashedOriginalLines, hashedModifiedLines, timeout, considerWhitespaceChanges) {
  13100. const moves = computeMovedLines(changes, originalLines, modifiedLines, hashedOriginalLines, hashedModifiedLines, timeout);
  13101. const movesWithDiffs = moves.map(m => {
  13102. const moveChanges = this.refineDiff(originalLines, modifiedLines, new SequenceDiff(m.original.toOffsetRange(), m.modified.toOffsetRange()), timeout, considerWhitespaceChanges);
  13103. const mappings = lineRangeMappingFromRangeMappings(moveChanges.mappings, originalLines, modifiedLines, true);
  13104. return new MovedText(m, mappings);
  13105. });
  13106. return movesWithDiffs;
  13107. }
  13108. refineDiff(originalLines, modifiedLines, diff, timeout, considerWhitespaceChanges) {
  13109. const lineRangeMapping = toLineRangeMapping(diff);
  13110. const rangeMapping = lineRangeMapping.toRangeMapping2(originalLines, modifiedLines);
  13111. const slice1 = new LinesSliceCharSequence(originalLines, rangeMapping.originalRange, considerWhitespaceChanges);
  13112. const slice2 = new LinesSliceCharSequence(modifiedLines, rangeMapping.modifiedRange, considerWhitespaceChanges);
  13113. const diffResult = slice1.length + slice2.length < 500
  13114. ? this.dynamicProgrammingDiffing.compute(slice1, slice2, timeout)
  13115. : this.myersDiffingAlgorithm.compute(slice1, slice2, timeout);
  13116. let diffs = diffResult.diffs;
  13117. diffs = optimizeSequenceDiffs(slice1, slice2, diffs);
  13118. diffs = extendDiffsToEntireWordIfAppropriate(slice1, slice2, diffs);
  13119. diffs = removeShortMatches(slice1, slice2, diffs);
  13120. diffs = removeVeryShortMatchingTextBetweenLongDiffs(slice1, slice2, diffs);
  13121. const result = diffs.map((d) => new RangeMapping(slice1.translateRange(d.seq1Range), slice2.translateRange(d.seq2Range)));
  13122. // Assert: result applied on original should be the same as diff applied to original
  13123. return {
  13124. mappings: result,
  13125. hitTimeout: diffResult.hitTimeout,
  13126. };
  13127. }
  13128. }
  13129. function lineRangeMappingFromRangeMappings(alignments, originalLines, modifiedLines, dontAssertStartLine = false) {
  13130. const changes = [];
  13131. for (const g of groupAdjacentBy(alignments.map(a => getLineRangeMapping(a, originalLines, modifiedLines)), (a1, a2) => a1.original.overlapOrTouch(a2.original)
  13132. || a1.modified.overlapOrTouch(a2.modified))) {
  13133. const first = g[0];
  13134. const last = g[g.length - 1];
  13135. changes.push(new DetailedLineRangeMapping(first.original.join(last.original), first.modified.join(last.modified), g.map(a => a.innerChanges[0])));
  13136. }
  13137. assertFn(() => {
  13138. if (!dontAssertStartLine && changes.length > 0) {
  13139. if (changes[0].modified.startLineNumber !== changes[0].original.startLineNumber) {
  13140. return false;
  13141. }
  13142. if (modifiedLines.length - changes[changes.length - 1].modified.endLineNumberExclusive !== originalLines.length - changes[changes.length - 1].original.endLineNumberExclusive) {
  13143. return false;
  13144. }
  13145. }
  13146. return checkAdjacentItems(changes, (m1, m2) => m2.original.startLineNumber - m1.original.endLineNumberExclusive === m2.modified.startLineNumber - m1.modified.endLineNumberExclusive &&
  13147. // There has to be an unchanged line in between (otherwise both diffs should have been joined)
  13148. m1.original.endLineNumberExclusive < m2.original.startLineNumber &&
  13149. m1.modified.endLineNumberExclusive < m2.modified.startLineNumber);
  13150. });
  13151. return changes;
  13152. }
  13153. function getLineRangeMapping(rangeMapping, originalLines, modifiedLines) {
  13154. let lineStartDelta = 0;
  13155. let lineEndDelta = 0;
  13156. // rangeMapping describes the edit that replaces `rangeMapping.originalRange` with `newText := getText(modifiedLines, rangeMapping.modifiedRange)`.
  13157. // original: ]xxx \n <- this line is not modified
  13158. // modified: ]xx \n
  13159. if (rangeMapping.modifiedRange.endColumn === 1 && rangeMapping.originalRange.endColumn === 1
  13160. && rangeMapping.originalRange.startLineNumber + lineStartDelta <= rangeMapping.originalRange.endLineNumber
  13161. && rangeMapping.modifiedRange.startLineNumber + lineStartDelta <= rangeMapping.modifiedRange.endLineNumber) {
  13162. // We can only do this if the range is not empty yet
  13163. lineEndDelta = -1;
  13164. }
  13165. // original: xxx[ \n <- this line is not modified
  13166. // modified: xxx[ \n
  13167. if (rangeMapping.modifiedRange.startColumn - 1 >= modifiedLines[rangeMapping.modifiedRange.startLineNumber - 1].length
  13168. && rangeMapping.originalRange.startColumn - 1 >= originalLines[rangeMapping.originalRange.startLineNumber - 1].length
  13169. && rangeMapping.originalRange.startLineNumber <= rangeMapping.originalRange.endLineNumber + lineEndDelta
  13170. && rangeMapping.modifiedRange.startLineNumber <= rangeMapping.modifiedRange.endLineNumber + lineEndDelta) {
  13171. // We can only do this if the range is not empty yet
  13172. lineStartDelta = 1;
  13173. }
  13174. const originalLineRange = new LineRange(rangeMapping.originalRange.startLineNumber + lineStartDelta, rangeMapping.originalRange.endLineNumber + 1 + lineEndDelta);
  13175. const modifiedLineRange = new LineRange(rangeMapping.modifiedRange.startLineNumber + lineStartDelta, rangeMapping.modifiedRange.endLineNumber + 1 + lineEndDelta);
  13176. return new DetailedLineRangeMapping(originalLineRange, modifiedLineRange, [rangeMapping]);
  13177. }
  13178. function toLineRangeMapping(sequenceDiff) {
  13179. return new LineRangeMapping(new LineRange(sequenceDiff.seq1Range.start + 1, sequenceDiff.seq1Range.endExclusive + 1), new LineRange(sequenceDiff.seq2Range.start + 1, sequenceDiff.seq2Range.endExclusive + 1));
  13180. }
  13181. /*---------------------------------------------------------------------------------------------
  13182. * Copyright (c) Microsoft Corporation. All rights reserved.
  13183. * Licensed under the MIT License. See License.txt in the project root for license information.
  13184. *--------------------------------------------------------------------------------------------*/
  13185. const linesDiffComputers = {
  13186. getLegacy: () => new LegacyLinesDiffComputer(),
  13187. getDefault: () => new DefaultLinesDiffComputer(),
  13188. };
  13189. /*---------------------------------------------------------------------------------------------
  13190. * Copyright (c) Microsoft Corporation. All rights reserved.
  13191. * Licensed under the MIT License. See License.txt in the project root for license information.
  13192. *--------------------------------------------------------------------------------------------*/
  13193. function roundFloat(number, decimalPoints) {
  13194. const decimal = Math.pow(10, decimalPoints);
  13195. return Math.round(number * decimal) / decimal;
  13196. }
  13197. class RGBA {
  13198. constructor(r, g, b, a = 1) {
  13199. this._rgbaBrand = undefined;
  13200. this.r = Math.min(255, Math.max(0, r)) | 0;
  13201. this.g = Math.min(255, Math.max(0, g)) | 0;
  13202. this.b = Math.min(255, Math.max(0, b)) | 0;
  13203. this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
  13204. }
  13205. static equals(a, b) {
  13206. return a.r === b.r && a.g === b.g && a.b === b.b && a.a === b.a;
  13207. }
  13208. }
  13209. class HSLA {
  13210. constructor(h, s, l, a) {
  13211. this._hslaBrand = undefined;
  13212. this.h = Math.max(Math.min(360, h), 0) | 0;
  13213. this.s = roundFloat(Math.max(Math.min(1, s), 0), 3);
  13214. this.l = roundFloat(Math.max(Math.min(1, l), 0), 3);
  13215. this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
  13216. }
  13217. static equals(a, b) {
  13218. return a.h === b.h && a.s === b.s && a.l === b.l && a.a === b.a;
  13219. }
  13220. /**
  13221. * Converts an RGB color value to HSL. Conversion formula
  13222. * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
  13223. * Assumes r, g, and b are contained in the set [0, 255] and
  13224. * returns h in the set [0, 360], s, and l in the set [0, 1].
  13225. */
  13226. static fromRGBA(rgba) {
  13227. const r = rgba.r / 255;
  13228. const g = rgba.g / 255;
  13229. const b = rgba.b / 255;
  13230. const a = rgba.a;
  13231. const max = Math.max(r, g, b);
  13232. const min = Math.min(r, g, b);
  13233. let h = 0;
  13234. let s = 0;
  13235. const l = (min + max) / 2;
  13236. const chroma = max - min;
  13237. if (chroma > 0) {
  13238. s = Math.min((l <= 0.5 ? chroma / (2 * l) : chroma / (2 - (2 * l))), 1);
  13239. switch (max) {
  13240. case r:
  13241. h = (g - b) / chroma + (g < b ? 6 : 0);
  13242. break;
  13243. case g:
  13244. h = (b - r) / chroma + 2;
  13245. break;
  13246. case b:
  13247. h = (r - g) / chroma + 4;
  13248. break;
  13249. }
  13250. h *= 60;
  13251. h = Math.round(h);
  13252. }
  13253. return new HSLA(h, s, l, a);
  13254. }
  13255. static _hue2rgb(p, q, t) {
  13256. if (t < 0) {
  13257. t += 1;
  13258. }
  13259. if (t > 1) {
  13260. t -= 1;
  13261. }
  13262. if (t < 1 / 6) {
  13263. return p + (q - p) * 6 * t;
  13264. }
  13265. if (t < 1 / 2) {
  13266. return q;
  13267. }
  13268. if (t < 2 / 3) {
  13269. return p + (q - p) * (2 / 3 - t) * 6;
  13270. }
  13271. return p;
  13272. }
  13273. /**
  13274. * Converts an HSL color value to RGB. Conversion formula
  13275. * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
  13276. * Assumes h in the set [0, 360] s, and l are contained in the set [0, 1] and
  13277. * returns r, g, and b in the set [0, 255].
  13278. */
  13279. static toRGBA(hsla) {
  13280. const h = hsla.h / 360;
  13281. const { s, l, a } = hsla;
  13282. let r, g, b;
  13283. if (s === 0) {
  13284. r = g = b = l; // achromatic
  13285. }
  13286. else {
  13287. const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  13288. const p = 2 * l - q;
  13289. r = HSLA._hue2rgb(p, q, h + 1 / 3);
  13290. g = HSLA._hue2rgb(p, q, h);
  13291. b = HSLA._hue2rgb(p, q, h - 1 / 3);
  13292. }
  13293. return new RGBA(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
  13294. }
  13295. }
  13296. class HSVA {
  13297. constructor(h, s, v, a) {
  13298. this._hsvaBrand = undefined;
  13299. this.h = Math.max(Math.min(360, h), 0) | 0;
  13300. this.s = roundFloat(Math.max(Math.min(1, s), 0), 3);
  13301. this.v = roundFloat(Math.max(Math.min(1, v), 0), 3);
  13302. this.a = roundFloat(Math.max(Math.min(1, a), 0), 3);
  13303. }
  13304. static equals(a, b) {
  13305. return a.h === b.h && a.s === b.s && a.v === b.v && a.a === b.a;
  13306. }
  13307. // from http://www.rapidtables.com/convert/color/rgb-to-hsv.htm
  13308. static fromRGBA(rgba) {
  13309. const r = rgba.r / 255;
  13310. const g = rgba.g / 255;
  13311. const b = rgba.b / 255;
  13312. const cmax = Math.max(r, g, b);
  13313. const cmin = Math.min(r, g, b);
  13314. const delta = cmax - cmin;
  13315. const s = cmax === 0 ? 0 : (delta / cmax);
  13316. let m;
  13317. if (delta === 0) {
  13318. m = 0;
  13319. }
  13320. else if (cmax === r) {
  13321. m = ((((g - b) / delta) % 6) + 6) % 6;
  13322. }
  13323. else if (cmax === g) {
  13324. m = ((b - r) / delta) + 2;
  13325. }
  13326. else {
  13327. m = ((r - g) / delta) + 4;
  13328. }
  13329. return new HSVA(Math.round(m * 60), s, cmax, rgba.a);
  13330. }
  13331. // from http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
  13332. static toRGBA(hsva) {
  13333. const { h, s, v, a } = hsva;
  13334. const c = v * s;
  13335. const x = c * (1 - Math.abs((h / 60) % 2 - 1));
  13336. const m = v - c;
  13337. let [r, g, b] = [0, 0, 0];
  13338. if (h < 60) {
  13339. r = c;
  13340. g = x;
  13341. }
  13342. else if (h < 120) {
  13343. r = x;
  13344. g = c;
  13345. }
  13346. else if (h < 180) {
  13347. g = c;
  13348. b = x;
  13349. }
  13350. else if (h < 240) {
  13351. g = x;
  13352. b = c;
  13353. }
  13354. else if (h < 300) {
  13355. r = x;
  13356. b = c;
  13357. }
  13358. else if (h <= 360) {
  13359. r = c;
  13360. b = x;
  13361. }
  13362. r = Math.round((r + m) * 255);
  13363. g = Math.round((g + m) * 255);
  13364. b = Math.round((b + m) * 255);
  13365. return new RGBA(r, g, b, a);
  13366. }
  13367. }
  13368. class Color {
  13369. static fromHex(hex) {
  13370. return Color.Format.CSS.parseHex(hex) || Color.red;
  13371. }
  13372. static equals(a, b) {
  13373. if (!a && !b) {
  13374. return true;
  13375. }
  13376. if (!a || !b) {
  13377. return false;
  13378. }
  13379. return a.equals(b);
  13380. }
  13381. get hsla() {
  13382. if (this._hsla) {
  13383. return this._hsla;
  13384. }
  13385. else {
  13386. return HSLA.fromRGBA(this.rgba);
  13387. }
  13388. }
  13389. get hsva() {
  13390. if (this._hsva) {
  13391. return this._hsva;
  13392. }
  13393. return HSVA.fromRGBA(this.rgba);
  13394. }
  13395. constructor(arg) {
  13396. if (!arg) {
  13397. throw new Error('Color needs a value');
  13398. }
  13399. else if (arg instanceof RGBA) {
  13400. this.rgba = arg;
  13401. }
  13402. else if (arg instanceof HSLA) {
  13403. this._hsla = arg;
  13404. this.rgba = HSLA.toRGBA(arg);
  13405. }
  13406. else if (arg instanceof HSVA) {
  13407. this._hsva = arg;
  13408. this.rgba = HSVA.toRGBA(arg);
  13409. }
  13410. else {
  13411. throw new Error('Invalid color ctor argument');
  13412. }
  13413. }
  13414. equals(other) {
  13415. return !!other && RGBA.equals(this.rgba, other.rgba) && HSLA.equals(this.hsla, other.hsla) && HSVA.equals(this.hsva, other.hsva);
  13416. }
  13417. /**
  13418. * http://www.w3.org/TR/WCAG20/#relativeluminancedef
  13419. * Returns the number in the set [0, 1]. O => Darkest Black. 1 => Lightest white.
  13420. */
  13421. getRelativeLuminance() {
  13422. const R = Color._relativeLuminanceForComponent(this.rgba.r);
  13423. const G = Color._relativeLuminanceForComponent(this.rgba.g);
  13424. const B = Color._relativeLuminanceForComponent(this.rgba.b);
  13425. const luminance = 0.2126 * R + 0.7152 * G + 0.0722 * B;
  13426. return roundFloat(luminance, 4);
  13427. }
  13428. static _relativeLuminanceForComponent(color) {
  13429. const c = color / 255;
  13430. return (c <= 0.03928) ? c / 12.92 : Math.pow(((c + 0.055) / 1.055), 2.4);
  13431. }
  13432. /**
  13433. * http://24ways.org/2010/calculating-color-contrast
  13434. * Return 'true' if lighter color otherwise 'false'
  13435. */
  13436. isLighter() {
  13437. const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000;
  13438. return yiq >= 128;
  13439. }
  13440. isLighterThan(another) {
  13441. const lum1 = this.getRelativeLuminance();
  13442. const lum2 = another.getRelativeLuminance();
  13443. return lum1 > lum2;
  13444. }
  13445. isDarkerThan(another) {
  13446. const lum1 = this.getRelativeLuminance();
  13447. const lum2 = another.getRelativeLuminance();
  13448. return lum1 < lum2;
  13449. }
  13450. lighten(factor) {
  13451. return new Color(new HSLA(this.hsla.h, this.hsla.s, this.hsla.l + this.hsla.l * factor, this.hsla.a));
  13452. }
  13453. darken(factor) {
  13454. return new Color(new HSLA(this.hsla.h, this.hsla.s, this.hsla.l - this.hsla.l * factor, this.hsla.a));
  13455. }
  13456. transparent(factor) {
  13457. const { r, g, b, a } = this.rgba;
  13458. return new Color(new RGBA(r, g, b, a * factor));
  13459. }
  13460. isTransparent() {
  13461. return this.rgba.a === 0;
  13462. }
  13463. isOpaque() {
  13464. return this.rgba.a === 1;
  13465. }
  13466. opposite() {
  13467. return new Color(new RGBA(255 - this.rgba.r, 255 - this.rgba.g, 255 - this.rgba.b, this.rgba.a));
  13468. }
  13469. makeOpaque(opaqueBackground) {
  13470. if (this.isOpaque() || opaqueBackground.rgba.a !== 1) {
  13471. // only allow to blend onto a non-opaque color onto a opaque color
  13472. return this;
  13473. }
  13474. const { r, g, b, a } = this.rgba;
  13475. // https://stackoverflow.com/questions/12228548/finding-equivalent-color-with-opacity
  13476. return new Color(new RGBA(opaqueBackground.rgba.r - a * (opaqueBackground.rgba.r - r), opaqueBackground.rgba.g - a * (opaqueBackground.rgba.g - g), opaqueBackground.rgba.b - a * (opaqueBackground.rgba.b - b), 1));
  13477. }
  13478. toString() {
  13479. if (!this._toString) {
  13480. this._toString = Color.Format.CSS.format(this);
  13481. }
  13482. return this._toString;
  13483. }
  13484. static getLighterColor(of, relative, factor) {
  13485. if (of.isLighterThan(relative)) {
  13486. return of;
  13487. }
  13488. factor = factor ? factor : 0.5;
  13489. const lum1 = of.getRelativeLuminance();
  13490. const lum2 = relative.getRelativeLuminance();
  13491. factor = factor * (lum2 - lum1) / lum2;
  13492. return of.lighten(factor);
  13493. }
  13494. static getDarkerColor(of, relative, factor) {
  13495. if (of.isDarkerThan(relative)) {
  13496. return of;
  13497. }
  13498. factor = factor ? factor : 0.5;
  13499. const lum1 = of.getRelativeLuminance();
  13500. const lum2 = relative.getRelativeLuminance();
  13501. factor = factor * (lum1 - lum2) / lum1;
  13502. return of.darken(factor);
  13503. }
  13504. static { this.white = new Color(new RGBA(255, 255, 255, 1)); }
  13505. static { this.black = new Color(new RGBA(0, 0, 0, 1)); }
  13506. static { this.red = new Color(new RGBA(255, 0, 0, 1)); }
  13507. static { this.blue = new Color(new RGBA(0, 0, 255, 1)); }
  13508. static { this.green = new Color(new RGBA(0, 255, 0, 1)); }
  13509. static { this.cyan = new Color(new RGBA(0, 255, 255, 1)); }
  13510. static { this.lightgrey = new Color(new RGBA(211, 211, 211, 1)); }
  13511. static { this.transparent = new Color(new RGBA(0, 0, 0, 0)); }
  13512. }
  13513. (function (Color) {
  13514. (function (Format) {
  13515. (function (CSS) {
  13516. function formatRGB(color) {
  13517. if (color.rgba.a === 1) {
  13518. return `rgb(${color.rgba.r}, ${color.rgba.g}, ${color.rgba.b})`;
  13519. }
  13520. return Color.Format.CSS.formatRGBA(color);
  13521. }
  13522. CSS.formatRGB = formatRGB;
  13523. function formatRGBA(color) {
  13524. return `rgba(${color.rgba.r}, ${color.rgba.g}, ${color.rgba.b}, ${+(color.rgba.a).toFixed(2)})`;
  13525. }
  13526. CSS.formatRGBA = formatRGBA;
  13527. function formatHSL(color) {
  13528. if (color.hsla.a === 1) {
  13529. return `hsl(${color.hsla.h}, ${(color.hsla.s * 100).toFixed(2)}%, ${(color.hsla.l * 100).toFixed(2)}%)`;
  13530. }
  13531. return Color.Format.CSS.formatHSLA(color);
  13532. }
  13533. CSS.formatHSL = formatHSL;
  13534. function formatHSLA(color) {
  13535. return `hsla(${color.hsla.h}, ${(color.hsla.s * 100).toFixed(2)}%, ${(color.hsla.l * 100).toFixed(2)}%, ${color.hsla.a.toFixed(2)})`;
  13536. }
  13537. CSS.formatHSLA = formatHSLA;
  13538. function _toTwoDigitHex(n) {
  13539. const r = n.toString(16);
  13540. return r.length !== 2 ? '0' + r : r;
  13541. }
  13542. /**
  13543. * Formats the color as #RRGGBB
  13544. */
  13545. function formatHex(color) {
  13546. return `#${_toTwoDigitHex(color.rgba.r)}${_toTwoDigitHex(color.rgba.g)}${_toTwoDigitHex(color.rgba.b)}`;
  13547. }
  13548. CSS.formatHex = formatHex;
  13549. /**
  13550. * Formats the color as #RRGGBBAA
  13551. * If 'compact' is set, colors without transparancy will be printed as #RRGGBB
  13552. */
  13553. function formatHexA(color, compact = false) {
  13554. if (compact && color.rgba.a === 1) {
  13555. return Color.Format.CSS.formatHex(color);
  13556. }
  13557. return `#${_toTwoDigitHex(color.rgba.r)}${_toTwoDigitHex(color.rgba.g)}${_toTwoDigitHex(color.rgba.b)}${_toTwoDigitHex(Math.round(color.rgba.a * 255))}`;
  13558. }
  13559. CSS.formatHexA = formatHexA;
  13560. /**
  13561. * The default format will use HEX if opaque and RGBA otherwise.
  13562. */
  13563. function format(color) {
  13564. if (color.isOpaque()) {
  13565. return Color.Format.CSS.formatHex(color);
  13566. }
  13567. return Color.Format.CSS.formatRGBA(color);
  13568. }
  13569. CSS.format = format;
  13570. /**
  13571. * Converts an Hex color value to a Color.
  13572. * returns r, g, and b are contained in the set [0, 255]
  13573. * @param hex string (#RGB, #RGBA, #RRGGBB or #RRGGBBAA).
  13574. */
  13575. function parseHex(hex) {
  13576. const length = hex.length;
  13577. if (length === 0) {
  13578. // Invalid color
  13579. return null;
  13580. }
  13581. if (hex.charCodeAt(0) !== 35 /* CharCode.Hash */) {
  13582. // Does not begin with a #
  13583. return null;
  13584. }
  13585. if (length === 7) {
  13586. // #RRGGBB format
  13587. const r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2));
  13588. const g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4));
  13589. const b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6));
  13590. return new Color(new RGBA(r, g, b, 1));
  13591. }
  13592. if (length === 9) {
  13593. // #RRGGBBAA format
  13594. const r = 16 * _parseHexDigit(hex.charCodeAt(1)) + _parseHexDigit(hex.charCodeAt(2));
  13595. const g = 16 * _parseHexDigit(hex.charCodeAt(3)) + _parseHexDigit(hex.charCodeAt(4));
  13596. const b = 16 * _parseHexDigit(hex.charCodeAt(5)) + _parseHexDigit(hex.charCodeAt(6));
  13597. const a = 16 * _parseHexDigit(hex.charCodeAt(7)) + _parseHexDigit(hex.charCodeAt(8));
  13598. return new Color(new RGBA(r, g, b, a / 255));
  13599. }
  13600. if (length === 4) {
  13601. // #RGB format
  13602. const r = _parseHexDigit(hex.charCodeAt(1));
  13603. const g = _parseHexDigit(hex.charCodeAt(2));
  13604. const b = _parseHexDigit(hex.charCodeAt(3));
  13605. return new Color(new RGBA(16 * r + r, 16 * g + g, 16 * b + b));
  13606. }
  13607. if (length === 5) {
  13608. // #RGBA format
  13609. const r = _parseHexDigit(hex.charCodeAt(1));
  13610. const g = _parseHexDigit(hex.charCodeAt(2));
  13611. const b = _parseHexDigit(hex.charCodeAt(3));
  13612. const a = _parseHexDigit(hex.charCodeAt(4));
  13613. return new Color(new RGBA(16 * r + r, 16 * g + g, 16 * b + b, (16 * a + a) / 255));
  13614. }
  13615. // Invalid color
  13616. return null;
  13617. }
  13618. CSS.parseHex = parseHex;
  13619. function _parseHexDigit(charCode) {
  13620. switch (charCode) {
  13621. case 48 /* CharCode.Digit0 */: return 0;
  13622. case 49 /* CharCode.Digit1 */: return 1;
  13623. case 50 /* CharCode.Digit2 */: return 2;
  13624. case 51 /* CharCode.Digit3 */: return 3;
  13625. case 52 /* CharCode.Digit4 */: return 4;
  13626. case 53 /* CharCode.Digit5 */: return 5;
  13627. case 54 /* CharCode.Digit6 */: return 6;
  13628. case 55 /* CharCode.Digit7 */: return 7;
  13629. case 56 /* CharCode.Digit8 */: return 8;
  13630. case 57 /* CharCode.Digit9 */: return 9;
  13631. case 97 /* CharCode.a */: return 10;
  13632. case 65 /* CharCode.A */: return 10;
  13633. case 98 /* CharCode.b */: return 11;
  13634. case 66 /* CharCode.B */: return 11;
  13635. case 99 /* CharCode.c */: return 12;
  13636. case 67 /* CharCode.C */: return 12;
  13637. case 100 /* CharCode.d */: return 13;
  13638. case 68 /* CharCode.D */: return 13;
  13639. case 101 /* CharCode.e */: return 14;
  13640. case 69 /* CharCode.E */: return 14;
  13641. case 102 /* CharCode.f */: return 15;
  13642. case 70 /* CharCode.F */: return 15;
  13643. }
  13644. return 0;
  13645. }
  13646. })(Format.CSS || (Format.CSS = {}));
  13647. })(Color.Format || (Color.Format = {}));
  13648. })(Color || (Color = {}));
  13649. /*---------------------------------------------------------------------------------------------
  13650. * Copyright (c) Microsoft Corporation. All rights reserved.
  13651. * Licensed under the MIT License. See License.txt in the project root for license information.
  13652. *--------------------------------------------------------------------------------------------*/
  13653. function _parseCaptureGroups(captureGroups) {
  13654. const values = [];
  13655. for (const captureGroup of captureGroups) {
  13656. const parsedNumber = Number(captureGroup);
  13657. if (parsedNumber || parsedNumber === 0 && captureGroup.replace(/\s/g, '') !== '') {
  13658. values.push(parsedNumber);
  13659. }
  13660. }
  13661. return values;
  13662. }
  13663. function _toIColor(r, g, b, a) {
  13664. return {
  13665. red: r / 255,
  13666. blue: b / 255,
  13667. green: g / 255,
  13668. alpha: a
  13669. };
  13670. }
  13671. function _findRange(model, match) {
  13672. const index = match.index;
  13673. const length = match[0].length;
  13674. if (!index) {
  13675. return;
  13676. }
  13677. const startPosition = model.positionAt(index);
  13678. const range = {
  13679. startLineNumber: startPosition.lineNumber,
  13680. startColumn: startPosition.column,
  13681. endLineNumber: startPosition.lineNumber,
  13682. endColumn: startPosition.column + length
  13683. };
  13684. return range;
  13685. }
  13686. function _findHexColorInformation(range, hexValue) {
  13687. if (!range) {
  13688. return;
  13689. }
  13690. const parsedHexColor = Color.Format.CSS.parseHex(hexValue);
  13691. if (!parsedHexColor) {
  13692. return;
  13693. }
  13694. return {
  13695. range: range,
  13696. color: _toIColor(parsedHexColor.rgba.r, parsedHexColor.rgba.g, parsedHexColor.rgba.b, parsedHexColor.rgba.a)
  13697. };
  13698. }
  13699. function _findRGBColorInformation(range, matches, isAlpha) {
  13700. if (!range || matches.length !== 1) {
  13701. return;
  13702. }
  13703. const match = matches[0];
  13704. const captureGroups = match.values();
  13705. const parsedRegex = _parseCaptureGroups(captureGroups);
  13706. return {
  13707. range: range,
  13708. color: _toIColor(parsedRegex[0], parsedRegex[1], parsedRegex[2], isAlpha ? parsedRegex[3] : 1)
  13709. };
  13710. }
  13711. function _findHSLColorInformation(range, matches, isAlpha) {
  13712. if (!range || matches.length !== 1) {
  13713. return;
  13714. }
  13715. const match = matches[0];
  13716. const captureGroups = match.values();
  13717. const parsedRegex = _parseCaptureGroups(captureGroups);
  13718. const colorEquivalent = new Color(new HSLA(parsedRegex[0], parsedRegex[1] / 100, parsedRegex[2] / 100, isAlpha ? parsedRegex[3] : 1));
  13719. return {
  13720. range: range,
  13721. color: _toIColor(colorEquivalent.rgba.r, colorEquivalent.rgba.g, colorEquivalent.rgba.b, colorEquivalent.rgba.a)
  13722. };
  13723. }
  13724. function _findMatches(model, regex) {
  13725. if (typeof model === 'string') {
  13726. return [...model.matchAll(regex)];
  13727. }
  13728. else {
  13729. return model.findMatches(regex);
  13730. }
  13731. }
  13732. function computeColors(model) {
  13733. const result = [];
  13734. // Early validation for RGB and HSL
  13735. const initialValidationRegex = /\b(rgb|rgba|hsl|hsla)(\([0-9\s,.\%]*\))|(#)([A-Fa-f0-9]{3})\b|(#)([A-Fa-f0-9]{4})\b|(#)([A-Fa-f0-9]{6})\b|(#)([A-Fa-f0-9]{8})\b/gm;
  13736. const initialValidationMatches = _findMatches(model, initialValidationRegex);
  13737. // Potential colors have been found, validate the parameters
  13738. if (initialValidationMatches.length > 0) {
  13739. for (const initialMatch of initialValidationMatches) {
  13740. const initialCaptureGroups = initialMatch.filter(captureGroup => captureGroup !== undefined);
  13741. const colorScheme = initialCaptureGroups[1];
  13742. const colorParameters = initialCaptureGroups[2];
  13743. if (!colorParameters) {
  13744. continue;
  13745. }
  13746. let colorInformation;
  13747. if (colorScheme === 'rgb') {
  13748. const regexParameters = /^\(\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*\)$/gm;
  13749. colorInformation = _findRGBColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), false);
  13750. }
  13751. else if (colorScheme === 'rgba') {
  13752. const regexParameters = /^\(\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(0[.][0-9]+|[.][0-9]+|[01][.]|[01])\s*\)$/gm;
  13753. colorInformation = _findRGBColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), true);
  13754. }
  13755. else if (colorScheme === 'hsl') {
  13756. const regexParameters = /^\(\s*(36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])\s*,\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*,\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*\)$/gm;
  13757. colorInformation = _findHSLColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), false);
  13758. }
  13759. else if (colorScheme === 'hsla') {
  13760. const regexParameters = /^\(\s*(36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])\s*,\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*,\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*,\s*(0[.][0-9]+|[.][0-9]+|[01][.]|[01])\s*\)$/gm;
  13761. colorInformation = _findHSLColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), true);
  13762. }
  13763. else if (colorScheme === '#') {
  13764. colorInformation = _findHexColorInformation(_findRange(model, initialMatch), colorScheme + colorParameters);
  13765. }
  13766. if (colorInformation) {
  13767. result.push(colorInformation);
  13768. }
  13769. }
  13770. }
  13771. return result;
  13772. }
  13773. /**
  13774. * Returns an array of all default document colors in the provided document
  13775. */
  13776. function computeDefaultDocumentColors(model) {
  13777. if (!model || typeof model.getValue !== 'function' || typeof model.positionAt !== 'function') {
  13778. // Unknown caller!
  13779. return [];
  13780. }
  13781. return computeColors(model);
  13782. }
  13783. /*---------------------------------------------------------------------------------------------
  13784. * Copyright (c) Microsoft Corporation. All rights reserved.
  13785. * Licensed under the MIT License. See License.txt in the project root for license information.
  13786. *--------------------------------------------------------------------------------------------*/
  13787. const markRegex = new RegExp('\\bMARK:\\s*(.*)$', 'd');
  13788. const trimDashesRegex = /^-+|-+$/g;
  13789. /**
  13790. * Find section headers in the model.
  13791. *
  13792. * @param model the text model to search in
  13793. * @param options options to search with
  13794. * @returns an array of section headers
  13795. */
  13796. function findSectionHeaders(model, options) {
  13797. let headers = [];
  13798. if (options.findRegionSectionHeaders && options.foldingRules?.markers) {
  13799. const regionHeaders = collectRegionHeaders(model, options);
  13800. headers = headers.concat(regionHeaders);
  13801. }
  13802. if (options.findMarkSectionHeaders) {
  13803. const markHeaders = collectMarkHeaders(model);
  13804. headers = headers.concat(markHeaders);
  13805. }
  13806. return headers;
  13807. }
  13808. function collectRegionHeaders(model, options) {
  13809. const regionHeaders = [];
  13810. const endLineNumber = model.getLineCount();
  13811. for (let lineNumber = 1; lineNumber <= endLineNumber; lineNumber++) {
  13812. const lineContent = model.getLineContent(lineNumber);
  13813. const match = lineContent.match(options.foldingRules.markers.start);
  13814. if (match) {
  13815. const range = { startLineNumber: lineNumber, startColumn: match[0].length + 1, endLineNumber: lineNumber, endColumn: lineContent.length + 1 };
  13816. if (range.endColumn > range.startColumn) {
  13817. const sectionHeader = {
  13818. range,
  13819. ...getHeaderText(lineContent.substring(match[0].length)),
  13820. shouldBeInComments: false
  13821. };
  13822. if (sectionHeader.text || sectionHeader.hasSeparatorLine) {
  13823. regionHeaders.push(sectionHeader);
  13824. }
  13825. }
  13826. }
  13827. }
  13828. return regionHeaders;
  13829. }
  13830. function collectMarkHeaders(model) {
  13831. const markHeaders = [];
  13832. const endLineNumber = model.getLineCount();
  13833. for (let lineNumber = 1; lineNumber <= endLineNumber; lineNumber++) {
  13834. const lineContent = model.getLineContent(lineNumber);
  13835. addMarkHeaderIfFound(lineContent, lineNumber, markHeaders);
  13836. }
  13837. return markHeaders;
  13838. }
  13839. function addMarkHeaderIfFound(lineContent, lineNumber, sectionHeaders) {
  13840. markRegex.lastIndex = 0;
  13841. const match = markRegex.exec(lineContent);
  13842. if (match) {
  13843. const column = match.indices[1][0] + 1;
  13844. const endColumn = match.indices[1][1] + 1;
  13845. const range = { startLineNumber: lineNumber, startColumn: column, endLineNumber: lineNumber, endColumn: endColumn };
  13846. if (range.endColumn > range.startColumn) {
  13847. const sectionHeader = {
  13848. range,
  13849. ...getHeaderText(match[1]),
  13850. shouldBeInComments: true
  13851. };
  13852. if (sectionHeader.text || sectionHeader.hasSeparatorLine) {
  13853. sectionHeaders.push(sectionHeader);
  13854. }
  13855. }
  13856. }
  13857. }
  13858. function getHeaderText(text) {
  13859. text = text.trim();
  13860. const hasSeparatorLine = text.startsWith('-');
  13861. text = text.replace(trimDashesRegex, '');
  13862. return { text, hasSeparatorLine };
  13863. }
  13864. /*---------------------------------------------------------------------------------------------
  13865. * Copyright (c) Microsoft Corporation. All rights reserved.
  13866. * Licensed under the MIT License. See License.txt in the project root for license information.
  13867. *--------------------------------------------------------------------------------------------*/
  13868. //#endregion
  13869. //#region Promises
  13870. var Promises;
  13871. (function (Promises) {
  13872. /**
  13873. * A drop-in replacement for `Promise.all` with the only difference
  13874. * that the method awaits every promise to either fulfill or reject.
  13875. *
  13876. * Similar to `Promise.all`, only the first error will be returned
  13877. * if any.
  13878. */
  13879. async function settled(promises) {
  13880. let firstError = undefined;
  13881. const result = await Promise.all(promises.map(promise => promise.then(value => value, error => {
  13882. if (!firstError) {
  13883. firstError = error;
  13884. }
  13885. return undefined; // do not rethrow so that other promises can settle
  13886. })));
  13887. if (typeof firstError !== 'undefined') {
  13888. throw firstError;
  13889. }
  13890. return result; // cast is needed and protected by the `throw` above
  13891. }
  13892. Promises.settled = settled;
  13893. /**
  13894. * A helper to create a new `Promise<T>` with a body that is a promise
  13895. * itself. By default, an error that raises from the async body will
  13896. * end up as a unhandled rejection, so this utility properly awaits the
  13897. * body and rejects the promise as a normal promise does without async
  13898. * body.
  13899. *
  13900. * This method should only be used in rare cases where otherwise `async`
  13901. * cannot be used (e.g. when callbacks are involved that require this).
  13902. */
  13903. function withAsyncBody(bodyFn) {
  13904. // eslint-disable-next-line no-async-promise-executor
  13905. return new Promise(async (resolve, reject) => {
  13906. try {
  13907. await bodyFn(resolve, reject);
  13908. }
  13909. catch (error) {
  13910. reject(error);
  13911. }
  13912. });
  13913. }
  13914. Promises.withAsyncBody = withAsyncBody;
  13915. })(Promises || (Promises = {}));
  13916. /**
  13917. * A rich implementation for an `AsyncIterable<T>`.
  13918. */
  13919. class AsyncIterableObject {
  13920. static fromArray(items) {
  13921. return new AsyncIterableObject((writer) => {
  13922. writer.emitMany(items);
  13923. });
  13924. }
  13925. static fromPromise(promise) {
  13926. return new AsyncIterableObject(async (emitter) => {
  13927. emitter.emitMany(await promise);
  13928. });
  13929. }
  13930. static fromPromises(promises) {
  13931. return new AsyncIterableObject(async (emitter) => {
  13932. await Promise.all(promises.map(async (p) => emitter.emitOne(await p)));
  13933. });
  13934. }
  13935. static merge(iterables) {
  13936. return new AsyncIterableObject(async (emitter) => {
  13937. await Promise.all(iterables.map(async (iterable) => {
  13938. for await (const item of iterable) {
  13939. emitter.emitOne(item);
  13940. }
  13941. }));
  13942. });
  13943. }
  13944. static { this.EMPTY = AsyncIterableObject.fromArray([]); }
  13945. constructor(executor, onReturn) {
  13946. this._state = 0 /* AsyncIterableSourceState.Initial */;
  13947. this._results = [];
  13948. this._error = null;
  13949. this._onReturn = onReturn;
  13950. this._onStateChanged = new Emitter();
  13951. queueMicrotask(async () => {
  13952. const writer = {
  13953. emitOne: (item) => this.emitOne(item),
  13954. emitMany: (items) => this.emitMany(items),
  13955. reject: (error) => this.reject(error)
  13956. };
  13957. try {
  13958. await Promise.resolve(executor(writer));
  13959. this.resolve();
  13960. }
  13961. catch (err) {
  13962. this.reject(err);
  13963. }
  13964. finally {
  13965. writer.emitOne = undefined;
  13966. writer.emitMany = undefined;
  13967. writer.reject = undefined;
  13968. }
  13969. });
  13970. }
  13971. [Symbol.asyncIterator]() {
  13972. let i = 0;
  13973. return {
  13974. next: async () => {
  13975. do {
  13976. if (this._state === 2 /* AsyncIterableSourceState.DoneError */) {
  13977. throw this._error;
  13978. }
  13979. if (i < this._results.length) {
  13980. return { done: false, value: this._results[i++] };
  13981. }
  13982. if (this._state === 1 /* AsyncIterableSourceState.DoneOK */) {
  13983. return { done: true, value: undefined };
  13984. }
  13985. await Event.toPromise(this._onStateChanged.event);
  13986. } while (true);
  13987. },
  13988. return: async () => {
  13989. this._onReturn?.();
  13990. return { done: true, value: undefined };
  13991. }
  13992. };
  13993. }
  13994. static map(iterable, mapFn) {
  13995. return new AsyncIterableObject(async (emitter) => {
  13996. for await (const item of iterable) {
  13997. emitter.emitOne(mapFn(item));
  13998. }
  13999. });
  14000. }
  14001. map(mapFn) {
  14002. return AsyncIterableObject.map(this, mapFn);
  14003. }
  14004. static filter(iterable, filterFn) {
  14005. return new AsyncIterableObject(async (emitter) => {
  14006. for await (const item of iterable) {
  14007. if (filterFn(item)) {
  14008. emitter.emitOne(item);
  14009. }
  14010. }
  14011. });
  14012. }
  14013. filter(filterFn) {
  14014. return AsyncIterableObject.filter(this, filterFn);
  14015. }
  14016. static coalesce(iterable) {
  14017. return AsyncIterableObject.filter(iterable, item => !!item);
  14018. }
  14019. coalesce() {
  14020. return AsyncIterableObject.coalesce(this);
  14021. }
  14022. static async toPromise(iterable) {
  14023. const result = [];
  14024. for await (const item of iterable) {
  14025. result.push(item);
  14026. }
  14027. return result;
  14028. }
  14029. toPromise() {
  14030. return AsyncIterableObject.toPromise(this);
  14031. }
  14032. /**
  14033. * The value will be appended at the end.
  14034. *
  14035. * **NOTE** If `resolve()` or `reject()` have already been called, this method has no effect.
  14036. */
  14037. emitOne(value) {
  14038. if (this._state !== 0 /* AsyncIterableSourceState.Initial */) {
  14039. return;
  14040. }
  14041. // it is important to add new values at the end,
  14042. // as we may have iterators already running on the array
  14043. this._results.push(value);
  14044. this._onStateChanged.fire();
  14045. }
  14046. /**
  14047. * The values will be appended at the end.
  14048. *
  14049. * **NOTE** If `resolve()` or `reject()` have already been called, this method has no effect.
  14050. */
  14051. emitMany(values) {
  14052. if (this._state !== 0 /* AsyncIterableSourceState.Initial */) {
  14053. return;
  14054. }
  14055. // it is important to add new values at the end,
  14056. // as we may have iterators already running on the array
  14057. this._results = this._results.concat(values);
  14058. this._onStateChanged.fire();
  14059. }
  14060. /**
  14061. * Calling `resolve()` will mark the result array as complete.
  14062. *
  14063. * **NOTE** `resolve()` must be called, otherwise all consumers of this iterable will hang indefinitely, similar to a non-resolved promise.
  14064. * **NOTE** If `resolve()` or `reject()` have already been called, this method has no effect.
  14065. */
  14066. resolve() {
  14067. if (this._state !== 0 /* AsyncIterableSourceState.Initial */) {
  14068. return;
  14069. }
  14070. this._state = 1 /* AsyncIterableSourceState.DoneOK */;
  14071. this._onStateChanged.fire();
  14072. }
  14073. /**
  14074. * Writing an error will permanently invalidate this iterable.
  14075. * The current users will receive an error thrown, as will all future users.
  14076. *
  14077. * **NOTE** If `resolve()` or `reject()` have already been called, this method has no effect.
  14078. */
  14079. reject(error) {
  14080. if (this._state !== 0 /* AsyncIterableSourceState.Initial */) {
  14081. return;
  14082. }
  14083. this._state = 2 /* AsyncIterableSourceState.DoneError */;
  14084. this._error = error;
  14085. this._onStateChanged.fire();
  14086. }
  14087. }
  14088. //#endregion
  14089. /*---------------------------------------------------------------------------------------------
  14090. * Copyright (c) Microsoft Corporation. All rights reserved.
  14091. * Licensed under the MIT License. See License.txt in the project root for license information.
  14092. *--------------------------------------------------------------------------------------------*/
  14093. class PrefixSumComputer {
  14094. constructor(values) {
  14095. this.values = values;
  14096. this.prefixSum = new Uint32Array(values.length);
  14097. this.prefixSumValidIndex = new Int32Array(1);
  14098. this.prefixSumValidIndex[0] = -1;
  14099. }
  14100. insertValues(insertIndex, insertValues) {
  14101. insertIndex = toUint32(insertIndex);
  14102. const oldValues = this.values;
  14103. const oldPrefixSum = this.prefixSum;
  14104. const insertValuesLen = insertValues.length;
  14105. if (insertValuesLen === 0) {
  14106. return false;
  14107. }
  14108. this.values = new Uint32Array(oldValues.length + insertValuesLen);
  14109. this.values.set(oldValues.subarray(0, insertIndex), 0);
  14110. this.values.set(oldValues.subarray(insertIndex), insertIndex + insertValuesLen);
  14111. this.values.set(insertValues, insertIndex);
  14112. if (insertIndex - 1 < this.prefixSumValidIndex[0]) {
  14113. this.prefixSumValidIndex[0] = insertIndex - 1;
  14114. }
  14115. this.prefixSum = new Uint32Array(this.values.length);
  14116. if (this.prefixSumValidIndex[0] >= 0) {
  14117. this.prefixSum.set(oldPrefixSum.subarray(0, this.prefixSumValidIndex[0] + 1));
  14118. }
  14119. return true;
  14120. }
  14121. setValue(index, value) {
  14122. index = toUint32(index);
  14123. value = toUint32(value);
  14124. if (this.values[index] === value) {
  14125. return false;
  14126. }
  14127. this.values[index] = value;
  14128. if (index - 1 < this.prefixSumValidIndex[0]) {
  14129. this.prefixSumValidIndex[0] = index - 1;
  14130. }
  14131. return true;
  14132. }
  14133. removeValues(startIndex, count) {
  14134. startIndex = toUint32(startIndex);
  14135. count = toUint32(count);
  14136. const oldValues = this.values;
  14137. const oldPrefixSum = this.prefixSum;
  14138. if (startIndex >= oldValues.length) {
  14139. return false;
  14140. }
  14141. const maxCount = oldValues.length - startIndex;
  14142. if (count >= maxCount) {
  14143. count = maxCount;
  14144. }
  14145. if (count === 0) {
  14146. return false;
  14147. }
  14148. this.values = new Uint32Array(oldValues.length - count);
  14149. this.values.set(oldValues.subarray(0, startIndex), 0);
  14150. this.values.set(oldValues.subarray(startIndex + count), startIndex);
  14151. this.prefixSum = new Uint32Array(this.values.length);
  14152. if (startIndex - 1 < this.prefixSumValidIndex[0]) {
  14153. this.prefixSumValidIndex[0] = startIndex - 1;
  14154. }
  14155. if (this.prefixSumValidIndex[0] >= 0) {
  14156. this.prefixSum.set(oldPrefixSum.subarray(0, this.prefixSumValidIndex[0] + 1));
  14157. }
  14158. return true;
  14159. }
  14160. getTotalSum() {
  14161. if (this.values.length === 0) {
  14162. return 0;
  14163. }
  14164. return this._getPrefixSum(this.values.length - 1);
  14165. }
  14166. /**
  14167. * Returns the sum of the first `index + 1` many items.
  14168. * @returns `SUM(0 <= j <= index, values[j])`.
  14169. */
  14170. getPrefixSum(index) {
  14171. if (index < 0) {
  14172. return 0;
  14173. }
  14174. index = toUint32(index);
  14175. return this._getPrefixSum(index);
  14176. }
  14177. _getPrefixSum(index) {
  14178. if (index <= this.prefixSumValidIndex[0]) {
  14179. return this.prefixSum[index];
  14180. }
  14181. let startIndex = this.prefixSumValidIndex[0] + 1;
  14182. if (startIndex === 0) {
  14183. this.prefixSum[0] = this.values[0];
  14184. startIndex++;
  14185. }
  14186. if (index >= this.values.length) {
  14187. index = this.values.length - 1;
  14188. }
  14189. for (let i = startIndex; i <= index; i++) {
  14190. this.prefixSum[i] = this.prefixSum[i - 1] + this.values[i];
  14191. }
  14192. this.prefixSumValidIndex[0] = Math.max(this.prefixSumValidIndex[0], index);
  14193. return this.prefixSum[index];
  14194. }
  14195. getIndexOf(sum) {
  14196. sum = Math.floor(sum);
  14197. // Compute all sums (to get a fully valid prefixSum)
  14198. this.getTotalSum();
  14199. let low = 0;
  14200. let high = this.values.length - 1;
  14201. let mid = 0;
  14202. let midStop = 0;
  14203. let midStart = 0;
  14204. while (low <= high) {
  14205. mid = low + ((high - low) / 2) | 0;
  14206. midStop = this.prefixSum[mid];
  14207. midStart = midStop - this.values[mid];
  14208. if (sum < midStart) {
  14209. high = mid - 1;
  14210. }
  14211. else if (sum >= midStop) {
  14212. low = mid + 1;
  14213. }
  14214. else {
  14215. break;
  14216. }
  14217. }
  14218. return new PrefixSumIndexOfResult(mid, sum - midStart);
  14219. }
  14220. }
  14221. class PrefixSumIndexOfResult {
  14222. constructor(index, remainder) {
  14223. this.index = index;
  14224. this.remainder = remainder;
  14225. this._prefixSumIndexOfResultBrand = undefined;
  14226. this.index = index;
  14227. this.remainder = remainder;
  14228. }
  14229. }
  14230. /*---------------------------------------------------------------------------------------------
  14231. * Copyright (c) Microsoft Corporation. All rights reserved.
  14232. * Licensed under the MIT License. See License.txt in the project root for license information.
  14233. *--------------------------------------------------------------------------------------------*/
  14234. class MirrorTextModel {
  14235. constructor(uri, lines, eol, versionId) {
  14236. this._uri = uri;
  14237. this._lines = lines;
  14238. this._eol = eol;
  14239. this._versionId = versionId;
  14240. this._lineStarts = null;
  14241. this._cachedTextValue = null;
  14242. }
  14243. dispose() {
  14244. this._lines.length = 0;
  14245. }
  14246. get version() {
  14247. return this._versionId;
  14248. }
  14249. getText() {
  14250. if (this._cachedTextValue === null) {
  14251. this._cachedTextValue = this._lines.join(this._eol);
  14252. }
  14253. return this._cachedTextValue;
  14254. }
  14255. onEvents(e) {
  14256. if (e.eol && e.eol !== this._eol) {
  14257. this._eol = e.eol;
  14258. this._lineStarts = null;
  14259. }
  14260. // Update my lines
  14261. const changes = e.changes;
  14262. for (const change of changes) {
  14263. this._acceptDeleteRange(change.range);
  14264. this._acceptInsertText(new Position(change.range.startLineNumber, change.range.startColumn), change.text);
  14265. }
  14266. this._versionId = e.versionId;
  14267. this._cachedTextValue = null;
  14268. }
  14269. _ensureLineStarts() {
  14270. if (!this._lineStarts) {
  14271. const eolLength = this._eol.length;
  14272. const linesLength = this._lines.length;
  14273. const lineStartValues = new Uint32Array(linesLength);
  14274. for (let i = 0; i < linesLength; i++) {
  14275. lineStartValues[i] = this._lines[i].length + eolLength;
  14276. }
  14277. this._lineStarts = new PrefixSumComputer(lineStartValues);
  14278. }
  14279. }
  14280. /**
  14281. * All changes to a line's text go through this method
  14282. */
  14283. _setLineText(lineIndex, newValue) {
  14284. this._lines[lineIndex] = newValue;
  14285. if (this._lineStarts) {
  14286. // update prefix sum
  14287. this._lineStarts.setValue(lineIndex, this._lines[lineIndex].length + this._eol.length);
  14288. }
  14289. }
  14290. _acceptDeleteRange(range) {
  14291. if (range.startLineNumber === range.endLineNumber) {
  14292. if (range.startColumn === range.endColumn) {
  14293. // Nothing to delete
  14294. return;
  14295. }
  14296. // Delete text on the affected line
  14297. this._setLineText(range.startLineNumber - 1, this._lines[range.startLineNumber - 1].substring(0, range.startColumn - 1)
  14298. + this._lines[range.startLineNumber - 1].substring(range.endColumn - 1));
  14299. return;
  14300. }
  14301. // Take remaining text on last line and append it to remaining text on first line
  14302. this._setLineText(range.startLineNumber - 1, this._lines[range.startLineNumber - 1].substring(0, range.startColumn - 1)
  14303. + this._lines[range.endLineNumber - 1].substring(range.endColumn - 1));
  14304. // Delete middle lines
  14305. this._lines.splice(range.startLineNumber, range.endLineNumber - range.startLineNumber);
  14306. if (this._lineStarts) {
  14307. // update prefix sum
  14308. this._lineStarts.removeValues(range.startLineNumber, range.endLineNumber - range.startLineNumber);
  14309. }
  14310. }
  14311. _acceptInsertText(position, insertText) {
  14312. if (insertText.length === 0) {
  14313. // Nothing to insert
  14314. return;
  14315. }
  14316. const insertLines = splitLines(insertText);
  14317. if (insertLines.length === 1) {
  14318. // Inserting text on one line
  14319. this._setLineText(position.lineNumber - 1, this._lines[position.lineNumber - 1].substring(0, position.column - 1)
  14320. + insertLines[0]
  14321. + this._lines[position.lineNumber - 1].substring(position.column - 1));
  14322. return;
  14323. }
  14324. // Append overflowing text from first line to the end of text to insert
  14325. insertLines[insertLines.length - 1] += this._lines[position.lineNumber - 1].substring(position.column - 1);
  14326. // Delete overflowing text from first line and insert text on first line
  14327. this._setLineText(position.lineNumber - 1, this._lines[position.lineNumber - 1].substring(0, position.column - 1)
  14328. + insertLines[0]);
  14329. // Insert new lines & store lengths
  14330. const newLengths = new Uint32Array(insertLines.length - 1);
  14331. for (let i = 1; i < insertLines.length; i++) {
  14332. this._lines.splice(position.lineNumber + i - 1, 0, insertLines[i]);
  14333. newLengths[i - 1] = insertLines[i].length + this._eol.length;
  14334. }
  14335. if (this._lineStarts) {
  14336. // update prefix sum
  14337. this._lineStarts.insertValues(position.lineNumber, newLengths);
  14338. }
  14339. }
  14340. }
  14341. /*---------------------------------------------------------------------------------------------
  14342. * Copyright (c) Microsoft Corporation. All rights reserved.
  14343. * Licensed under the MIT License. See License.txt in the project root for license information.
  14344. *--------------------------------------------------------------------------------------------*/
  14345. class WorkerTextModelSyncServer {
  14346. constructor() {
  14347. this._models = Object.create(null);
  14348. }
  14349. getModel(uri) {
  14350. return this._models[uri];
  14351. }
  14352. getModels() {
  14353. const all = [];
  14354. Object.keys(this._models).forEach((key) => all.push(this._models[key]));
  14355. return all;
  14356. }
  14357. $acceptNewModel(data) {
  14358. this._models[data.url] = new MirrorModel(URI.parse(data.url), data.lines, data.EOL, data.versionId);
  14359. }
  14360. $acceptModelChanged(uri, e) {
  14361. if (!this._models[uri]) {
  14362. return;
  14363. }
  14364. const model = this._models[uri];
  14365. model.onEvents(e);
  14366. }
  14367. $acceptRemovedModel(uri) {
  14368. if (!this._models[uri]) {
  14369. return;
  14370. }
  14371. delete this._models[uri];
  14372. }
  14373. }
  14374. class MirrorModel extends MirrorTextModel {
  14375. get uri() {
  14376. return this._uri;
  14377. }
  14378. get eol() {
  14379. return this._eol;
  14380. }
  14381. getValue() {
  14382. return this.getText();
  14383. }
  14384. findMatches(regex) {
  14385. const matches = [];
  14386. for (let i = 0; i < this._lines.length; i++) {
  14387. const line = this._lines[i];
  14388. const offsetToAdd = this.offsetAt(new Position(i + 1, 1));
  14389. const iteratorOverMatches = line.matchAll(regex);
  14390. for (const match of iteratorOverMatches) {
  14391. if (match.index || match.index === 0) {
  14392. match.index = match.index + offsetToAdd;
  14393. }
  14394. matches.push(match);
  14395. }
  14396. }
  14397. return matches;
  14398. }
  14399. getLinesContent() {
  14400. return this._lines.slice(0);
  14401. }
  14402. getLineCount() {
  14403. return this._lines.length;
  14404. }
  14405. getLineContent(lineNumber) {
  14406. return this._lines[lineNumber - 1];
  14407. }
  14408. getWordAtPosition(position, wordDefinition) {
  14409. const wordAtText = getWordAtText(position.column, ensureValidWordDefinition(wordDefinition), this._lines[position.lineNumber - 1], 0);
  14410. if (wordAtText) {
  14411. return new Range(position.lineNumber, wordAtText.startColumn, position.lineNumber, wordAtText.endColumn);
  14412. }
  14413. return null;
  14414. }
  14415. words(wordDefinition) {
  14416. const lines = this._lines;
  14417. const wordenize = this._wordenize.bind(this);
  14418. let lineNumber = 0;
  14419. let lineText = '';
  14420. let wordRangesIdx = 0;
  14421. let wordRanges = [];
  14422. return {
  14423. *[Symbol.iterator]() {
  14424. while (true) {
  14425. if (wordRangesIdx < wordRanges.length) {
  14426. const value = lineText.substring(wordRanges[wordRangesIdx].start, wordRanges[wordRangesIdx].end);
  14427. wordRangesIdx += 1;
  14428. yield value;
  14429. }
  14430. else {
  14431. if (lineNumber < lines.length) {
  14432. lineText = lines[lineNumber];
  14433. wordRanges = wordenize(lineText, wordDefinition);
  14434. wordRangesIdx = 0;
  14435. lineNumber += 1;
  14436. }
  14437. else {
  14438. break;
  14439. }
  14440. }
  14441. }
  14442. }
  14443. };
  14444. }
  14445. getLineWords(lineNumber, wordDefinition) {
  14446. const content = this._lines[lineNumber - 1];
  14447. const ranges = this._wordenize(content, wordDefinition);
  14448. const words = [];
  14449. for (const range of ranges) {
  14450. words.push({
  14451. word: content.substring(range.start, range.end),
  14452. startColumn: range.start + 1,
  14453. endColumn: range.end + 1
  14454. });
  14455. }
  14456. return words;
  14457. }
  14458. _wordenize(content, wordDefinition) {
  14459. const result = [];
  14460. let match;
  14461. wordDefinition.lastIndex = 0; // reset lastIndex just to be sure
  14462. while (match = wordDefinition.exec(content)) {
  14463. if (match[0].length === 0) {
  14464. // it did match the empty string
  14465. break;
  14466. }
  14467. result.push({ start: match.index, end: match.index + match[0].length });
  14468. }
  14469. return result;
  14470. }
  14471. getValueInRange(range) {
  14472. range = this._validateRange(range);
  14473. if (range.startLineNumber === range.endLineNumber) {
  14474. return this._lines[range.startLineNumber - 1].substring(range.startColumn - 1, range.endColumn - 1);
  14475. }
  14476. const lineEnding = this._eol;
  14477. const startLineIndex = range.startLineNumber - 1;
  14478. const endLineIndex = range.endLineNumber - 1;
  14479. const resultLines = [];
  14480. resultLines.push(this._lines[startLineIndex].substring(range.startColumn - 1));
  14481. for (let i = startLineIndex + 1; i < endLineIndex; i++) {
  14482. resultLines.push(this._lines[i]);
  14483. }
  14484. resultLines.push(this._lines[endLineIndex].substring(0, range.endColumn - 1));
  14485. return resultLines.join(lineEnding);
  14486. }
  14487. offsetAt(position) {
  14488. position = this._validatePosition(position);
  14489. this._ensureLineStarts();
  14490. return this._lineStarts.getPrefixSum(position.lineNumber - 2) + (position.column - 1);
  14491. }
  14492. positionAt(offset) {
  14493. offset = Math.floor(offset);
  14494. offset = Math.max(0, offset);
  14495. this._ensureLineStarts();
  14496. const out = this._lineStarts.getIndexOf(offset);
  14497. const lineLength = this._lines[out.index].length;
  14498. // Ensure we return a valid position
  14499. return {
  14500. lineNumber: 1 + out.index,
  14501. column: 1 + Math.min(out.remainder, lineLength)
  14502. };
  14503. }
  14504. _validateRange(range) {
  14505. const start = this._validatePosition({ lineNumber: range.startLineNumber, column: range.startColumn });
  14506. const end = this._validatePosition({ lineNumber: range.endLineNumber, column: range.endColumn });
  14507. if (start.lineNumber !== range.startLineNumber
  14508. || start.column !== range.startColumn
  14509. || end.lineNumber !== range.endLineNumber
  14510. || end.column !== range.endColumn) {
  14511. return {
  14512. startLineNumber: start.lineNumber,
  14513. startColumn: start.column,
  14514. endLineNumber: end.lineNumber,
  14515. endColumn: end.column
  14516. };
  14517. }
  14518. return range;
  14519. }
  14520. _validatePosition(position) {
  14521. if (!Position.isIPosition(position)) {
  14522. throw new Error('bad position');
  14523. }
  14524. let { lineNumber, column } = position;
  14525. let hasChanged = false;
  14526. if (lineNumber < 1) {
  14527. lineNumber = 1;
  14528. column = 1;
  14529. hasChanged = true;
  14530. }
  14531. else if (lineNumber > this._lines.length) {
  14532. lineNumber = this._lines.length;
  14533. column = this._lines[lineNumber - 1].length + 1;
  14534. hasChanged = true;
  14535. }
  14536. else {
  14537. const maxCharacter = this._lines[lineNumber - 1].length + 1;
  14538. if (column < 1) {
  14539. column = 1;
  14540. hasChanged = true;
  14541. }
  14542. else if (column > maxCharacter) {
  14543. column = maxCharacter;
  14544. hasChanged = true;
  14545. }
  14546. }
  14547. if (!hasChanged) {
  14548. return position;
  14549. }
  14550. else {
  14551. return { lineNumber, column };
  14552. }
  14553. }
  14554. }
  14555. /*---------------------------------------------------------------------------------------------
  14556. * Copyright (c) Microsoft Corporation. All rights reserved.
  14557. * Licensed under the MIT License. See License.txt in the project root for license information.
  14558. *--------------------------------------------------------------------------------------------*/
  14559. /**
  14560. * @internal
  14561. */
  14562. class BaseEditorSimpleWorker {
  14563. constructor() {
  14564. this._workerTextModelSyncServer = new WorkerTextModelSyncServer();
  14565. }
  14566. dispose() {
  14567. }
  14568. _getModel(uri) {
  14569. return this._workerTextModelSyncServer.getModel(uri);
  14570. }
  14571. _getModels() {
  14572. return this._workerTextModelSyncServer.getModels();
  14573. }
  14574. $acceptNewModel(data) {
  14575. this._workerTextModelSyncServer.$acceptNewModel(data);
  14576. }
  14577. $acceptModelChanged(uri, e) {
  14578. this._workerTextModelSyncServer.$acceptModelChanged(uri, e);
  14579. }
  14580. $acceptRemovedModel(uri) {
  14581. this._workerTextModelSyncServer.$acceptRemovedModel(uri);
  14582. }
  14583. async $computeUnicodeHighlights(url, options, range) {
  14584. const model = this._getModel(url);
  14585. if (!model) {
  14586. return { ranges: [], hasMore: false, ambiguousCharacterCount: 0, invisibleCharacterCount: 0, nonBasicAsciiCharacterCount: 0 };
  14587. }
  14588. return UnicodeTextModelHighlighter.computeUnicodeHighlights(model, options, range);
  14589. }
  14590. async $findSectionHeaders(url, options) {
  14591. const model = this._getModel(url);
  14592. if (!model) {
  14593. return [];
  14594. }
  14595. return findSectionHeaders(model, options);
  14596. }
  14597. // ---- BEGIN diff --------------------------------------------------------------------------
  14598. async $computeDiff(originalUrl, modifiedUrl, options, algorithm) {
  14599. const original = this._getModel(originalUrl);
  14600. const modified = this._getModel(modifiedUrl);
  14601. if (!original || !modified) {
  14602. return null;
  14603. }
  14604. const result = EditorSimpleWorker.computeDiff(original, modified, options, algorithm);
  14605. return result;
  14606. }
  14607. static computeDiff(originalTextModel, modifiedTextModel, options, algorithm) {
  14608. const diffAlgorithm = algorithm === 'advanced' ? linesDiffComputers.getDefault() : linesDiffComputers.getLegacy();
  14609. const originalLines = originalTextModel.getLinesContent();
  14610. const modifiedLines = modifiedTextModel.getLinesContent();
  14611. const result = diffAlgorithm.computeDiff(originalLines, modifiedLines, options);
  14612. const identical = (result.changes.length > 0 ? false : this._modelsAreIdentical(originalTextModel, modifiedTextModel));
  14613. function getLineChanges(changes) {
  14614. return changes.map(m => ([m.original.startLineNumber, m.original.endLineNumberExclusive, m.modified.startLineNumber, m.modified.endLineNumberExclusive, m.innerChanges?.map(m => [
  14615. m.originalRange.startLineNumber,
  14616. m.originalRange.startColumn,
  14617. m.originalRange.endLineNumber,
  14618. m.originalRange.endColumn,
  14619. m.modifiedRange.startLineNumber,
  14620. m.modifiedRange.startColumn,
  14621. m.modifiedRange.endLineNumber,
  14622. m.modifiedRange.endColumn,
  14623. ])]));
  14624. }
  14625. return {
  14626. identical,
  14627. quitEarly: result.hitTimeout,
  14628. changes: getLineChanges(result.changes),
  14629. moves: result.moves.map(m => ([
  14630. m.lineRangeMapping.original.startLineNumber,
  14631. m.lineRangeMapping.original.endLineNumberExclusive,
  14632. m.lineRangeMapping.modified.startLineNumber,
  14633. m.lineRangeMapping.modified.endLineNumberExclusive,
  14634. getLineChanges(m.changes)
  14635. ])),
  14636. };
  14637. }
  14638. static _modelsAreIdentical(original, modified) {
  14639. const originalLineCount = original.getLineCount();
  14640. const modifiedLineCount = modified.getLineCount();
  14641. if (originalLineCount !== modifiedLineCount) {
  14642. return false;
  14643. }
  14644. for (let line = 1; line <= originalLineCount; line++) {
  14645. const originalLine = original.getLineContent(line);
  14646. const modifiedLine = modified.getLineContent(line);
  14647. if (originalLine !== modifiedLine) {
  14648. return false;
  14649. }
  14650. }
  14651. return true;
  14652. }
  14653. // ---- END diff --------------------------------------------------------------------------
  14654. // ---- BEGIN minimal edits ---------------------------------------------------------------
  14655. static { this._diffLimit = 100000; }
  14656. async $computeMoreMinimalEdits(modelUrl, edits, pretty) {
  14657. const model = this._getModel(modelUrl);
  14658. if (!model) {
  14659. return edits;
  14660. }
  14661. const result = [];
  14662. let lastEol = undefined;
  14663. edits = edits.slice(0).sort((a, b) => {
  14664. if (a.range && b.range) {
  14665. return Range.compareRangesUsingStarts(a.range, b.range);
  14666. }
  14667. // eol only changes should go to the end
  14668. const aRng = a.range ? 0 : 1;
  14669. const bRng = b.range ? 0 : 1;
  14670. return aRng - bRng;
  14671. });
  14672. // merge adjacent edits
  14673. let writeIndex = 0;
  14674. for (let readIndex = 1; readIndex < edits.length; readIndex++) {
  14675. if (Range.getEndPosition(edits[writeIndex].range).equals(Range.getStartPosition(edits[readIndex].range))) {
  14676. edits[writeIndex].range = Range.fromPositions(Range.getStartPosition(edits[writeIndex].range), Range.getEndPosition(edits[readIndex].range));
  14677. edits[writeIndex].text += edits[readIndex].text;
  14678. }
  14679. else {
  14680. writeIndex++;
  14681. edits[writeIndex] = edits[readIndex];
  14682. }
  14683. }
  14684. edits.length = writeIndex + 1;
  14685. for (let { range, text, eol } of edits) {
  14686. if (typeof eol === 'number') {
  14687. lastEol = eol;
  14688. }
  14689. if (Range.isEmpty(range) && !text) {
  14690. // empty change
  14691. continue;
  14692. }
  14693. const original = model.getValueInRange(range);
  14694. text = text.replace(/\r\n|\n|\r/g, model.eol);
  14695. if (original === text) {
  14696. // noop
  14697. continue;
  14698. }
  14699. // make sure diff won't take too long
  14700. if (Math.max(text.length, original.length) > EditorSimpleWorker._diffLimit) {
  14701. result.push({ range, text });
  14702. continue;
  14703. }
  14704. // compute diff between original and edit.text
  14705. const changes = stringDiff(original, text, pretty);
  14706. const editOffset = model.offsetAt(Range.lift(range).getStartPosition());
  14707. for (const change of changes) {
  14708. const start = model.positionAt(editOffset + change.originalStart);
  14709. const end = model.positionAt(editOffset + change.originalStart + change.originalLength);
  14710. const newEdit = {
  14711. text: text.substr(change.modifiedStart, change.modifiedLength),
  14712. range: { startLineNumber: start.lineNumber, startColumn: start.column, endLineNumber: end.lineNumber, endColumn: end.column }
  14713. };
  14714. if (model.getValueInRange(newEdit.range) !== newEdit.text) {
  14715. result.push(newEdit);
  14716. }
  14717. }
  14718. }
  14719. if (typeof lastEol === 'number') {
  14720. result.push({ eol: lastEol, text: '', range: { startLineNumber: 0, startColumn: 0, endLineNumber: 0, endColumn: 0 } });
  14721. }
  14722. return result;
  14723. }
  14724. // ---- END minimal edits ---------------------------------------------------------------
  14725. async $computeLinks(modelUrl) {
  14726. const model = this._getModel(modelUrl);
  14727. if (!model) {
  14728. return null;
  14729. }
  14730. return computeLinks(model);
  14731. }
  14732. // --- BEGIN default document colors -----------------------------------------------------------
  14733. async $computeDefaultDocumentColors(modelUrl) {
  14734. const model = this._getModel(modelUrl);
  14735. if (!model) {
  14736. return null;
  14737. }
  14738. return computeDefaultDocumentColors(model);
  14739. }
  14740. // ---- BEGIN suggest --------------------------------------------------------------------------
  14741. static { this._suggestionsLimit = 10000; }
  14742. async $textualSuggest(modelUrls, leadingWord, wordDef, wordDefFlags) {
  14743. const sw = new StopWatch();
  14744. const wordDefRegExp = new RegExp(wordDef, wordDefFlags);
  14745. const seen = new Set();
  14746. outer: for (const url of modelUrls) {
  14747. const model = this._getModel(url);
  14748. if (!model) {
  14749. continue;
  14750. }
  14751. for (const word of model.words(wordDefRegExp)) {
  14752. if (word === leadingWord || !isNaN(Number(word))) {
  14753. continue;
  14754. }
  14755. seen.add(word);
  14756. if (seen.size > EditorSimpleWorker._suggestionsLimit) {
  14757. break outer;
  14758. }
  14759. }
  14760. }
  14761. return { words: Array.from(seen), duration: sw.elapsed() };
  14762. }
  14763. // ---- END suggest --------------------------------------------------------------------------
  14764. //#region -- word ranges --
  14765. async $computeWordRanges(modelUrl, range, wordDef, wordDefFlags) {
  14766. const model = this._getModel(modelUrl);
  14767. if (!model) {
  14768. return Object.create(null);
  14769. }
  14770. const wordDefRegExp = new RegExp(wordDef, wordDefFlags);
  14771. const result = Object.create(null);
  14772. for (let line = range.startLineNumber; line < range.endLineNumber; line++) {
  14773. const words = model.getLineWords(line, wordDefRegExp);
  14774. for (const word of words) {
  14775. if (!isNaN(Number(word.word))) {
  14776. continue;
  14777. }
  14778. let array = result[word.word];
  14779. if (!array) {
  14780. array = [];
  14781. result[word.word] = array;
  14782. }
  14783. array.push({
  14784. startLineNumber: line,
  14785. startColumn: word.startColumn,
  14786. endLineNumber: line,
  14787. endColumn: word.endColumn
  14788. });
  14789. }
  14790. }
  14791. return result;
  14792. }
  14793. //#endregion
  14794. async $navigateValueSet(modelUrl, range, up, wordDef, wordDefFlags) {
  14795. const model = this._getModel(modelUrl);
  14796. if (!model) {
  14797. return null;
  14798. }
  14799. const wordDefRegExp = new RegExp(wordDef, wordDefFlags);
  14800. if (range.startColumn === range.endColumn) {
  14801. range = {
  14802. startLineNumber: range.startLineNumber,
  14803. startColumn: range.startColumn,
  14804. endLineNumber: range.endLineNumber,
  14805. endColumn: range.endColumn + 1
  14806. };
  14807. }
  14808. const selectionText = model.getValueInRange(range);
  14809. const wordRange = model.getWordAtPosition({ lineNumber: range.startLineNumber, column: range.startColumn }, wordDefRegExp);
  14810. if (!wordRange) {
  14811. return null;
  14812. }
  14813. const word = model.getValueInRange(wordRange);
  14814. const result = BasicInplaceReplace.INSTANCE.navigateValueSet(range, selectionText, wordRange, word, up);
  14815. return result;
  14816. }
  14817. }
  14818. /**
  14819. * @internal
  14820. */
  14821. class EditorSimpleWorker extends BaseEditorSimpleWorker {
  14822. constructor(_host, _foreignModuleFactory) {
  14823. super();
  14824. this._host = _host;
  14825. this._foreignModuleFactory = _foreignModuleFactory;
  14826. this._foreignModule = null;
  14827. }
  14828. async $ping() {
  14829. return 'pong';
  14830. }
  14831. // ---- BEGIN foreign module support --------------------------------------------------------------------------
  14832. $loadForeignModule(moduleId, createData, foreignHostMethods) {
  14833. const proxyMethodRequest = (method, args) => {
  14834. return this._host.$fhr(method, args);
  14835. };
  14836. const foreignHost = createProxyObject(foreignHostMethods, proxyMethodRequest);
  14837. const ctx = {
  14838. host: foreignHost,
  14839. getMirrorModels: () => {
  14840. return this._getModels();
  14841. }
  14842. };
  14843. if (this._foreignModuleFactory) {
  14844. this._foreignModule = this._foreignModuleFactory(ctx, createData);
  14845. // static foreing module
  14846. return Promise.resolve(getAllMethodNames(this._foreignModule));
  14847. }
  14848. return new Promise((resolve, reject) => {
  14849. const onModuleCallback = (foreignModule) => {
  14850. this._foreignModule = foreignModule.create(ctx, createData);
  14851. resolve(getAllMethodNames(this._foreignModule));
  14852. };
  14853. {
  14854. const url = FileAccess.asBrowserUri(`${moduleId}.js`).toString(true);
  14855. import(`${url}`).then(onModuleCallback).catch(reject);
  14856. }
  14857. });
  14858. }
  14859. // foreign method request
  14860. $fmr(method, args) {
  14861. if (!this._foreignModule || typeof this._foreignModule[method] !== 'function') {
  14862. return Promise.reject(new Error('Missing requestHandler or method: ' + method));
  14863. }
  14864. try {
  14865. return Promise.resolve(this._foreignModule[method].apply(this._foreignModule, args));
  14866. }
  14867. catch (e) {
  14868. return Promise.reject(e);
  14869. }
  14870. }
  14871. }
  14872. if (typeof importScripts === 'function') {
  14873. // Running in a web worker
  14874. globalThis.monaco = createMonacoBaseAPI();
  14875. }
  14876. /*---------------------------------------------------------------------------------------------
  14877. * Copyright (c) Microsoft Corporation. All rights reserved.
  14878. * Licensed under the MIT License. See License.txt in the project root for license information.
  14879. *--------------------------------------------------------------------------------------------*/
  14880. let initialized = false;
  14881. function initialize(foreignModule) {
  14882. if (initialized) {
  14883. return;
  14884. }
  14885. initialized = true;
  14886. const simpleWorker = new SimpleWorkerServer((msg) => {
  14887. globalThis.postMessage(msg);
  14888. }, (workerServer) => new EditorSimpleWorker(EditorWorkerHost.getChannel(workerServer), foreignModule));
  14889. globalThis.onmessage = (e) => {
  14890. simpleWorker.onmessage(e.data);
  14891. };
  14892. }
  14893. globalThis.onmessage = (e) => {
  14894. // Ignore first message in this case and initialize if not yet initialized
  14895. if (!initialized) {
  14896. initialize(null);
  14897. }
  14898. };