@lvce-editor/hover-worker 1.0.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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/hoverWorkerMain.js +1557 -0
- package/package.json +13 -0
|
@@ -0,0 +1,1557 @@
|
|
|
1
|
+
const normalizeLine = line => {
|
|
2
|
+
if (line.startsWith('Error: ')) {
|
|
3
|
+
return line.slice('Error: '.length);
|
|
4
|
+
}
|
|
5
|
+
if (line.startsWith('VError: ')) {
|
|
6
|
+
return line.slice('VError: '.length);
|
|
7
|
+
}
|
|
8
|
+
return line;
|
|
9
|
+
};
|
|
10
|
+
const getCombinedMessage = (error, message) => {
|
|
11
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
12
|
+
if (message) {
|
|
13
|
+
return `${message}: ${stringifiedError}`;
|
|
14
|
+
}
|
|
15
|
+
return stringifiedError;
|
|
16
|
+
};
|
|
17
|
+
const NewLine$2 = '\n';
|
|
18
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
19
|
+
return string.indexOf(NewLine$2, startIndex);
|
|
20
|
+
};
|
|
21
|
+
const mergeStacks = (parent, child) => {
|
|
22
|
+
if (!child) {
|
|
23
|
+
return parent;
|
|
24
|
+
}
|
|
25
|
+
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
26
|
+
const childNewLineIndex = getNewLineIndex$1(child);
|
|
27
|
+
if (childNewLineIndex === -1) {
|
|
28
|
+
return parent;
|
|
29
|
+
}
|
|
30
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
31
|
+
const childRest = child.slice(childNewLineIndex);
|
|
32
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
33
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
34
|
+
return parentFirstLine + childRest;
|
|
35
|
+
}
|
|
36
|
+
return child;
|
|
37
|
+
};
|
|
38
|
+
class VError extends Error {
|
|
39
|
+
constructor(error, message) {
|
|
40
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
41
|
+
super(combinedMessage);
|
|
42
|
+
this.name = 'VError';
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
|
45
|
+
}
|
|
46
|
+
if (error.codeFrame) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
this.codeFrame = error.codeFrame;
|
|
49
|
+
}
|
|
50
|
+
if (error.code) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
this.code = error.code;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const isMessagePort = value => {
|
|
58
|
+
return value && value instanceof MessagePort;
|
|
59
|
+
};
|
|
60
|
+
const isMessagePortMain = value => {
|
|
61
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
62
|
+
};
|
|
63
|
+
const isOffscreenCanvas = value => {
|
|
64
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
65
|
+
};
|
|
66
|
+
const isInstanceOf = (value, constructorName) => {
|
|
67
|
+
return value?.constructor?.name === constructorName;
|
|
68
|
+
};
|
|
69
|
+
const isSocket = value => {
|
|
70
|
+
return isInstanceOf(value, 'Socket');
|
|
71
|
+
};
|
|
72
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
73
|
+
const isTransferrable = value => {
|
|
74
|
+
for (const fn of transferrables) {
|
|
75
|
+
if (fn(value)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
};
|
|
81
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
82
|
+
if (!value) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (isTransferrable(value)) {
|
|
86
|
+
transferrables.push(value);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
for (const item of value) {
|
|
91
|
+
walkValue(item, transferrables, isTransferrable);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (typeof value === 'object') {
|
|
96
|
+
for (const property of Object.values(value)) {
|
|
97
|
+
walkValue(property, transferrables, isTransferrable);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const getTransferrables = value => {
|
|
103
|
+
const transferrables = [];
|
|
104
|
+
walkValue(value, transferrables, isTransferrable);
|
|
105
|
+
return transferrables;
|
|
106
|
+
};
|
|
107
|
+
const attachEvents = that => {
|
|
108
|
+
const handleMessage = (...args) => {
|
|
109
|
+
const data = that.getData(...args);
|
|
110
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
111
|
+
data
|
|
112
|
+
}));
|
|
113
|
+
};
|
|
114
|
+
that.onMessage(handleMessage);
|
|
115
|
+
const handleClose = event => {
|
|
116
|
+
that.dispatchEvent(new Event('close'));
|
|
117
|
+
};
|
|
118
|
+
that.onClose(handleClose);
|
|
119
|
+
};
|
|
120
|
+
class Ipc extends EventTarget {
|
|
121
|
+
constructor(rawIpc) {
|
|
122
|
+
super();
|
|
123
|
+
this._rawIpc = rawIpc;
|
|
124
|
+
attachEvents(this);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
128
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
129
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
130
|
+
const NewLine$1 = '\n';
|
|
131
|
+
const joinLines$1 = lines => {
|
|
132
|
+
return lines.join(NewLine$1);
|
|
133
|
+
};
|
|
134
|
+
const RE_AT = /^\s+at/;
|
|
135
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
136
|
+
const isNormalStackLine = line => {
|
|
137
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
138
|
+
};
|
|
139
|
+
const getDetails = lines => {
|
|
140
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
141
|
+
if (index === -1) {
|
|
142
|
+
return {
|
|
143
|
+
actualMessage: joinLines$1(lines),
|
|
144
|
+
rest: []
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
let lastIndex = index - 1;
|
|
148
|
+
while (++lastIndex < lines.length) {
|
|
149
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
actualMessage: lines[index - 1],
|
|
155
|
+
rest: lines.slice(index, lastIndex)
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
const splitLines$1 = lines => {
|
|
159
|
+
return lines.split(NewLine$1);
|
|
160
|
+
};
|
|
161
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
162
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
163
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
164
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
165
|
+
};
|
|
166
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
167
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
168
|
+
};
|
|
169
|
+
const getMessageCodeBlock = stderr => {
|
|
170
|
+
const lines = splitLines$1(stderr);
|
|
171
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
172
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
173
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
174
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
175
|
+
return relevantMessage;
|
|
176
|
+
};
|
|
177
|
+
const isModuleNotFoundMessage = line => {
|
|
178
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
179
|
+
};
|
|
180
|
+
const getModuleNotFoundError = stderr => {
|
|
181
|
+
const lines = splitLines$1(stderr);
|
|
182
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
183
|
+
const message = lines[messageIndex];
|
|
184
|
+
return {
|
|
185
|
+
message,
|
|
186
|
+
code: ERR_MODULE_NOT_FOUND
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const isModuleNotFoundError = stderr => {
|
|
190
|
+
if (!stderr) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
194
|
+
};
|
|
195
|
+
const isModulesSyntaxError = stderr => {
|
|
196
|
+
if (!stderr) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
200
|
+
};
|
|
201
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
202
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
203
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
204
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
205
|
+
};
|
|
206
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
207
|
+
const message = getMessageCodeBlock(stderr);
|
|
208
|
+
return {
|
|
209
|
+
message: `Incompatible native node module: ${message}`,
|
|
210
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
const getModuleSyntaxError = () => {
|
|
214
|
+
return {
|
|
215
|
+
message: `ES Modules are not supported in electron`,
|
|
216
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
220
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
221
|
+
return getNativeModuleErrorMessage(stderr);
|
|
222
|
+
}
|
|
223
|
+
if (isModulesSyntaxError(stderr)) {
|
|
224
|
+
return getModuleSyntaxError();
|
|
225
|
+
}
|
|
226
|
+
if (isModuleNotFoundError(stderr)) {
|
|
227
|
+
return getModuleNotFoundError(stderr);
|
|
228
|
+
}
|
|
229
|
+
const lines = splitLines$1(stderr);
|
|
230
|
+
const {
|
|
231
|
+
actualMessage,
|
|
232
|
+
rest
|
|
233
|
+
} = getDetails(lines);
|
|
234
|
+
return {
|
|
235
|
+
message: actualMessage,
|
|
236
|
+
code: '',
|
|
237
|
+
stack: rest
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
class IpcError extends VError {
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
243
|
+
if (stdout || stderr) {
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
const {
|
|
246
|
+
message,
|
|
247
|
+
code,
|
|
248
|
+
stack
|
|
249
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
250
|
+
const cause = new Error(message);
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
cause.code = code;
|
|
253
|
+
cause.stack = stack;
|
|
254
|
+
super(cause, betterMessage);
|
|
255
|
+
} else {
|
|
256
|
+
super(betterMessage);
|
|
257
|
+
}
|
|
258
|
+
// @ts-ignore
|
|
259
|
+
this.name = 'IpcError';
|
|
260
|
+
// @ts-ignore
|
|
261
|
+
this.stdout = stdout;
|
|
262
|
+
// @ts-ignore
|
|
263
|
+
this.stderr = stderr;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const readyMessage = 'ready';
|
|
267
|
+
const getData$2 = event => {
|
|
268
|
+
return event.data;
|
|
269
|
+
};
|
|
270
|
+
const listen$7 = () => {
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
273
|
+
throw new TypeError('module is not in web worker scope');
|
|
274
|
+
}
|
|
275
|
+
return globalThis;
|
|
276
|
+
};
|
|
277
|
+
const signal$8 = global => {
|
|
278
|
+
global.postMessage(readyMessage);
|
|
279
|
+
};
|
|
280
|
+
class IpcChildWithModuleWorker extends Ipc {
|
|
281
|
+
getData(event) {
|
|
282
|
+
return getData$2(event);
|
|
283
|
+
}
|
|
284
|
+
send(message) {
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
this._rawIpc.postMessage(message);
|
|
287
|
+
}
|
|
288
|
+
sendAndTransfer(message) {
|
|
289
|
+
const transfer = getTransferrables(message);
|
|
290
|
+
// @ts-ignore
|
|
291
|
+
this._rawIpc.postMessage(message, transfer);
|
|
292
|
+
}
|
|
293
|
+
dispose() {
|
|
294
|
+
// ignore
|
|
295
|
+
}
|
|
296
|
+
onClose(callback) {
|
|
297
|
+
// ignore
|
|
298
|
+
}
|
|
299
|
+
onMessage(callback) {
|
|
300
|
+
this._rawIpc.addEventListener('message', callback);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const wrap$f = global => {
|
|
304
|
+
return new IpcChildWithModuleWorker(global);
|
|
305
|
+
};
|
|
306
|
+
const waitForFirstMessage = async port => {
|
|
307
|
+
const {
|
|
308
|
+
resolve,
|
|
309
|
+
promise
|
|
310
|
+
} = Promise.withResolvers();
|
|
311
|
+
port.addEventListener('message', resolve, {
|
|
312
|
+
once: true
|
|
313
|
+
});
|
|
314
|
+
const event = await promise;
|
|
315
|
+
// @ts-ignore
|
|
316
|
+
return event.data;
|
|
317
|
+
};
|
|
318
|
+
const listen$6 = async () => {
|
|
319
|
+
const parentIpcRaw = listen$7();
|
|
320
|
+
signal$8(parentIpcRaw);
|
|
321
|
+
const parentIpc = wrap$f(parentIpcRaw);
|
|
322
|
+
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
323
|
+
if (firstMessage.method !== 'initialize') {
|
|
324
|
+
throw new IpcError('unexpected first message');
|
|
325
|
+
}
|
|
326
|
+
const type = firstMessage.params[0];
|
|
327
|
+
if (type === 'message-port') {
|
|
328
|
+
parentIpc.send({
|
|
329
|
+
jsonrpc: '2.0',
|
|
330
|
+
id: firstMessage.id,
|
|
331
|
+
result: null
|
|
332
|
+
});
|
|
333
|
+
parentIpc.dispose();
|
|
334
|
+
const port = firstMessage.params[1];
|
|
335
|
+
return port;
|
|
336
|
+
}
|
|
337
|
+
return globalThis;
|
|
338
|
+
};
|
|
339
|
+
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
340
|
+
getData(event) {
|
|
341
|
+
return getData$2(event);
|
|
342
|
+
}
|
|
343
|
+
send(message) {
|
|
344
|
+
this._rawIpc.postMessage(message);
|
|
345
|
+
}
|
|
346
|
+
sendAndTransfer(message) {
|
|
347
|
+
const transfer = getTransferrables(message);
|
|
348
|
+
this._rawIpc.postMessage(message, transfer);
|
|
349
|
+
}
|
|
350
|
+
dispose() {
|
|
351
|
+
if (this._rawIpc.close) {
|
|
352
|
+
this._rawIpc.close();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
onClose(callback) {
|
|
356
|
+
// ignore
|
|
357
|
+
}
|
|
358
|
+
onMessage(callback) {
|
|
359
|
+
this._rawIpc.addEventListener('message', callback);
|
|
360
|
+
this._rawIpc.start();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const wrap$e = port => {
|
|
364
|
+
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
365
|
+
};
|
|
366
|
+
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
367
|
+
__proto__: null,
|
|
368
|
+
listen: listen$6,
|
|
369
|
+
wrap: wrap$e
|
|
370
|
+
};
|
|
371
|
+
const addListener = (emitter, type, callback) => {
|
|
372
|
+
if ('addEventListener' in emitter) {
|
|
373
|
+
emitter.addEventListener(type, callback);
|
|
374
|
+
} else {
|
|
375
|
+
emitter.on(type, callback);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
const removeListener = (emitter, type, callback) => {
|
|
379
|
+
if ('removeEventListener' in emitter) {
|
|
380
|
+
emitter.removeEventListener(type, callback);
|
|
381
|
+
} else {
|
|
382
|
+
emitter.off(type, callback);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
386
|
+
const {
|
|
387
|
+
resolve,
|
|
388
|
+
promise
|
|
389
|
+
} = Promise.withResolvers();
|
|
390
|
+
const listenerMap = Object.create(null);
|
|
391
|
+
const cleanup = value => {
|
|
392
|
+
for (const event of Object.keys(eventMap)) {
|
|
393
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
394
|
+
}
|
|
395
|
+
resolve(value);
|
|
396
|
+
};
|
|
397
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
398
|
+
const listener = event => {
|
|
399
|
+
cleanup({
|
|
400
|
+
type,
|
|
401
|
+
event
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
addListener(eventEmitter, event, listener);
|
|
405
|
+
listenerMap[event] = listener;
|
|
406
|
+
}
|
|
407
|
+
return promise;
|
|
408
|
+
};
|
|
409
|
+
const Message$1 = 3;
|
|
410
|
+
const create$5$1 = async ({
|
|
411
|
+
messagePort,
|
|
412
|
+
isMessagePortOpen
|
|
413
|
+
}) => {
|
|
414
|
+
if (!isMessagePort(messagePort)) {
|
|
415
|
+
throw new IpcError('port must be of type MessagePort');
|
|
416
|
+
}
|
|
417
|
+
if (isMessagePortOpen) {
|
|
418
|
+
return messagePort;
|
|
419
|
+
}
|
|
420
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
421
|
+
message: Message$1
|
|
422
|
+
});
|
|
423
|
+
messagePort.start();
|
|
424
|
+
const {
|
|
425
|
+
type,
|
|
426
|
+
event
|
|
427
|
+
} = await eventPromise;
|
|
428
|
+
if (type !== Message$1) {
|
|
429
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
430
|
+
}
|
|
431
|
+
if (event.data !== readyMessage) {
|
|
432
|
+
throw new IpcError('unexpected first message');
|
|
433
|
+
}
|
|
434
|
+
return messagePort;
|
|
435
|
+
};
|
|
436
|
+
const signal$1 = messagePort => {
|
|
437
|
+
messagePort.start();
|
|
438
|
+
};
|
|
439
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
440
|
+
getData = getData$2;
|
|
441
|
+
send(message) {
|
|
442
|
+
this._rawIpc.postMessage(message);
|
|
443
|
+
}
|
|
444
|
+
sendAndTransfer(message) {
|
|
445
|
+
const transfer = getTransferrables(message);
|
|
446
|
+
this._rawIpc.postMessage(message, transfer);
|
|
447
|
+
}
|
|
448
|
+
dispose() {
|
|
449
|
+
this._rawIpc.close();
|
|
450
|
+
}
|
|
451
|
+
onMessage(callback) {
|
|
452
|
+
this._rawIpc.addEventListener('message', callback);
|
|
453
|
+
}
|
|
454
|
+
onClose(callback) {}
|
|
455
|
+
}
|
|
456
|
+
const wrap$5 = messagePort => {
|
|
457
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
458
|
+
};
|
|
459
|
+
const IpcParentWithMessagePort$1 = {
|
|
460
|
+
__proto__: null,
|
|
461
|
+
create: create$5$1,
|
|
462
|
+
signal: signal$1,
|
|
463
|
+
wrap: wrap$5
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const Two = '2.0';
|
|
467
|
+
const create$4$1 = (method, params) => {
|
|
468
|
+
return {
|
|
469
|
+
jsonrpc: Two,
|
|
470
|
+
method,
|
|
471
|
+
params
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
const callbacks = Object.create(null);
|
|
475
|
+
const set$6 = (id, fn) => {
|
|
476
|
+
callbacks[id] = fn;
|
|
477
|
+
};
|
|
478
|
+
const get$2 = id => {
|
|
479
|
+
return callbacks[id];
|
|
480
|
+
};
|
|
481
|
+
const remove = id => {
|
|
482
|
+
delete callbacks[id];
|
|
483
|
+
};
|
|
484
|
+
let id = 0;
|
|
485
|
+
const create$3$1 = () => {
|
|
486
|
+
return ++id;
|
|
487
|
+
};
|
|
488
|
+
const registerPromise = () => {
|
|
489
|
+
const id = create$3$1();
|
|
490
|
+
const {
|
|
491
|
+
resolve,
|
|
492
|
+
promise
|
|
493
|
+
} = Promise.withResolvers();
|
|
494
|
+
set$6(id, resolve);
|
|
495
|
+
return {
|
|
496
|
+
id,
|
|
497
|
+
promise
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
const create$2$1 = (method, params) => {
|
|
501
|
+
const {
|
|
502
|
+
id,
|
|
503
|
+
promise
|
|
504
|
+
} = registerPromise();
|
|
505
|
+
const message = {
|
|
506
|
+
jsonrpc: Two,
|
|
507
|
+
method,
|
|
508
|
+
params,
|
|
509
|
+
id
|
|
510
|
+
};
|
|
511
|
+
return {
|
|
512
|
+
message,
|
|
513
|
+
promise
|
|
514
|
+
};
|
|
515
|
+
};
|
|
516
|
+
class JsonRpcError extends Error {
|
|
517
|
+
constructor(message) {
|
|
518
|
+
super(message);
|
|
519
|
+
this.name = 'JsonRpcError';
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const NewLine = '\n';
|
|
523
|
+
const DomException = 'DOMException';
|
|
524
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
525
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
526
|
+
const TypeError$1 = 'TypeError';
|
|
527
|
+
const getErrorConstructor = (message, type) => {
|
|
528
|
+
if (type) {
|
|
529
|
+
switch (type) {
|
|
530
|
+
case DomException:
|
|
531
|
+
return DOMException;
|
|
532
|
+
case TypeError$1:
|
|
533
|
+
return TypeError;
|
|
534
|
+
case SyntaxError$1:
|
|
535
|
+
return SyntaxError;
|
|
536
|
+
case ReferenceError$1:
|
|
537
|
+
return ReferenceError;
|
|
538
|
+
default:
|
|
539
|
+
return Error;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (message.startsWith('TypeError: ')) {
|
|
543
|
+
return TypeError;
|
|
544
|
+
}
|
|
545
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
546
|
+
return SyntaxError;
|
|
547
|
+
}
|
|
548
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
549
|
+
return ReferenceError;
|
|
550
|
+
}
|
|
551
|
+
return Error;
|
|
552
|
+
};
|
|
553
|
+
const constructError = (message, type, name) => {
|
|
554
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
555
|
+
if (ErrorConstructor === DOMException && name) {
|
|
556
|
+
return new ErrorConstructor(message, name);
|
|
557
|
+
}
|
|
558
|
+
if (ErrorConstructor === Error) {
|
|
559
|
+
const error = new Error(message);
|
|
560
|
+
if (name && name !== 'VError') {
|
|
561
|
+
error.name = name;
|
|
562
|
+
}
|
|
563
|
+
return error;
|
|
564
|
+
}
|
|
565
|
+
return new ErrorConstructor(message);
|
|
566
|
+
};
|
|
567
|
+
const joinLines = lines => {
|
|
568
|
+
return lines.join(NewLine);
|
|
569
|
+
};
|
|
570
|
+
const splitLines = lines => {
|
|
571
|
+
return lines.split(NewLine);
|
|
572
|
+
};
|
|
573
|
+
const getCurrentStack = () => {
|
|
574
|
+
const stackLinesToSkip = 3;
|
|
575
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
576
|
+
return currentStack;
|
|
577
|
+
};
|
|
578
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
579
|
+
return string.indexOf(NewLine, startIndex);
|
|
580
|
+
};
|
|
581
|
+
const getParentStack = error => {
|
|
582
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
583
|
+
if (parentStack.startsWith(' at')) {
|
|
584
|
+
parentStack = error.message + NewLine + parentStack;
|
|
585
|
+
}
|
|
586
|
+
return parentStack;
|
|
587
|
+
};
|
|
588
|
+
const MethodNotFound = -32601;
|
|
589
|
+
const Custom = -32001;
|
|
590
|
+
const restoreJsonRpcError = error => {
|
|
591
|
+
const currentStack = getCurrentStack();
|
|
592
|
+
if (error && error instanceof Error) {
|
|
593
|
+
if (typeof error.stack === 'string') {
|
|
594
|
+
error.stack = error.stack + NewLine + currentStack;
|
|
595
|
+
}
|
|
596
|
+
return error;
|
|
597
|
+
}
|
|
598
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
599
|
+
const restoredError = new JsonRpcError(error.message);
|
|
600
|
+
const parentStack = getParentStack(error);
|
|
601
|
+
restoredError.stack = parentStack + NewLine + currentStack;
|
|
602
|
+
return restoredError;
|
|
603
|
+
}
|
|
604
|
+
if (error && error.message) {
|
|
605
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
606
|
+
if (error.data) {
|
|
607
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
608
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
609
|
+
} else if (error.data.stack) {
|
|
610
|
+
restoredError.stack = error.data.stack;
|
|
611
|
+
}
|
|
612
|
+
if (error.data.codeFrame) {
|
|
613
|
+
// @ts-ignore
|
|
614
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
615
|
+
}
|
|
616
|
+
if (error.data.code) {
|
|
617
|
+
// @ts-ignore
|
|
618
|
+
restoredError.code = error.data.code;
|
|
619
|
+
}
|
|
620
|
+
if (error.data.type) {
|
|
621
|
+
// @ts-ignore
|
|
622
|
+
restoredError.name = error.data.type;
|
|
623
|
+
}
|
|
624
|
+
} else {
|
|
625
|
+
if (error.stack) {
|
|
626
|
+
const lowerStack = restoredError.stack || '';
|
|
627
|
+
// @ts-ignore
|
|
628
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
629
|
+
const parentStack = getParentStack(error);
|
|
630
|
+
// @ts-ignore
|
|
631
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
632
|
+
}
|
|
633
|
+
if (error.codeFrame) {
|
|
634
|
+
// @ts-ignore
|
|
635
|
+
restoredError.codeFrame = error.codeFrame;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return restoredError;
|
|
639
|
+
}
|
|
640
|
+
if (typeof error === 'string') {
|
|
641
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
642
|
+
}
|
|
643
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
644
|
+
};
|
|
645
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
646
|
+
if ('error' in responseMessage) {
|
|
647
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
648
|
+
throw restoredError;
|
|
649
|
+
}
|
|
650
|
+
if ('result' in responseMessage) {
|
|
651
|
+
return responseMessage.result;
|
|
652
|
+
}
|
|
653
|
+
throw new JsonRpcError('unexpected response message');
|
|
654
|
+
};
|
|
655
|
+
const warn = (...args) => {
|
|
656
|
+
console.warn(...args);
|
|
657
|
+
};
|
|
658
|
+
const resolve = (id, response) => {
|
|
659
|
+
const fn = get$2(id);
|
|
660
|
+
if (!fn) {
|
|
661
|
+
console.log(response);
|
|
662
|
+
warn(`callback ${id} may already be disposed`);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
fn(response);
|
|
666
|
+
remove(id);
|
|
667
|
+
};
|
|
668
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
669
|
+
const getErrorType = prettyError => {
|
|
670
|
+
if (prettyError && prettyError.type) {
|
|
671
|
+
return prettyError.type;
|
|
672
|
+
}
|
|
673
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
674
|
+
return prettyError.constructor.name;
|
|
675
|
+
}
|
|
676
|
+
return undefined;
|
|
677
|
+
};
|
|
678
|
+
const isAlreadyStack = line => {
|
|
679
|
+
return line.trim().startsWith('at ');
|
|
680
|
+
};
|
|
681
|
+
const getStack = prettyError => {
|
|
682
|
+
const stackString = prettyError.stack || '';
|
|
683
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
684
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
685
|
+
return stackString.slice(newLineIndex + 1);
|
|
686
|
+
}
|
|
687
|
+
return stackString;
|
|
688
|
+
};
|
|
689
|
+
const getErrorProperty = (error, prettyError) => {
|
|
690
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
691
|
+
return {
|
|
692
|
+
code: MethodNotFound,
|
|
693
|
+
message: error.message,
|
|
694
|
+
data: error.stack
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
return {
|
|
698
|
+
code: Custom,
|
|
699
|
+
message: prettyError.message,
|
|
700
|
+
data: {
|
|
701
|
+
stack: getStack(prettyError),
|
|
702
|
+
codeFrame: prettyError.codeFrame,
|
|
703
|
+
type: getErrorType(prettyError),
|
|
704
|
+
code: prettyError.code,
|
|
705
|
+
name: prettyError.name
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
};
|
|
709
|
+
const create$1$1 = (id, error) => {
|
|
710
|
+
return {
|
|
711
|
+
jsonrpc: Two,
|
|
712
|
+
id,
|
|
713
|
+
error
|
|
714
|
+
};
|
|
715
|
+
};
|
|
716
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
717
|
+
const prettyError = preparePrettyError(error);
|
|
718
|
+
logError(error, prettyError);
|
|
719
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
720
|
+
return create$1$1(id, errorProperty);
|
|
721
|
+
};
|
|
722
|
+
const create$6 = (message, result) => {
|
|
723
|
+
return {
|
|
724
|
+
jsonrpc: Two,
|
|
725
|
+
id: message.id,
|
|
726
|
+
result: result ?? null
|
|
727
|
+
};
|
|
728
|
+
};
|
|
729
|
+
const getSuccessResponse = (message, result) => {
|
|
730
|
+
const resultProperty = result ?? null;
|
|
731
|
+
return create$6(message, resultProperty);
|
|
732
|
+
};
|
|
733
|
+
const getErrorResponseSimple = (id, error) => {
|
|
734
|
+
return {
|
|
735
|
+
jsonrpc: Two,
|
|
736
|
+
id,
|
|
737
|
+
error: {
|
|
738
|
+
code: Custom,
|
|
739
|
+
// @ts-ignore
|
|
740
|
+
message: error.message,
|
|
741
|
+
data: error
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
746
|
+
try {
|
|
747
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
748
|
+
return getSuccessResponse(message, result);
|
|
749
|
+
} catch (error) {
|
|
750
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
751
|
+
return getErrorResponseSimple(message.id, error);
|
|
752
|
+
}
|
|
753
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
const defaultPreparePrettyError = error => {
|
|
757
|
+
return error;
|
|
758
|
+
};
|
|
759
|
+
const defaultLogError = () => {
|
|
760
|
+
// ignore
|
|
761
|
+
};
|
|
762
|
+
const defaultRequiresSocket = () => {
|
|
763
|
+
return false;
|
|
764
|
+
};
|
|
765
|
+
const defaultResolve = resolve;
|
|
766
|
+
|
|
767
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
768
|
+
const normalizeParams = args => {
|
|
769
|
+
if (args.length === 1) {
|
|
770
|
+
const options = args[0];
|
|
771
|
+
return {
|
|
772
|
+
ipc: options.ipc,
|
|
773
|
+
message: options.message,
|
|
774
|
+
execute: options.execute,
|
|
775
|
+
resolve: options.resolve || defaultResolve,
|
|
776
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
777
|
+
logError: options.logError || defaultLogError,
|
|
778
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
return {
|
|
782
|
+
ipc: args[0],
|
|
783
|
+
message: args[1],
|
|
784
|
+
execute: args[2],
|
|
785
|
+
resolve: args[3],
|
|
786
|
+
preparePrettyError: args[4],
|
|
787
|
+
logError: args[5],
|
|
788
|
+
requiresSocket: args[6]
|
|
789
|
+
};
|
|
790
|
+
};
|
|
791
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
792
|
+
const options = normalizeParams(args);
|
|
793
|
+
const {
|
|
794
|
+
message,
|
|
795
|
+
ipc,
|
|
796
|
+
execute,
|
|
797
|
+
resolve,
|
|
798
|
+
preparePrettyError,
|
|
799
|
+
logError,
|
|
800
|
+
requiresSocket
|
|
801
|
+
} = options;
|
|
802
|
+
if ('id' in message) {
|
|
803
|
+
if ('method' in message) {
|
|
804
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
805
|
+
try {
|
|
806
|
+
ipc.send(response);
|
|
807
|
+
} catch (error) {
|
|
808
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
809
|
+
ipc.send(errorResponse);
|
|
810
|
+
}
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
resolve(message.id, message);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if ('method' in message) {
|
|
817
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
throw new JsonRpcError('unexpected message');
|
|
821
|
+
};
|
|
822
|
+
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
823
|
+
const {
|
|
824
|
+
message,
|
|
825
|
+
promise
|
|
826
|
+
} = create$2$1(method, params);
|
|
827
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
828
|
+
ipc.sendAndTransfer(message);
|
|
829
|
+
} else {
|
|
830
|
+
ipc.send(message);
|
|
831
|
+
}
|
|
832
|
+
const responseMessage = await promise;
|
|
833
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
834
|
+
};
|
|
835
|
+
const send = (transport, method, ...params) => {
|
|
836
|
+
const message = create$4$1(method, params);
|
|
837
|
+
transport.send(message);
|
|
838
|
+
};
|
|
839
|
+
const invoke$3 = (ipc, method, ...params) => {
|
|
840
|
+
return invokeHelper(ipc, method, params, false);
|
|
841
|
+
};
|
|
842
|
+
const invokeAndTransfer$3 = (ipc, method, ...params) => {
|
|
843
|
+
return invokeHelper(ipc, method, params, true);
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
class CommandNotFoundError extends Error {
|
|
847
|
+
constructor(command) {
|
|
848
|
+
super(`Command not found ${command}`);
|
|
849
|
+
this.name = 'CommandNotFoundError';
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
const commands = Object.create(null);
|
|
853
|
+
const register = commandMap => {
|
|
854
|
+
Object.assign(commands, commandMap);
|
|
855
|
+
};
|
|
856
|
+
const getCommand$1 = key => {
|
|
857
|
+
return commands[key];
|
|
858
|
+
};
|
|
859
|
+
const execute = (command, ...args) => {
|
|
860
|
+
const fn = getCommand$1(command);
|
|
861
|
+
if (!fn) {
|
|
862
|
+
throw new CommandNotFoundError(command);
|
|
863
|
+
}
|
|
864
|
+
return fn(...args);
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
const createRpc = ipc => {
|
|
868
|
+
const rpc = {
|
|
869
|
+
// @ts-ignore
|
|
870
|
+
ipc,
|
|
871
|
+
/**
|
|
872
|
+
* @deprecated
|
|
873
|
+
*/
|
|
874
|
+
send(method, ...params) {
|
|
875
|
+
send(ipc, method, ...params);
|
|
876
|
+
},
|
|
877
|
+
invoke(method, ...params) {
|
|
878
|
+
return invoke$3(ipc, method, ...params);
|
|
879
|
+
},
|
|
880
|
+
invokeAndTransfer(method, ...params) {
|
|
881
|
+
return invokeAndTransfer$3(ipc, method, ...params);
|
|
882
|
+
},
|
|
883
|
+
async dispose() {
|
|
884
|
+
await ipc?.dispose();
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
return rpc;
|
|
888
|
+
};
|
|
889
|
+
const requiresSocket = () => {
|
|
890
|
+
return false;
|
|
891
|
+
};
|
|
892
|
+
const preparePrettyError = error => {
|
|
893
|
+
return error;
|
|
894
|
+
};
|
|
895
|
+
const logError = () => {
|
|
896
|
+
// handled by renderer worker
|
|
897
|
+
};
|
|
898
|
+
const handleMessage = event => {
|
|
899
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
900
|
+
const actualExecute = event?.target?.execute || execute;
|
|
901
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
902
|
+
};
|
|
903
|
+
const handleIpc = ipc => {
|
|
904
|
+
if ('addEventListener' in ipc) {
|
|
905
|
+
ipc.addEventListener('message', handleMessage);
|
|
906
|
+
} else if ('on' in ipc) {
|
|
907
|
+
// deprecated
|
|
908
|
+
ipc.on('message', handleMessage);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
const listen$1 = async (module, options) => {
|
|
912
|
+
const rawIpc = await module.listen(options);
|
|
913
|
+
if (module.signal) {
|
|
914
|
+
module.signal(rawIpc);
|
|
915
|
+
}
|
|
916
|
+
const ipc = module.wrap(rawIpc);
|
|
917
|
+
return ipc;
|
|
918
|
+
};
|
|
919
|
+
const create$5 = async ({
|
|
920
|
+
commandMap,
|
|
921
|
+
messagePort
|
|
922
|
+
}) => {
|
|
923
|
+
// TODO create a commandMap per rpc instance
|
|
924
|
+
register(commandMap);
|
|
925
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
926
|
+
messagePort,
|
|
927
|
+
isMessagePortOpen: true
|
|
928
|
+
});
|
|
929
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
930
|
+
handleIpc(ipc);
|
|
931
|
+
const rpc = createRpc(ipc);
|
|
932
|
+
messagePort.start();
|
|
933
|
+
return rpc;
|
|
934
|
+
};
|
|
935
|
+
const create$4 = async ({
|
|
936
|
+
commandMap,
|
|
937
|
+
messagePort
|
|
938
|
+
}) => {
|
|
939
|
+
return create$5({
|
|
940
|
+
commandMap,
|
|
941
|
+
messagePort
|
|
942
|
+
});
|
|
943
|
+
};
|
|
944
|
+
const PlainMessagePortRpcParent = {
|
|
945
|
+
__proto__: null,
|
|
946
|
+
create: create$4
|
|
947
|
+
};
|
|
948
|
+
const create$3 = async ({
|
|
949
|
+
commandMap
|
|
950
|
+
}) => {
|
|
951
|
+
// TODO create a commandMap per rpc instance
|
|
952
|
+
register(commandMap);
|
|
953
|
+
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
954
|
+
handleIpc(ipc);
|
|
955
|
+
const rpc = createRpc(ipc);
|
|
956
|
+
return rpc;
|
|
957
|
+
};
|
|
958
|
+
const WebWorkerRpcClient = {
|
|
959
|
+
__proto__: null,
|
|
960
|
+
create: create$3
|
|
961
|
+
};
|
|
962
|
+
const createMockRpc = ({
|
|
963
|
+
commandMap
|
|
964
|
+
}) => {
|
|
965
|
+
const invocations = [];
|
|
966
|
+
const invoke = (method, ...params) => {
|
|
967
|
+
invocations.push([method, ...params]);
|
|
968
|
+
const command = commandMap[method];
|
|
969
|
+
if (!command) {
|
|
970
|
+
throw new Error(`command ${method} not found`);
|
|
971
|
+
}
|
|
972
|
+
return command(...params);
|
|
973
|
+
};
|
|
974
|
+
const mockRpc = {
|
|
975
|
+
invoke,
|
|
976
|
+
invokeAndTransfer: invoke,
|
|
977
|
+
invocations
|
|
978
|
+
};
|
|
979
|
+
return mockRpc;
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
const EditorWorker$1 = 99;
|
|
983
|
+
const ExtensionHostWorker = 44;
|
|
984
|
+
|
|
985
|
+
const rpcs = Object.create(null);
|
|
986
|
+
const set$5 = (id, rpc) => {
|
|
987
|
+
rpcs[id] = rpc;
|
|
988
|
+
};
|
|
989
|
+
const get$1 = id => {
|
|
990
|
+
return rpcs[id];
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
const create$2 = rpcId => {
|
|
994
|
+
return {
|
|
995
|
+
// @ts-ignore
|
|
996
|
+
invoke(method, ...params) {
|
|
997
|
+
const rpc = get$1(rpcId);
|
|
998
|
+
// @ts-ignore
|
|
999
|
+
return rpc.invoke(method, ...params);
|
|
1000
|
+
},
|
|
1001
|
+
// @ts-ignore
|
|
1002
|
+
invokeAndTransfer(method, ...params) {
|
|
1003
|
+
const rpc = get$1(rpcId);
|
|
1004
|
+
// @ts-ignore
|
|
1005
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1006
|
+
},
|
|
1007
|
+
set(rpc) {
|
|
1008
|
+
set$5(rpcId, rpc);
|
|
1009
|
+
},
|
|
1010
|
+
async dispose() {
|
|
1011
|
+
const rpc = get$1(rpcId);
|
|
1012
|
+
await rpc.dispose();
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
const {
|
|
1018
|
+
invoke: invoke$2,
|
|
1019
|
+
invokeAndTransfer: invokeAndTransfer$2,
|
|
1020
|
+
set: set$4,
|
|
1021
|
+
dispose: dispose$3
|
|
1022
|
+
} = create$2(EditorWorker$1);
|
|
1023
|
+
const sendMessagePortToExtensionHostWorker$1 = async port => {
|
|
1024
|
+
const command = 'HandleMessagePort.handleMessagePort2';
|
|
1025
|
+
await invokeAndTransfer$2(
|
|
1026
|
+
// @ts-ignore
|
|
1027
|
+
'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0);
|
|
1028
|
+
};
|
|
1029
|
+
// TODO add tests for this
|
|
1030
|
+
const activateByEvent = async event => {
|
|
1031
|
+
// @ts-ignore
|
|
1032
|
+
await invoke$2('ActivateByEvent.activateByEvent', event);
|
|
1033
|
+
};
|
|
1034
|
+
const applyEdit = async (editorUid, changes) => {
|
|
1035
|
+
// @ts-ignore
|
|
1036
|
+
await invoke$2('Editor.applyEdit2', editorUid, changes);
|
|
1037
|
+
};
|
|
1038
|
+
const applyWorkspaceEdit = async (editorUid, changes) => {
|
|
1039
|
+
// @ts-ignore
|
|
1040
|
+
await invoke$2('Editor.applyWorkspaceEdit', editorUid, changes);
|
|
1041
|
+
};
|
|
1042
|
+
const closeWidget = async (editorUid, widgetId, widgetName, focusId) => {
|
|
1043
|
+
// @ts-ignore
|
|
1044
|
+
await invoke$2('Editor.closeWidget2', editorUid, widgetId, widgetName, focusId);
|
|
1045
|
+
};
|
|
1046
|
+
const getWordAt = async (uid, rowIndex, columnIndex) => {
|
|
1047
|
+
// @ts-ignore
|
|
1048
|
+
const word = await invoke$2('Editor.getWordAt2', uid, rowIndex, columnIndex);
|
|
1049
|
+
return word;
|
|
1050
|
+
};
|
|
1051
|
+
const getLines = async editorUid => {
|
|
1052
|
+
const lines = await invoke$2('Editor.getLines2', editorUid);
|
|
1053
|
+
return lines;
|
|
1054
|
+
};
|
|
1055
|
+
const getPositionAtCursor = async parentUid => {
|
|
1056
|
+
const position = await invoke$2('Editor.getPositionAtCursor', parentUid);
|
|
1057
|
+
return position;
|
|
1058
|
+
};
|
|
1059
|
+
const getOffsetAtCursor = async editorId => {
|
|
1060
|
+
// @ts-ignore
|
|
1061
|
+
return await invoke$2('Editor.getOffsetAtCursor', editorId);
|
|
1062
|
+
};
|
|
1063
|
+
const getSelections = async editorUid => {
|
|
1064
|
+
const selections = await invoke$2('Editor.getSelections2', editorUid);
|
|
1065
|
+
return selections;
|
|
1066
|
+
};
|
|
1067
|
+
const getWordAtOffset2 = async editorUid => {
|
|
1068
|
+
return invoke$2('Editor.getWordAtOffset2', editorUid);
|
|
1069
|
+
};
|
|
1070
|
+
const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
|
|
1071
|
+
return invoke$2('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
|
|
1072
|
+
};
|
|
1073
|
+
const updateDebugInfo = async info => {
|
|
1074
|
+
await invoke$2('Editor.updateDebugInfo', info);
|
|
1075
|
+
};
|
|
1076
|
+
const getUri = async editorUid => {
|
|
1077
|
+
// @ts-ignore
|
|
1078
|
+
return invoke$2('Editor.getUri', editorUid);
|
|
1079
|
+
};
|
|
1080
|
+
const getLanguageId = async editorUid => {
|
|
1081
|
+
// @ts-ignore
|
|
1082
|
+
return invoke$2('Editor.getLanguageId', editorUid);
|
|
1083
|
+
};
|
|
1084
|
+
const getProblems = async () => {
|
|
1085
|
+
// @ts-ignore
|
|
1086
|
+
return invoke$2('Editor.getProblems');
|
|
1087
|
+
};
|
|
1088
|
+
const registerMockRpc$1 = commandMap => {
|
|
1089
|
+
const mockRpc = createMockRpc({
|
|
1090
|
+
commandMap
|
|
1091
|
+
});
|
|
1092
|
+
set$4(mockRpc);
|
|
1093
|
+
return mockRpc;
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
const EditorWorker = {
|
|
1097
|
+
__proto__: null,
|
|
1098
|
+
activateByEvent,
|
|
1099
|
+
applyEdit,
|
|
1100
|
+
applyWorkspaceEdit,
|
|
1101
|
+
closeWidget,
|
|
1102
|
+
dispose: dispose$3,
|
|
1103
|
+
getLanguageId,
|
|
1104
|
+
getLines,
|
|
1105
|
+
getOffsetAtCursor,
|
|
1106
|
+
getPositionAtCursor,
|
|
1107
|
+
getProblems,
|
|
1108
|
+
getSelections,
|
|
1109
|
+
getUri,
|
|
1110
|
+
getWordAt,
|
|
1111
|
+
getWordAtOffset2,
|
|
1112
|
+
getWordBefore,
|
|
1113
|
+
invoke: invoke$2,
|
|
1114
|
+
invokeAndTransfer: invokeAndTransfer$2,
|
|
1115
|
+
registerMockRpc: registerMockRpc$1,
|
|
1116
|
+
sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
|
|
1117
|
+
set: set$4,
|
|
1118
|
+
updateDebugInfo
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1121
|
+
const {
|
|
1122
|
+
invoke: invoke$1,
|
|
1123
|
+
invokeAndTransfer: invokeAndTransfer$1,
|
|
1124
|
+
set: set$3,
|
|
1125
|
+
dispose: dispose$2
|
|
1126
|
+
} = create$2(ExtensionHostWorker);
|
|
1127
|
+
const executeReferenceProvider = async (id, offset) => {
|
|
1128
|
+
// @ts-ignore
|
|
1129
|
+
return invoke$1('ExtensionHostReference.executeReferenceProvider', id, offset);
|
|
1130
|
+
};
|
|
1131
|
+
const executeFileReferenceProvider = async id => {
|
|
1132
|
+
// @ts-ignore
|
|
1133
|
+
return invoke$1('ExtensionHostReference.executeFileReferenceProvider', id);
|
|
1134
|
+
};
|
|
1135
|
+
const getRuntimeStatus = async extensionId => {
|
|
1136
|
+
// @ts-ignore
|
|
1137
|
+
return invoke$1('ExtensionHost.getRuntimeStatus', extensionId);
|
|
1138
|
+
};
|
|
1139
|
+
const registerMockRpc = commandMap => {
|
|
1140
|
+
const mockRpc = createMockRpc({
|
|
1141
|
+
commandMap
|
|
1142
|
+
});
|
|
1143
|
+
set$3(mockRpc);
|
|
1144
|
+
return mockRpc;
|
|
1145
|
+
};
|
|
1146
|
+
|
|
1147
|
+
const ExtensionHost = {
|
|
1148
|
+
__proto__: null,
|
|
1149
|
+
dispose: dispose$2,
|
|
1150
|
+
executeFileReferenceProvider,
|
|
1151
|
+
executeReferenceProvider,
|
|
1152
|
+
getRuntimeStatus,
|
|
1153
|
+
invoke: invoke$1,
|
|
1154
|
+
invokeAndTransfer: invokeAndTransfer$1,
|
|
1155
|
+
registerMockRpc,
|
|
1156
|
+
set: set$3
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
const {
|
|
1160
|
+
invoke,
|
|
1161
|
+
set: set$2,
|
|
1162
|
+
invokeAndTransfer
|
|
1163
|
+
} = EditorWorker;
|
|
1164
|
+
|
|
1165
|
+
const FocusEditorHovers = 9;
|
|
1166
|
+
const FocusEditorRename = 11;
|
|
1167
|
+
|
|
1168
|
+
const Hover = 6;
|
|
1169
|
+
|
|
1170
|
+
const close = async state => {
|
|
1171
|
+
const {
|
|
1172
|
+
editorUid
|
|
1173
|
+
} = state;
|
|
1174
|
+
// @ts-ignore
|
|
1175
|
+
await invoke('Editor.closeWidget2', editorUid, Hover, 'Hovers', FocusEditorHovers);
|
|
1176
|
+
return state;
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
const toCommandId = key => {
|
|
1180
|
+
const dotIndex = key.indexOf('.');
|
|
1181
|
+
return key.slice(dotIndex + 1);
|
|
1182
|
+
};
|
|
1183
|
+
const create$1 = () => {
|
|
1184
|
+
const states = Object.create(null);
|
|
1185
|
+
const commandMapRef = {};
|
|
1186
|
+
return {
|
|
1187
|
+
get(uid) {
|
|
1188
|
+
return states[uid];
|
|
1189
|
+
},
|
|
1190
|
+
set(uid, oldState, newState) {
|
|
1191
|
+
states[uid] = {
|
|
1192
|
+
oldState,
|
|
1193
|
+
newState
|
|
1194
|
+
};
|
|
1195
|
+
},
|
|
1196
|
+
dispose(uid) {
|
|
1197
|
+
delete states[uid];
|
|
1198
|
+
},
|
|
1199
|
+
getKeys() {
|
|
1200
|
+
return Object.keys(states).map(key => {
|
|
1201
|
+
return Number.parseInt(key);
|
|
1202
|
+
});
|
|
1203
|
+
},
|
|
1204
|
+
clear() {
|
|
1205
|
+
for (const key of Object.keys(states)) {
|
|
1206
|
+
delete states[key];
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
wrapCommand(fn) {
|
|
1210
|
+
const wrapped = async (uid, ...args) => {
|
|
1211
|
+
const {
|
|
1212
|
+
newState
|
|
1213
|
+
} = states[uid];
|
|
1214
|
+
const newerState = await fn(newState, ...args);
|
|
1215
|
+
if (newState === newerState) {
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
const latest = states[uid];
|
|
1219
|
+
states[uid] = {
|
|
1220
|
+
oldState: latest.oldState,
|
|
1221
|
+
newState: newerState
|
|
1222
|
+
};
|
|
1223
|
+
};
|
|
1224
|
+
return wrapped;
|
|
1225
|
+
},
|
|
1226
|
+
wrapGetter(fn) {
|
|
1227
|
+
const wrapped = (uid, ...args) => {
|
|
1228
|
+
const {
|
|
1229
|
+
newState
|
|
1230
|
+
} = states[uid];
|
|
1231
|
+
return fn(newState, ...args);
|
|
1232
|
+
};
|
|
1233
|
+
return wrapped;
|
|
1234
|
+
},
|
|
1235
|
+
diff(uid, modules, numbers) {
|
|
1236
|
+
const {
|
|
1237
|
+
oldState,
|
|
1238
|
+
newState
|
|
1239
|
+
} = states[uid];
|
|
1240
|
+
const diffResult = [];
|
|
1241
|
+
for (let i = 0; i < modules.length; i++) {
|
|
1242
|
+
const fn = modules[i];
|
|
1243
|
+
if (!fn(oldState, newState)) {
|
|
1244
|
+
diffResult.push(numbers[i]);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
return diffResult;
|
|
1248
|
+
},
|
|
1249
|
+
getCommandIds() {
|
|
1250
|
+
const keys = Object.keys(commandMapRef);
|
|
1251
|
+
const ids = keys.map(toCommandId);
|
|
1252
|
+
return ids;
|
|
1253
|
+
},
|
|
1254
|
+
registerCommands(commandMap) {
|
|
1255
|
+
Object.assign(commandMapRef, commandMap);
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
const {
|
|
1261
|
+
get,
|
|
1262
|
+
set: set$1,
|
|
1263
|
+
wrapCommand,
|
|
1264
|
+
dispose: dispose$1
|
|
1265
|
+
} = create$1();
|
|
1266
|
+
|
|
1267
|
+
const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
|
|
1268
|
+
const state = {
|
|
1269
|
+
uid,
|
|
1270
|
+
focusedIndex: -1,
|
|
1271
|
+
x: 0,
|
|
1272
|
+
y: 0,
|
|
1273
|
+
width: 0,
|
|
1274
|
+
height: 0,
|
|
1275
|
+
focused: false,
|
|
1276
|
+
leadingWord: '',
|
|
1277
|
+
version: 0,
|
|
1278
|
+
editorUid,
|
|
1279
|
+
editorLanguageId
|
|
1280
|
+
};
|
|
1281
|
+
set$1(uid, state, state);
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
const isEqual$3 = (oldState, newState) => {
|
|
1285
|
+
return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
const isEqual$2 = (oldState, newState) => {
|
|
1289
|
+
return oldState.version === newState.version;
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1292
|
+
const isEqual$1 = (oldState, newState) => {
|
|
1293
|
+
return oldState.version === newState.version;
|
|
1294
|
+
};
|
|
1295
|
+
|
|
1296
|
+
const isEqual = (oldState, newState) => {
|
|
1297
|
+
return oldState.version === newState.version;
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
const RenderBounds = 8;
|
|
1301
|
+
const RenderEventListeners = 11;
|
|
1302
|
+
const RenderUid = 12;
|
|
1303
|
+
const RenderContent = 13;
|
|
1304
|
+
const RenderFocusContext = 14;
|
|
1305
|
+
|
|
1306
|
+
const modules = [isEqual$2, isEqual$3, isEqual, isEqual$1];
|
|
1307
|
+
const numbers = [RenderEventListeners, RenderBounds, RenderUid, RenderFocusContext];
|
|
1308
|
+
|
|
1309
|
+
const diff = (oldState, newState) => {
|
|
1310
|
+
const diffResult = [];
|
|
1311
|
+
for (let i = 0; i < modules.length; i++) {
|
|
1312
|
+
const fn = modules[i];
|
|
1313
|
+
if (!fn(oldState, newState)) {
|
|
1314
|
+
diffResult.push(numbers[i]);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
return diffResult;
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
const diff2 = uid => {
|
|
1321
|
+
const {
|
|
1322
|
+
oldState,
|
|
1323
|
+
newState
|
|
1324
|
+
} = get(uid);
|
|
1325
|
+
const diffResult = diff(oldState, newState);
|
|
1326
|
+
return diffResult;
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
const dispose = uid => {
|
|
1330
|
+
dispose$1(uid);
|
|
1331
|
+
};
|
|
1332
|
+
|
|
1333
|
+
const commandIds = ['handleSliderPointerDown', 'handleSliderPointerMove', 'initialize'];
|
|
1334
|
+
|
|
1335
|
+
const getCommandIds = () => {
|
|
1336
|
+
return commandIds;
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1339
|
+
const Enter = 3;
|
|
1340
|
+
const Escape = 8;
|
|
1341
|
+
const Space = 9;
|
|
1342
|
+
const End = 255;
|
|
1343
|
+
const Home = 12;
|
|
1344
|
+
const UpArrow = 14;
|
|
1345
|
+
const DownArrow = 16;
|
|
1346
|
+
|
|
1347
|
+
const CtrlCmd = 1 << 11 >>> 0;
|
|
1348
|
+
|
|
1349
|
+
const getCommand = shortId => {
|
|
1350
|
+
return {
|
|
1351
|
+
command: 'Editor.executeWidgetCommand',
|
|
1352
|
+
args: ['Hovers', `Hovers.${shortId}`, 0, Hover]
|
|
1353
|
+
};
|
|
1354
|
+
};
|
|
1355
|
+
const getKeyBindings = () => {
|
|
1356
|
+
return [{
|
|
1357
|
+
key: DownArrow,
|
|
1358
|
+
...getCommand('focusNext'),
|
|
1359
|
+
when: FocusEditorHovers
|
|
1360
|
+
}, {
|
|
1361
|
+
key: UpArrow,
|
|
1362
|
+
...getCommand('focusPrevious'),
|
|
1363
|
+
when: FocusEditorHovers
|
|
1364
|
+
}, {
|
|
1365
|
+
key: Enter,
|
|
1366
|
+
...getCommand('selectCurrent'),
|
|
1367
|
+
when: FocusEditorHovers
|
|
1368
|
+
}, {
|
|
1369
|
+
key: End,
|
|
1370
|
+
...getCommand('focusLast'),
|
|
1371
|
+
when: FocusEditorHovers
|
|
1372
|
+
}, {
|
|
1373
|
+
key: Home,
|
|
1374
|
+
...getCommand('focusFirst'),
|
|
1375
|
+
when: FocusEditorHovers
|
|
1376
|
+
}, {
|
|
1377
|
+
key: CtrlCmd | Space,
|
|
1378
|
+
...getCommand('toggleDetails'),
|
|
1379
|
+
when: FocusEditorHovers
|
|
1380
|
+
}, {
|
|
1381
|
+
key: Escape,
|
|
1382
|
+
...getCommand('close'),
|
|
1383
|
+
when: FocusEditorHovers
|
|
1384
|
+
}];
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
const getPortTuple = () => {
|
|
1388
|
+
const {
|
|
1389
|
+
port1,
|
|
1390
|
+
port2
|
|
1391
|
+
} = new MessageChannel();
|
|
1392
|
+
return {
|
|
1393
|
+
port1,
|
|
1394
|
+
port2
|
|
1395
|
+
};
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1398
|
+
const sendMessagePortToExtensionHostWorker = async port => {
|
|
1399
|
+
const command = 'HandleMessagePort.handleMessagePort2';
|
|
1400
|
+
// @ts-ignore
|
|
1401
|
+
await invokeAndTransfer(
|
|
1402
|
+
// @ts-ignore
|
|
1403
|
+
'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0 // TODO
|
|
1404
|
+
);
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
const createExtensionHostRpc = async () => {
|
|
1408
|
+
try {
|
|
1409
|
+
const {
|
|
1410
|
+
port1,
|
|
1411
|
+
port2
|
|
1412
|
+
} = getPortTuple();
|
|
1413
|
+
await sendMessagePortToExtensionHostWorker(port2);
|
|
1414
|
+
const rpc = await PlainMessagePortRpcParent.create({
|
|
1415
|
+
commandMap: {},
|
|
1416
|
+
messagePort: port1
|
|
1417
|
+
});
|
|
1418
|
+
return rpc;
|
|
1419
|
+
} catch (error) {
|
|
1420
|
+
throw new VError(error, `Failed to create extension host rpc`);
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
|
|
1424
|
+
const {
|
|
1425
|
+
set
|
|
1426
|
+
} = ExtensionHost;
|
|
1427
|
+
|
|
1428
|
+
const initialize = async () => {
|
|
1429
|
+
const rpc = await createExtensionHostRpc();
|
|
1430
|
+
set(rpc);
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
const loadContent = async state => {
|
|
1434
|
+
return {
|
|
1435
|
+
...state
|
|
1436
|
+
};
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1439
|
+
const SetBounds = 'Viewlet.setBounds';
|
|
1440
|
+
const SetDom2 = 'Viewlet.setDom2';
|
|
1441
|
+
const SetUid = 'Viewlet.setUid';
|
|
1442
|
+
const SetEventListeners = 'Viewlet.registerEventListeners';
|
|
1443
|
+
|
|
1444
|
+
const renderBounds = (oldState, newState) => {
|
|
1445
|
+
const {
|
|
1446
|
+
x,
|
|
1447
|
+
y,
|
|
1448
|
+
width,
|
|
1449
|
+
height,
|
|
1450
|
+
uid
|
|
1451
|
+
} = newState;
|
|
1452
|
+
return [SetBounds, uid, x, y, width, height];
|
|
1453
|
+
};
|
|
1454
|
+
|
|
1455
|
+
const renderContent = (oldState, newState) => {
|
|
1456
|
+
const {
|
|
1457
|
+
uid
|
|
1458
|
+
} = newState;
|
|
1459
|
+
const dom = [];
|
|
1460
|
+
return [SetDom2, uid, dom];
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
const HandleWheel = 'handleWheel';
|
|
1464
|
+
|
|
1465
|
+
const getEventListeners = () => {
|
|
1466
|
+
return [{
|
|
1467
|
+
name: HandleWheel,
|
|
1468
|
+
params: ['EditorHover.handleWheel', 'event.deltaMode', 'event.deltaY'],
|
|
1469
|
+
passive: true
|
|
1470
|
+
}];
|
|
1471
|
+
};
|
|
1472
|
+
|
|
1473
|
+
const renderEventListeners = state => {
|
|
1474
|
+
const {
|
|
1475
|
+
uid
|
|
1476
|
+
} = state;
|
|
1477
|
+
const eventListeners = getEventListeners();
|
|
1478
|
+
return [SetEventListeners, uid, eventListeners];
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
const renderFocusContext = (oldState, newState) => {
|
|
1482
|
+
return [/* method */'Viewlet.setFocusContext', FocusEditorRename];
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
const renderUid = (oldState, newState) => {
|
|
1486
|
+
const {
|
|
1487
|
+
uid,
|
|
1488
|
+
editorUid
|
|
1489
|
+
} = newState;
|
|
1490
|
+
return [SetUid, uid, editorUid];
|
|
1491
|
+
};
|
|
1492
|
+
|
|
1493
|
+
const getRenderer = diffType => {
|
|
1494
|
+
switch (diffType) {
|
|
1495
|
+
case RenderContent:
|
|
1496
|
+
return renderContent;
|
|
1497
|
+
case RenderBounds:
|
|
1498
|
+
return renderBounds;
|
|
1499
|
+
case RenderEventListeners:
|
|
1500
|
+
return renderEventListeners;
|
|
1501
|
+
case RenderUid:
|
|
1502
|
+
return renderUid;
|
|
1503
|
+
case RenderFocusContext:
|
|
1504
|
+
return renderFocusContext;
|
|
1505
|
+
default:
|
|
1506
|
+
throw new Error('unknown renderer');
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
1511
|
+
const commands = [];
|
|
1512
|
+
for (const item of diffResult) {
|
|
1513
|
+
const fn = getRenderer(item);
|
|
1514
|
+
commands.push(fn(oldState, newState));
|
|
1515
|
+
}
|
|
1516
|
+
return commands;
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
const render2 = (uid, diffResult) => {
|
|
1520
|
+
const {
|
|
1521
|
+
oldState,
|
|
1522
|
+
newState
|
|
1523
|
+
} = get(uid);
|
|
1524
|
+
set$1(uid, newState, newState);
|
|
1525
|
+
const commands = applyRender(oldState, newState, diffResult);
|
|
1526
|
+
return commands;
|
|
1527
|
+
};
|
|
1528
|
+
|
|
1529
|
+
const terminate = () => {
|
|
1530
|
+
globalThis.close();
|
|
1531
|
+
};
|
|
1532
|
+
|
|
1533
|
+
const commandMap = {
|
|
1534
|
+
'Hovers.close': wrapCommand(close),
|
|
1535
|
+
'Hovers.create': create,
|
|
1536
|
+
'Hovers.diff2': diff2,
|
|
1537
|
+
'Hovers.dispose': dispose,
|
|
1538
|
+
'Hovers.getCommandIds': getCommandIds,
|
|
1539
|
+
'Hovers.getKeyBindings': getKeyBindings,
|
|
1540
|
+
'Hovers.initialize': initialize,
|
|
1541
|
+
'Hovers.loadContent': wrapCommand(loadContent),
|
|
1542
|
+
'Hovers.render2': render2,
|
|
1543
|
+
'Hovers.terminate': terminate
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
const listen = async () => {
|
|
1547
|
+
const rpc = await WebWorkerRpcClient.create({
|
|
1548
|
+
commandMap: commandMap
|
|
1549
|
+
});
|
|
1550
|
+
set$2(rpc);
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
const main = async () => {
|
|
1554
|
+
await listen();
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
main();
|