@lvce-editor/extension-host-worker 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensionHostWorkerMain.js +183 -1133
- package/package.json +7 -55
|
@@ -36,9 +36,6 @@ let AssertionError$1 = class AssertionError extends Error {
|
|
|
36
36
|
this.name = 'AssertionError';
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
|
|
40
|
-
// TODO consider using an assertion library like https://github.com/alexreardon/tiny-invariant, https://github.com/tj/better-assert
|
|
41
|
-
|
|
42
39
|
const getType$3 = value => {
|
|
43
40
|
switch (typeof value) {
|
|
44
41
|
case 'number':
|
|
@@ -310,7 +307,7 @@ const get$3 = textDocumentId => {
|
|
|
310
307
|
const textDocument = getDocument(textDocumentId);
|
|
311
308
|
return textDocument;
|
|
312
309
|
};
|
|
313
|
-
const getText
|
|
310
|
+
const getText = textDocument => {
|
|
314
311
|
return textDocument.text;
|
|
315
312
|
};
|
|
316
313
|
const setLanguageId = (textDocumentId, languageId) => {
|
|
@@ -334,32 +331,38 @@ class NoProviderFoundError extends Error {
|
|
|
334
331
|
}
|
|
335
332
|
}
|
|
336
333
|
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
for (const errorPrefix of errorPrefixes) {
|
|
341
|
-
if (stringifiedError.startsWith(errorPrefix)) {
|
|
342
|
-
return stringifiedError.slice(errorPrefix.length);
|
|
343
|
-
}
|
|
334
|
+
const normalizeLine$1 = line => {
|
|
335
|
+
if (line.startsWith('Error: ')) {
|
|
336
|
+
return line.slice(`Error: `.length);
|
|
344
337
|
}
|
|
345
|
-
|
|
338
|
+
if (line.startsWith('VError: ')) {
|
|
339
|
+
return line.slice(`VError: `.length);
|
|
340
|
+
}
|
|
341
|
+
return line;
|
|
346
342
|
};
|
|
347
343
|
const getCombinedMessage$1 = (error, message) => {
|
|
348
|
-
const stringifiedError =
|
|
344
|
+
const stringifiedError = normalizeLine$1(`${error}`);
|
|
349
345
|
if (message) {
|
|
350
346
|
return `${message}: ${stringifiedError}`;
|
|
351
347
|
}
|
|
352
|
-
return
|
|
348
|
+
return stringifiedError;
|
|
349
|
+
};
|
|
350
|
+
const NewLine$3 = '\n';
|
|
351
|
+
const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
352
|
+
return string.indexOf(NewLine$3, startIndex);
|
|
353
353
|
};
|
|
354
354
|
const mergeStacks$1 = (parent, child) => {
|
|
355
355
|
if (!child) {
|
|
356
356
|
return parent;
|
|
357
357
|
}
|
|
358
|
-
const parentNewLineIndex = parent
|
|
359
|
-
const childNewLineIndex = child
|
|
358
|
+
const parentNewLineIndex = getNewLineIndex$2(parent);
|
|
359
|
+
const childNewLineIndex = getNewLineIndex$2(child);
|
|
360
|
+
if (childNewLineIndex === -1) {
|
|
361
|
+
return parent;
|
|
362
|
+
}
|
|
360
363
|
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
361
364
|
const childRest = child.slice(childNewLineIndex);
|
|
362
|
-
const childFirstLine = child.slice(0, childNewLineIndex);
|
|
365
|
+
const childFirstLine = normalizeLine$1(child.slice(0, childNewLineIndex));
|
|
363
366
|
if (parentFirstLine.includes(childFirstLine)) {
|
|
364
367
|
return parentFirstLine + childRest;
|
|
365
368
|
}
|
|
@@ -377,6 +380,10 @@ let VError$1 = class VError extends Error {
|
|
|
377
380
|
// @ts-ignore
|
|
378
381
|
this.codeFrame = error.codeFrame;
|
|
379
382
|
}
|
|
383
|
+
if (error.code) {
|
|
384
|
+
// @ts-ignore
|
|
385
|
+
this.code = error.code;
|
|
386
|
+
}
|
|
380
387
|
}
|
|
381
388
|
};
|
|
382
389
|
|
|
@@ -505,17 +512,17 @@ const improveValidationError = (name, validationError) => {
|
|
|
505
512
|
const post = improveValidationErrorPostMessage(validationError, camelCaseName);
|
|
506
513
|
return pre + ': ' + post;
|
|
507
514
|
};
|
|
508
|
-
|
|
515
|
+
class NonError extends Error {
|
|
509
516
|
name = 'NonError';
|
|
510
517
|
constructor(message) {
|
|
511
518
|
super(message);
|
|
512
519
|
}
|
|
513
|
-
}
|
|
520
|
+
}
|
|
514
521
|
|
|
515
522
|
// ensureError based on https://github.com/sindresorhus/ensure-error/blob/main/index.ts (License MIT)
|
|
516
|
-
const ensureError
|
|
523
|
+
const ensureError = input => {
|
|
517
524
|
if (!(input instanceof Error)) {
|
|
518
|
-
return new NonError
|
|
525
|
+
return new NonError(input);
|
|
519
526
|
}
|
|
520
527
|
return input;
|
|
521
528
|
};
|
|
@@ -550,7 +557,7 @@ const registerMethod = ({
|
|
|
550
557
|
}
|
|
551
558
|
return result;
|
|
552
559
|
} catch (error) {
|
|
553
|
-
const actualError = ensureError
|
|
560
|
+
const actualError = ensureError(error);
|
|
554
561
|
const spacedOutName = spaceOut(name);
|
|
555
562
|
if (actualError && actualError.message) {
|
|
556
563
|
if (actualError.message === 'provider[methodName] is not a function') {
|
|
@@ -565,7 +572,7 @@ const registerMethod = ({
|
|
|
565
572
|
}
|
|
566
573
|
};
|
|
567
574
|
};
|
|
568
|
-
const create$
|
|
575
|
+
const create$9 = ({
|
|
569
576
|
name,
|
|
570
577
|
resultShape,
|
|
571
578
|
executeKey = '',
|
|
@@ -609,15 +616,15 @@ const create$a = ({
|
|
|
609
616
|
|
|
610
617
|
const Array$1 = 'array';
|
|
611
618
|
const Boolean = 'boolean';
|
|
612
|
-
const Number
|
|
619
|
+
const Number = 'number';
|
|
613
620
|
const Object$1 = 'object';
|
|
614
|
-
const String
|
|
621
|
+
const String = 'string';
|
|
615
622
|
|
|
616
623
|
const {
|
|
617
624
|
registerBraceCompletionProvider,
|
|
618
625
|
executeBraceCompletionProvider,
|
|
619
626
|
reset: reset$9
|
|
620
|
-
} = create$
|
|
627
|
+
} = create$9({
|
|
621
628
|
name: 'BraceCompletion',
|
|
622
629
|
resultShape: {
|
|
623
630
|
type: Boolean
|
|
@@ -627,7 +634,7 @@ const {
|
|
|
627
634
|
const {
|
|
628
635
|
registerClosingTagProvider,
|
|
629
636
|
executeClosingTagProvider
|
|
630
|
-
} = create$
|
|
637
|
+
} = create$9({
|
|
631
638
|
name: 'ClosingTag',
|
|
632
639
|
returnUndefinedWhenNoProviderFound: true,
|
|
633
640
|
resultShape: {
|
|
@@ -639,7 +646,7 @@ const {
|
|
|
639
646
|
const {
|
|
640
647
|
registerCodeActionProvider,
|
|
641
648
|
executeCodeActionProvider
|
|
642
|
-
} = create$
|
|
649
|
+
} = create$9({
|
|
643
650
|
name: 'CodeAction',
|
|
644
651
|
resultShape: {
|
|
645
652
|
type: Array$1,
|
|
@@ -722,7 +729,7 @@ const {
|
|
|
722
729
|
registerCompletionProvider,
|
|
723
730
|
executeCompletionProvider,
|
|
724
731
|
executeresolveCompletionItemProvider
|
|
725
|
-
} = create$
|
|
732
|
+
} = create$9({
|
|
726
733
|
name: 'Completion',
|
|
727
734
|
resultShape: {
|
|
728
735
|
type: Array$1,
|
|
@@ -752,10 +759,10 @@ const setConfigurations = preferences => {
|
|
|
752
759
|
state$9.configuration = preferences;
|
|
753
760
|
};
|
|
754
761
|
|
|
755
|
-
const Two
|
|
762
|
+
const Two = '2.0';
|
|
756
763
|
const create$4$1 = (method, params) => {
|
|
757
764
|
return {
|
|
758
|
-
jsonrpc: Two
|
|
765
|
+
jsonrpc: Two,
|
|
759
766
|
method,
|
|
760
767
|
params
|
|
761
768
|
};
|
|
@@ -857,7 +864,7 @@ const create$2$1 = (method, params) => {
|
|
|
857
864
|
promise
|
|
858
865
|
} = registerPromise();
|
|
859
866
|
const message = {
|
|
860
|
-
jsonrpc: Two
|
|
867
|
+
jsonrpc: Two,
|
|
861
868
|
method,
|
|
862
869
|
params,
|
|
863
870
|
id
|
|
@@ -867,12 +874,12 @@ const create$2$1 = (method, params) => {
|
|
|
867
874
|
promise
|
|
868
875
|
};
|
|
869
876
|
};
|
|
870
|
-
|
|
877
|
+
class JsonRpcError extends Error {
|
|
871
878
|
constructor(message) {
|
|
872
879
|
super(message);
|
|
873
880
|
this.name = 'JsonRpcError';
|
|
874
881
|
}
|
|
875
|
-
}
|
|
882
|
+
}
|
|
876
883
|
const NewLine$2 = '\n';
|
|
877
884
|
const DomException = 'DOMException';
|
|
878
885
|
const ReferenceError$1 = 'ReferenceError';
|
|
@@ -928,21 +935,21 @@ const getParentStack = error => {
|
|
|
928
935
|
}
|
|
929
936
|
return parentStack;
|
|
930
937
|
};
|
|
931
|
-
const joinLines$
|
|
938
|
+
const joinLines$1 = lines => {
|
|
932
939
|
return lines.join(NewLine$2);
|
|
933
940
|
};
|
|
934
|
-
const MethodNotFound
|
|
941
|
+
const MethodNotFound = -32601;
|
|
935
942
|
const Custom = -32001;
|
|
936
|
-
const splitLines$
|
|
943
|
+
const splitLines$1 = lines => {
|
|
937
944
|
return lines.split(NewLine$2);
|
|
938
945
|
};
|
|
939
946
|
const restoreJsonRpcError = error => {
|
|
940
947
|
if (error && error instanceof Error) {
|
|
941
948
|
return error;
|
|
942
949
|
}
|
|
943
|
-
const currentStack = joinLines$
|
|
944
|
-
if (error && error.code && error.code === MethodNotFound
|
|
945
|
-
const restoredError = new JsonRpcError
|
|
950
|
+
const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(1));
|
|
951
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
952
|
+
const restoredError = new JsonRpcError(error.message);
|
|
946
953
|
const parentStack = getParentStack(error);
|
|
947
954
|
restoredError.stack = parentStack + NewLine$2 + currentStack;
|
|
948
955
|
return restoredError;
|
|
@@ -996,7 +1003,7 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
996
1003
|
if ('result' in responseMessage) {
|
|
997
1004
|
return responseMessage.result;
|
|
998
1005
|
}
|
|
999
|
-
throw new JsonRpcError
|
|
1006
|
+
throw new JsonRpcError('unexpected response message');
|
|
1000
1007
|
};
|
|
1001
1008
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
1002
1009
|
const getType = prettyError => {
|
|
@@ -1011,7 +1018,7 @@ const getType = prettyError => {
|
|
|
1011
1018
|
const getErrorProperty = (error, prettyError) => {
|
|
1012
1019
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
1013
1020
|
return {
|
|
1014
|
-
code: MethodNotFound
|
|
1021
|
+
code: MethodNotFound,
|
|
1015
1022
|
message: error.message,
|
|
1016
1023
|
data: error.stack
|
|
1017
1024
|
};
|
|
@@ -1030,34 +1037,34 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1030
1037
|
};
|
|
1031
1038
|
const create$1$1 = (message, error) => {
|
|
1032
1039
|
return {
|
|
1033
|
-
jsonrpc: Two
|
|
1040
|
+
jsonrpc: Two,
|
|
1034
1041
|
id: message.id,
|
|
1035
1042
|
error
|
|
1036
1043
|
};
|
|
1037
1044
|
};
|
|
1038
|
-
const getErrorResponse
|
|
1045
|
+
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
1039
1046
|
const prettyError = preparePrettyError(error);
|
|
1040
1047
|
logError(error, prettyError);
|
|
1041
1048
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
1042
1049
|
return create$1$1(message, errorProperty);
|
|
1043
1050
|
};
|
|
1044
|
-
const create$
|
|
1051
|
+
const create$8 = (message, result) => {
|
|
1045
1052
|
return {
|
|
1046
|
-
jsonrpc: Two
|
|
1053
|
+
jsonrpc: Two,
|
|
1047
1054
|
id: message.id,
|
|
1048
1055
|
result: result ?? null
|
|
1049
1056
|
};
|
|
1050
1057
|
};
|
|
1051
|
-
const getSuccessResponse
|
|
1058
|
+
const getSuccessResponse = (message, result) => {
|
|
1052
1059
|
const resultProperty = result ?? null;
|
|
1053
|
-
return create$
|
|
1060
|
+
return create$8(message, resultProperty);
|
|
1054
1061
|
};
|
|
1055
|
-
const getResponse
|
|
1062
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
1056
1063
|
try {
|
|
1057
1064
|
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
1058
|
-
return getSuccessResponse
|
|
1065
|
+
return getSuccessResponse(message, result);
|
|
1059
1066
|
} catch (error) {
|
|
1060
|
-
return getErrorResponse
|
|
1067
|
+
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
1061
1068
|
}
|
|
1062
1069
|
};
|
|
1063
1070
|
const defaultPreparePrettyError = error => {
|
|
@@ -1070,7 +1077,7 @@ const defaultRequiresSocket = () => {
|
|
|
1070
1077
|
return false;
|
|
1071
1078
|
};
|
|
1072
1079
|
const defaultResolve = resolve;
|
|
1073
|
-
const handleJsonRpcMessage
|
|
1080
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
1074
1081
|
let message;
|
|
1075
1082
|
let ipc;
|
|
1076
1083
|
let execute;
|
|
@@ -1098,11 +1105,11 @@ const handleJsonRpcMessage$1 = async (...args) => {
|
|
|
1098
1105
|
}
|
|
1099
1106
|
if ('id' in message) {
|
|
1100
1107
|
if ('method' in message) {
|
|
1101
|
-
const response = await getResponse
|
|
1108
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1102
1109
|
try {
|
|
1103
1110
|
ipc.send(response);
|
|
1104
1111
|
} catch (error) {
|
|
1105
|
-
const errorResponse = getErrorResponse
|
|
1112
|
+
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
1106
1113
|
ipc.send(errorResponse);
|
|
1107
1114
|
}
|
|
1108
1115
|
return;
|
|
@@ -1111,10 +1118,10 @@ const handleJsonRpcMessage$1 = async (...args) => {
|
|
|
1111
1118
|
return;
|
|
1112
1119
|
}
|
|
1113
1120
|
if ('method' in message) {
|
|
1114
|
-
await getResponse
|
|
1121
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1115
1122
|
return;
|
|
1116
1123
|
}
|
|
1117
|
-
throw new JsonRpcError
|
|
1124
|
+
throw new JsonRpcError('unexpected message');
|
|
1118
1125
|
};
|
|
1119
1126
|
const send$1 = (transport, method, ...params) => {
|
|
1120
1127
|
const message = create$4$1(method, params);
|
|
@@ -1141,31 +1148,43 @@ const invokeAndTransfer$1 = async (ipc, method, ...params) => {
|
|
|
1141
1148
|
return result;
|
|
1142
1149
|
};
|
|
1143
1150
|
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1151
|
+
const processName = `extension host worker`;
|
|
1152
|
+
|
|
1153
|
+
class CommandNotFoundError extends Error {
|
|
1154
|
+
constructor(id) {
|
|
1155
|
+
super(`Command "${id}" not found (${processName})`);
|
|
1156
|
+
this.name = 'CommandNotFoundError';
|
|
1157
|
+
// @ts-ignore
|
|
1158
|
+
this.code = E_COMMAND_NOT_FOUND$1;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
const state$7 = {};
|
|
1163
|
+
const register = commandMap => {
|
|
1164
|
+
Object.assign(state$7, commandMap);
|
|
1146
1165
|
};
|
|
1147
1166
|
const execute = (method, ...params) => {
|
|
1148
1167
|
// @ts-ignore
|
|
1149
|
-
const fn = state$7
|
|
1168
|
+
const fn = state$7[method];
|
|
1150
1169
|
// @ts-ignore
|
|
1151
1170
|
if (!fn) {
|
|
1152
|
-
throw new
|
|
1171
|
+
throw new CommandNotFoundError(method);
|
|
1153
1172
|
}
|
|
1154
1173
|
// @ts-ignore
|
|
1155
1174
|
return fn(...params);
|
|
1156
1175
|
};
|
|
1157
1176
|
|
|
1158
|
-
const requiresSocket = () => {
|
|
1177
|
+
const requiresSocket$1 = () => {
|
|
1159
1178
|
return false;
|
|
1160
1179
|
};
|
|
1161
|
-
const preparePrettyError = error => {
|
|
1180
|
+
const preparePrettyError$1 = error => {
|
|
1162
1181
|
return error;
|
|
1163
1182
|
};
|
|
1164
1183
|
const logError$1 = error => {
|
|
1165
1184
|
// handled by renderer worker
|
|
1166
1185
|
};
|
|
1167
1186
|
const handleMessage = event => {
|
|
1168
|
-
return handleJsonRpcMessage
|
|
1187
|
+
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError$1, logError$1, requiresSocket$1);
|
|
1169
1188
|
};
|
|
1170
1189
|
|
|
1171
1190
|
const handleIpc = ipc => {
|
|
@@ -1328,20 +1347,20 @@ const {
|
|
|
1328
1347
|
registerDefinitionProvider,
|
|
1329
1348
|
executeDefinitionProvider,
|
|
1330
1349
|
reset: reset$8
|
|
1331
|
-
} = create$
|
|
1350
|
+
} = create$9({
|
|
1332
1351
|
name: 'Definition',
|
|
1333
1352
|
resultShape: {
|
|
1334
1353
|
allowUndefined: true,
|
|
1335
1354
|
type: Object$1,
|
|
1336
1355
|
properties: {
|
|
1337
1356
|
uri: {
|
|
1338
|
-
type: String
|
|
1357
|
+
type: String
|
|
1339
1358
|
},
|
|
1340
1359
|
startOffset: {
|
|
1341
|
-
type: Number
|
|
1360
|
+
type: Number
|
|
1342
1361
|
},
|
|
1343
1362
|
endOffset: {
|
|
1344
|
-
type: Number
|
|
1363
|
+
type: Number
|
|
1345
1364
|
}
|
|
1346
1365
|
}
|
|
1347
1366
|
}
|
|
@@ -1350,7 +1369,7 @@ const {
|
|
|
1350
1369
|
const {
|
|
1351
1370
|
registerDiagnosticProvider,
|
|
1352
1371
|
executeDiagnosticProvider
|
|
1353
|
-
} = create$
|
|
1372
|
+
} = create$9({
|
|
1354
1373
|
name: 'Diagnostic',
|
|
1355
1374
|
resultShape: {
|
|
1356
1375
|
type: Array$1,
|
|
@@ -1518,7 +1537,7 @@ const {
|
|
|
1518
1537
|
registerFormattingProvider,
|
|
1519
1538
|
executeFormattingProvider,
|
|
1520
1539
|
reset: reset$7
|
|
1521
|
-
} = create$
|
|
1540
|
+
} = create$9({
|
|
1522
1541
|
name: 'Formatting',
|
|
1523
1542
|
executeKey: 'format',
|
|
1524
1543
|
resultShape: {
|
|
@@ -1528,13 +1547,13 @@ const {
|
|
|
1528
1547
|
type: Object$1,
|
|
1529
1548
|
properties: {
|
|
1530
1549
|
startOffset: {
|
|
1531
|
-
type: Number
|
|
1550
|
+
type: Number
|
|
1532
1551
|
},
|
|
1533
1552
|
endOffset: {
|
|
1534
|
-
type: Number
|
|
1553
|
+
type: Number
|
|
1535
1554
|
},
|
|
1536
1555
|
inserted: {
|
|
1537
|
-
type: String
|
|
1556
|
+
type: String
|
|
1538
1557
|
}
|
|
1539
1558
|
}
|
|
1540
1559
|
}
|
|
@@ -1580,7 +1599,7 @@ const {
|
|
|
1580
1599
|
registerHoverProvider,
|
|
1581
1600
|
executeHoverProvider,
|
|
1582
1601
|
reset: reset$6
|
|
1583
|
-
} = create$
|
|
1602
|
+
} = create$9({
|
|
1584
1603
|
name: 'Hover',
|
|
1585
1604
|
resultShape: {
|
|
1586
1605
|
allowUndefined: true,
|
|
@@ -1593,7 +1612,7 @@ const {
|
|
|
1593
1612
|
registerImplementationProvider,
|
|
1594
1613
|
executeImplementationProvider,
|
|
1595
1614
|
reset: reset$5
|
|
1596
|
-
} = create$
|
|
1615
|
+
} = create$9({
|
|
1597
1616
|
name: 'Implementation',
|
|
1598
1617
|
resultShape: {
|
|
1599
1618
|
type: Array$1,
|
|
@@ -1620,7 +1639,7 @@ const getModule$3 = method => {
|
|
|
1620
1639
|
}
|
|
1621
1640
|
};
|
|
1622
1641
|
|
|
1623
|
-
const create$
|
|
1642
|
+
const create$7 = async ({
|
|
1624
1643
|
method,
|
|
1625
1644
|
...options
|
|
1626
1645
|
}) => {
|
|
@@ -1647,7 +1666,7 @@ const getModule$2 = method => {
|
|
|
1647
1666
|
}
|
|
1648
1667
|
};
|
|
1649
1668
|
|
|
1650
|
-
const create$
|
|
1669
|
+
const create$6 = async ({
|
|
1651
1670
|
method,
|
|
1652
1671
|
...options
|
|
1653
1672
|
}) => {
|
|
@@ -1668,12 +1687,12 @@ const createNodeRpc = async ({
|
|
|
1668
1687
|
try {
|
|
1669
1688
|
string(path);
|
|
1670
1689
|
fn(execute);
|
|
1671
|
-
const ipc = await create$
|
|
1690
|
+
const ipc = await create$7({
|
|
1672
1691
|
method: ElectronMessagePort,
|
|
1673
1692
|
type: 'extension-host-helper-process',
|
|
1674
1693
|
name
|
|
1675
1694
|
});
|
|
1676
|
-
const rpc = await create$
|
|
1695
|
+
const rpc = await create$6({
|
|
1677
1696
|
ipc,
|
|
1678
1697
|
method: JsonRpc,
|
|
1679
1698
|
execute
|
|
@@ -1707,7 +1726,7 @@ const {
|
|
|
1707
1726
|
executeReferenceProvider,
|
|
1708
1727
|
executefileReferenceProvider,
|
|
1709
1728
|
reset: reset$4
|
|
1710
|
-
} = create$
|
|
1729
|
+
} = create$9({
|
|
1711
1730
|
name: 'Reference',
|
|
1712
1731
|
resultShape: {
|
|
1713
1732
|
type: Array$1,
|
|
@@ -1734,7 +1753,7 @@ const {
|
|
|
1734
1753
|
executeRenameProvider,
|
|
1735
1754
|
executeprepareRenameProvider,
|
|
1736
1755
|
reset: reset$3
|
|
1737
|
-
} = create$
|
|
1756
|
+
} = create$9({
|
|
1738
1757
|
name: 'Rename',
|
|
1739
1758
|
resultShape: {
|
|
1740
1759
|
type: Object$1,
|
|
@@ -1774,12 +1793,12 @@ const createRpcWithId = async ({
|
|
|
1774
1793
|
if (!info) {
|
|
1775
1794
|
throw new Error(`rpc with id ${id} not found`);
|
|
1776
1795
|
}
|
|
1777
|
-
const ipc = await create$
|
|
1796
|
+
const ipc = await create$7({
|
|
1778
1797
|
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
1779
1798
|
url: extensionHostSubWorkerUrl,
|
|
1780
1799
|
name: info.name
|
|
1781
1800
|
});
|
|
1782
|
-
const rpc = await create$
|
|
1801
|
+
const rpc = await create$6({
|
|
1783
1802
|
ipc,
|
|
1784
1803
|
method: JsonRpc,
|
|
1785
1804
|
execute
|
|
@@ -1820,12 +1839,12 @@ const createRpc = async ({
|
|
|
1820
1839
|
if (contentSecurityPolicy) {
|
|
1821
1840
|
await set(url, contentSecurityPolicy);
|
|
1822
1841
|
}
|
|
1823
|
-
const ipc = await create$
|
|
1842
|
+
const ipc = await create$7({
|
|
1824
1843
|
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
1825
1844
|
url: extensionHostSubWorkerUrl,
|
|
1826
1845
|
name
|
|
1827
1846
|
});
|
|
1828
|
-
const rpc = await create$
|
|
1847
|
+
const rpc = await create$6({
|
|
1829
1848
|
ipc,
|
|
1830
1849
|
method: JsonRpc,
|
|
1831
1850
|
execute
|
|
@@ -1841,7 +1860,7 @@ const {
|
|
|
1841
1860
|
registerSelectionProvider,
|
|
1842
1861
|
executeSelectionProvider,
|
|
1843
1862
|
reset: reset$2
|
|
1844
|
-
} = create$
|
|
1863
|
+
} = create$9({
|
|
1845
1864
|
name: 'Selection',
|
|
1846
1865
|
resultShape: {
|
|
1847
1866
|
allowUndefined: true,
|
|
@@ -1949,7 +1968,7 @@ const {
|
|
|
1949
1968
|
registerTabCompletionProvider,
|
|
1950
1969
|
executeTabCompletionProvider,
|
|
1951
1970
|
reset: reset$1
|
|
1952
|
-
} = create$
|
|
1971
|
+
} = create$9({
|
|
1953
1972
|
name: 'TabCompletion',
|
|
1954
1973
|
resultShape: {
|
|
1955
1974
|
type: Object$1,
|
|
@@ -1990,20 +2009,20 @@ const {
|
|
|
1990
2009
|
registerTypeDefinitionProvider,
|
|
1991
2010
|
executeTypeDefinitionProvider,
|
|
1992
2011
|
reset
|
|
1993
|
-
} = create$
|
|
2012
|
+
} = create$9({
|
|
1994
2013
|
name: 'TypeDefinition',
|
|
1995
2014
|
resultShape: {
|
|
1996
2015
|
allowUndefined: true,
|
|
1997
2016
|
type: Object$1,
|
|
1998
2017
|
properties: {
|
|
1999
2018
|
uri: {
|
|
2000
|
-
type: String
|
|
2019
|
+
type: String
|
|
2001
2020
|
},
|
|
2002
2021
|
startOffset: {
|
|
2003
|
-
type: Number
|
|
2022
|
+
type: Number
|
|
2004
2023
|
},
|
|
2005
2024
|
endOffset: {
|
|
2006
|
-
type: Number
|
|
2025
|
+
type: Number
|
|
2007
2026
|
}
|
|
2008
2027
|
}
|
|
2009
2028
|
}
|
|
@@ -2017,7 +2036,7 @@ const createWorker = async ({
|
|
|
2017
2036
|
string(method);
|
|
2018
2037
|
string(url);
|
|
2019
2038
|
string(name);
|
|
2020
|
-
const ipc = create$
|
|
2039
|
+
const ipc = create$7({
|
|
2021
2040
|
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
2022
2041
|
url,
|
|
2023
2042
|
name
|
|
@@ -2247,7 +2266,7 @@ const api = {
|
|
|
2247
2266
|
registerTabCompletionProvider: registerTabCompletionProvider,
|
|
2248
2267
|
executeTabCompletionProvider: executeTabCompletionProvider,
|
|
2249
2268
|
// Text Document
|
|
2250
|
-
getTextFromTextDocument: getText
|
|
2269
|
+
getTextFromTextDocument: getText,
|
|
2251
2270
|
// Text Search
|
|
2252
2271
|
registerTextSearchProvider: registerTextSearchProvider,
|
|
2253
2272
|
executeTextSearchProvider: executeTextSearchProvider,
|
|
@@ -2265,17 +2284,6 @@ const api = {
|
|
|
2265
2284
|
getWorkspaceFolder: getWorkspaceFolder
|
|
2266
2285
|
};
|
|
2267
2286
|
|
|
2268
|
-
const processName = `extension host worker`;
|
|
2269
|
-
|
|
2270
|
-
class CommandNotFoundError extends Error {
|
|
2271
|
-
constructor(id) {
|
|
2272
|
-
super(`Command "${id}" not found (${processName})`);
|
|
2273
|
-
this.name = 'CommandNotFoundError';
|
|
2274
|
-
// @ts-ignore
|
|
2275
|
-
this.code = E_COMMAND_NOT_FOUND$1;
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
|
|
2279
2287
|
const BraceCompletionExecuteBraceCompletionProvider = 'ExtensionHostBraceCompletion.executeBraceCompletionProvider';
|
|
2280
2288
|
const ClosingTagExecuteClosingTagProvider = 'ExtensionHostClosingTag.executeClosingTagProvider';
|
|
2281
2289
|
const CommandExecute = 'ExtensionHostCommand.executeCommand';
|
|
@@ -2315,7 +2323,7 @@ const WorkspaceSetPath = 'Workspace.setWorkspacePath';
|
|
|
2315
2323
|
const SelectionExecuteSelectionProvider = 'ExtensionHostSelection.executeSelectionProvider';
|
|
2316
2324
|
const ConfigurationSetConfiguration = 'ExtensionHostConfiguration.setConfiguration';
|
|
2317
2325
|
|
|
2318
|
-
const create$
|
|
2326
|
+
const create$5 = () => {
|
|
2319
2327
|
return {
|
|
2320
2328
|
finished: false
|
|
2321
2329
|
};
|
|
@@ -2750,7 +2758,7 @@ const activate = async (extension, absolutePath) => {
|
|
|
2750
2758
|
string(absolutePath);
|
|
2751
2759
|
const module = await importScript(absolutePath);
|
|
2752
2760
|
handleRpcInfos(extension);
|
|
2753
|
-
const token = create$
|
|
2761
|
+
const token = create$5();
|
|
2754
2762
|
try {
|
|
2755
2763
|
await Promise.race([module.activate(extension), rejectAfterTimeout(activationTimeout, token)]);
|
|
2756
2764
|
} catch (error) {
|
|
@@ -2968,17 +2976,17 @@ const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
|
2968
2976
|
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
2969
2977
|
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
2970
2978
|
const NewLine$1 = '\n';
|
|
2971
|
-
const joinLines
|
|
2979
|
+
const joinLines = lines => {
|
|
2972
2980
|
return lines.join(NewLine$1);
|
|
2973
2981
|
};
|
|
2974
|
-
const splitLines
|
|
2982
|
+
const splitLines = lines => {
|
|
2975
2983
|
return lines.split(NewLine$1);
|
|
2976
2984
|
};
|
|
2977
2985
|
const isModuleNotFoundMessage = line => {
|
|
2978
2986
|
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
2979
2987
|
};
|
|
2980
2988
|
const getModuleNotFoundError = stderr => {
|
|
2981
|
-
const lines = splitLines
|
|
2989
|
+
const lines = splitLines(stderr);
|
|
2982
2990
|
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
2983
2991
|
const message = lines[messageIndex];
|
|
2984
2992
|
return {
|
|
@@ -3002,7 +3010,7 @@ const isMessageCodeBlockEndIndex = line => {
|
|
|
3002
3010
|
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
3003
3011
|
};
|
|
3004
3012
|
const getMessageCodeBlock = stderr => {
|
|
3005
|
-
const lines = splitLines
|
|
3013
|
+
const lines = splitLines(stderr);
|
|
3006
3014
|
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
3007
3015
|
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
3008
3016
|
const relevantLines = lines.slice(startIndex, endIndex);
|
|
@@ -3041,7 +3049,7 @@ const getDetails = lines => {
|
|
|
3041
3049
|
const index = lines.findIndex(isNormalStackLine);
|
|
3042
3050
|
if (index === -1) {
|
|
3043
3051
|
return {
|
|
3044
|
-
actualMessage: joinLines
|
|
3052
|
+
actualMessage: joinLines(lines),
|
|
3045
3053
|
rest: []
|
|
3046
3054
|
};
|
|
3047
3055
|
}
|
|
@@ -3066,7 +3074,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
3066
3074
|
if (isModuleNotFoundError(stderr)) {
|
|
3067
3075
|
return getModuleNotFoundError(stderr);
|
|
3068
3076
|
}
|
|
3069
|
-
const lines = splitLines
|
|
3077
|
+
const lines = splitLines(stderr);
|
|
3070
3078
|
const {
|
|
3071
3079
|
actualMessage,
|
|
3072
3080
|
rest
|
|
@@ -3299,925 +3307,64 @@ const handleMessagePort = port => {
|
|
|
3299
3307
|
ipc.send('ready');
|
|
3300
3308
|
};
|
|
3301
3309
|
|
|
3302
|
-
const
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
case SourceControlAdd:
|
|
3357
|
-
return add;
|
|
3358
|
-
case SourceControlDiscard:
|
|
3359
|
-
return discard;
|
|
3360
|
-
case SourceControlGetEnabledProviderIds:
|
|
3361
|
-
return getEnabledProviderIds;
|
|
3362
|
-
case SourceControlGetGroups:
|
|
3363
|
-
return getGroups;
|
|
3364
|
-
case 'ExtensionHostDebug.listProcesses':
|
|
3365
|
-
return listProcesses;
|
|
3366
|
-
case 'ExtensionHostDebug.pause':
|
|
3367
|
-
return pause;
|
|
3368
|
-
case 'ExtensionHostDebug.resume':
|
|
3369
|
-
return resume;
|
|
3370
|
-
case 'ExtensionHostDebug.setPauseOnException':
|
|
3371
|
-
return setPauseOnException;
|
|
3372
|
-
case 'ExtensionHostDebug.start':
|
|
3373
|
-
return start;
|
|
3374
|
-
case 'ExtensionHostDebug.stepOver':
|
|
3375
|
-
return stepOver;
|
|
3376
|
-
case 'ExtensionHostDebug.stepOut':
|
|
3377
|
-
return stepOut;
|
|
3378
|
-
case 'ExtensionHostDebug.stepInto':
|
|
3379
|
-
return stepInto;
|
|
3380
|
-
case 'ExtensionHostDebug.getProperties':
|
|
3381
|
-
return getProperties;
|
|
3382
|
-
case 'ExtensionHostDebug.evaluate':
|
|
3383
|
-
return evaluate;
|
|
3384
|
-
case 'ExtensionHostDebug.setPauseOnExceptions':
|
|
3385
|
-
return setPauseOnExceptions;
|
|
3386
|
-
case ClosingTagExecuteClosingTagProvider:
|
|
3387
|
-
return executeClosingTagProvider;
|
|
3388
|
-
case ImplementationExecuteImplementationProvider:
|
|
3389
|
-
return executeImplementationProvider;
|
|
3390
|
-
case HoverExecute:
|
|
3391
|
-
return executeHoverProvider;
|
|
3392
|
-
case StatusBarGetStatusBarItems:
|
|
3393
|
-
return getStatusBarItems;
|
|
3394
|
-
case StatusBarRegisterChangeListener:
|
|
3395
|
-
return registerChangeListener;
|
|
3396
|
-
case OrganizeImportsExecute:
|
|
3397
|
-
return executeOrganizeImports;
|
|
3398
|
-
case SelectionExecuteSelectionProvider:
|
|
3399
|
-
return executeSelectionProvider;
|
|
3400
|
-
case ConfigurationSetConfiguration:
|
|
3401
|
-
return setConfigurations;
|
|
3402
|
-
case 'HandleMessagePort.handleMessagePort':
|
|
3403
|
-
return handleMessagePort;
|
|
3404
|
-
case 'ExtensionHostWebView.create':
|
|
3405
|
-
return createWebView;
|
|
3406
|
-
case 'ExtensionHostWebView.dispose':
|
|
3407
|
-
return disposeWebView;
|
|
3408
|
-
case 'ExtensionHostWebView.load':
|
|
3409
|
-
return load;
|
|
3410
|
-
default:
|
|
3411
|
-
throw new CommandNotFoundError(method);
|
|
3412
|
-
}
|
|
3413
|
-
};
|
|
3414
|
-
|
|
3415
|
-
class HTTPError extends Error {
|
|
3416
|
-
response;
|
|
3417
|
-
request;
|
|
3418
|
-
options;
|
|
3419
|
-
constructor(response, request, options) {
|
|
3420
|
-
const code = response.status || response.status === 0 ? response.status : '';
|
|
3421
|
-
const title = response.statusText || '';
|
|
3422
|
-
const status = `${code} ${title}`.trim();
|
|
3423
|
-
const reason = status ? `status code ${status}` : 'an unknown error';
|
|
3424
|
-
super(`Request failed with ${reason}: ${request.method} ${request.url}`);
|
|
3425
|
-
this.name = 'HTTPError';
|
|
3426
|
-
this.response = response;
|
|
3427
|
-
this.request = request;
|
|
3428
|
-
this.options = options;
|
|
3429
|
-
}
|
|
3430
|
-
}
|
|
3431
|
-
|
|
3432
|
-
class TimeoutError extends Error {
|
|
3433
|
-
request;
|
|
3434
|
-
constructor(request) {
|
|
3435
|
-
super(`Request timed out: ${request.method} ${request.url}`);
|
|
3436
|
-
this.name = 'TimeoutError';
|
|
3437
|
-
this.request = request;
|
|
3438
|
-
}
|
|
3439
|
-
}
|
|
3440
|
-
|
|
3441
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
3442
|
-
const isObject = value => value !== null && typeof value === 'object';
|
|
3443
|
-
|
|
3444
|
-
const validateAndMerge = (...sources) => {
|
|
3445
|
-
for (const source of sources) {
|
|
3446
|
-
if ((!isObject(source) || Array.isArray(source)) && source !== undefined) {
|
|
3447
|
-
throw new TypeError('The `options` argument must be an object');
|
|
3448
|
-
}
|
|
3449
|
-
}
|
|
3450
|
-
return deepMerge({}, ...sources);
|
|
3451
|
-
};
|
|
3452
|
-
const mergeHeaders = (source1 = {}, source2 = {}) => {
|
|
3453
|
-
const result = new globalThis.Headers(source1);
|
|
3454
|
-
const isHeadersInstance = source2 instanceof globalThis.Headers;
|
|
3455
|
-
const source = new globalThis.Headers(source2);
|
|
3456
|
-
for (const [key, value] of source.entries()) {
|
|
3457
|
-
if (isHeadersInstance && value === 'undefined' || value === undefined) {
|
|
3458
|
-
result.delete(key);
|
|
3459
|
-
} else {
|
|
3460
|
-
result.set(key, value);
|
|
3461
|
-
}
|
|
3462
|
-
}
|
|
3463
|
-
return result;
|
|
3464
|
-
};
|
|
3465
|
-
function newHookValue(original, incoming, property) {
|
|
3466
|
-
return Object.hasOwn(incoming, property) && incoming[property] === undefined ? [] : deepMerge(original[property] ?? [], incoming[property] ?? []);
|
|
3467
|
-
}
|
|
3468
|
-
const mergeHooks = (original = {}, incoming = {}) => ({
|
|
3469
|
-
beforeRequest: newHookValue(original, incoming, 'beforeRequest'),
|
|
3470
|
-
beforeRetry: newHookValue(original, incoming, 'beforeRetry'),
|
|
3471
|
-
afterResponse: newHookValue(original, incoming, 'afterResponse'),
|
|
3472
|
-
beforeError: newHookValue(original, incoming, 'beforeError')
|
|
3473
|
-
});
|
|
3474
|
-
// TODO: Make this strongly-typed (no `any`).
|
|
3475
|
-
const deepMerge = (...sources) => {
|
|
3476
|
-
let returnValue = {};
|
|
3477
|
-
let headers = {};
|
|
3478
|
-
let hooks = {};
|
|
3479
|
-
for (const source of sources) {
|
|
3480
|
-
if (Array.isArray(source)) {
|
|
3481
|
-
if (!Array.isArray(returnValue)) {
|
|
3482
|
-
returnValue = [];
|
|
3483
|
-
}
|
|
3484
|
-
returnValue = [...returnValue, ...source];
|
|
3485
|
-
} else if (isObject(source)) {
|
|
3486
|
-
for (let [key, value] of Object.entries(source)) {
|
|
3487
|
-
if (isObject(value) && key in returnValue) {
|
|
3488
|
-
value = deepMerge(returnValue[key], value);
|
|
3489
|
-
}
|
|
3490
|
-
returnValue = {
|
|
3491
|
-
...returnValue,
|
|
3492
|
-
[key]: value
|
|
3493
|
-
};
|
|
3494
|
-
}
|
|
3495
|
-
if (isObject(source.hooks)) {
|
|
3496
|
-
hooks = mergeHooks(hooks, source.hooks);
|
|
3497
|
-
returnValue.hooks = hooks;
|
|
3498
|
-
}
|
|
3499
|
-
if (isObject(source.headers)) {
|
|
3500
|
-
headers = mergeHeaders(headers, source.headers);
|
|
3501
|
-
returnValue.headers = headers;
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
return returnValue;
|
|
3506
|
-
};
|
|
3507
|
-
|
|
3508
|
-
const supportsRequestStreams = (() => {
|
|
3509
|
-
let duplexAccessed = false;
|
|
3510
|
-
let hasContentType = false;
|
|
3511
|
-
const supportsReadableStream = typeof globalThis.ReadableStream === 'function';
|
|
3512
|
-
const supportsRequest = typeof globalThis.Request === 'function';
|
|
3513
|
-
if (supportsReadableStream && supportsRequest) {
|
|
3514
|
-
try {
|
|
3515
|
-
hasContentType = new globalThis.Request('https://empty.invalid', {
|
|
3516
|
-
body: new globalThis.ReadableStream(),
|
|
3517
|
-
method: 'POST',
|
|
3518
|
-
// @ts-expect-error - Types are outdated.
|
|
3519
|
-
get duplex() {
|
|
3520
|
-
duplexAccessed = true;
|
|
3521
|
-
return 'half';
|
|
3522
|
-
}
|
|
3523
|
-
}).headers.has('Content-Type');
|
|
3524
|
-
} catch (error) {
|
|
3525
|
-
// QQBrowser on iOS throws "unsupported BodyInit type" error (see issue #581)
|
|
3526
|
-
if (error instanceof Error && error.message === 'unsupported BodyInit type') {
|
|
3527
|
-
return false;
|
|
3528
|
-
}
|
|
3529
|
-
throw error;
|
|
3530
|
-
}
|
|
3531
|
-
}
|
|
3532
|
-
return duplexAccessed && !hasContentType;
|
|
3533
|
-
})();
|
|
3534
|
-
const supportsAbortController = typeof globalThis.AbortController === 'function';
|
|
3535
|
-
const supportsResponseStreams = typeof globalThis.ReadableStream === 'function';
|
|
3536
|
-
const supportsFormData = typeof globalThis.FormData === 'function';
|
|
3537
|
-
const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'];
|
|
3538
|
-
const responseTypes = {
|
|
3539
|
-
json: 'application/json',
|
|
3540
|
-
text: 'text/*',
|
|
3541
|
-
formData: 'multipart/form-data',
|
|
3542
|
-
arrayBuffer: '*/*',
|
|
3543
|
-
blob: '*/*'
|
|
3544
|
-
};
|
|
3545
|
-
// The maximum value of a 32bit int (see issue #117)
|
|
3546
|
-
const maxSafeTimeout = 2_147_483_647;
|
|
3547
|
-
const stop = Symbol('stop');
|
|
3548
|
-
const kyOptionKeys = {
|
|
3549
|
-
json: true,
|
|
3550
|
-
parseJson: true,
|
|
3551
|
-
stringifyJson: true,
|
|
3552
|
-
searchParams: true,
|
|
3553
|
-
prefixUrl: true,
|
|
3554
|
-
retry: true,
|
|
3555
|
-
timeout: true,
|
|
3556
|
-
hooks: true,
|
|
3557
|
-
throwHttpErrors: true,
|
|
3558
|
-
onDownloadProgress: true,
|
|
3559
|
-
fetch: true
|
|
3560
|
-
};
|
|
3561
|
-
const requestOptionsRegistry = {
|
|
3562
|
-
method: true,
|
|
3563
|
-
headers: true,
|
|
3564
|
-
body: true,
|
|
3565
|
-
mode: true,
|
|
3566
|
-
credentials: true,
|
|
3567
|
-
cache: true,
|
|
3568
|
-
redirect: true,
|
|
3569
|
-
referrer: true,
|
|
3570
|
-
referrerPolicy: true,
|
|
3571
|
-
integrity: true,
|
|
3572
|
-
keepalive: true,
|
|
3573
|
-
signal: true,
|
|
3574
|
-
window: true,
|
|
3575
|
-
dispatcher: true,
|
|
3576
|
-
duplex: true,
|
|
3577
|
-
priority: true
|
|
3578
|
-
};
|
|
3579
|
-
|
|
3580
|
-
const normalizeRequestMethod = input => requestMethods.includes(input) ? input.toUpperCase() : input;
|
|
3581
|
-
const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
|
|
3582
|
-
const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
|
3583
|
-
const retryAfterStatusCodes = [413, 429, 503];
|
|
3584
|
-
const defaultRetryOptions = {
|
|
3585
|
-
limit: 2,
|
|
3586
|
-
methods: retryMethods,
|
|
3587
|
-
statusCodes: retryStatusCodes,
|
|
3588
|
-
afterStatusCodes: retryAfterStatusCodes,
|
|
3589
|
-
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
3590
|
-
backoffLimit: Number.POSITIVE_INFINITY,
|
|
3591
|
-
delay: attemptCount => 0.3 * 2 ** (attemptCount - 1) * 1000
|
|
3592
|
-
};
|
|
3593
|
-
const normalizeRetryOptions = (retry = {}) => {
|
|
3594
|
-
if (typeof retry === 'number') {
|
|
3595
|
-
return {
|
|
3596
|
-
...defaultRetryOptions,
|
|
3597
|
-
limit: retry
|
|
3598
|
-
};
|
|
3599
|
-
}
|
|
3600
|
-
if (retry.methods && !Array.isArray(retry.methods)) {
|
|
3601
|
-
throw new Error('retry.methods must be an array');
|
|
3602
|
-
}
|
|
3603
|
-
if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
|
|
3604
|
-
throw new Error('retry.statusCodes must be an array');
|
|
3605
|
-
}
|
|
3606
|
-
return {
|
|
3607
|
-
...defaultRetryOptions,
|
|
3608
|
-
...retry
|
|
3609
|
-
};
|
|
3610
|
-
};
|
|
3611
|
-
|
|
3612
|
-
// `Promise.race()` workaround (#91)
|
|
3613
|
-
async function timeout(request, init, abortController, options) {
|
|
3614
|
-
return new Promise((resolve, reject) => {
|
|
3615
|
-
const timeoutId = setTimeout(() => {
|
|
3616
|
-
if (abortController) {
|
|
3617
|
-
abortController.abort();
|
|
3618
|
-
}
|
|
3619
|
-
reject(new TimeoutError(request));
|
|
3620
|
-
}, options.timeout);
|
|
3621
|
-
void options.fetch(request, init).then(resolve).catch(reject).then(() => {
|
|
3622
|
-
clearTimeout(timeoutId);
|
|
3623
|
-
});
|
|
3624
|
-
});
|
|
3625
|
-
}
|
|
3626
|
-
|
|
3627
|
-
// https://github.com/sindresorhus/delay/tree/ab98ae8dfcb38e1593286c94d934e70d14a4e111
|
|
3628
|
-
async function delay(ms, {
|
|
3629
|
-
signal
|
|
3630
|
-
}) {
|
|
3631
|
-
return new Promise((resolve, reject) => {
|
|
3632
|
-
if (signal) {
|
|
3633
|
-
signal.throwIfAborted();
|
|
3634
|
-
signal.addEventListener('abort', abortHandler, {
|
|
3635
|
-
once: true
|
|
3636
|
-
});
|
|
3637
|
-
}
|
|
3638
|
-
function abortHandler() {
|
|
3639
|
-
clearTimeout(timeoutId);
|
|
3640
|
-
reject(signal.reason);
|
|
3641
|
-
}
|
|
3642
|
-
const timeoutId = setTimeout(() => {
|
|
3643
|
-
signal?.removeEventListener('abort', abortHandler);
|
|
3644
|
-
resolve();
|
|
3645
|
-
}, ms);
|
|
3646
|
-
});
|
|
3647
|
-
}
|
|
3648
|
-
|
|
3649
|
-
const findUnknownOptions = (request, options) => {
|
|
3650
|
-
const unknownOptions = {};
|
|
3651
|
-
for (const key in options) {
|
|
3652
|
-
if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && !(key in request)) {
|
|
3653
|
-
unknownOptions[key] = options[key];
|
|
3654
|
-
}
|
|
3655
|
-
}
|
|
3656
|
-
return unknownOptions;
|
|
3657
|
-
};
|
|
3658
|
-
|
|
3659
|
-
class Ky {
|
|
3660
|
-
static create(input, options) {
|
|
3661
|
-
const ky = new Ky(input, options);
|
|
3662
|
-
const function_ = async () => {
|
|
3663
|
-
if (typeof ky._options.timeout === 'number' && ky._options.timeout > maxSafeTimeout) {
|
|
3664
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
|
|
3665
|
-
}
|
|
3666
|
-
// Delay the fetch so that body method shortcuts can set the Accept header
|
|
3667
|
-
await Promise.resolve();
|
|
3668
|
-
let response = await ky._fetch();
|
|
3669
|
-
for (const hook of ky._options.hooks.afterResponse) {
|
|
3670
|
-
// eslint-disable-next-line no-await-in-loop
|
|
3671
|
-
const modifiedResponse = await hook(ky.request, ky._options, ky._decorateResponse(response.clone()));
|
|
3672
|
-
if (modifiedResponse instanceof globalThis.Response) {
|
|
3673
|
-
response = modifiedResponse;
|
|
3674
|
-
}
|
|
3675
|
-
}
|
|
3676
|
-
ky._decorateResponse(response);
|
|
3677
|
-
if (!response.ok && ky._options.throwHttpErrors) {
|
|
3678
|
-
let error = new HTTPError(response, ky.request, ky._options);
|
|
3679
|
-
for (const hook of ky._options.hooks.beforeError) {
|
|
3680
|
-
// eslint-disable-next-line no-await-in-loop
|
|
3681
|
-
error = await hook(error);
|
|
3682
|
-
}
|
|
3683
|
-
throw error;
|
|
3684
|
-
}
|
|
3685
|
-
// If `onDownloadProgress` is passed, it uses the stream API internally
|
|
3686
|
-
/* istanbul ignore next */
|
|
3687
|
-
if (ky._options.onDownloadProgress) {
|
|
3688
|
-
if (typeof ky._options.onDownloadProgress !== 'function') {
|
|
3689
|
-
throw new TypeError('The `onDownloadProgress` option must be a function');
|
|
3690
|
-
}
|
|
3691
|
-
if (!supportsResponseStreams) {
|
|
3692
|
-
throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');
|
|
3693
|
-
}
|
|
3694
|
-
return ky._stream(response.clone(), ky._options.onDownloadProgress);
|
|
3695
|
-
}
|
|
3696
|
-
return response;
|
|
3697
|
-
};
|
|
3698
|
-
const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());
|
|
3699
|
-
const result = isRetriableMethod ? ky._retry(function_) : function_();
|
|
3700
|
-
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
|
3701
|
-
result[type] = async () => {
|
|
3702
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
3703
|
-
ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);
|
|
3704
|
-
const awaitedResult = await result;
|
|
3705
|
-
const response = awaitedResult.clone();
|
|
3706
|
-
if (type === 'json') {
|
|
3707
|
-
if (response.status === 204) {
|
|
3708
|
-
return '';
|
|
3709
|
-
}
|
|
3710
|
-
const arrayBuffer = await response.clone().arrayBuffer();
|
|
3711
|
-
const responseSize = arrayBuffer.byteLength;
|
|
3712
|
-
if (responseSize === 0) {
|
|
3713
|
-
return '';
|
|
3714
|
-
}
|
|
3715
|
-
if (options.parseJson) {
|
|
3716
|
-
return options.parseJson(await response.text());
|
|
3717
|
-
}
|
|
3718
|
-
}
|
|
3719
|
-
return response[type]();
|
|
3720
|
-
};
|
|
3721
|
-
}
|
|
3722
|
-
return result;
|
|
3723
|
-
}
|
|
3724
|
-
request;
|
|
3725
|
-
abortController;
|
|
3726
|
-
_retryCount = 0;
|
|
3727
|
-
_input;
|
|
3728
|
-
_options;
|
|
3729
|
-
// eslint-disable-next-line complexity
|
|
3730
|
-
constructor(input, options = {}) {
|
|
3731
|
-
this._input = input;
|
|
3732
|
-
this._options = {
|
|
3733
|
-
...options,
|
|
3734
|
-
headers: mergeHeaders(this._input.headers, options.headers),
|
|
3735
|
-
hooks: mergeHooks({
|
|
3736
|
-
beforeRequest: [],
|
|
3737
|
-
beforeRetry: [],
|
|
3738
|
-
beforeError: [],
|
|
3739
|
-
afterResponse: []
|
|
3740
|
-
}, options.hooks),
|
|
3741
|
-
method: normalizeRequestMethod(options.method ?? this._input.method),
|
|
3742
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
3743
|
-
prefixUrl: String(options.prefixUrl || ''),
|
|
3744
|
-
retry: normalizeRetryOptions(options.retry),
|
|
3745
|
-
throwHttpErrors: options.throwHttpErrors !== false,
|
|
3746
|
-
timeout: options.timeout ?? 10_000,
|
|
3747
|
-
fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
|
|
3748
|
-
};
|
|
3749
|
-
if (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
|
|
3750
|
-
throw new TypeError('`input` must be a string, URL, or Request');
|
|
3751
|
-
}
|
|
3752
|
-
if (this._options.prefixUrl && typeof this._input === 'string') {
|
|
3753
|
-
if (this._input.startsWith('/')) {
|
|
3754
|
-
throw new Error('`input` must not begin with a slash when using `prefixUrl`');
|
|
3755
|
-
}
|
|
3756
|
-
if (!this._options.prefixUrl.endsWith('/')) {
|
|
3757
|
-
this._options.prefixUrl += '/';
|
|
3758
|
-
}
|
|
3759
|
-
this._input = this._options.prefixUrl + this._input;
|
|
3760
|
-
}
|
|
3761
|
-
if (supportsAbortController) {
|
|
3762
|
-
this.abortController = new globalThis.AbortController();
|
|
3763
|
-
const originalSignal = this._options.signal ?? this._input.signal;
|
|
3764
|
-
originalSignal?.addEventListener('abort', () => {
|
|
3765
|
-
this.abortController.abort(originalSignal.reason);
|
|
3766
|
-
});
|
|
3767
|
-
this._options.signal = this.abortController.signal;
|
|
3768
|
-
}
|
|
3769
|
-
if (supportsRequestStreams) {
|
|
3770
|
-
// @ts-expect-error - Types are outdated.
|
|
3771
|
-
this._options.duplex = 'half';
|
|
3772
|
-
}
|
|
3773
|
-
if (this._options.json !== undefined) {
|
|
3774
|
-
this._options.body = this._options.stringifyJson?.(this._options.json) ?? JSON.stringify(this._options.json);
|
|
3775
|
-
this._options.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');
|
|
3776
|
-
}
|
|
3777
|
-
this.request = new globalThis.Request(this._input, this._options);
|
|
3778
|
-
if (this._options.searchParams) {
|
|
3779
|
-
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
3780
|
-
const textSearchParams = typeof this._options.searchParams === 'string' ? this._options.searchParams.replace(/^\?/, '') : new URLSearchParams(this._options.searchParams).toString();
|
|
3781
|
-
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
3782
|
-
const searchParams = '?' + textSearchParams;
|
|
3783
|
-
const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
|
|
3784
|
-
// To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one
|
|
3785
|
-
if ((supportsFormData && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers['content-type'])) {
|
|
3786
|
-
this.request.headers.delete('content-type');
|
|
3787
|
-
}
|
|
3788
|
-
// The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws.
|
|
3789
|
-
this.request = new globalThis.Request(new globalThis.Request(url, {
|
|
3790
|
-
...this.request
|
|
3791
|
-
}), this._options);
|
|
3792
|
-
}
|
|
3793
|
-
}
|
|
3794
|
-
_calculateRetryDelay(error) {
|
|
3795
|
-
this._retryCount++;
|
|
3796
|
-
if (this._retryCount > this._options.retry.limit || error instanceof TimeoutError) {
|
|
3797
|
-
throw error;
|
|
3798
|
-
}
|
|
3799
|
-
if (error instanceof HTTPError) {
|
|
3800
|
-
if (!this._options.retry.statusCodes.includes(error.response.status)) {
|
|
3801
|
-
throw error;
|
|
3802
|
-
}
|
|
3803
|
-
const retryAfter = error.response.headers.get('Retry-After') ?? error.response.headers.get('RateLimit-Reset') ?? error.response.headers.get('X-RateLimit-Reset') // GitHub
|
|
3804
|
-
?? error.response.headers.get('X-Rate-Limit-Reset'); // Twitter
|
|
3805
|
-
if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
|
|
3806
|
-
let after = Number(retryAfter) * 1000;
|
|
3807
|
-
if (Number.isNaN(after)) {
|
|
3808
|
-
after = Date.parse(retryAfter) - Date.now();
|
|
3809
|
-
} else if (after >= Date.parse('2024-01-01')) {
|
|
3810
|
-
// A large number is treated as a timestamp (fixed threshold protects against clock skew)
|
|
3811
|
-
after -= Date.now();
|
|
3812
|
-
}
|
|
3813
|
-
const max = this._options.retry.maxRetryAfter ?? after;
|
|
3814
|
-
return after < max ? after : max;
|
|
3815
|
-
}
|
|
3816
|
-
if (error.response.status === 413) {
|
|
3817
|
-
throw error;
|
|
3818
|
-
}
|
|
3819
|
-
}
|
|
3820
|
-
const retryDelay = this._options.retry.delay(this._retryCount);
|
|
3821
|
-
return Math.min(this._options.retry.backoffLimit, retryDelay);
|
|
3822
|
-
}
|
|
3823
|
-
_decorateResponse(response) {
|
|
3824
|
-
if (this._options.parseJson) {
|
|
3825
|
-
response.json = async () => this._options.parseJson(await response.text());
|
|
3826
|
-
}
|
|
3827
|
-
return response;
|
|
3828
|
-
}
|
|
3829
|
-
async _retry(function_) {
|
|
3830
|
-
try {
|
|
3831
|
-
return await function_();
|
|
3832
|
-
} catch (error) {
|
|
3833
|
-
const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
|
|
3834
|
-
if (this._retryCount < 1) {
|
|
3835
|
-
throw error;
|
|
3836
|
-
}
|
|
3837
|
-
await delay(ms, {
|
|
3838
|
-
signal: this._options.signal
|
|
3839
|
-
});
|
|
3840
|
-
for (const hook of this._options.hooks.beforeRetry) {
|
|
3841
|
-
// eslint-disable-next-line no-await-in-loop
|
|
3842
|
-
const hookResult = await hook({
|
|
3843
|
-
request: this.request,
|
|
3844
|
-
options: this._options,
|
|
3845
|
-
error: error,
|
|
3846
|
-
retryCount: this._retryCount
|
|
3847
|
-
});
|
|
3848
|
-
// If `stop` is returned from the hook, the retry process is stopped
|
|
3849
|
-
if (hookResult === stop) {
|
|
3850
|
-
return;
|
|
3851
|
-
}
|
|
3852
|
-
}
|
|
3853
|
-
return this._retry(function_);
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
async _fetch() {
|
|
3857
|
-
for (const hook of this._options.hooks.beforeRequest) {
|
|
3858
|
-
// eslint-disable-next-line no-await-in-loop
|
|
3859
|
-
const result = await hook(this.request, this._options);
|
|
3860
|
-
if (result instanceof Request) {
|
|
3861
|
-
this.request = result;
|
|
3862
|
-
break;
|
|
3863
|
-
}
|
|
3864
|
-
if (result instanceof Response) {
|
|
3865
|
-
return result;
|
|
3866
|
-
}
|
|
3867
|
-
}
|
|
3868
|
-
const nonRequestOptions = findUnknownOptions(this.request, this._options);
|
|
3869
|
-
// Cloning is done here to prepare in advance for retries
|
|
3870
|
-
const mainRequest = this.request;
|
|
3871
|
-
this.request = mainRequest.clone();
|
|
3872
|
-
if (this._options.timeout === false) {
|
|
3873
|
-
return this._options.fetch(mainRequest, nonRequestOptions);
|
|
3874
|
-
}
|
|
3875
|
-
return timeout(mainRequest, nonRequestOptions, this.abortController, this._options);
|
|
3876
|
-
}
|
|
3877
|
-
/* istanbul ignore next */
|
|
3878
|
-
_stream(response, onDownloadProgress) {
|
|
3879
|
-
const totalBytes = Number(response.headers.get('content-length')) || 0;
|
|
3880
|
-
let transferredBytes = 0;
|
|
3881
|
-
if (response.status === 204) {
|
|
3882
|
-
if (onDownloadProgress) {
|
|
3883
|
-
onDownloadProgress({
|
|
3884
|
-
percent: 1,
|
|
3885
|
-
totalBytes,
|
|
3886
|
-
transferredBytes
|
|
3887
|
-
}, new Uint8Array());
|
|
3888
|
-
}
|
|
3889
|
-
return new globalThis.Response(null, {
|
|
3890
|
-
status: response.status,
|
|
3891
|
-
statusText: response.statusText,
|
|
3892
|
-
headers: response.headers
|
|
3893
|
-
});
|
|
3894
|
-
}
|
|
3895
|
-
return new globalThis.Response(new globalThis.ReadableStream({
|
|
3896
|
-
async start(controller) {
|
|
3897
|
-
const reader = response.body.getReader();
|
|
3898
|
-
if (onDownloadProgress) {
|
|
3899
|
-
onDownloadProgress({
|
|
3900
|
-
percent: 0,
|
|
3901
|
-
transferredBytes: 0,
|
|
3902
|
-
totalBytes
|
|
3903
|
-
}, new Uint8Array());
|
|
3904
|
-
}
|
|
3905
|
-
async function read() {
|
|
3906
|
-
const {
|
|
3907
|
-
done,
|
|
3908
|
-
value
|
|
3909
|
-
} = await reader.read();
|
|
3910
|
-
if (done) {
|
|
3911
|
-
controller.close();
|
|
3912
|
-
return;
|
|
3913
|
-
}
|
|
3914
|
-
if (onDownloadProgress) {
|
|
3915
|
-
transferredBytes += value.byteLength;
|
|
3916
|
-
const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
|
3917
|
-
onDownloadProgress({
|
|
3918
|
-
percent,
|
|
3919
|
-
transferredBytes,
|
|
3920
|
-
totalBytes
|
|
3921
|
-
}, value);
|
|
3922
|
-
}
|
|
3923
|
-
controller.enqueue(value);
|
|
3924
|
-
await read();
|
|
3925
|
-
}
|
|
3926
|
-
await read();
|
|
3927
|
-
}
|
|
3928
|
-
}), {
|
|
3929
|
-
status: response.status,
|
|
3930
|
-
statusText: response.statusText,
|
|
3931
|
-
headers: response.headers
|
|
3932
|
-
});
|
|
3933
|
-
}
|
|
3934
|
-
}
|
|
3935
|
-
|
|
3936
|
-
/*! MIT License © Sindre Sorhus */
|
|
3937
|
-
const createInstance = defaults => {
|
|
3938
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
3939
|
-
const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
|
|
3940
|
-
for (const method of requestMethods) {
|
|
3941
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
3942
|
-
ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, {
|
|
3943
|
-
method
|
|
3944
|
-
}));
|
|
3945
|
-
}
|
|
3946
|
-
ky.create = newDefaults => createInstance(validateAndMerge(newDefaults));
|
|
3947
|
-
ky.extend = newDefaults => {
|
|
3948
|
-
if (typeof newDefaults === 'function') {
|
|
3949
|
-
newDefaults = newDefaults(defaults ?? {});
|
|
3950
|
-
}
|
|
3951
|
-
return createInstance(validateAndMerge(defaults, newDefaults));
|
|
3952
|
-
};
|
|
3953
|
-
ky.stop = stop;
|
|
3954
|
-
return ky;
|
|
3955
|
-
};
|
|
3956
|
-
const ky = createInstance();
|
|
3957
|
-
|
|
3958
|
-
const getText = async (url, options = {}) => {
|
|
3959
|
-
try {
|
|
3960
|
-
return await ky(url, options).text();
|
|
3961
|
-
} catch (error) {
|
|
3962
|
-
if (error && error instanceof TypeError && error.message === 'Failed to fetch') {
|
|
3963
|
-
throw new VError$1(error, `Failed to request text from "${url}". Make sure that the server is running and has CORS enabled`);
|
|
3964
|
-
}
|
|
3965
|
-
throw new VError$1(error, `Failed to request text from "${url}"`);
|
|
3966
|
-
}
|
|
3967
|
-
};
|
|
3968
|
-
|
|
3969
|
-
// based on https://github.com/babel/babel/blob/6be6e04f396f03feace4431f709564a8d842163a/packages/babel-code-frame/src/index.ts (License MIT)
|
|
3970
|
-
|
|
3971
|
-
/**
|
|
3972
|
-
* RegExp to test for newlines in terminal.
|
|
3973
|
-
*/
|
|
3974
|
-
|
|
3975
|
-
const NEWLINE = /\n/;
|
|
3976
|
-
|
|
3977
|
-
/**
|
|
3978
|
-
* Extract what lines should be marked and highlighted.
|
|
3979
|
-
*/
|
|
3980
|
-
const getMarkerLines = (loc, source, opts) => {
|
|
3981
|
-
const startLoc = {
|
|
3982
|
-
column: 0,
|
|
3983
|
-
line: -1,
|
|
3984
|
-
...loc.start
|
|
3985
|
-
};
|
|
3986
|
-
const endLoc = {
|
|
3987
|
-
...startLoc,
|
|
3988
|
-
...loc.end
|
|
3989
|
-
};
|
|
3990
|
-
const {
|
|
3991
|
-
linesAbove = 2,
|
|
3992
|
-
linesBelow = 3
|
|
3993
|
-
} = opts || {};
|
|
3994
|
-
const startLine = startLoc.line;
|
|
3995
|
-
const startColumn = startLoc.column;
|
|
3996
|
-
const endLine = endLoc.line;
|
|
3997
|
-
const endColumn = endLoc.column;
|
|
3998
|
-
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
3999
|
-
let end = Math.min(source.length, endLine + linesBelow);
|
|
4000
|
-
if (startLine === -1) {
|
|
4001
|
-
start = 0;
|
|
4002
|
-
}
|
|
4003
|
-
if (endLine === -1) {
|
|
4004
|
-
end = source.length;
|
|
4005
|
-
}
|
|
4006
|
-
const lineDiff = endLine - startLine;
|
|
4007
|
-
const markerLines = {};
|
|
4008
|
-
if (lineDiff) {
|
|
4009
|
-
for (let i = 0; i <= lineDiff; i++) {
|
|
4010
|
-
const lineNumber = i + startLine;
|
|
4011
|
-
if (!startColumn) {
|
|
4012
|
-
markerLines[lineNumber] = true;
|
|
4013
|
-
} else if (i === 0) {
|
|
4014
|
-
const sourceLength = source[lineNumber - 1].length;
|
|
4015
|
-
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
|
|
4016
|
-
} else if (i === lineDiff) {
|
|
4017
|
-
markerLines[lineNumber] = [0, endColumn];
|
|
4018
|
-
} else {
|
|
4019
|
-
const sourceLength = source[lineNumber - i].length;
|
|
4020
|
-
markerLines[lineNumber] = [0, sourceLength];
|
|
4021
|
-
}
|
|
4022
|
-
}
|
|
4023
|
-
} else if (startColumn === endColumn) {
|
|
4024
|
-
if (startColumn) {
|
|
4025
|
-
markerLines[startLine] = [startColumn, 0];
|
|
4026
|
-
} else {
|
|
4027
|
-
markerLines[startLine] = true;
|
|
4028
|
-
}
|
|
4029
|
-
} else {
|
|
4030
|
-
markerLines[startLine] = [startColumn, endColumn - startColumn];
|
|
4031
|
-
}
|
|
4032
|
-
return {
|
|
4033
|
-
start,
|
|
4034
|
-
end,
|
|
4035
|
-
markerLines
|
|
4036
|
-
};
|
|
4037
|
-
};
|
|
4038
|
-
const create$5 = (rawLines, loc, opts = {}) => {
|
|
4039
|
-
const lines = rawLines.split(NEWLINE);
|
|
4040
|
-
const {
|
|
4041
|
-
start,
|
|
4042
|
-
end,
|
|
4043
|
-
markerLines
|
|
4044
|
-
} = getMarkerLines(loc, lines, opts);
|
|
4045
|
-
const hasColumns = loc.start && typeof loc.start.column === 'number';
|
|
4046
|
-
const numberMaxWidth = String(end).length;
|
|
4047
|
-
let frame = rawLines.split(NEWLINE, end).slice(start, end).map((line, index) => {
|
|
4048
|
-
const number = start + 1 + index;
|
|
4049
|
-
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
4050
|
-
const gutter = ` ${paddedNumber} |`;
|
|
4051
|
-
const hasMarker = markerLines[number];
|
|
4052
|
-
const lastMarkerLine = !markerLines[number + 1];
|
|
4053
|
-
if (hasMarker) {
|
|
4054
|
-
let markerLine = '';
|
|
4055
|
-
if (Array.isArray(hasMarker)) {
|
|
4056
|
-
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, ' ');
|
|
4057
|
-
const numberOfMarkers = hasMarker[1] || 1;
|
|
4058
|
-
markerLine = ['\n ', gutter.replace(/\d/g, ' '), ' ', markerSpacing, '^'.repeat(numberOfMarkers)].join('');
|
|
4059
|
-
|
|
4060
|
-
// @ts-ignore
|
|
4061
|
-
if (lastMarkerLine && opts.message) {
|
|
4062
|
-
// @ts-ignore
|
|
4063
|
-
markerLine += ' ' + opts.message;
|
|
4064
|
-
}
|
|
4065
|
-
}
|
|
4066
|
-
return ['>', gutter, line.length > 0 ? ` ${line}` : '', markerLine].join('');
|
|
4067
|
-
}
|
|
4068
|
-
return ` ${gutter}${line.length > 0 ? ` ${line}` : ''}`;
|
|
4069
|
-
}).join('\n');
|
|
4070
|
-
|
|
4071
|
-
// @ts-ignore
|
|
4072
|
-
if (opts.message && !hasColumns) {
|
|
4073
|
-
// @ts-ignore
|
|
4074
|
-
frame = `${' '.repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
|
|
4075
|
-
}
|
|
4076
|
-
return frame;
|
|
4077
|
-
};
|
|
4078
|
-
|
|
4079
|
-
const joinLines = lines => {
|
|
4080
|
-
return lines.join('\n');
|
|
4081
|
-
};
|
|
4082
|
-
|
|
4083
|
-
const splitLines = lines => {
|
|
4084
|
-
return lines.split('\n');
|
|
4085
|
-
};
|
|
4086
|
-
|
|
4087
|
-
const getErrorMessage = error => {
|
|
4088
|
-
if (!error) {
|
|
4089
|
-
return `Error: ${error}`;
|
|
4090
|
-
}
|
|
4091
|
-
let message = error.message;
|
|
4092
|
-
while (error.cause) {
|
|
4093
|
-
error = error.cause;
|
|
4094
|
-
message += `: ${error}`;
|
|
4095
|
-
}
|
|
4096
|
-
return message;
|
|
4097
|
-
};
|
|
4098
|
-
const prepareErrorMessageWithCodeFrame = error => {
|
|
4099
|
-
if (!error) {
|
|
4100
|
-
return {
|
|
4101
|
-
message: error,
|
|
4102
|
-
stack: undefined,
|
|
4103
|
-
codeFrame: undefined,
|
|
4104
|
-
type: 'Error'
|
|
4105
|
-
};
|
|
4106
|
-
}
|
|
4107
|
-
const message = getErrorMessage(error);
|
|
4108
|
-
if (error.codeFrame) {
|
|
4109
|
-
return {
|
|
4110
|
-
message,
|
|
4111
|
-
stack: error.stack,
|
|
4112
|
-
codeFrame: error.codeFrame,
|
|
4113
|
-
type: error.constructor.name
|
|
4114
|
-
};
|
|
4115
|
-
}
|
|
4116
|
-
return {
|
|
4117
|
-
message,
|
|
4118
|
-
stack: error.originalStack,
|
|
4119
|
-
codeFrame: error.originalCodeFrame,
|
|
4120
|
-
category: error.category,
|
|
4121
|
-
stderr: error.stderr
|
|
4122
|
-
};
|
|
4123
|
-
};
|
|
4124
|
-
const RE_PATH_1 = /\((.*):(\d+):(\d+)\)$/;
|
|
4125
|
-
const RE_PATH_2 = /at (.*):(\d+):(\d+)$/;
|
|
4126
|
-
|
|
4127
|
-
/**
|
|
4128
|
-
*
|
|
4129
|
-
* @param {readonly string[]} lines
|
|
4130
|
-
* @returns
|
|
4131
|
-
*/
|
|
4132
|
-
const getFile = lines => {
|
|
4133
|
-
for (const line of lines) {
|
|
4134
|
-
if (RE_PATH_1.test(line) || RE_PATH_2.test(line)) {
|
|
4135
|
-
return line;
|
|
4136
|
-
}
|
|
4137
|
-
}
|
|
4138
|
-
return '';
|
|
4139
|
-
};
|
|
4140
|
-
const prepareErrorMessageWithoutCodeFrame = async error => {
|
|
4141
|
-
try {
|
|
4142
|
-
const lines = splitLines(error.stack);
|
|
4143
|
-
const file = getFile(lines);
|
|
4144
|
-
let match = file.match(RE_PATH_1);
|
|
4145
|
-
if (!match) {
|
|
4146
|
-
match = file.match(RE_PATH_2);
|
|
4147
|
-
}
|
|
4148
|
-
if (!match) {
|
|
4149
|
-
return error;
|
|
4150
|
-
}
|
|
4151
|
-
const [_, path, line, column] = match;
|
|
4152
|
-
const text = await getText(path);
|
|
4153
|
-
const parsedLine = Number.parseInt(line);
|
|
4154
|
-
const parsedColumn = Number.parseInt(column);
|
|
4155
|
-
const codeFrame = create$5(text, {
|
|
4156
|
-
start: {
|
|
4157
|
-
line: parsedLine,
|
|
4158
|
-
column: parsedColumn
|
|
4159
|
-
},
|
|
4160
|
-
end: {
|
|
4161
|
-
line: parsedLine,
|
|
4162
|
-
column: parsedColumn
|
|
4163
|
-
}
|
|
4164
|
-
});
|
|
4165
|
-
const relevantStack = joinLines(lines.slice(1));
|
|
4166
|
-
const message = getErrorMessage(error);
|
|
4167
|
-
return {
|
|
4168
|
-
message,
|
|
4169
|
-
codeFrame,
|
|
4170
|
-
stack: relevantStack,
|
|
4171
|
-
type: error.constructor.name
|
|
4172
|
-
};
|
|
4173
|
-
} catch (otherError) {
|
|
4174
|
-
console.warn('ErrorHandling Error');
|
|
4175
|
-
console.warn(otherError);
|
|
4176
|
-
return error;
|
|
4177
|
-
}
|
|
4178
|
-
};
|
|
4179
|
-
const prepare = async error => {
|
|
4180
|
-
if (error && error.message && error.codeFrame) {
|
|
4181
|
-
return prepareErrorMessageWithCodeFrame(error);
|
|
4182
|
-
}
|
|
4183
|
-
if (error && error.stack) {
|
|
4184
|
-
return prepareErrorMessageWithoutCodeFrame(error);
|
|
4185
|
-
}
|
|
4186
|
-
return error;
|
|
4187
|
-
};
|
|
4188
|
-
const print = error => {
|
|
4189
|
-
if (error && error.type && error.message && error.codeFrame) {
|
|
4190
|
-
return `${error.type}: ${error.message}\n\n${error.codeFrame}\n\n${error.stack}`;
|
|
4191
|
-
}
|
|
4192
|
-
if (error && error.message && error.codeFrame) {
|
|
4193
|
-
return `${error.message}\n\n${error.codeFrame}\n\n${error.stack}`;
|
|
4194
|
-
}
|
|
4195
|
-
if (error && error.type && error.message) {
|
|
4196
|
-
return `${error.type}: ${error.message}\n${error.stack}`;
|
|
4197
|
-
}
|
|
4198
|
-
if (error && error.stack) {
|
|
4199
|
-
return `${error.stack}`;
|
|
4200
|
-
}
|
|
4201
|
-
if (error === null) {
|
|
4202
|
-
return null;
|
|
4203
|
-
}
|
|
4204
|
-
return `${error}`;
|
|
3310
|
+
const commandMap = {
|
|
3311
|
+
['ExtensionHostDebug.evaluate']: evaluate,
|
|
3312
|
+
['ExtensionHostDebug.getProperties']: getProperties,
|
|
3313
|
+
['ExtensionHostDebug.listProcesses']: listProcesses,
|
|
3314
|
+
['ExtensionHostDebug.pause']: pause,
|
|
3315
|
+
['ExtensionHostDebug.resume']: resume,
|
|
3316
|
+
['ExtensionHostDebug.setPauseOnException']: setPauseOnException,
|
|
3317
|
+
['ExtensionHostDebug.setPauseOnExceptions']: setPauseOnExceptions,
|
|
3318
|
+
['ExtensionHostDebug.start']: start,
|
|
3319
|
+
['ExtensionHostDebug.stepInto']: stepInto,
|
|
3320
|
+
['ExtensionHostDebug.stepOut']: stepOut,
|
|
3321
|
+
['ExtensionHostDebug.stepOver']: stepOver,
|
|
3322
|
+
['ExtensionHostWebView.create']: createWebView,
|
|
3323
|
+
['ExtensionHostWebView.dispose']: disposeWebView,
|
|
3324
|
+
['ExtensionHostWebView.load']: load,
|
|
3325
|
+
['HandleMessagePort.handleMessagePort']: handleMessagePort,
|
|
3326
|
+
[BraceCompletionExecuteBraceCompletionProvider]: executeBraceCompletionProvider,
|
|
3327
|
+
[ClosingTagExecuteClosingTagProvider]: executeClosingTagProvider,
|
|
3328
|
+
[CommandExecute]: executeCommand,
|
|
3329
|
+
[CompletionExecute]: executeCompletionProvider,
|
|
3330
|
+
[CompletionResolveExecute]: executeresolveCompletionItemProvider,
|
|
3331
|
+
[ConfigurationSetConfiguration]: setConfigurations,
|
|
3332
|
+
[DefinitionExecuteDefinitionProvider]: executeDefinitionProvider,
|
|
3333
|
+
[DiagnosticExecuteDiagnosticProvider]: executeDiagnosticProvider,
|
|
3334
|
+
[ExtensionActivate]: activate,
|
|
3335
|
+
[FileSystemGetPathSeparator]: getPathSeparator,
|
|
3336
|
+
[FileSystemReadDirWithFileTypes]: readDirWithFileTypes,
|
|
3337
|
+
[FileSystemReadFile]: readFile,
|
|
3338
|
+
[FileSystemWriteFile]: writeFile,
|
|
3339
|
+
[FormattingExecuteFormmattingProvider]: executeFormattingProvider,
|
|
3340
|
+
[HoverExecute]: executeHoverProvider,
|
|
3341
|
+
[ImplementationExecuteImplementationProvider]: executeImplementationProvider,
|
|
3342
|
+
[MockExec]: mockExec,
|
|
3343
|
+
[MockRpc]: mockRpc,
|
|
3344
|
+
[OrganizeImportsExecute]: executeOrganizeImports,
|
|
3345
|
+
[ReferenceExecuteFileReferenceProvider]: executefileReferenceProvider,
|
|
3346
|
+
[ReferenceExecuteReferenceProvider]: executeReferenceProvider,
|
|
3347
|
+
[SelectionExecuteSelectionProvider]: executeSelectionProvider,
|
|
3348
|
+
[SourceControlAcceptInput]: acceptInput,
|
|
3349
|
+
[SourceControlAdd]: add,
|
|
3350
|
+
[SourceControlDiscard]: discard,
|
|
3351
|
+
[SourceControlGetChangedFiles]: getChangedFiles,
|
|
3352
|
+
[SourceControlGetEnabledProviderIds]: getEnabledProviderIds,
|
|
3353
|
+
[SourceControlGetFileBefore]: getFileBefore,
|
|
3354
|
+
[SourceControlGetGroups]: getGroups,
|
|
3355
|
+
[StatusBarGetStatusBarItems]: getStatusBarItems,
|
|
3356
|
+
[StatusBarRegisterChangeListener]: registerChangeListener,
|
|
3357
|
+
[TabCompletionExecuteTabCompletionProvider]: executeTabCompletionProvider,
|
|
3358
|
+
[TextDocumentSetLanguageId]: setLanguageId,
|
|
3359
|
+
[TextDocumentSyncFull]: syncFull,
|
|
3360
|
+
[TextDocumentSyncIncremental]: syncIncremental,
|
|
3361
|
+
[TextSearchExecuteTextSearchProvider]: executeTextSearchProvider,
|
|
3362
|
+
[TypeDefinitionExecuteTypeDefinitionProvider]: executeTypeDefinitionProvider,
|
|
3363
|
+
[WorkspaceSetPath]: setWorkspacePath
|
|
4205
3364
|
};
|
|
4206
3365
|
|
|
4207
|
-
const logError = async error => {
|
|
4208
|
-
const prettyError = await prepare(error);
|
|
4209
|
-
const prettyErrorString = print(prettyError);
|
|
4210
|
-
console.error(prettyErrorString);
|
|
4211
|
-
return prettyError;
|
|
4212
|
-
};
|
|
4213
3366
|
const handleError = async error => {
|
|
4214
|
-
|
|
4215
|
-
await logError(error);
|
|
4216
|
-
} catch (otherError) {
|
|
4217
|
-
console.warn('ErrorHandling error');
|
|
4218
|
-
console.warn(otherError);
|
|
4219
|
-
console.error(error);
|
|
4220
|
-
}
|
|
3367
|
+
console.error(error);
|
|
4221
3368
|
};
|
|
4222
3369
|
|
|
4223
3370
|
/**
|
|
@@ -4287,8 +3434,7 @@ const main = async () => {
|
|
|
4287
3434
|
self.addEventListener('securitypolicyviolation', handleContentSecurityPolicyViolation);
|
|
4288
3435
|
}
|
|
4289
3436
|
globalThis.vscode = api;
|
|
4290
|
-
|
|
4291
|
-
state$7.getFn = getFn;
|
|
3437
|
+
register(commandMap);
|
|
4292
3438
|
const ipc = await listen({
|
|
4293
3439
|
method: Auto()
|
|
4294
3440
|
});
|
|
@@ -4306,17 +3452,11 @@ const withResolvers = () => {
|
|
|
4306
3452
|
* @type {any}
|
|
4307
3453
|
*/
|
|
4308
3454
|
let _resolve;
|
|
4309
|
-
|
|
4310
|
-
* @type {any}
|
|
4311
|
-
*/
|
|
4312
|
-
let _reject;
|
|
4313
|
-
const promise = new Promise((resolve, reject) => {
|
|
3455
|
+
const promise = new Promise(resolve => {
|
|
4314
3456
|
_resolve = resolve;
|
|
4315
|
-
_reject = reject;
|
|
4316
3457
|
});
|
|
4317
3458
|
return {
|
|
4318
3459
|
resolve: _resolve,
|
|
4319
|
-
reject: _reject,
|
|
4320
3460
|
promise
|
|
4321
3461
|
};
|
|
4322
3462
|
};
|
|
@@ -4547,105 +3687,15 @@ const IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug = {
|
|
|
4547
3687
|
wrap: wrap$1
|
|
4548
3688
|
};
|
|
4549
3689
|
|
|
4550
|
-
const
|
|
4551
|
-
|
|
4552
|
-
const Two = '2.0';
|
|
4553
|
-
|
|
4554
|
-
class NonError extends Error {
|
|
4555
|
-
constructor(message) {
|
|
4556
|
-
super(message);
|
|
4557
|
-
this.name = 'NonError';
|
|
4558
|
-
}
|
|
4559
|
-
}
|
|
4560
|
-
|
|
4561
|
-
// ensureError based on https://github.com/sindresorhus/ensure-error/blob/main/index.ts (License MIT)
|
|
4562
|
-
const ensureError = input => {
|
|
4563
|
-
if (!(input instanceof Error)) {
|
|
4564
|
-
return new NonError(input);
|
|
4565
|
-
}
|
|
4566
|
-
return input;
|
|
4567
|
-
};
|
|
4568
|
-
|
|
4569
|
-
const serializeError = error => {
|
|
4570
|
-
error = ensureError(error);
|
|
4571
|
-
return {
|
|
4572
|
-
stack: error.stack,
|
|
4573
|
-
message: error.message,
|
|
4574
|
-
name: error.name,
|
|
4575
|
-
type: error.constructor.name,
|
|
4576
|
-
codeFrame: error.codeFrame || ''
|
|
4577
|
-
};
|
|
4578
|
-
};
|
|
4579
|
-
|
|
4580
|
-
const getErrorResponse = (message, error) => {
|
|
4581
|
-
if (error && error instanceof CommandNotFoundError) {
|
|
4582
|
-
return {
|
|
4583
|
-
jsonrpc: Two,
|
|
4584
|
-
id: message.id,
|
|
4585
|
-
error: {
|
|
4586
|
-
code: MethodNotFound,
|
|
4587
|
-
message: error.message,
|
|
4588
|
-
data: error.stack
|
|
4589
|
-
}
|
|
4590
|
-
};
|
|
4591
|
-
}
|
|
4592
|
-
const serializedError = serializeError(error);
|
|
4593
|
-
return {
|
|
4594
|
-
jsonrpc: Two,
|
|
4595
|
-
id: message.id,
|
|
4596
|
-
error: {
|
|
4597
|
-
codeFrame: serializedError.codeFrame,
|
|
4598
|
-
message: serializedError.message,
|
|
4599
|
-
stack: serializedError.stack,
|
|
4600
|
-
name: serializedError.name,
|
|
4601
|
-
type: serializedError.type
|
|
4602
|
-
}
|
|
4603
|
-
};
|
|
4604
|
-
};
|
|
4605
|
-
|
|
4606
|
-
const getSuccessResponse = (message, result) => {
|
|
4607
|
-
return {
|
|
4608
|
-
jsonrpc: Two,
|
|
4609
|
-
id: message.id,
|
|
4610
|
-
result
|
|
4611
|
-
};
|
|
3690
|
+
const preparePrettyError = error => {
|
|
3691
|
+
return error;
|
|
4612
3692
|
};
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
try {
|
|
4616
|
-
const result = await execute(message.method, ...message.params);
|
|
4617
|
-
return getSuccessResponse(message, result);
|
|
4618
|
-
} catch (error) {
|
|
4619
|
-
return getErrorResponse(message, error);
|
|
4620
|
-
}
|
|
3693
|
+
const logError = error => {
|
|
3694
|
+
// handled by renderer worker
|
|
4621
3695
|
};
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
constructor(message) {
|
|
4625
|
-
super(message);
|
|
4626
|
-
this.name = 'JsonRpcError';
|
|
4627
|
-
}
|
|
4628
|
-
}
|
|
4629
|
-
|
|
4630
|
-
const handleJsonRpcMessage = async (ipc, message, execute, resolve) => {
|
|
4631
|
-
if ('id' in message) {
|
|
4632
|
-
if ('method' in message) {
|
|
4633
|
-
const response = await getResponse(message, execute);
|
|
4634
|
-
try {
|
|
4635
|
-
ipc.send(response);
|
|
4636
|
-
} catch (error) {
|
|
4637
|
-
await logError(error);
|
|
4638
|
-
const errorResponse = getErrorResponse(message, error);
|
|
4639
|
-
ipc.send(errorResponse);
|
|
4640
|
-
}
|
|
4641
|
-
return;
|
|
4642
|
-
}
|
|
4643
|
-
resolve(message.id, message);
|
|
4644
|
-
return;
|
|
4645
|
-
}
|
|
4646
|
-
throw new JsonRpcError('unexpected message from renderer worker');
|
|
3696
|
+
const requiresSocket = () => {
|
|
3697
|
+
return false;
|
|
4647
3698
|
};
|
|
4648
|
-
|
|
4649
3699
|
const create$1 = ({
|
|
4650
3700
|
ipc,
|
|
4651
3701
|
execute
|
|
@@ -4653,7 +3703,7 @@ const create$1 = ({
|
|
|
4653
3703
|
object(ipc);
|
|
4654
3704
|
fn(execute);
|
|
4655
3705
|
const handleMessage = async message => {
|
|
4656
|
-
return handleJsonRpcMessage(ipc, message, execute, resolve);
|
|
3706
|
+
return handleJsonRpcMessage(ipc, message, execute, resolve, preparePrettyError, logError, requiresSocket);
|
|
4657
3707
|
};
|
|
4658
3708
|
ipc.onmessage = handleMessage;
|
|
4659
3709
|
return {
|