@lvce-editor/extension-host-worker 5.17.0 → 5.19.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/dist/extensionHostWorkerMain.js +198 -112
- package/package.json +1 -1
|
@@ -1749,11 +1749,11 @@ const remove$3 = id => {
|
|
|
1749
1749
|
delete callbacks[id];
|
|
1750
1750
|
};
|
|
1751
1751
|
let id$1 = 0;
|
|
1752
|
-
const create$3$
|
|
1752
|
+
const create$3$2 = () => {
|
|
1753
1753
|
return ++id$1;
|
|
1754
1754
|
};
|
|
1755
1755
|
const registerPromise = () => {
|
|
1756
|
-
const id = create$3$
|
|
1756
|
+
const id = create$3$2();
|
|
1757
1757
|
const {
|
|
1758
1758
|
resolve,
|
|
1759
1759
|
promise
|
|
@@ -1838,7 +1838,8 @@ const splitLines$1 = lines => {
|
|
|
1838
1838
|
return lines.split(NewLine$1);
|
|
1839
1839
|
};
|
|
1840
1840
|
const getCurrentStack = () => {
|
|
1841
|
-
const
|
|
1841
|
+
const stackLinesToSkip = 3;
|
|
1842
|
+
const currentStack = joinLines(splitLines$1(new Error().stack || '').slice(stackLinesToSkip));
|
|
1842
1843
|
return currentStack;
|
|
1843
1844
|
};
|
|
1844
1845
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
@@ -2098,7 +2099,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
2098
2099
|
const responseMessage = await promise;
|
|
2099
2100
|
return unwrapJsonRpcResult(responseMessage);
|
|
2100
2101
|
};
|
|
2101
|
-
const send = (transport, method, ...params) => {
|
|
2102
|
+
const send$1 = (transport, method, ...params) => {
|
|
2102
2103
|
const message = create$4$2(method, params);
|
|
2103
2104
|
transport.send(message);
|
|
2104
2105
|
};
|
|
@@ -2109,6 +2110,12 @@ const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
|
2109
2110
|
return invokeHelper(ipc, method, params, true);
|
|
2110
2111
|
};
|
|
2111
2112
|
|
|
2113
|
+
class CommandNotFoundError extends Error {
|
|
2114
|
+
constructor(command) {
|
|
2115
|
+
super(`Command not found ${command}`);
|
|
2116
|
+
this.name = 'CommandNotFoundError';
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2112
2119
|
const commands = Object.create(null);
|
|
2113
2120
|
const register$1 = commandMap => {
|
|
2114
2121
|
Object.assign(commands, commandMap);
|
|
@@ -2119,7 +2126,7 @@ const getCommand = key => {
|
|
|
2119
2126
|
const execute = (command, ...args) => {
|
|
2120
2127
|
const fn = getCommand(command);
|
|
2121
2128
|
if (!fn) {
|
|
2122
|
-
throw new
|
|
2129
|
+
throw new CommandNotFoundError(command);
|
|
2123
2130
|
}
|
|
2124
2131
|
return fn(...args);
|
|
2125
2132
|
};
|
|
@@ -2132,7 +2139,7 @@ const createRpc$1 = ipc => {
|
|
|
2132
2139
|
* @deprecated
|
|
2133
2140
|
*/
|
|
2134
2141
|
send(method, ...params) {
|
|
2135
|
-
send(ipc, method, ...params);
|
|
2142
|
+
send$1(ipc, method, ...params);
|
|
2136
2143
|
},
|
|
2137
2144
|
invoke(method, ...params) {
|
|
2138
2145
|
return invoke$1(ipc, method, ...params);
|
|
@@ -2176,7 +2183,7 @@ const listen$1 = async (module, options) => {
|
|
|
2176
2183
|
const ipc = module.wrap(rawIpc);
|
|
2177
2184
|
return ipc;
|
|
2178
2185
|
};
|
|
2179
|
-
const create$
|
|
2186
|
+
const create$f = async ({
|
|
2180
2187
|
commandMap,
|
|
2181
2188
|
messagePort
|
|
2182
2189
|
}) => {
|
|
@@ -2191,9 +2198,9 @@ const create$e = async ({
|
|
|
2191
2198
|
};
|
|
2192
2199
|
const MessagePortRpcClient = {
|
|
2193
2200
|
__proto__: null,
|
|
2194
|
-
create: create$
|
|
2201
|
+
create: create$f
|
|
2195
2202
|
};
|
|
2196
|
-
const create$
|
|
2203
|
+
const create$e = async ({
|
|
2197
2204
|
commandMap,
|
|
2198
2205
|
messagePort,
|
|
2199
2206
|
isMessagePortOpen
|
|
@@ -2211,7 +2218,7 @@ const create$d = async ({
|
|
|
2211
2218
|
};
|
|
2212
2219
|
const MessagePortRpcParent = {
|
|
2213
2220
|
__proto__: null,
|
|
2214
|
-
create: create$
|
|
2221
|
+
create: create$e
|
|
2215
2222
|
};
|
|
2216
2223
|
const create$5$1 = async ({
|
|
2217
2224
|
commandMap,
|
|
@@ -2242,6 +2249,24 @@ const PlainMessagePortRpcParent = {
|
|
|
2242
2249
|
__proto__: null,
|
|
2243
2250
|
create: create$4$1
|
|
2244
2251
|
};
|
|
2252
|
+
const create$3$1 = async ({
|
|
2253
|
+
commandMap,
|
|
2254
|
+
send
|
|
2255
|
+
}) => {
|
|
2256
|
+
const {
|
|
2257
|
+
port1,
|
|
2258
|
+
port2
|
|
2259
|
+
} = new MessageChannel();
|
|
2260
|
+
await send(port1);
|
|
2261
|
+
return create$5$1({
|
|
2262
|
+
commandMap,
|
|
2263
|
+
messagePort: port2
|
|
2264
|
+
});
|
|
2265
|
+
};
|
|
2266
|
+
const TransferMessagePortRpcParent = {
|
|
2267
|
+
__proto__: null,
|
|
2268
|
+
create: create$3$1
|
|
2269
|
+
};
|
|
2245
2270
|
const create$2$1 = async ({
|
|
2246
2271
|
commandMap,
|
|
2247
2272
|
webSocket
|
|
@@ -2492,6 +2517,63 @@ const createNodeRpc = async ({
|
|
|
2492
2517
|
}
|
|
2493
2518
|
};
|
|
2494
2519
|
|
|
2520
|
+
const send = async port => {
|
|
2521
|
+
const initialCommand = 'FileSystem.handleMessagePort';
|
|
2522
|
+
await invokeAndTransfer$2('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, initialCommand);
|
|
2523
|
+
};
|
|
2524
|
+
const launchFileSystemProcess = async () => {
|
|
2525
|
+
const rpc = await TransferMessagePortRpcParent.create({
|
|
2526
|
+
commandMap: {},
|
|
2527
|
+
send
|
|
2528
|
+
});
|
|
2529
|
+
return rpc;
|
|
2530
|
+
};
|
|
2531
|
+
|
|
2532
|
+
let fileSystemWorkerPromise;
|
|
2533
|
+
const getOrCreateRpc$1 = async () => {
|
|
2534
|
+
if (!fileSystemWorkerPromise) {
|
|
2535
|
+
fileSystemWorkerPromise = launchFileSystemProcess();
|
|
2536
|
+
}
|
|
2537
|
+
return fileSystemWorkerPromise;
|
|
2538
|
+
};
|
|
2539
|
+
const append = async (uri, content) => {
|
|
2540
|
+
const rpc = await getOrCreateRpc$1();
|
|
2541
|
+
await rpc.invoke('FileSystem.appendFile', uri, content);
|
|
2542
|
+
};
|
|
2543
|
+
|
|
2544
|
+
const providers = Object.create(null);
|
|
2545
|
+
const getOutputFilePath = id => {
|
|
2546
|
+
const outputFolderPath = 'file:///tmp';
|
|
2547
|
+
const uri = `${outputFolderPath}/${id}.txt`;
|
|
2548
|
+
return uri;
|
|
2549
|
+
};
|
|
2550
|
+
const registerOutputChannel = provider => {
|
|
2551
|
+
const uri = getOutputFilePath(provider.id);
|
|
2552
|
+
providers[provider.id] = {
|
|
2553
|
+
...provider
|
|
2554
|
+
};
|
|
2555
|
+
return {
|
|
2556
|
+
async append(text) {
|
|
2557
|
+
await append(uri, text);
|
|
2558
|
+
},
|
|
2559
|
+
getUri() {
|
|
2560
|
+
return uri;
|
|
2561
|
+
}
|
|
2562
|
+
};
|
|
2563
|
+
};
|
|
2564
|
+
const getEnabledProviders = () => {
|
|
2565
|
+
const values = Object.values(providers);
|
|
2566
|
+
const enabledProviders = [];
|
|
2567
|
+
for (const provider of values) {
|
|
2568
|
+
enabledProviders.push({
|
|
2569
|
+
id: provider.id,
|
|
2570
|
+
label: provider.label,
|
|
2571
|
+
uri: provider.uri
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
return enabledProviders;
|
|
2575
|
+
};
|
|
2576
|
+
|
|
2495
2577
|
const confirm = message => {
|
|
2496
2578
|
string(message);
|
|
2497
2579
|
const result = invoke$2('ConfirmPrompt.prompt', message);
|
|
@@ -3124,6 +3206,8 @@ const api = {
|
|
|
3124
3206
|
// Implementation
|
|
3125
3207
|
registerImplementationProvider: registerImplementationProvider,
|
|
3126
3208
|
executeImplementationProvider: executeImplementationProvider,
|
|
3209
|
+
// Output
|
|
3210
|
+
registerOutputChannel: registerOutputChannel,
|
|
3127
3211
|
// Prompt
|
|
3128
3212
|
confirm: confirm,
|
|
3129
3213
|
// QuickPick
|
|
@@ -3283,6 +3367,22 @@ const getExtensionId = extension => {
|
|
|
3283
3367
|
return '<unknown>';
|
|
3284
3368
|
};
|
|
3285
3369
|
|
|
3370
|
+
const isImportErrorChrome = error => {
|
|
3371
|
+
return error && error instanceof Error && error.message.startsWith('Failed to fetch dynamically imported module');
|
|
3372
|
+
};
|
|
3373
|
+
|
|
3374
|
+
const isImportErrorFirefox = error => {
|
|
3375
|
+
return error && error instanceof TypeError && error.message === 'error loading dynamically imported module';
|
|
3376
|
+
};
|
|
3377
|
+
|
|
3378
|
+
const isSyntaxError = error => {
|
|
3379
|
+
return error instanceof SyntaxError;
|
|
3380
|
+
};
|
|
3381
|
+
|
|
3382
|
+
const isImportError = error => {
|
|
3383
|
+
return isImportErrorChrome(error) || isImportErrorFirefox(error) || isSyntaxError(error);
|
|
3384
|
+
};
|
|
3385
|
+
|
|
3286
3386
|
const states = Object.create(null);
|
|
3287
3387
|
const set$5 = status => {
|
|
3288
3388
|
states[status.id] = status;
|
|
@@ -3312,108 +3412,6 @@ const sleep = duration => {
|
|
|
3312
3412
|
return promise;
|
|
3313
3413
|
};
|
|
3314
3414
|
|
|
3315
|
-
// TODO make activation timeout configurable or remove it.
|
|
3316
|
-
// some extension might do workspace indexing which could take some time
|
|
3317
|
-
const activationTimeout$1 = 10_000;
|
|
3318
|
-
const rejectAfterTimeout$1 = async (timeout, token) => {
|
|
3319
|
-
await sleep(timeout);
|
|
3320
|
-
if (isCanceled(token)) {
|
|
3321
|
-
return;
|
|
3322
|
-
}
|
|
3323
|
-
throw new Error(`Activation timeout of ${timeout}ms exceeded`);
|
|
3324
|
-
};
|
|
3325
|
-
|
|
3326
|
-
// TODO separate importing extension and activating extension for smaller functions
|
|
3327
|
-
// and better error handling
|
|
3328
|
-
const activateExtension2 = async (extensionId, extension) => {
|
|
3329
|
-
const token = create$1();
|
|
3330
|
-
try {
|
|
3331
|
-
const startTime = performance.now();
|
|
3332
|
-
update(extensionId, {
|
|
3333
|
-
status: Activating,
|
|
3334
|
-
activationStartTime: startTime
|
|
3335
|
-
});
|
|
3336
|
-
const module = acquire(extensionId);
|
|
3337
|
-
await Promise.race([module.activate(extension), rejectAfterTimeout$1(activationTimeout$1, token)]);
|
|
3338
|
-
const endTime = performance.now();
|
|
3339
|
-
const time = endTime - startTime;
|
|
3340
|
-
update(extensionId, {
|
|
3341
|
-
status: Activated,
|
|
3342
|
-
activationTime: time,
|
|
3343
|
-
activationEndTime: endTime
|
|
3344
|
-
});
|
|
3345
|
-
} catch (error) {
|
|
3346
|
-
update(extensionId, {
|
|
3347
|
-
status: Error$1 // TODO maybe store error also in runtime status state
|
|
3348
|
-
});
|
|
3349
|
-
const id = getExtensionId(extension);
|
|
3350
|
-
throw new VError(error, `Failed to activate extension ${id}`);
|
|
3351
|
-
} finally {
|
|
3352
|
-
cancel(token);
|
|
3353
|
-
}
|
|
3354
|
-
};
|
|
3355
|
-
|
|
3356
|
-
const getUrlPrefix = (platform, extensionPath) => {
|
|
3357
|
-
if (extensionPath.startsWith('http://') || extensionPath.startsWith('https://')) {
|
|
3358
|
-
return extensionPath;
|
|
3359
|
-
}
|
|
3360
|
-
if (platform === Web) {
|
|
3361
|
-
return extensionPath;
|
|
3362
|
-
}
|
|
3363
|
-
if (extensionPath.startsWith('/')) {
|
|
3364
|
-
return `/remote${extensionPath}`;
|
|
3365
|
-
}
|
|
3366
|
-
return `/remote/${extensionPath}`;
|
|
3367
|
-
};
|
|
3368
|
-
|
|
3369
|
-
const handleRpcInfos = (extension, platform) => {
|
|
3370
|
-
try {
|
|
3371
|
-
if (!extension) {
|
|
3372
|
-
return;
|
|
3373
|
-
}
|
|
3374
|
-
const rpcs = extension.rpc;
|
|
3375
|
-
const urlPrefix = getUrlPrefix(platform, extension.path);
|
|
3376
|
-
if (!rpcs) {
|
|
3377
|
-
return;
|
|
3378
|
-
}
|
|
3379
|
-
if (!Array.isArray(rpcs)) {
|
|
3380
|
-
return;
|
|
3381
|
-
}
|
|
3382
|
-
for (const rpc of rpcs) {
|
|
3383
|
-
rpc.url = `${urlPrefix}/${rpc.url}`;
|
|
3384
|
-
add$1(rpc.id, rpc);
|
|
3385
|
-
}
|
|
3386
|
-
} catch (error) {
|
|
3387
|
-
console.warn(`Failed to handle extension rpcs: ${error}`);
|
|
3388
|
-
}
|
|
3389
|
-
};
|
|
3390
|
-
|
|
3391
|
-
class ContentSecurityPolicyError extends Error {
|
|
3392
|
-
constructor(violatedDirective, sourceFile, lineNumber, columnNumber) {
|
|
3393
|
-
super(`Content Security Policy Violation: ${violatedDirective}`);
|
|
3394
|
-
this.name = 'ContentSecurityPolicyError';
|
|
3395
|
-
this.stack = sourceFile ? `Content Security Policy Violation
|
|
3396
|
-
at ${sourceFile}:${lineNumber}:${columnNumber}` : `Content Security Policy Violation
|
|
3397
|
-
at <unknown>`;
|
|
3398
|
-
}
|
|
3399
|
-
}
|
|
3400
|
-
|
|
3401
|
-
const isImportErrorChrome = error => {
|
|
3402
|
-
return error && error instanceof Error && error.message.startsWith('Failed to fetch dynamically imported module');
|
|
3403
|
-
};
|
|
3404
|
-
|
|
3405
|
-
const isImportErrorFirefox = error => {
|
|
3406
|
-
return error && error instanceof TypeError && error.message === 'error loading dynamically imported module';
|
|
3407
|
-
};
|
|
3408
|
-
|
|
3409
|
-
const isSyntaxError = error => {
|
|
3410
|
-
return error instanceof SyntaxError;
|
|
3411
|
-
};
|
|
3412
|
-
|
|
3413
|
-
const isImportError = error => {
|
|
3414
|
-
return isImportErrorChrome(error) || isImportErrorFirefox(error) || isSyntaxError(error);
|
|
3415
|
-
};
|
|
3416
|
-
|
|
3417
3415
|
const NotFound = 404;
|
|
3418
3416
|
|
|
3419
3417
|
const RE_LINE_COLUMN = /(.*)(?:\(\d+:\d+\))/;
|
|
@@ -3465,6 +3463,16 @@ const parse = async (code, options) => {
|
|
|
3465
3463
|
|
|
3466
3464
|
const Module = 'module';
|
|
3467
3465
|
|
|
3466
|
+
class ContentSecurityPolicyError extends Error {
|
|
3467
|
+
constructor(violatedDirective, sourceFile, lineNumber, columnNumber) {
|
|
3468
|
+
super(`Content Security Policy Violation: ${violatedDirective}`);
|
|
3469
|
+
this.name = 'ContentSecurityPolicyError';
|
|
3470
|
+
this.stack = sourceFile ? `Content Security Policy Violation
|
|
3471
|
+
at ${sourceFile}:${lineNumber}:${columnNumber}` : `Content Security Policy Violation
|
|
3472
|
+
at <unknown>`;
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
|
|
3468
3476
|
const getLineAndColumn = (text, start, end) => {
|
|
3469
3477
|
let index = -1;
|
|
3470
3478
|
let line = 0;
|
|
@@ -3722,6 +3730,83 @@ const tryToGetActualImportErrorMessage = async (url, error) => {
|
|
|
3722
3730
|
}
|
|
3723
3731
|
};
|
|
3724
3732
|
|
|
3733
|
+
// TODO make activation timeout configurable or remove it.
|
|
3734
|
+
// some extension might do workspace indexing which could take some time
|
|
3735
|
+
const activationTimeout$1 = 10_000;
|
|
3736
|
+
const rejectAfterTimeout$1 = async (timeout, token) => {
|
|
3737
|
+
await sleep(timeout);
|
|
3738
|
+
if (isCanceled(token)) {
|
|
3739
|
+
return;
|
|
3740
|
+
}
|
|
3741
|
+
throw new Error(`Activation timeout of ${timeout}ms exceeded`);
|
|
3742
|
+
};
|
|
3743
|
+
const activateExtension2 = async (extensionId, extension, absolutePath) => {
|
|
3744
|
+
const token = create$1();
|
|
3745
|
+
try {
|
|
3746
|
+
const startTime = performance.now();
|
|
3747
|
+
update(extensionId, {
|
|
3748
|
+
status: Activating,
|
|
3749
|
+
activationStartTime: startTime
|
|
3750
|
+
});
|
|
3751
|
+
const module = acquire(extensionId);
|
|
3752
|
+
await Promise.race([module.activate(extension), rejectAfterTimeout$1(activationTimeout$1, token)]);
|
|
3753
|
+
const endTime = performance.now();
|
|
3754
|
+
const time = endTime - startTime;
|
|
3755
|
+
update(extensionId, {
|
|
3756
|
+
status: Activated,
|
|
3757
|
+
activationTime: time,
|
|
3758
|
+
activationEndTime: endTime
|
|
3759
|
+
});
|
|
3760
|
+
} catch (error) {
|
|
3761
|
+
const id = getExtensionId(extension);
|
|
3762
|
+
if (isImportError(error)) {
|
|
3763
|
+
const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
|
|
3764
|
+
throw new Error(`Failed to activate extension ${id}: ${actualErrorMessage}`);
|
|
3765
|
+
}
|
|
3766
|
+
update(extensionId, {
|
|
3767
|
+
status: Error$1 // TODO maybe store error also in runtime status state
|
|
3768
|
+
});
|
|
3769
|
+
throw new VError(error, `Failed to activate extension ${id}`);
|
|
3770
|
+
} finally {
|
|
3771
|
+
cancel(token);
|
|
3772
|
+
}
|
|
3773
|
+
};
|
|
3774
|
+
|
|
3775
|
+
const getUrlPrefix = (platform, extensionPath) => {
|
|
3776
|
+
if (extensionPath.startsWith('http://') || extensionPath.startsWith('https://')) {
|
|
3777
|
+
return extensionPath;
|
|
3778
|
+
}
|
|
3779
|
+
if (platform === Web) {
|
|
3780
|
+
return extensionPath;
|
|
3781
|
+
}
|
|
3782
|
+
if (extensionPath.startsWith('/')) {
|
|
3783
|
+
return `/remote${extensionPath}`;
|
|
3784
|
+
}
|
|
3785
|
+
return `/remote/${extensionPath}`;
|
|
3786
|
+
};
|
|
3787
|
+
|
|
3788
|
+
const handleRpcInfos = (extension, platform) => {
|
|
3789
|
+
try {
|
|
3790
|
+
if (!extension) {
|
|
3791
|
+
return;
|
|
3792
|
+
}
|
|
3793
|
+
const rpcs = extension.rpc;
|
|
3794
|
+
const urlPrefix = getUrlPrefix(platform, extension.path);
|
|
3795
|
+
if (!rpcs) {
|
|
3796
|
+
return;
|
|
3797
|
+
}
|
|
3798
|
+
if (!Array.isArray(rpcs)) {
|
|
3799
|
+
return;
|
|
3800
|
+
}
|
|
3801
|
+
for (const rpc of rpcs) {
|
|
3802
|
+
rpc.url = `${urlPrefix}/${rpc.url}`;
|
|
3803
|
+
add$1(rpc.id, rpc);
|
|
3804
|
+
}
|
|
3805
|
+
} catch (error) {
|
|
3806
|
+
console.warn(`Failed to handle extension rpcs: ${error}`);
|
|
3807
|
+
}
|
|
3808
|
+
};
|
|
3809
|
+
|
|
3725
3810
|
const importScript = async url => {
|
|
3726
3811
|
try {
|
|
3727
3812
|
return await import(url);
|
|
@@ -5948,6 +6033,7 @@ const commandMap = {
|
|
|
5948
6033
|
'IndexedDb.saveValue': saveValue,
|
|
5949
6034
|
'IndexedDb.set': set$3,
|
|
5950
6035
|
'Languages.getLanguages': getLanguages,
|
|
6036
|
+
'Output.getEnabledProviders': getEnabledProviders,
|
|
5951
6037
|
'SaveState.saveState': saveState,
|
|
5952
6038
|
'SearchFileWithFetch.searchFileWithFetch': searchFile$2,
|
|
5953
6039
|
'SearchFileWithHtml.searchFileWithHtml': searchFile$1,
|