@codingame/monaco-languageclient-wrapper 1.8.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import * as monaco from 'monaco-editor/esm/vs/editor/edcore.main';
3
3
  import { Uri } from 'monaco-editor/esm/vs/editor/edcore.main';
4
4
  import { registerTextModelContentProvider } from '@codingame/monaco-editor-wrapper';
5
5
  import swal from 'sweetalert';
6
- import once from 'once';
6
+ import once$1 from 'once';
7
7
 
8
8
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
9
9
 
@@ -338,16 +338,227 @@ function RAL() {
338
338
  ral.default = RAL;
339
339
 
340
340
  // shim for using process in browser
341
+ // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
342
+
343
+ function defaultSetTimout() {
344
+ throw new Error('setTimeout has not been defined');
345
+ }
346
+ function defaultClearTimeout () {
347
+ throw new Error('clearTimeout has not been defined');
348
+ }
349
+ var cachedSetTimeout = defaultSetTimout;
350
+ var cachedClearTimeout = defaultClearTimeout;
351
+ if (typeof global.setTimeout === 'function') {
352
+ cachedSetTimeout = setTimeout;
353
+ }
354
+ if (typeof global.clearTimeout === 'function') {
355
+ cachedClearTimeout = clearTimeout;
356
+ }
357
+
358
+ function runTimeout(fun) {
359
+ if (cachedSetTimeout === setTimeout) {
360
+ //normal enviroments in sane situations
361
+ return setTimeout(fun, 0);
362
+ }
363
+ // if setTimeout wasn't available but was latter defined
364
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
365
+ cachedSetTimeout = setTimeout;
366
+ return setTimeout(fun, 0);
367
+ }
368
+ try {
369
+ // when when somebody has screwed with setTimeout but no I.E. maddness
370
+ return cachedSetTimeout(fun, 0);
371
+ } catch(e){
372
+ try {
373
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
374
+ return cachedSetTimeout.call(null, fun, 0);
375
+ } catch(e){
376
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
377
+ return cachedSetTimeout.call(this, fun, 0);
378
+ }
379
+ }
380
+
381
+
382
+ }
383
+ function runClearTimeout(marker) {
384
+ if (cachedClearTimeout === clearTimeout) {
385
+ //normal enviroments in sane situations
386
+ return clearTimeout(marker);
387
+ }
388
+ // if clearTimeout wasn't available but was latter defined
389
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
390
+ cachedClearTimeout = clearTimeout;
391
+ return clearTimeout(marker);
392
+ }
393
+ try {
394
+ // when when somebody has screwed with setTimeout but no I.E. maddness
395
+ return cachedClearTimeout(marker);
396
+ } catch (e){
397
+ try {
398
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
399
+ return cachedClearTimeout.call(null, marker);
400
+ } catch (e){
401
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
402
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
403
+ return cachedClearTimeout.call(this, marker);
404
+ }
405
+ }
406
+
407
+
408
+
409
+ }
410
+ var queue = [];
411
+ var draining = false;
412
+ var currentQueue;
413
+ var queueIndex = -1;
414
+
415
+ function cleanUpNextTick() {
416
+ if (!draining || !currentQueue) {
417
+ return;
418
+ }
419
+ draining = false;
420
+ if (currentQueue.length) {
421
+ queue = currentQueue.concat(queue);
422
+ } else {
423
+ queueIndex = -1;
424
+ }
425
+ if (queue.length) {
426
+ drainQueue();
427
+ }
428
+ }
429
+
430
+ function drainQueue() {
431
+ if (draining) {
432
+ return;
433
+ }
434
+ var timeout = runTimeout(cleanUpNextTick);
435
+ draining = true;
436
+
437
+ var len = queue.length;
438
+ while(len) {
439
+ currentQueue = queue;
440
+ queue = [];
441
+ while (++queueIndex < len) {
442
+ if (currentQueue) {
443
+ currentQueue[queueIndex].run();
444
+ }
445
+ }
446
+ queueIndex = -1;
447
+ len = queue.length;
448
+ }
449
+ currentQueue = null;
450
+ draining = false;
451
+ runClearTimeout(timeout);
452
+ }
453
+ function nextTick(fun) {
454
+ var args = new Array(arguments.length - 1);
455
+ if (arguments.length > 1) {
456
+ for (var i = 1; i < arguments.length; i++) {
457
+ args[i - 1] = arguments[i];
458
+ }
459
+ }
460
+ queue.push(new Item(fun, args));
461
+ if (queue.length === 1 && !draining) {
462
+ runTimeout(drainQueue);
463
+ }
464
+ }
465
+ // v8 likes predictible objects
466
+ function Item(fun, array) {
467
+ this.fun = fun;
468
+ this.array = array;
469
+ }
470
+ Item.prototype.run = function () {
471
+ this.fun.apply(null, this.array);
472
+ };
473
+ var title = 'browser';
474
+ var platform$1 = 'browser';
475
+ var browser = true;
476
+ var env = {};
477
+ var argv = [];
478
+ var version = ''; // empty string to avoid regexp issues
479
+ var versions = {};
480
+ var release$1 = {};
481
+ var config = {};
482
+
483
+ function noop() {}
484
+
485
+ var on = noop;
486
+ var addListener = noop;
487
+ var once = noop;
488
+ var off = noop;
489
+ var removeListener = noop;
490
+ var removeAllListeners = noop;
491
+ var emit = noop;
492
+
493
+ function binding(name) {
494
+ throw new Error('process.binding is not supported');
495
+ }
496
+
497
+ function cwd () { return '/' }
498
+ function chdir (dir) {
499
+ throw new Error('process.chdir is not supported');
500
+ }function umask() { return 0; }
341
501
 
342
502
  // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
343
503
  var performance = global.performance || {};
344
- performance.now ||
504
+ var performanceNow =
505
+ performance.now ||
345
506
  performance.mozNow ||
346
507
  performance.msNow ||
347
508
  performance.oNow ||
348
509
  performance.webkitNow ||
349
510
  function(){ return (new Date()).getTime() };
350
511
 
512
+ // generate timestamp or delta
513
+ // see http://nodejs.org/api/process.html#process_process_hrtime
514
+ function hrtime(previousTimestamp){
515
+ var clocktime = performanceNow.call(performance)*1e-3;
516
+ var seconds = Math.floor(clocktime);
517
+ var nanoseconds = Math.floor((clocktime%1)*1e9);
518
+ if (previousTimestamp) {
519
+ seconds = seconds - previousTimestamp[0];
520
+ nanoseconds = nanoseconds - previousTimestamp[1];
521
+ if (nanoseconds<0) {
522
+ seconds--;
523
+ nanoseconds += 1e9;
524
+ }
525
+ }
526
+ return [seconds,nanoseconds]
527
+ }
528
+
529
+ var startTime = new Date();
530
+ function uptime$1() {
531
+ var currentTime = new Date();
532
+ var dif = currentTime - startTime;
533
+ return dif / 1000;
534
+ }
535
+
536
+ var process$1 = {
537
+ nextTick: nextTick,
538
+ title: title,
539
+ browser: browser,
540
+ env: env,
541
+ argv: argv,
542
+ version: version,
543
+ versions: versions,
544
+ on: on,
545
+ addListener: addListener,
546
+ once: once,
547
+ off: off,
548
+ removeListener: removeListener,
549
+ removeAllListeners: removeAllListeners,
550
+ emit: emit,
551
+ binding: binding,
552
+ cwd: cwd,
553
+ chdir: chdir,
554
+ umask: umask,
555
+ hrtime: hrtime,
556
+ platform: platform$1,
557
+ release: release$1,
558
+ config: config,
559
+ uptime: uptime$1
560
+ };
561
+
351
562
  var inherits;
352
563
  if (typeof Object.create === 'function'){
353
564
  inherits = function inherits(ctor, superCtor) {
@@ -424,10 +635,18 @@ function deprecate(fn, msg) {
424
635
  };
425
636
  }
426
637
 
638
+ if (process$1.noDeprecation === true) {
639
+ return fn;
640
+ }
641
+
427
642
  var warned = false;
428
643
  function deprecated() {
429
644
  if (!warned) {
430
- {
645
+ if (process$1.throwDeprecation) {
646
+ throw new Error(msg);
647
+ } else if (process$1.traceDeprecation) {
648
+ console.trace(msg);
649
+ } else {
431
650
  console.error(msg);
432
651
  }
433
652
  warned = true;
@@ -442,7 +661,7 @@ var debugs = {};
442
661
  var debugEnviron;
443
662
  function debuglog(set) {
444
663
  if (isUndefined(debugEnviron))
445
- debugEnviron = '';
664
+ debugEnviron = process$1.env.NODE_DEBUG || '';
446
665
  set = set.toUpperCase();
447
666
  if (!debugs[set]) {
448
667
  if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
@@ -19924,15 +20143,15 @@ const staticOptions = asLanguageClientOptionsById({
19924
20143
  synchronize: {
19925
20144
  configurationSection: 'serenata'
19926
20145
  },
19927
- initializationOptions: {
20146
+ initializationOptions: () => ({
19928
20147
  configuration: {
19929
- uris: ['file:///tmp/project'],
20148
+ uris: [lib$1.Services.get().workspace.rootUri],
19930
20149
  phpVersion: 7.3,
19931
20150
  fileExtensions: ['php'],
19932
20151
  indexDatabaseUri: 'file:///tmp/index.sqlite',
19933
20152
  excludedPathExpressions: ['file:///opt/serenata']
19934
20153
  }
19935
- },
20154
+ }),
19936
20155
  mutualizable: true
19937
20156
  },
19938
20157
  php: {
@@ -20152,185 +20371,574 @@ function _defineProperty(obj, key, value) {
20152
20371
  return obj;
20153
20372
  }
20154
20373
 
20155
- var delay$2 = {exports: {}};
20156
-
20157
- // From https://github.com/sindresorhus/random-int/blob/c37741b56f76b9160b0b63dae4e9c64875128146/index.js#L13-L15
20158
- const randomInteger = (minimum, maximum) => Math.floor((Math.random() * (maximum - minimum + 1)) + minimum);
20159
-
20160
- const createAbortError = () => {
20161
- const error = new Error('Delay aborted');
20162
- error.name = 'AbortError';
20163
- return error;
20164
- };
20374
+ var lib = {};
20165
20375
 
20166
- const createDelay = ({clearTimeout: defaultClear, setTimeout: set, willResolve}) => (ms, {value, signal} = {}) => {
20167
- if (signal && signal.aborted) {
20168
- return Promise.reject(createAbortError());
20169
- }
20376
+ var disposable = {};
20170
20377
 
20171
- let timeoutId;
20172
- let settle;
20173
- let rejectFn;
20174
- const clear = defaultClear || clearTimeout;
20378
+ (function (exports) {
20379
+ Object.defineProperty(exports, "__esModule", { value: true });
20380
+ exports.DisposableCollection = exports.Disposable = void 0;
20381
+ /* --------------------------------------------------------------------------------------------
20382
+ * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20383
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20384
+ * ------------------------------------------------------------------------------------------ */
20385
+ const disposable_1 = disposable$1;
20386
+ Object.defineProperty(exports, "Disposable", { enumerable: true, get: function () { return disposable_1.Disposable; } });
20387
+ class DisposableCollection {
20388
+ constructor() {
20389
+ this.disposables = [];
20390
+ }
20391
+ dispose() {
20392
+ while (this.disposables.length !== 0) {
20393
+ this.disposables.pop().dispose();
20394
+ }
20395
+ }
20396
+ push(disposable) {
20397
+ const disposables = this.disposables;
20398
+ disposables.push(disposable);
20399
+ return {
20400
+ dispose() {
20401
+ const index = disposables.indexOf(disposable);
20402
+ if (index !== -1) {
20403
+ disposables.splice(index, 1);
20404
+ }
20405
+ }
20406
+ };
20407
+ }
20408
+ }
20409
+ exports.DisposableCollection = DisposableCollection;
20175
20410
 
20176
- const signalListener = () => {
20177
- clear(timeoutId);
20178
- rejectFn(createAbortError());
20179
- };
20411
+ }(disposable));
20180
20412
 
20181
- const cleanup = () => {
20182
- if (signal) {
20183
- signal.removeEventListener('abort', signalListener);
20184
- }
20185
- };
20413
+ var socket$1 = {};
20186
20414
 
20187
- const delayPromise = new Promise((resolve, reject) => {
20188
- settle = () => {
20189
- cleanup();
20190
- if (willResolve) {
20191
- resolve(value);
20192
- } else {
20193
- reject(value);
20194
- }
20195
- };
20415
+ var socket = {};
20196
20416
 
20197
- rejectFn = reject;
20198
- timeoutId = (set || setTimeout)(settle, ms);
20199
- });
20417
+ Object.defineProperty(socket, "__esModule", { value: true });
20200
20418
 
20201
- if (signal) {
20202
- signal.addEventListener('abort', signalListener, {once: true});
20203
- }
20419
+ var reader = {};
20204
20420
 
20205
- delayPromise.clear = () => {
20206
- clear(timeoutId);
20207
- timeoutId = null;
20208
- settle();
20209
- };
20421
+ /* --------------------------------------------------------------------------------------------
20422
+ * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20423
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20424
+ * ------------------------------------------------------------------------------------------ */
20425
+ Object.defineProperty(reader, "__esModule", { value: true });
20426
+ reader.WebSocketMessageReader = void 0;
20427
+ const messageReader_1 = messageReader;
20428
+ class WebSocketMessageReader extends messageReader_1.AbstractMessageReader {
20429
+ constructor(socket) {
20430
+ super();
20431
+ this.socket = socket;
20432
+ this.state = 'initial';
20433
+ this.events = [];
20434
+ this.socket.onMessage(message => this.readMessage(message));
20435
+ this.socket.onError(error => this.fireError(error));
20436
+ this.socket.onClose((code, reason) => {
20437
+ if (code !== 1000) {
20438
+ const error = {
20439
+ name: '' + code,
20440
+ message: `Error during socket reconnect: code = ${code}, reason = ${reason}`
20441
+ };
20442
+ this.fireError(error);
20443
+ }
20444
+ this.fireClose();
20445
+ });
20446
+ }
20447
+ listen(callback) {
20448
+ if (this.state === 'initial') {
20449
+ this.state = 'listening';
20450
+ this.callback = callback;
20451
+ while (this.events.length !== 0) {
20452
+ const event = this.events.pop();
20453
+ if (event.message) {
20454
+ this.readMessage(event.message);
20455
+ }
20456
+ else if (event.error) {
20457
+ this.fireError(event.error);
20458
+ }
20459
+ else {
20460
+ this.fireClose();
20461
+ }
20462
+ }
20463
+ }
20464
+ return {
20465
+ dispose: () => {
20466
+ if (this.callback === callback) {
20467
+ this.callback = undefined;
20468
+ }
20469
+ }
20470
+ };
20471
+ }
20472
+ readMessage(message) {
20473
+ if (this.state === 'initial') {
20474
+ this.events.splice(0, 0, { message });
20475
+ }
20476
+ else if (this.state === 'listening') {
20477
+ const data = JSON.parse(message);
20478
+ this.callback(data);
20479
+ }
20480
+ }
20481
+ fireError(error) {
20482
+ if (this.state === 'initial') {
20483
+ this.events.splice(0, 0, { error });
20484
+ }
20485
+ else if (this.state === 'listening') {
20486
+ super.fireError(error);
20487
+ }
20488
+ }
20489
+ fireClose() {
20490
+ if (this.state === 'initial') {
20491
+ this.events.splice(0, 0, {});
20492
+ }
20493
+ else if (this.state === 'listening') {
20494
+ super.fireClose();
20495
+ }
20496
+ this.state = 'closed';
20497
+ }
20498
+ }
20499
+ reader.WebSocketMessageReader = WebSocketMessageReader;
20210
20500
 
20211
- return delayPromise;
20212
- };
20501
+ var writer = {};
20213
20502
 
20214
- const createWithTimers = clearAndSet => {
20215
- const delay = createDelay({...clearAndSet, willResolve: true});
20216
- delay.reject = createDelay({...clearAndSet, willResolve: false});
20217
- delay.range = (minimum, maximum, options) => delay(randomInteger(minimum, maximum), options);
20218
- return delay;
20503
+ /* --------------------------------------------------------------------------------------------
20504
+ * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20505
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20506
+ * ------------------------------------------------------------------------------------------ */
20507
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
20508
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20509
+ return new (P || (P = Promise))(function (resolve, reject) {
20510
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20511
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
20512
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20513
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20514
+ });
20219
20515
  };
20516
+ Object.defineProperty(writer, "__esModule", { value: true });
20517
+ writer.WebSocketMessageWriter = void 0;
20518
+ const messageWriter_1 = messageWriter;
20519
+ class WebSocketMessageWriter extends messageWriter_1.AbstractMessageWriter {
20520
+ constructor(socket) {
20521
+ super();
20522
+ this.socket = socket;
20523
+ this.errorCount = 0;
20524
+ }
20525
+ end() {
20526
+ }
20527
+ write(msg) {
20528
+ return __awaiter(this, void 0, void 0, function* () {
20529
+ try {
20530
+ const content = JSON.stringify(msg);
20531
+ this.socket.send(content);
20532
+ }
20533
+ catch (e) {
20534
+ this.errorCount++;
20535
+ this.fireError(e, msg, this.errorCount);
20536
+ }
20537
+ });
20538
+ }
20539
+ }
20540
+ writer.WebSocketMessageWriter = WebSocketMessageWriter;
20220
20541
 
20221
- const delay = createWithTimers();
20222
- delay.createWithTimers = createWithTimers;
20223
-
20224
- delay$2.exports = delay;
20225
- // TODO: Remove this for the next major release
20226
- delay$2.exports.default = delay;
20227
-
20228
- var delay$1 = delay$2.exports;
20229
-
20230
- class WatchableOutputChannel {
20231
- constructor(name) {
20232
- _defineProperty(this, "logs", '');
20233
-
20234
- _defineProperty(this, "name", void 0);
20542
+ var connection$1 = {};
20235
20543
 
20236
- _defineProperty(this, "onWillCloseEmitter", new lib$1.Emitter());
20544
+ Object.defineProperty(connection$1, "__esModule", { value: true });
20545
+ connection$1.createWebSocketConnection = void 0;
20546
+ /* --------------------------------------------------------------------------------------------
20547
+ * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20548
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20549
+ * ------------------------------------------------------------------------------------------ */
20550
+ const vscode_jsonrpc_1 = main$2;
20551
+ const reader_1 = reader;
20552
+ const writer_1 = writer;
20553
+ function createWebSocketConnection(socket, logger) {
20554
+ const messageReader = new reader_1.WebSocketMessageReader(socket);
20555
+ const messageWriter = new writer_1.WebSocketMessageWriter(socket);
20556
+ const connection = vscode_jsonrpc_1.createMessageConnection(messageReader, messageWriter, logger);
20557
+ connection.onClose(() => connection.dispose());
20558
+ return connection;
20559
+ }
20560
+ connection$1.createWebSocketConnection = createWebSocketConnection;
20237
20561
 
20238
- _defineProperty(this, "onDidChangeLogEmitter", new lib$1.Emitter());
20562
+ (function (exports) {
20563
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20564
+ if (k2 === undefined) k2 = k;
20565
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20566
+ }) : (function(o, m, k, k2) {
20567
+ if (k2 === undefined) k2 = k;
20568
+ o[k2] = m[k];
20569
+ }));
20570
+ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
20571
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20572
+ };
20573
+ Object.defineProperty(exports, "__esModule", { value: true });
20574
+ /* --------------------------------------------------------------------------------------------
20575
+ * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20576
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20577
+ * ------------------------------------------------------------------------------------------ */
20578
+ __exportStar(socket, exports);
20579
+ __exportStar(reader, exports);
20580
+ __exportStar(writer, exports);
20581
+ __exportStar(connection$1, exports);
20239
20582
 
20240
- this.name = name;
20241
- }
20583
+ }(socket$1));
20242
20584
 
20243
- get onWillClose() {
20244
- return this.onWillCloseEmitter.event;
20245
- }
20585
+ var logger = {};
20246
20586
 
20247
- get onDidChangeLog() {
20248
- return this.onDidChangeLogEmitter.event;
20249
- }
20587
+ Object.defineProperty(logger, "__esModule", { value: true });
20588
+ logger.ConsoleLogger = void 0;
20589
+ class ConsoleLogger {
20590
+ error(message) {
20591
+ console.error(message);
20592
+ }
20593
+ warn(message) {
20594
+ console.warn(message);
20595
+ }
20596
+ info(message) {
20597
+ console.info(message);
20598
+ }
20599
+ log(message) {
20600
+ console.log(message);
20601
+ }
20602
+ debug(message) {
20603
+ console.debug(message);
20604
+ }
20605
+ }
20606
+ logger.ConsoleLogger = ConsoleLogger;
20250
20607
 
20251
- append(value) {
20252
- this.logs += value;
20253
- this.onDidChangeLogEmitter.fire();
20254
- }
20608
+ var connection = {};
20255
20609
 
20256
- appendLine(line) {
20257
- this.logs += line + '\n';
20258
- this.onDidChangeLogEmitter.fire();
20259
- }
20610
+ Object.defineProperty(connection, "__esModule", { value: true });
20611
+ connection.toSocket = connection.listen = void 0;
20612
+ const socket_1 = socket$1;
20613
+ const logger_1 = logger;
20614
+ function listen(options) {
20615
+ const { webSocket, onConnection } = options;
20616
+ const logger = options.logger || new logger_1.ConsoleLogger();
20617
+ webSocket.onopen = () => {
20618
+ const socket = toSocket(webSocket);
20619
+ const connection = socket_1.createWebSocketConnection(socket, logger);
20620
+ onConnection(connection);
20621
+ };
20622
+ }
20623
+ connection.listen = listen;
20624
+ function toSocket(webSocket) {
20625
+ return {
20626
+ send: content => webSocket.send(content),
20627
+ onMessage: cb => webSocket.onmessage = event => cb(event.data),
20628
+ onError: cb => webSocket.onerror = event => {
20629
+ if ('message' in event) {
20630
+ cb(event.message);
20631
+ }
20632
+ },
20633
+ onClose: cb => webSocket.onclose = event => cb(event.code, event.reason),
20634
+ dispose: () => webSocket.close()
20635
+ };
20636
+ }
20637
+ connection.toSocket = toSocket;
20260
20638
 
20261
- show() {// ignore
20262
- }
20639
+ (function (exports) {
20640
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20641
+ if (k2 === undefined) k2 = k;
20642
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20643
+ }) : (function(o, m, k, k2) {
20644
+ if (k2 === undefined) k2 = k;
20645
+ o[k2] = m[k];
20646
+ }));
20647
+ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
20648
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20649
+ };
20650
+ Object.defineProperty(exports, "__esModule", { value: true });
20651
+ /* --------------------------------------------------------------------------------------------
20652
+ * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20653
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20654
+ * ------------------------------------------------------------------------------------------ */
20655
+ __exportStar(main$2, exports);
20656
+ __exportStar(messages$1, exports);
20657
+ __exportStar(disposable, exports);
20658
+ __exportStar(socket$1, exports);
20659
+ __exportStar(logger, exports);
20660
+ __exportStar(connection, exports);
20263
20661
 
20264
- dispose() {
20265
- this.onWillCloseEmitter.fire();
20266
- }
20662
+ }(lib));
20267
20663
 
20664
+ const willShutdownNotificationType = new main$3.ProtocolNotificationType('willShutdown');
20665
+ const saveTextDocumentRequestType = new main$3.ProtocolRequestType('textDocument/save');
20666
+ const getTextDocumentRequestType = new main$3.ProtocolRequestType('textDocument/get');
20667
+ function updateFile(uri, text, languageClient) {
20668
+ return languageClient.sendRequest(saveTextDocumentRequestType, {
20669
+ textDocument: {
20670
+ uri,
20671
+ text
20672
+ }
20673
+ });
20674
+ }
20675
+ function getFile(uri, languageClient) {
20676
+ return languageClient.sendRequest(getTextDocumentRequestType, {
20677
+ textDocument: {
20678
+ uri
20679
+ }
20680
+ });
20268
20681
  }
20269
20682
 
20270
- class WatchableConsoleWindow {
20271
- constructor() {
20272
- _defineProperty(this, "onDidChangeChannelsEmitter", new lib$1.Emitter());
20683
+ function openWebsocketConnection(url) {
20684
+ return new Promise((resolve, reject) => {
20685
+ const webSocket = new WebSocket(url);
20273
20686
 
20274
- _defineProperty(this, "channels", new Map());
20687
+ webSocket.onopen = () => {
20688
+ const socket = lib.toSocket(webSocket);
20689
+ const webSocketConnection = lib.createWebSocketConnection(socket, new lib.ConsoleLogger());
20690
+ webSocketConnection.onDispose(() => {
20691
+ webSocket.close();
20692
+ });
20693
+ resolve(webSocketConnection);
20694
+ };
20275
20695
 
20276
- _defineProperty(this, "withProgress", async (options, task) => {
20277
- console.info('[LSP]', 'Starting task with progress:', options.location, options.title);
20696
+ webSocket.onerror = () => {
20697
+ reject(new Error('Unable to connect to server'));
20698
+ };
20699
+ });
20700
+ }
20278
20701
 
20279
- try {
20280
- return await task({
20281
- report: params => {
20282
- console.info('[LSP]', "Task progress: ".concat(params.increment, "%:"), params.message);
20283
- }
20284
- }, new lib$1.CancellationTokenSource().token);
20285
- } finally {
20286
- console.info('[LSP]', 'Task completed:', options.title);
20287
- }
20288
- });
20289
- }
20702
+ class CodinGameInfrastructure {
20703
+ constructor(
20704
+ /**
20705
+ * The domain of the server
20706
+ */
20707
+ serverAddress, useMutualizedProxy,
20708
+ /**
20709
+ * An optional sessionId when connecting to the session-mutualized server
20710
+ */
20711
+ sessionId,
20712
+ /**
20713
+ * A list of urls which link to zip files containing libraries/resources
20714
+ */
20715
+ libraryUrls) {
20716
+ this.serverAddress = serverAddress;
20717
+ this.useMutualizedProxy = useMutualizedProxy;
20718
+ this.sessionId = sessionId;
20719
+ this.libraryUrls = libraryUrls;
20290
20720
 
20291
- async showMessage(type, message) {
20292
- for (var _len = arguments.length, actions = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
20293
- actions[_key - 2] = arguments[_key];
20294
- }
20721
+ _defineProperty(this, "automaticTextDocumentUpdate", false);
20295
20722
 
20296
- const displayedMessage = message + '\n' + actions.map(action => "- ".concat(action.title)).join('\n');
20723
+ _defineProperty(this, "rootUri", 'file:///tmp/project');
20297
20724
 
20298
- if (type === lib$1.MessageType.Error) {
20299
- console.error('[LSP]', displayedMessage);
20300
- }
20725
+ _defineProperty(this, "workspaceFolders", [{
20726
+ uri: monaco.Uri.file('/tmp/project'),
20727
+ index: 0,
20728
+ name: 'main'
20729
+ }]);
20730
+ }
20301
20731
 
20302
- if (type === lib$1.MessageType.Warning) {
20303
- console.warn('[LSP]', displayedMessage);
20732
+ async saveFileContent(document, reason, languageClient) {
20733
+ if (languageClient.isReady()) {
20734
+ await updateFile(document.uri.toString(), document.getText(), languageClient);
20304
20735
  }
20736
+ }
20305
20737
 
20306
- if (type === lib$1.MessageType.Info) {
20307
- console.info('[LSP]', displayedMessage);
20738
+ async getFileContent(resource, languageClient) {
20739
+ try {
20740
+ return (await getFile(resource.toString(true), languageClient)).text;
20741
+ } catch (error) {
20742
+ console.error('File not found', resource.toString());
20743
+ return null;
20308
20744
  }
20745
+ }
20746
+ /**
20747
+ * A function which returns a valid JWT token to use to connect to the server
20748
+ */
20309
20749
 
20310
- if (type === lib$1.MessageType.Log) {
20311
- // eslint-disable-next-line no-console
20312
- console.log('[LSP]', displayedMessage);
20313
- }
20314
20750
 
20315
- if (actions.length > 1) {
20316
- return swal({
20317
- text: message,
20318
- buttons: actions.reduce((acc, action, index) => _objectSpread2(_objectSpread2({}, acc), {}, {
20319
- ["option-".concat(index)]: {
20320
- text: action.title,
20321
- value: action
20322
- }
20323
- }), {})
20324
- });
20325
- }
20751
+ async openConnection(id) {
20752
+ var _this$libraryUrls;
20326
20753
 
20327
- return actions[0];
20754
+ const url = new URL(this.sessionId != null ? "run/".concat(this.sessionId, "/").concat(id) : "run/".concat(id), this.serverAddress);
20755
+ (_this$libraryUrls = this.libraryUrls) === null || _this$libraryUrls === void 0 ? void 0 : _this$libraryUrls.forEach(libraryUrl => url.searchParams.append('libraryUrl', libraryUrl));
20756
+ url.searchParams.append('token', await this.getSecurityToken());
20757
+ const connection = await openWebsocketConnection(url);
20758
+ return connection;
20328
20759
  }
20329
20760
 
20330
- createOutputChannel(name) {
20331
- let channel = this.channels.get(name);
20761
+ }
20332
20762
 
20333
- if (channel == null) {
20763
+ var delay$2 = {exports: {}};
20764
+
20765
+ // From https://github.com/sindresorhus/random-int/blob/c37741b56f76b9160b0b63dae4e9c64875128146/index.js#L13-L15
20766
+ const randomInteger = (minimum, maximum) => Math.floor((Math.random() * (maximum - minimum + 1)) + minimum);
20767
+
20768
+ const createAbortError = () => {
20769
+ const error = new Error('Delay aborted');
20770
+ error.name = 'AbortError';
20771
+ return error;
20772
+ };
20773
+
20774
+ const createDelay = ({clearTimeout: defaultClear, setTimeout: set, willResolve}) => (ms, {value, signal} = {}) => {
20775
+ if (signal && signal.aborted) {
20776
+ return Promise.reject(createAbortError());
20777
+ }
20778
+
20779
+ let timeoutId;
20780
+ let settle;
20781
+ let rejectFn;
20782
+ const clear = defaultClear || clearTimeout;
20783
+
20784
+ const signalListener = () => {
20785
+ clear(timeoutId);
20786
+ rejectFn(createAbortError());
20787
+ };
20788
+
20789
+ const cleanup = () => {
20790
+ if (signal) {
20791
+ signal.removeEventListener('abort', signalListener);
20792
+ }
20793
+ };
20794
+
20795
+ const delayPromise = new Promise((resolve, reject) => {
20796
+ settle = () => {
20797
+ cleanup();
20798
+ if (willResolve) {
20799
+ resolve(value);
20800
+ } else {
20801
+ reject(value);
20802
+ }
20803
+ };
20804
+
20805
+ rejectFn = reject;
20806
+ timeoutId = (set || setTimeout)(settle, ms);
20807
+ });
20808
+
20809
+ if (signal) {
20810
+ signal.addEventListener('abort', signalListener, {once: true});
20811
+ }
20812
+
20813
+ delayPromise.clear = () => {
20814
+ clear(timeoutId);
20815
+ timeoutId = null;
20816
+ settle();
20817
+ };
20818
+
20819
+ return delayPromise;
20820
+ };
20821
+
20822
+ const createWithTimers = clearAndSet => {
20823
+ const delay = createDelay({...clearAndSet, willResolve: true});
20824
+ delay.reject = createDelay({...clearAndSet, willResolve: false});
20825
+ delay.range = (minimum, maximum, options) => delay(randomInteger(minimum, maximum), options);
20826
+ return delay;
20827
+ };
20828
+
20829
+ const delay = createWithTimers();
20830
+ delay.createWithTimers = createWithTimers;
20831
+
20832
+ delay$2.exports = delay;
20833
+ // TODO: Remove this for the next major release
20834
+ delay$2.exports.default = delay;
20835
+
20836
+ var delay$1 = delay$2.exports;
20837
+
20838
+ class WatchableOutputChannel {
20839
+ constructor(name) {
20840
+ _defineProperty(this, "logs", '');
20841
+
20842
+ _defineProperty(this, "name", void 0);
20843
+
20844
+ _defineProperty(this, "onWillCloseEmitter", new lib$1.Emitter());
20845
+
20846
+ _defineProperty(this, "onDidChangeLogEmitter", new lib$1.Emitter());
20847
+
20848
+ this.name = name;
20849
+ }
20850
+
20851
+ get onWillClose() {
20852
+ return this.onWillCloseEmitter.event;
20853
+ }
20854
+
20855
+ get onDidChangeLog() {
20856
+ return this.onDidChangeLogEmitter.event;
20857
+ }
20858
+
20859
+ append(value) {
20860
+ this.logs += value;
20861
+ this.onDidChangeLogEmitter.fire();
20862
+ }
20863
+
20864
+ appendLine(line) {
20865
+ this.logs += line + '\n';
20866
+ this.onDidChangeLogEmitter.fire();
20867
+ }
20868
+
20869
+ show() {// ignore
20870
+ }
20871
+
20872
+ dispose() {
20873
+ this.onWillCloseEmitter.fire();
20874
+ }
20875
+
20876
+ }
20877
+
20878
+ class WatchableConsoleWindow {
20879
+ constructor() {
20880
+ _defineProperty(this, "onDidChangeChannelsEmitter", new lib$1.Emitter());
20881
+
20882
+ _defineProperty(this, "channels", new Map());
20883
+
20884
+ _defineProperty(this, "withProgress", async (options, task) => {
20885
+ console.info('[LSP]', 'Starting task with progress:', options.location, options.title);
20886
+
20887
+ try {
20888
+ return await task({
20889
+ report: params => {
20890
+ console.info('[LSP]', "Task progress: ".concat(params.increment, "%:"), params.message);
20891
+ }
20892
+ }, new lib$1.CancellationTokenSource().token);
20893
+ } finally {
20894
+ console.info('[LSP]', 'Task completed:', options.title);
20895
+ }
20896
+ });
20897
+ }
20898
+
20899
+ async showMessage(type, message) {
20900
+ for (var _len = arguments.length, actions = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
20901
+ actions[_key - 2] = arguments[_key];
20902
+ }
20903
+
20904
+ const displayedMessage = message + '\n' + actions.map(action => "- ".concat(action.title)).join('\n');
20905
+
20906
+ if (type === lib$1.MessageType.Error) {
20907
+ console.error('[LSP]', displayedMessage);
20908
+ }
20909
+
20910
+ if (type === lib$1.MessageType.Warning) {
20911
+ console.warn('[LSP]', displayedMessage);
20912
+ }
20913
+
20914
+ if (type === lib$1.MessageType.Info) {
20915
+ console.info('[LSP]', displayedMessage);
20916
+ }
20917
+
20918
+ if (type === lib$1.MessageType.Log) {
20919
+ // eslint-disable-next-line no-console
20920
+ console.log('[LSP]', displayedMessage);
20921
+ }
20922
+
20923
+ if (actions.length > 1) {
20924
+ return swal({
20925
+ text: message,
20926
+ buttons: actions.reduce((acc, action, index) => _objectSpread2(_objectSpread2({}, acc), {}, {
20927
+ ["option-".concat(index)]: {
20928
+ text: action.title,
20929
+ value: action
20930
+ }
20931
+ }), {})
20932
+ });
20933
+ }
20934
+
20935
+ return actions[0];
20936
+ }
20937
+
20938
+ createOutputChannel(name) {
20939
+ let channel = this.channels.get(name);
20940
+
20941
+ if (channel == null) {
20334
20942
  channel = new WatchableOutputChannel(name);
20335
20943
  channel.onWillClose(() => {
20336
20944
  this.channels.delete(name);
@@ -20418,415 +21026,126 @@ class Configuration {
20418
21026
 
20419
21027
  }
20420
21028
 
20421
- function updateFile(uri, text, languageClient) {
20422
- return languageClient.sendRequest('textDocument/save', {
20423
- textDocument: {
20424
- uri,
20425
- text
20426
- }
20427
- });
20428
- }
20429
- function getFile(uri, languageClient) {
20430
- return languageClient.sendRequest('textDocument/get', {
20431
- textDocument: {
20432
- uri
20433
- }
20434
- });
20435
- }
20436
-
20437
21029
  class CodinGameMonacoWorkspace extends lib$1.MonacoWorkspace {
20438
21030
  constructor(p2m, m2p) {
20439
21031
  let _rootUri = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
20440
21032
 
21033
+ let workspaceFolders = arguments.length > 3 ? arguments[3] : undefined;
20441
21034
  super(monaco, p2m, m2p, _rootUri); // "workaround" for https://github.com/TypeFox/monaco-languageclient/pull/199#issuecomment-593414330
20442
21035
 
20443
- _defineProperty(this, "onWillSaveTextDocumentEmitter", new lib$1.Emitter());
20444
-
20445
- _defineProperty(this, "onDidSaveTextDocumentEmitter", new lib$1.Emitter());
21036
+ this.workspaceFolders = workspaceFolders;
20446
21037
 
20447
- _defineProperty(this, "workspaceFolders", void 0);
20448
-
20449
- _defineProperty(this, "configurations", new Configuration());
20450
-
20451
- if (_rootUri != null) {
20452
- const uri = monaco.Uri.parse(_rootUri);
20453
- this.workspaceFolders = [{
20454
- uri,
20455
- index: 0,
20456
- name: uri.toString()
20457
- }];
20458
- }
20459
- }
20460
-
20461
- get onWillSaveTextDocument() {
20462
- return this.onWillSaveTextDocumentEmitter.event;
20463
- }
20464
-
20465
- get onDidSaveTextDocument() {
20466
- return this.onDidSaveTextDocumentEmitter.event;
20467
- }
20468
-
20469
- async saveDocument(document, reason) {
20470
- this.onWillSaveTextDocumentEmitter.fire({
20471
- textDocument: document,
20472
- reason
20473
- });
20474
-
20475
- try {
20476
- await Promise.all(getAllLanguageClientManagersByTextDocument(document).map(async languageClient => {
20477
- if (languageClient.isReady()) {
20478
- await updateFile(document.uri.toString(), document.getText(), languageClient);
20479
- }
20480
- }));
20481
- this.onDidSaveTextDocumentEmitter.fire(document);
20482
- } catch (err) {
20483
- console.error('[LSP]', 'Unable to save file on language server', err);
20484
- }
20485
- }
20486
-
20487
- }
20488
-
20489
- function installCommands(services) {
20490
- // Comes from https://github.com/redhat-developer/vscode-java/blob/9b0f0aca80cbefabad4c034fb5dd365d029f6170/src/extension.ts#L155-L160
20491
- // Other commands needs to be implemented as well?
20492
- // (https://github.com/eclipse/eclipse.jdt.ls/issues/376#issuecomment-333923685)
20493
- services.commands.registerCommand('java.apply.workspaceEdit', edit => {
20494
- if (edit.documentChanges != null && edit.documentChanges.some(change => main$3.RenameFile.is(change) || main$3.CreateFile.is(change))) {
20495
- alert('Unimplemented command');
20496
- return;
20497
- }
20498
-
20499
- return services.workspace.applyEdit(edit);
20500
- });
20501
- }
20502
-
20503
- function autoSaveModels(services) {
20504
- const timeoutMap = new Map();
20505
- services.workspace.onDidChangeTextDocument(e => {
20506
- const timeout = timeoutMap.get(e.textDocument.uri);
20507
-
20508
- if (timeout != null) {
20509
- window.clearTimeout(timeout);
20510
- timeoutMap.delete(e.textDocument.uri);
20511
- }
20512
-
20513
- timeoutMap.set(e.textDocument.uri, window.setTimeout(() => {
20514
- timeoutMap.delete(e.textDocument.uri);
20515
- services.workspace.saveDocument(e.textDocument, lib$1.TextDocumentSaveReason.AfterDelay).catch(err => {
20516
- console.error('[LSP]', "Unable to save the document ".concat(e.textDocument.uri.toString()), err);
20517
- });
20518
- }, 500));
20519
- });
20520
- }
20521
-
20522
- let services = null;
20523
-
20524
- function installServices() {
20525
- const m2p = new lib$1.MonacoToProtocolConverter(monaco);
20526
- const p2m = new lib$1.ProtocolToMonacoConverter(monaco);
20527
-
20528
- if (services == null) {
20529
- services = {
20530
- commands: new lib$1.MonacoCommands(monaco),
20531
- languages: new lib$1.MonacoLanguages(monaco, p2m, m2p),
20532
- workspace: new CodinGameMonacoWorkspace(p2m, m2p, 'file:///tmp/project'),
20533
- window: new WatchableConsoleWindow()
20534
- };
20535
- lib$1.Services.install(services);
20536
- installCommands(services);
20537
- autoSaveModels(services);
20538
- }
20539
- }
20540
-
20541
- var lib = {};
20542
-
20543
- var disposable = {};
20544
-
20545
- (function (exports) {
20546
- Object.defineProperty(exports, "__esModule", { value: true });
20547
- exports.DisposableCollection = exports.Disposable = void 0;
20548
- /* --------------------------------------------------------------------------------------------
20549
- * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20550
- * Licensed under the MIT License. See License.txt in the project root for license information.
20551
- * ------------------------------------------------------------------------------------------ */
20552
- const disposable_1 = disposable$1;
20553
- Object.defineProperty(exports, "Disposable", { enumerable: true, get: function () { return disposable_1.Disposable; } });
20554
- class DisposableCollection {
20555
- constructor() {
20556
- this.disposables = [];
20557
- }
20558
- dispose() {
20559
- while (this.disposables.length !== 0) {
20560
- this.disposables.pop().dispose();
20561
- }
20562
- }
20563
- push(disposable) {
20564
- const disposables = this.disposables;
20565
- disposables.push(disposable);
20566
- return {
20567
- dispose() {
20568
- const index = disposables.indexOf(disposable);
20569
- if (index !== -1) {
20570
- disposables.splice(index, 1);
20571
- }
20572
- }
20573
- };
20574
- }
20575
- }
20576
- exports.DisposableCollection = DisposableCollection;
20577
-
20578
- }(disposable));
20579
-
20580
- var socket$1 = {};
20581
-
20582
- var socket = {};
20583
-
20584
- Object.defineProperty(socket, "__esModule", { value: true });
20585
-
20586
- var reader = {};
20587
-
20588
- /* --------------------------------------------------------------------------------------------
20589
- * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20590
- * Licensed under the MIT License. See License.txt in the project root for license information.
20591
- * ------------------------------------------------------------------------------------------ */
20592
- Object.defineProperty(reader, "__esModule", { value: true });
20593
- reader.WebSocketMessageReader = void 0;
20594
- const messageReader_1 = messageReader;
20595
- class WebSocketMessageReader extends messageReader_1.AbstractMessageReader {
20596
- constructor(socket) {
20597
- super();
20598
- this.socket = socket;
20599
- this.state = 'initial';
20600
- this.events = [];
20601
- this.socket.onMessage(message => this.readMessage(message));
20602
- this.socket.onError(error => this.fireError(error));
20603
- this.socket.onClose((code, reason) => {
20604
- if (code !== 1000) {
20605
- const error = {
20606
- name: '' + code,
20607
- message: `Error during socket reconnect: code = ${code}, reason = ${reason}`
20608
- };
20609
- this.fireError(error);
20610
- }
20611
- this.fireClose();
20612
- });
20613
- }
20614
- listen(callback) {
20615
- if (this.state === 'initial') {
20616
- this.state = 'listening';
20617
- this.callback = callback;
20618
- while (this.events.length !== 0) {
20619
- const event = this.events.pop();
20620
- if (event.message) {
20621
- this.readMessage(event.message);
20622
- }
20623
- else if (event.error) {
20624
- this.fireError(event.error);
20625
- }
20626
- else {
20627
- this.fireClose();
20628
- }
20629
- }
20630
- }
20631
- return {
20632
- dispose: () => {
20633
- if (this.callback === callback) {
20634
- this.callback = undefined;
20635
- }
20636
- }
20637
- };
20638
- }
20639
- readMessage(message) {
20640
- if (this.state === 'initial') {
20641
- this.events.splice(0, 0, { message });
20642
- }
20643
- else if (this.state === 'listening') {
20644
- const data = JSON.parse(message);
20645
- this.callback(data);
20646
- }
20647
- }
20648
- fireError(error) {
20649
- if (this.state === 'initial') {
20650
- this.events.splice(0, 0, { error });
20651
- }
20652
- else if (this.state === 'listening') {
20653
- super.fireError(error);
20654
- }
20655
- }
20656
- fireClose() {
20657
- if (this.state === 'initial') {
20658
- this.events.splice(0, 0, {});
20659
- }
20660
- else if (this.state === 'listening') {
20661
- super.fireClose();
20662
- }
20663
- this.state = 'closed';
20664
- }
20665
- }
20666
- reader.WebSocketMessageReader = WebSocketMessageReader;
21038
+ _defineProperty(this, "onWillSaveTextDocumentEmitter", new lib$1.Emitter());
20667
21039
 
20668
- var writer = {};
21040
+ _defineProperty(this, "savehandlers", []);
20669
21041
 
20670
- /* --------------------------------------------------------------------------------------------
20671
- * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20672
- * Licensed under the MIT License. See License.txt in the project root for license information.
20673
- * ------------------------------------------------------------------------------------------ */
20674
- var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
20675
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20676
- return new (P || (P = Promise))(function (resolve, reject) {
20677
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20678
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
20679
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20680
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20681
- });
20682
- };
20683
- Object.defineProperty(writer, "__esModule", { value: true });
20684
- writer.WebSocketMessageWriter = void 0;
20685
- const messageWriter_1 = messageWriter;
20686
- class WebSocketMessageWriter extends messageWriter_1.AbstractMessageWriter {
20687
- constructor(socket) {
20688
- super();
20689
- this.socket = socket;
20690
- this.errorCount = 0;
20691
- }
20692
- end() {
20693
- }
20694
- write(msg) {
20695
- return __awaiter(this, void 0, void 0, function* () {
20696
- try {
20697
- const content = JSON.stringify(msg);
20698
- this.socket.send(content);
20699
- }
20700
- catch (e) {
20701
- this.errorCount++;
20702
- this.fireError(e, msg, this.errorCount);
20703
- }
20704
- });
21042
+ _defineProperty(this, "onDidSaveTextDocumentEmitter", new lib$1.Emitter());
21043
+
21044
+ _defineProperty(this, "configurations", new Configuration());
21045
+
21046
+ if (this.workspaceFolders == null && _rootUri != null) {
21047
+ const uri = monaco.Uri.parse(_rootUri);
21048
+ this.workspaceFolders = [{
21049
+ uri,
21050
+ index: 0,
21051
+ name: uri.toString()
21052
+ }];
20705
21053
  }
20706
- }
20707
- writer.WebSocketMessageWriter = WebSocketMessageWriter;
21054
+ }
20708
21055
 
20709
- var connection$1 = {};
21056
+ get onWillSaveTextDocument() {
21057
+ return this.onWillSaveTextDocumentEmitter.event;
21058
+ }
20710
21059
 
20711
- Object.defineProperty(connection$1, "__esModule", { value: true });
20712
- connection$1.createWebSocketConnection = void 0;
20713
- /* --------------------------------------------------------------------------------------------
20714
- * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20715
- * Licensed under the MIT License. See License.txt in the project root for license information.
20716
- * ------------------------------------------------------------------------------------------ */
20717
- const vscode_jsonrpc_1 = main$2;
20718
- const reader_1 = reader;
20719
- const writer_1 = writer;
20720
- function createWebSocketConnection(socket, logger) {
20721
- const messageReader = new reader_1.WebSocketMessageReader(socket);
20722
- const messageWriter = new writer_1.WebSocketMessageWriter(socket);
20723
- const connection = vscode_jsonrpc_1.createMessageConnection(messageReader, messageWriter, logger);
20724
- connection.onClose(() => connection.dispose());
20725
- return connection;
20726
- }
20727
- connection$1.createWebSocketConnection = createWebSocketConnection;
21060
+ get onDidSaveTextDocument() {
21061
+ return this.onDidSaveTextDocumentEmitter.event;
21062
+ }
20728
21063
 
20729
- (function (exports) {
20730
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20731
- if (k2 === undefined) k2 = k;
20732
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20733
- }) : (function(o, m, k, k2) {
20734
- if (k2 === undefined) k2 = k;
20735
- o[k2] = m[k];
20736
- }));
20737
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
20738
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20739
- };
20740
- Object.defineProperty(exports, "__esModule", { value: true });
20741
- /* --------------------------------------------------------------------------------------------
20742
- * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20743
- * Licensed under the MIT License. See License.txt in the project root for license information.
20744
- * ------------------------------------------------------------------------------------------ */
20745
- __exportStar(socket, exports);
20746
- __exportStar(reader, exports);
20747
- __exportStar(writer, exports);
20748
- __exportStar(connection$1, exports);
21064
+ registerSaveDocumentHandler(handler) {
21065
+ this.savehandlers.push(handler);
21066
+ return lib$1.Disposable.create(() => {
21067
+ const index = this.savehandlers.indexOf(handler);
20749
21068
 
20750
- }(socket$1));
21069
+ if (index >= 0) {
21070
+ this.savehandlers.splice(index, 1);
21071
+ }
21072
+ });
21073
+ }
20751
21074
 
20752
- var logger = {};
21075
+ async saveDocument(document, reason) {
21076
+ this.onWillSaveTextDocumentEmitter.fire({
21077
+ textDocument: document,
21078
+ reason
21079
+ });
20753
21080
 
20754
- Object.defineProperty(logger, "__esModule", { value: true });
20755
- logger.ConsoleLogger = void 0;
20756
- class ConsoleLogger {
20757
- error(message) {
20758
- console.error(message);
20759
- }
20760
- warn(message) {
20761
- console.warn(message);
20762
- }
20763
- info(message) {
20764
- console.info(message);
20765
- }
20766
- log(message) {
20767
- console.log(message);
21081
+ try {
21082
+ await Promise.all(this.savehandlers.map(handler => {
21083
+ return handler.saveTextContent(document, reason);
21084
+ }));
21085
+ this.onDidSaveTextDocumentEmitter.fire(document);
21086
+ } catch (err) {
21087
+ console.error('[LSP]', 'Unable to save file on language server', err);
20768
21088
  }
20769
- debug(message) {
20770
- console.debug(message);
21089
+ }
21090
+
21091
+ }
21092
+
21093
+ function installCommands(services) {
21094
+ // Comes from https://github.com/redhat-developer/vscode-java/blob/9b0f0aca80cbefabad4c034fb5dd365d029f6170/src/extension.ts#L155-L160
21095
+ // Other commands needs to be implemented as well?
21096
+ // (https://github.com/eclipse/eclipse.jdt.ls/issues/376#issuecomment-333923685)
21097
+ services.commands.registerCommand('java.apply.workspaceEdit', edit => {
21098
+ if (edit.documentChanges != null && edit.documentChanges.some(change => main$3.RenameFile.is(change) || main$3.CreateFile.is(change))) {
21099
+ alert('Unimplemented command');
21100
+ return;
20771
21101
  }
21102
+
21103
+ return services.workspace.applyEdit(edit);
21104
+ });
20772
21105
  }
20773
- logger.ConsoleLogger = ConsoleLogger;
20774
21106
 
20775
- var connection = {};
21107
+ function autoSaveModels(services) {
21108
+ const timeoutMap = new Map();
21109
+ services.workspace.onDidChangeTextDocument(e => {
21110
+ const timeout = timeoutMap.get(e.textDocument.uri);
20776
21111
 
20777
- Object.defineProperty(connection, "__esModule", { value: true });
20778
- connection.toSocket = connection.listen = void 0;
20779
- const socket_1 = socket$1;
20780
- const logger_1 = logger;
20781
- function listen(options) {
20782
- const { webSocket, onConnection } = options;
20783
- const logger = options.logger || new logger_1.ConsoleLogger();
20784
- webSocket.onopen = () => {
20785
- const socket = toSocket(webSocket);
20786
- const connection = socket_1.createWebSocketConnection(socket, logger);
20787
- onConnection(connection);
20788
- };
21112
+ if (timeout != null) {
21113
+ window.clearTimeout(timeout);
21114
+ timeoutMap.delete(e.textDocument.uri);
21115
+ }
21116
+
21117
+ timeoutMap.set(e.textDocument.uri, window.setTimeout(() => {
21118
+ timeoutMap.delete(e.textDocument.uri);
21119
+ services.workspace.saveDocument(e.textDocument, lib$1.TextDocumentSaveReason.AfterDelay).catch(err => {
21120
+ console.error('[LSP]', "Unable to save the document ".concat(e.textDocument.uri.toString()), err);
21121
+ });
21122
+ }, 500));
21123
+ });
20789
21124
  }
20790
- connection.listen = listen;
20791
- function toSocket(webSocket) {
20792
- return {
20793
- send: content => webSocket.send(content),
20794
- onMessage: cb => webSocket.onmessage = event => cb(event.data),
20795
- onError: cb => webSocket.onerror = event => {
20796
- if ('message' in event) {
20797
- cb(event.message);
20798
- }
20799
- },
20800
- onClose: cb => webSocket.onclose = event => cb(event.code, event.reason),
20801
- dispose: () => webSocket.close()
21125
+
21126
+ let services = null;
21127
+
21128
+ function installServices(infrastructure) {
21129
+ const m2p = new lib$1.MonacoToProtocolConverter(monaco);
21130
+ const p2m = new lib$1.ProtocolToMonacoConverter(monaco);
21131
+
21132
+ if (services == null) {
21133
+ services = {
21134
+ commands: new lib$1.MonacoCommands(monaco),
21135
+ languages: new lib$1.MonacoLanguages(monaco, p2m, m2p),
21136
+ workspace: new CodinGameMonacoWorkspace(p2m, m2p, infrastructure.rootUri, infrastructure.workspaceFolders),
21137
+ window: new WatchableConsoleWindow()
20802
21138
  };
20803
- }
20804
- connection.toSocket = toSocket;
21139
+ lib$1.Services.install(services);
21140
+ installCommands(services);
20805
21141
 
20806
- (function (exports) {
20807
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20808
- if (k2 === undefined) k2 = k;
20809
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20810
- }) : (function(o, m, k, k2) {
20811
- if (k2 === undefined) k2 = k;
20812
- o[k2] = m[k];
20813
- }));
20814
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
20815
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20816
- };
20817
- Object.defineProperty(exports, "__esModule", { value: true });
20818
- /* --------------------------------------------------------------------------------------------
20819
- * Copyright (c) 2018 TypeFox GmbH (http://www.typefox.io). All rights reserved.
20820
- * Licensed under the MIT License. See License.txt in the project root for license information.
20821
- * ------------------------------------------------------------------------------------------ */
20822
- __exportStar(main$2, exports);
20823
- __exportStar(messages$1, exports);
20824
- __exportStar(disposable, exports);
20825
- __exportStar(socket$1, exports);
20826
- __exportStar(logger, exports);
20827
- __exportStar(connection, exports);
21142
+ if (!infrastructure.automaticTextDocumentUpdate) {
21143
+ autoSaveModels(services);
21144
+ }
21145
+ }
20828
21146
 
20829
- }(lib));
21147
+ return services;
21148
+ }
20830
21149
 
20831
21150
  // Initialize the file content into the lsp server for implementations that don't support open/close notifications
20832
21151
  class InitializeTextDocumentFeature {
@@ -20890,10 +21209,10 @@ class CobolResolveSubroutineFeature {
20890
21209
 
20891
21210
  initialize(capabilities, documentSelector) {
20892
21211
  this.onRequestDisposable = this.languageClient.onRequest('cobol/resolveSubroutine', routineName => {
20893
- var _Services$get$workspa;
21212
+ var _Services$get$workspa, _Services$get$workspa2;
20894
21213
 
20895
21214
  const constantRoutinePaths = {
20896
- 'assert-equals': 'file:/tmp/project/deps/assert-equals.cbl'
21215
+ 'assert-equals': "".concat((_Services$get$workspa = lib$1.Services.get().workspace.rootUri) !== null && _Services$get$workspa !== void 0 ? _Services$get$workspa : 'file:/tmp/project', "/deps/assert-equals.cbl")
20897
21216
  };
20898
21217
  const contantRoutinePath = constantRoutinePaths[routineName.toLowerCase()];
20899
21218
 
@@ -20901,7 +21220,7 @@ class CobolResolveSubroutineFeature {
20901
21220
  return contantRoutinePath;
20902
21221
  }
20903
21222
 
20904
- return (_Services$get$workspa = lib$1.Services.get().workspace.textDocuments.filter(textDocument => lib$1.Services.get().languages.match(documentSelector, textDocument)).filter(document => document.getText().match(new RegExp("PROGRAM-ID\\.\\W+".concat(routineName, "\\."), 'gi'))).sort((a, b) => a.uri.localeCompare(b.uri))[0]) === null || _Services$get$workspa === void 0 ? void 0 : _Services$get$workspa.uri;
21223
+ return (_Services$get$workspa2 = lib$1.Services.get().workspace.textDocuments.filter(textDocument => lib$1.Services.get().languages.match(documentSelector, textDocument)).filter(document => document.getText().match(new RegExp("PROGRAM-ID\\.\\W+".concat(routineName, "\\."), 'gi'))).sort((a, b) => a.uri.localeCompare(b.uri))[0]) === null || _Services$get$workspa2 === void 0 ? void 0 : _Services$get$workspa2.uri;
20905
21224
  });
20906
21225
  }
20907
21226
 
@@ -20914,13 +21233,10 @@ class CobolResolveSubroutineFeature {
20914
21233
  }
20915
21234
 
20916
21235
  function registerExtensionFeatures(client, language) {
20917
- client.registerFeature(new InitializeTextDocumentFeature(client));
20918
-
20919
21236
  if (language === 'cobol') {
20920
21237
  client.registerFeature(new CobolResolveSubroutineFeature(client));
20921
21238
  }
20922
21239
  }
20923
- const willShutdownNotificationType = new lib$1.ProtocolNotificationType('willShutdown');
20924
21240
  class WillDisposeFeature {
20925
21241
  constructor(languageClient, onWillShutdownEmitter) {
20926
21242
  this.languageClient = languageClient;
@@ -20939,131 +21255,110 @@ class WillDisposeFeature {
20939
21255
 
20940
21256
  }
20941
21257
 
20942
- async function openConnection(url, errorHandler, closeHandler) {
20943
- return new Promise((resolve, reject) => {
20944
- const webSocket = new WebSocket(url);
20945
-
20946
- webSocket.onopen = () => {
20947
- const socket = lib.toSocket(webSocket);
20948
- const webSocketConnection = lib.createWebSocketConnection(socket, new lib.ConsoleLogger());
20949
- webSocketConnection.onDispose(() => {
20950
- webSocket.close();
20951
- });
20952
- const connection = lib$1.createConnection(webSocketConnection, errorHandler, closeHandler);
20953
- const existingRegistrations = new Set();
20954
-
20955
- const fixedConnection = _objectSpread2(_objectSpread2({}, connection), {}, {
20956
- initialize: params => {
20957
- var _params$rootPath;
20958
-
20959
- // Hack to fix url converted from /toto/tata to \\toto\tata in windows
20960
- const rootPath = (_params$rootPath = params.rootPath) === null || _params$rootPath === void 0 ? void 0 : _params$rootPath.replace(/\\/g, '/');
20961
-
20962
- const fixedParams = _objectSpread2(_objectSpread2({}, params), {}, {
20963
- rootPath: rootPath,
20964
- rootUri: rootPath != null ? Uri.from({
20965
- scheme: 'file',
20966
- path: rootPath
20967
- }).toString() : null
20968
- });
21258
+ async function messageConnectionToConnection(messageConnection, errorHandler, closeHandler) {
21259
+ const connection = lib$1.createConnection(messageConnection, errorHandler, closeHandler);
21260
+ const existingRegistrations = new Set();
20969
21261
 
20970
- return connection.initialize(fixedParams);
20971
- },
21262
+ const fixedConnection = _objectSpread2(_objectSpread2({}, connection), {}, {
21263
+ initialize: params => {
21264
+ var _params$rootPath;
20972
21265
 
20973
- onRequest() {
20974
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
20975
- args[_key] = arguments[_key];
20976
- }
21266
+ // Hack to fix url converted from /toto/tata to \\toto\tata in windows
21267
+ const rootPath = (_params$rootPath = params.rootPath) === null || _params$rootPath === void 0 ? void 0 : _params$rootPath.replace(/\\/g, '/');
20977
21268
 
20978
- return connection.onRequest(args[0], function () {
20979
- // Hack for https://github.com/OmniSharp/omnisharp-roslyn/issues/2119
20980
- const method = args[0].method;
21269
+ const fixedParams = _objectSpread2(_objectSpread2({}, params), {}, {
21270
+ rootPath: rootPath,
21271
+ rootUri: rootPath != null ? Uri.from({
21272
+ scheme: 'file',
21273
+ path: rootPath
21274
+ }).toString() : null
21275
+ });
20981
21276
 
20982
- if (method === lib$1.RegistrationRequest.type.method) {
20983
- const registrationParams = arguments.length <= 0 ? undefined : arguments[0];
20984
- registrationParams.registrations = registrationParams.registrations.filter(registration => {
20985
- const alreadyExisting = existingRegistrations.has(registration.id);
21277
+ return connection.initialize(fixedParams);
21278
+ },
20986
21279
 
20987
- if (alreadyExisting) {
20988
- console.warn('Registration already existing', registration.id, registration.method);
20989
- }
21280
+ onRequest() {
21281
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
21282
+ args[_key] = arguments[_key];
21283
+ }
20990
21284
 
20991
- return !alreadyExisting;
20992
- });
20993
- registrationParams.registrations.forEach(registration => {
20994
- existingRegistrations.add(registration.id);
20995
- });
20996
- }
21285
+ return connection.onRequest(args[0], function () {
21286
+ // Hack for https://github.com/OmniSharp/omnisharp-roslyn/issues/2119
21287
+ const method = args[0].method;
20997
21288
 
20998
- if (method === lib$1.UnregistrationRequest.type.method) {
20999
- const unregistrationParams = arguments.length <= 0 ? undefined : arguments[0];
21289
+ if (method === lib$1.RegistrationRequest.type.method) {
21290
+ const registrationParams = arguments.length <= 0 ? undefined : arguments[0];
21291
+ registrationParams.registrations = registrationParams.registrations.filter(registration => {
21292
+ const alreadyExisting = existingRegistrations.has(registration.id);
21000
21293
 
21001
- for (const unregistration of unregistrationParams.unregisterations) {
21002
- existingRegistrations.delete(unregistration.id);
21003
- }
21294
+ if (alreadyExisting) {
21295
+ console.warn('Registration already existing', registration.id, registration.method);
21004
21296
  }
21005
21297
 
21006
- return args[1](...arguments);
21298
+ return !alreadyExisting;
21007
21299
  });
21008
- },
21009
-
21010
- dispose: () => {
21011
- try {
21012
- connection.dispose();
21013
- } catch (error) {
21014
- // The dispose should NEVER fail or the lsp client is not properly cleaned
21015
- // see https://github.com/microsoft/vscode-languageserver-node/blob/master/client/src/client.ts#L3105
21016
- console.warn('[LSP]', 'Error while disposing connection', error);
21017
- } // Hack, when the language client is removed, the connection is disposed but the closeHandler is not always properly called
21018
- // The language client is then still active but without a proper connection and errors will occurs
21300
+ registrationParams.registrations.forEach(registration => {
21301
+ existingRegistrations.add(registration.id);
21302
+ });
21303
+ }
21019
21304
 
21305
+ if (method === lib$1.UnregistrationRequest.type.method) {
21306
+ const unregistrationParams = arguments.length <= 0 ? undefined : arguments[0];
21020
21307
 
21021
- closeHandler();
21022
- },
21023
- shutdown: async () => {
21024
- // The shutdown should NEVER fail or the connection is not closed and the lsp client is not properly cleaned
21025
- // see https://github.com/microsoft/vscode-languageserver-node/blob/master/client/src/client.ts#L3103
21026
- try {
21027
- await connection.shutdown();
21028
- } catch (error) {
21029
- console.warn('[LSP]', 'Error while shutdown lsp', error);
21308
+ for (const unregistration of unregistrationParams.unregisterations) {
21309
+ existingRegistrations.delete(unregistration.id);
21030
21310
  }
21031
21311
  }
21312
+
21313
+ return args[1](...arguments);
21032
21314
  });
21315
+ },
21033
21316
 
21034
- resolve(fixedConnection);
21035
- };
21317
+ dispose: () => {
21318
+ try {
21319
+ connection.dispose();
21320
+ } catch (error) {
21321
+ // The dispose should NEVER fail or the lsp client is not properly cleaned
21322
+ // see https://github.com/microsoft/vscode-languageserver-node/blob/master/client/src/client.ts#L3105
21323
+ console.warn('[LSP]', 'Error while disposing connection', error);
21324
+ } // Hack, when the language client is removed, the connection is disposed but the closeHandler is not always properly called
21325
+ // The language client is then still active but without a proper connection and errors will occurs
21036
21326
 
21037
- webSocket.onerror = () => {
21038
- reject(new Error('Unable to connect to server'));
21039
- };
21327
+
21328
+ closeHandler();
21329
+ },
21330
+ shutdown: async () => {
21331
+ // The shutdown should NEVER fail or the connection is not closed and the lsp client is not properly cleaned
21332
+ // see https://github.com/microsoft/vscode-languageserver-node/blob/master/client/src/client.ts#L3103
21333
+ try {
21334
+ await connection.shutdown();
21335
+ } catch (error) {
21336
+ console.warn('[LSP]', 'Error while shutdown lsp', error);
21337
+ }
21338
+ }
21040
21339
  });
21340
+
21341
+ return fixedConnection;
21041
21342
  }
21042
21343
 
21043
21344
  const RETRY_DELAY = 3000;
21044
21345
 
21045
21346
  class CGLSPConnectionProvider {
21046
- constructor(serverAddress, id, sessionId, libraryUrls, getSecurityToken) {
21047
- this.serverAddress = serverAddress;
21347
+ constructor(id, infrastructure) {
21048
21348
  this.id = id;
21049
- this.sessionId = sessionId;
21050
- this.libraryUrls = libraryUrls;
21051
- this.getSecurityToken = getSecurityToken;
21349
+ this.infrastructure = infrastructure;
21052
21350
  }
21053
21351
 
21054
21352
  async get(errorHandler, closeHandler) {
21055
- const onceDelayedCloseHandler = once(() => {
21353
+ const onceDelayedCloseHandler = once$1(() => {
21056
21354
  setTimeout(() => {
21057
21355
  closeHandler();
21058
21356
  }, RETRY_DELAY);
21059
21357
  });
21060
21358
 
21061
21359
  try {
21062
- const path = this.sessionId != null ? "run/".concat(this.sessionId, "/").concat(this.id) : "run/".concat(this.id);
21063
- const url = new URL(path, this.serverAddress);
21064
- this.libraryUrls.forEach(libraryUrl => url.searchParams.append('libraryUrl', libraryUrl));
21065
- url.searchParams.append('token', await this.getSecurityToken());
21066
- return await openConnection(url, errorHandler, onceDelayedCloseHandler);
21360
+ const connection = await this.infrastructure.openConnection(this.id);
21361
+ return await messageConnectionToConnection(connection, errorHandler, onceDelayedCloseHandler);
21067
21362
  } catch (err) {
21068
21363
  onceDelayedCloseHandler();
21069
21364
  throw err;
@@ -21072,7 +21367,7 @@ class CGLSPConnectionProvider {
21072
21367
 
21073
21368
  }
21074
21369
 
21075
- function createLanguageClient(id, sessionId, _ref, languageServerAddress, getSecurityToken, libraryUrls, errorHandler, middleware) {
21370
+ function createLanguageClient(id, infrastructure, _ref, errorHandler, middleware) {
21076
21371
  let {
21077
21372
  documentSelector,
21078
21373
  synchronize,
@@ -21090,7 +21385,7 @@ function createLanguageClient(id, sessionId, _ref, languageServerAddress, getSec
21090
21385
  synchronize,
21091
21386
  initializationOptions
21092
21387
  },
21093
- connectionProvider: new CGLSPConnectionProvider(languageServerAddress, id, sessionId, libraryUrls, getSecurityToken)
21388
+ connectionProvider: new CGLSPConnectionProvider(id, infrastructure)
21094
21389
  });
21095
21390
  client.registerProposedFeatures();
21096
21391
  registerExtensionFeatures(client, id);
@@ -21098,14 +21393,10 @@ function createLanguageClient(id, sessionId, _ref, languageServerAddress, getSec
21098
21393
  }
21099
21394
 
21100
21395
  class LanguageClientManager {
21101
- constructor(id, sessionId, languageServerAddress, getSecurityToken, languageServerOptions, libraryUrls, useMutualizedProxy) {
21396
+ constructor(id, languageServerOptions, infrastructure) {
21102
21397
  this.id = id;
21103
- this.sessionId = sessionId;
21104
- this.languageServerAddress = languageServerAddress;
21105
- this.getSecurityToken = getSecurityToken;
21106
21398
  this.languageServerOptions = languageServerOptions;
21107
- this.libraryUrls = libraryUrls;
21108
- this.useMutualizedProxy = useMutualizedProxy;
21399
+ this.infrastructure = infrastructure;
21109
21400
 
21110
21401
  _defineProperty(this, "languageClient", void 0);
21111
21402
 
@@ -21192,7 +21483,7 @@ class LanguageClientManager {
21192
21483
 
21193
21484
  async start() {
21194
21485
  try {
21195
- await loadExtensionConfigurations([this.id], this.useMutualizedProxy);
21486
+ await loadExtensionConfigurations([this.id], this.infrastructure.useMutualizedProxy);
21196
21487
  } catch (error) {
21197
21488
  console.error('Unable to load extension configuration', error);
21198
21489
  }
@@ -21206,7 +21497,7 @@ class LanguageClientManager {
21206
21497
  var _this$languageServerO;
21207
21498
 
21208
21499
  const onServerResponse = new lib$1.Emitter();
21209
- const languageClient = createLanguageClient(this.id, this.sessionId, this.languageServerOptions, this.languageServerAddress, this.getSecurityToken, this.libraryUrls, {
21500
+ const languageClient = createLanguageClient(this.id, this.infrastructure, this.languageServerOptions, {
21210
21501
  error: this.handleError,
21211
21502
  closed: this.handleClose
21212
21503
  }, _objectSpread2(_objectSpread2({}, (_this$languageServerO = this.languageServerOptions.middleware) !== null && _this$languageServerO !== void 0 ? _this$languageServerO : {}), {}, {
@@ -21322,15 +21613,20 @@ class LanguageClientManager {
21322
21613
  }
21323
21614
  });
21324
21615
  this.languageClient.registerFeature(new WillDisposeFeature(this.languageClient, this.onWillShutdownEmitter));
21616
+
21617
+ if (!this.infrastructure.automaticTextDocumentUpdate) {
21618
+ this.languageClient.registerFeature(new InitializeTextDocumentFeature(this));
21619
+ }
21620
+
21325
21621
  this.languageClient.start();
21326
21622
  }
21327
21623
 
21328
- sendNotification(method, params) {
21329
- this.languageClient.sendNotification(method, params);
21624
+ sendNotification(type, params) {
21625
+ this.languageClient.sendNotification(type, params);
21330
21626
  }
21331
21627
 
21332
- sendRequest(method, params) {
21333
- return this.languageClient.sendRequest(method, params);
21628
+ sendRequest(type, params) {
21629
+ return this.languageClient.sendRequest(type, params);
21334
21630
  }
21335
21631
 
21336
21632
  }
@@ -21338,17 +21634,12 @@ const languageClientManagerByLanguageId = {};
21338
21634
  /**
21339
21635
  * Create a language client manager
21340
21636
  * @param id The predefined id of the language client
21341
- * @param sessionId An optional sessionId when connecting to the session-mutualized server
21342
- * @param languageServerAddress The domain of the server
21343
- * @param getSecurityToken A function which returns a valid JWT token to use to connect to the server
21344
- * @param libraryUrls A list of urls which link to zip files containing libraries/resources
21345
- * @param useMutualizedProxy The language server proxy is used, so we only need to load configurations for language servers which are not mutualized
21637
+ * @param infrastructure The infrastructure to use
21638
+ * @param parameters the infrastructure parameters
21346
21639
  * @returns A language client manager
21347
21640
  */
21348
21641
 
21349
- function createLanguageClientManager(id, sessionId, languageServerAddress, getSecurityToken, libraryUrls) {
21350
- let useMutualizedProxy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : languageServerAddress.includes('mutualized');
21351
-
21642
+ function createLanguageClientManager(id, infrastructure) {
21352
21643
  if (languageClientManagerByLanguageId[id] != null) {
21353
21644
  throw new Error("Language client for language ".concat(id, " already started"));
21354
21645
  }
@@ -21359,7 +21650,7 @@ function createLanguageClientManager(id, sessionId, languageServerAddress, getSe
21359
21650
  throw new Error("Unknown ".concat(id, " language server"));
21360
21651
  }
21361
21652
 
21362
- if (useMutualizedProxy && languageServerOptions.mutualizable) {
21653
+ if (infrastructure.useMutualizedProxy && languageServerOptions.mutualizable) {
21363
21654
  // When using the mutualized proxy, we don't need to synchronize the configuration nor send the initialization options
21364
21655
  languageServerOptions = _objectSpread2(_objectSpread2({}, languageServerOptions), {}, {
21365
21656
  synchronize: undefined,
@@ -21367,34 +21658,32 @@ function createLanguageClientManager(id, sessionId, languageServerAddress, getSe
21367
21658
  });
21368
21659
  }
21369
21660
 
21370
- installServices();
21371
- const languageClientManager = new LanguageClientManager(id, sessionId, languageServerAddress, getSecurityToken, languageServerOptions, libraryUrls, useMutualizedProxy);
21661
+ const services = installServices(infrastructure);
21662
+ const disposableCollection = new lib$1.DisposableCollection();
21663
+ const languageClientManager = new LanguageClientManager(id, languageServerOptions, infrastructure);
21372
21664
  languageClientManagerByLanguageId[id] = languageClientManager;
21373
- const textModelContentProviderDisposable = registerTextModelContentProvider('file', {
21665
+ disposableCollection.push(lib$1.Disposable.create(() => {
21666
+ delete languageClientManagerByLanguageId[id];
21667
+ }));
21668
+ disposableCollection.push(registerTextModelContentProvider('file', {
21374
21669
  async provideTextContent(resource) {
21375
- try {
21376
- const content = (await getFile(resource.toString(true), languageClientManager)).text;
21377
- return monaco.editor.createModel(content, undefined, resource);
21378
- } catch (error) {
21379
- // file not found
21380
- return null;
21381
- }
21670
+ const content = await infrastructure.getFileContent(resource, languageClientManager);
21671
+ return content != null ? monaco.editor.createModel(content, undefined, resource) : null;
21382
21672
  }
21383
21673
 
21384
- });
21674
+ }));
21675
+ disposableCollection.push(services.workspace.registerSaveDocumentHandler({
21676
+ async saveTextContent(textDocument, reason) {
21677
+ var _infrastructure$saveF;
21678
+
21679
+ await ((_infrastructure$saveF = infrastructure.saveFileContent) === null || _infrastructure$saveF === void 0 ? void 0 : _infrastructure$saveF.call(infrastructure, textDocument, reason, languageClientManager));
21680
+ }
21681
+
21682
+ }));
21385
21683
  languageClientManager.onWillClose(() => {
21386
- delete languageClientManagerByLanguageId[id];
21387
- textModelContentProviderDisposable.dispose();
21684
+ disposableCollection.dispose();
21388
21685
  });
21389
21686
  return languageClientManager;
21390
21687
  }
21391
21688
 
21392
- function getAllLanguageClientManagers() {
21393
- return Object.values(languageClientManagerByLanguageId);
21394
- }
21395
-
21396
- function getAllLanguageClientManagersByTextDocument(textDocument) {
21397
- return getAllLanguageClientManagers().filter(manager => manager.isModelManaged(textDocument));
21398
- }
21399
-
21400
- export { LanguageClientManager, createLanguageClientManager, loadExtensionConfigurations, registerLanguageClient };
21689
+ export { CodinGameInfrastructure, LanguageClientManager, createLanguageClientManager, loadExtensionConfigurations, registerLanguageClient };