@lvce-editor/editor-worker 6.0.0 → 6.2.0

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.
@@ -13,6 +13,389 @@ const execute$1 = (command, ...args) => {
13
13
  return fn(...args);
14
14
  };
15
15
 
16
+ const state$9 = {
17
+ /**
18
+ * @type {any}
19
+ */
20
+ ipc: undefined
21
+ };
22
+ const get$7 = () => {
23
+ return state$9.ipc;
24
+ };
25
+ const set$7 = ipc => {
26
+ state$9.ipc = ipc;
27
+ };
28
+
29
+ const Two = '2.0';
30
+ const create$4$1 = (method, params) => {
31
+ return {
32
+ jsonrpc: Two,
33
+ method,
34
+ params
35
+ };
36
+ };
37
+ const callbacks = Object.create(null);
38
+ const set$6 = (id, fn) => {
39
+ callbacks[id] = fn;
40
+ };
41
+ const get$6 = id => {
42
+ return callbacks[id];
43
+ };
44
+ const remove$8 = id => {
45
+ delete callbacks[id];
46
+ };
47
+ let id = 0;
48
+ const create$3$1 = () => {
49
+ return ++id;
50
+ };
51
+ const registerPromise = () => {
52
+ const id = create$3$1();
53
+ const {
54
+ resolve,
55
+ promise
56
+ } = Promise.withResolvers();
57
+ set$6(id, resolve);
58
+ return {
59
+ id,
60
+ promise
61
+ };
62
+ };
63
+ const create$2$1 = (method, params) => {
64
+ const {
65
+ id,
66
+ promise
67
+ } = registerPromise();
68
+ const message = {
69
+ jsonrpc: Two,
70
+ method,
71
+ params,
72
+ id
73
+ };
74
+ return {
75
+ message,
76
+ promise
77
+ };
78
+ };
79
+ class JsonRpcError extends Error {
80
+ constructor(message) {
81
+ super(message);
82
+ this.name = 'JsonRpcError';
83
+ }
84
+ }
85
+ const NewLine$3 = '\n';
86
+ const DomException = 'DOMException';
87
+ const ReferenceError$1 = 'ReferenceError';
88
+ const SyntaxError$1 = 'SyntaxError';
89
+ const TypeError$1 = 'TypeError';
90
+ const getErrorConstructor = (message, type) => {
91
+ if (type) {
92
+ switch (type) {
93
+ case DomException:
94
+ return DOMException;
95
+ case TypeError$1:
96
+ return TypeError;
97
+ case SyntaxError$1:
98
+ return SyntaxError;
99
+ case ReferenceError$1:
100
+ return ReferenceError;
101
+ default:
102
+ return Error;
103
+ }
104
+ }
105
+ if (message.startsWith('TypeError: ')) {
106
+ return TypeError;
107
+ }
108
+ if (message.startsWith('SyntaxError: ')) {
109
+ return SyntaxError;
110
+ }
111
+ if (message.startsWith('ReferenceError: ')) {
112
+ return ReferenceError;
113
+ }
114
+ return Error;
115
+ };
116
+ const constructError = (message, type, name) => {
117
+ const ErrorConstructor = getErrorConstructor(message, type);
118
+ if (ErrorConstructor === DOMException && name) {
119
+ return new ErrorConstructor(message, name);
120
+ }
121
+ if (ErrorConstructor === Error) {
122
+ const error = new Error(message);
123
+ if (name && name !== 'VError') {
124
+ error.name = name;
125
+ }
126
+ return error;
127
+ }
128
+ return new ErrorConstructor(message);
129
+ };
130
+ const getNewLineIndex$1 = (string, startIndex = undefined) => {
131
+ return string.indexOf(NewLine$3, startIndex);
132
+ };
133
+ const getParentStack = error => {
134
+ let parentStack = error.stack || error.data || error.message || '';
135
+ if (parentStack.startsWith(' at')) {
136
+ parentStack = error.message + NewLine$3 + parentStack;
137
+ }
138
+ return parentStack;
139
+ };
140
+ const joinLines$2 = lines => {
141
+ return lines.join(NewLine$3);
142
+ };
143
+ const MethodNotFound = -32601;
144
+ const Custom = -32001;
145
+ const splitLines$2 = lines => {
146
+ return lines.split(NewLine$3);
147
+ };
148
+ const restoreJsonRpcError = error => {
149
+ if (error && error instanceof Error) {
150
+ return error;
151
+ }
152
+ const currentStack = joinLines$2(splitLines$2(new Error().stack || '').slice(1));
153
+ if (error && error.code && error.code === MethodNotFound) {
154
+ const restoredError = new JsonRpcError(error.message);
155
+ const parentStack = getParentStack(error);
156
+ restoredError.stack = parentStack + NewLine$3 + currentStack;
157
+ return restoredError;
158
+ }
159
+ if (error && error.message) {
160
+ const restoredError = constructError(error.message, error.type, error.name);
161
+ if (error.data) {
162
+ if (error.data.stack && error.data.type && error.message) {
163
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine$3 + error.data.stack + NewLine$3 + currentStack;
164
+ } else if (error.data.stack) {
165
+ restoredError.stack = error.data.stack;
166
+ }
167
+ if (error.data.codeFrame) {
168
+ // @ts-ignore
169
+ restoredError.codeFrame = error.data.codeFrame;
170
+ }
171
+ if (error.data.code) {
172
+ // @ts-ignore
173
+ restoredError.code = error.data.code;
174
+ }
175
+ if (error.data.type) {
176
+ // @ts-ignore
177
+ restoredError.name = error.data.type;
178
+ }
179
+ } else {
180
+ if (error.stack) {
181
+ const lowerStack = restoredError.stack || '';
182
+ // @ts-ignore
183
+ const indexNewLine = getNewLineIndex$1(lowerStack);
184
+ const parentStack = getParentStack(error);
185
+ // @ts-ignore
186
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
187
+ }
188
+ if (error.codeFrame) {
189
+ // @ts-ignore
190
+ restoredError.codeFrame = error.codeFrame;
191
+ }
192
+ }
193
+ return restoredError;
194
+ }
195
+ if (typeof error === 'string') {
196
+ return new Error(`JsonRpc Error: ${error}`);
197
+ }
198
+ return new Error(`JsonRpc Error: ${error}`);
199
+ };
200
+ const unwrapJsonRpcResult = responseMessage => {
201
+ if ('error' in responseMessage) {
202
+ const restoredError = restoreJsonRpcError(responseMessage.error);
203
+ throw restoredError;
204
+ }
205
+ if ('result' in responseMessage) {
206
+ return responseMessage.result;
207
+ }
208
+ throw new JsonRpcError('unexpected response message');
209
+ };
210
+ const warn$1 = (...args) => {
211
+ console.warn(...args);
212
+ };
213
+ const resolve = (id, response) => {
214
+ const fn = get$6(id);
215
+ if (!fn) {
216
+ console.log(response);
217
+ warn$1(`callback ${id} may already be disposed`);
218
+ return;
219
+ }
220
+ fn(response);
221
+ remove$8(id);
222
+ };
223
+ const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
224
+ const getErrorType = prettyError => {
225
+ if (prettyError && prettyError.type) {
226
+ return prettyError.type;
227
+ }
228
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
229
+ return prettyError.constructor.name;
230
+ }
231
+ return undefined;
232
+ };
233
+ const getErrorProperty = (error, prettyError) => {
234
+ if (error && error.code === E_COMMAND_NOT_FOUND) {
235
+ return {
236
+ code: MethodNotFound,
237
+ message: error.message,
238
+ data: error.stack
239
+ };
240
+ }
241
+ return {
242
+ code: Custom,
243
+ message: prettyError.message,
244
+ data: {
245
+ stack: prettyError.stack,
246
+ codeFrame: prettyError.codeFrame,
247
+ type: getErrorType(prettyError),
248
+ code: prettyError.code,
249
+ name: prettyError.name
250
+ }
251
+ };
252
+ };
253
+ const create$1$1 = (message, error) => {
254
+ return {
255
+ jsonrpc: Two,
256
+ id: message.id,
257
+ error
258
+ };
259
+ };
260
+ const getErrorResponse = (message, error, preparePrettyError, logError) => {
261
+ const prettyError = preparePrettyError(error);
262
+ logError(error, prettyError);
263
+ const errorProperty = getErrorProperty(error, prettyError);
264
+ return create$1$1(message, errorProperty);
265
+ };
266
+ const create$e = (message, result) => {
267
+ return {
268
+ jsonrpc: Two,
269
+ id: message.id,
270
+ result: result ?? null
271
+ };
272
+ };
273
+ const getSuccessResponse = (message, result) => {
274
+ const resultProperty = result ?? null;
275
+ return create$e(message, resultProperty);
276
+ };
277
+ const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
278
+ try {
279
+ const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
280
+ return getSuccessResponse(message, result);
281
+ } catch (error) {
282
+ return getErrorResponse(message, error, preparePrettyError, logError);
283
+ }
284
+ };
285
+ const defaultPreparePrettyError = error => {
286
+ return error;
287
+ };
288
+ const defaultLogError = () => {
289
+ // ignore
290
+ };
291
+ const defaultRequiresSocket = () => {
292
+ return false;
293
+ };
294
+ const defaultResolve = resolve;
295
+
296
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
297
+ const normalizeParams = args => {
298
+ if (args.length === 1) {
299
+ const options = args[0];
300
+ return {
301
+ ipc: options.ipc,
302
+ message: options.message,
303
+ execute: options.execute,
304
+ resolve: options.resolve || defaultResolve,
305
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
306
+ logError: options.logError || defaultLogError,
307
+ requiresSocket: options.requiresSocket || defaultRequiresSocket
308
+ };
309
+ }
310
+ return {
311
+ ipc: args[0],
312
+ message: args[1],
313
+ execute: args[2],
314
+ resolve: args[3],
315
+ preparePrettyError: args[4],
316
+ logError: args[5],
317
+ requiresSocket: args[6]
318
+ };
319
+ };
320
+ const handleJsonRpcMessage = async (...args) => {
321
+ const options = normalizeParams(args);
322
+ const {
323
+ message,
324
+ ipc,
325
+ execute,
326
+ resolve,
327
+ preparePrettyError,
328
+ logError,
329
+ requiresSocket
330
+ } = options;
331
+ if ('id' in message) {
332
+ if ('method' in message) {
333
+ const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
334
+ try {
335
+ ipc.send(response);
336
+ } catch (error) {
337
+ const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
338
+ ipc.send(errorResponse);
339
+ }
340
+ return;
341
+ }
342
+ resolve(message.id, message);
343
+ return;
344
+ }
345
+ if ('method' in message) {
346
+ await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
347
+ return;
348
+ }
349
+ throw new JsonRpcError('unexpected message');
350
+ };
351
+ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
352
+ const {
353
+ message,
354
+ promise
355
+ } = create$2$1(method, params);
356
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
357
+ ipc.sendAndTransfer(message);
358
+ } else {
359
+ ipc.send(message);
360
+ }
361
+ const responseMessage = await promise;
362
+ return unwrapJsonRpcResult(responseMessage);
363
+ };
364
+ const send = (transport, method, ...params) => {
365
+ const message = create$4$1(method, params);
366
+ transport.send(message);
367
+ };
368
+ const invoke$7 = (ipc, method, ...params) => {
369
+ return invokeHelper(ipc, method, params, false);
370
+ };
371
+ const invokeAndTransfer$2 = (ipc, method, ...params) => {
372
+ return invokeHelper(ipc, method, params, true);
373
+ };
374
+
375
+ const invoke$6 = async (method, ...params) => {
376
+ const ipc = get$7();
377
+ return invoke$7(ipc, method, ...params);
378
+ };
379
+ const invokeAndTransfer$1 = async (method, ...params) => {
380
+ const ipc = get$7();
381
+ return invokeAndTransfer$2(ipc, method, ...params);
382
+ };
383
+ const listen$5 = ipc => {
384
+ set$7(ipc);
385
+ };
386
+
387
+ const invoke$5 = async (method, ...params) => {
388
+ return invoke$6(method, ...params);
389
+ };
390
+ const invokeAndTransfer = async (method, ...params) => {
391
+ return invokeAndTransfer$1(method, ...params);
392
+ };
393
+
394
+ // TODO add tests for this
395
+ const activateByEvent = async event => {
396
+ await invoke$5('ExtensionHostManagement.activateByEvent', event);
397
+ };
398
+
16
399
  const codeGeneratorAccept = state => {
17
400
  // TODO close code generator widget
18
401
  return state;
@@ -34,16 +417,16 @@ const getCombinedMessage = (error, message) => {
34
417
  }
35
418
  return stringifiedError;
36
419
  };
37
- const NewLine$3 = '\n';
38
- const getNewLineIndex$1 = (string, startIndex = undefined) => {
39
- return string.indexOf(NewLine$3, startIndex);
420
+ const NewLine$2 = '\n';
421
+ const getNewLineIndex = (string, startIndex = undefined) => {
422
+ return string.indexOf(NewLine$2, startIndex);
40
423
  };
41
424
  const mergeStacks = (parent, child) => {
42
425
  if (!child) {
43
426
  return parent;
44
427
  }
45
- const parentNewLineIndex = getNewLineIndex$1(parent);
46
- const childNewLineIndex = getNewLineIndex$1(child);
428
+ const parentNewLineIndex = getNewLineIndex(parent);
429
+ const childNewLineIndex = getNewLineIndex(child);
47
430
  if (childNewLineIndex === -1) {
48
431
  return parent;
49
432
  }
@@ -206,9 +589,9 @@ class Ipc extends EventTarget {
206
589
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
207
590
  const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
208
591
  const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
209
- const NewLine$2 = '\n';
210
- const joinLines$2 = lines => {
211
- return lines.join(NewLine$2);
592
+ const NewLine$1 = '\n';
593
+ const joinLines$1 = lines => {
594
+ return lines.join(NewLine$1);
212
595
  };
213
596
  const RE_AT = /^\s+at/;
214
597
  const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
@@ -219,7 +602,7 @@ const getDetails = lines => {
219
602
  const index = lines.findIndex(isNormalStackLine);
220
603
  if (index === -1) {
221
604
  return {
222
- actualMessage: joinLines$2(lines),
605
+ actualMessage: joinLines$1(lines),
223
606
  rest: []
224
607
  };
225
608
  }
@@ -234,8 +617,8 @@ const getDetails = lines => {
234
617
  rest: lines.slice(index, lastIndex)
235
618
  };
236
619
  };
237
- const splitLines$2 = lines => {
238
- return lines.split(NewLine$2);
620
+ const splitLines$1 = lines => {
621
+ return lines.split(NewLine$1);
239
622
  };
240
623
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
241
624
  const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
@@ -246,7 +629,7 @@ const isMessageCodeBlockEndIndex = line => {
246
629
  return RE_MESSAGE_CODE_BLOCK_END.test(line);
247
630
  };
248
631
  const getMessageCodeBlock = stderr => {
249
- const lines = splitLines$2(stderr);
632
+ const lines = splitLines$1(stderr);
250
633
  const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
251
634
  const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
252
635
  const relevantLines = lines.slice(startIndex, endIndex);
@@ -257,7 +640,7 @@ const isModuleNotFoundMessage = line => {
257
640
  return line.includes('[ERR_MODULE_NOT_FOUND]');
258
641
  };
259
642
  const getModuleNotFoundError = stderr => {
260
- const lines = splitLines$2(stderr);
643
+ const lines = splitLines$1(stderr);
261
644
  const messageIndex = lines.findIndex(isModuleNotFoundMessage);
262
645
  const message = lines[messageIndex];
263
646
  return {
@@ -305,7 +688,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
305
688
  if (isModuleNotFoundError(stderr)) {
306
689
  return getModuleNotFoundError(stderr);
307
690
  }
308
- const lines = splitLines$2(stderr);
691
+ const lines = splitLines$1(stderr);
309
692
  const {
310
693
  actualMessage,
311
694
  rest
@@ -336,232 +719,28 @@ let IpcError$1 = class IpcError extends VError {
336
719
  }
337
720
  // @ts-ignore
338
721
  this.name = 'IpcError';
339
- // @ts-ignore
340
- this.stdout = stdout;
341
- // @ts-ignore
342
- this.stderr = stderr;
343
- }
344
- };
345
- const readyMessage = 'ready';
346
- const getData$2 = event => {
347
- return event.data;
348
- };
349
- const listen$8 = ({
350
- port
351
- }) => {
352
- return port;
353
- };
354
- const signal$9 = port => {
355
- port.postMessage(readyMessage);
356
- };
357
- class IpcChildWithMessagePort extends Ipc {
358
- getData(event) {
359
- return getData$2(event);
360
- }
361
- send(message) {
362
- this._rawIpc.postMessage(message);
363
- }
364
- sendAndTransfer(message) {
365
- const transfer = getTransferrables(message);
366
- this._rawIpc.postMessage(message, transfer);
367
- }
368
- dispose() {
369
- // ignore
370
- }
371
- onClose(callback) {
372
- // ignore
373
- }
374
- onMessage(callback) {
375
- this._rawIpc.addEventListener('message', callback);
376
- this._rawIpc.start();
377
- }
378
- }
379
- const wrap$g = port => {
380
- return new IpcChildWithMessagePort(port);
381
- };
382
- const IpcChildWithMessagePort$1 = {
383
- __proto__: null,
384
- listen: listen$8,
385
- signal: signal$9,
386
- wrap: wrap$g
387
- };
388
- const listen$7 = () => {
389
- // @ts-ignore
390
- if (typeof WorkerGlobalScope === 'undefined') {
391
- throw new TypeError('module is not in web worker scope');
392
- }
393
- return globalThis;
394
- };
395
- const signal$8 = global => {
396
- global.postMessage(readyMessage);
397
- };
398
- class IpcChildWithModuleWorker extends Ipc {
399
- getData(event) {
400
- return getData$2(event);
401
- }
402
- send(message) {
403
- // @ts-ignore
404
- this._rawIpc.postMessage(message);
405
- }
406
- sendAndTransfer(message) {
407
- const transfer = getTransferrables(message);
408
- // @ts-ignore
409
- this._rawIpc.postMessage(message, transfer);
410
- }
411
- dispose() {
412
- // ignore
413
- }
414
- onClose(callback) {
415
- // ignore
416
- }
417
- onMessage(callback) {
418
- this._rawIpc.addEventListener('message', callback);
419
- }
420
- }
421
- const wrap$f = global => {
422
- return new IpcChildWithModuleWorker(global);
423
- };
424
- const IpcChildWithModuleWorker$1 = {
425
- __proto__: null,
426
- listen: listen$7,
427
- signal: signal$8,
428
- wrap: wrap$f
429
- };
430
- const waitForFirstMessage$1 = async port => {
431
- const {
432
- resolve,
433
- promise
434
- } = Promise.withResolvers();
435
- port.addEventListener('message', resolve, {
436
- once: true
437
- });
438
- const event = await promise;
439
- // @ts-ignore
440
- return event.data;
441
- };
442
- const listen$6 = async () => {
443
- const parentIpcRaw = listen$7();
444
- signal$8(parentIpcRaw);
445
- const parentIpc = wrap$f(parentIpcRaw);
446
- const firstMessage = await waitForFirstMessage$1(parentIpc);
447
- if (firstMessage.method !== 'initialize') {
448
- throw new IpcError$1('unexpected first message');
449
- }
450
- const type = firstMessage.params[0];
451
- if (type === 'message-port') {
452
- parentIpc.send({
453
- jsonrpc: '2.0',
454
- id: firstMessage.id,
455
- result: null
456
- });
457
- parentIpc.dispose();
458
- const port = firstMessage.params[1];
459
- return port;
460
- }
461
- return globalThis;
462
- };
463
- class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
464
- getData(event) {
465
- return getData$2(event);
466
- }
467
- send(message) {
468
- this._rawIpc.postMessage(message);
469
- }
470
- sendAndTransfer(message) {
471
- const transfer = getTransferrables(message);
472
- this._rawIpc.postMessage(message, transfer);
473
- }
474
- dispose() {
475
- if (this._rawIpc.close) {
476
- this._rawIpc.close();
477
- }
478
- }
479
- onClose(callback) {
480
- // ignore
481
- }
482
- onMessage(callback) {
483
- this._rawIpc.addEventListener('message', callback);
484
- this._rawIpc.start();
485
- }
486
- }
487
- const wrap$e = port => {
488
- return new IpcChildWithModuleWorkerAndMessagePort(port);
489
- };
490
- const IpcChildWithModuleWorkerAndMessagePort$1 = {
491
- __proto__: null,
492
- listen: listen$6,
493
- wrap: wrap$e
494
- };
495
- const addListener = (emitter, type, callback) => {
496
- if ('addEventListener' in emitter) {
497
- emitter.addEventListener(type, callback);
498
- } else {
499
- emitter.on(type, callback);
500
- }
501
- };
502
- const removeListener = (emitter, type, callback) => {
503
- if ('removeEventListener' in emitter) {
504
- emitter.removeEventListener(type, callback);
505
- } else {
506
- emitter.off(type, callback);
507
- }
508
- };
509
- const getFirstEvent = (eventEmitter, eventMap) => {
510
- const {
511
- resolve,
512
- promise
513
- } = Promise.withResolvers();
514
- const listenerMap = Object.create(null);
515
- const cleanup = value => {
516
- for (const event of Object.keys(eventMap)) {
517
- removeListener(eventEmitter, event, listenerMap[event]);
518
- }
519
- resolve(value);
520
- };
521
- for (const [event, type] of Object.entries(eventMap)) {
522
- const listener = event => {
523
- cleanup({
524
- type,
525
- event
526
- });
527
- };
528
- addListener(eventEmitter, event, listener);
529
- listenerMap[event] = listener;
722
+ // @ts-ignore
723
+ this.stdout = stdout;
724
+ // @ts-ignore
725
+ this.stderr = stderr;
530
726
  }
531
- return promise;
532
727
  };
533
- const Message$1 = 3;
534
- const create$5$1 = async ({
535
- messagePort,
536
- isMessagePortOpen
728
+ const readyMessage = 'ready';
729
+ const getData$2 = event => {
730
+ return event.data;
731
+ };
732
+ const listen$8 = ({
733
+ port
537
734
  }) => {
538
- if (!isMessagePort(messagePort)) {
539
- throw new IpcError$1('port must be of type MessagePort');
540
- }
541
- if (isMessagePortOpen) {
542
- return messagePort;
543
- }
544
- const eventPromise = getFirstEvent(messagePort, {
545
- message: Message$1
546
- });
547
- messagePort.start();
548
- const {
549
- type,
550
- event
551
- } = await eventPromise;
552
- if (type !== Message$1) {
553
- throw new IpcError$1('Failed to wait for ipc message');
554
- }
555
- if (event.data !== readyMessage) {
556
- throw new IpcError$1('unexpected first message');
557
- }
558
- return messagePort;
735
+ return port;
559
736
  };
560
- const signal$1 = messagePort => {
561
- messagePort.start();
737
+ const signal$9 = port => {
738
+ port.postMessage(readyMessage);
562
739
  };
563
- class IpcParentWithMessagePort extends Ipc {
564
- getData = getData$2;
740
+ class IpcChildWithMessagePort extends Ipc {
741
+ getData(event) {
742
+ return getData$2(event);
743
+ }
565
744
  send(message) {
566
745
  this._rawIpc.postMessage(message);
567
746
  }
@@ -570,367 +749,225 @@ class IpcParentWithMessagePort extends Ipc {
570
749
  this._rawIpc.postMessage(message, transfer);
571
750
  }
572
751
  dispose() {
573
- this._rawIpc.close();
752
+ // ignore
753
+ }
754
+ onClose(callback) {
755
+ // ignore
574
756
  }
575
757
  onMessage(callback) {
576
758
  this._rawIpc.addEventListener('message', callback);
759
+ this._rawIpc.start();
577
760
  }
578
- onClose(callback) {}
579
761
  }
580
- const wrap$5 = messagePort => {
581
- return new IpcParentWithMessagePort(messagePort);
762
+ const wrap$g = port => {
763
+ return new IpcChildWithMessagePort(port);
582
764
  };
583
- const IpcParentWithMessagePort$1 = {
765
+ const IpcChildWithMessagePort$1 = {
584
766
  __proto__: null,
585
- create: create$5$1,
586
- signal: signal$1,
587
- wrap: wrap$5
588
- };
589
-
590
- const Two = '2.0';
591
- const create$4$1 = (method, params) => {
592
- return {
593
- jsonrpc: Two,
594
- method,
595
- params
596
- };
597
- };
598
- const callbacks = Object.create(null);
599
- const set$7 = (id, fn) => {
600
- callbacks[id] = fn;
601
- };
602
- const get$7 = id => {
603
- return callbacks[id];
604
- };
605
- const remove$8 = id => {
606
- delete callbacks[id];
607
- };
608
- let id = 0;
609
- const create$3$1 = () => {
610
- return ++id;
767
+ listen: listen$8,
768
+ signal: signal$9,
769
+ wrap: wrap$g
611
770
  };
612
- const registerPromise = () => {
613
- const id = create$3$1();
614
- const {
615
- resolve,
616
- promise
617
- } = Promise.withResolvers();
618
- set$7(id, resolve);
619
- return {
620
- id,
621
- promise
622
- };
771
+ const listen$7 = () => {
772
+ // @ts-ignore
773
+ if (typeof WorkerGlobalScope === 'undefined') {
774
+ throw new TypeError('module is not in web worker scope');
775
+ }
776
+ return globalThis;
623
777
  };
624
- const create$2$1 = (method, params) => {
625
- const {
626
- id,
627
- promise
628
- } = registerPromise();
629
- const message = {
630
- jsonrpc: Two,
631
- method,
632
- params,
633
- id
634
- };
635
- return {
636
- message,
637
- promise
638
- };
778
+ const signal$8 = global => {
779
+ global.postMessage(readyMessage);
639
780
  };
640
- class JsonRpcError extends Error {
641
- constructor(message) {
642
- super(message);
643
- this.name = 'JsonRpcError';
644
- }
645
- }
646
- const NewLine$1 = '\n';
647
- const DomException = 'DOMException';
648
- const ReferenceError$1 = 'ReferenceError';
649
- const SyntaxError$1 = 'SyntaxError';
650
- const TypeError$1 = 'TypeError';
651
- const getErrorConstructor = (message, type) => {
652
- if (type) {
653
- switch (type) {
654
- case DomException:
655
- return DOMException;
656
- case TypeError$1:
657
- return TypeError;
658
- case SyntaxError$1:
659
- return SyntaxError;
660
- case ReferenceError$1:
661
- return ReferenceError;
662
- default:
663
- return Error;
664
- }
665
- }
666
- if (message.startsWith('TypeError: ')) {
667
- return TypeError;
781
+ class IpcChildWithModuleWorker extends Ipc {
782
+ getData(event) {
783
+ return getData$2(event);
668
784
  }
669
- if (message.startsWith('SyntaxError: ')) {
670
- return SyntaxError;
785
+ send(message) {
786
+ // @ts-ignore
787
+ this._rawIpc.postMessage(message);
671
788
  }
672
- if (message.startsWith('ReferenceError: ')) {
673
- return ReferenceError;
789
+ sendAndTransfer(message) {
790
+ const transfer = getTransferrables(message);
791
+ // @ts-ignore
792
+ this._rawIpc.postMessage(message, transfer);
674
793
  }
675
- return Error;
676
- };
677
- const constructError = (message, type, name) => {
678
- const ErrorConstructor = getErrorConstructor(message, type);
679
- if (ErrorConstructor === DOMException && name) {
680
- return new ErrorConstructor(message, name);
794
+ dispose() {
795
+ // ignore
681
796
  }
682
- if (ErrorConstructor === Error) {
683
- const error = new Error(message);
684
- if (name && name !== 'VError') {
685
- error.name = name;
686
- }
687
- return error;
797
+ onClose(callback) {
798
+ // ignore
688
799
  }
689
- return new ErrorConstructor(message);
690
- };
691
- const getNewLineIndex = (string, startIndex = undefined) => {
692
- return string.indexOf(NewLine$1, startIndex);
693
- };
694
- const getParentStack = error => {
695
- let parentStack = error.stack || error.data || error.message || '';
696
- if (parentStack.startsWith(' at')) {
697
- parentStack = error.message + NewLine$1 + parentStack;
800
+ onMessage(callback) {
801
+ this._rawIpc.addEventListener('message', callback);
698
802
  }
699
- return parentStack;
700
- };
701
- const joinLines$1 = lines => {
702
- return lines.join(NewLine$1);
803
+ }
804
+ const wrap$f = global => {
805
+ return new IpcChildWithModuleWorker(global);
703
806
  };
704
- const MethodNotFound = -32601;
705
- const Custom = -32001;
706
- const splitLines$1 = lines => {
707
- return lines.split(NewLine$1);
807
+ const IpcChildWithModuleWorker$1 = {
808
+ __proto__: null,
809
+ listen: listen$7,
810
+ signal: signal$8,
811
+ wrap: wrap$f
708
812
  };
709
- const restoreJsonRpcError = error => {
710
- if (error && error instanceof Error) {
711
- return error;
712
- }
713
- const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(1));
714
- if (error && error.code && error.code === MethodNotFound) {
715
- const restoredError = new JsonRpcError(error.message);
716
- const parentStack = getParentStack(error);
717
- restoredError.stack = parentStack + NewLine$1 + currentStack;
718
- return restoredError;
719
- }
720
- if (error && error.message) {
721
- const restoredError = constructError(error.message, error.type, error.name);
722
- if (error.data) {
723
- if (error.data.stack && error.data.type && error.message) {
724
- restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
725
- } else if (error.data.stack) {
726
- restoredError.stack = error.data.stack;
727
- }
728
- if (error.data.codeFrame) {
729
- // @ts-ignore
730
- restoredError.codeFrame = error.data.codeFrame;
731
- }
732
- if (error.data.code) {
733
- // @ts-ignore
734
- restoredError.code = error.data.code;
735
- }
736
- if (error.data.type) {
737
- // @ts-ignore
738
- restoredError.name = error.data.type;
739
- }
740
- } else {
741
- if (error.stack) {
742
- const lowerStack = restoredError.stack || '';
743
- // @ts-ignore
744
- const indexNewLine = getNewLineIndex(lowerStack);
745
- const parentStack = getParentStack(error);
746
- // @ts-ignore
747
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
748
- }
749
- if (error.codeFrame) {
750
- // @ts-ignore
751
- restoredError.codeFrame = error.codeFrame;
752
- }
753
- }
754
- return restoredError;
813
+ const waitForFirstMessage$1 = async port => {
814
+ const {
815
+ resolve,
816
+ promise
817
+ } = Promise.withResolvers();
818
+ port.addEventListener('message', resolve, {
819
+ once: true
820
+ });
821
+ const event = await promise;
822
+ // @ts-ignore
823
+ return event.data;
824
+ };
825
+ const listen$6 = async () => {
826
+ const parentIpcRaw = listen$7();
827
+ signal$8(parentIpcRaw);
828
+ const parentIpc = wrap$f(parentIpcRaw);
829
+ const firstMessage = await waitForFirstMessage$1(parentIpc);
830
+ if (firstMessage.method !== 'initialize') {
831
+ throw new IpcError$1('unexpected first message');
755
832
  }
756
- if (typeof error === 'string') {
757
- return new Error(`JsonRpc Error: ${error}`);
833
+ const type = firstMessage.params[0];
834
+ if (type === 'message-port') {
835
+ parentIpc.send({
836
+ jsonrpc: '2.0',
837
+ id: firstMessage.id,
838
+ result: null
839
+ });
840
+ parentIpc.dispose();
841
+ const port = firstMessage.params[1];
842
+ return port;
758
843
  }
759
- return new Error(`JsonRpc Error: ${error}`);
844
+ return globalThis;
760
845
  };
761
- const unwrapJsonRpcResult = responseMessage => {
762
- if ('error' in responseMessage) {
763
- const restoredError = restoreJsonRpcError(responseMessage.error);
764
- throw restoredError;
846
+ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
847
+ getData(event) {
848
+ return getData$2(event);
765
849
  }
766
- if ('result' in responseMessage) {
767
- return responseMessage.result;
850
+ send(message) {
851
+ this._rawIpc.postMessage(message);
768
852
  }
769
- throw new JsonRpcError('unexpected response message');
770
- };
771
- const warn$1 = (...args) => {
772
- console.warn(...args);
773
- };
774
- const resolve = (id, response) => {
775
- const fn = get$7(id);
776
- if (!fn) {
777
- console.log(response);
778
- warn$1(`callback ${id} may already be disposed`);
779
- return;
853
+ sendAndTransfer(message) {
854
+ const transfer = getTransferrables(message);
855
+ this._rawIpc.postMessage(message, transfer);
780
856
  }
781
- fn(response);
782
- remove$8(id);
783
- };
784
- const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
785
- const getErrorType = prettyError => {
786
- if (prettyError && prettyError.type) {
787
- return prettyError.type;
857
+ dispose() {
858
+ if (this._rawIpc.close) {
859
+ this._rawIpc.close();
860
+ }
788
861
  }
789
- if (prettyError && prettyError.constructor && prettyError.constructor.name) {
790
- return prettyError.constructor.name;
862
+ onClose(callback) {
863
+ // ignore
791
864
  }
792
- return undefined;
793
- };
794
- const getErrorProperty = (error, prettyError) => {
795
- if (error && error.code === E_COMMAND_NOT_FOUND) {
796
- return {
797
- code: MethodNotFound,
798
- message: error.message,
799
- data: error.stack
800
- };
865
+ onMessage(callback) {
866
+ this._rawIpc.addEventListener('message', callback);
867
+ this._rawIpc.start();
801
868
  }
802
- return {
803
- code: Custom,
804
- message: prettyError.message,
805
- data: {
806
- stack: prettyError.stack,
807
- codeFrame: prettyError.codeFrame,
808
- type: getErrorType(prettyError),
809
- code: prettyError.code,
810
- name: prettyError.name
811
- }
812
- };
813
- };
814
- const create$1$1 = (message, error) => {
815
- return {
816
- jsonrpc: Two,
817
- id: message.id,
818
- error
819
- };
820
- };
821
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
822
- const prettyError = preparePrettyError(error);
823
- logError(error, prettyError);
824
- const errorProperty = getErrorProperty(error, prettyError);
825
- return create$1$1(message, errorProperty);
826
- };
827
- const create$e = (message, result) => {
828
- return {
829
- jsonrpc: Two,
830
- id: message.id,
831
- result: result ?? null
832
- };
869
+ }
870
+ const wrap$e = port => {
871
+ return new IpcChildWithModuleWorkerAndMessagePort(port);
833
872
  };
834
- const getSuccessResponse = (message, result) => {
835
- const resultProperty = result ?? null;
836
- return create$e(message, resultProperty);
873
+ const IpcChildWithModuleWorkerAndMessagePort$1 = {
874
+ __proto__: null,
875
+ listen: listen$6,
876
+ wrap: wrap$e
837
877
  };
838
- const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
839
- try {
840
- const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
841
- return getSuccessResponse(message, result);
842
- } catch (error) {
843
- return getErrorResponse(message, error, preparePrettyError, logError);
878
+ const addListener = (emitter, type, callback) => {
879
+ if ('addEventListener' in emitter) {
880
+ emitter.addEventListener(type, callback);
881
+ } else {
882
+ emitter.on(type, callback);
844
883
  }
845
884
  };
846
- const defaultPreparePrettyError = error => {
847
- return error;
848
- };
849
- const defaultLogError = () => {
850
- // ignore
851
- };
852
- const defaultRequiresSocket = () => {
853
- return false;
854
- };
855
- const defaultResolve = resolve;
856
-
857
- // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
858
- const normalizeParams = args => {
859
- if (args.length === 1) {
860
- const options = args[0];
861
- return {
862
- ipc: options.ipc,
863
- message: options.message,
864
- execute: options.execute,
865
- resolve: options.resolve || defaultResolve,
866
- preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
867
- logError: options.logError || defaultLogError,
868
- requiresSocket: options.requiresSocket || defaultRequiresSocket
869
- };
885
+ const removeListener = (emitter, type, callback) => {
886
+ if ('removeEventListener' in emitter) {
887
+ emitter.removeEventListener(type, callback);
888
+ } else {
889
+ emitter.off(type, callback);
870
890
  }
871
- return {
872
- ipc: args[0],
873
- message: args[1],
874
- execute: args[2],
875
- resolve: args[3],
876
- preparePrettyError: args[4],
877
- logError: args[5],
878
- requiresSocket: args[6]
879
- };
880
891
  };
881
- const handleJsonRpcMessage = async (...args) => {
882
- const options = normalizeParams(args);
892
+ const getFirstEvent = (eventEmitter, eventMap) => {
883
893
  const {
884
- message,
885
- ipc,
886
- execute,
887
894
  resolve,
888
- preparePrettyError,
889
- logError,
890
- requiresSocket
891
- } = options;
892
- if ('id' in message) {
893
- if ('method' in message) {
894
- const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
895
- try {
896
- ipc.send(response);
897
- } catch (error) {
898
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
899
- ipc.send(errorResponse);
900
- }
901
- return;
895
+ promise
896
+ } = Promise.withResolvers();
897
+ const listenerMap = Object.create(null);
898
+ const cleanup = value => {
899
+ for (const event of Object.keys(eventMap)) {
900
+ removeListener(eventEmitter, event, listenerMap[event]);
902
901
  }
903
- resolve(message.id, message);
904
- return;
905
- }
906
- if ('method' in message) {
907
- await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
908
- return;
902
+ resolve(value);
903
+ };
904
+ for (const [event, type] of Object.entries(eventMap)) {
905
+ const listener = event => {
906
+ cleanup({
907
+ type,
908
+ event
909
+ });
910
+ };
911
+ addListener(eventEmitter, event, listener);
912
+ listenerMap[event] = listener;
909
913
  }
910
- throw new JsonRpcError('unexpected message');
914
+ return promise;
911
915
  };
912
- const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
916
+ const Message$1 = 3;
917
+ const create$5$1 = async ({
918
+ messagePort,
919
+ isMessagePortOpen
920
+ }) => {
921
+ if (!isMessagePort(messagePort)) {
922
+ throw new IpcError$1('port must be of type MessagePort');
923
+ }
924
+ if (isMessagePortOpen) {
925
+ return messagePort;
926
+ }
927
+ const eventPromise = getFirstEvent(messagePort, {
928
+ message: Message$1
929
+ });
930
+ messagePort.start();
913
931
  const {
914
- message,
915
- promise
916
- } = create$2$1(method, params);
917
- if (useSendAndTransfer && ipc.sendAndTransfer) {
918
- ipc.sendAndTransfer(message);
919
- } else {
920
- ipc.send(message);
932
+ type,
933
+ event
934
+ } = await eventPromise;
935
+ if (type !== Message$1) {
936
+ throw new IpcError$1('Failed to wait for ipc message');
921
937
  }
922
- const responseMessage = await promise;
923
- return unwrapJsonRpcResult(responseMessage);
938
+ if (event.data !== readyMessage) {
939
+ throw new IpcError$1('unexpected first message');
940
+ }
941
+ return messagePort;
924
942
  };
925
- const send = (transport, method, ...params) => {
926
- const message = create$4$1(method, params);
927
- transport.send(message);
943
+ const signal$1 = messagePort => {
944
+ messagePort.start();
928
945
  };
929
- const invoke$6 = (ipc, method, ...params) => {
930
- return invokeHelper(ipc, method, params, false);
946
+ class IpcParentWithMessagePort extends Ipc {
947
+ getData = getData$2;
948
+ send(message) {
949
+ this._rawIpc.postMessage(message);
950
+ }
951
+ sendAndTransfer(message) {
952
+ const transfer = getTransferrables(message);
953
+ this._rawIpc.postMessage(message, transfer);
954
+ }
955
+ dispose() {
956
+ this._rawIpc.close();
957
+ }
958
+ onMessage(callback) {
959
+ this._rawIpc.addEventListener('message', callback);
960
+ }
961
+ onClose(callback) {}
962
+ }
963
+ const wrap$5 = messagePort => {
964
+ return new IpcParentWithMessagePort(messagePort);
931
965
  };
932
- const invokeAndTransfer$2 = (ipc, method, ...params) => {
933
- return invokeHelper(ipc, method, params, true);
966
+ const IpcParentWithMessagePort$1 = {
967
+ __proto__: null,
968
+ create: create$5$1,
969
+ signal: signal$1,
970
+ wrap: wrap$5
934
971
  };
935
972
 
936
973
  const createRpc$1 = ipc => {
@@ -944,7 +981,7 @@ const createRpc$1 = ipc => {
944
981
  send(ipc, method, ...params);
945
982
  },
946
983
  invoke(method, ...params) {
947
- return invoke$6(ipc, method, ...params);
984
+ return invoke$7(ipc, method, ...params);
948
985
  },
949
986
  invokeAndTransfer(method, ...params) {
950
987
  return invokeAndTransfer$2(ipc, method, ...params);
@@ -1009,38 +1046,6 @@ const getPortTuple = () => {
1009
1046
  };
1010
1047
  };
1011
1048
 
1012
- const state$9 = {
1013
- /**
1014
- * @type {any}
1015
- */
1016
- ipc: undefined
1017
- };
1018
- const get$6 = () => {
1019
- return state$9.ipc;
1020
- };
1021
- const set$6 = ipc => {
1022
- state$9.ipc = ipc;
1023
- };
1024
-
1025
- const invoke$5 = async (method, ...params) => {
1026
- const ipc = get$6();
1027
- return invoke$6(ipc, method, ...params);
1028
- };
1029
- const invokeAndTransfer$1 = async (method, ...params) => {
1030
- const ipc = get$6();
1031
- return invokeAndTransfer$2(ipc, method, ...params);
1032
- };
1033
- const listen$5 = ipc => {
1034
- set$6(ipc);
1035
- };
1036
-
1037
- const invoke$4 = async (method, ...params) => {
1038
- return invoke$5(method, ...params);
1039
- };
1040
- const invokeAndTransfer = async (method, ...params) => {
1041
- return invokeAndTransfer$1(method, ...params);
1042
- };
1043
-
1044
1049
  const ModuleWorkerAndWorkaroundForChromeDevtoolsBug = 6;
1045
1050
 
1046
1051
  const launchColorPickerWorker = async () => {
@@ -1065,15 +1070,15 @@ const launchColorPickerWorker = async () => {
1065
1070
  return rpc;
1066
1071
  };
1067
1072
 
1068
- let workerPromise;
1069
- const getOrCreate$1 = () => {
1070
- if (!workerPromise) {
1071
- workerPromise = launchColorPickerWorker();
1073
+ let workerPromise$1;
1074
+ const getOrCreate$2 = () => {
1075
+ if (!workerPromise$1) {
1076
+ workerPromise$1 = launchColorPickerWorker();
1072
1077
  }
1073
- return workerPromise;
1078
+ return workerPromise$1;
1074
1079
  };
1075
- const invoke$3 = async (method, ...params) => {
1076
- const worker = await getOrCreate$1();
1080
+ const invoke$4 = async (method, ...params) => {
1081
+ const worker = await getOrCreate$2();
1077
1082
  return await worker.invoke(method, ...params);
1078
1083
  };
1079
1084
 
@@ -1085,10 +1090,10 @@ const loadContent$3 = async (state, parentUid) => {
1085
1090
  width,
1086
1091
  height
1087
1092
  } = state;
1088
- await invoke$3('ColorPicker.create', uid, x, y, width, height, parentUid);
1089
- await invoke$3('ColorPicker.loadContent', uid);
1090
- const diff = await invoke$3('ColorPicker.diff2', uid);
1091
- const commands = await invoke$3('ColorPicker.render2', uid, diff);
1093
+ await invoke$4('ColorPicker.create', uid, x, y, width, height, parentUid);
1094
+ await invoke$4('ColorPicker.loadContent', uid);
1095
+ const diff = await invoke$4('ColorPicker.diff2', uid);
1096
+ const commands = await invoke$4('ColorPicker.render2', uid, diff);
1092
1097
  return {
1093
1098
  ...state,
1094
1099
  commands
@@ -1110,7 +1115,6 @@ const IndentLess = 'indentLess';
1110
1115
  const IndentMore = 'indentMore';
1111
1116
  const InsertLineBreak = 'insertLineBreak';
1112
1117
  const LineComment = 'lineComment';
1113
- const Rename$1 = 'rename';
1114
1118
  const ReplaceAll$2 = 'replaceAll';
1115
1119
  const ToggleBlockComment$1 = 'toggleBlockComment';
1116
1120
 
@@ -1485,7 +1489,7 @@ const createMeasureContext = () => {
1485
1489
  const state$8 = {
1486
1490
  ctx: undefined
1487
1491
  };
1488
- const getOrCreate = createCtx => {
1492
+ const getOrCreate$1 = createCtx => {
1489
1493
  if (state$8.ctx) {
1490
1494
  return state$8.ctx;
1491
1495
  }
@@ -1494,7 +1498,7 @@ const getOrCreate = createCtx => {
1494
1498
  };
1495
1499
 
1496
1500
  const getContext = () => {
1497
- const ctx = getOrCreate(createMeasureContext);
1501
+ const ctx = getOrCreate$1(createMeasureContext);
1498
1502
  return ctx;
1499
1503
  };
1500
1504
 
@@ -2032,7 +2036,6 @@ const set$4 = (id, oldEditor, newEditor) => {
2032
2036
  const CompletionExecute = 'ExtensionHostCompletion.execute';
2033
2037
  const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
2034
2038
  const HoverExecute = 'ExtensionHostHover.execute';
2035
- const RenameExecuteRename = 'ExtensionHostRename.executeRenameProvider';
2036
2039
  const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
2037
2040
  const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
2038
2041
 
@@ -2077,6 +2080,9 @@ class IpcError extends Error {
2077
2080
  const sendMessagePortToExtensionHostWorker = async port => {
2078
2081
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, 'HandleMessagePort.handleMessagePort');
2079
2082
  };
2083
+ const sendMessagePortToExtensionHostWorker2 = async (port, initialCommand, rpcId) => {
2084
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, initialCommand, rpcId);
2085
+ };
2080
2086
 
2081
2087
  const withResolvers = () => {
2082
2088
  let _resolve;
@@ -2299,18 +2305,21 @@ const createRpc = method => {
2299
2305
  _ipc = ipc;
2300
2306
  };
2301
2307
  const invoke = async (method, ...params) => {
2302
- return invoke$6(_ipc, method, ...params);
2308
+ return invoke$7(_ipc, method, ...params);
2309
+ };
2310
+ const invokeAndTransfer = async (method, ...params) => {
2311
+ return invokeAndTransfer$2(_ipc, method, ...params);
2303
2312
  };
2304
2313
  return {
2305
2314
  listen,
2306
- invoke
2315
+ invoke,
2316
+ invokeAndTransfer
2307
2317
  };
2308
2318
  };
2309
2319
 
2310
2320
  const {
2311
2321
  listen: listen$4,
2312
- invoke: invoke$2
2313
- } = createRpc(ExtensionHostWorker);
2322
+ invoke: invoke$3} = createRpc(ExtensionHostWorker);
2314
2323
 
2315
2324
  const ColorPicker$1 = 41;
2316
2325
  const CompletionDetail$1 = 999;
@@ -2333,17 +2342,11 @@ const measureCharacterWidth = (fontWeight, fontSize, fontFamily, letterSpacing)
2333
2342
  return measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
2334
2343
  };
2335
2344
 
2336
- const OnRename = 'onRename';
2337
2345
  const OnCompletion = 'onCompletion';
2338
2346
  const OnDiagnostic = 'onDiagnostic';
2339
2347
  const OnHover = 'onHover';
2340
2348
  const OnTabCompletion = 'onTabCompletion';
2341
2349
 
2342
- // TODO add tests for this
2343
- const activateByEvent = async event => {
2344
- await invoke$4('ExtensionHostManagement.activateByEvent', event);
2345
- };
2346
-
2347
2350
  const execute = async ({
2348
2351
  editor,
2349
2352
  args,
@@ -2354,7 +2357,7 @@ const execute = async ({
2354
2357
  }) => {
2355
2358
  const fullEvent = `${event}:${editor.languageId}`;
2356
2359
  await activateByEvent(fullEvent);
2357
- const result = await invoke$2(method, editor.uid, ...args);
2360
+ const result = await invoke$3(method, editor.uid, ...args);
2358
2361
  return result;
2359
2362
  };
2360
2363
 
@@ -2421,7 +2424,7 @@ const updateDiagnostics = async newState => {
2421
2424
 
2422
2425
  // TODO don't really need text document sync response
2423
2426
  // could perhaps save a lot of messages by using send instead of invoke
2424
- await invoke$2(TextDocumentSyncFull, newState.uri, newState.id, newState.languageId, content);
2427
+ await invoke$3(TextDocumentSyncFull, newState.uri, newState.id, newState.languageId, content);
2425
2428
  const diagnostics = await executeDiagnosticProvider(newState);
2426
2429
  const latest = get$4(newState.id);
2427
2430
  if (!latest) {
@@ -2434,7 +2437,7 @@ const updateDiagnostics = async newState => {
2434
2437
  decorations
2435
2438
  };
2436
2439
  set$4(newState.id, latest.oldState, newEditor);
2437
- await invoke$4('Editor.rerender', newState.id);
2440
+ await invoke$5('Editor.rerender', newState.id);
2438
2441
  return newEditor;
2439
2442
  } catch (error) {
2440
2443
  // @ts-ignore
@@ -2568,7 +2571,7 @@ const createEditor = async ({
2568
2571
  focused: true
2569
2572
  };
2570
2573
  set$4(id, emptyEditor, newEditor4);
2571
- await invoke$2(TextDocumentSyncFull, uri, id, languageId, content);
2574
+ await invoke$3(TextDocumentSyncFull, uri, id, languageId, content);
2572
2575
  if (diagnosticsEnabled) {
2573
2576
  updateDiagnostics(newEditor4);
2574
2577
  }
@@ -2637,7 +2640,7 @@ const applyEdit = async (editor, changes) => {
2637
2640
  return scheduleDocumentAndCursorsSelections(editor, changes);
2638
2641
  };
2639
2642
 
2640
- const handleBlur$2 = editor => {
2643
+ const handleBlur$1 = editor => {
2641
2644
  if (editor.focusKey !== Empty) {
2642
2645
  return editor;
2643
2646
  }
@@ -2879,7 +2882,7 @@ const editorShowMessage = async (editor, rowIndex, columnIndex, message, isError
2879
2882
  const x$1 = x(editor, rowIndex, columnIndex);
2880
2883
  const y$1 = y(editor, rowIndex);
2881
2884
  const displayErrorMessage = message;
2882
- await invoke$4('Editor.showOverlayMessage', editor, 'Viewlet.send', editor.uid, 'showOverlayMessage', x$1, y$1, displayErrorMessage);
2885
+ await invoke$5('Editor.showOverlayMessage', editor, 'Viewlet.send', editor.uid, 'showOverlayMessage', x$1, y$1, displayErrorMessage);
2883
2886
  if (!isError) {
2884
2887
  const handleTimeout = () => {
2885
2888
  editorHideMessage(editor);
@@ -2935,7 +2938,7 @@ const braceCompletion = async (editor, text) => {
2935
2938
  try {
2936
2939
  // @ts-ignore
2937
2940
  const offset = offsetAt(editor, editor.cursor);
2938
- const result = await invoke$4('ExtensionHostBraceCompletion.executeBraceCompletionProvider', editor, offset, text);
2941
+ const result = await invoke$5('ExtensionHostBraceCompletion.executeBraceCompletionProvider', editor, offset, text);
2939
2942
  if (result) {
2940
2943
  const closingBrace = getMatchingClosingBrace$1(text);
2941
2944
  const insertText = text + closingBrace;
@@ -3092,14 +3095,14 @@ const hasWidget = (widgets, id) => {
3092
3095
  };
3093
3096
 
3094
3097
  const setAdditionalFocus = async focusKey => {
3095
- await invoke$4('Focus.setAdditionalFocus', focusKey);
3098
+ await invoke$5('Focus.setAdditionalFocus', focusKey);
3096
3099
  };
3097
3100
 
3098
3101
  const setFocus = async focusKey => {
3099
3102
  if (!focusKey) {
3100
3103
  return;
3101
3104
  }
3102
- await invoke$4('Focus.setFocus', focusKey);
3105
+ await invoke$5('Focus.setFocus', focusKey);
3103
3106
  };
3104
3107
 
3105
3108
  const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGenerator, fullFocus) => {
@@ -3160,11 +3163,11 @@ const create$7 = () => {
3160
3163
  return widget;
3161
3164
  };
3162
3165
 
3163
- const newStateGenerator$2 = (state, parentUid) => {
3166
+ const newStateGenerator$3 = (state, parentUid) => {
3164
3167
  return loadContent$3(state, parentUid);
3165
3168
  };
3166
3169
  const openColorPicker = async editor => {
3167
- return addWidgetToEditor(ColorPicker, ColorPicker$1, editor, create$7, newStateGenerator$2);
3170
+ return addWidgetToEditor(ColorPicker, ColorPicker$1, editor, create$7, newStateGenerator$3);
3168
3171
  };
3169
3172
 
3170
3173
  const state$6 = {
@@ -3220,7 +3223,7 @@ const compositionEnd = (editor, data) => {
3220
3223
  const writeText = async text => {
3221
3224
  try {
3222
3225
  string(text);
3223
- await invoke$4('ClipBoard.writeText', /* text */text);
3226
+ await invoke$5('ClipBoard.writeText', /* text */text);
3224
3227
  } catch (error) {
3225
3228
  throw new VError(error, 'Failed to write text to clipboard');
3226
3229
  }
@@ -3854,7 +3857,7 @@ const deleteWordRight = editor => {
3854
3857
  };
3855
3858
 
3856
3859
  const findAllReferences = async editor => {
3857
- await invoke$4('SideBar.show', 'References', /* focus */true);
3860
+ await invoke$5('SideBar.show', 'References', /* focus */true);
3858
3861
  return editor;
3859
3862
  };
3860
3863
 
@@ -3984,7 +3987,7 @@ const getWordBefore = (editor, rowIndex, columnIndex) => {
3984
3987
 
3985
3988
  // @ts-ignore
3986
3989
  const getDefinition = async (editor, offset) => {
3987
- const definition = await invoke$4('ExtensionHostDefinition.executeDefinitionProvider', editor, offset);
3990
+ const definition = await invoke$5('ExtensionHostDefinition.executeDefinitionProvider', editor, offset);
3988
3991
  return definition;
3989
3992
  };
3990
3993
 
@@ -4171,7 +4174,7 @@ const goTo = async ({
4171
4174
  endRowIndex: definition.endRowIndex,
4172
4175
  endColumnIndex: definition.endColumnIndex
4173
4176
  };
4174
- await invoke$4(/* Main.openUri */'Main.openUri', /* uri */uri, /* focus */true, context);
4177
+ await invoke$5(/* Main.openUri */'Main.openUri', /* uri */uri, /* focus */true, context);
4175
4178
  return editor;
4176
4179
  } catch (error) {
4177
4180
  // TODO if editor is already disposed at this point, do nothing
@@ -4248,7 +4251,7 @@ const getNoLocationFoundMessage = info => {
4248
4251
  };
4249
4252
 
4250
4253
  const getTypeDefinition = async (editor, offset) => {
4251
- const definition = await invoke$4('ExtensionHostTypeDefinition.executeTypeDefinitionProvider', editor, offset);
4254
+ const definition = await invoke$5('ExtensionHostTypeDefinition.executeTypeDefinitionProvider', editor, offset);
4252
4255
  return definition;
4253
4256
  };
4254
4257
 
@@ -4288,7 +4291,7 @@ const goToTypeDefinition = async (editor, explicit = true) => {
4288
4291
  const Editor = 3;
4289
4292
 
4290
4293
  const handleContextMenu = async (editor, button, x, y) => {
4291
- await invoke$4(/* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
4294
+ await invoke$5(/* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
4292
4295
  return editor;
4293
4296
  };
4294
4297
 
@@ -4326,7 +4329,7 @@ const WhenExpressionEditorText = 12;
4326
4329
  const handleFocus = editor => {
4327
4330
  // TODO make change events functional,
4328
4331
  // when rendering, send focus changes to renderer worker
4329
- invoke$4('Focus.setFocus', WhenExpressionEditorText);
4332
+ invoke$5('Focus.setFocus', WhenExpressionEditorText);
4330
4333
  return editor;
4331
4334
  };
4332
4335
 
@@ -4987,7 +4990,7 @@ const indentMore = editor => {
4987
4990
  };
4988
4991
 
4989
4992
  const getLanguageConfiguration = async editor => {
4990
- return invoke$4('Languages.getLanguageConfiguration', {
4993
+ return invoke$5('Languages.getLanguageConfiguration', {
4991
4994
  uri: editor.uri,
4992
4995
  languageId: editor.languageId
4993
4996
  });
@@ -5291,7 +5294,7 @@ const create$6 = () => {
5291
5294
  return widget;
5292
5295
  };
5293
5296
 
5294
- const newStateGenerator$1 = async state => {
5297
+ const newStateGenerator$2 = async state => {
5295
5298
  const latestState = {
5296
5299
  ...state,
5297
5300
  x: 100,
@@ -5303,7 +5306,7 @@ const newStateGenerator$1 = async state => {
5303
5306
  };
5304
5307
  const openCodeGenerator = async editor => {
5305
5308
  const fullFocus = true;
5306
- return addWidgetToEditor(CodeGenerator, FocusCodeGenerator, editor, create$6, newStateGenerator$1, fullFocus);
5309
+ return addWidgetToEditor(CodeGenerator, FocusCodeGenerator, editor, create$6, newStateGenerator$2, fullFocus);
5307
5310
  };
5308
5311
 
5309
5312
  const create$5 = () => {
@@ -6058,7 +6061,7 @@ const focusToggleReplaceButton = state => {
6058
6061
  return setFindWidgetFocus(state, FocusFindWidgetToggleReplace);
6059
6062
  };
6060
6063
 
6061
- const handleBlur$1 = async state => {
6064
+ const handleBlur = async state => {
6062
6065
  await setFocus(Empty);
6063
6066
  return state;
6064
6067
  };
@@ -6227,53 +6230,82 @@ const openFind = async state => {
6227
6230
  return openFind2(state);
6228
6231
  };
6229
6232
 
6230
- const getRenamePosition = editor => {
6231
- const width = 300;
6232
- const height = 30;
6233
- const paddingTop = 10;
6234
- const cursor = getPositionAtCursor$1(editor);
6235
- const {
6236
- x
6237
- } = cursor;
6238
- const y = cursor.y + paddingTop;
6239
- return {
6240
- y,
6241
- x,
6242
- width,
6243
- height
6244
- };
6245
- };
6246
-
6247
6233
  const create$3 = () => {
6248
6234
  const completionUid = create$8();
6249
6235
  const renameWidget = {
6250
6236
  id: Rename,
6251
6237
  oldState: {
6252
6238
  uid: completionUid,
6253
- focusedIndex: -1,
6254
- oldValue: '',
6255
- newValue: '',
6256
- focused: false,
6257
6239
  x: 0,
6258
6240
  y: 0,
6259
6241
  width: 0,
6260
- height: 0
6242
+ height: 0,
6243
+ commands: []
6261
6244
  },
6262
6245
  newState: {
6263
6246
  uid: completionUid,
6264
- focusedIndex: -1,
6265
- oldValue: '',
6266
- newValue: '',
6267
- focused: true,
6268
6247
  x: 0,
6269
6248
  y: 0,
6270
6249
  width: 0,
6271
- height: 0
6250
+ height: 0,
6251
+ commands: []
6272
6252
  }
6273
6253
  };
6274
6254
  return renameWidget;
6275
6255
  };
6276
6256
 
6257
+ const launchRenameWorker = async () => {
6258
+ const name = 'Rename Worker';
6259
+ const {
6260
+ port1,
6261
+ port2
6262
+ } = getPortTuple();
6263
+ await invokeAndTransfer('IpcParent.create', {
6264
+ method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
6265
+ url: 'renameWorkerMain.js',
6266
+ name: name,
6267
+ raw: true,
6268
+ port: port1
6269
+ });
6270
+ const rpc = await MessagePortRpcParent.create({
6271
+ commandMap: {},
6272
+ messagePort: port2,
6273
+ isMessagePortOpen: true
6274
+ });
6275
+ port2.start();
6276
+ return rpc;
6277
+ };
6278
+
6279
+ let workerPromise;
6280
+ const getOrCreate = () => {
6281
+ if (!workerPromise) {
6282
+ workerPromise = launchRenameWorker();
6283
+ }
6284
+ return workerPromise;
6285
+ };
6286
+ const invoke$2 = async (method, ...params) => {
6287
+ const worker = await getOrCreate();
6288
+ return await worker.invoke(method, ...params);
6289
+ };
6290
+
6291
+ const newStateGenerator$1 = async (state, parentUid) => {
6292
+ // const editor: any = {}
6293
+ const {
6294
+ uid,
6295
+ x,
6296
+ y,
6297
+ width,
6298
+ height
6299
+ } = state;
6300
+ await invoke$2('Rename.create', uid, x, y, width, height, parentUid);
6301
+ await invoke$2('Rename.loadContent', uid);
6302
+ const diff = await invoke$2('Rename.diff2', uid);
6303
+ const commands = await invoke$2('Rename.render2', uid, diff);
6304
+ return {
6305
+ ...state,
6306
+ commands
6307
+ };
6308
+ };
6277
6309
  const openRename = async editor => {
6278
6310
  const {
6279
6311
  rowIndex,
@@ -6285,27 +6317,8 @@ const openRename = async editor => {
6285
6317
  if (!word) {
6286
6318
  return editor;
6287
6319
  }
6288
- const newStateGenerator = async state => {
6289
- // TODO query if can rename from extension host
6290
- const {
6291
- x,
6292
- y,
6293
- width,
6294
- height
6295
- } = getRenamePosition(editor);
6296
- const latestState = {
6297
- ...state,
6298
- x,
6299
- y,
6300
- width,
6301
- height,
6302
- oldValue: word,
6303
- newValue: word
6304
- };
6305
- return latestState;
6306
- };
6307
6320
  const fullFocus = true;
6308
- return addWidgetToEditor(Rename, FocusEditorRename$1, editor, create$3, newStateGenerator, fullFocus);
6321
+ return addWidgetToEditor(Rename, FocusEditorRename$1, editor, create$3, newStateGenerator$1, fullFocus);
6309
6322
  };
6310
6323
 
6311
6324
  const getOrganizeImportEdits = async editor => {
@@ -6333,7 +6346,7 @@ const pasteText = (editor, text) => {
6333
6346
  };
6334
6347
 
6335
6348
  const paste = async editor => {
6336
- const text = await invoke$4('ClipBoard.readText');
6349
+ const text = await invoke$5('ClipBoard.readText');
6337
6350
  string(text);
6338
6351
  return pasteText(editor, text);
6339
6352
  };
@@ -6475,7 +6488,7 @@ const save = async editor => {
6475
6488
  } = editor;
6476
6489
  const newEditor = await getNewEditor(editor);
6477
6490
  const content = getText$1(newEditor);
6478
- await invoke$4('FileSystem.writeFile', uri, content);
6491
+ await invoke$5('FileSystem.writeFile', uri, content);
6479
6492
  return newEditor;
6480
6493
  } catch (error) {
6481
6494
  // @ts-ignore
@@ -6781,7 +6794,7 @@ const selectInsideString = editor => {
6781
6794
  // import * as ExtensionHostSelection from '../ExtensionHost/ExtensionHostSelection.ts'
6782
6795
 
6783
6796
  const getNewSelections = async (editor, selections) => {
6784
- const newSelections = await invoke$4('ExtensionHostSelection.executeGrowSelection', editor, selections);
6797
+ const newSelections = await invoke$5('ExtensionHostSelection.executeGrowSelection', editor, selections);
6785
6798
  if (newSelections.length === 0) {
6786
6799
  return selections;
6787
6800
  }
@@ -7271,7 +7284,7 @@ const listen$2 = async () => {
7271
7284
  _ipc = ipc;
7272
7285
  };
7273
7286
  const invoke = async (method, ...args) => {
7274
- return invoke$6(_ipc, method, ...args);
7287
+ return invoke$7(_ipc, method, ...args);
7275
7288
  };
7276
7289
 
7277
7290
  const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
@@ -7486,13 +7499,13 @@ const showHover2 = async editor => {
7486
7499
 
7487
7500
  const EditorHover = 'EditorHover';
7488
7501
  const showHover = async state => {
7489
- await invoke$4('Viewlet.openWidget', EditorHover);
7502
+ await invoke$5('Viewlet.openWidget', EditorHover);
7490
7503
  return state;
7491
7504
  };
7492
7505
 
7493
7506
  // TODO ask extension host worker instead
7494
7507
  const getEditorSourceActions = async () => {
7495
- const sourceActions = await invoke$4('GetEditorSourceActions.getEditorSourceActions');
7508
+ const sourceActions = await invoke$5('GetEditorSourceActions.getEditorSourceActions');
7496
7509
  return sourceActions;
7497
7510
  };
7498
7511
 
@@ -8142,7 +8155,7 @@ const typeWithAutoClosingQuote = (editor, text) => {
8142
8155
 
8143
8156
  const typeWithAutoClosingTag = async (editor, text) => {
8144
8157
  const offset = offsetAt(editor, editor.selections[0], editor.selections[1]);
8145
- const result = await invoke$4('ExtensionHostClosingTagCompletion.executeClosingTagProvider', editor, offset, text);
8158
+ const result = await invoke$5('ExtensionHostClosingTagCompletion.executeClosingTagProvider', editor, offset, text);
8146
8159
  if (!result) {
8147
8160
  const changes = editorReplaceSelections(editor, [text], EditorType);
8148
8161
  return scheduleDocumentAndCursorsSelections(editor, changes);
@@ -8790,6 +8803,9 @@ const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
8790
8803
  const AppendToBody = 'Viewlet.appendToBody';
8791
8804
  const Focus = 'focus';
8792
8805
  const RegisterEventListeners = 'Viewlet.registerEventListeners';
8806
+ const SetSelectionByName = 'Viewlet.setSelectionByName';
8807
+ const SetValueByName = 'Viewlet.setValueByName';
8808
+ const SetFocusContext = 'Viewlet.setFocusContext';
8793
8809
  const SetBounds = 'setBounds';
8794
8810
  const SetBounds2 = 'Viewlet.setBounds';
8795
8811
  const SetContentHeight = 'setContentHeight';
@@ -8809,7 +8825,7 @@ const renderHoverDom = {
8809
8825
  return [/* method */SetDom2, dom];
8810
8826
  }
8811
8827
  };
8812
- const renderBounds$6 = {
8828
+ const renderBounds$5 = {
8813
8829
  isEqual(oldState, newState) {
8814
8830
  return oldState.x === newState.x && oldState.y === newState.y;
8815
8831
  },
@@ -8823,10 +8839,10 @@ const renderBounds$6 = {
8823
8839
  return [SetBounds, x, y, width, height];
8824
8840
  }
8825
8841
  };
8826
- const render$f = [renderHoverDom, renderBounds$6];
8842
+ const render$e = [renderHoverDom, renderBounds$5];
8827
8843
  const renderHover = (oldState, newState) => {
8828
8844
  const commands = [];
8829
- for (const item of render$f) {
8845
+ for (const item of render$e) {
8830
8846
  if (!item.isEqual(oldState, newState)) {
8831
8847
  commands.push(item.apply(oldState, newState));
8832
8848
  }
@@ -8834,79 +8850,6 @@ const renderHover = (oldState, newState) => {
8834
8850
  return commands;
8835
8851
  };
8836
8852
 
8837
- const executeRenameProvider = async (editor, offset, newName) => {
8838
- return execute({
8839
- editor,
8840
- event: OnRename,
8841
- method: RenameExecuteRename,
8842
- args: [offset, newName],
8843
- noProviderFoundMessage: 'no rename provider found',
8844
- noProviderFoundResult: []});
8845
- };
8846
-
8847
- const getRenameState = editor => {
8848
- return getWidgetState(editor, Rename);
8849
- };
8850
-
8851
- const getRenameChanges = (editor, result) => {
8852
- if (!result?.edits) {
8853
- return [];
8854
- }
8855
- const changes = [];
8856
- console.log({
8857
- result
8858
- });
8859
- for (const edit of result.edits) {
8860
- const position = positionAt(editor, edit.offset);
8861
- const start = position;
8862
- const end = {
8863
- ...position,
8864
- columnIndex: start.columnIndex + edit.deleted
8865
- };
8866
- const selection = {
8867
- start,
8868
- end
8869
- };
8870
- changes.push({
8871
- start,
8872
- end,
8873
- inserted: [result.inserted],
8874
- deleted: getSelectionText(editor, selection),
8875
- origin: Rename$1
8876
- });
8877
- }
8878
- return changes;
8879
- };
8880
- const accept = async editor => {
8881
- const child = getRenameState(editor);
8882
- if (!child) {
8883
- return editor;
8884
- }
8885
- const {
8886
- widgets
8887
- } = editor;
8888
- const newWidgets = removeEditorWidget(widgets, Rename);
8889
- // TODO
8890
- const offset = getOffsetAtCursor(editor);
8891
- const result = await executeRenameProvider(editor, offset, child.newValue);
8892
- const changes = getRenameChanges(editor, result);
8893
- console.log({
8894
- changes
8895
- });
8896
- // 1. ask extension host for rename edits
8897
- // 2. apply rename edit across editor (and whole workspace)
8898
- // 3. close rename widget
8899
- return {
8900
- ...editor,
8901
- focused: true,
8902
- widgets: newWidgets
8903
- };
8904
- };
8905
-
8906
- const handleBlur = editor => {
8907
- return closeRename(editor);
8908
- };
8909
-
8910
8853
  const rerender = editor => {
8911
8854
  // TODO avoid slow clone
8912
8855
  return structuredClone(editor);
@@ -8946,7 +8889,7 @@ const updateWidget = (editor, widgetId, newState) => {
8946
8889
  };
8947
8890
 
8948
8891
  const getInvoke = () => {
8949
- return invoke$3;
8892
+ return invoke$4;
8950
8893
  };
8951
8894
  const executeWidgetCommand = async (editor, name, method, uid, widgetId, ...params) => {
8952
8895
  const invoke = getInvoke();
@@ -10351,7 +10294,7 @@ const renderScrollBarX = {
10351
10294
  return [/* method */'setScrollBarHorizontal', /* scrollBarX */scrollBarX, /* scrollBarWidth */scrollBarWidth, /* deltaX */newState.deltaX];
10352
10295
  }
10353
10296
  };
10354
- const renderFocus$3 = {
10297
+ const renderFocus$2 = {
10355
10298
  isEqual(oldState, newState) {
10356
10299
  return oldState.focused === newState.focused;
10357
10300
  },
@@ -10359,7 +10302,7 @@ const renderFocus$3 = {
10359
10302
  // TODO avoid side effect
10360
10303
  if (newState.focused) {
10361
10304
  const FocusEditorText = 12;
10362
- invoke$4('Focus.setFocus', FocusEditorText);
10305
+ invoke$5('Focus.setFocus', FocusEditorText);
10363
10306
  }
10364
10307
  return [/* method */'setFocused', newState.focused];
10365
10308
  }
@@ -10449,7 +10392,7 @@ const renderWidgets = {
10449
10392
  },
10450
10393
  multiple: true
10451
10394
  };
10452
- const render$e = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus$3, renderDecorations, renderGutterInfo, renderWidgets];
10395
+ const render$d = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus$2, renderDecorations, renderGutterInfo, renderWidgets];
10453
10396
  const renderEditor = async id => {
10454
10397
  const instance = get$4(id);
10455
10398
  if (!instance) {
@@ -10461,7 +10404,7 @@ const renderEditor = async id => {
10461
10404
  } = instance;
10462
10405
  const commands = [];
10463
10406
  set$4(id, newState, newState);
10464
- for (const item of render$e) {
10407
+ for (const item of render$d) {
10465
10408
  if (!item.isEqual(oldState, newState)) {
10466
10409
  const result = await item.apply(oldState, newState);
10467
10410
  // @ts-ignore
@@ -10527,9 +10470,9 @@ const keep = [
10527
10470
  // 'ColorPicker.handleSliderPointerDown',
10528
10471
  // 'ColorPicker.handleSliderPointerMove',
10529
10472
  // 'ColorPicker.loadContent',
10530
- 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'Editor.getKeyBindings', 'Editor.getPositionAtCursor', 'Editor.getWordAt2', 'Editor.getQuickPickMenuEntries',
10473
+ 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'Editor.getKeyBindings', 'Editor.getPositionAtCursor', 'Editor.getWordAt2', 'Editor.getWordAtOffset2', 'Editor.getQuickPickMenuEntries',
10531
10474
  // 'ColorPicker.render',
10532
- 'Editor.getText', 'Editor.getSelections', 'Font.ensure', 'Hover.getHoverInfo', 'Hover.handleSashPointerDown', 'Hover.handleSashPointerMove', 'Hover.handleSashPointerUp', 'Hover.loadContent', 'Hover.render', 'Initialize.initialize'];
10475
+ 'Editor.getText', 'Editor.getSelections', 'Font.ensure', 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', 'Hover.getHoverInfo', 'Hover.handleSashPointerDown', 'Hover.handleSashPointerMove', 'Hover.handleSashPointerUp', 'Hover.loadContent', 'Hover.render', 'Initialize.initialize', 'ActivateByEvent.activateByEvent'];
10533
10476
 
10534
10477
  const wrapWidgetCommand = (widgetId, fn) => {
10535
10478
  const isWidget = widget => {
@@ -10609,14 +10552,13 @@ const wrapCommands = commands => {
10609
10552
  };
10610
10553
 
10611
10554
  const commandMap = {
10555
+ 'ActivateByEvent.activateByEvent': activateByEvent,
10612
10556
  'CodeGenerator.accept': codeGeneratorAccept,
10613
10557
  'ColorPicker.loadContent': loadContent$3,
10614
10558
  'Editor.addCursorAbove': addCursorAbove,
10615
10559
  'Editor.addCursorBelow': addCursorBelow,
10616
10560
  'Editor.applyEdit': applyEdit,
10617
10561
  'Editor.braceCompletion': braceCompletion,
10618
- 'Editor.getPositionAtCursor': getPositionAtCursor,
10619
- 'Editor.getWordAt2': getWordAt,
10620
10562
  'Editor.cancelSelection': cancelSelection,
10621
10563
  'Editor.closeCodeGenerator': closeCodeGenerator,
10622
10564
  'Editor.closeCompletion': closeCompletion,
@@ -10660,16 +10602,19 @@ const commandMap = {
10660
10602
  'Editor.findAllReferences': findAllReferences,
10661
10603
  'Editor.format': format,
10662
10604
  'Editor.getKeyBindings': getKeyBindings,
10605
+ 'Editor.getPositionAtCursor': getPositionAtCursor,
10663
10606
  'Editor.getQuickPickMenuEntries': getQuickPickMenuEntries,
10664
10607
  'Editor.getSelections': getSelections,
10665
10608
  'Editor.getText': getText,
10666
10609
  'Editor.getWordAt': getWordAt$1,
10610
+ 'Editor.getWordAt2': getWordAt,
10611
+ 'Editor.getWordAtOffset2': getWordAt,
10667
10612
  'Editor.getWordBefore': getWordBefore,
10668
10613
  'Editor.goToDefinition': goToDefinition,
10669
10614
  'Editor.goToTypeDefinition': goToTypeDefinition,
10670
10615
  'Editor.handleBeforeInput': handleBeforeInput,
10671
10616
  'Editor.handleBeforeInputFromContentEditable': handleBeforeInputFromContentEditable,
10672
- 'Editor.handleBlur': handleBlur$2,
10617
+ 'Editor.handleBlur': handleBlur$1,
10673
10618
  'Editor.handleContextMenu': handleContextMenu,
10674
10619
  'Editor.handleDoubleClick': handleDoubleClick,
10675
10620
  'Editor.handleFocus': handleFocus,
@@ -10767,8 +10712,6 @@ const commandMap = {
10767
10712
  'EditorCompletion.selectCurrent': selectCurrent,
10768
10713
  'EditorCompletion.selectIndex': selectIndex,
10769
10714
  'EditorCompletion.toggleDetails': toggleDetails,
10770
- 'EditorRename.accept': accept,
10771
- 'EditorRename.handleBlur': handleBlur,
10772
10715
  'EditorSourceActions.focusNext': focusNext,
10773
10716
  'FindWidget.close': close$1,
10774
10717
  'FindWidget.focusCloseButton': focusCloseButton,
@@ -10784,7 +10727,7 @@ const commandMap = {
10784
10727
  'FindWidget.focusReplaceAllButton': focusReplaceAllButton,
10785
10728
  'FindWidget.focusReplaceButton': focusReplaceButton,
10786
10729
  'FindWidget.focusToggleReplace': focusToggleReplaceButton,
10787
- 'FindWidget.handleBlur': handleBlur$1,
10730
+ 'FindWidget.handleBlur': handleBlur,
10788
10731
  'FindWidget.handleFocus': handleFindWidgetFocus,
10789
10732
  'FindWidget.handleInput': handleInput,
10790
10733
  'FindWidget.handleReplaceAllFocus': handleReplaceAllFocus,
@@ -10801,7 +10744,8 @@ const commandMap = {
10801
10744
  'Hover.handleSashPointerUp': handleSashPointerUp,
10802
10745
  'Hover.loadContent': loadContent,
10803
10746
  'Hover.render': renderHover,
10804
- 'Initialize.initialize': intialize
10747
+ 'Initialize.initialize': intialize,
10748
+ 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker': sendMessagePortToExtensionHostWorker2
10805
10749
  };
10806
10750
  wrapCommands(commandMap);
10807
10751
 
@@ -10863,7 +10807,8 @@ const listen = async () => {
10863
10807
  const isFunctional = widgetId => {
10864
10808
  switch (widgetId) {
10865
10809
  case ColorPicker:
10866
- // case WidgetId.Rename: // TODO
10810
+ case Rename:
10811
+ // case WidgetId.Completion:
10867
10812
  return true;
10868
10813
  default:
10869
10814
  return false;
@@ -10929,7 +10874,7 @@ const getCodeGeneratorVirtualDom = state => {
10929
10874
  }, text(escapeToClose$1)];
10930
10875
  };
10931
10876
 
10932
- const renderContent$2 = {
10877
+ const renderContent$1 = {
10933
10878
  isEqual(oldState, newState) {
10934
10879
  return oldState.questions === newState.questions;
10935
10880
  },
@@ -10938,7 +10883,7 @@ const renderContent$2 = {
10938
10883
  return [SetDom2, newState.uid, dom];
10939
10884
  }
10940
10885
  };
10941
- const renderBounds$5 = {
10886
+ const renderBounds$4 = {
10942
10887
  isEqual(oldState, newState) {
10943
10888
  return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
10944
10889
  },
@@ -10952,7 +10897,7 @@ const renderBounds$5 = {
10952
10897
  return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
10953
10898
  }
10954
10899
  };
10955
- const renderFocus$2 = {
10900
+ const renderFocus$1 = {
10956
10901
  isEqual(oldState, newState) {
10957
10902
  return oldState.focused === newState.focused && oldState.focusSource === newState.focusSource;
10958
10903
  },
@@ -10960,10 +10905,10 @@ const renderFocus$2 = {
10960
10905
  return [Focus, '.CodeGeneratorInput', newState.focusSource];
10961
10906
  }
10962
10907
  };
10963
- const render$d = [renderContent$2, renderBounds$5, renderFocus$2];
10908
+ const render$c = [renderContent$1, renderBounds$4, renderFocus$1];
10964
10909
  const renderFull$3 = (oldState, newState) => {
10965
10910
  const commands = [];
10966
- for (const item of render$d) {
10911
+ for (const item of render$c) {
10967
10912
  if (!item.isEqual(oldState, newState)) {
10968
10913
  commands.push(item.apply(oldState, newState));
10969
10914
  }
@@ -10971,7 +10916,7 @@ const renderFull$3 = (oldState, newState) => {
10971
10916
  return commands;
10972
10917
  };
10973
10918
 
10974
- const render$c = widget => {
10919
+ const render$b = widget => {
10975
10920
  const commands = renderFull$3(widget.oldState, widget.newState);
10976
10921
  const wrappedCommands = [];
10977
10922
  const {
@@ -10988,7 +10933,7 @@ const render$c = widget => {
10988
10933
  return wrappedCommands;
10989
10934
  };
10990
10935
  const add$7 = widget => {
10991
- return addWidget(widget, 'EditorCodeGenerator', render$c);
10936
+ return addWidget(widget, 'EditorCodeGenerator', render$b);
10992
10937
  };
10993
10938
  const remove$7 = removeWidget;
10994
10939
 
@@ -10996,7 +10941,7 @@ const EditorCodeGeneratorWidget = {
10996
10941
  __proto__: null,
10997
10942
  add: add$7,
10998
10943
  remove: remove$7,
10999
- render: render$c
10944
+ render: render$b
11000
10945
  };
11001
10946
 
11002
10947
  const renderFull$2 = (oldState, newState) => {
@@ -11006,7 +10951,7 @@ const renderFull$2 = (oldState, newState) => {
11006
10951
  return commands;
11007
10952
  };
11008
10953
 
11009
- const render$b = widget => {
10954
+ const render$a = widget => {
11010
10955
  const commands = renderFull$2(widget.oldState, widget.newState);
11011
10956
  const wrappedCommands = [];
11012
10957
  const {
@@ -11022,7 +10967,7 @@ const render$b = widget => {
11022
10967
  return wrappedCommands;
11023
10968
  };
11024
10969
  const add$6 = widget => {
11025
- return addWidget(widget, 'ColorPicker', render$b);
10970
+ return addWidget(widget, 'ColorPicker', render$a);
11026
10971
  };
11027
10972
  const remove$6 = removeWidget;
11028
10973
  const Commands$1 = {};
@@ -11032,7 +10977,7 @@ const EditorColorPickerWidget = {
11032
10977
  Commands: Commands$1,
11033
10978
  add: add$6,
11034
10979
  remove: remove$6,
11035
- render: render$b
10980
+ render: render$a
11036
10981
  };
11037
10982
 
11038
10983
  const getCompletionDetailVirtualDom = content => {
@@ -11067,7 +11012,7 @@ const renderParts = (render, oldState, newState) => {
11067
11012
  return commands;
11068
11013
  };
11069
11014
 
11070
- const renderContent$1 = {
11015
+ const renderContent = {
11071
11016
  isEqual(oldState, newState) {
11072
11017
  return oldState.content === newState.content;
11073
11018
  },
@@ -11076,7 +11021,7 @@ const renderContent$1 = {
11076
11021
  return [SetDom2, newState.uid, dom];
11077
11022
  }
11078
11023
  };
11079
- const renderBounds$4 = {
11024
+ const renderBounds$3 = {
11080
11025
  isEqual(oldState, newState) {
11081
11026
  return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
11082
11027
  },
@@ -11090,12 +11035,12 @@ const renderBounds$4 = {
11090
11035
  return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
11091
11036
  }
11092
11037
  };
11093
- const render$a = [renderContent$1, renderBounds$4];
11038
+ const render$9 = [renderContent, renderBounds$3];
11094
11039
  const renderFull$1 = (oldState, newState) => {
11095
- return renderParts(render$a, oldState, newState);
11040
+ return renderParts(render$9, oldState, newState);
11096
11041
  };
11097
11042
 
11098
- const render$9 = widget => {
11043
+ const render$8 = widget => {
11099
11044
  const commands = renderFull$1(widget.oldState, widget.newState);
11100
11045
  const wrappedCommands = [];
11101
11046
  const {
@@ -11111,7 +11056,7 @@ const render$9 = widget => {
11111
11056
  return wrappedCommands;
11112
11057
  };
11113
11058
  const add$5 = widget => {
11114
- return addWidget(widget, 'EditorCompletionDetails', render$9);
11059
+ return addWidget(widget, 'EditorCompletionDetails', render$8);
11115
11060
  };
11116
11061
  const remove$5 = removeWidget;
11117
11062
  const handleEditorType$1 = (editor, state) => {
@@ -11149,7 +11094,7 @@ const EditorCompletionDetailWidget = {
11149
11094
  handleEditorDeleteLeft: handleEditorDeleteLeft$1,
11150
11095
  handleEditorType: handleEditorType$1,
11151
11096
  remove: remove$5,
11152
- render: render$9
11097
+ render: render$8
11153
11098
  };
11154
11099
 
11155
11100
  const CheckBox = 'checkbox';
@@ -11354,7 +11299,7 @@ const renderItems = {
11354
11299
  return ['setDom', dom];
11355
11300
  }
11356
11301
  };
11357
- const renderBounds$3 = {
11302
+ const renderBounds$2 = {
11358
11303
  isEqual(oldState, newState) {
11359
11304
  return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.x === newState.x && oldState.y === newState.y;
11360
11305
  },
@@ -11400,10 +11345,10 @@ const renderScrollBar = {
11400
11345
  return [/* method */SetScrollBar, /* scrollBarY */scrollBarY, /* scrollBarHeight */scrollBarHeight];
11401
11346
  }
11402
11347
  };
11403
- const render$8 = [renderItems, renderBounds$3, renderHeight, renderNegativeMargin, renderScrollBar];
11348
+ const render$7 = [renderItems, renderBounds$2, renderHeight, renderNegativeMargin, renderScrollBar];
11404
11349
  const renderCompletion = (oldState, newState) => {
11405
11350
  const commands = [];
11406
- for (const item of render$8) {
11351
+ for (const item of render$7) {
11407
11352
  if (!item.isEqual(oldState, newState)) {
11408
11353
  commands.push(item.apply(oldState, newState));
11409
11354
  }
@@ -11411,7 +11356,7 @@ const renderCompletion = (oldState, newState) => {
11411
11356
  return commands;
11412
11357
  };
11413
11358
 
11414
- const render$7 = widget => {
11359
+ const render$6 = widget => {
11415
11360
  const commands = renderCompletion(widget.oldState, widget.newState);
11416
11361
  const wrappedCommands = [];
11417
11362
  const {
@@ -11423,7 +11368,7 @@ const render$7 = widget => {
11423
11368
  return wrappedCommands;
11424
11369
  };
11425
11370
  const add$4 = widget => {
11426
- const commands = render$7(widget);
11371
+ const commands = render$6(widget);
11427
11372
  const id = 'EditorCompletion';
11428
11373
  // TODO how to generate a unique integer id
11429
11374
  // that doesn't collide with ids created in renderer worker?
@@ -11502,7 +11447,7 @@ const EditorCompletionWidget = {
11502
11447
  handleEditorDeleteLeft,
11503
11448
  handleEditorType,
11504
11449
  remove: remove$4,
11505
- render: render$7
11450
+ render: render$6
11506
11451
  };
11507
11452
 
11508
11453
  /**
@@ -11842,7 +11787,7 @@ const renderDetails = {
11842
11787
  return [SetDom2, dom];
11843
11788
  }
11844
11789
  };
11845
- const renderBounds$2 = {
11790
+ const renderBounds$1 = {
11846
11791
  isEqual(oldState, newState) {
11847
11792
  return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
11848
11793
  },
@@ -11856,7 +11801,7 @@ const renderBounds$2 = {
11856
11801
  return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
11857
11802
  }
11858
11803
  };
11859
- const renderFocus$1 = {
11804
+ const renderFocus = {
11860
11805
  isEqual(oldState, newState) {
11861
11806
  return oldState.focused === newState.focused && oldState.focus === newState.focus && oldState.focusSource === newState.focusSource;
11862
11807
  },
@@ -11885,16 +11830,16 @@ const renderFocus$1 = {
11885
11830
  // },
11886
11831
  // }
11887
11832
 
11888
- const render$6 = [renderDetails, renderBounds$2, renderValue, renderFocus$1];
11833
+ const render$5 = [renderDetails, renderBounds$1, renderValue, renderFocus];
11889
11834
  const apply = (oldState, newState) => {
11890
11835
  // TODO avoid side effect
11891
11836
  if (oldState.focus !== newState.focus) {
11892
11837
  setFocus(newState.focus);
11893
11838
  }
11894
- return renderParts(render$6, oldState, newState);
11839
+ return renderParts(render$5, oldState, newState);
11895
11840
  };
11896
11841
 
11897
- const render$5 = widget => {
11842
+ const render$4 = widget => {
11898
11843
  const commands = apply(widget.oldState, widget.newState);
11899
11844
  const wrappedCommands = [];
11900
11845
  const {
@@ -11910,7 +11855,7 @@ const render$5 = widget => {
11910
11855
  return wrappedCommands;
11911
11856
  };
11912
11857
  const add$3 = widget => {
11913
- return addWidget(widget, 'FindWidget', render$5);
11858
+ return addWidget(widget, 'FindWidget', render$4);
11914
11859
  };
11915
11860
  const remove$3 = removeWidget;
11916
11861
  const Commands = {
@@ -11921,7 +11866,7 @@ const Commands = {
11921
11866
  'FindWidget.focusLast': focusLast,
11922
11867
  'FindWidget.toggleReplace': toggleReplace,
11923
11868
  'FindWidget.handleFocus': focusFind,
11924
- 'FindWidget.handleBlur': handleBlur$1
11869
+ 'FindWidget.handleBlur': handleBlur
11925
11870
  };
11926
11871
 
11927
11872
  const EditorFindWidget = {
@@ -11929,10 +11874,10 @@ const EditorFindWidget = {
11929
11874
  Commands,
11930
11875
  add: add$3,
11931
11876
  remove: remove$3,
11932
- render: render$5
11877
+ render: render$4
11933
11878
  };
11934
11879
 
11935
- const render$4 = widget => {
11880
+ const render$3 = widget => {
11936
11881
  const commands = renderHover(widget.oldState, widget.newState);
11937
11882
  const wrappedCommands = [];
11938
11883
  const {
@@ -11948,7 +11893,7 @@ const render$4 = widget => {
11948
11893
  return wrappedCommands;
11949
11894
  };
11950
11895
  const add$2 = widget => {
11951
- return addWidget(widget, 'EditorHover', render$4);
11896
+ return addWidget(widget, 'EditorHover', render$3);
11952
11897
  };
11953
11898
  const remove$2 = removeWidget;
11954
11899
 
@@ -11956,57 +11901,17 @@ const EditorHoverWidget = {
11956
11901
  __proto__: null,
11957
11902
  add: add$2,
11958
11903
  remove: remove$2,
11959
- render: render$4
11960
- };
11961
-
11962
- const getRenameVirtualDom = state => {
11963
- return [{
11964
- type: Div,
11965
- className: 'Viewlet EditorRename',
11966
- childCount: 1
11967
- }, {
11968
- type: Input,
11969
- className: 'InputBox RenameInputBox',
11970
- value: state.newValue,
11971
- childCount: 0,
11972
- onBlur: 'handleBlur'
11973
- }];
11904
+ render: render$3
11974
11905
  };
11975
11906
 
11976
- const renderContent = {
11977
- isEqual(oldState, newState) {
11978
- return false;
11979
- },
11980
- apply(oldState, newState) {
11981
- const dom = getRenameVirtualDom(newState);
11982
- return [SetDom2, newState.uid, dom];
11983
- }
11984
- };
11985
- const renderBounds$1 = {
11986
- isEqual(oldState, newState) {
11987
- return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
11988
- },
11989
- apply(oldState, newState) {
11990
- const {
11991
- x,
11992
- y,
11993
- width,
11994
- height
11995
- } = newState;
11996
- return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
11997
- }
11998
- };
11999
- const renderFocus = {
12000
- isEqual(oldState, newState) {
12001
- return oldState.focused === newState.focused;
12002
- },
12003
- apply(oldState, newState) {
12004
- return [/* method */'Viewlet.focusSelector', newState.uid, '.RenameInputBox'];
12005
- }
12006
- };
12007
- const render$3 = [renderContent, renderBounds$1, renderFocus];
12008
11907
  const renderFull = (oldState, newState) => {
12009
- return renderParts(render$3, oldState, newState);
11908
+ const commands = [...newState.commands];
11909
+ // @ts-ignore
11910
+ newState.commands = [];
11911
+ console.log({
11912
+ commands
11913
+ });
11914
+ return commands;
12010
11915
  };
12011
11916
 
12012
11917
  const render$2 = widget => {
@@ -12016,9 +11921,7 @@ const render$2 = widget => {
12016
11921
  uid
12017
11922
  } = widget.newState;
12018
11923
  for (const command of commands) {
12019
- if (command[0] === SetDom2) {
12020
- wrappedCommands.push(command);
12021
- } else if (command[0] === 'Viewlet.focusSelector') {
11924
+ if (command[0] === SetDom2 || command[0] === SetCss || command[0] === AppendToBody || command[0] === SetBounds2 || command[0] === RegisterEventListeners || command[0] === SetSelectionByName || command[0] === SetValueByName || command[0] === SetFocusContext || command[0] === SetUid || command[0] === 'Viewlet.focusSelector') {
12022
11925
  wrappedCommands.push(command);
12023
11926
  } else {
12024
11927
  wrappedCommands.push(['Viewlet.send', uid, ...command]);