@lvce-editor/extension-host-worker 2.2.0 → 2.3.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 +2266 -2269
- package/package.json +1 -1
|
@@ -571,7 +571,7 @@ const registerMethod = ({
|
|
|
571
571
|
}
|
|
572
572
|
};
|
|
573
573
|
};
|
|
574
|
-
const create$
|
|
574
|
+
const create$c = ({
|
|
575
575
|
name,
|
|
576
576
|
resultShape,
|
|
577
577
|
executeKey = '',
|
|
@@ -623,7 +623,7 @@ const {
|
|
|
623
623
|
registerBraceCompletionProvider,
|
|
624
624
|
executeBraceCompletionProvider,
|
|
625
625
|
reset: reset$9
|
|
626
|
-
} = create$
|
|
626
|
+
} = create$c({
|
|
627
627
|
name: 'BraceCompletion',
|
|
628
628
|
resultShape: {
|
|
629
629
|
type: Boolean
|
|
@@ -633,7 +633,7 @@ const {
|
|
|
633
633
|
const {
|
|
634
634
|
registerClosingTagProvider,
|
|
635
635
|
executeClosingTagProvider
|
|
636
|
-
} = create$
|
|
636
|
+
} = create$c({
|
|
637
637
|
name: 'ClosingTag',
|
|
638
638
|
returnUndefinedWhenNoProviderFound: true,
|
|
639
639
|
resultShape: {
|
|
@@ -645,7 +645,7 @@ const {
|
|
|
645
645
|
const {
|
|
646
646
|
registerCodeActionProvider,
|
|
647
647
|
executeCodeActionProvider
|
|
648
|
-
} = create$
|
|
648
|
+
} = create$c({
|
|
649
649
|
name: 'CodeAction',
|
|
650
650
|
resultShape: {
|
|
651
651
|
type: Array$1,
|
|
@@ -728,7 +728,7 @@ const {
|
|
|
728
728
|
registerCompletionProvider,
|
|
729
729
|
executeCompletionProvider,
|
|
730
730
|
executeresolveCompletionItemProvider
|
|
731
|
-
} = create$
|
|
731
|
+
} = create$c({
|
|
732
732
|
name: 'Completion',
|
|
733
733
|
resultShape: {
|
|
734
734
|
type: Array$1,
|
|
@@ -903,7 +903,7 @@ const {
|
|
|
903
903
|
registerDefinitionProvider,
|
|
904
904
|
executeDefinitionProvider,
|
|
905
905
|
reset: reset$8
|
|
906
|
-
} = create$
|
|
906
|
+
} = create$c({
|
|
907
907
|
name: 'Definition',
|
|
908
908
|
resultShape: {
|
|
909
909
|
allowUndefined: true,
|
|
@@ -925,7 +925,7 @@ const {
|
|
|
925
925
|
const {
|
|
926
926
|
registerDiagnosticProvider,
|
|
927
927
|
executeDiagnosticProvider
|
|
928
|
-
} = create$
|
|
928
|
+
} = create$c({
|
|
929
929
|
name: 'Diagnostic',
|
|
930
930
|
resultShape: {
|
|
931
931
|
type: Array$1,
|
|
@@ -1026,7 +1026,7 @@ const {
|
|
|
1026
1026
|
registerFormattingProvider,
|
|
1027
1027
|
executeFormattingProvider,
|
|
1028
1028
|
reset: reset$7
|
|
1029
|
-
} = create$
|
|
1029
|
+
} = create$c({
|
|
1030
1030
|
name: 'Formatting',
|
|
1031
1031
|
executeKey: 'format',
|
|
1032
1032
|
resultShape: {
|
|
@@ -1088,7 +1088,7 @@ const {
|
|
|
1088
1088
|
registerHoverProvider,
|
|
1089
1089
|
executeHoverProvider,
|
|
1090
1090
|
reset: reset$6
|
|
1091
|
-
} = create$
|
|
1091
|
+
} = create$c({
|
|
1092
1092
|
name: 'Hover',
|
|
1093
1093
|
resultShape: {
|
|
1094
1094
|
allowUndefined: true,
|
|
@@ -1101,7 +1101,7 @@ const {
|
|
|
1101
1101
|
registerImplementationProvider,
|
|
1102
1102
|
executeImplementationProvider,
|
|
1103
1103
|
reset: reset$5
|
|
1104
|
-
} = create$
|
|
1104
|
+
} = create$c({
|
|
1105
1105
|
name: 'Implementation',
|
|
1106
1106
|
resultShape: {
|
|
1107
1107
|
type: Array$1,
|
|
@@ -1115,933 +1115,630 @@ const WebSocket$1 = 5;
|
|
|
1115
1115
|
const ElectronMessagePort = 6;
|
|
1116
1116
|
const ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1 = 7;
|
|
1117
1117
|
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
throw new Error('unexpected ipc type');
|
|
1128
|
-
}
|
|
1118
|
+
const getPortTuple = () => {
|
|
1119
|
+
const {
|
|
1120
|
+
port1,
|
|
1121
|
+
port2
|
|
1122
|
+
} = new MessageChannel();
|
|
1123
|
+
return {
|
|
1124
|
+
port1,
|
|
1125
|
+
port2
|
|
1126
|
+
};
|
|
1129
1127
|
};
|
|
1130
1128
|
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1133
|
-
|
|
1129
|
+
const ModuleWorkerAndWorkaroundForChromeDevtoolsBug = 6;
|
|
1130
|
+
|
|
1131
|
+
const create$b = async ({
|
|
1132
|
+
url,
|
|
1133
|
+
name
|
|
1134
1134
|
}) => {
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1135
|
+
string(url);
|
|
1136
|
+
string(name);
|
|
1137
|
+
const {
|
|
1138
|
+
port1,
|
|
1139
|
+
port2
|
|
1140
|
+
} = getPortTuple();
|
|
1141
|
+
await invokeAndTransfer$1('IpcParent.create', {
|
|
1142
|
+
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
|
|
1143
|
+
url,
|
|
1144
|
+
name,
|
|
1145
|
+
raw: true,
|
|
1146
|
+
port: port1
|
|
1147
|
+
});
|
|
1148
|
+
return port2;
|
|
1145
1149
|
};
|
|
1150
|
+
const wrap$5 = port => {
|
|
1151
|
+
return {
|
|
1152
|
+
port,
|
|
1153
|
+
/**
|
|
1154
|
+
* @type {any}
|
|
1155
|
+
*/
|
|
1156
|
+
handleMessage: undefined,
|
|
1157
|
+
get onmessage() {
|
|
1158
|
+
return this.handleMessage;
|
|
1159
|
+
},
|
|
1160
|
+
set onmessage(listener) {
|
|
1161
|
+
if (listener) {
|
|
1162
|
+
// @ts-ignore
|
|
1163
|
+
this.handleMessage = event => {
|
|
1164
|
+
// TODO why are some events not instance of message event?
|
|
1165
|
+
if (event instanceof MessageEvent) {
|
|
1166
|
+
const message = event.data;
|
|
1167
|
+
// @ts-ignore
|
|
1168
|
+
listener(message, event);
|
|
1169
|
+
} else {
|
|
1170
|
+
// @ts-ignore
|
|
1146
1171
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1172
|
+
listener(event);
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1175
|
+
} else {
|
|
1176
|
+
// @ts-ignore
|
|
1177
|
+
this.handleMessage = null;
|
|
1178
|
+
}
|
|
1179
|
+
this.port.onmessage = this.handleMessage;
|
|
1180
|
+
},
|
|
1181
|
+
send(message) {
|
|
1182
|
+
this.port.postMessage(message);
|
|
1183
|
+
},
|
|
1184
|
+
sendAndTransfer(message, transfer) {
|
|
1185
|
+
this.port.postMessage(message, transfer);
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1156
1188
|
};
|
|
1157
1189
|
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
const module = await getModule$2(method);
|
|
1163
|
-
// @ts-ignore
|
|
1164
|
-
const rpc = module.create(options);
|
|
1165
|
-
return rpc;
|
|
1190
|
+
const IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug = {
|
|
1191
|
+
__proto__: null,
|
|
1192
|
+
create: create$b,
|
|
1193
|
+
wrap: wrap$5
|
|
1166
1194
|
};
|
|
1167
1195
|
|
|
1168
|
-
const
|
|
1169
|
-
|
|
1170
|
-
};
|
|
1171
|
-
const createNodeRpc = async ({
|
|
1172
|
-
path,
|
|
1173
|
-
execute = defaultExecute$1,
|
|
1174
|
-
name = ''
|
|
1175
|
-
}) => {
|
|
1176
|
-
try {
|
|
1177
|
-
string(path);
|
|
1178
|
-
fn(execute);
|
|
1179
|
-
const ipc = await create$9({
|
|
1180
|
-
method: ElectronMessagePort,
|
|
1181
|
-
type: 'extension-host-helper-process',
|
|
1182
|
-
name
|
|
1183
|
-
});
|
|
1184
|
-
const rpc = await create$8({
|
|
1185
|
-
ipc,
|
|
1186
|
-
method: JsonRpc,
|
|
1187
|
-
execute
|
|
1188
|
-
});
|
|
1189
|
-
await rpc.invoke('LoadFile.loadFile', path);
|
|
1190
|
-
return rpc;
|
|
1191
|
-
} catch (error) {
|
|
1192
|
-
throw new VError(error, `Failed to create node rpc`);
|
|
1193
|
-
}
|
|
1196
|
+
const sendMessagePortToElectron = async (port, initialCommand) => {
|
|
1197
|
+
await invokeAndTransfer$1('SendMessagePortToElectron.sendMessagePortToElectron', port, initialCommand);
|
|
1194
1198
|
};
|
|
1195
1199
|
|
|
1196
|
-
const
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
+
const getPort = async type => {
|
|
1201
|
+
const {
|
|
1202
|
+
port1,
|
|
1203
|
+
port2
|
|
1204
|
+
} = getPortTuple();
|
|
1205
|
+
await sendMessagePortToElectron(port1, 'HandleMessagePortForExtensionHostHelperProcess.handleMessagePortForExtensionHostHelperProcess');
|
|
1206
|
+
return port2;
|
|
1200
1207
|
};
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
const showQuickPick = async ({
|
|
1205
|
-
getPicks,
|
|
1206
|
-
toPick
|
|
1208
|
+
const create$a = async ({
|
|
1209
|
+
type
|
|
1207
1210
|
}) => {
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
return invoke$1(ExtensionHostQuickPickShow, picks);
|
|
1211
|
+
const port = await getPort();
|
|
1212
|
+
return port;
|
|
1211
1213
|
};
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
additionalMethodNames: [
|
|
1227
|
-
// @ts-ignore
|
|
1228
|
-
{
|
|
1229
|
-
name: 'fileReference',
|
|
1230
|
-
methodName: 'provideFileReferences',
|
|
1231
|
-
resultShape: {
|
|
1232
|
-
type: Array$1,
|
|
1233
|
-
items: {
|
|
1234
|
-
type: Object$1
|
|
1214
|
+
const wrap$4 = port => {
|
|
1215
|
+
let handleMessage;
|
|
1216
|
+
return {
|
|
1217
|
+
get onmessage() {
|
|
1218
|
+
return handleMessage;
|
|
1219
|
+
},
|
|
1220
|
+
set onmessage(listener) {
|
|
1221
|
+
let handleMessage;
|
|
1222
|
+
if (listener) {
|
|
1223
|
+
handleMessage = event => {
|
|
1224
|
+
listener(event.data);
|
|
1225
|
+
};
|
|
1226
|
+
} else {
|
|
1227
|
+
handleMessage = null;
|
|
1235
1228
|
}
|
|
1229
|
+
port.onmessage = handleMessage;
|
|
1230
|
+
},
|
|
1231
|
+
send(message) {
|
|
1232
|
+
port.postMessage(message);
|
|
1236
1233
|
}
|
|
1237
|
-
}
|
|
1238
|
-
});
|
|
1239
|
-
|
|
1240
|
-
const {
|
|
1241
|
-
registerRenameProvider,
|
|
1242
|
-
executeRenameProvider,
|
|
1243
|
-
executeprepareRenameProvider,
|
|
1244
|
-
reset: reset$3
|
|
1245
|
-
} = create$a({
|
|
1246
|
-
name: 'Rename',
|
|
1247
|
-
resultShape: {
|
|
1248
|
-
type: Object$1,
|
|
1249
|
-
allowUndefined: true
|
|
1250
|
-
},
|
|
1251
|
-
additionalMethodNames: [
|
|
1252
|
-
// @ts-ignore
|
|
1253
|
-
{
|
|
1254
|
-
name: 'prepareRename',
|
|
1255
|
-
methodName: 'prepareRename',
|
|
1256
|
-
resultShape: {
|
|
1257
|
-
type: Object$1,
|
|
1258
|
-
allowUndefined: true
|
|
1259
|
-
}
|
|
1260
|
-
}]
|
|
1261
|
-
});
|
|
1262
|
-
|
|
1263
|
-
const getExtensionHostSubWorkerUrl = () => {
|
|
1264
|
-
return new URL('../../../../extension-host-sub-worker/src/extensionHostSubWorkerMain.js', import.meta.url).toString();
|
|
1234
|
+
};
|
|
1265
1235
|
};
|
|
1266
|
-
const extensionHostSubWorkerUrl = getExtensionHostSubWorkerUrl();
|
|
1267
1236
|
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1270
|
-
|
|
1237
|
+
const IpcParentWithElectronMessagePort = {
|
|
1238
|
+
__proto__: null,
|
|
1239
|
+
create: create$a,
|
|
1240
|
+
wrap: wrap$4
|
|
1271
1241
|
};
|
|
1272
1242
|
|
|
1273
|
-
const
|
|
1274
|
-
|
|
1275
|
-
rpcs$1[id] = rpc;
|
|
1243
|
+
const isMessagePort = value => {
|
|
1244
|
+
return value && value instanceof MessagePort;
|
|
1276
1245
|
};
|
|
1277
|
-
const
|
|
1278
|
-
return
|
|
1246
|
+
const isMessagePortMain = value => {
|
|
1247
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
1279
1248
|
};
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
const rpcs = Object.create(null);
|
|
1283
|
-
const register$1 = (id, execute) => {
|
|
1284
|
-
registry[id] = execute;
|
|
1249
|
+
const isOffscreenCanvas = value => {
|
|
1250
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
1285
1251
|
};
|
|
1286
|
-
const
|
|
1287
|
-
|
|
1288
|
-
delete registry[id];
|
|
1289
|
-
return fn;
|
|
1252
|
+
const isInstanceOf = (value, constructorName) => {
|
|
1253
|
+
return value?.constructor?.name === constructorName;
|
|
1290
1254
|
};
|
|
1291
|
-
const
|
|
1292
|
-
return
|
|
1255
|
+
const isSocket = value => {
|
|
1256
|
+
return isInstanceOf(value, 'Socket');
|
|
1293
1257
|
};
|
|
1294
|
-
const
|
|
1295
|
-
|
|
1258
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
1259
|
+
const isTransferrable = value => {
|
|
1260
|
+
for (const fn of transferrables) {
|
|
1261
|
+
if (fn(value)) {
|
|
1262
|
+
return true;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
return false;
|
|
1296
1266
|
};
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
const info = get$3(id);
|
|
1301
|
-
if (!info) {
|
|
1302
|
-
throw new Error(`rpc with id ${id} not found`);
|
|
1303
|
-
}
|
|
1304
|
-
const ipc = await create$9({
|
|
1305
|
-
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
1306
|
-
url: extensionHostSubWorkerUrl,
|
|
1307
|
-
name: info.name
|
|
1308
|
-
});
|
|
1309
|
-
const newRpc = await create$8({
|
|
1310
|
-
ipc,
|
|
1311
|
-
method: JsonRpc,
|
|
1312
|
-
execute: fn
|
|
1313
|
-
});
|
|
1314
|
-
await newRpc.invoke('LoadFile.loadFile', info.url);
|
|
1315
|
-
set$2(id, newRpc);
|
|
1316
|
-
return newRpc;
|
|
1317
|
-
};
|
|
1318
|
-
|
|
1319
|
-
const getOrCreateRpc = async id => {
|
|
1320
|
-
const rpc = get$2(id);
|
|
1321
|
-
if (!rpc) {
|
|
1322
|
-
set$2(id, createRpcWithId$1(id));
|
|
1267
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
1268
|
+
if (!value) {
|
|
1269
|
+
return;
|
|
1323
1270
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
id,
|
|
1328
|
-
execute
|
|
1329
|
-
}) => {
|
|
1330
|
-
string(id);
|
|
1331
|
-
register$1(id, execute);
|
|
1332
|
-
const lazyRpc = {
|
|
1333
|
-
async invoke(method, ...params) {
|
|
1334
|
-
const rpc = await getOrCreateRpc(id);
|
|
1335
|
-
return rpc.invoke(method, ...params);
|
|
1336
|
-
}
|
|
1337
|
-
};
|
|
1338
|
-
return lazyRpc;
|
|
1339
|
-
};
|
|
1340
|
-
|
|
1341
|
-
const defaultExecute = () => {
|
|
1342
|
-
throw new Error('not implemented');
|
|
1343
|
-
};
|
|
1344
|
-
|
|
1345
|
-
/**
|
|
1346
|
-
*
|
|
1347
|
-
* @deprecated
|
|
1348
|
-
*/
|
|
1349
|
-
const createLegacyRpc = async ({
|
|
1350
|
-
url,
|
|
1351
|
-
name,
|
|
1352
|
-
execute = defaultExecute,
|
|
1353
|
-
contentSecurityPolicy
|
|
1354
|
-
}) => {
|
|
1355
|
-
string(url);
|
|
1356
|
-
string(name);
|
|
1357
|
-
fn(execute);
|
|
1358
|
-
if (contentSecurityPolicy) {
|
|
1359
|
-
await set$3(url, contentSecurityPolicy);
|
|
1271
|
+
if (isTransferrable(value)) {
|
|
1272
|
+
transferrables.push(value);
|
|
1273
|
+
return;
|
|
1360
1274
|
}
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
name
|
|
1365
|
-
});
|
|
1366
|
-
const rpc = await create$8({
|
|
1367
|
-
ipc,
|
|
1368
|
-
method: JsonRpc,
|
|
1369
|
-
execute
|
|
1370
|
-
});
|
|
1371
|
-
await rpc.invoke('LoadFile.loadFile', url);
|
|
1372
|
-
return rpc;
|
|
1373
|
-
};
|
|
1374
|
-
const createRpc$1 = ({
|
|
1375
|
-
id,
|
|
1376
|
-
url,
|
|
1377
|
-
name,
|
|
1378
|
-
execute = defaultExecute,
|
|
1379
|
-
contentSecurityPolicy
|
|
1380
|
-
}) => {
|
|
1381
|
-
try {
|
|
1382
|
-
if (id) {
|
|
1383
|
-
string(id);
|
|
1384
|
-
return createRpcWithId({
|
|
1385
|
-
id,
|
|
1386
|
-
execute
|
|
1387
|
-
});
|
|
1275
|
+
if (Array.isArray(value)) {
|
|
1276
|
+
for (const item of value) {
|
|
1277
|
+
walkValue(item, transferrables, isTransferrable);
|
|
1388
1278
|
}
|
|
1389
|
-
return
|
|
1390
|
-
url,
|
|
1391
|
-
name,
|
|
1392
|
-
execute,
|
|
1393
|
-
contentSecurityPolicy
|
|
1394
|
-
});
|
|
1395
|
-
} catch (error) {
|
|
1396
|
-
throw new VError(error, `Failed to create webworker rpc`);
|
|
1279
|
+
return;
|
|
1397
1280
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
registerSelectionProvider,
|
|
1402
|
-
executeSelectionProvider,
|
|
1403
|
-
reset: reset$2
|
|
1404
|
-
} = create$a({
|
|
1405
|
-
name: 'Selection',
|
|
1406
|
-
resultShape: {
|
|
1407
|
-
allowUndefined: true,
|
|
1408
|
-
type: Array$1,
|
|
1409
|
-
items: {
|
|
1410
|
-
type: 'number'
|
|
1281
|
+
if (typeof value === 'object') {
|
|
1282
|
+
for (const property of Object.values(value)) {
|
|
1283
|
+
walkValue(property, transferrables, isTransferrable);
|
|
1411
1284
|
}
|
|
1285
|
+
return;
|
|
1412
1286
|
}
|
|
1413
|
-
});
|
|
1414
|
-
|
|
1415
|
-
const state$5 = {
|
|
1416
|
-
providers: Object.create(null)
|
|
1417
1287
|
};
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1288
|
+
const getTransferrables = value => {
|
|
1289
|
+
const transferrables = [];
|
|
1290
|
+
walkValue(value, transferrables, isTransferrable);
|
|
1291
|
+
return transferrables;
|
|
1420
1292
|
};
|
|
1421
|
-
const
|
|
1422
|
-
|
|
1293
|
+
const attachEvents = that => {
|
|
1294
|
+
const handleMessage = (...args) => {
|
|
1295
|
+
const data = that.getData(...args);
|
|
1296
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
1297
|
+
data
|
|
1298
|
+
}));
|
|
1299
|
+
};
|
|
1300
|
+
that.onMessage(handleMessage);
|
|
1301
|
+
const handleClose = event => {
|
|
1302
|
+
that.dispatchEvent(new Event('close'));
|
|
1303
|
+
};
|
|
1304
|
+
that.onClose(handleClose);
|
|
1423
1305
|
};
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1306
|
+
class Ipc extends EventTarget {
|
|
1307
|
+
constructor(rawIpc) {
|
|
1308
|
+
super();
|
|
1309
|
+
this._rawIpc = rawIpc;
|
|
1310
|
+
attachEvents(this);
|
|
1428
1311
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1312
|
+
}
|
|
1313
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
1314
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
1315
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
1316
|
+
const NewLine$1 = '\n';
|
|
1317
|
+
const joinLines$1 = lines => {
|
|
1318
|
+
return lines.join(NewLine$1);
|
|
1432
1319
|
};
|
|
1433
|
-
const
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
if (!provider) {
|
|
1438
|
-
throw new Error('no source control provider found');
|
|
1439
|
-
}
|
|
1440
|
-
return provider.getFileBefore(uri);
|
|
1320
|
+
const RE_AT = /^\s+at/;
|
|
1321
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
1322
|
+
const isNormalStackLine = line => {
|
|
1323
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
1441
1324
|
};
|
|
1442
|
-
const
|
|
1443
|
-
|
|
1444
|
-
|
|
1325
|
+
const getDetails = lines => {
|
|
1326
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
1327
|
+
if (index === -1) {
|
|
1328
|
+
return {
|
|
1329
|
+
actualMessage: joinLines$1(lines),
|
|
1330
|
+
rest: []
|
|
1331
|
+
};
|
|
1445
1332
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
items: files
|
|
1452
|
-
}];
|
|
1453
|
-
return groups;
|
|
1333
|
+
let lastIndex = index - 1;
|
|
1334
|
+
while (++lastIndex < lines.length) {
|
|
1335
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
1336
|
+
break;
|
|
1337
|
+
}
|
|
1454
1338
|
}
|
|
1455
|
-
|
|
1339
|
+
return {
|
|
1340
|
+
actualMessage: lines[index - 1],
|
|
1341
|
+
rest: lines.slice(index, lastIndex)
|
|
1342
|
+
};
|
|
1456
1343
|
};
|
|
1457
|
-
const
|
|
1458
|
-
|
|
1459
|
-
if (!provider) {
|
|
1460
|
-
throw new Error('no source control provider found');
|
|
1461
|
-
}
|
|
1462
|
-
const groups = await getGroupsFromProvider(provider, cwd);
|
|
1463
|
-
return groups;
|
|
1344
|
+
const splitLines$2 = lines => {
|
|
1345
|
+
return lines.split(NewLine$1);
|
|
1464
1346
|
};
|
|
1465
|
-
const
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
}
|
|
1470
|
-
await provider.acceptInput(value);
|
|
1347
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
1348
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
1349
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
1350
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
1471
1351
|
};
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1352
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
1353
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
1354
|
+
};
|
|
1355
|
+
const getMessageCodeBlock = stderr => {
|
|
1356
|
+
const lines = splitLines$2(stderr);
|
|
1357
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
1358
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
1359
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
1360
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
1361
|
+
return relevantMessage;
|
|
1362
|
+
};
|
|
1363
|
+
const isModuleNotFoundMessage = line => {
|
|
1364
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
1365
|
+
};
|
|
1366
|
+
const getModuleNotFoundError = stderr => {
|
|
1367
|
+
const lines = splitLines$2(stderr);
|
|
1368
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
1369
|
+
const message = lines[messageIndex];
|
|
1370
|
+
return {
|
|
1371
|
+
message,
|
|
1372
|
+
code: ERR_MODULE_NOT_FOUND
|
|
1373
|
+
};
|
|
1374
|
+
};
|
|
1375
|
+
const isModuleNotFoundError = stderr => {
|
|
1376
|
+
if (!stderr) {
|
|
1377
|
+
return false;
|
|
1476
1378
|
}
|
|
1477
|
-
|
|
1478
|
-
await provider.add(path);
|
|
1379
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
1479
1380
|
};
|
|
1480
|
-
const
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
return;
|
|
1381
|
+
const isModulesSyntaxError = stderr => {
|
|
1382
|
+
if (!stderr) {
|
|
1383
|
+
return false;
|
|
1484
1384
|
}
|
|
1485
|
-
|
|
1486
|
-
await provider.discard(path);
|
|
1385
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
1487
1386
|
};
|
|
1488
|
-
const
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
const enabledIds = [];
|
|
1493
|
-
for (const provider of providers) {
|
|
1494
|
-
// @ts-ignore
|
|
1495
|
-
if (typeof provider.isActive !== 'function') {
|
|
1496
|
-
continue;
|
|
1497
|
-
}
|
|
1498
|
-
// @ts-ignore
|
|
1499
|
-
const isActive = await provider.isActive(scheme, root);
|
|
1500
|
-
if (isActive) {
|
|
1501
|
-
// @ts-ignore
|
|
1502
|
-
enabledIds.push(provider.id);
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
return enabledIds;
|
|
1387
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
1388
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
1389
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
1390
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
1506
1391
|
};
|
|
1507
|
-
|
|
1508
|
-
const
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1513
|
-
name: 'TabCompletion',
|
|
1514
|
-
resultShape: {
|
|
1515
|
-
type: Object$1,
|
|
1516
|
-
allowUndefined: true
|
|
1517
|
-
}
|
|
1518
|
-
});
|
|
1519
|
-
|
|
1520
|
-
const state$4 = {
|
|
1521
|
-
textSearchProviders: Object.create(null)
|
|
1392
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
1393
|
+
const message = getMessageCodeBlock(stderr);
|
|
1394
|
+
return {
|
|
1395
|
+
message: `Incompatible native node module: ${message}`,
|
|
1396
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE
|
|
1397
|
+
};
|
|
1522
1398
|
};
|
|
1523
|
-
const
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
if (!textSearchProvider.scheme) {
|
|
1529
|
-
throw new Error('textSearchProvider is missing scheme');
|
|
1530
|
-
}
|
|
1531
|
-
state$4.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
|
|
1532
|
-
} catch (error) {
|
|
1533
|
-
throw new VError(error, 'Failed to register text search provider');
|
|
1534
|
-
}
|
|
1399
|
+
const getModuleSyntaxError = () => {
|
|
1400
|
+
return {
|
|
1401
|
+
message: `ES Modules are not supported in electron`,
|
|
1402
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
1403
|
+
};
|
|
1535
1404
|
};
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
if (!textSearchProvider) {
|
|
1540
|
-
throw new Error(`No text search provider for ${scheme} found`);
|
|
1541
|
-
}
|
|
1542
|
-
const results = await textSearchProvider.provideTextSearchResults(query);
|
|
1543
|
-
return results;
|
|
1544
|
-
} catch (error) {
|
|
1545
|
-
throw new VError(error, 'Failed to execute text search provider');
|
|
1405
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
1406
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
1407
|
+
return getNativeModuleErrorMessage(stderr);
|
|
1546
1408
|
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
const {
|
|
1550
|
-
registerTypeDefinitionProvider,
|
|
1551
|
-
executeTypeDefinitionProvider,
|
|
1552
|
-
reset
|
|
1553
|
-
} = create$a({
|
|
1554
|
-
name: 'TypeDefinition',
|
|
1555
|
-
resultShape: {
|
|
1556
|
-
allowUndefined: true,
|
|
1557
|
-
type: Object$1,
|
|
1558
|
-
properties: {
|
|
1559
|
-
uri: {
|
|
1560
|
-
type: String$1
|
|
1561
|
-
},
|
|
1562
|
-
startOffset: {
|
|
1563
|
-
type: Number
|
|
1564
|
-
},
|
|
1565
|
-
endOffset: {
|
|
1566
|
-
type: Number
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1409
|
+
if (isModulesSyntaxError(stderr)) {
|
|
1410
|
+
return getModuleSyntaxError();
|
|
1569
1411
|
}
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
const RE_PROTOCOL = /^([a-z\-]+):\/\//;
|
|
1573
|
-
const getProtocol = uri => {
|
|
1574
|
-
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1575
|
-
if (protocolMatch) {
|
|
1576
|
-
return protocolMatch[1];
|
|
1412
|
+
if (isModuleNotFoundError(stderr)) {
|
|
1413
|
+
return getModuleNotFoundError(stderr);
|
|
1577
1414
|
}
|
|
1578
|
-
|
|
1579
|
-
};
|
|
1580
|
-
|
|
1581
|
-
const getPortTuple = () => {
|
|
1415
|
+
const lines = splitLines$2(stderr);
|
|
1582
1416
|
const {
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
} =
|
|
1417
|
+
actualMessage,
|
|
1418
|
+
rest
|
|
1419
|
+
} = getDetails(lines);
|
|
1586
1420
|
return {
|
|
1587
|
-
|
|
1588
|
-
|
|
1421
|
+
message: actualMessage,
|
|
1422
|
+
code: '',
|
|
1423
|
+
stack: rest
|
|
1589
1424
|
};
|
|
1590
1425
|
};
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1426
|
+
class IpcError extends VError {
|
|
1427
|
+
// @ts-ignore
|
|
1428
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
1429
|
+
if (stdout || stderr) {
|
|
1430
|
+
// @ts-ignore
|
|
1431
|
+
const {
|
|
1432
|
+
message,
|
|
1433
|
+
code,
|
|
1434
|
+
stack
|
|
1435
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
1436
|
+
const cause = new Error(message);
|
|
1437
|
+
// @ts-ignore
|
|
1438
|
+
cause.code = code;
|
|
1439
|
+
cause.stack = stack;
|
|
1440
|
+
super(cause, betterMessage);
|
|
1441
|
+
} else {
|
|
1442
|
+
super(betterMessage);
|
|
1443
|
+
}
|
|
1444
|
+
// @ts-ignore
|
|
1445
|
+
this.name = 'IpcError';
|
|
1446
|
+
// @ts-ignore
|
|
1447
|
+
this.stdout = stdout;
|
|
1448
|
+
// @ts-ignore
|
|
1449
|
+
this.stderr = stderr;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
const readyMessage = 'ready';
|
|
1453
|
+
const getData$2 = event => {
|
|
1454
|
+
return event.data;
|
|
1599
1455
|
};
|
|
1600
|
-
const
|
|
1601
|
-
|
|
1602
|
-
|
|
1456
|
+
const listen$8 = ({
|
|
1457
|
+
port
|
|
1458
|
+
}) => {
|
|
1459
|
+
return port;
|
|
1603
1460
|
};
|
|
1604
|
-
const
|
|
1605
|
-
|
|
1461
|
+
const signal$9 = port => {
|
|
1462
|
+
port.postMessage(readyMessage);
|
|
1606
1463
|
};
|
|
1607
|
-
|
|
1608
|
-
|
|
1464
|
+
class IpcChildWithMessagePort extends Ipc {
|
|
1465
|
+
getData(event) {
|
|
1466
|
+
return getData$2(event);
|
|
1467
|
+
}
|
|
1468
|
+
send(message) {
|
|
1469
|
+
this._rawIpc.postMessage(message);
|
|
1470
|
+
}
|
|
1471
|
+
sendAndTransfer(message) {
|
|
1472
|
+
const transfer = getTransferrables(message);
|
|
1473
|
+
this._rawIpc.postMessage(message, transfer);
|
|
1474
|
+
}
|
|
1475
|
+
dispose() {
|
|
1476
|
+
// ignore
|
|
1477
|
+
}
|
|
1478
|
+
onClose(callback) {
|
|
1479
|
+
// ignore
|
|
1480
|
+
}
|
|
1481
|
+
onMessage(callback) {
|
|
1482
|
+
this._rawIpc.addEventListener('message', callback);
|
|
1483
|
+
this._rawIpc.start();
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
const wrap$g = port => {
|
|
1487
|
+
return new IpcChildWithMessagePort(port);
|
|
1609
1488
|
};
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1489
|
+
const IpcChildWithMessagePort$1 = {
|
|
1490
|
+
__proto__: null,
|
|
1491
|
+
listen: listen$8,
|
|
1492
|
+
signal: signal$9,
|
|
1493
|
+
wrap: wrap$g
|
|
1613
1494
|
};
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1495
|
+
const listen$7 = () => {
|
|
1496
|
+
// @ts-ignore
|
|
1497
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
1498
|
+
throw new TypeError('module is not in web worker scope');
|
|
1499
|
+
}
|
|
1500
|
+
return globalThis;
|
|
1501
|
+
};
|
|
1502
|
+
const signal$8 = global => {
|
|
1503
|
+
global.postMessage(readyMessage);
|
|
1504
|
+
};
|
|
1505
|
+
class IpcChildWithModuleWorker extends Ipc {
|
|
1506
|
+
getData(event) {
|
|
1507
|
+
return getData$2(event);
|
|
1508
|
+
}
|
|
1509
|
+
send(message) {
|
|
1510
|
+
// @ts-ignore
|
|
1511
|
+
this._rawIpc.postMessage(message);
|
|
1512
|
+
}
|
|
1513
|
+
sendAndTransfer(message) {
|
|
1514
|
+
const transfer = getTransferrables(message);
|
|
1515
|
+
// @ts-ignore
|
|
1516
|
+
this._rawIpc.postMessage(message, transfer);
|
|
1517
|
+
}
|
|
1518
|
+
dispose() {
|
|
1519
|
+
// ignore
|
|
1520
|
+
}
|
|
1521
|
+
onClose(callback) {
|
|
1522
|
+
// ignore
|
|
1523
|
+
}
|
|
1524
|
+
onMessage(callback) {
|
|
1525
|
+
this._rawIpc.addEventListener('message', callback);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
const wrap$f = global => {
|
|
1529
|
+
return new IpcChildWithModuleWorker(global);
|
|
1530
|
+
};
|
|
1531
|
+
const IpcChildWithModuleWorker$1 = {
|
|
1532
|
+
__proto__: null,
|
|
1533
|
+
listen: listen$7,
|
|
1534
|
+
signal: signal$8,
|
|
1535
|
+
wrap: wrap$f
|
|
1536
|
+
};
|
|
1537
|
+
const withResolvers = () => {
|
|
1538
|
+
let _resolve;
|
|
1539
|
+
const promise = new Promise(resolve => {
|
|
1540
|
+
_resolve = resolve;
|
|
1541
|
+
});
|
|
1621
1542
|
return {
|
|
1622
|
-
|
|
1543
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1544
|
+
resolve: _resolve,
|
|
1623
1545
|
promise
|
|
1624
1546
|
};
|
|
1625
1547
|
};
|
|
1626
|
-
const
|
|
1548
|
+
const waitForFirstMessage$1 = async port => {
|
|
1627
1549
|
const {
|
|
1628
|
-
|
|
1550
|
+
resolve,
|
|
1629
1551
|
promise
|
|
1630
|
-
} =
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
return {
|
|
1638
|
-
message,
|
|
1639
|
-
promise
|
|
1640
|
-
};
|
|
1552
|
+
} = withResolvers();
|
|
1553
|
+
port.addEventListener('message', resolve, {
|
|
1554
|
+
once: true
|
|
1555
|
+
});
|
|
1556
|
+
const event = await promise;
|
|
1557
|
+
// @ts-ignore
|
|
1558
|
+
return event.data;
|
|
1641
1559
|
};
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
const DomException = 'DOMException';
|
|
1650
|
-
const ReferenceError$1 = 'ReferenceError';
|
|
1651
|
-
const SyntaxError$1 = 'SyntaxError';
|
|
1652
|
-
const TypeError$1 = 'TypeError';
|
|
1653
|
-
const getErrorConstructor = (message, type) => {
|
|
1654
|
-
if (type) {
|
|
1655
|
-
switch (type) {
|
|
1656
|
-
case DomException:
|
|
1657
|
-
return DOMException;
|
|
1658
|
-
case TypeError$1:
|
|
1659
|
-
return TypeError;
|
|
1660
|
-
case SyntaxError$1:
|
|
1661
|
-
return SyntaxError;
|
|
1662
|
-
case ReferenceError$1:
|
|
1663
|
-
return ReferenceError;
|
|
1664
|
-
default:
|
|
1665
|
-
return Error;
|
|
1666
|
-
}
|
|
1560
|
+
const listen$6 = async () => {
|
|
1561
|
+
const parentIpcRaw = listen$7();
|
|
1562
|
+
signal$8(parentIpcRaw);
|
|
1563
|
+
const parentIpc = wrap$f(parentIpcRaw);
|
|
1564
|
+
const firstMessage = await waitForFirstMessage$1(parentIpc);
|
|
1565
|
+
if (firstMessage.method !== 'initialize') {
|
|
1566
|
+
throw new IpcError('unexpected first message');
|
|
1667
1567
|
}
|
|
1668
|
-
|
|
1669
|
-
|
|
1568
|
+
const type = firstMessage.params[0];
|
|
1569
|
+
if (type === 'message-port') {
|
|
1570
|
+
parentIpc.send({
|
|
1571
|
+
jsonrpc: '2.0',
|
|
1572
|
+
id: firstMessage.id,
|
|
1573
|
+
result: null
|
|
1574
|
+
});
|
|
1575
|
+
parentIpc.dispose();
|
|
1576
|
+
const port = firstMessage.params[1];
|
|
1577
|
+
return port;
|
|
1670
1578
|
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1579
|
+
return globalThis;
|
|
1580
|
+
};
|
|
1581
|
+
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
1582
|
+
getData(event) {
|
|
1583
|
+
return getData$2(event);
|
|
1673
1584
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1585
|
+
send(message) {
|
|
1586
|
+
this._rawIpc.postMessage(message);
|
|
1676
1587
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
const ErrorConstructor = getErrorConstructor(message, type);
|
|
1681
|
-
if (ErrorConstructor === DOMException && name) {
|
|
1682
|
-
return new ErrorConstructor(message, name);
|
|
1588
|
+
sendAndTransfer(message) {
|
|
1589
|
+
const transfer = getTransferrables(message);
|
|
1590
|
+
this._rawIpc.postMessage(message, transfer);
|
|
1683
1591
|
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
error.name = name;
|
|
1592
|
+
dispose() {
|
|
1593
|
+
if (this._rawIpc.close) {
|
|
1594
|
+
this._rawIpc.close();
|
|
1688
1595
|
}
|
|
1689
|
-
return error;
|
|
1690
1596
|
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
1694
|
-
return string.indexOf(NewLine$1, startIndex);
|
|
1695
|
-
};
|
|
1696
|
-
const getParentStack = error => {
|
|
1697
|
-
let parentStack = error.stack || error.data || error.message || '';
|
|
1698
|
-
if (parentStack.startsWith(' at')) {
|
|
1699
|
-
parentStack = error.message + NewLine$1 + parentStack;
|
|
1597
|
+
onClose(callback) {
|
|
1598
|
+
// ignore
|
|
1700
1599
|
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1600
|
+
onMessage(callback) {
|
|
1601
|
+
this._rawIpc.addEventListener('message', callback);
|
|
1602
|
+
this._rawIpc.start();
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
const wrap$e = port => {
|
|
1606
|
+
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
1705
1607
|
};
|
|
1706
|
-
const
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1608
|
+
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
1609
|
+
__proto__: null,
|
|
1610
|
+
listen: listen$6,
|
|
1611
|
+
wrap: wrap$e
|
|
1710
1612
|
};
|
|
1711
|
-
const
|
|
1712
|
-
|
|
1713
|
-
|
|
1613
|
+
const Error$3 = 1;
|
|
1614
|
+
const Open = 2;
|
|
1615
|
+
const Close = 3;
|
|
1616
|
+
const addListener = (emitter, type, callback) => {
|
|
1617
|
+
if ('addEventListener' in emitter) {
|
|
1618
|
+
emitter.addEventListener(type, callback);
|
|
1619
|
+
} else {
|
|
1620
|
+
emitter.on(type, callback);
|
|
1714
1621
|
}
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1622
|
+
};
|
|
1623
|
+
const removeListener = (emitter, type, callback) => {
|
|
1624
|
+
if ('removeEventListener' in emitter) {
|
|
1625
|
+
emitter.removeEventListener(type, callback);
|
|
1626
|
+
} else {
|
|
1627
|
+
emitter.off(type, callback);
|
|
1721
1628
|
}
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
1733
|
-
}
|
|
1734
|
-
if (error.data.code) {
|
|
1735
|
-
// @ts-ignore
|
|
1736
|
-
restoredError.code = error.data.code;
|
|
1737
|
-
}
|
|
1738
|
-
if (error.data.type) {
|
|
1739
|
-
// @ts-ignore
|
|
1740
|
-
restoredError.name = error.data.type;
|
|
1741
|
-
}
|
|
1742
|
-
} else {
|
|
1743
|
-
if (error.stack) {
|
|
1744
|
-
const lowerStack = restoredError.stack || '';
|
|
1745
|
-
// @ts-ignore
|
|
1746
|
-
const indexNewLine = getNewLineIndex(lowerStack);
|
|
1747
|
-
const parentStack = getParentStack(error);
|
|
1748
|
-
// @ts-ignore
|
|
1749
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
1750
|
-
}
|
|
1751
|
-
if (error.codeFrame) {
|
|
1752
|
-
// @ts-ignore
|
|
1753
|
-
restoredError.codeFrame = error.codeFrame;
|
|
1754
|
-
}
|
|
1629
|
+
};
|
|
1630
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
1631
|
+
const {
|
|
1632
|
+
resolve,
|
|
1633
|
+
promise
|
|
1634
|
+
} = withResolvers();
|
|
1635
|
+
const listenerMap = Object.create(null);
|
|
1636
|
+
const cleanup = value => {
|
|
1637
|
+
for (const event of Object.keys(eventMap)) {
|
|
1638
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
1755
1639
|
}
|
|
1756
|
-
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1640
|
+
resolve(value);
|
|
1641
|
+
};
|
|
1642
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
1643
|
+
const listener = event => {
|
|
1644
|
+
cleanup({
|
|
1645
|
+
type,
|
|
1646
|
+
event
|
|
1647
|
+
});
|
|
1648
|
+
};
|
|
1649
|
+
addListener(eventEmitter, event, listener);
|
|
1650
|
+
listenerMap[event] = listener;
|
|
1760
1651
|
}
|
|
1761
|
-
return
|
|
1652
|
+
return promise;
|
|
1762
1653
|
};
|
|
1763
|
-
const
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1654
|
+
const stringifyCompact = value => {
|
|
1655
|
+
return JSON.stringify(value);
|
|
1656
|
+
};
|
|
1657
|
+
const parse$1 = content => {
|
|
1658
|
+
if (content === 'undefined') {
|
|
1659
|
+
return null;
|
|
1767
1660
|
}
|
|
1768
|
-
|
|
1769
|
-
return
|
|
1661
|
+
try {
|
|
1662
|
+
return JSON.parse(content);
|
|
1663
|
+
} catch (error) {
|
|
1664
|
+
throw new VError(error, 'failed to parse json');
|
|
1770
1665
|
}
|
|
1771
|
-
throw new JsonRpcError('unexpected response message');
|
|
1772
1666
|
};
|
|
1773
|
-
const
|
|
1774
|
-
|
|
1667
|
+
const waitForWebSocketToBeOpen = webSocket => {
|
|
1668
|
+
return getFirstEvent(webSocket, {
|
|
1669
|
+
open: Open,
|
|
1670
|
+
close: Close,
|
|
1671
|
+
error: Error$3
|
|
1672
|
+
});
|
|
1775
1673
|
};
|
|
1776
|
-
const
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1674
|
+
const create$9 = async ({
|
|
1675
|
+
webSocket
|
|
1676
|
+
}) => {
|
|
1677
|
+
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
1678
|
+
if (firstWebSocketEvent.type === Error$3) {
|
|
1679
|
+
throw new IpcError(`WebSocket connection error`);
|
|
1782
1680
|
}
|
|
1783
|
-
|
|
1784
|
-
|
|
1681
|
+
if (firstWebSocketEvent.type === Close) {
|
|
1682
|
+
throw new IpcError('Websocket connection was immediately closed');
|
|
1683
|
+
}
|
|
1684
|
+
return webSocket;
|
|
1785
1685
|
};
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
return prettyError.type;
|
|
1686
|
+
let IpcParentWithWebSocket$1 = class IpcParentWithWebSocket extends Ipc {
|
|
1687
|
+
getData(event) {
|
|
1688
|
+
return parse$1(event.data);
|
|
1790
1689
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1690
|
+
send(message) {
|
|
1691
|
+
this._rawIpc.send(stringifyCompact(message));
|
|
1793
1692
|
}
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1693
|
+
sendAndTransfer(message) {
|
|
1694
|
+
throw new Error('sendAndTransfer not supported');
|
|
1695
|
+
}
|
|
1696
|
+
dispose() {
|
|
1697
|
+
this._rawIpc.close();
|
|
1698
|
+
}
|
|
1699
|
+
onClose(callback) {
|
|
1700
|
+
this._rawIpc.addEventListener('close', callback);
|
|
1701
|
+
}
|
|
1702
|
+
onMessage(callback) {
|
|
1703
|
+
this._rawIpc.addEventListener('message', callback);
|
|
1803
1704
|
}
|
|
1804
|
-
return {
|
|
1805
|
-
code: Custom,
|
|
1806
|
-
message: prettyError.message,
|
|
1807
|
-
data: {
|
|
1808
|
-
stack: prettyError.stack,
|
|
1809
|
-
codeFrame: prettyError.codeFrame,
|
|
1810
|
-
type: getErrorType(prettyError),
|
|
1811
|
-
code: prettyError.code,
|
|
1812
|
-
name: prettyError.name
|
|
1813
|
-
}
|
|
1814
|
-
};
|
|
1815
1705
|
};
|
|
1816
|
-
const
|
|
1817
|
-
return
|
|
1818
|
-
jsonrpc: Two,
|
|
1819
|
-
id: message.id,
|
|
1820
|
-
error
|
|
1821
|
-
};
|
|
1706
|
+
const wrap$3 = webSocket => {
|
|
1707
|
+
return new IpcParentWithWebSocket$1(webSocket);
|
|
1822
1708
|
};
|
|
1823
|
-
const
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
return create$1$1(message, errorProperty);
|
|
1828
|
-
};
|
|
1829
|
-
const create$7 = (message, result) => {
|
|
1830
|
-
return {
|
|
1831
|
-
jsonrpc: Two,
|
|
1832
|
-
id: message.id,
|
|
1833
|
-
result: result ?? null
|
|
1834
|
-
};
|
|
1835
|
-
};
|
|
1836
|
-
const getSuccessResponse = (message, result) => {
|
|
1837
|
-
const resultProperty = result ?? null;
|
|
1838
|
-
return create$7(message, resultProperty);
|
|
1839
|
-
};
|
|
1840
|
-
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
1841
|
-
try {
|
|
1842
|
-
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
1843
|
-
return getSuccessResponse(message, result);
|
|
1844
|
-
} catch (error) {
|
|
1845
|
-
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
1846
|
-
}
|
|
1847
|
-
};
|
|
1848
|
-
const defaultPreparePrettyError = error => {
|
|
1849
|
-
return error;
|
|
1850
|
-
};
|
|
1851
|
-
const defaultLogError = () => {
|
|
1852
|
-
// ignore
|
|
1853
|
-
};
|
|
1854
|
-
const defaultRequiresSocket = () => {
|
|
1855
|
-
return false;
|
|
1856
|
-
};
|
|
1857
|
-
const defaultResolve = resolve;
|
|
1858
|
-
|
|
1859
|
-
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
1860
|
-
const normalizeParams = args => {
|
|
1861
|
-
if (args.length === 1) {
|
|
1862
|
-
const options = args[0];
|
|
1863
|
-
return {
|
|
1864
|
-
ipc: options.ipc,
|
|
1865
|
-
message: options.message,
|
|
1866
|
-
execute: options.execute,
|
|
1867
|
-
resolve: options.resolve || defaultResolve,
|
|
1868
|
-
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
1869
|
-
logError: options.logError || defaultLogError,
|
|
1870
|
-
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
1871
|
-
};
|
|
1872
|
-
}
|
|
1873
|
-
return {
|
|
1874
|
-
ipc: args[0],
|
|
1875
|
-
message: args[1],
|
|
1876
|
-
execute: args[2],
|
|
1877
|
-
resolve: args[3],
|
|
1878
|
-
preparePrettyError: args[4],
|
|
1879
|
-
logError: args[5],
|
|
1880
|
-
requiresSocket: args[6]
|
|
1881
|
-
};
|
|
1882
|
-
};
|
|
1883
|
-
const handleJsonRpcMessage = async (...args) => {
|
|
1884
|
-
const options = normalizeParams(args);
|
|
1885
|
-
const {
|
|
1886
|
-
message,
|
|
1887
|
-
ipc,
|
|
1888
|
-
execute,
|
|
1889
|
-
resolve,
|
|
1890
|
-
preparePrettyError,
|
|
1891
|
-
logError,
|
|
1892
|
-
requiresSocket
|
|
1893
|
-
} = options;
|
|
1894
|
-
if ('id' in message) {
|
|
1895
|
-
if ('method' in message) {
|
|
1896
|
-
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1897
|
-
try {
|
|
1898
|
-
ipc.send(response);
|
|
1899
|
-
} catch (error) {
|
|
1900
|
-
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
1901
|
-
ipc.send(errorResponse);
|
|
1902
|
-
}
|
|
1903
|
-
return;
|
|
1904
|
-
}
|
|
1905
|
-
resolve(message.id, message);
|
|
1906
|
-
return;
|
|
1907
|
-
}
|
|
1908
|
-
if ('method' in message) {
|
|
1909
|
-
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1910
|
-
return;
|
|
1911
|
-
}
|
|
1912
|
-
throw new JsonRpcError('unexpected message');
|
|
1913
|
-
};
|
|
1914
|
-
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
1915
|
-
const {
|
|
1916
|
-
message,
|
|
1917
|
-
promise
|
|
1918
|
-
} = create$2$1(method, params);
|
|
1919
|
-
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
1920
|
-
ipc.sendAndTransfer(message);
|
|
1921
|
-
} else {
|
|
1922
|
-
ipc.send(message);
|
|
1923
|
-
}
|
|
1924
|
-
const responseMessage = await promise;
|
|
1925
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
1926
|
-
};
|
|
1927
|
-
const send = (transport, method, ...params) => {
|
|
1928
|
-
const message = create$4$1(method, params);
|
|
1929
|
-
transport.send(message);
|
|
1930
|
-
};
|
|
1931
|
-
const invoke = (ipc, method, ...params) => {
|
|
1932
|
-
return invokeHelper(ipc, method, params, false);
|
|
1933
|
-
};
|
|
1934
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
1935
|
-
return invokeHelper(ipc, method, params, true);
|
|
1936
|
-
};
|
|
1937
|
-
|
|
1938
|
-
const commands = Object.create(null);
|
|
1939
|
-
const register = commandMap => {
|
|
1940
|
-
Object.assign(commands, commandMap);
|
|
1941
|
-
};
|
|
1942
|
-
const getCommand = key => {
|
|
1943
|
-
return commands[key];
|
|
1944
|
-
};
|
|
1945
|
-
const execute = (command, ...args) => {
|
|
1946
|
-
const fn = getCommand(command);
|
|
1947
|
-
if (!fn) {
|
|
1948
|
-
throw new Error(`command not found ${command}`);
|
|
1949
|
-
}
|
|
1950
|
-
return fn(...args);
|
|
1709
|
+
const IpcParentWithWebSocket$1$1 = {
|
|
1710
|
+
__proto__: null,
|
|
1711
|
+
create: create$9,
|
|
1712
|
+
wrap: wrap$3
|
|
1951
1713
|
};
|
|
1952
1714
|
|
|
1953
|
-
const
|
|
1954
|
-
return
|
|
1955
|
-
};
|
|
1956
|
-
const preparePrettyError$2 = error => {
|
|
1957
|
-
return error;
|
|
1958
|
-
};
|
|
1959
|
-
const logError$2 = error => {
|
|
1960
|
-
// handled by renderer worker
|
|
1961
|
-
};
|
|
1962
|
-
const handleMessage$1 = event => {
|
|
1963
|
-
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError$2, logError$2, requiresSocket$2);
|
|
1715
|
+
const getWebSocketProtocol = () => {
|
|
1716
|
+
return location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
1964
1717
|
};
|
|
1965
1718
|
|
|
1966
|
-
const
|
|
1967
|
-
|
|
1719
|
+
const getWebSocketUrl = type => {
|
|
1720
|
+
const wsProtocol = getWebSocketProtocol();
|
|
1721
|
+
return `${wsProtocol}//${location.host}/websocket/${type}`;
|
|
1968
1722
|
};
|
|
1969
1723
|
|
|
1970
|
-
const
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
const
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
} = getPortTuple();
|
|
1979
|
-
const promise = new Promise(resolve => {
|
|
1980
|
-
port2.onmessage = resolve;
|
|
1724
|
+
const create$8 = async ({
|
|
1725
|
+
type
|
|
1726
|
+
}) => {
|
|
1727
|
+
string(type);
|
|
1728
|
+
const wsUrl = getWebSocketUrl(type);
|
|
1729
|
+
const webSocket = new WebSocket(wsUrl);
|
|
1730
|
+
return IpcParentWithWebSocket$1$1.create({
|
|
1731
|
+
webSocket
|
|
1981
1732
|
});
|
|
1982
|
-
const portType = 'test';
|
|
1983
|
-
await invokeAndTransfer$1('WebView.setPort', uid, port1, origin, portType);
|
|
1984
|
-
const event = await promise;
|
|
1985
|
-
// @ts-ignore
|
|
1986
|
-
if (event.data !== 'ready') {
|
|
1987
|
-
throw new Error('unexpected first message');
|
|
1988
|
-
}
|
|
1989
|
-
const ipc = {
|
|
1990
|
-
addEventListener(type, listener) {
|
|
1991
|
-
const that = this;
|
|
1992
|
-
const wrapped = event => {
|
|
1993
|
-
const actualEvent = {
|
|
1994
|
-
target: that,
|
|
1995
|
-
data: event.data
|
|
1996
|
-
};
|
|
1997
|
-
listener(actualEvent);
|
|
1998
|
-
};
|
|
1999
|
-
port2.addEventListener(type, wrapped);
|
|
2000
|
-
},
|
|
2001
|
-
dispose() {},
|
|
2002
|
-
send(message) {
|
|
2003
|
-
port2.postMessage(message);
|
|
2004
|
-
}
|
|
2005
|
-
};
|
|
2006
|
-
// TODO maybe don't send a message port only to get object url?
|
|
2007
|
-
// TODO dispose ipc to avoid memory leak
|
|
2008
|
-
handleIpc$1(ipc);
|
|
2009
|
-
return ipc;
|
|
2010
|
-
};
|
|
2011
|
-
|
|
2012
|
-
const webViews = Object.create(null);
|
|
2013
|
-
const webViewProviders = Object.create(null);
|
|
2014
|
-
const getProvider = providerId => {
|
|
2015
|
-
return webViewProviders[providerId];
|
|
2016
|
-
};
|
|
2017
|
-
const setProvider = (providerId, provider) => {
|
|
2018
|
-
webViewProviders[providerId] = provider;
|
|
2019
|
-
};
|
|
2020
|
-
const getWebView = id => {
|
|
2021
|
-
return webViews[id];
|
|
2022
|
-
};
|
|
2023
|
-
const setWebView = (id, webView) => {
|
|
2024
|
-
webViews[id] = webView;
|
|
2025
1733
|
};
|
|
2026
|
-
const
|
|
2027
|
-
return
|
|
1734
|
+
const wrap$2 = webSocket => {
|
|
1735
|
+
return IpcParentWithWebSocket$1$1.wrap(webSocket);
|
|
2028
1736
|
};
|
|
2029
1737
|
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
// 4. send back objecturl to extension host worker
|
|
2035
|
-
// 5. provide objectUrl to extension
|
|
2036
|
-
|
|
2037
|
-
const getRemoteUrlForWebView = async (uri, options = {}) => {
|
|
2038
|
-
const webView = getWebView(options.webViewId);
|
|
2039
|
-
if (!webView) {
|
|
2040
|
-
throw new Error(`webview ${options.webViewId} not found`);
|
|
2041
|
-
}
|
|
2042
|
-
const [ipc, blob] = await Promise.all([createWebViewIpc(webView), invoke$1('FileSystem.getBlob', uri)]);
|
|
2043
|
-
const objectUrl = await invoke(ipc, 'createObjectUrl', blob);
|
|
2044
|
-
return objectUrl;
|
|
1738
|
+
const IpcParentWithWebSocket = {
|
|
1739
|
+
__proto__: null,
|
|
1740
|
+
create: create$8,
|
|
1741
|
+
wrap: wrap$2
|
|
2045
1742
|
};
|
|
2046
1743
|
|
|
2047
1744
|
const Electron = 'electron';
|
|
@@ -2069,187 +1766,1177 @@ const getPlatform = () => {
|
|
|
2069
1766
|
};
|
|
2070
1767
|
const platform = getPlatform(); // TODO tree-shake this out in production
|
|
2071
1768
|
|
|
2072
|
-
const
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
return `/remote${uri}`;
|
|
2079
|
-
}
|
|
2080
|
-
return `/remote/${uri}`;
|
|
2081
|
-
}
|
|
2082
|
-
if (platform === Electron && !protocol) {
|
|
2083
|
-
if (uri.startsWith('/')) {
|
|
2084
|
-
return `/remote${uri}`;
|
|
2085
|
-
}
|
|
2086
|
-
return `/remote/${uri}`;
|
|
2087
|
-
}
|
|
2088
|
-
if (options.webViewId) {
|
|
2089
|
-
return getRemoteUrlForWebView(uri, options);
|
|
1769
|
+
const getModule$3 = () => {
|
|
1770
|
+
switch (platform) {
|
|
1771
|
+
case Remote:
|
|
1772
|
+
return IpcParentWithWebSocket;
|
|
1773
|
+
default:
|
|
1774
|
+
return IpcParentWithElectronMessagePort;
|
|
2090
1775
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
1776
|
+
};
|
|
1777
|
+
const create$7 = async ({
|
|
1778
|
+
type,
|
|
1779
|
+
raw
|
|
1780
|
+
}) => {
|
|
1781
|
+
const module = getModule$3();
|
|
1782
|
+
const rawIpc = await module.create({
|
|
1783
|
+
type
|
|
1784
|
+
});
|
|
1785
|
+
if (raw) {
|
|
1786
|
+
return rawIpc;
|
|
2094
1787
|
}
|
|
2095
|
-
|
|
1788
|
+
return {
|
|
1789
|
+
module,
|
|
1790
|
+
rawIpc
|
|
1791
|
+
};
|
|
2096
1792
|
};
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
} = Promise.withResolvers();
|
|
2103
|
-
port.onmessage = resolve;
|
|
2104
|
-
const firstMessage = await promise;
|
|
2105
|
-
return firstMessage;
|
|
1793
|
+
const wrap$1 = ({
|
|
1794
|
+
module,
|
|
1795
|
+
rawIpc
|
|
1796
|
+
}) => {
|
|
1797
|
+
return module.wrap(rawIpc);
|
|
2106
1798
|
};
|
|
2107
1799
|
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
1800
|
+
const IpcParentWithNode = {
|
|
1801
|
+
__proto__: null,
|
|
1802
|
+
create: create$7,
|
|
1803
|
+
wrap: wrap$1
|
|
1804
|
+
};
|
|
1805
|
+
|
|
1806
|
+
const getModule$2 = method => {
|
|
1807
|
+
switch (method) {
|
|
1808
|
+
case WebSocket$1:
|
|
1809
|
+
return IpcParentWithWebSocket;
|
|
1810
|
+
case ElectronMessagePort:
|
|
1811
|
+
return IpcParentWithNode;
|
|
1812
|
+
case ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1:
|
|
1813
|
+
return IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug;
|
|
1814
|
+
default:
|
|
1815
|
+
throw new Error('unexpected ipc type');
|
|
2113
1816
|
}
|
|
1817
|
+
};
|
|
2114
1818
|
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
1819
|
+
const create$6 = async ({
|
|
1820
|
+
method,
|
|
1821
|
+
...options
|
|
1822
|
+
}) => {
|
|
1823
|
+
try {
|
|
1824
|
+
const module = getModule$2(method);
|
|
1825
|
+
// @ts-ignore
|
|
1826
|
+
const rawIpc = await module.create(options);
|
|
1827
|
+
// @ts-ignore
|
|
1828
|
+
const ipc = module.wrap(rawIpc);
|
|
1829
|
+
return ipc;
|
|
1830
|
+
} catch (error) {
|
|
1831
|
+
throw new VError(error, `Failed to create ipc`);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
2119
1834
|
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
params,
|
|
2129
|
-
id
|
|
2130
|
-
} = data;
|
|
2131
|
-
if (id && !method) {
|
|
2132
|
-
resolve(id, data);
|
|
2133
|
-
return;
|
|
2134
|
-
}
|
|
2135
|
-
if (provider && provider.commands && provider.commands[method]) {
|
|
2136
|
-
const fn = provider.commands[method];
|
|
2137
|
-
const result = await fn(...params);
|
|
2138
|
-
if (id && method) {
|
|
2139
|
-
target.postMessage({
|
|
2140
|
-
jsonrpc: '2.0',
|
|
2141
|
-
id,
|
|
2142
|
-
result
|
|
2143
|
-
});
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
};
|
|
2147
|
-
port.onmessage = handlePortMessage;
|
|
2148
|
-
const rpc = {
|
|
2149
|
-
uri,
|
|
2150
|
-
provider,
|
|
2151
|
-
uid,
|
|
2152
|
-
origin,
|
|
2153
|
-
async invoke(method, ...params) {
|
|
2154
|
-
const {
|
|
2155
|
-
id,
|
|
2156
|
-
promise
|
|
2157
|
-
} = registerPromise();
|
|
2158
|
-
port.postMessage({
|
|
2159
|
-
jsonrpc: '2.0',
|
|
2160
|
-
id,
|
|
2161
|
-
method,
|
|
2162
|
-
params
|
|
2163
|
-
});
|
|
2164
|
-
const result = await promise;
|
|
2165
|
-
if (result.error) {
|
|
2166
|
-
throw new Error(`Error: ${result.error.message}`);
|
|
2167
|
-
}
|
|
2168
|
-
return result.result;
|
|
2169
|
-
}
|
|
1835
|
+
const JsonRpc = 1;
|
|
1836
|
+
|
|
1837
|
+
const Two = '2.0';
|
|
1838
|
+
const create$4 = (method, params) => {
|
|
1839
|
+
return {
|
|
1840
|
+
jsonrpc: Two,
|
|
1841
|
+
method,
|
|
1842
|
+
params
|
|
2170
1843
|
};
|
|
2171
|
-
// TODO allow creating multiple webviews per provider
|
|
2172
|
-
setWebView(providerId, rpc);
|
|
2173
1844
|
};
|
|
2174
|
-
const
|
|
2175
|
-
|
|
2176
|
-
|
|
1845
|
+
const callbacks = Object.create(null);
|
|
1846
|
+
const set$3 = (id, fn) => {
|
|
1847
|
+
callbacks[id] = fn;
|
|
2177
1848
|
};
|
|
2178
|
-
const
|
|
2179
|
-
|
|
2180
|
-
// const webView=webViews[id]
|
|
1849
|
+
const get$3 = id => {
|
|
1850
|
+
return callbacks[id];
|
|
2181
1851
|
};
|
|
2182
|
-
const
|
|
2183
|
-
|
|
1852
|
+
const remove = id => {
|
|
1853
|
+
delete callbacks[id];
|
|
2184
1854
|
};
|
|
2185
|
-
|
|
2186
|
-
|
|
1855
|
+
let id = 0;
|
|
1856
|
+
const create$3$1 = () => {
|
|
1857
|
+
return ++id;
|
|
1858
|
+
};
|
|
1859
|
+
const registerPromise = () => {
|
|
1860
|
+
const id = create$3$1();
|
|
1861
|
+
const {
|
|
1862
|
+
resolve,
|
|
1863
|
+
promise
|
|
1864
|
+
} = Promise.withResolvers();
|
|
1865
|
+
set$3(id, resolve);
|
|
2187
1866
|
return {
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
uri: webView.uri
|
|
1867
|
+
id,
|
|
1868
|
+
promise
|
|
2191
1869
|
};
|
|
2192
1870
|
};
|
|
2193
|
-
|
|
2194
|
-
const
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
1871
|
+
const create$2$1 = (method, params) => {
|
|
1872
|
+
const {
|
|
1873
|
+
id,
|
|
1874
|
+
promise
|
|
1875
|
+
} = registerPromise();
|
|
1876
|
+
const message = {
|
|
1877
|
+
jsonrpc: Two,
|
|
1878
|
+
method,
|
|
1879
|
+
params,
|
|
1880
|
+
id
|
|
1881
|
+
};
|
|
1882
|
+
return {
|
|
1883
|
+
message,
|
|
1884
|
+
promise
|
|
1885
|
+
};
|
|
2208
1886
|
};
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
1887
|
+
class JsonRpcError extends Error {
|
|
1888
|
+
constructor(message) {
|
|
1889
|
+
super(message);
|
|
1890
|
+
this.name = 'JsonRpcError';
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
const NewLine = '\n';
|
|
1894
|
+
const DomException = 'DOMException';
|
|
1895
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
1896
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
1897
|
+
const TypeError$1 = 'TypeError';
|
|
1898
|
+
const getErrorConstructor = (message, type) => {
|
|
1899
|
+
if (type) {
|
|
1900
|
+
switch (type) {
|
|
1901
|
+
case DomException:
|
|
1902
|
+
return DOMException;
|
|
1903
|
+
case TypeError$1:
|
|
1904
|
+
return TypeError;
|
|
1905
|
+
case SyntaxError$1:
|
|
1906
|
+
return SyntaxError;
|
|
1907
|
+
case ReferenceError$1:
|
|
1908
|
+
return ReferenceError;
|
|
1909
|
+
default:
|
|
1910
|
+
return Error;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
if (message.startsWith('TypeError: ')) {
|
|
1914
|
+
return TypeError;
|
|
1915
|
+
}
|
|
1916
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
1917
|
+
return SyntaxError;
|
|
1918
|
+
}
|
|
1919
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
1920
|
+
return ReferenceError;
|
|
1921
|
+
}
|
|
1922
|
+
return Error;
|
|
2212
1923
|
};
|
|
2213
|
-
const
|
|
2214
|
-
|
|
1924
|
+
const constructError = (message, type, name) => {
|
|
1925
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
1926
|
+
if (ErrorConstructor === DOMException && name) {
|
|
1927
|
+
return new ErrorConstructor(message, name);
|
|
1928
|
+
}
|
|
1929
|
+
if (ErrorConstructor === Error) {
|
|
1930
|
+
const error = new Error(message);
|
|
1931
|
+
if (name && name !== 'VError') {
|
|
1932
|
+
error.name = name;
|
|
1933
|
+
}
|
|
1934
|
+
return error;
|
|
1935
|
+
}
|
|
1936
|
+
return new ErrorConstructor(message);
|
|
2215
1937
|
};
|
|
2216
|
-
const
|
|
2217
|
-
return
|
|
1938
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
1939
|
+
return string.indexOf(NewLine, startIndex);
|
|
2218
1940
|
};
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
// @ts-ignore
|
|
2224
|
-
this.codeFrame = codeFrame;
|
|
2225
|
-
this.name = 'FormattingError';
|
|
1941
|
+
const getParentStack = error => {
|
|
1942
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
1943
|
+
if (parentStack.startsWith(' at')) {
|
|
1944
|
+
parentStack = error.message + NewLine + parentStack;
|
|
2226
1945
|
}
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
const File$2 = 1;
|
|
2230
|
-
const Match = 2;
|
|
2231
|
-
|
|
2232
|
-
const TextSearchResultType = {
|
|
2233
|
-
__proto__: null,
|
|
2234
|
-
File: File$2,
|
|
2235
|
-
Match
|
|
1946
|
+
return parentStack;
|
|
2236
1947
|
};
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
1948
|
+
const joinLines = lines => {
|
|
1949
|
+
return lines.join(NewLine);
|
|
1950
|
+
};
|
|
1951
|
+
const MethodNotFound = -32601;
|
|
1952
|
+
const Custom = -32001;
|
|
1953
|
+
const splitLines$1 = lines => {
|
|
1954
|
+
return lines.split(NewLine);
|
|
1955
|
+
};
|
|
1956
|
+
const restoreJsonRpcError = error => {
|
|
1957
|
+
if (error && error instanceof Error) {
|
|
1958
|
+
return error;
|
|
1959
|
+
}
|
|
1960
|
+
const currentStack = joinLines(splitLines$1(new Error().stack || '').slice(1));
|
|
1961
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
1962
|
+
const restoredError = new JsonRpcError(error.message);
|
|
1963
|
+
const parentStack = getParentStack(error);
|
|
1964
|
+
restoredError.stack = parentStack + NewLine + currentStack;
|
|
1965
|
+
return restoredError;
|
|
1966
|
+
}
|
|
1967
|
+
if (error && error.message) {
|
|
1968
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
1969
|
+
if (error.data) {
|
|
1970
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
1971
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
1972
|
+
} else if (error.data.stack) {
|
|
1973
|
+
restoredError.stack = error.data.stack;
|
|
1974
|
+
}
|
|
1975
|
+
if (error.data.codeFrame) {
|
|
1976
|
+
// @ts-ignore
|
|
1977
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
1978
|
+
}
|
|
1979
|
+
if (error.data.code) {
|
|
1980
|
+
// @ts-ignore
|
|
1981
|
+
restoredError.code = error.data.code;
|
|
1982
|
+
}
|
|
1983
|
+
if (error.data.type) {
|
|
1984
|
+
// @ts-ignore
|
|
1985
|
+
restoredError.name = error.data.type;
|
|
1986
|
+
}
|
|
1987
|
+
} else {
|
|
1988
|
+
if (error.stack) {
|
|
1989
|
+
const lowerStack = restoredError.stack || '';
|
|
1990
|
+
// @ts-ignore
|
|
1991
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
1992
|
+
const parentStack = getParentStack(error);
|
|
1993
|
+
// @ts-ignore
|
|
1994
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
1995
|
+
}
|
|
1996
|
+
if (error.codeFrame) {
|
|
1997
|
+
// @ts-ignore
|
|
1998
|
+
restoredError.codeFrame = error.codeFrame;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
return restoredError;
|
|
2002
|
+
}
|
|
2003
|
+
if (typeof error === 'string') {
|
|
2004
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
2005
|
+
}
|
|
2006
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
2007
|
+
};
|
|
2008
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
2009
|
+
if ('error' in responseMessage) {
|
|
2010
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
2011
|
+
throw restoredError;
|
|
2012
|
+
}
|
|
2013
|
+
if ('result' in responseMessage) {
|
|
2014
|
+
return responseMessage.result;
|
|
2015
|
+
}
|
|
2016
|
+
throw new JsonRpcError('unexpected response message');
|
|
2017
|
+
};
|
|
2018
|
+
const warn = (...args) => {
|
|
2019
|
+
console.warn(...args);
|
|
2020
|
+
};
|
|
2021
|
+
const resolve = (id, response) => {
|
|
2022
|
+
const fn = get$3(id);
|
|
2023
|
+
if (!fn) {
|
|
2024
|
+
console.log(response);
|
|
2025
|
+
warn(`callback ${id} may already be disposed`);
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
fn(response);
|
|
2029
|
+
remove(id);
|
|
2030
|
+
};
|
|
2031
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
2032
|
+
const getErrorType = prettyError => {
|
|
2033
|
+
if (prettyError && prettyError.type) {
|
|
2034
|
+
return prettyError.type;
|
|
2035
|
+
}
|
|
2036
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
2037
|
+
return prettyError.constructor.name;
|
|
2038
|
+
}
|
|
2039
|
+
return undefined;
|
|
2040
|
+
};
|
|
2041
|
+
const getErrorProperty = (error, prettyError) => {
|
|
2042
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
2043
|
+
return {
|
|
2044
|
+
code: MethodNotFound,
|
|
2045
|
+
message: error.message,
|
|
2046
|
+
data: error.stack
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
return {
|
|
2050
|
+
code: Custom,
|
|
2051
|
+
message: prettyError.message,
|
|
2052
|
+
data: {
|
|
2053
|
+
stack: prettyError.stack,
|
|
2054
|
+
codeFrame: prettyError.codeFrame,
|
|
2055
|
+
type: getErrorType(prettyError),
|
|
2056
|
+
code: prettyError.code,
|
|
2057
|
+
name: prettyError.name
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
2060
|
+
};
|
|
2061
|
+
const create$1$1 = (message, error) => {
|
|
2062
|
+
return {
|
|
2063
|
+
jsonrpc: Two,
|
|
2064
|
+
id: message.id,
|
|
2065
|
+
error
|
|
2066
|
+
};
|
|
2067
|
+
};
|
|
2068
|
+
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
2069
|
+
const prettyError = preparePrettyError(error);
|
|
2070
|
+
logError(error, prettyError);
|
|
2071
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
2072
|
+
return create$1$1(message, errorProperty);
|
|
2073
|
+
};
|
|
2074
|
+
const create$5 = (message, result) => {
|
|
2075
|
+
return {
|
|
2076
|
+
jsonrpc: Two,
|
|
2077
|
+
id: message.id,
|
|
2078
|
+
result: result ?? null
|
|
2079
|
+
};
|
|
2080
|
+
};
|
|
2081
|
+
const getSuccessResponse = (message, result) => {
|
|
2082
|
+
const resultProperty = result ?? null;
|
|
2083
|
+
return create$5(message, resultProperty);
|
|
2084
|
+
};
|
|
2085
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
2086
|
+
try {
|
|
2087
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
2088
|
+
return getSuccessResponse(message, result);
|
|
2089
|
+
} catch (error) {
|
|
2090
|
+
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
2091
|
+
}
|
|
2092
|
+
};
|
|
2093
|
+
const defaultPreparePrettyError = error => {
|
|
2094
|
+
return error;
|
|
2095
|
+
};
|
|
2096
|
+
const defaultLogError = () => {
|
|
2097
|
+
// ignore
|
|
2098
|
+
};
|
|
2099
|
+
const defaultRequiresSocket = () => {
|
|
2100
|
+
return false;
|
|
2101
|
+
};
|
|
2102
|
+
const defaultResolve = resolve;
|
|
2103
|
+
|
|
2104
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
2105
|
+
const normalizeParams = args => {
|
|
2106
|
+
if (args.length === 1) {
|
|
2107
|
+
const options = args[0];
|
|
2108
|
+
return {
|
|
2109
|
+
ipc: options.ipc,
|
|
2110
|
+
message: options.message,
|
|
2111
|
+
execute: options.execute,
|
|
2112
|
+
resolve: options.resolve || defaultResolve,
|
|
2113
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
2114
|
+
logError: options.logError || defaultLogError,
|
|
2115
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
return {
|
|
2119
|
+
ipc: args[0],
|
|
2120
|
+
message: args[1],
|
|
2121
|
+
execute: args[2],
|
|
2122
|
+
resolve: args[3],
|
|
2123
|
+
preparePrettyError: args[4],
|
|
2124
|
+
logError: args[5],
|
|
2125
|
+
requiresSocket: args[6]
|
|
2126
|
+
};
|
|
2127
|
+
};
|
|
2128
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
2129
|
+
const options = normalizeParams(args);
|
|
2130
|
+
const {
|
|
2131
|
+
message,
|
|
2132
|
+
ipc,
|
|
2133
|
+
execute,
|
|
2134
|
+
resolve,
|
|
2135
|
+
preparePrettyError,
|
|
2136
|
+
logError,
|
|
2137
|
+
requiresSocket
|
|
2138
|
+
} = options;
|
|
2139
|
+
if ('id' in message) {
|
|
2140
|
+
if ('method' in message) {
|
|
2141
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
2142
|
+
try {
|
|
2143
|
+
ipc.send(response);
|
|
2144
|
+
} catch (error) {
|
|
2145
|
+
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
2146
|
+
ipc.send(errorResponse);
|
|
2147
|
+
}
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
resolve(message.id, message);
|
|
2151
|
+
return;
|
|
2152
|
+
}
|
|
2153
|
+
if ('method' in message) {
|
|
2154
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
2155
|
+
return;
|
|
2156
|
+
}
|
|
2157
|
+
throw new JsonRpcError('unexpected message');
|
|
2158
|
+
};
|
|
2159
|
+
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
2160
|
+
const {
|
|
2161
|
+
message,
|
|
2162
|
+
promise
|
|
2163
|
+
} = create$2$1(method, params);
|
|
2164
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
2165
|
+
ipc.sendAndTransfer(message);
|
|
2166
|
+
} else {
|
|
2167
|
+
ipc.send(message);
|
|
2168
|
+
}
|
|
2169
|
+
const responseMessage = await promise;
|
|
2170
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
2171
|
+
};
|
|
2172
|
+
const send = (transport, method, ...params) => {
|
|
2173
|
+
const message = create$4(method, params);
|
|
2174
|
+
transport.send(message);
|
|
2175
|
+
};
|
|
2176
|
+
const invoke = (ipc, method, ...params) => {
|
|
2177
|
+
return invokeHelper(ipc, method, params, false);
|
|
2178
|
+
};
|
|
2179
|
+
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
2180
|
+
return invokeHelper(ipc, method, params, true);
|
|
2181
|
+
};
|
|
2182
|
+
|
|
2183
|
+
const preparePrettyError$2 = error => {
|
|
2184
|
+
return error;
|
|
2185
|
+
};
|
|
2186
|
+
const logError$2 = error => {
|
|
2187
|
+
// handled by renderer worker
|
|
2188
|
+
};
|
|
2189
|
+
const requiresSocket$2 = () => {
|
|
2190
|
+
return false;
|
|
2191
|
+
};
|
|
2192
|
+
const create$3 = ({
|
|
2193
|
+
ipc,
|
|
2194
|
+
execute
|
|
2195
|
+
}) => {
|
|
2196
|
+
object(ipc);
|
|
2197
|
+
fn(execute);
|
|
2198
|
+
const handleMessage = async message => {
|
|
2199
|
+
return handleJsonRpcMessage(ipc, message, execute, resolve, preparePrettyError$2, logError$2, requiresSocket$2);
|
|
2200
|
+
};
|
|
2201
|
+
ipc.onmessage = handleMessage;
|
|
2202
|
+
return {
|
|
2203
|
+
ipc,
|
|
2204
|
+
invoke(method, ...params) {
|
|
2205
|
+
return invoke(this.ipc, method, ...params);
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
};
|
|
2209
|
+
|
|
2210
|
+
const RpcParentWithJsonRpc = {
|
|
2211
|
+
__proto__: null,
|
|
2212
|
+
create: create$3
|
|
2213
|
+
};
|
|
2214
|
+
|
|
2215
|
+
const getModule$1 = method => {
|
|
2216
|
+
switch (method) {
|
|
2217
|
+
case JsonRpc:
|
|
2218
|
+
return RpcParentWithJsonRpc;
|
|
2219
|
+
default:
|
|
2220
|
+
throw new Error('unexpected rpc type');
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
|
|
2224
|
+
const create$2 = async ({
|
|
2225
|
+
method,
|
|
2226
|
+
...options
|
|
2227
|
+
}) => {
|
|
2228
|
+
const module = await getModule$1(method);
|
|
2229
|
+
// @ts-ignore
|
|
2230
|
+
const rpc = module.create(options);
|
|
2231
|
+
return rpc;
|
|
2232
|
+
};
|
|
2233
|
+
|
|
2234
|
+
const defaultExecute$2 = () => {
|
|
2235
|
+
throw new Error('not implemented');
|
|
2236
|
+
};
|
|
2237
|
+
const createNodeRpc = async ({
|
|
2238
|
+
path,
|
|
2239
|
+
execute = defaultExecute$2,
|
|
2240
|
+
name = ''
|
|
2241
|
+
}) => {
|
|
2242
|
+
try {
|
|
2243
|
+
string(path);
|
|
2244
|
+
fn(execute);
|
|
2245
|
+
const ipc = await create$6({
|
|
2246
|
+
method: ElectronMessagePort,
|
|
2247
|
+
type: 'extension-host-helper-process',
|
|
2248
|
+
name
|
|
2249
|
+
});
|
|
2250
|
+
const rpc = await create$2({
|
|
2251
|
+
ipc,
|
|
2252
|
+
method: JsonRpc,
|
|
2253
|
+
execute
|
|
2254
|
+
});
|
|
2255
|
+
await rpc.invoke('LoadFile.loadFile', path);
|
|
2256
|
+
return rpc;
|
|
2257
|
+
} catch (error) {
|
|
2258
|
+
throw new VError(error, `Failed to create node rpc`);
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2261
|
+
|
|
2262
|
+
const confirm = message => {
|
|
2263
|
+
string(message);
|
|
2264
|
+
const result = invoke$1('ConfirmPrompt.prompt', message);
|
|
2265
|
+
return result;
|
|
2266
|
+
};
|
|
2267
|
+
|
|
2268
|
+
const ExtensionHostQuickPickShow = 'ExtensionHostQuickPick.show';
|
|
2269
|
+
|
|
2270
|
+
const showQuickPick = async ({
|
|
2271
|
+
getPicks,
|
|
2272
|
+
toPick
|
|
2273
|
+
}) => {
|
|
2274
|
+
const rawPicks = await getPicks();
|
|
2275
|
+
const picks = rawPicks.map(toPick);
|
|
2276
|
+
return invoke$1(ExtensionHostQuickPickShow, picks);
|
|
2277
|
+
};
|
|
2278
|
+
|
|
2279
|
+
const {
|
|
2280
|
+
registerReferenceProvider,
|
|
2281
|
+
executeReferenceProvider,
|
|
2282
|
+
executefileReferenceProvider,
|
|
2283
|
+
reset: reset$4
|
|
2284
|
+
} = create$c({
|
|
2285
|
+
name: 'Reference',
|
|
2286
|
+
resultShape: {
|
|
2287
|
+
type: Array$1,
|
|
2288
|
+
items: {
|
|
2289
|
+
type: Object$1
|
|
2290
|
+
}
|
|
2291
|
+
},
|
|
2292
|
+
additionalMethodNames: [
|
|
2293
|
+
// @ts-ignore
|
|
2294
|
+
{
|
|
2295
|
+
name: 'fileReference',
|
|
2296
|
+
methodName: 'provideFileReferences',
|
|
2297
|
+
resultShape: {
|
|
2298
|
+
type: Array$1,
|
|
2299
|
+
items: {
|
|
2300
|
+
type: Object$1
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
}]
|
|
2304
|
+
});
|
|
2305
|
+
|
|
2306
|
+
const {
|
|
2307
|
+
registerRenameProvider,
|
|
2308
|
+
executeRenameProvider,
|
|
2309
|
+
executeprepareRenameProvider,
|
|
2310
|
+
reset: reset$3
|
|
2311
|
+
} = create$c({
|
|
2312
|
+
name: 'Rename',
|
|
2313
|
+
resultShape: {
|
|
2314
|
+
type: Object$1,
|
|
2315
|
+
allowUndefined: true
|
|
2316
|
+
},
|
|
2317
|
+
additionalMethodNames: [
|
|
2318
|
+
// @ts-ignore
|
|
2319
|
+
{
|
|
2320
|
+
name: 'prepareRename',
|
|
2321
|
+
methodName: 'prepareRename',
|
|
2322
|
+
resultShape: {
|
|
2323
|
+
type: Object$1,
|
|
2324
|
+
allowUndefined: true
|
|
2325
|
+
}
|
|
2326
|
+
}]
|
|
2327
|
+
});
|
|
2328
|
+
|
|
2329
|
+
const getExtensionHostSubWorkerUrl = () => {
|
|
2330
|
+
return new URL('../../../../extension-host-sub-worker/src/extensionHostSubWorkerMain.js', import.meta.url).toString();
|
|
2331
|
+
};
|
|
2332
|
+
const extensionHostSubWorkerUrl = getExtensionHostSubWorkerUrl();
|
|
2333
|
+
|
|
2334
|
+
const set$2 = async (url, contentSecurityPolicy) => {
|
|
2335
|
+
const pathName = new URL(url).pathname;
|
|
2336
|
+
await invoke$1('ExtensionHostWorkerContentSecurityPolicy.set', pathName, contentSecurityPolicy);
|
|
2337
|
+
};
|
|
2338
|
+
|
|
2339
|
+
const defaultExecute$1 = () => {
|
|
2340
|
+
throw new Error('not implemented');
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
/**
|
|
2344
|
+
*
|
|
2345
|
+
* @deprecated
|
|
2346
|
+
*/
|
|
2347
|
+
const createLegacyRpc = async ({
|
|
2348
|
+
url,
|
|
2349
|
+
name,
|
|
2350
|
+
execute = defaultExecute$1,
|
|
2351
|
+
contentSecurityPolicy
|
|
2352
|
+
}) => {
|
|
2353
|
+
string(url);
|
|
2354
|
+
string(name);
|
|
2355
|
+
fn(execute);
|
|
2356
|
+
if (contentSecurityPolicy) {
|
|
2357
|
+
await set$2(url, contentSecurityPolicy);
|
|
2358
|
+
}
|
|
2359
|
+
const ipc = await create$6({
|
|
2360
|
+
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
2361
|
+
url: extensionHostSubWorkerUrl,
|
|
2362
|
+
name
|
|
2363
|
+
});
|
|
2364
|
+
const rpc = await create$2({
|
|
2365
|
+
ipc,
|
|
2366
|
+
method: JsonRpc,
|
|
2367
|
+
execute
|
|
2368
|
+
});
|
|
2369
|
+
await rpc.invoke('LoadFile.loadFile', url);
|
|
2370
|
+
return rpc;
|
|
2371
|
+
};
|
|
2372
|
+
|
|
2373
|
+
const rpcs$1 = Object.create(null);
|
|
2374
|
+
const add$1 = (id, rpc) => {
|
|
2375
|
+
rpcs$1[id] = rpc;
|
|
2376
|
+
};
|
|
2377
|
+
const get$2 = id => {
|
|
2378
|
+
return rpcs$1[id];
|
|
2379
|
+
};
|
|
2380
|
+
|
|
2381
|
+
const registry = Object.create(null);
|
|
2382
|
+
const rpcs = Object.create(null);
|
|
2383
|
+
const register$1 = (id, execute) => {
|
|
2384
|
+
registry[id] = execute;
|
|
2385
|
+
};
|
|
2386
|
+
const acquire = id => {
|
|
2387
|
+
const fn = registry[id];
|
|
2388
|
+
delete registry[id];
|
|
2389
|
+
return fn;
|
|
2390
|
+
};
|
|
2391
|
+
const get$1 = id => {
|
|
2392
|
+
return rpcs[id];
|
|
2393
|
+
};
|
|
2394
|
+
const set$1 = (id, rpc) => {
|
|
2395
|
+
rpcs[id] = rpc;
|
|
2396
|
+
};
|
|
2397
|
+
|
|
2398
|
+
const createRpcWithId$1 = async id => {
|
|
2399
|
+
const fn = acquire(id);
|
|
2400
|
+
const info = get$2(id);
|
|
2401
|
+
if (!info) {
|
|
2402
|
+
throw new Error(`rpc with id ${id} not found`);
|
|
2403
|
+
}
|
|
2404
|
+
const ipc = await create$6({
|
|
2405
|
+
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
2406
|
+
url: extensionHostSubWorkerUrl,
|
|
2407
|
+
name: info.name
|
|
2408
|
+
});
|
|
2409
|
+
const newRpc = await create$2({
|
|
2410
|
+
ipc,
|
|
2411
|
+
method: JsonRpc,
|
|
2412
|
+
execute: fn
|
|
2413
|
+
});
|
|
2414
|
+
await newRpc.invoke('LoadFile.loadFile', info.url);
|
|
2415
|
+
set$1(id, newRpc);
|
|
2416
|
+
return newRpc;
|
|
2417
|
+
};
|
|
2418
|
+
|
|
2419
|
+
const getOrCreateRpc = async id => {
|
|
2420
|
+
const rpc = get$1(id);
|
|
2421
|
+
if (!rpc) {
|
|
2422
|
+
set$1(id, createRpcWithId$1(id));
|
|
2423
|
+
}
|
|
2424
|
+
return get$1(id);
|
|
2425
|
+
};
|
|
2426
|
+
const createRpcWithId = ({
|
|
2427
|
+
id,
|
|
2428
|
+
execute
|
|
2429
|
+
}) => {
|
|
2430
|
+
string(id);
|
|
2431
|
+
register$1(id, execute);
|
|
2432
|
+
const lazyRpc = {
|
|
2433
|
+
async invoke(method, ...params) {
|
|
2434
|
+
const rpc = await getOrCreateRpc(id);
|
|
2435
|
+
return rpc.invoke(method, ...params);
|
|
2436
|
+
}
|
|
2437
|
+
};
|
|
2438
|
+
return lazyRpc;
|
|
2439
|
+
};
|
|
2440
|
+
|
|
2441
|
+
const defaultExecute = () => {
|
|
2442
|
+
throw new Error('not implemented');
|
|
2443
|
+
};
|
|
2444
|
+
const createRpc$1 = ({
|
|
2445
|
+
id,
|
|
2446
|
+
url,
|
|
2447
|
+
name,
|
|
2448
|
+
execute = defaultExecute,
|
|
2449
|
+
contentSecurityPolicy
|
|
2450
|
+
}) => {
|
|
2451
|
+
try {
|
|
2452
|
+
if (id) {
|
|
2453
|
+
string(id);
|
|
2454
|
+
return createRpcWithId({
|
|
2455
|
+
id,
|
|
2456
|
+
execute
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
return createLegacyRpc({
|
|
2460
|
+
url,
|
|
2461
|
+
name,
|
|
2462
|
+
execute,
|
|
2463
|
+
contentSecurityPolicy
|
|
2464
|
+
});
|
|
2465
|
+
} catch (error) {
|
|
2466
|
+
throw new VError(error, `Failed to create webworker rpc`);
|
|
2467
|
+
}
|
|
2468
|
+
};
|
|
2469
|
+
|
|
2470
|
+
const {
|
|
2471
|
+
registerSelectionProvider,
|
|
2472
|
+
executeSelectionProvider,
|
|
2473
|
+
reset: reset$2
|
|
2474
|
+
} = create$c({
|
|
2475
|
+
name: 'Selection',
|
|
2476
|
+
resultShape: {
|
|
2477
|
+
allowUndefined: true,
|
|
2478
|
+
type: Array$1,
|
|
2479
|
+
items: {
|
|
2480
|
+
type: 'number'
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
});
|
|
2484
|
+
|
|
2485
|
+
const state$5 = {
|
|
2486
|
+
providers: Object.create(null)
|
|
2487
|
+
};
|
|
2488
|
+
const registerSourceControlProvider = provider => {
|
|
2489
|
+
state$5.providers[provider.id] = provider;
|
|
2490
|
+
};
|
|
2491
|
+
const getFilesFromProvider = provider => {
|
|
2492
|
+
return provider.getChangedFiles();
|
|
2493
|
+
};
|
|
2494
|
+
const getChangedFiles = async providerId => {
|
|
2495
|
+
const provider = state$5.providers[providerId];
|
|
2496
|
+
if (!provider) {
|
|
2497
|
+
throw new Error('no source control provider found');
|
|
2498
|
+
}
|
|
2499
|
+
const changedFiles = await getFilesFromProvider(provider);
|
|
2500
|
+
const flattenedChangedFiles = changedFiles;
|
|
2501
|
+
return flattenedChangedFiles;
|
|
2502
|
+
};
|
|
2503
|
+
const getFileBefore = async (providerId, uri) => {
|
|
2504
|
+
string(providerId);
|
|
2505
|
+
string(uri);
|
|
2506
|
+
const provider = state$5.providers[providerId];
|
|
2507
|
+
if (!provider) {
|
|
2508
|
+
throw new Error('no source control provider found');
|
|
2509
|
+
}
|
|
2510
|
+
return provider.getFileBefore(uri);
|
|
2511
|
+
};
|
|
2512
|
+
const getGroupsFromProvider = async (provider, cwd) => {
|
|
2513
|
+
if (provider.getGroups) {
|
|
2514
|
+
return provider.getGroups(cwd);
|
|
2515
|
+
}
|
|
2516
|
+
if (provider.getChangedFiles) {
|
|
2517
|
+
const files = await provider.getChangedFiles();
|
|
2518
|
+
const groups = [{
|
|
2519
|
+
id: 'changes',
|
|
2520
|
+
label: 'Changes',
|
|
2521
|
+
items: files
|
|
2522
|
+
}];
|
|
2523
|
+
return groups;
|
|
2524
|
+
}
|
|
2525
|
+
throw new Error('source control provider is missing required function getGroups');
|
|
2526
|
+
};
|
|
2527
|
+
const getGroups = async (providerId, cwd) => {
|
|
2528
|
+
const provider = state$5.providers[providerId];
|
|
2529
|
+
if (!provider) {
|
|
2530
|
+
throw new Error('no source control provider found');
|
|
2531
|
+
}
|
|
2532
|
+
const groups = await getGroupsFromProvider(provider, cwd);
|
|
2533
|
+
return groups;
|
|
2534
|
+
};
|
|
2535
|
+
const acceptInput = async (providerId, value) => {
|
|
2536
|
+
const provider = state$5.providers[providerId];
|
|
2537
|
+
if (!provider) {
|
|
2538
|
+
throw new Error('no source control provider found');
|
|
2539
|
+
}
|
|
2540
|
+
await provider.acceptInput(value);
|
|
2541
|
+
};
|
|
2542
|
+
const add = async path => {
|
|
2543
|
+
const provider = Object.values(state$5.providers)[0];
|
|
2544
|
+
if (!provider) {
|
|
2545
|
+
return;
|
|
2546
|
+
}
|
|
2547
|
+
// @ts-ignore
|
|
2548
|
+
await provider.add(path);
|
|
2549
|
+
};
|
|
2550
|
+
const discard = async path => {
|
|
2551
|
+
const provider = Object.values(state$5.providers)[0];
|
|
2552
|
+
if (!provider) {
|
|
2553
|
+
return;
|
|
2554
|
+
}
|
|
2555
|
+
// @ts-ignore
|
|
2556
|
+
await provider.discard(path);
|
|
2557
|
+
};
|
|
2558
|
+
const getEnabledProviderIds = async (scheme, root) => {
|
|
2559
|
+
string(scheme);
|
|
2560
|
+
string(root);
|
|
2561
|
+
const providers = Object.values(state$5.providers);
|
|
2562
|
+
const enabledIds = [];
|
|
2563
|
+
for (const provider of providers) {
|
|
2564
|
+
// @ts-ignore
|
|
2565
|
+
if (typeof provider.isActive !== 'function') {
|
|
2566
|
+
continue;
|
|
2567
|
+
}
|
|
2568
|
+
// @ts-ignore
|
|
2569
|
+
const isActive = await provider.isActive(scheme, root);
|
|
2570
|
+
if (isActive) {
|
|
2571
|
+
// @ts-ignore
|
|
2572
|
+
enabledIds.push(provider.id);
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
return enabledIds;
|
|
2576
|
+
};
|
|
2577
|
+
|
|
2578
|
+
const {
|
|
2579
|
+
registerTabCompletionProvider,
|
|
2580
|
+
executeTabCompletionProvider,
|
|
2581
|
+
reset: reset$1
|
|
2582
|
+
} = create$c({
|
|
2583
|
+
name: 'TabCompletion',
|
|
2584
|
+
resultShape: {
|
|
2585
|
+
type: Object$1,
|
|
2586
|
+
allowUndefined: true
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
|
|
2590
|
+
const state$4 = {
|
|
2591
|
+
textSearchProviders: Object.create(null)
|
|
2592
|
+
};
|
|
2593
|
+
const registerTextSearchProvider = textSearchProvider => {
|
|
2594
|
+
try {
|
|
2595
|
+
if (!textSearchProvider) {
|
|
2596
|
+
throw new Error('textSearchProvider is not defined');
|
|
2597
|
+
}
|
|
2598
|
+
if (!textSearchProvider.scheme) {
|
|
2599
|
+
throw new Error('textSearchProvider is missing scheme');
|
|
2600
|
+
}
|
|
2601
|
+
state$4.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
|
|
2602
|
+
} catch (error) {
|
|
2603
|
+
throw new VError(error, 'Failed to register text search provider');
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
const executeTextSearchProvider = async (scheme, query) => {
|
|
2607
|
+
try {
|
|
2608
|
+
const textSearchProvider = state$4.textSearchProviders[scheme];
|
|
2609
|
+
if (!textSearchProvider) {
|
|
2610
|
+
throw new Error(`No text search provider for ${scheme} found`);
|
|
2611
|
+
}
|
|
2612
|
+
const results = await textSearchProvider.provideTextSearchResults(query);
|
|
2613
|
+
return results;
|
|
2614
|
+
} catch (error) {
|
|
2615
|
+
throw new VError(error, 'Failed to execute text search provider');
|
|
2616
|
+
}
|
|
2617
|
+
};
|
|
2618
|
+
|
|
2619
|
+
const {
|
|
2620
|
+
registerTypeDefinitionProvider,
|
|
2621
|
+
executeTypeDefinitionProvider,
|
|
2622
|
+
reset
|
|
2623
|
+
} = create$c({
|
|
2624
|
+
name: 'TypeDefinition',
|
|
2625
|
+
resultShape: {
|
|
2626
|
+
allowUndefined: true,
|
|
2627
|
+
type: Object$1,
|
|
2628
|
+
properties: {
|
|
2629
|
+
uri: {
|
|
2630
|
+
type: String$1
|
|
2631
|
+
},
|
|
2632
|
+
startOffset: {
|
|
2633
|
+
type: Number
|
|
2634
|
+
},
|
|
2635
|
+
endOffset: {
|
|
2636
|
+
type: Number
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
});
|
|
2641
|
+
|
|
2642
|
+
const RE_PROTOCOL = /^([a-z\-]+):\/\//;
|
|
2643
|
+
const getProtocol = uri => {
|
|
2644
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
2645
|
+
if (protocolMatch) {
|
|
2646
|
+
return protocolMatch[1];
|
|
2647
|
+
}
|
|
2648
|
+
return '';
|
|
2649
|
+
};
|
|
2650
|
+
|
|
2651
|
+
const commands = Object.create(null);
|
|
2652
|
+
const register = commandMap => {
|
|
2653
|
+
Object.assign(commands, commandMap);
|
|
2654
|
+
};
|
|
2655
|
+
const getCommand = key => {
|
|
2656
|
+
return commands[key];
|
|
2657
|
+
};
|
|
2658
|
+
const execute = (command, ...args) => {
|
|
2659
|
+
const fn = getCommand(command);
|
|
2660
|
+
if (!fn) {
|
|
2661
|
+
throw new Error(`command not found ${command}`);
|
|
2662
|
+
}
|
|
2663
|
+
return fn(...args);
|
|
2664
|
+
};
|
|
2665
|
+
|
|
2666
|
+
const requiresSocket$1 = () => {
|
|
2667
|
+
return false;
|
|
2668
|
+
};
|
|
2669
|
+
const preparePrettyError$1 = error => {
|
|
2670
|
+
return error;
|
|
2671
|
+
};
|
|
2672
|
+
const logError$1 = error => {
|
|
2673
|
+
// handled by renderer worker
|
|
2674
|
+
};
|
|
2675
|
+
const handleMessage$1 = event => {
|
|
2676
|
+
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError$1, logError$1, requiresSocket$1);
|
|
2677
|
+
};
|
|
2678
|
+
|
|
2679
|
+
const handleIpc$1 = ipc => {
|
|
2680
|
+
ipc.addEventListener('message', handleMessage$1);
|
|
2681
|
+
};
|
|
2682
|
+
|
|
2683
|
+
const createWebViewIpc = async webView => {
|
|
2684
|
+
const {
|
|
2685
|
+
uid,
|
|
2686
|
+
origin
|
|
2687
|
+
} = webView;
|
|
2688
|
+
const {
|
|
2689
|
+
port1,
|
|
2690
|
+
port2
|
|
2691
|
+
} = getPortTuple();
|
|
2692
|
+
const {
|
|
2693
|
+
resolve,
|
|
2694
|
+
promise
|
|
2695
|
+
} = Promise.withResolvers();
|
|
2696
|
+
port2.onmessage = resolve;
|
|
2697
|
+
const portType = 'test';
|
|
2698
|
+
await invokeAndTransfer$1('WebView.setPort', uid, port1, origin, portType);
|
|
2699
|
+
const event = await promise;
|
|
2700
|
+
// @ts-ignore
|
|
2701
|
+
if (event.data !== 'ready') {
|
|
2702
|
+
throw new Error('unexpected first message');
|
|
2703
|
+
}
|
|
2704
|
+
const ipc = {
|
|
2705
|
+
addEventListener(type, listener) {
|
|
2706
|
+
const that = this;
|
|
2707
|
+
const wrapped = event => {
|
|
2708
|
+
const actualEvent = {
|
|
2709
|
+
target: that,
|
|
2710
|
+
data: event.data
|
|
2711
|
+
};
|
|
2712
|
+
listener(actualEvent);
|
|
2713
|
+
};
|
|
2714
|
+
port2.addEventListener(type, wrapped);
|
|
2715
|
+
},
|
|
2716
|
+
dispose() {},
|
|
2717
|
+
send(message) {
|
|
2718
|
+
port2.postMessage(message);
|
|
2719
|
+
}
|
|
2720
|
+
};
|
|
2721
|
+
// TODO maybe don't send a message port only to get object url?
|
|
2722
|
+
// TODO dispose ipc to avoid memory leak
|
|
2723
|
+
handleIpc$1(ipc);
|
|
2724
|
+
return ipc;
|
|
2725
|
+
};
|
|
2726
|
+
|
|
2727
|
+
const webViews = Object.create(null);
|
|
2728
|
+
const webViewProviders = Object.create(null);
|
|
2729
|
+
const getProvider = providerId => {
|
|
2730
|
+
return webViewProviders[providerId];
|
|
2731
|
+
};
|
|
2732
|
+
const setProvider = (providerId, provider) => {
|
|
2733
|
+
webViewProviders[providerId] = provider;
|
|
2734
|
+
};
|
|
2735
|
+
const getWebView = id => {
|
|
2736
|
+
return webViews[id];
|
|
2737
|
+
};
|
|
2738
|
+
const setWebView = (id, webView) => {
|
|
2739
|
+
webViews[id] = webView;
|
|
2740
|
+
};
|
|
2741
|
+
const getWebViews = () => {
|
|
2742
|
+
return webViews;
|
|
2743
|
+
};
|
|
2744
|
+
|
|
2745
|
+
// TODO if webViewId is provided,
|
|
2746
|
+
// 1. read file as blob
|
|
2747
|
+
// 2. send blob to webview
|
|
2748
|
+
// 3. create objecturl in webview
|
|
2749
|
+
// 4. send back objecturl to extension host worker
|
|
2750
|
+
// 5. provide objectUrl to extension
|
|
2751
|
+
|
|
2752
|
+
const getRemoteUrlForWebView = async (uri, options = {}) => {
|
|
2753
|
+
const webView = getWebView(options.webViewId);
|
|
2754
|
+
if (!webView) {
|
|
2755
|
+
throw new Error(`webview ${options.webViewId} not found`);
|
|
2756
|
+
}
|
|
2757
|
+
const [ipc, blob] = await Promise.all([createWebViewIpc(webView), invoke$1('FileSystem.getBlob', uri)]);
|
|
2758
|
+
const objectUrl = await invoke(ipc, 'createObjectUrl', blob);
|
|
2759
|
+
return objectUrl;
|
|
2760
|
+
};
|
|
2761
|
+
|
|
2762
|
+
const getRemoteUrl = async (uri, options = {}) => {
|
|
2763
|
+
// TODO uri should always have protocol
|
|
2764
|
+
// then ask file system provider for remote url, for example disk file system provider or html file system provider
|
|
2765
|
+
const protocol = getProtocol(uri);
|
|
2766
|
+
if (platform === Remote && !protocol) {
|
|
2767
|
+
if (uri.startsWith('/')) {
|
|
2768
|
+
return `/remote${uri}`;
|
|
2769
|
+
}
|
|
2770
|
+
return `/remote/${uri}`;
|
|
2771
|
+
}
|
|
2772
|
+
if (platform === Electron && !protocol) {
|
|
2773
|
+
if (uri.startsWith('/')) {
|
|
2774
|
+
return `/remote${uri}`;
|
|
2775
|
+
}
|
|
2776
|
+
return `/remote/${uri}`;
|
|
2777
|
+
}
|
|
2778
|
+
if (options.webViewId) {
|
|
2779
|
+
return getRemoteUrlForWebView(uri, options);
|
|
2780
|
+
}
|
|
2781
|
+
if (uri.startsWith('html://')) {
|
|
2782
|
+
const url = await invoke$1('Blob.getSrc', uri);
|
|
2783
|
+
return url;
|
|
2784
|
+
}
|
|
2785
|
+
throw new Error(`unsupported platform for remote url`);
|
|
2786
|
+
};
|
|
2787
|
+
|
|
2788
|
+
const waitForFirstMessage = async port => {
|
|
2789
|
+
const {
|
|
2790
|
+
resolve,
|
|
2791
|
+
promise
|
|
2792
|
+
} = Promise.withResolvers();
|
|
2793
|
+
port.onmessage = resolve;
|
|
2794
|
+
const firstMessage = await promise;
|
|
2795
|
+
return firstMessage;
|
|
2796
|
+
};
|
|
2797
|
+
|
|
2798
|
+
// TODO pass uuid to allow having multiple webviews open at the same time
|
|
2799
|
+
const createWebView = async (providerId, port, uri, uid, origin, webView) => {
|
|
2800
|
+
const provider = getProvider(providerId);
|
|
2801
|
+
if (!provider) {
|
|
2802
|
+
throw new Error(`webview provider ${providerId} not found`);
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
// TODO cancel promise when webview is disposed before sending message
|
|
2806
|
+
// TODO handle case when webview doesn't send ready message
|
|
2807
|
+
// TODO handle error
|
|
2808
|
+
await waitForFirstMessage(port);
|
|
2809
|
+
|
|
2810
|
+
// TODO use ipc module
|
|
2811
|
+
const handlePortMessage = async event => {
|
|
2812
|
+
const {
|
|
2813
|
+
data,
|
|
2814
|
+
target
|
|
2815
|
+
} = event;
|
|
2816
|
+
const {
|
|
2817
|
+
method,
|
|
2818
|
+
params,
|
|
2819
|
+
id
|
|
2820
|
+
} = data;
|
|
2821
|
+
if (id && !method) {
|
|
2822
|
+
resolve(id, data);
|
|
2823
|
+
return;
|
|
2824
|
+
}
|
|
2825
|
+
if (provider && provider.commands && provider.commands[method]) {
|
|
2826
|
+
const fn = provider.commands[method];
|
|
2827
|
+
const result = await fn(...params);
|
|
2828
|
+
if (id && method) {
|
|
2829
|
+
target.postMessage({
|
|
2830
|
+
jsonrpc: '2.0',
|
|
2831
|
+
id,
|
|
2832
|
+
result
|
|
2833
|
+
});
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
port.onmessage = handlePortMessage;
|
|
2838
|
+
const rpc = {
|
|
2839
|
+
uri,
|
|
2840
|
+
provider,
|
|
2841
|
+
uid,
|
|
2842
|
+
origin,
|
|
2843
|
+
webView,
|
|
2844
|
+
async invoke(method, ...params) {
|
|
2845
|
+
const {
|
|
2846
|
+
id,
|
|
2847
|
+
promise
|
|
2848
|
+
} = registerPromise();
|
|
2849
|
+
port.postMessage({
|
|
2850
|
+
jsonrpc: '2.0',
|
|
2851
|
+
id,
|
|
2852
|
+
method,
|
|
2853
|
+
params
|
|
2854
|
+
});
|
|
2855
|
+
const result = await promise;
|
|
2856
|
+
if (result.error) {
|
|
2857
|
+
throw new Error(`Error: ${result.error.message}`);
|
|
2858
|
+
}
|
|
2859
|
+
return result.result;
|
|
2860
|
+
}
|
|
2861
|
+
};
|
|
2862
|
+
// TODO allow creating multiple webviews per provider
|
|
2863
|
+
setWebView(providerId, rpc);
|
|
2864
|
+
};
|
|
2865
|
+
const disposeWebView = id => {
|
|
2866
|
+
// TODO race condition
|
|
2867
|
+
// const webView=webViews[id]
|
|
2868
|
+
};
|
|
2869
|
+
const registerWebViewProvider = provider => {
|
|
2870
|
+
setProvider(provider.id, provider);
|
|
2871
|
+
};
|
|
2872
|
+
const getWebViewInfo = providerId => {
|
|
2873
|
+
const webView = getWebView(providerId);
|
|
2874
|
+
return {
|
|
2875
|
+
uid: webView.uid,
|
|
2876
|
+
origin: webView.origin,
|
|
2877
|
+
uri: webView.uri
|
|
2878
|
+
};
|
|
2879
|
+
};
|
|
2880
|
+
|
|
2881
|
+
const createWorker = async ({
|
|
2882
|
+
method,
|
|
2883
|
+
url,
|
|
2884
|
+
name
|
|
2885
|
+
}) => {
|
|
2886
|
+
string(method);
|
|
2887
|
+
string(url);
|
|
2888
|
+
string(name);
|
|
2889
|
+
const ipc = create$6({
|
|
2890
|
+
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
2891
|
+
url,
|
|
2892
|
+
name
|
|
2893
|
+
});
|
|
2894
|
+
return ipc;
|
|
2895
|
+
};
|
|
2896
|
+
|
|
2897
|
+
const state$3 = {
|
|
2898
|
+
workspacePath: ''
|
|
2899
|
+
};
|
|
2900
|
+
const setWorkspacePath = path => {
|
|
2901
|
+
state$3.workspacePath = path;
|
|
2902
|
+
};
|
|
2903
|
+
const getWorkspaceFolder = path => {
|
|
2904
|
+
return state$3.workspacePath;
|
|
2905
|
+
};
|
|
2906
|
+
|
|
2907
|
+
class FormattingError extends Error {
|
|
2908
|
+
constructor(message, codeFrame) {
|
|
2909
|
+
super(message);
|
|
2910
|
+
// @ts-ignore
|
|
2911
|
+
this.codeFrame = codeFrame;
|
|
2912
|
+
this.name = 'FormattingError';
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
const File$2 = 1;
|
|
2917
|
+
const Match = 2;
|
|
2918
|
+
|
|
2919
|
+
const TextSearchResultType = {
|
|
2920
|
+
__proto__: null,
|
|
2921
|
+
File: File$2,
|
|
2922
|
+
Match
|
|
2923
|
+
};
|
|
2924
|
+
|
|
2925
|
+
const api = {
|
|
2926
|
+
// Ajax
|
|
2927
|
+
getJson: getJson$1,
|
|
2928
|
+
// Brace Completion
|
|
2929
|
+
registerBraceCompletionProvider: registerBraceCompletionProvider,
|
|
2930
|
+
executeBraceCompletionProvider: executeBraceCompletionProvider,
|
|
2931
|
+
// Closing Tag
|
|
2932
|
+
registerClosingTagProvider: registerClosingTagProvider,
|
|
2933
|
+
executeClosingTagProvider: executeClosingTagProvider,
|
|
2934
|
+
// Code Action
|
|
2935
|
+
registerCodeActionsProvider: registerCodeActionProvider,
|
|
2936
|
+
// Command
|
|
2937
|
+
registerCommand: registerCommand,
|
|
2938
|
+
executeCommand: executeCommand,
|
|
2939
|
+
// Completion
|
|
2253
2940
|
registerCompletionProvider: registerCompletionProvider,
|
|
2254
2941
|
executeCompletionProvider: executeCompletionProvider,
|
|
2255
2942
|
EditorCompletionType,
|
|
@@ -2319,479 +3006,103 @@ const api = {
|
|
|
2319
3006
|
TextSearchResultType,
|
|
2320
3007
|
// Type Definition
|
|
2321
3008
|
registerTypeDefinitionProvider: registerTypeDefinitionProvider,
|
|
2322
|
-
executeTypeDefinitionProvider: executeTypeDefinitionProvider,
|
|
2323
|
-
// Url
|
|
2324
|
-
getRemoteUrl: getRemoteUrl,
|
|
2325
|
-
// Webview
|
|
2326
|
-
registerWebViewProvider: registerWebViewProvider,
|
|
2327
|
-
// Worker
|
|
2328
|
-
createWorker: createWorker,
|
|
2329
|
-
// Workspace
|
|
2330
|
-
getWorkspaceFolder: getWorkspaceFolder
|
|
2331
|
-
};
|
|
2332
|
-
|
|
2333
|
-
const handleError = async error => {
|
|
2334
|
-
console.error(error);
|
|
2335
|
-
};
|
|
2336
|
-
|
|
2337
|
-
/**
|
|
2338
|
-
* @param {ErrorEvent} event
|
|
2339
|
-
*/
|
|
2340
|
-
const handleUnhandledError = async event => {
|
|
2341
|
-
try {
|
|
2342
|
-
event.preventDefault();
|
|
2343
|
-
await handleError(event.error);
|
|
2344
|
-
} catch {
|
|
2345
|
-
console.error(event.error);
|
|
2346
|
-
}
|
|
2347
|
-
};
|
|
2348
|
-
|
|
2349
|
-
const processName = `extension host worker`;
|
|
2350
|
-
|
|
2351
|
-
const getOutput = error => {
|
|
2352
|
-
const errorMessage = error && error.message ? error.message : String(error);
|
|
2353
|
-
const prefix = `[${processName}] Unhandled Rejection: ${errorMessage}`;
|
|
2354
|
-
if (error && error.stack) {
|
|
2355
|
-
return `${prefix}\n${error.stack}`;
|
|
2356
|
-
}
|
|
2357
|
-
return prefix;
|
|
2358
|
-
};
|
|
2359
|
-
const handleUnhandledRejection = event => {
|
|
2360
|
-
if (event instanceof PromiseRejectionEvent) {
|
|
2361
|
-
event.preventDefault();
|
|
2362
|
-
const output = getOutput(event.reason);
|
|
2363
|
-
console.error(output);
|
|
2364
|
-
return;
|
|
2365
|
-
}
|
|
2366
|
-
const output = getOutput(event);
|
|
2367
|
-
console.error(output);
|
|
2368
|
-
};
|
|
2369
|
-
|
|
2370
|
-
const state$2 = {
|
|
2371
|
-
/**
|
|
2372
|
-
* @type {any[]}
|
|
2373
|
-
*/
|
|
2374
|
-
errors: []
|
|
2375
|
-
};
|
|
2376
|
-
const addError = error => {
|
|
2377
|
-
// @ts-ignore
|
|
2378
|
-
state$2.errors.push(error);
|
|
2379
|
-
};
|
|
2380
|
-
const hasRecentErrors = () => {
|
|
2381
|
-
return state$2.errors.length > 0;
|
|
2382
|
-
};
|
|
2383
|
-
const getRecentError = () => {
|
|
2384
|
-
};
|
|
2385
|
-
|
|
2386
|
-
const handleContentSecurityPolicyViolation = event => {
|
|
2387
|
-
const {
|
|
2388
|
-
violatedDirective,
|
|
2389
|
-
sourceFile,
|
|
2390
|
-
lineNumber,
|
|
2391
|
-
columnNumber
|
|
2392
|
-
} = event;
|
|
2393
|
-
addError({
|
|
2394
|
-
violatedDirective,
|
|
2395
|
-
sourceFile,
|
|
2396
|
-
lineNumber,
|
|
2397
|
-
columnNumber
|
|
2398
|
-
});
|
|
2399
|
-
};
|
|
2400
|
-
|
|
2401
|
-
const setStackTraceLimit = (errorConstructor, value) => {
|
|
2402
|
-
if (errorConstructor.stackTraceLimit && errorConstructor.stackTraceLimit < value) {
|
|
2403
|
-
errorConstructor.stackTraceLimit = value;
|
|
2404
|
-
}
|
|
2405
|
-
};
|
|
2406
|
-
|
|
2407
|
-
const setup = ({
|
|
2408
|
-
global,
|
|
2409
|
-
errorConstructor
|
|
2410
|
-
}) => {
|
|
2411
|
-
setStackTraceLimit(errorConstructor, 20);
|
|
2412
|
-
global.onerror ||= handleUnhandledError;
|
|
2413
|
-
global.onunhandledrejection ||= handleUnhandledRejection;
|
|
2414
|
-
if ('SecurityPolicyViolationEvent' in self) {
|
|
2415
|
-
global.addEventListener('securitypolicyviolation', handleContentSecurityPolicyViolation);
|
|
2416
|
-
}
|
|
2417
|
-
// @ts-ignore
|
|
2418
|
-
global.vscode = api;
|
|
2419
|
-
};
|
|
2420
|
-
|
|
2421
|
-
const walkValue = (value, transferrables, isTransferrable) => {
|
|
2422
|
-
if (!value) {
|
|
2423
|
-
return;
|
|
2424
|
-
}
|
|
2425
|
-
if (isTransferrable(value)) {
|
|
2426
|
-
transferrables.push(value);
|
|
2427
|
-
return;
|
|
2428
|
-
}
|
|
2429
|
-
if (Array.isArray(value)) {
|
|
2430
|
-
for (const item of value) {
|
|
2431
|
-
walkValue(item, transferrables, isTransferrable);
|
|
2432
|
-
}
|
|
2433
|
-
return;
|
|
2434
|
-
}
|
|
2435
|
-
if (typeof value === 'object') {
|
|
2436
|
-
for (const property of Object.values(value)) {
|
|
2437
|
-
walkValue(property, transferrables, isTransferrable);
|
|
2438
|
-
}
|
|
2439
|
-
return;
|
|
2440
|
-
}
|
|
2441
|
-
};
|
|
2442
|
-
const isMessagePort = value => {
|
|
2443
|
-
return value && value instanceof MessagePort;
|
|
2444
|
-
};
|
|
2445
|
-
const isMessagePortMain = value => {
|
|
2446
|
-
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
2447
|
-
};
|
|
2448
|
-
const isOffscreenCanvas = value => {
|
|
2449
|
-
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
2450
|
-
};
|
|
2451
|
-
const isInstanceOf = (value, constructorName) => {
|
|
2452
|
-
return value?.constructor?.name === constructorName;
|
|
2453
|
-
};
|
|
2454
|
-
const isSocket = value => {
|
|
2455
|
-
return isInstanceOf(value, 'Socket');
|
|
2456
|
-
};
|
|
2457
|
-
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
2458
|
-
const isTransferrable = value => {
|
|
2459
|
-
for (const fn of transferrables) {
|
|
2460
|
-
if (fn(value)) {
|
|
2461
|
-
return true;
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
return false;
|
|
2465
|
-
};
|
|
2466
|
-
const getTransferrables = value => {
|
|
2467
|
-
const transferrables = [];
|
|
2468
|
-
walkValue(value, transferrables, isTransferrable);
|
|
2469
|
-
return transferrables;
|
|
2470
|
-
};
|
|
2471
|
-
const attachEvents = that => {
|
|
2472
|
-
const handleMessage = (...args) => {
|
|
2473
|
-
const data = that.getData(...args);
|
|
2474
|
-
that.dispatchEvent(new MessageEvent('message', {
|
|
2475
|
-
data
|
|
2476
|
-
}));
|
|
2477
|
-
};
|
|
2478
|
-
that.onMessage(handleMessage);
|
|
2479
|
-
const handleClose = event => {
|
|
2480
|
-
that.dispatchEvent(new Event('close'));
|
|
2481
|
-
};
|
|
2482
|
-
that.onClose(handleClose);
|
|
2483
|
-
};
|
|
2484
|
-
class Ipc extends EventTarget {
|
|
2485
|
-
constructor(rawIpc) {
|
|
2486
|
-
super();
|
|
2487
|
-
this._rawIpc = rawIpc;
|
|
2488
|
-
attachEvents(this);
|
|
2489
|
-
}
|
|
2490
|
-
}
|
|
2491
|
-
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
2492
|
-
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
2493
|
-
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
2494
|
-
const NewLine = '\n';
|
|
2495
|
-
const joinLines = lines => {
|
|
2496
|
-
return lines.join(NewLine);
|
|
2497
|
-
};
|
|
2498
|
-
const splitLines$1 = lines => {
|
|
2499
|
-
return lines.split(NewLine);
|
|
2500
|
-
};
|
|
2501
|
-
const isModuleNotFoundMessage = line => {
|
|
2502
|
-
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
2503
|
-
};
|
|
2504
|
-
const getModuleNotFoundError = stderr => {
|
|
2505
|
-
const lines = splitLines$1(stderr);
|
|
2506
|
-
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
2507
|
-
const message = lines[messageIndex];
|
|
2508
|
-
return {
|
|
2509
|
-
message,
|
|
2510
|
-
code: ERR_MODULE_NOT_FOUND
|
|
2511
|
-
};
|
|
2512
|
-
};
|
|
2513
|
-
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
2514
|
-
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
2515
|
-
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
2516
|
-
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
2517
|
-
const RE_AT = /^\s+at/;
|
|
2518
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
2519
|
-
const isUnhelpfulNativeModuleError = stderr => {
|
|
2520
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
2521
|
-
};
|
|
2522
|
-
const isMessageCodeBlockStartIndex = line => {
|
|
2523
|
-
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
2524
|
-
};
|
|
2525
|
-
const isMessageCodeBlockEndIndex = line => {
|
|
2526
|
-
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
2527
|
-
};
|
|
2528
|
-
const getMessageCodeBlock = stderr => {
|
|
2529
|
-
const lines = splitLines$1(stderr);
|
|
2530
|
-
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
2531
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
2532
|
-
const relevantLines = lines.slice(startIndex, endIndex);
|
|
2533
|
-
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
2534
|
-
return relevantMessage;
|
|
2535
|
-
};
|
|
2536
|
-
const getNativeModuleErrorMessage = stderr => {
|
|
2537
|
-
const message = getMessageCodeBlock(stderr);
|
|
2538
|
-
return {
|
|
2539
|
-
message: `Incompatible native node module: ${message}`,
|
|
2540
|
-
code: E_INCOMPATIBLE_NATIVE_MODULE
|
|
2541
|
-
};
|
|
2542
|
-
};
|
|
2543
|
-
const isModulesSyntaxError = stderr => {
|
|
2544
|
-
if (!stderr) {
|
|
2545
|
-
return false;
|
|
2546
|
-
}
|
|
2547
|
-
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
2548
|
-
};
|
|
2549
|
-
const getModuleSyntaxError = () => {
|
|
2550
|
-
return {
|
|
2551
|
-
message: `ES Modules are not supported in electron`,
|
|
2552
|
-
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
2553
|
-
};
|
|
2554
|
-
};
|
|
2555
|
-
const isModuleNotFoundError = stderr => {
|
|
2556
|
-
if (!stderr) {
|
|
2557
|
-
return false;
|
|
2558
|
-
}
|
|
2559
|
-
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
2560
|
-
};
|
|
2561
|
-
const isNormalStackLine = line => {
|
|
2562
|
-
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
3009
|
+
executeTypeDefinitionProvider: executeTypeDefinitionProvider,
|
|
3010
|
+
// Url
|
|
3011
|
+
getRemoteUrl: getRemoteUrl,
|
|
3012
|
+
// Webview
|
|
3013
|
+
registerWebViewProvider: registerWebViewProvider,
|
|
3014
|
+
// Worker
|
|
3015
|
+
createWorker: createWorker,
|
|
3016
|
+
// Workspace
|
|
3017
|
+
getWorkspaceFolder: getWorkspaceFolder
|
|
2563
3018
|
};
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
return {
|
|
2568
|
-
actualMessage: joinLines(lines),
|
|
2569
|
-
rest: []
|
|
2570
|
-
};
|
|
2571
|
-
}
|
|
2572
|
-
let lastIndex = index - 1;
|
|
2573
|
-
while (++lastIndex < lines.length) {
|
|
2574
|
-
if (!isNormalStackLine(lines[lastIndex])) {
|
|
2575
|
-
break;
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
return {
|
|
2579
|
-
actualMessage: lines[index - 1],
|
|
2580
|
-
rest: lines.slice(index, lastIndex)
|
|
2581
|
-
};
|
|
3019
|
+
|
|
3020
|
+
const handleError = async error => {
|
|
3021
|
+
console.error(error);
|
|
2582
3022
|
};
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
3023
|
+
|
|
3024
|
+
/**
|
|
3025
|
+
* @param {ErrorEvent} event
|
|
3026
|
+
*/
|
|
3027
|
+
const handleUnhandledError = async event => {
|
|
3028
|
+
try {
|
|
3029
|
+
event.preventDefault();
|
|
3030
|
+
await handleError(event.error);
|
|
3031
|
+
} catch {
|
|
3032
|
+
console.error(event.error);
|
|
2592
3033
|
}
|
|
2593
|
-
const lines = splitLines$1(stderr);
|
|
2594
|
-
const {
|
|
2595
|
-
actualMessage,
|
|
2596
|
-
rest
|
|
2597
|
-
} = getDetails(lines);
|
|
2598
|
-
return {
|
|
2599
|
-
message: `${actualMessage}`,
|
|
2600
|
-
code: '',
|
|
2601
|
-
stack: rest
|
|
2602
|
-
};
|
|
2603
3034
|
};
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
stack
|
|
2613
|
-
} = getHelpfulChildProcessError(stdout, stderr);
|
|
2614
|
-
const cause = new Error(message);
|
|
2615
|
-
// @ts-ignore
|
|
2616
|
-
cause.code = code;
|
|
2617
|
-
cause.stack = stack;
|
|
2618
|
-
super(cause, betterMessage);
|
|
2619
|
-
} else {
|
|
2620
|
-
super(betterMessage);
|
|
2621
|
-
}
|
|
2622
|
-
// @ts-ignore
|
|
2623
|
-
this.name = 'IpcError';
|
|
2624
|
-
// @ts-ignore
|
|
2625
|
-
this.stdout = stdout;
|
|
2626
|
-
// @ts-ignore
|
|
2627
|
-
this.stderr = stderr;
|
|
3035
|
+
|
|
3036
|
+
const processName = `extension host worker`;
|
|
3037
|
+
|
|
3038
|
+
const getOutput = error => {
|
|
3039
|
+
const errorMessage = error && error.message ? error.message : String(error);
|
|
3040
|
+
const prefix = `[${processName}] Unhandled Rejection: ${errorMessage}`;
|
|
3041
|
+
if (error && error.stack) {
|
|
3042
|
+
return `${prefix}\n${error.stack}`;
|
|
2628
3043
|
}
|
|
3044
|
+
return prefix;
|
|
2629
3045
|
};
|
|
2630
|
-
const
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
}) => {
|
|
2637
|
-
return port;
|
|
2638
|
-
};
|
|
2639
|
-
const signal$8 = port => {
|
|
2640
|
-
port.postMessage(readyMessage);
|
|
2641
|
-
};
|
|
2642
|
-
class IpcChildWithMessagePort extends Ipc {
|
|
2643
|
-
constructor(port) {
|
|
2644
|
-
super(port);
|
|
2645
|
-
}
|
|
2646
|
-
getData(event) {
|
|
2647
|
-
return getData$2(event);
|
|
2648
|
-
}
|
|
2649
|
-
send(message) {
|
|
2650
|
-
this._rawIpc.postMessage(message);
|
|
2651
|
-
}
|
|
2652
|
-
sendAndTransfer(message) {
|
|
2653
|
-
const transfer = getTransferrables(message);
|
|
2654
|
-
this._rawIpc.postMessage(message, transfer);
|
|
2655
|
-
}
|
|
2656
|
-
dispose() {
|
|
2657
|
-
// ignore
|
|
2658
|
-
}
|
|
2659
|
-
onClose(callback) {
|
|
2660
|
-
// ignore
|
|
2661
|
-
}
|
|
2662
|
-
onMessage(callback) {
|
|
2663
|
-
this._rawIpc.addEventListener('message', callback);
|
|
2664
|
-
this._rawIpc.start();
|
|
3046
|
+
const handleUnhandledRejection = event => {
|
|
3047
|
+
if (event instanceof PromiseRejectionEvent) {
|
|
3048
|
+
event.preventDefault();
|
|
3049
|
+
const output = getOutput(event.reason);
|
|
3050
|
+
console.error(output);
|
|
3051
|
+
return;
|
|
2665
3052
|
}
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
return new IpcChildWithMessagePort(port);
|
|
3053
|
+
const output = getOutput(event);
|
|
3054
|
+
console.error(output);
|
|
2669
3055
|
};
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
3056
|
+
|
|
3057
|
+
const state$2 = {
|
|
3058
|
+
/**
|
|
3059
|
+
* @type {any[]}
|
|
3060
|
+
*/
|
|
3061
|
+
errors: []
|
|
2675
3062
|
};
|
|
2676
|
-
const
|
|
3063
|
+
const addError = error => {
|
|
2677
3064
|
// @ts-ignore
|
|
2678
|
-
|
|
2679
|
-
throw new TypeError('module is not in web worker scope');
|
|
2680
|
-
}
|
|
2681
|
-
return globalThis;
|
|
2682
|
-
};
|
|
2683
|
-
const signal$7 = global => {
|
|
2684
|
-
global.postMessage(readyMessage);
|
|
2685
|
-
};
|
|
2686
|
-
class IpcChildWithModuleWorker extends Ipc {
|
|
2687
|
-
getData(event) {
|
|
2688
|
-
return getData$2(event);
|
|
2689
|
-
}
|
|
2690
|
-
send(message) {
|
|
2691
|
-
// @ts-ignore
|
|
2692
|
-
this._rawIpc.postMessage(message);
|
|
2693
|
-
}
|
|
2694
|
-
sendAndTransfer(message) {
|
|
2695
|
-
const transfer = getTransferrables(message);
|
|
2696
|
-
// @ts-ignore
|
|
2697
|
-
this._rawIpc.postMessage(message, transfer);
|
|
2698
|
-
}
|
|
2699
|
-
dispose() {
|
|
2700
|
-
// ignore
|
|
2701
|
-
}
|
|
2702
|
-
onClose(callback) {
|
|
2703
|
-
// ignore
|
|
2704
|
-
}
|
|
2705
|
-
onMessage(callback) {
|
|
2706
|
-
this._rawIpc.addEventListener('message', callback);
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
const wrap$e = global => {
|
|
2710
|
-
return new IpcChildWithModuleWorker(global);
|
|
3065
|
+
state$2.errors.push(error);
|
|
2711
3066
|
};
|
|
2712
|
-
const
|
|
2713
|
-
|
|
2714
|
-
listen: listen$7,
|
|
2715
|
-
signal: signal$7,
|
|
2716
|
-
wrap: wrap$e
|
|
3067
|
+
const hasRecentErrors = () => {
|
|
3068
|
+
return state$2.errors.length > 0;
|
|
2717
3069
|
};
|
|
2718
|
-
const
|
|
2719
|
-
let _resolve;
|
|
2720
|
-
const promise = new Promise(resolve => {
|
|
2721
|
-
_resolve = resolve;
|
|
2722
|
-
});
|
|
2723
|
-
return {
|
|
2724
|
-
resolve: _resolve,
|
|
2725
|
-
promise
|
|
2726
|
-
};
|
|
3070
|
+
const getRecentError = () => {
|
|
2727
3071
|
};
|
|
2728
|
-
|
|
3072
|
+
|
|
3073
|
+
const handleContentSecurityPolicyViolation = event => {
|
|
2729
3074
|
const {
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
3075
|
+
violatedDirective,
|
|
3076
|
+
sourceFile,
|
|
3077
|
+
lineNumber,
|
|
3078
|
+
columnNumber
|
|
3079
|
+
} = event;
|
|
3080
|
+
addError({
|
|
3081
|
+
violatedDirective,
|
|
3082
|
+
sourceFile,
|
|
3083
|
+
lineNumber,
|
|
3084
|
+
columnNumber
|
|
2735
3085
|
});
|
|
2736
|
-
const event = await promise;
|
|
2737
|
-
// @ts-ignore
|
|
2738
|
-
return event.data;
|
|
2739
|
-
};
|
|
2740
|
-
const listen$6 = async () => {
|
|
2741
|
-
const parentIpcRaw = listen$7();
|
|
2742
|
-
signal$7(parentIpcRaw);
|
|
2743
|
-
const parentIpc = wrap$e(parentIpcRaw);
|
|
2744
|
-
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
2745
|
-
if (firstMessage.method !== 'initialize') {
|
|
2746
|
-
throw new IpcError$1('unexpected first message');
|
|
2747
|
-
}
|
|
2748
|
-
const type = firstMessage.params[0];
|
|
2749
|
-
if (type === 'message-port') {
|
|
2750
|
-
parentIpc.send({
|
|
2751
|
-
jsonrpc: '2.0',
|
|
2752
|
-
id: firstMessage.id,
|
|
2753
|
-
result: null
|
|
2754
|
-
});
|
|
2755
|
-
parentIpc.dispose();
|
|
2756
|
-
const port = firstMessage.params[1];
|
|
2757
|
-
return port;
|
|
2758
|
-
}
|
|
2759
|
-
return globalThis;
|
|
2760
3086
|
};
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
getData(event) {
|
|
2766
|
-
return getData$2(event);
|
|
2767
|
-
}
|
|
2768
|
-
send(message) {
|
|
2769
|
-
this._rawIpc.postMessage(message);
|
|
2770
|
-
}
|
|
2771
|
-
sendAndTransfer(message) {
|
|
2772
|
-
const transfer = getTransferrables(message);
|
|
2773
|
-
this._rawIpc.postMessage(message, transfer);
|
|
2774
|
-
}
|
|
2775
|
-
dispose() {
|
|
2776
|
-
if (this._rawIpc.close) {
|
|
2777
|
-
this._rawIpc.close();
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2780
|
-
onClose(callback) {
|
|
2781
|
-
// ignore
|
|
2782
|
-
}
|
|
2783
|
-
onMessage(callback) {
|
|
2784
|
-
this._rawIpc.addEventListener('message', callback);
|
|
2785
|
-
this._rawIpc.start();
|
|
3087
|
+
|
|
3088
|
+
const setStackTraceLimit = (errorConstructor, value) => {
|
|
3089
|
+
if (errorConstructor.stackTraceLimit && errorConstructor.stackTraceLimit < value) {
|
|
3090
|
+
errorConstructor.stackTraceLimit = value;
|
|
2786
3091
|
}
|
|
2787
|
-
}
|
|
2788
|
-
const wrap$d = port => {
|
|
2789
|
-
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
2790
3092
|
};
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
3093
|
+
|
|
3094
|
+
const setup = ({
|
|
3095
|
+
global,
|
|
3096
|
+
errorConstructor
|
|
3097
|
+
}) => {
|
|
3098
|
+
setStackTraceLimit(errorConstructor, 20);
|
|
3099
|
+
global.onerror ||= handleUnhandledError;
|
|
3100
|
+
global.onunhandledrejection ||= handleUnhandledRejection;
|
|
3101
|
+
if ('SecurityPolicyViolationEvent' in self) {
|
|
3102
|
+
global.addEventListener('securitypolicyviolation', handleContentSecurityPolicyViolation);
|
|
3103
|
+
}
|
|
3104
|
+
// @ts-ignore
|
|
3105
|
+
global.vscode = api;
|
|
2795
3106
|
};
|
|
2796
3107
|
|
|
2797
3108
|
const createRpc = ipc => {
|
|
@@ -2811,18 +3122,18 @@ const createRpc = ipc => {
|
|
|
2811
3122
|
};
|
|
2812
3123
|
return rpc;
|
|
2813
3124
|
};
|
|
2814
|
-
const requiresSocket
|
|
3125
|
+
const requiresSocket = () => {
|
|
2815
3126
|
return false;
|
|
2816
3127
|
};
|
|
2817
|
-
const preparePrettyError
|
|
3128
|
+
const preparePrettyError = error => {
|
|
2818
3129
|
return error;
|
|
2819
3130
|
};
|
|
2820
|
-
const logError
|
|
3131
|
+
const logError = () => {
|
|
2821
3132
|
// handled by renderer worker
|
|
2822
3133
|
};
|
|
2823
3134
|
const handleMessage = event => {
|
|
2824
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket
|
|
2825
|
-
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError
|
|
3135
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
3136
|
+
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
2826
3137
|
};
|
|
2827
3138
|
const handleIpc = ipc => {
|
|
2828
3139
|
if ('addEventListener' in ipc) {
|
|
@@ -2840,7 +3151,7 @@ const listen$1 = async (module, options) => {
|
|
|
2840
3151
|
const ipc = module.wrap(rawIpc);
|
|
2841
3152
|
return ipc;
|
|
2842
3153
|
};
|
|
2843
|
-
const create$
|
|
3154
|
+
const create$1 = async ({
|
|
2844
3155
|
commandMap
|
|
2845
3156
|
}) => {
|
|
2846
3157
|
// TODO create a commandMap per rpc instance
|
|
@@ -2852,7 +3163,7 @@ const create$6 = async ({
|
|
|
2852
3163
|
};
|
|
2853
3164
|
const WebWorkerRpcClient = {
|
|
2854
3165
|
__proto__: null,
|
|
2855
|
-
create: create$
|
|
3166
|
+
create: create$1
|
|
2856
3167
|
};
|
|
2857
3168
|
|
|
2858
3169
|
const BraceCompletionExecuteBraceCompletionProvider = 'ExtensionHostBraceCompletion.executeBraceCompletionProvider';
|
|
@@ -2894,7 +3205,7 @@ const WorkspaceSetPath = 'Workspace.setWorkspacePath';
|
|
|
2894
3205
|
const SelectionExecuteSelectionProvider = 'ExtensionHostSelection.executeSelectionProvider';
|
|
2895
3206
|
const ConfigurationSetConfiguration = 'ExtensionHostConfiguration.setConfiguration';
|
|
2896
3207
|
|
|
2897
|
-
const create
|
|
3208
|
+
const create = () => {
|
|
2898
3209
|
return {
|
|
2899
3210
|
finished: false
|
|
2900
3211
|
};
|
|
@@ -3319,7 +3630,7 @@ const activate = async (extension, absolutePath) => {
|
|
|
3319
3630
|
string(absolutePath);
|
|
3320
3631
|
const module = await importScript(absolutePath);
|
|
3321
3632
|
handleRpcInfos(extension);
|
|
3322
|
-
const token = create
|
|
3633
|
+
const token = create();
|
|
3323
3634
|
try {
|
|
3324
3635
|
await Promise.race([module.activate(extension), rejectAfterTimeout(activationTimeout, token)]);
|
|
3325
3636
|
} catch (error) {
|
|
@@ -3417,8 +3728,7 @@ const MessagePort$1 = 1;
|
|
|
3417
3728
|
const ModuleWorker = 2;
|
|
3418
3729
|
const ModuleWorkerWithMessagePort = 4;
|
|
3419
3730
|
|
|
3420
|
-
|
|
3421
|
-
const getModule$1 = method => {
|
|
3731
|
+
const getModule = method => {
|
|
3422
3732
|
switch (method) {
|
|
3423
3733
|
case ModuleWorker:
|
|
3424
3734
|
return IpcChildWithModuleWorker$1;
|
|
@@ -3432,7 +3742,8 @@ const getModule$1 = method => {
|
|
|
3432
3742
|
};
|
|
3433
3743
|
|
|
3434
3744
|
const handleMessagePort = port => {
|
|
3435
|
-
const module = getModule
|
|
3745
|
+
const module = getModule(MessagePort$1);
|
|
3746
|
+
// @ts-ignore
|
|
3436
3747
|
const ipc = module.wrap(port);
|
|
3437
3748
|
handleIpc$1(ipc);
|
|
3438
3749
|
ipc.send('ready');
|
|
@@ -3459,7 +3770,7 @@ function promisifyRequest(request) {
|
|
|
3459
3770
|
request.removeEventListener('error', error);
|
|
3460
3771
|
};
|
|
3461
3772
|
const success = () => {
|
|
3462
|
-
resolve(wrap
|
|
3773
|
+
resolve(wrap(request.result));
|
|
3463
3774
|
unlisten();
|
|
3464
3775
|
};
|
|
3465
3776
|
const error = () => {
|
|
@@ -3509,7 +3820,7 @@ let idbProxyTraps = {
|
|
|
3509
3820
|
}
|
|
3510
3821
|
}
|
|
3511
3822
|
// Else transform whatever we get back.
|
|
3512
|
-
return wrap
|
|
3823
|
+
return wrap(target[prop]);
|
|
3513
3824
|
},
|
|
3514
3825
|
set(target, prop, value) {
|
|
3515
3826
|
target[prop] = value;
|
|
@@ -3538,13 +3849,13 @@ function wrapFunction(func) {
|
|
|
3538
3849
|
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
3539
3850
|
// the original object.
|
|
3540
3851
|
func.apply(unwrap(this), args);
|
|
3541
|
-
return wrap
|
|
3852
|
+
return wrap(this.request);
|
|
3542
3853
|
};
|
|
3543
3854
|
}
|
|
3544
3855
|
return function (...args) {
|
|
3545
3856
|
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
3546
3857
|
// the original object.
|
|
3547
|
-
return wrap
|
|
3858
|
+
return wrap(func.apply(unwrap(this), args));
|
|
3548
3859
|
};
|
|
3549
3860
|
}
|
|
3550
3861
|
function transformCachableValue(value) {
|
|
@@ -3556,7 +3867,7 @@ function transformCachableValue(value) {
|
|
|
3556
3867
|
// Return the same value back if we're not going to transform it.
|
|
3557
3868
|
return value;
|
|
3558
3869
|
}
|
|
3559
|
-
function wrap
|
|
3870
|
+
function wrap(value) {
|
|
3560
3871
|
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
3561
3872
|
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
3562
3873
|
if (value instanceof IDBRequest) return promisifyRequest(value);
|
|
@@ -3588,10 +3899,10 @@ function openDB(name, version, {
|
|
|
3588
3899
|
terminated
|
|
3589
3900
|
} = {}) {
|
|
3590
3901
|
const request = indexedDB.open(name, version);
|
|
3591
|
-
const openPromise = wrap
|
|
3902
|
+
const openPromise = wrap(request);
|
|
3592
3903
|
if (upgrade) {
|
|
3593
3904
|
request.addEventListener('upgradeneeded', event => {
|
|
3594
|
-
upgrade(wrap
|
|
3905
|
+
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
3595
3906
|
});
|
|
3596
3907
|
}
|
|
3597
3908
|
if (blocked) {
|
|
@@ -3656,894 +3967,580 @@ const cursorIteratorTraps = {
|
|
|
3656
3967
|
advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
|
|
3657
3968
|
};
|
|
3658
3969
|
}
|
|
3659
|
-
return cachedFunc;
|
|
3660
|
-
}
|
|
3661
|
-
};
|
|
3662
|
-
async function* iterate(...args) {
|
|
3663
|
-
// tslint:disable-next-line:no-this-assignment
|
|
3664
|
-
let cursor = this;
|
|
3665
|
-
if (!(cursor instanceof IDBCursor)) {
|
|
3666
|
-
cursor = await cursor.openCursor(...args);
|
|
3667
|
-
}
|
|
3668
|
-
if (!cursor) return;
|
|
3669
|
-
cursor = cursor;
|
|
3670
|
-
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
|
|
3671
|
-
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
|
|
3672
|
-
// Map this double-proxy back to the original, so other cursor methods work.
|
|
3673
|
-
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
|
|
3674
|
-
while (cursor) {
|
|
3675
|
-
yield proxiedCursor;
|
|
3676
|
-
// If one of the advancing methods was not called, call continue().
|
|
3677
|
-
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
|
|
3678
|
-
advanceResults.delete(proxiedCursor);
|
|
3679
|
-
}
|
|
3680
|
-
}
|
|
3681
|
-
function isIteratorProp(target, prop) {
|
|
3682
|
-
return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
|
|
3683
|
-
}
|
|
3684
|
-
replaceTraps(oldTraps => ({
|
|
3685
|
-
...oldTraps,
|
|
3686
|
-
get(target, prop, receiver) {
|
|
3687
|
-
if (isIteratorProp(target, prop)) return iterate;
|
|
3688
|
-
return oldTraps.get(target, prop, receiver);
|
|
3689
|
-
},
|
|
3690
|
-
has(target, prop) {
|
|
3691
|
-
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
|
|
3692
|
-
}
|
|
3693
|
-
}));
|
|
3694
|
-
|
|
3695
|
-
const state$1 = {
|
|
3696
|
-
databases: Object.create(null),
|
|
3697
|
-
eventId: 0,
|
|
3698
|
-
dbVersion: 1,
|
|
3699
|
-
/**
|
|
3700
|
-
* @type {any}
|
|
3701
|
-
*/
|
|
3702
|
-
cachedDb: undefined
|
|
3703
|
-
};
|
|
3704
|
-
|
|
3705
|
-
const isDataCloneError = error => {
|
|
3706
|
-
return error && error.name === 'DataCloneError';
|
|
3707
|
-
};
|
|
3708
|
-
|
|
3709
|
-
// TODO high memory usage in idb because of transactionDoneMap
|
|
3710
|
-
|
|
3711
|
-
const getDb$1 = async () => {
|
|
3712
|
-
// @ts-ignore
|
|
3713
|
-
const db = await openDB('session', state$1.dbVersion, {
|
|
3714
|
-
async upgrade(db, oldVersion) {
|
|
3715
|
-
if (!db.objectStoreNames.contains('session')) {
|
|
3716
|
-
const objectStore = await db.createObjectStore('session', {
|
|
3717
|
-
autoIncrement: true
|
|
3718
|
-
});
|
|
3719
|
-
objectStore.createIndex('sessionId', 'sessionId', {
|
|
3720
|
-
unique: false
|
|
3721
|
-
});
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
});
|
|
3725
|
-
return db;
|
|
3726
|
-
};
|
|
3727
|
-
const getDbMemoized$1 = async () => {
|
|
3728
|
-
state$1.cachedDb ||= await getDb$1();
|
|
3729
|
-
return state$1.cachedDb;
|
|
3730
|
-
};
|
|
3731
|
-
const saveValue = async (storeId, value) => {
|
|
3732
|
-
try {
|
|
3733
|
-
const db = await getDbMemoized$1();
|
|
3734
|
-
await db.add('session', value);
|
|
3735
|
-
} catch (error) {
|
|
3736
|
-
if (isDataCloneError(error)) {
|
|
3737
|
-
// TODO
|
|
3738
|
-
return;
|
|
3739
|
-
}
|
|
3740
|
-
throw new VError(error, 'Failed to save value to indexed db');
|
|
3741
|
-
}
|
|
3742
|
-
};
|
|
3743
|
-
const getValues = async storeId => {
|
|
3744
|
-
try {
|
|
3745
|
-
const db = await getDbMemoized$1();
|
|
3746
|
-
const tx = db.transaction(storeId, 'readwrite');
|
|
3747
|
-
const [objects] = await Promise.all([tx.store.getAll(), tx.done]);
|
|
3748
|
-
console.log({
|
|
3749
|
-
objects
|
|
3750
|
-
});
|
|
3751
|
-
return objects;
|
|
3752
|
-
} catch (error) {
|
|
3753
|
-
throw new VError(error, 'Failed to get values from indexed db');
|
|
3754
|
-
}
|
|
3755
|
-
};
|
|
3756
|
-
const getValuesByIndexName = async (storeId, indexName, only) => {
|
|
3757
|
-
const db = await getDbMemoized$1();
|
|
3758
|
-
const transaction = db.transaction(storeId);
|
|
3759
|
-
const index = transaction.store.index(indexName);
|
|
3760
|
-
const iterator = index.iterate(only);
|
|
3761
|
-
const objects = [];
|
|
3762
|
-
for await (const cursor of iterator) {
|
|
3763
|
-
objects.push(cursor.value);
|
|
3764
|
-
}
|
|
3765
|
-
return objects;
|
|
3766
|
-
};
|
|
3767
|
-
const getHandleDb = async () => {
|
|
3768
|
-
const db = await openDB('handle', state$1.dbVersion, {
|
|
3769
|
-
async upgrade(db, oldVersion) {
|
|
3770
|
-
if (!db.objectStoreNames.contains('file-handles-store')) {
|
|
3771
|
-
// @ts-ignore
|
|
3772
|
-
await db.createObjectStore('file-handles-store', {});
|
|
3773
|
-
}
|
|
3774
|
-
}
|
|
3775
|
-
});
|
|
3776
|
-
return db;
|
|
3777
|
-
};
|
|
3778
|
-
const addHandle = async (uri, handle) => {
|
|
3779
|
-
const handleDb = await getHandleDb();
|
|
3780
|
-
await handleDb.put('file-handles-store', handle, uri);
|
|
3781
|
-
};
|
|
3782
|
-
const getHandle$1 = async uri => {
|
|
3783
|
-
const handleDb = await getHandleDb();
|
|
3784
|
-
const handle = await handleDb.get('file-handles-store', uri);
|
|
3785
|
-
return handle;
|
|
3786
|
-
};
|
|
3787
|
-
|
|
3788
|
-
// TODO high memory usage in idb because of transactionDoneMap
|
|
3789
|
-
|
|
3790
|
-
const state = {
|
|
3791
|
-
databases: Object.create(null),
|
|
3792
|
-
dbVersion: 2,
|
|
3793
|
-
cachedDb: undefined
|
|
3794
|
-
};
|
|
3795
|
-
const storeId = 'lvce-keyvalue';
|
|
3796
|
-
const getDb = async () => {
|
|
3797
|
-
const db = await openDB(storeId, state.dbVersion, {
|
|
3798
|
-
async upgrade(db, oldVersion) {
|
|
3799
|
-
if (!db.objectStoreNames.contains(storeId)) {
|
|
3800
|
-
await db.createObjectStore(storeId, {
|
|
3801
|
-
autoIncrement: true
|
|
3802
|
-
});
|
|
3803
|
-
}
|
|
3804
|
-
}
|
|
3805
|
-
});
|
|
3806
|
-
return db;
|
|
3807
|
-
};
|
|
3808
|
-
const getDbMemoized = async () => {
|
|
3809
|
-
state.cachedDb ||= await getDb();
|
|
3810
|
-
return state.cachedDb;
|
|
3811
|
-
};
|
|
3812
|
-
const set = async (key, value) => {
|
|
3813
|
-
try {
|
|
3814
|
-
const db = await getDbMemoized();
|
|
3815
|
-
await db.put(storeId, value, key);
|
|
3816
|
-
} catch (error) {
|
|
3817
|
-
throw new VError(error, 'Failed to save value to indexed db');
|
|
3818
|
-
}
|
|
3819
|
-
};
|
|
3820
|
-
const get = async key => {
|
|
3821
|
-
try {
|
|
3822
|
-
const db = await getDbMemoized();
|
|
3823
|
-
const value = db.get(storeId, key);
|
|
3824
|
-
return value;
|
|
3825
|
-
} catch (error) {
|
|
3826
|
-
throw new VError(error, 'Failed to get value from indexed db');
|
|
3827
|
-
}
|
|
3828
|
-
};
|
|
3829
|
-
|
|
3830
|
-
const serializeWebView = async webView => {
|
|
3831
|
-
if (webView && webView.provider && webView.provider.saveState) {
|
|
3832
|
-
const saved = await webView.provider.saveState();
|
|
3833
|
-
return {
|
|
3834
|
-
uri: webView.uri,
|
|
3835
|
-
state: saved
|
|
3836
|
-
};
|
|
3837
|
-
}
|
|
3838
|
-
return undefined;
|
|
3839
|
-
};
|
|
3840
|
-
const serializeWebViews = async webViews => {
|
|
3841
|
-
const serialized = [];
|
|
3842
|
-
for (const [key, value] of Object.entries(webViews)) {
|
|
3843
|
-
const serializedValue = await serializeWebView(value);
|
|
3844
|
-
if (serializedValue) {
|
|
3845
|
-
serialized.push({
|
|
3846
|
-
key,
|
|
3847
|
-
value: serializedValue
|
|
3848
|
-
});
|
|
3849
|
-
}
|
|
3850
|
-
}
|
|
3851
|
-
return serialized;
|
|
3852
|
-
};
|
|
3853
|
-
const saveState = async () => {
|
|
3854
|
-
const webViews = getWebViews();
|
|
3855
|
-
const serialized = await serializeWebViews(webViews);
|
|
3856
|
-
return serialized;
|
|
3857
|
-
};
|
|
3858
|
-
|
|
3859
|
-
const fileMapUrl = `${assetDir}/config/fileMap.json`;
|
|
3860
|
-
|
|
3861
|
-
const getJson = async url => {
|
|
3862
|
-
try {
|
|
3863
|
-
const response = await fetch(url);
|
|
3864
|
-
if (!response.ok) {
|
|
3865
|
-
throw new Error(response.statusText);
|
|
3866
|
-
}
|
|
3867
|
-
const json = await response.json();
|
|
3868
|
-
return json;
|
|
3869
|
-
} catch (error) {
|
|
3870
|
-
throw new VError(error, `Failed to get json`);
|
|
3871
|
-
}
|
|
3872
|
-
};
|
|
3873
|
-
|
|
3874
|
-
const removeLeadingSlash = path => {
|
|
3875
|
-
if (path.startsWith('/')) {
|
|
3876
|
-
return path.slice(1);
|
|
3877
|
-
}
|
|
3878
|
-
return path;
|
|
3879
|
-
};
|
|
3880
|
-
|
|
3881
|
-
// TODO simplify code
|
|
3882
|
-
// 1. don't have playground prefix in fileMap json
|
|
3883
|
-
// 2. remove code here that removes the prefix
|
|
3884
|
-
const searchFile$1 = async path => {
|
|
3885
|
-
const fileList = await getJson(fileMapUrl);
|
|
3886
|
-
const result = fileList.map(removeLeadingSlash);
|
|
3887
|
-
const prefixLength = path.length - 'file:///'.length;
|
|
3888
|
-
const final = [];
|
|
3889
|
-
for (const item of result) {
|
|
3890
|
-
final.push(item.slice(prefixLength));
|
|
3970
|
+
return cachedFunc;
|
|
3891
3971
|
}
|
|
3892
|
-
return final;
|
|
3893
3972
|
};
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
const insertInto = (array, start, newItems) => {
|
|
3901
|
-
const originalLength = array.length;
|
|
3902
|
-
const newItemsLength = newItems.length;
|
|
3903
|
-
array.length = originalLength + newItemsLength;
|
|
3904
|
-
// Move the items after the start index, start from the end so that we don't overwrite any value.
|
|
3905
|
-
for (let i = originalLength - 1; i >= start; i--) {
|
|
3906
|
-
array[i + newItemsLength] = array[i];
|
|
3973
|
+
async function* iterate(...args) {
|
|
3974
|
+
// tslint:disable-next-line:no-this-assignment
|
|
3975
|
+
let cursor = this;
|
|
3976
|
+
if (!(cursor instanceof IDBCursor)) {
|
|
3977
|
+
cursor = await cursor.openCursor(...args);
|
|
3907
3978
|
}
|
|
3908
|
-
|
|
3909
|
-
|
|
3979
|
+
if (!cursor) return;
|
|
3980
|
+
cursor = cursor;
|
|
3981
|
+
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
|
|
3982
|
+
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
|
|
3983
|
+
// Map this double-proxy back to the original, so other cursor methods work.
|
|
3984
|
+
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
|
|
3985
|
+
while (cursor) {
|
|
3986
|
+
yield proxiedCursor;
|
|
3987
|
+
// If one of the advancing methods was not called, call continue().
|
|
3988
|
+
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
|
|
3989
|
+
advanceResults.delete(proxiedCursor);
|
|
3910
3990
|
}
|
|
3911
|
-
}
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
}
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3991
|
+
}
|
|
3992
|
+
function isIteratorProp(target, prop) {
|
|
3993
|
+
return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
|
|
3994
|
+
}
|
|
3995
|
+
replaceTraps(oldTraps => ({
|
|
3996
|
+
...oldTraps,
|
|
3997
|
+
get(target, prop, receiver) {
|
|
3998
|
+
if (isIteratorProp(target, prop)) return iterate;
|
|
3999
|
+
return oldTraps.get(target, prop, receiver);
|
|
4000
|
+
},
|
|
4001
|
+
has(target, prop) {
|
|
4002
|
+
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
|
|
3919
4003
|
}
|
|
3920
|
-
|
|
3921
|
-
};
|
|
4004
|
+
}));
|
|
3922
4005
|
|
|
3923
|
-
const
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
4006
|
+
const state$1 = {
|
|
4007
|
+
databases: Object.create(null),
|
|
4008
|
+
eventId: 0,
|
|
4009
|
+
dbVersion: 1,
|
|
4010
|
+
/**
|
|
4011
|
+
* @type {any}
|
|
4012
|
+
*/
|
|
4013
|
+
cachedDb: undefined
|
|
3929
4014
|
};
|
|
3930
4015
|
|
|
3931
|
-
const
|
|
3932
|
-
|
|
3933
|
-
if (index === -1) {
|
|
3934
|
-
return path;
|
|
3935
|
-
}
|
|
3936
|
-
return path.slice(0, index);
|
|
4016
|
+
const isDataCloneError = error => {
|
|
4017
|
+
return error && error.name === 'DataCloneError';
|
|
3937
4018
|
};
|
|
3938
4019
|
|
|
3939
|
-
|
|
3940
|
-
try {
|
|
3941
|
-
// TODO retrieve handle from state or from indexeddb
|
|
3942
|
-
// TODO if not found, throw error
|
|
3943
|
-
const handle = await getHandle$1(uri);
|
|
3944
|
-
return handle;
|
|
3945
|
-
} catch (error) {
|
|
3946
|
-
throw new VError(error, 'Failed to get handle');
|
|
3947
|
-
}
|
|
3948
|
-
};
|
|
4020
|
+
// TODO high memory usage in idb because of transactionDoneMap
|
|
3949
4021
|
|
|
3950
|
-
const
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
};
|
|
3961
|
-
|
|
3962
|
-
const searchFilesRecursively = async (all, parent, handle) => {
|
|
3963
|
-
const childHandles = await getChildHandles$1(handle);
|
|
3964
|
-
const promises = [];
|
|
3965
|
-
for (const childHandle of childHandles) {
|
|
3966
|
-
if (toIgnore.includes(childHandle.name)) {
|
|
3967
|
-
continue;
|
|
3968
|
-
}
|
|
3969
|
-
const absolutePath = parent + '/' + childHandle.name;
|
|
3970
|
-
switch (childHandle.kind) {
|
|
3971
|
-
case Directory:
|
|
3972
|
-
promises.push(searchFilesRecursively(all, absolutePath, childHandle));
|
|
3973
|
-
break;
|
|
3974
|
-
case File:
|
|
3975
|
-
all.push(absolutePath);
|
|
3976
|
-
break;
|
|
4022
|
+
const getDb$1 = async () => {
|
|
4023
|
+
// @ts-ignore
|
|
4024
|
+
const db = await openDB('session', state$1.dbVersion, {
|
|
4025
|
+
async upgrade(db, oldVersion) {
|
|
4026
|
+
if (!db.objectStoreNames.contains('session')) {
|
|
4027
|
+
const objectStore = await db.createObjectStore('session', {
|
|
4028
|
+
autoIncrement: true
|
|
4029
|
+
});
|
|
4030
|
+
objectStore.createIndex('sessionId', 'sessionId', {
|
|
4031
|
+
unique: false
|
|
4032
|
+
});
|
|
4033
|
+
}
|
|
3977
4034
|
}
|
|
3978
|
-
}
|
|
3979
|
-
|
|
4035
|
+
});
|
|
4036
|
+
return db;
|
|
3980
4037
|
};
|
|
3981
|
-
const
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
if (!handle) {
|
|
3985
|
-
// @ts-ignore
|
|
3986
|
-
throw new VError(`Folder not found ${uri}`);
|
|
3987
|
-
}
|
|
3988
|
-
const all = [];
|
|
3989
|
-
await searchFilesRecursively(all, '', handle);
|
|
3990
|
-
return all;
|
|
4038
|
+
const getDbMemoized$1 = async () => {
|
|
4039
|
+
state$1.cachedDb ||= await getDb$1();
|
|
4040
|
+
return state$1.cachedDb;
|
|
3991
4041
|
};
|
|
3992
|
-
|
|
3993
|
-
const getText = async url => {
|
|
4042
|
+
const saveValue = async (storeId, value) => {
|
|
3994
4043
|
try {
|
|
3995
|
-
const
|
|
3996
|
-
|
|
3997
|
-
throw new Error(response.statusText);
|
|
3998
|
-
}
|
|
3999
|
-
const text = await response.text();
|
|
4000
|
-
return text;
|
|
4044
|
+
const db = await getDbMemoized$1();
|
|
4045
|
+
await db.add('session', value);
|
|
4001
4046
|
} catch (error) {
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
const splitLines = lines => {
|
|
4007
|
-
return lines.split('\n');
|
|
4008
|
-
};
|
|
4009
|
-
|
|
4010
|
-
const textSearchInText = (file, content, query) => {
|
|
4011
|
-
const results = [];
|
|
4012
|
-
const lines = splitLines(content);
|
|
4013
|
-
for (let i = 0; i < lines.length; i++) {
|
|
4014
|
-
const line = lines[i];
|
|
4015
|
-
const index = line.indexOf(query);
|
|
4016
|
-
if (index !== -1) {
|
|
4017
|
-
results.push({
|
|
4018
|
-
type: Match,
|
|
4019
|
-
text: line,
|
|
4020
|
-
start: index,
|
|
4021
|
-
end: index + query.length,
|
|
4022
|
-
lineNumber: i
|
|
4023
|
-
});
|
|
4047
|
+
if (isDataCloneError(error)) {
|
|
4048
|
+
// TODO
|
|
4049
|
+
return;
|
|
4024
4050
|
}
|
|
4051
|
+
throw new VError(error, 'Failed to save value to indexed db');
|
|
4025
4052
|
}
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4053
|
+
};
|
|
4054
|
+
const getValues = async storeId => {
|
|
4055
|
+
try {
|
|
4056
|
+
const db = await getDbMemoized$1();
|
|
4057
|
+
const tx = db.transaction(storeId, 'readwrite');
|
|
4058
|
+
const [objects] = await Promise.all([tx.store.getAll(), tx.done]);
|
|
4059
|
+
console.log({
|
|
4060
|
+
objects
|
|
4033
4061
|
});
|
|
4062
|
+
return objects;
|
|
4063
|
+
} catch (error) {
|
|
4064
|
+
throw new VError(error, 'Failed to get values from indexed db');
|
|
4034
4065
|
}
|
|
4035
|
-
return results;
|
|
4036
4066
|
};
|
|
4037
|
-
|
|
4038
|
-
const
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
const
|
|
4043
|
-
const
|
|
4044
|
-
|
|
4045
|
-
const relativeRoot = root.slice('fetch://'.length);
|
|
4046
|
-
for (const uri of fileList) {
|
|
4047
|
-
const fetchUri = `${assetDir}${uri}`;
|
|
4048
|
-
const content = await getText(fetchUri);
|
|
4049
|
-
const relativeUri = uri.slice(relativeRoot.length + 1);
|
|
4050
|
-
const results = textSearchInText(relativeUri, content, query);
|
|
4051
|
-
allResults.push(...results);
|
|
4067
|
+
const getValuesByIndexName = async (storeId, indexName, only) => {
|
|
4068
|
+
const db = await getDbMemoized$1();
|
|
4069
|
+
const transaction = db.transaction(storeId);
|
|
4070
|
+
const index = transaction.store.index(indexName);
|
|
4071
|
+
const iterator = index.iterate(only);
|
|
4072
|
+
const objects = [];
|
|
4073
|
+
for await (const cursor of iterator) {
|
|
4074
|
+
objects.push(cursor.value);
|
|
4052
4075
|
}
|
|
4053
|
-
return
|
|
4076
|
+
return objects;
|
|
4054
4077
|
};
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
}
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4078
|
+
const getHandleDb = async () => {
|
|
4079
|
+
const db = await openDB('handle', state$1.dbVersion, {
|
|
4080
|
+
async upgrade(db, oldVersion) {
|
|
4081
|
+
if (!db.objectStoreNames.contains('file-handles-store')) {
|
|
4082
|
+
// @ts-ignore
|
|
4083
|
+
await db.createObjectStore('file-handles-store', {});
|
|
4084
|
+
}
|
|
4085
|
+
}
|
|
4086
|
+
});
|
|
4087
|
+
return db;
|
|
4088
|
+
};
|
|
4089
|
+
const addHandle = async (uri, handle) => {
|
|
4090
|
+
const handleDb = await getHandleDb();
|
|
4091
|
+
await handleDb.put('file-handles-store', handle, uri);
|
|
4092
|
+
};
|
|
4093
|
+
const getHandle$1 = async uri => {
|
|
4094
|
+
const handleDb = await getHandleDb();
|
|
4095
|
+
const handle = await handleDb.get('file-handles-store', uri);
|
|
4096
|
+
return handle;
|
|
4069
4097
|
};
|
|
4070
4098
|
|
|
4071
|
-
const
|
|
4072
|
-
const handle = await getHandle(uri);
|
|
4073
|
-
if (handle) {
|
|
4074
|
-
return handle;
|
|
4075
|
-
}
|
|
4076
|
-
const dirname$1 = dirname('/', uri);
|
|
4077
|
-
if (uri === dirname$1) {
|
|
4078
|
-
return undefined;
|
|
4079
|
-
}
|
|
4080
|
-
return getDirectoryHandle(dirname$1);
|
|
4081
|
-
};
|
|
4099
|
+
const storeId = 'lvce-keyvalue';
|
|
4082
4100
|
|
|
4083
|
-
|
|
4101
|
+
// TODO high memory usage in idb because of transactionDoneMap
|
|
4084
4102
|
|
|
4085
|
-
const
|
|
4086
|
-
|
|
4103
|
+
const state = {
|
|
4104
|
+
databases: Object.create(null),
|
|
4105
|
+
dbVersion: 2,
|
|
4106
|
+
cachedDb: undefined
|
|
4087
4107
|
};
|
|
4088
|
-
|
|
4089
|
-
const
|
|
4090
|
-
|
|
4108
|
+
const getDb = async () => {
|
|
4109
|
+
const db = await openDB(storeId, state.dbVersion, {
|
|
4110
|
+
async upgrade(db, oldVersion) {
|
|
4111
|
+
if (!db.objectStoreNames.contains(storeId)) {
|
|
4112
|
+
await db.createObjectStore(storeId, {
|
|
4113
|
+
autoIncrement: true
|
|
4114
|
+
});
|
|
4115
|
+
}
|
|
4116
|
+
}
|
|
4117
|
+
});
|
|
4118
|
+
return db;
|
|
4119
|
+
};
|
|
4120
|
+
const getDbMemoized = async () => {
|
|
4121
|
+
state.cachedDb ||= await getDb();
|
|
4122
|
+
return state.cachedDb;
|
|
4091
4123
|
};
|
|
4092
4124
|
|
|
4093
|
-
|
|
4125
|
+
// TODO high memory usage in idb because of transactionDoneMap
|
|
4126
|
+
|
|
4127
|
+
const set = async (key, value) => {
|
|
4094
4128
|
try {
|
|
4095
|
-
const
|
|
4096
|
-
|
|
4097
|
-
const results = textSearchInText(absolutePath, content, query);
|
|
4098
|
-
push(all, results);
|
|
4129
|
+
const db = await getDbMemoized();
|
|
4130
|
+
await db.put(storeId, value, key);
|
|
4099
4131
|
} catch (error) {
|
|
4100
|
-
|
|
4101
|
-
// ignore
|
|
4102
|
-
return;
|
|
4103
|
-
}
|
|
4104
|
-
throw error;
|
|
4105
|
-
}
|
|
4106
|
-
};
|
|
4107
|
-
|
|
4108
|
-
const textSearchRecursively = async (all, parent, handle, query) => {
|
|
4109
|
-
const childHandles = await getChildHandles(handle);
|
|
4110
|
-
const promises = [];
|
|
4111
|
-
for (const childHandle of childHandles) {
|
|
4112
|
-
const absolutePath = parent + '/' + childHandle.name;
|
|
4113
|
-
switch (childHandle.kind) {
|
|
4114
|
-
case Directory:
|
|
4115
|
-
promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
|
|
4116
|
-
break;
|
|
4117
|
-
case File:
|
|
4118
|
-
// @ts-ignore
|
|
4119
|
-
promises.push(textSearchInFile(all, childHandle, absolutePath, query));
|
|
4120
|
-
break;
|
|
4121
|
-
}
|
|
4132
|
+
throw new VError(error, 'Failed to save value to indexed db');
|
|
4122
4133
|
}
|
|
4123
|
-
await Promise.all(promises);
|
|
4124
4134
|
};
|
|
4125
|
-
const
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
throw new FileNotFoundError(`Folder not found: ${relativeRoot}`);
|
|
4135
|
+
const get = async key => {
|
|
4136
|
+
try {
|
|
4137
|
+
const db = await getDbMemoized();
|
|
4138
|
+
const value = db.get(storeId, key);
|
|
4139
|
+
return value;
|
|
4140
|
+
} catch (error) {
|
|
4141
|
+
throw new VError(error, 'Failed to get value from indexed db');
|
|
4133
4142
|
}
|
|
4134
|
-
const all = [];
|
|
4135
|
-
await textSearchRecursively(all, '', handle, query);
|
|
4136
|
-
return all;
|
|
4137
|
-
};
|
|
4138
|
-
|
|
4139
|
-
const commandMap = {
|
|
4140
|
-
'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
|
|
4141
|
-
'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
|
|
4142
|
-
'IndexedDb.addHandle': addHandle,
|
|
4143
|
-
'IndexedDb.get': get,
|
|
4144
|
-
'IndexedDb.getHandle': getHandle$1,
|
|
4145
|
-
'IndexedDb.getValues': getValues,
|
|
4146
|
-
'IndexedDb.getValuesByIndexName': getValuesByIndexName,
|
|
4147
|
-
'IndexedDb.saveValue': saveValue,
|
|
4148
|
-
'IndexedDb.set': set,
|
|
4149
|
-
'SearchFileWithFetch.searchFileWithFetch': searchFile$1,
|
|
4150
|
-
'SearchFileWithHtml.searchFileWithHtml': searchFile,
|
|
4151
|
-
'TextSearchFetch.textSearch': textSearch$1,
|
|
4152
|
-
'TextSearchHtml.textSearch': textSearch,
|
|
4153
|
-
['ExtensionHostDebug.evaluate']: evaluate,
|
|
4154
|
-
['ExtensionHostDebug.getProperties']: getProperties,
|
|
4155
|
-
['ExtensionHostDebug.listProcesses']: listProcesses,
|
|
4156
|
-
['ExtensionHostDebug.pause']: pause,
|
|
4157
|
-
['ExtensionHostDebug.resume']: resume,
|
|
4158
|
-
['ExtensionHostDebug.setPauseOnException']: setPauseOnException,
|
|
4159
|
-
['ExtensionHostDebug.setPauseOnExceptions']: setPauseOnExceptions,
|
|
4160
|
-
['ExtensionHostDebug.start']: start,
|
|
4161
|
-
['ExtensionHostDebug.stepInto']: stepInto,
|
|
4162
|
-
['ExtensionHostDebug.stepOut']: stepOut,
|
|
4163
|
-
['ExtensionHostDebug.stepOver']: stepOver,
|
|
4164
|
-
['ExtensionHostWebView.create']: createWebView,
|
|
4165
|
-
['ExtensionHostWebView.dispose']: disposeWebView,
|
|
4166
|
-
['ExtensionHostWebView.load']: load,
|
|
4167
|
-
['ExtensionHostWebView.getWebViewInfo']: getWebViewInfo,
|
|
4168
|
-
['HandleBeforeUnload.handleBeforeUnload']: handleBeforeUnload,
|
|
4169
|
-
['HandleMessagePort.handleMessagePort']: handleMessagePort,
|
|
4170
|
-
['SaveState.saveState']: saveState,
|
|
4171
|
-
[BraceCompletionExecuteBraceCompletionProvider]: executeBraceCompletionProvider,
|
|
4172
|
-
[ClosingTagExecuteClosingTagProvider]: executeClosingTagProvider,
|
|
4173
|
-
[CommandExecute]: executeCommand,
|
|
4174
|
-
[CompletionExecute]: executeCompletionProvider,
|
|
4175
|
-
[CompletionResolveExecute]: executeresolveCompletionItemProvider,
|
|
4176
|
-
[ConfigurationSetConfiguration]: setConfigurations,
|
|
4177
|
-
[DefinitionExecuteDefinitionProvider]: executeDefinitionProvider,
|
|
4178
|
-
[DiagnosticExecuteDiagnosticProvider]: executeDiagnosticProvider,
|
|
4179
|
-
[ExtensionActivate]: activate,
|
|
4180
|
-
[FileSystemGetPathSeparator]: getPathSeparator,
|
|
4181
|
-
[FileSystemReadDirWithFileTypes]: readDirWithFileTypes,
|
|
4182
|
-
[FileSystemReadFile]: readFile,
|
|
4183
|
-
[FileSystemWriteFile]: writeFile,
|
|
4184
|
-
[FormattingExecuteFormmattingProvider]: executeFormattingProvider,
|
|
4185
|
-
[HoverExecute]: executeHoverProvider,
|
|
4186
|
-
[ImplementationExecuteImplementationProvider]: executeImplementationProvider,
|
|
4187
|
-
[MockExec]: mockExec,
|
|
4188
|
-
[MockRpc]: mockRpc,
|
|
4189
|
-
[OrganizeImportsExecute]: executeOrganizeImports,
|
|
4190
|
-
[ReferenceExecuteFileReferenceProvider]: executefileReferenceProvider,
|
|
4191
|
-
[ReferenceExecuteReferenceProvider]: executeReferenceProvider,
|
|
4192
|
-
[SelectionExecuteSelectionProvider]: executeSelectionProvider,
|
|
4193
|
-
[SourceControlAcceptInput]: acceptInput,
|
|
4194
|
-
[SourceControlAdd]: add,
|
|
4195
|
-
[SourceControlDiscard]: discard,
|
|
4196
|
-
[SourceControlGetChangedFiles]: getChangedFiles,
|
|
4197
|
-
[SourceControlGetEnabledProviderIds]: getEnabledProviderIds,
|
|
4198
|
-
[SourceControlGetFileBefore]: getFileBefore,
|
|
4199
|
-
[SourceControlGetGroups]: getGroups,
|
|
4200
|
-
[StatusBarGetStatusBarItems]: getStatusBarItems,
|
|
4201
|
-
[StatusBarRegisterChangeListener]: registerChangeListener,
|
|
4202
|
-
[TabCompletionExecuteTabCompletionProvider]: executeTabCompletionProvider,
|
|
4203
|
-
[TextDocumentSetLanguageId]: setLanguageId,
|
|
4204
|
-
[TextDocumentSyncFull]: syncFull,
|
|
4205
|
-
[TextDocumentSyncIncremental]: syncIncremental,
|
|
4206
|
-
[TextSearchExecuteTextSearchProvider]: executeTextSearchProvider,
|
|
4207
|
-
[TypeDefinitionExecuteTypeDefinitionProvider]: executeTypeDefinitionProvider,
|
|
4208
|
-
[WorkspaceSetPath]: setWorkspacePath
|
|
4209
|
-
};
|
|
4210
|
-
|
|
4211
|
-
const listen = async () => {
|
|
4212
|
-
const rpc = await WebWorkerRpcClient.create({
|
|
4213
|
-
commandMap: commandMap
|
|
4214
|
-
});
|
|
4215
|
-
setRpc(rpc);
|
|
4216
4143
|
};
|
|
4217
4144
|
|
|
4218
|
-
const
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
global: globalThis
|
|
4222
|
-
});
|
|
4223
|
-
await listen();
|
|
4145
|
+
const loadWebView = async (providerId, savedState) => {
|
|
4146
|
+
const rpc = getWebView(providerId);
|
|
4147
|
+
await rpc.provider.create(rpc, rpc.uri, savedState);
|
|
4224
4148
|
};
|
|
4225
4149
|
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
const
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
*/
|
|
4236
|
-
let _resolve;
|
|
4237
|
-
const promise = new Promise(resolve => {
|
|
4238
|
-
_resolve = resolve;
|
|
4239
|
-
});
|
|
4240
|
-
return {
|
|
4241
|
-
resolve: _resolve,
|
|
4242
|
-
promise
|
|
4243
|
-
};
|
|
4150
|
+
const serializeWebView = async webView => {
|
|
4151
|
+
if (webView && webView.provider && webView.provider.saveState) {
|
|
4152
|
+
const saved = await webView.provider.saveState();
|
|
4153
|
+
return {
|
|
4154
|
+
uri: webView.uri,
|
|
4155
|
+
state: saved
|
|
4156
|
+
};
|
|
4157
|
+
}
|
|
4158
|
+
return undefined;
|
|
4244
4159
|
};
|
|
4245
|
-
|
|
4246
|
-
const
|
|
4247
|
-
const {
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
for (const event of Object.keys(eventMap)) {
|
|
4254
|
-
eventTarget.removeEventListener(event, listenerMap[event]);
|
|
4255
|
-
}
|
|
4256
|
-
resolve(value);
|
|
4257
|
-
};
|
|
4258
|
-
for (const [event, type] of Object.entries(eventMap)) {
|
|
4259
|
-
const listener = event => {
|
|
4260
|
-
cleanup({
|
|
4261
|
-
type,
|
|
4262
|
-
event
|
|
4160
|
+
const serializeWebViews = async webViews => {
|
|
4161
|
+
const serialized = [];
|
|
4162
|
+
for (const [key, value] of Object.entries(webViews)) {
|
|
4163
|
+
const serializedValue = await serializeWebView(value);
|
|
4164
|
+
if (serializedValue) {
|
|
4165
|
+
serialized.push({
|
|
4166
|
+
key,
|
|
4167
|
+
value: serializedValue
|
|
4263
4168
|
});
|
|
4264
|
-
}
|
|
4265
|
-
eventTarget.addEventListener(event, listener);
|
|
4266
|
-
listenerMap[event] = listener;
|
|
4169
|
+
}
|
|
4267
4170
|
}
|
|
4268
|
-
return
|
|
4171
|
+
return serialized;
|
|
4172
|
+
};
|
|
4173
|
+
const saveState = async () => {
|
|
4174
|
+
const webViews = getWebViews();
|
|
4175
|
+
const serialized = await serializeWebViews(webViews);
|
|
4176
|
+
return serialized;
|
|
4269
4177
|
};
|
|
4270
4178
|
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
})
|
|
4179
|
+
const fileMapUrl = `${assetDir}/config/fileMap.json`;
|
|
4180
|
+
|
|
4181
|
+
const getJson = async url => {
|
|
4182
|
+
try {
|
|
4183
|
+
const response = await fetch(url);
|
|
4184
|
+
if (!response.ok) {
|
|
4185
|
+
throw new Error(response.statusText);
|
|
4186
|
+
}
|
|
4187
|
+
const json = await response.json();
|
|
4188
|
+
return json;
|
|
4189
|
+
} catch (error) {
|
|
4190
|
+
throw new VError(error, `Failed to get json`);
|
|
4191
|
+
}
|
|
4282
4192
|
};
|
|
4283
4193
|
|
|
4284
|
-
const
|
|
4285
|
-
|
|
4194
|
+
const removeLeadingSlash = path => {
|
|
4195
|
+
if (path.startsWith('/')) {
|
|
4196
|
+
return path.slice(1);
|
|
4197
|
+
}
|
|
4198
|
+
return path;
|
|
4286
4199
|
};
|
|
4287
4200
|
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4201
|
+
// TODO simplify code
|
|
4202
|
+
// 1. don't have playground prefix in fileMap json
|
|
4203
|
+
// 2. remove code here that removes the prefix
|
|
4204
|
+
const searchFile$1 = async path => {
|
|
4205
|
+
const fileList = await getJson(fileMapUrl);
|
|
4206
|
+
const result = fileList.map(removeLeadingSlash);
|
|
4207
|
+
const prefixLength = path.length - 'file:///'.length;
|
|
4208
|
+
const final = [];
|
|
4209
|
+
for (const item of result) {
|
|
4210
|
+
final.push(item.slice(prefixLength));
|
|
4211
|
+
}
|
|
4212
|
+
return final;
|
|
4291
4213
|
};
|
|
4292
4214
|
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
super(message);
|
|
4296
|
-
this.name = 'IpcError';
|
|
4297
|
-
}
|
|
4298
|
-
}
|
|
4215
|
+
const Directory = 'directory';
|
|
4216
|
+
const File = 'file';
|
|
4299
4217
|
|
|
4300
|
-
|
|
4301
|
-
return JSON.stringify(value);
|
|
4302
|
-
};
|
|
4218
|
+
// based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
|
|
4303
4219
|
|
|
4304
|
-
const
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
// @ts-ignore
|
|
4312
|
-
if (firstWebSocketEvent.type === Error$1) {
|
|
4313
|
-
throw new IpcError(`WebSocket connection error`);
|
|
4220
|
+
const insertInto = (array, start, newItems) => {
|
|
4221
|
+
const originalLength = array.length;
|
|
4222
|
+
const newItemsLength = newItems.length;
|
|
4223
|
+
array.length = originalLength + newItemsLength;
|
|
4224
|
+
// Move the items after the start index, start from the end so that we don't overwrite any value.
|
|
4225
|
+
for (let i = originalLength - 1; i >= start; i--) {
|
|
4226
|
+
array[i + newItemsLength] = array[i];
|
|
4314
4227
|
}
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
throw new IpcError(`Websocket connection was closed`);
|
|
4228
|
+
for (let i = 0; i < newItemsLength; i++) {
|
|
4229
|
+
array[i + start] = newItems[i];
|
|
4318
4230
|
}
|
|
4319
|
-
return webSocket;
|
|
4320
4231
|
};
|
|
4321
|
-
const
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
},
|
|
4331
|
-
set onmessage(listener) {
|
|
4332
|
-
if (listener) {
|
|
4333
|
-
// @ts-ignore
|
|
4334
|
-
this.handleMessage = event => {
|
|
4335
|
-
// TODO why are some events not instance of message event?
|
|
4336
|
-
if (event instanceof MessageEvent) {
|
|
4337
|
-
const message = JSON.parse(event.data);
|
|
4338
|
-
// @ts-ignore
|
|
4339
|
-
listener(message);
|
|
4340
|
-
} else {
|
|
4341
|
-
// @ts-ignore
|
|
4342
|
-
listener(event);
|
|
4343
|
-
}
|
|
4344
|
-
};
|
|
4345
|
-
} else {
|
|
4346
|
-
// @ts-ignore
|
|
4347
|
-
this.handleMessage = null;
|
|
4348
|
-
}
|
|
4349
|
-
this.webSocket.onmessage = this.handleMessage;
|
|
4350
|
-
},
|
|
4351
|
-
send(message) {
|
|
4352
|
-
if (this.webSocket.readyState !== webSocket.OPEN) {
|
|
4353
|
-
// @ts-ignore
|
|
4354
|
-
throw new VError(`Failed to send message: WebSocket is not open`);
|
|
4355
|
-
}
|
|
4356
|
-
const stringifiedMessage = stringifyCompact(message);
|
|
4357
|
-
this.webSocket.send(stringifiedMessage);
|
|
4358
|
-
}
|
|
4359
|
-
};
|
|
4232
|
+
const push = (array, newItems) => {
|
|
4233
|
+
insertInto(array, array.length, newItems);
|
|
4234
|
+
};
|
|
4235
|
+
const fromAsync = async asyncIterable => {
|
|
4236
|
+
const children = [];
|
|
4237
|
+
for await (const value of asyncIterable) {
|
|
4238
|
+
children.push(value);
|
|
4239
|
+
}
|
|
4240
|
+
return children;
|
|
4360
4241
|
};
|
|
4361
4242
|
|
|
4362
|
-
const
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4243
|
+
const getChildHandles$1 = async handle => {
|
|
4244
|
+
object(handle);
|
|
4245
|
+
// @ts-ignore
|
|
4246
|
+
const childHandles = handle.values();
|
|
4247
|
+
const handles = await fromAsync(childHandles);
|
|
4248
|
+
return handles;
|
|
4366
4249
|
};
|
|
4367
4250
|
|
|
4368
|
-
const
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
default:
|
|
4373
|
-
return Promise.resolve().then(function () { return IpcParentWithElectronMessagePort; });
|
|
4251
|
+
const dirname = (pathSeparator, path) => {
|
|
4252
|
+
const index = path.lastIndexOf(pathSeparator);
|
|
4253
|
+
if (index === -1) {
|
|
4254
|
+
return path;
|
|
4374
4255
|
}
|
|
4256
|
+
return path.slice(0, index);
|
|
4375
4257
|
};
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
})
|
|
4384
|
-
|
|
4385
|
-
return rawIpc;
|
|
4258
|
+
|
|
4259
|
+
const getHandle = async uri => {
|
|
4260
|
+
try {
|
|
4261
|
+
// TODO retrieve handle from state or from indexeddb
|
|
4262
|
+
// TODO if not found, throw error
|
|
4263
|
+
const handle = await getHandle$1(uri);
|
|
4264
|
+
return handle;
|
|
4265
|
+
} catch (error) {
|
|
4266
|
+
throw new VError(error, 'Failed to get handle');
|
|
4386
4267
|
}
|
|
4387
|
-
return {
|
|
4388
|
-
module,
|
|
4389
|
-
rawIpc
|
|
4390
|
-
};
|
|
4391
|
-
};
|
|
4392
|
-
const wrap$2 = ({
|
|
4393
|
-
module,
|
|
4394
|
-
rawIpc
|
|
4395
|
-
}) => {
|
|
4396
|
-
return module.wrap(rawIpc);
|
|
4397
4268
|
};
|
|
4398
4269
|
|
|
4399
|
-
const
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4270
|
+
const getDirectoryHandle$1 = async uri => {
|
|
4271
|
+
const handle = await getHandle(uri);
|
|
4272
|
+
if (handle) {
|
|
4273
|
+
return handle;
|
|
4274
|
+
}
|
|
4275
|
+
const dirname$1 = dirname('/', uri);
|
|
4276
|
+
if (uri === dirname$1) {
|
|
4277
|
+
return undefined;
|
|
4278
|
+
}
|
|
4279
|
+
return getDirectoryHandle$1(dirname$1);
|
|
4280
|
+
};
|
|
4281
|
+
const toIgnore = ['.git', 'node_modules', 'dist', 'dist2'];
|
|
4282
|
+
const searchFilesRecursively = async (all, parent, handle) => {
|
|
4283
|
+
const childHandles = await getChildHandles$1(handle);
|
|
4284
|
+
const promises = [];
|
|
4285
|
+
for (const childHandle of childHandles) {
|
|
4286
|
+
if (toIgnore.includes(childHandle.name)) {
|
|
4287
|
+
continue;
|
|
4288
|
+
}
|
|
4289
|
+
const absolutePath = parent + '/' + childHandle.name;
|
|
4290
|
+
switch (childHandle.kind) {
|
|
4291
|
+
case Directory:
|
|
4292
|
+
promises.push(searchFilesRecursively(all, absolutePath, childHandle));
|
|
4293
|
+
break;
|
|
4294
|
+
case File:
|
|
4295
|
+
all.push(absolutePath);
|
|
4296
|
+
break;
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
await Promise.all(promises);
|
|
4300
|
+
};
|
|
4301
|
+
const searchFile = async uri => {
|
|
4302
|
+
const path = uri.slice('html://'.length);
|
|
4303
|
+
const handle = await getDirectoryHandle$1(path);
|
|
4304
|
+
if (!handle) {
|
|
4305
|
+
// @ts-ignore
|
|
4306
|
+
throw new VError(`Folder not found ${uri}`);
|
|
4307
|
+
}
|
|
4308
|
+
const all = [];
|
|
4309
|
+
await searchFilesRecursively(all, '', handle);
|
|
4310
|
+
return all;
|
|
4403
4311
|
};
|
|
4404
4312
|
|
|
4405
|
-
const
|
|
4313
|
+
const getText = async url => {
|
|
4314
|
+
try {
|
|
4315
|
+
const response = await fetch(url);
|
|
4316
|
+
if (!response.ok) {
|
|
4317
|
+
throw new Error(response.statusText);
|
|
4318
|
+
}
|
|
4319
|
+
const text = await response.text();
|
|
4320
|
+
return text;
|
|
4321
|
+
} catch (error) {
|
|
4322
|
+
throw new VError(error, `Failed to get text`);
|
|
4323
|
+
}
|
|
4324
|
+
};
|
|
4406
4325
|
|
|
4407
|
-
const
|
|
4408
|
-
|
|
4409
|
-
name
|
|
4410
|
-
}) => {
|
|
4411
|
-
string(url);
|
|
4412
|
-
string(name);
|
|
4413
|
-
const {
|
|
4414
|
-
port1,
|
|
4415
|
-
port2
|
|
4416
|
-
} = getPortTuple();
|
|
4417
|
-
await invokeAndTransfer$1('IpcParent.create', {
|
|
4418
|
-
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
|
|
4419
|
-
url,
|
|
4420
|
-
name,
|
|
4421
|
-
raw: true,
|
|
4422
|
-
port: port1
|
|
4423
|
-
});
|
|
4424
|
-
return port2;
|
|
4326
|
+
const splitLines = lines => {
|
|
4327
|
+
return lines.split('\n');
|
|
4425
4328
|
};
|
|
4426
|
-
const wrap$1 = port => {
|
|
4427
|
-
return {
|
|
4428
|
-
port,
|
|
4429
|
-
/**
|
|
4430
|
-
* @type {any}
|
|
4431
|
-
*/
|
|
4432
|
-
handleMessage: undefined,
|
|
4433
|
-
get onmessage() {
|
|
4434
|
-
return this.handleMessage;
|
|
4435
|
-
},
|
|
4436
|
-
set onmessage(listener) {
|
|
4437
|
-
if (listener) {
|
|
4438
|
-
// @ts-ignore
|
|
4439
|
-
this.handleMessage = event => {
|
|
4440
|
-
// TODO why are some events not instance of message event?
|
|
4441
|
-
if (event instanceof MessageEvent) {
|
|
4442
|
-
const message = event.data;
|
|
4443
|
-
// @ts-ignore
|
|
4444
|
-
listener(message, event);
|
|
4445
|
-
} else {
|
|
4446
|
-
// @ts-ignore
|
|
4447
4329
|
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4330
|
+
const textSearchInText = (file, content, query) => {
|
|
4331
|
+
const results = [];
|
|
4332
|
+
const lines = splitLines(content);
|
|
4333
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4334
|
+
const line = lines[i];
|
|
4335
|
+
const index = line.indexOf(query);
|
|
4336
|
+
if (index !== -1) {
|
|
4337
|
+
results.push({
|
|
4338
|
+
type: Match,
|
|
4339
|
+
text: line,
|
|
4340
|
+
start: index,
|
|
4341
|
+
end: index + query.length,
|
|
4342
|
+
lineNumber: i
|
|
4343
|
+
});
|
|
4462
4344
|
}
|
|
4463
|
-
}
|
|
4345
|
+
}
|
|
4346
|
+
if (results.length > 0) {
|
|
4347
|
+
results.unshift({
|
|
4348
|
+
type: File$2,
|
|
4349
|
+
text: file,
|
|
4350
|
+
start: 0,
|
|
4351
|
+
end: 0,
|
|
4352
|
+
lineNumber: 0
|
|
4353
|
+
});
|
|
4354
|
+
}
|
|
4355
|
+
return results;
|
|
4464
4356
|
};
|
|
4465
4357
|
|
|
4466
|
-
const
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4358
|
+
const textSearch$1 = async (scheme, root, query, options, assetDir) => {
|
|
4359
|
+
string(scheme);
|
|
4360
|
+
string(root);
|
|
4361
|
+
string(query);
|
|
4362
|
+
const fetchUri = `${assetDir}/config/fileMap.json`;
|
|
4363
|
+
const fileList = await getJson(fetchUri);
|
|
4364
|
+
const allResults = [];
|
|
4365
|
+
const relativeRoot = root.slice('fetch://'.length);
|
|
4366
|
+
for (const uri of fileList) {
|
|
4367
|
+
const fetchUri = `${assetDir}${uri}`;
|
|
4368
|
+
const content = await getText(fetchUri);
|
|
4369
|
+
const relativeUri = uri.slice(relativeRoot.length + 1);
|
|
4370
|
+
const results = textSearchInText(relativeUri, content, query);
|
|
4371
|
+
allResults.push(...results);
|
|
4372
|
+
}
|
|
4373
|
+
return allResults;
|
|
4470
4374
|
};
|
|
4471
4375
|
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4376
|
+
class FileNotFoundError extends Error {
|
|
4377
|
+
constructor(message) {
|
|
4378
|
+
super(message);
|
|
4379
|
+
this.name = 'FileNotFoundError';
|
|
4380
|
+
}
|
|
4381
|
+
}
|
|
4382
|
+
|
|
4383
|
+
const getChildHandles = async handle => {
|
|
4384
|
+
try {
|
|
4385
|
+
return await getChildHandles$1(handle);
|
|
4386
|
+
} catch (error) {
|
|
4387
|
+
throw new VError(error, 'failed to get child handles');
|
|
4388
|
+
}
|
|
4477
4389
|
};
|
|
4478
|
-
|
|
4479
|
-
|
|
4390
|
+
|
|
4391
|
+
const getDirectoryHandle = async uri => {
|
|
4392
|
+
const handle = await getHandle(uri);
|
|
4393
|
+
if (handle) {
|
|
4394
|
+
return handle;
|
|
4395
|
+
}
|
|
4396
|
+
const dirname$1 = dirname('/', uri);
|
|
4397
|
+
if (uri === dirname$1) {
|
|
4398
|
+
return undefined;
|
|
4399
|
+
}
|
|
4400
|
+
return getDirectoryHandle(dirname$1);
|
|
4480
4401
|
};
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
fn(execute);
|
|
4487
|
-
const handleMessage = async message => {
|
|
4488
|
-
return handleJsonRpcMessage(ipc, message, execute, resolve, preparePrettyError, logError, requiresSocket);
|
|
4489
|
-
};
|
|
4490
|
-
ipc.onmessage = handleMessage;
|
|
4491
|
-
return {
|
|
4492
|
-
ipc,
|
|
4493
|
-
invoke(method, ...params) {
|
|
4494
|
-
return invoke(this.ipc, method, ...params);
|
|
4495
|
-
}
|
|
4496
|
-
};
|
|
4402
|
+
|
|
4403
|
+
const NotReadableError = 'NotReadableError';
|
|
4404
|
+
|
|
4405
|
+
const isNotReadableError = error => {
|
|
4406
|
+
return error && error.name === NotReadableError;
|
|
4497
4407
|
};
|
|
4498
4408
|
|
|
4499
|
-
const
|
|
4500
|
-
|
|
4501
|
-
create: create$1
|
|
4409
|
+
const getFile = handle => {
|
|
4410
|
+
return handle.getFile();
|
|
4502
4411
|
};
|
|
4503
4412
|
|
|
4504
|
-
const
|
|
4505
|
-
|
|
4413
|
+
const textSearchInFile = async (all, handle, absolutePath, query) => {
|
|
4414
|
+
try {
|
|
4415
|
+
const file = await getFile(handle);
|
|
4416
|
+
const content = await file.text();
|
|
4417
|
+
const results = textSearchInText(absolutePath, content, query);
|
|
4418
|
+
push(all, results);
|
|
4419
|
+
} catch (error) {
|
|
4420
|
+
if (isNotReadableError(error)) {
|
|
4421
|
+
// ignore
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
throw error;
|
|
4425
|
+
}
|
|
4506
4426
|
};
|
|
4507
4427
|
|
|
4508
|
-
const
|
|
4509
|
-
const
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4428
|
+
const textSearchRecursively = async (all, parent, handle, query) => {
|
|
4429
|
+
const childHandles = await getChildHandles(handle);
|
|
4430
|
+
const promises = [];
|
|
4431
|
+
for (const childHandle of childHandles) {
|
|
4432
|
+
const absolutePath = parent + '/' + childHandle.name;
|
|
4433
|
+
switch (childHandle.kind) {
|
|
4434
|
+
case Directory:
|
|
4435
|
+
promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
|
|
4436
|
+
break;
|
|
4437
|
+
case File:
|
|
4438
|
+
// @ts-ignore
|
|
4439
|
+
promises.push(textSearchInFile(all, childHandle, absolutePath, query));
|
|
4440
|
+
break;
|
|
4441
|
+
}
|
|
4442
|
+
}
|
|
4443
|
+
await Promise.all(promises);
|
|
4515
4444
|
};
|
|
4516
|
-
const
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4445
|
+
const textSearch = async (scheme, root, query) => {
|
|
4446
|
+
string(scheme);
|
|
4447
|
+
string(root);
|
|
4448
|
+
string(query);
|
|
4449
|
+
const relativeRoot = root.slice('html://'.length);
|
|
4450
|
+
const handle = await getDirectoryHandle(relativeRoot);
|
|
4451
|
+
if (!handle) {
|
|
4452
|
+
throw new FileNotFoundError(`Folder not found: ${relativeRoot}`);
|
|
4453
|
+
}
|
|
4454
|
+
const all = [];
|
|
4455
|
+
await textSearchRecursively(all, '', handle, query);
|
|
4456
|
+
return all;
|
|
4521
4457
|
};
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4458
|
+
|
|
4459
|
+
const commandMap = {
|
|
4460
|
+
'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
|
|
4461
|
+
'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
|
|
4462
|
+
'IndexedDb.addHandle': addHandle,
|
|
4463
|
+
'IndexedDb.get': get,
|
|
4464
|
+
'IndexedDb.getHandle': getHandle$1,
|
|
4465
|
+
'IndexedDb.getValues': getValues,
|
|
4466
|
+
'IndexedDb.getValuesByIndexName': getValuesByIndexName,
|
|
4467
|
+
'IndexedDb.saveValue': saveValue,
|
|
4468
|
+
'IndexedDb.set': set,
|
|
4469
|
+
'SearchFileWithFetch.searchFileWithFetch': searchFile$1,
|
|
4470
|
+
'SearchFileWithHtml.searchFileWithHtml': searchFile,
|
|
4471
|
+
'TextSearchFetch.textSearch': textSearch$1,
|
|
4472
|
+
'TextSearchHtml.textSearch': textSearch,
|
|
4473
|
+
['ExtensionHostDebug.evaluate']: evaluate,
|
|
4474
|
+
['ExtensionHostDebug.getProperties']: getProperties,
|
|
4475
|
+
['ExtensionHostDebug.listProcesses']: listProcesses,
|
|
4476
|
+
['ExtensionHostDebug.pause']: pause,
|
|
4477
|
+
['ExtensionHostDebug.resume']: resume,
|
|
4478
|
+
['ExtensionHostDebug.setPauseOnException']: setPauseOnException,
|
|
4479
|
+
['ExtensionHostDebug.setPauseOnExceptions']: setPauseOnExceptions,
|
|
4480
|
+
['ExtensionHostDebug.start']: start,
|
|
4481
|
+
['ExtensionHostDebug.stepInto']: stepInto,
|
|
4482
|
+
['ExtensionHostDebug.stepOut']: stepOut,
|
|
4483
|
+
['ExtensionHostDebug.stepOver']: stepOver,
|
|
4484
|
+
['ExtensionHostWebView.create']: createWebView,
|
|
4485
|
+
['ExtensionHostWebView.dispose']: disposeWebView,
|
|
4486
|
+
['ExtensionHostWebView.load']: loadWebView,
|
|
4487
|
+
['ExtensionHostWebView.getWebViewInfo']: getWebViewInfo,
|
|
4488
|
+
['HandleBeforeUnload.handleBeforeUnload']: handleBeforeUnload,
|
|
4489
|
+
['HandleMessagePort.handleMessagePort']: handleMessagePort,
|
|
4490
|
+
['SaveState.saveState']: saveState,
|
|
4491
|
+
[BraceCompletionExecuteBraceCompletionProvider]: executeBraceCompletionProvider,
|
|
4492
|
+
[ClosingTagExecuteClosingTagProvider]: executeClosingTagProvider,
|
|
4493
|
+
[CommandExecute]: executeCommand,
|
|
4494
|
+
[CompletionExecute]: executeCompletionProvider,
|
|
4495
|
+
[CompletionResolveExecute]: executeresolveCompletionItemProvider,
|
|
4496
|
+
[ConfigurationSetConfiguration]: setConfigurations,
|
|
4497
|
+
[DefinitionExecuteDefinitionProvider]: executeDefinitionProvider,
|
|
4498
|
+
[DiagnosticExecuteDiagnosticProvider]: executeDiagnosticProvider,
|
|
4499
|
+
[ExtensionActivate]: activate,
|
|
4500
|
+
[FileSystemGetPathSeparator]: getPathSeparator,
|
|
4501
|
+
[FileSystemReadDirWithFileTypes]: readDirWithFileTypes,
|
|
4502
|
+
[FileSystemReadFile]: readFile,
|
|
4503
|
+
[FileSystemWriteFile]: writeFile,
|
|
4504
|
+
[FormattingExecuteFormmattingProvider]: executeFormattingProvider,
|
|
4505
|
+
[HoverExecute]: executeHoverProvider,
|
|
4506
|
+
[ImplementationExecuteImplementationProvider]: executeImplementationProvider,
|
|
4507
|
+
[MockExec]: mockExec,
|
|
4508
|
+
[MockRpc]: mockRpc,
|
|
4509
|
+
[OrganizeImportsExecute]: executeOrganizeImports,
|
|
4510
|
+
[ReferenceExecuteFileReferenceProvider]: executefileReferenceProvider,
|
|
4511
|
+
[ReferenceExecuteReferenceProvider]: executeReferenceProvider,
|
|
4512
|
+
[SelectionExecuteSelectionProvider]: executeSelectionProvider,
|
|
4513
|
+
[SourceControlAcceptInput]: acceptInput,
|
|
4514
|
+
[SourceControlAdd]: add,
|
|
4515
|
+
[SourceControlDiscard]: discard,
|
|
4516
|
+
[SourceControlGetChangedFiles]: getChangedFiles,
|
|
4517
|
+
[SourceControlGetEnabledProviderIds]: getEnabledProviderIds,
|
|
4518
|
+
[SourceControlGetFileBefore]: getFileBefore,
|
|
4519
|
+
[SourceControlGetGroups]: getGroups,
|
|
4520
|
+
[StatusBarGetStatusBarItems]: getStatusBarItems,
|
|
4521
|
+
[StatusBarRegisterChangeListener]: registerChangeListener,
|
|
4522
|
+
[TabCompletionExecuteTabCompletionProvider]: executeTabCompletionProvider,
|
|
4523
|
+
[TextDocumentSetLanguageId]: setLanguageId,
|
|
4524
|
+
[TextDocumentSyncFull]: syncFull,
|
|
4525
|
+
[TextDocumentSyncIncremental]: syncIncremental,
|
|
4526
|
+
[TextSearchExecuteTextSearchProvider]: executeTextSearchProvider,
|
|
4527
|
+
[TypeDefinitionExecuteTypeDefinitionProvider]: executeTypeDefinitionProvider,
|
|
4528
|
+
[WorkspaceSetPath]: setWorkspacePath
|
|
4543
4529
|
};
|
|
4544
4530
|
|
|
4545
|
-
const
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4531
|
+
const listen = async () => {
|
|
4532
|
+
const rpc = await WebWorkerRpcClient.create({
|
|
4533
|
+
commandMap: commandMap
|
|
4534
|
+
});
|
|
4535
|
+
setRpc(rpc);
|
|
4536
|
+
};
|
|
4537
|
+
|
|
4538
|
+
const main = async () => {
|
|
4539
|
+
setup({
|
|
4540
|
+
errorConstructor: Error,
|
|
4541
|
+
global: globalThis
|
|
4542
|
+
});
|
|
4543
|
+
await listen();
|
|
4549
4544
|
};
|
|
4545
|
+
|
|
4546
|
+
main();
|