@lvce-editor/extension-host-worker 2.0.0 → 2.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 +2083 -2013
- package/package.json +1 -1
|
@@ -303,7 +303,7 @@ const syncIncremental = (textDocumentId, changes) => {
|
|
|
303
303
|
textDocument.text = before + syntheticChange.inserted + after;
|
|
304
304
|
runListenersSafe(getDidChangeListeners(), textDocument, syntheticChanges);
|
|
305
305
|
};
|
|
306
|
-
const get$
|
|
306
|
+
const get$5 = textDocumentId => {
|
|
307
307
|
const textDocument = getDocument(textDocumentId);
|
|
308
308
|
return textDocument;
|
|
309
309
|
};
|
|
@@ -330,62 +330,6 @@ class NoProviderFoundError extends Error {
|
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
const normalizeLine = line => {
|
|
334
|
-
if (line.startsWith('Error: ')) {
|
|
335
|
-
return line.slice('Error: '.length);
|
|
336
|
-
}
|
|
337
|
-
if (line.startsWith('VError: ')) {
|
|
338
|
-
return line.slice('VError: '.length);
|
|
339
|
-
}
|
|
340
|
-
return line;
|
|
341
|
-
};
|
|
342
|
-
const getCombinedMessage = (error, message) => {
|
|
343
|
-
const stringifiedError = normalizeLine(`${error}`);
|
|
344
|
-
if (message) {
|
|
345
|
-
return `${message}: ${stringifiedError}`;
|
|
346
|
-
}
|
|
347
|
-
return stringifiedError;
|
|
348
|
-
};
|
|
349
|
-
const NewLine$2 = '\n';
|
|
350
|
-
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
351
|
-
return string.indexOf(NewLine$2, startIndex);
|
|
352
|
-
};
|
|
353
|
-
const mergeStacks = (parent, child) => {
|
|
354
|
-
if (!child) {
|
|
355
|
-
return parent;
|
|
356
|
-
}
|
|
357
|
-
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
358
|
-
const childNewLineIndex = getNewLineIndex$1(child);
|
|
359
|
-
if (childNewLineIndex === -1) {
|
|
360
|
-
return parent;
|
|
361
|
-
}
|
|
362
|
-
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
363
|
-
const childRest = child.slice(childNewLineIndex);
|
|
364
|
-
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
365
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
366
|
-
return parentFirstLine + childRest;
|
|
367
|
-
}
|
|
368
|
-
return child;
|
|
369
|
-
};
|
|
370
|
-
class VError extends Error {
|
|
371
|
-
constructor(error, message) {
|
|
372
|
-
const combinedMessage = getCombinedMessage(error, message);
|
|
373
|
-
super(combinedMessage);
|
|
374
|
-
this.name = 'VError';
|
|
375
|
-
if (error instanceof Error) {
|
|
376
|
-
this.stack = mergeStacks(this.stack, error.stack);
|
|
377
|
-
}
|
|
378
|
-
if (error.codeFrame) {
|
|
379
|
-
// @ts-ignore
|
|
380
|
-
this.codeFrame = error.codeFrame;
|
|
381
|
-
}
|
|
382
|
-
if (error.code) {
|
|
383
|
-
// @ts-ignore
|
|
384
|
-
this.code = error.code;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
333
|
const getType = value => {
|
|
390
334
|
switch (typeof value) {
|
|
391
335
|
case 'number':
|
|
@@ -479,6 +423,62 @@ const validate = (item, schema) => {
|
|
|
479
423
|
return undefined;
|
|
480
424
|
};
|
|
481
425
|
|
|
426
|
+
const normalizeLine = line => {
|
|
427
|
+
if (line.startsWith('Error: ')) {
|
|
428
|
+
return line.slice('Error: '.length);
|
|
429
|
+
}
|
|
430
|
+
if (line.startsWith('VError: ')) {
|
|
431
|
+
return line.slice('VError: '.length);
|
|
432
|
+
}
|
|
433
|
+
return line;
|
|
434
|
+
};
|
|
435
|
+
const getCombinedMessage = (error, message) => {
|
|
436
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
437
|
+
if (message) {
|
|
438
|
+
return `${message}: ${stringifiedError}`;
|
|
439
|
+
}
|
|
440
|
+
return stringifiedError;
|
|
441
|
+
};
|
|
442
|
+
const NewLine$2 = '\n';
|
|
443
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
444
|
+
return string.indexOf(NewLine$2, startIndex);
|
|
445
|
+
};
|
|
446
|
+
const mergeStacks = (parent, child) => {
|
|
447
|
+
if (!child) {
|
|
448
|
+
return parent;
|
|
449
|
+
}
|
|
450
|
+
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
451
|
+
const childNewLineIndex = getNewLineIndex$1(child);
|
|
452
|
+
if (childNewLineIndex === -1) {
|
|
453
|
+
return parent;
|
|
454
|
+
}
|
|
455
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
456
|
+
const childRest = child.slice(childNewLineIndex);
|
|
457
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
458
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
459
|
+
return parentFirstLine + childRest;
|
|
460
|
+
}
|
|
461
|
+
return child;
|
|
462
|
+
};
|
|
463
|
+
class VError extends Error {
|
|
464
|
+
constructor(error, message) {
|
|
465
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
466
|
+
super(combinedMessage);
|
|
467
|
+
this.name = 'VError';
|
|
468
|
+
if (error instanceof Error) {
|
|
469
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
|
470
|
+
}
|
|
471
|
+
if (error.codeFrame) {
|
|
472
|
+
// @ts-ignore
|
|
473
|
+
this.codeFrame = error.codeFrame;
|
|
474
|
+
}
|
|
475
|
+
if (error.code) {
|
|
476
|
+
// @ts-ignore
|
|
477
|
+
this.code = error.code;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
482
|
const RE_UPPERCASE_LETTER = /[A-Z]/g;
|
|
483
483
|
const RE_PROPERTY = /item\..*must be of type/;
|
|
484
484
|
const spaceOut = camelCaseWord => {
|
|
@@ -535,7 +535,7 @@ const registerMethod = ({
|
|
|
535
535
|
}) => {
|
|
536
536
|
context[`execute${name}Provider`] = async function (textDocumentId, ...params) {
|
|
537
537
|
try {
|
|
538
|
-
const textDocument = get$
|
|
538
|
+
const textDocument = get$5(textDocumentId);
|
|
539
539
|
if (!textDocument) {
|
|
540
540
|
throw new Error(`textDocument with id ${textDocumentId} not found`);
|
|
541
541
|
}
|
|
@@ -564,14 +564,14 @@ const registerMethod = ({
|
|
|
564
564
|
// @ts-ignore
|
|
565
565
|
throw new VError(`Failed to execute ${spacedOutName} provider: VError: ${camelCaseName}Provider.${methodName} is not a function`);
|
|
566
566
|
}
|
|
567
|
-
const message = actualError.name === 'Error' ?
|
|
567
|
+
const message = actualError.name === 'Error' ? actualError.message : `${actualError.name}: ${actualError.message}`;
|
|
568
568
|
actualError.message = `Failed to execute ${spacedOutName} provider: ${message}`;
|
|
569
569
|
}
|
|
570
570
|
throw actualError;
|
|
571
571
|
}
|
|
572
572
|
};
|
|
573
573
|
};
|
|
574
|
-
const create$
|
|
574
|
+
const create$a = ({
|
|
575
575
|
name,
|
|
576
576
|
resultShape,
|
|
577
577
|
executeKey = '',
|
|
@@ -617,13 +617,13 @@ const Array$1 = 'array';
|
|
|
617
617
|
const Boolean = 'boolean';
|
|
618
618
|
const Number = 'number';
|
|
619
619
|
const Object$1 = 'object';
|
|
620
|
-
const String = 'string';
|
|
620
|
+
const String$1 = 'string';
|
|
621
621
|
|
|
622
622
|
const {
|
|
623
623
|
registerBraceCompletionProvider,
|
|
624
624
|
executeBraceCompletionProvider,
|
|
625
625
|
reset: reset$9
|
|
626
|
-
} = create$
|
|
626
|
+
} = create$a({
|
|
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$a({
|
|
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$a({
|
|
649
649
|
name: 'CodeAction',
|
|
650
650
|
resultShape: {
|
|
651
651
|
type: Array$1,
|
|
@@ -670,7 +670,7 @@ const executeOrganizeImports = async uid => {
|
|
|
670
670
|
if (!organizeImportsAction) {
|
|
671
671
|
return [];
|
|
672
672
|
}
|
|
673
|
-
const textDocument = get$
|
|
673
|
+
const textDocument = get$5(uid);
|
|
674
674
|
const edits = await organizeImportsAction.execute(textDocument);
|
|
675
675
|
return edits;
|
|
676
676
|
};
|
|
@@ -728,7 +728,7 @@ const {
|
|
|
728
728
|
registerCompletionProvider,
|
|
729
729
|
executeCompletionProvider,
|
|
730
730
|
executeresolveCompletionItemProvider
|
|
731
|
-
} = create$
|
|
731
|
+
} = create$a({
|
|
732
732
|
name: 'Completion',
|
|
733
733
|
resultShape: {
|
|
734
734
|
type: Array$1,
|
|
@@ -758,1224 +758,1213 @@ const setConfigurations = preferences => {
|
|
|
758
758
|
state$8.configuration = preferences;
|
|
759
759
|
};
|
|
760
760
|
|
|
761
|
-
const
|
|
762
|
-
|
|
763
|
-
return {
|
|
764
|
-
jsonrpc: Two,
|
|
765
|
-
method,
|
|
766
|
-
params
|
|
767
|
-
};
|
|
768
|
-
};
|
|
769
|
-
const callbacks = Object.create(null);
|
|
770
|
-
const set$5 = (id, fn) => {
|
|
771
|
-
callbacks[id] = fn;
|
|
761
|
+
const state$7 = {
|
|
762
|
+
rpc: undefined
|
|
772
763
|
};
|
|
773
|
-
const
|
|
774
|
-
|
|
764
|
+
const invoke$1 = (method, ...params) => {
|
|
765
|
+
const rpc = state$7.rpc;
|
|
766
|
+
return rpc.invoke(method, ...params);
|
|
775
767
|
};
|
|
776
|
-
const
|
|
777
|
-
|
|
768
|
+
const send$1 = (method, ...params) => {
|
|
769
|
+
const rpc = state$7.rpc;
|
|
770
|
+
return rpc.send(method, ...params);
|
|
778
771
|
};
|
|
779
|
-
|
|
780
|
-
const
|
|
781
|
-
return
|
|
772
|
+
const invokeAndTransfer$1 = (method, ...params) => {
|
|
773
|
+
const rpc = state$7.rpc;
|
|
774
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
782
775
|
};
|
|
783
|
-
const
|
|
784
|
-
|
|
776
|
+
const setRpc = rpc => {
|
|
777
|
+
state$7.rpc = rpc;
|
|
785
778
|
};
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
resolve,
|
|
790
|
-
promise
|
|
791
|
-
} = Promise.withResolvers();
|
|
792
|
-
set$5(id, resolve);
|
|
793
|
-
return {
|
|
794
|
-
id,
|
|
795
|
-
promise
|
|
796
|
-
};
|
|
779
|
+
|
|
780
|
+
const state$6 = {
|
|
781
|
+
debugProviderMap: Object.create(null)
|
|
797
782
|
};
|
|
798
|
-
const
|
|
799
|
-
const
|
|
800
|
-
if (!
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
return;
|
|
783
|
+
const getDebugProvider = id => {
|
|
784
|
+
const provider = state$6.debugProviderMap[id];
|
|
785
|
+
if (!provider) {
|
|
786
|
+
// @ts-ignore
|
|
787
|
+
throw new VError(`no debug provider "${id}" found`);
|
|
804
788
|
}
|
|
805
|
-
|
|
806
|
-
remove(id);
|
|
789
|
+
return provider;
|
|
807
790
|
};
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
id
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
const message = {
|
|
814
|
-
jsonrpc: Two,
|
|
815
|
-
method,
|
|
816
|
-
params,
|
|
817
|
-
id
|
|
818
|
-
};
|
|
819
|
-
return {
|
|
820
|
-
message,
|
|
821
|
-
promise
|
|
822
|
-
};
|
|
791
|
+
const registerDebugProvider = debugProvider => {
|
|
792
|
+
if (!debugProvider.id) {
|
|
793
|
+
throw new Error('Failed to register debug system provider: missing id');
|
|
794
|
+
}
|
|
795
|
+
state$6.debugProviderMap[debugProvider.id] = debugProvider;
|
|
823
796
|
};
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
797
|
+
const start = async (protocol, path) => {
|
|
798
|
+
try {
|
|
799
|
+
const handlePaused = params => {
|
|
800
|
+
console.log('send paused', params);
|
|
801
|
+
send$1('Debug.paused', params);
|
|
802
|
+
};
|
|
803
|
+
const handleResumed = () => {
|
|
804
|
+
send$1('Debug.resumed');
|
|
805
|
+
};
|
|
806
|
+
const handleScriptParsed = parsedScript => {
|
|
807
|
+
send$1('Debug.scriptParsed', parsedScript);
|
|
808
|
+
};
|
|
809
|
+
const provider = getDebugProvider(protocol);
|
|
810
|
+
await provider.start({
|
|
811
|
+
handlePaused,
|
|
812
|
+
handleResumed,
|
|
813
|
+
handleScriptParsed
|
|
814
|
+
}, path);
|
|
815
|
+
} catch (error) {
|
|
816
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
828
817
|
}
|
|
829
|
-
}
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
const
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
case DomException:
|
|
839
|
-
return DOMException;
|
|
840
|
-
case TypeError$1:
|
|
841
|
-
return TypeError;
|
|
842
|
-
case SyntaxError$1:
|
|
843
|
-
return SyntaxError;
|
|
844
|
-
case ReferenceError$1:
|
|
845
|
-
return ReferenceError;
|
|
846
|
-
default:
|
|
847
|
-
return Error;
|
|
848
|
-
}
|
|
818
|
+
};
|
|
819
|
+
const listProcesses = async (protocol, path) => {
|
|
820
|
+
try {
|
|
821
|
+
const provider = getDebugProvider(protocol);
|
|
822
|
+
const processes = await provider.listProcesses(path);
|
|
823
|
+
array(processes);
|
|
824
|
+
return processes;
|
|
825
|
+
} catch (error) {
|
|
826
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
849
827
|
}
|
|
850
|
-
|
|
851
|
-
|
|
828
|
+
};
|
|
829
|
+
const resume = async protocol => {
|
|
830
|
+
try {
|
|
831
|
+
const provider = getDebugProvider(protocol);
|
|
832
|
+
return await provider.resume();
|
|
833
|
+
} catch (error) {
|
|
834
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
852
835
|
}
|
|
853
|
-
|
|
854
|
-
|
|
836
|
+
};
|
|
837
|
+
const pause = async protocol => {
|
|
838
|
+
try {
|
|
839
|
+
const provider = getDebugProvider(protocol);
|
|
840
|
+
return await provider.pause();
|
|
841
|
+
} catch (error) {
|
|
842
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
855
843
|
}
|
|
856
|
-
|
|
857
|
-
|
|
844
|
+
};
|
|
845
|
+
const stepInto = async protocol => {
|
|
846
|
+
try {
|
|
847
|
+
const provider = getDebugProvider(protocol);
|
|
848
|
+
return await provider.stepInto();
|
|
849
|
+
} catch (error) {
|
|
850
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
858
851
|
}
|
|
859
|
-
return Error;
|
|
860
852
|
};
|
|
861
|
-
const
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
return
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
const error = new Error(message);
|
|
868
|
-
if (name && name !== 'VError') {
|
|
869
|
-
error.name = name;
|
|
870
|
-
}
|
|
871
|
-
return error;
|
|
853
|
+
const stepOut = async protocol => {
|
|
854
|
+
try {
|
|
855
|
+
const provider = getDebugProvider(protocol);
|
|
856
|
+
return await provider.stepOut();
|
|
857
|
+
} catch (error) {
|
|
858
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
872
859
|
}
|
|
873
|
-
return new ErrorConstructor(message);
|
|
874
|
-
};
|
|
875
|
-
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
876
|
-
return string.indexOf(NewLine$1, startIndex);
|
|
877
860
|
};
|
|
878
|
-
const
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
861
|
+
const stepOver = async protocol => {
|
|
862
|
+
try {
|
|
863
|
+
const provider = getDebugProvider(protocol);
|
|
864
|
+
return await provider.stepOver();
|
|
865
|
+
} catch (error) {
|
|
866
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
882
867
|
}
|
|
883
|
-
return parentStack;
|
|
884
868
|
};
|
|
885
|
-
const
|
|
886
|
-
|
|
869
|
+
const setPauseOnException = async (protocol, value) => {
|
|
870
|
+
try {
|
|
871
|
+
const provider = getDebugProvider(protocol);
|
|
872
|
+
return await provider.setPauseOnExceptions(value);
|
|
873
|
+
} catch (error) {
|
|
874
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
875
|
+
}
|
|
887
876
|
};
|
|
888
|
-
const
|
|
889
|
-
|
|
890
|
-
const
|
|
891
|
-
|
|
877
|
+
const getProperties = async (protocol, objectId) => {
|
|
878
|
+
try {
|
|
879
|
+
const provider = getDebugProvider(protocol);
|
|
880
|
+
return await provider.getProperties(objectId);
|
|
881
|
+
} catch (error) {
|
|
882
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
883
|
+
}
|
|
892
884
|
};
|
|
893
|
-
const
|
|
894
|
-
|
|
895
|
-
|
|
885
|
+
const evaluate = async (protocol, expression, callFrameId) => {
|
|
886
|
+
try {
|
|
887
|
+
const provider = getDebugProvider(protocol);
|
|
888
|
+
return await provider.evaluate(expression, callFrameId);
|
|
889
|
+
} catch (error) {
|
|
890
|
+
throw new VError(error, 'Failed to execute debug provider');
|
|
896
891
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
892
|
+
};
|
|
893
|
+
const setPauseOnExceptions = async (protocol, value) => {
|
|
894
|
+
try {
|
|
895
|
+
const provider = getDebugProvider(protocol);
|
|
896
|
+
return await provider.setPauseOnExceptions(value);
|
|
897
|
+
} catch (error) {
|
|
898
|
+
throw new VError(error, 'Failed to execute setPauseOnExceptions');
|
|
903
899
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
} else {
|
|
925
|
-
if (error.stack) {
|
|
926
|
-
const lowerStack = restoredError.stack || '';
|
|
927
|
-
// @ts-ignore
|
|
928
|
-
const indexNewLine = getNewLineIndex(lowerStack);
|
|
929
|
-
const parentStack = getParentStack(error);
|
|
930
|
-
// @ts-ignore
|
|
931
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
932
|
-
}
|
|
933
|
-
if (error.codeFrame) {
|
|
934
|
-
// @ts-ignore
|
|
935
|
-
restoredError.codeFrame = error.codeFrame;
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
const {
|
|
903
|
+
registerDefinitionProvider,
|
|
904
|
+
executeDefinitionProvider,
|
|
905
|
+
reset: reset$8
|
|
906
|
+
} = create$a({
|
|
907
|
+
name: 'Definition',
|
|
908
|
+
resultShape: {
|
|
909
|
+
allowUndefined: true,
|
|
910
|
+
type: Object$1,
|
|
911
|
+
properties: {
|
|
912
|
+
uri: {
|
|
913
|
+
type: String$1
|
|
914
|
+
},
|
|
915
|
+
startOffset: {
|
|
916
|
+
type: Number
|
|
917
|
+
},
|
|
918
|
+
endOffset: {
|
|
919
|
+
type: Number
|
|
936
920
|
}
|
|
937
921
|
}
|
|
938
|
-
return restoredError;
|
|
939
922
|
}
|
|
940
|
-
|
|
941
|
-
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
const {
|
|
926
|
+
registerDiagnosticProvider,
|
|
927
|
+
executeDiagnosticProvider
|
|
928
|
+
} = create$a({
|
|
929
|
+
name: 'Diagnostic',
|
|
930
|
+
resultShape: {
|
|
931
|
+
type: Array$1,
|
|
932
|
+
items: {
|
|
933
|
+
type: Object$1
|
|
934
|
+
}
|
|
942
935
|
}
|
|
943
|
-
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
const showInformationMessage = message => {
|
|
939
|
+
string(message);
|
|
940
|
+
const result = invoke$1('ExtensionHostDialog.showInformationMessage', message);
|
|
941
|
+
return result;
|
|
944
942
|
};
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
943
|
+
|
|
944
|
+
const env = {};
|
|
945
|
+
|
|
946
|
+
const exec = async (command, args, options) => {
|
|
947
|
+
throw new DepecratedError(`vscode.exec is deprecated, use createNodeRpc instead`);
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
const fileSystemProviderMap = Object.create(null);
|
|
951
|
+
const get$4 = protocol => {
|
|
952
|
+
const provider = fileSystemProviderMap[protocol];
|
|
953
|
+
if (!provider) {
|
|
954
|
+
// @ts-ignore
|
|
955
|
+
throw new VError(`no file system provider for protocol "${protocol}" found`);
|
|
952
956
|
}
|
|
953
|
-
|
|
957
|
+
return provider;
|
|
954
958
|
};
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
return prettyError.type;
|
|
959
|
+
const set$4 = (id, provider) => {
|
|
960
|
+
if (!id) {
|
|
961
|
+
throw new Error('Failed to register file system provider: missing id');
|
|
959
962
|
}
|
|
960
|
-
|
|
961
|
-
|
|
963
|
+
fileSystemProviderMap[id] = provider;
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
const registerFileSystemProvider = fileSystemProvider => {
|
|
967
|
+
if (!fileSystemProvider.id) {
|
|
968
|
+
throw new Error('Failed to register file system provider: missing id');
|
|
962
969
|
}
|
|
963
|
-
|
|
970
|
+
set$4(fileSystemProvider.id, fileSystemProvider);
|
|
964
971
|
};
|
|
965
|
-
const
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
};
|
|
972
|
+
const readDirWithFileTypes = async (protocol, path) => {
|
|
973
|
+
try {
|
|
974
|
+
const provider = get$4(protocol);
|
|
975
|
+
return await provider.readDirWithFileTypes(path);
|
|
976
|
+
} catch (error) {
|
|
977
|
+
throw new VError(error, 'Failed to execute file system provider');
|
|
972
978
|
}
|
|
973
|
-
return {
|
|
974
|
-
code: Custom,
|
|
975
|
-
message: prettyError.message,
|
|
976
|
-
data: {
|
|
977
|
-
stack: prettyError.stack,
|
|
978
|
-
codeFrame: prettyError.codeFrame,
|
|
979
|
-
type: getErrorType(prettyError),
|
|
980
|
-
code: prettyError.code,
|
|
981
|
-
name: prettyError.name
|
|
982
|
-
}
|
|
983
|
-
};
|
|
984
979
|
};
|
|
985
|
-
const
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
980
|
+
const readFile = async (protocol, path) => {
|
|
981
|
+
try {
|
|
982
|
+
const provider = get$4(protocol);
|
|
983
|
+
return await provider.readFile(path);
|
|
984
|
+
} catch (error) {
|
|
985
|
+
throw new VError(error, 'Failed to execute file system provider');
|
|
986
|
+
}
|
|
991
987
|
};
|
|
992
|
-
const
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
988
|
+
const readFileExternal = async path => {
|
|
989
|
+
// TODO when file is local,
|
|
990
|
+
// don't ask renderer worker
|
|
991
|
+
// instead read file directly from shared process
|
|
992
|
+
// this avoid parsing the potentially large message
|
|
993
|
+
// and improve performance by not blocking the renderer worker
|
|
994
|
+
// when reading / writing large files
|
|
995
|
+
const content = await invoke$1('FileSystem.readFile', path);
|
|
996
|
+
return content;
|
|
997
997
|
};
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
998
|
+
const readDirWithFileTypesExternal = async path => {
|
|
999
|
+
// TODO when file is local,
|
|
1000
|
+
// don't ask renderer worker
|
|
1001
|
+
// instead read file directly from shared process
|
|
1002
|
+
// this avoid parsing the potentially large message
|
|
1003
|
+
// and improve performance by not blocking the renderer worker
|
|
1004
|
+
// when reading / writing large files
|
|
1005
|
+
const content = await invoke$1('FileSystem.readDirWithFileTypes', path);
|
|
1006
|
+
return content;
|
|
1004
1007
|
};
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
+
const writeFile = async (protocol, uri, content) => {
|
|
1009
|
+
try {
|
|
1010
|
+
const provider = get$4(protocol);
|
|
1011
|
+
return await provider.writeFile(uri, content);
|
|
1012
|
+
} catch (error) {
|
|
1013
|
+
throw new VError(error, 'Failed to execute file system provider');
|
|
1014
|
+
}
|
|
1008
1015
|
};
|
|
1009
|
-
const
|
|
1016
|
+
const getPathSeparator = protocol => {
|
|
1010
1017
|
try {
|
|
1011
|
-
const
|
|
1012
|
-
return
|
|
1018
|
+
const provider = get$4(protocol);
|
|
1019
|
+
return provider.pathSeparator;
|
|
1013
1020
|
} catch (error) {
|
|
1014
|
-
|
|
1021
|
+
throw new VError(error, 'Failed to execute file system provider');
|
|
1015
1022
|
}
|
|
1016
1023
|
};
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1024
|
+
|
|
1025
|
+
const {
|
|
1026
|
+
registerFormattingProvider,
|
|
1027
|
+
executeFormattingProvider,
|
|
1028
|
+
reset: reset$7
|
|
1029
|
+
} = create$a({
|
|
1030
|
+
name: 'Formatting',
|
|
1031
|
+
executeKey: 'format',
|
|
1032
|
+
resultShape: {
|
|
1033
|
+
allowUndefined: true,
|
|
1034
|
+
type: Array$1,
|
|
1035
|
+
items: {
|
|
1036
|
+
type: Object$1,
|
|
1037
|
+
properties: {
|
|
1038
|
+
startOffset: {
|
|
1039
|
+
type: Number
|
|
1040
|
+
},
|
|
1041
|
+
endOffset: {
|
|
1042
|
+
type: Number
|
|
1043
|
+
},
|
|
1044
|
+
inserted: {
|
|
1045
|
+
type: String$1
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
const getOffset = (textDocument, position) => {
|
|
1053
|
+
let offset = 0;
|
|
1054
|
+
let rowIndex = 0;
|
|
1055
|
+
while (rowIndex++ < position.rowIndex) {
|
|
1056
|
+
const newLineIndex = textDocument.text.indexOf('\n', offset);
|
|
1057
|
+
offset = newLineIndex + 1;
|
|
1058
|
+
}
|
|
1059
|
+
offset += position.columnIndex;
|
|
1060
|
+
return offset;
|
|
1025
1061
|
};
|
|
1026
|
-
const defaultResolve = resolve;
|
|
1027
1062
|
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1063
|
+
const getPosition = (textDocument, offset) => {
|
|
1064
|
+
let index = 0;
|
|
1065
|
+
let rowIndex = 0;
|
|
1066
|
+
let newLineIndex = 0;
|
|
1067
|
+
const text = textDocument.text;
|
|
1068
|
+
while (index < offset) {
|
|
1069
|
+
newLineIndex = text.indexOf('\n', index);
|
|
1070
|
+
if (newLineIndex === -1) {
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
const newIndex = newLineIndex + 1;
|
|
1074
|
+
if (newIndex > offset) {
|
|
1075
|
+
break;
|
|
1076
|
+
}
|
|
1077
|
+
index = newIndex;
|
|
1078
|
+
rowIndex++;
|
|
1041
1079
|
}
|
|
1080
|
+
const columnIndex = offset - index;
|
|
1042
1081
|
return {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
execute: args[2],
|
|
1046
|
-
resolve: args[3],
|
|
1047
|
-
preparePrettyError: args[4],
|
|
1048
|
-
logError: args[5],
|
|
1049
|
-
requiresSocket: args[6]
|
|
1082
|
+
rowIndex,
|
|
1083
|
+
columnIndex
|
|
1050
1084
|
};
|
|
1051
1085
|
};
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1086
|
+
|
|
1087
|
+
const {
|
|
1088
|
+
registerHoverProvider,
|
|
1089
|
+
executeHoverProvider,
|
|
1090
|
+
reset: reset$6
|
|
1091
|
+
} = create$a({
|
|
1092
|
+
name: 'Hover',
|
|
1093
|
+
resultShape: {
|
|
1094
|
+
allowUndefined: true,
|
|
1095
|
+
type: Object$1,
|
|
1096
|
+
properties: {}
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
const {
|
|
1101
|
+
registerImplementationProvider,
|
|
1102
|
+
executeImplementationProvider,
|
|
1103
|
+
reset: reset$5
|
|
1104
|
+
} = create$a({
|
|
1105
|
+
name: 'Implementation',
|
|
1106
|
+
resultShape: {
|
|
1107
|
+
type: Array$1,
|
|
1108
|
+
items: {
|
|
1109
|
+
type: Object$1
|
|
1073
1110
|
}
|
|
1074
|
-
resolve(message.id, message);
|
|
1075
|
-
return;
|
|
1076
1111
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
const WebSocket$1 = 5;
|
|
1115
|
+
const ElectronMessagePort = 6;
|
|
1116
|
+
const ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1 = 7;
|
|
1117
|
+
|
|
1118
|
+
const getModule$3 = method => {
|
|
1119
|
+
switch (method) {
|
|
1120
|
+
case WebSocket$1:
|
|
1121
|
+
return Promise.resolve().then(function () { return IpcParentWithWebSocket; });
|
|
1122
|
+
case ElectronMessagePort:
|
|
1123
|
+
return Promise.resolve().then(function () { return IpcParentWithNode; });
|
|
1124
|
+
case ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1:
|
|
1125
|
+
return Promise.resolve().then(function () { return IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug; });
|
|
1126
|
+
default:
|
|
1127
|
+
throw new Error('unexpected ipc type');
|
|
1080
1128
|
}
|
|
1081
|
-
throw new JsonRpcError('unexpected message');
|
|
1082
1129
|
};
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1130
|
+
|
|
1131
|
+
const create$9 = async ({
|
|
1132
|
+
method,
|
|
1133
|
+
...options
|
|
1134
|
+
}) => {
|
|
1135
|
+
try {
|
|
1136
|
+
const module = await getModule$3(method);
|
|
1137
|
+
// @ts-ignore
|
|
1138
|
+
const rawIpc = await module.create(options);
|
|
1139
|
+
// @ts-ignore
|
|
1140
|
+
const ipc = module.wrap(rawIpc);
|
|
1141
|
+
return ipc;
|
|
1142
|
+
} catch (error) {
|
|
1143
|
+
throw new VError(error, `Failed to create ipc`);
|
|
1092
1144
|
}
|
|
1093
|
-
const responseMessage = await promise;
|
|
1094
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
1095
|
-
};
|
|
1096
|
-
const send$1 = (transport, method, ...params) => {
|
|
1097
|
-
const message = create$4$1(method, params);
|
|
1098
|
-
transport.send(message);
|
|
1099
|
-
};
|
|
1100
|
-
const invoke$1 = (ipc, method, ...params) => {
|
|
1101
|
-
return invokeHelper(ipc, method, params, false);
|
|
1102
|
-
};
|
|
1103
|
-
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
1104
|
-
return invokeHelper(ipc, method, params, true);
|
|
1105
1145
|
};
|
|
1106
1146
|
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
const fn = getCommand(command);
|
|
1116
|
-
if (!fn) {
|
|
1117
|
-
throw new Error(`command not found ${command}`);
|
|
1147
|
+
const JsonRpc = 1;
|
|
1148
|
+
|
|
1149
|
+
const getModule$2 = method => {
|
|
1150
|
+
switch (method) {
|
|
1151
|
+
case JsonRpc:
|
|
1152
|
+
return Promise.resolve().then(function () { return RpcParentWithJsonRpc; });
|
|
1153
|
+
default:
|
|
1154
|
+
throw new Error('unexpected rpc type');
|
|
1118
1155
|
}
|
|
1119
|
-
return fn(...args);
|
|
1120
1156
|
};
|
|
1121
1157
|
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1158
|
+
const create$8 = async ({
|
|
1159
|
+
method,
|
|
1160
|
+
...options
|
|
1161
|
+
}) => {
|
|
1162
|
+
const module = await getModule$2(method);
|
|
1163
|
+
// @ts-ignore
|
|
1164
|
+
const rpc = module.create(options);
|
|
1165
|
+
return rpc;
|
|
1127
1166
|
};
|
|
1128
|
-
|
|
1129
|
-
|
|
1167
|
+
|
|
1168
|
+
const defaultExecute$1 = () => {
|
|
1169
|
+
throw new Error('not implemented');
|
|
1130
1170
|
};
|
|
1131
|
-
const
|
|
1132
|
-
|
|
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
|
+
}
|
|
1133
1194
|
};
|
|
1134
1195
|
|
|
1135
|
-
const
|
|
1136
|
-
|
|
1196
|
+
const confirm = message => {
|
|
1197
|
+
string(message);
|
|
1198
|
+
const result = invoke$1('ConfirmPrompt.prompt', message);
|
|
1199
|
+
return result;
|
|
1137
1200
|
};
|
|
1138
1201
|
|
|
1139
|
-
const
|
|
1140
|
-
/**
|
|
1141
|
-
* @type {any}
|
|
1142
|
-
*/
|
|
1143
|
-
ipc: undefined
|
|
1144
|
-
};
|
|
1145
|
-
const get$4 = () => {
|
|
1146
|
-
return state$7.ipc;
|
|
1147
|
-
};
|
|
1148
|
-
const set$4 = ipc => {
|
|
1149
|
-
state$7.ipc = ipc;
|
|
1150
|
-
};
|
|
1202
|
+
const ExtensionHostQuickPickShow = 'ExtensionHostQuickPick.show';
|
|
1151
1203
|
|
|
1152
|
-
const
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
}
|
|
1156
|
-
const
|
|
1157
|
-
const
|
|
1158
|
-
return invoke$1(
|
|
1159
|
-
};
|
|
1160
|
-
const invokeAndTransfer = (method, ...params) => {
|
|
1161
|
-
const ipc = get$4();
|
|
1162
|
-
return invokeAndTransfer$1(ipc, method, ...params);
|
|
1163
|
-
};
|
|
1164
|
-
const listen$1 = ipc => {
|
|
1165
|
-
handleIpc(ipc);
|
|
1166
|
-
set$4(ipc);
|
|
1204
|
+
const showQuickPick = async ({
|
|
1205
|
+
getPicks,
|
|
1206
|
+
toPick
|
|
1207
|
+
}) => {
|
|
1208
|
+
const rawPicks = await getPicks();
|
|
1209
|
+
const picks = rawPicks.map(toPick);
|
|
1210
|
+
return invoke$1(ExtensionHostQuickPickShow, picks);
|
|
1167
1211
|
};
|
|
1168
1212
|
|
|
1169
|
-
const
|
|
1170
|
-
|
|
1213
|
+
const {
|
|
1214
|
+
registerReferenceProvider,
|
|
1215
|
+
executeReferenceProvider,
|
|
1216
|
+
executefileReferenceProvider,
|
|
1217
|
+
reset: reset$4
|
|
1218
|
+
} = create$a({
|
|
1219
|
+
name: 'Reference',
|
|
1220
|
+
resultShape: {
|
|
1221
|
+
type: Array$1,
|
|
1222
|
+
items: {
|
|
1223
|
+
type: Object$1
|
|
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
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
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();
|
|
1171
1265
|
};
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
}
|
|
1178
|
-
return provider;
|
|
1266
|
+
const extensionHostSubWorkerUrl = getExtensionHostSubWorkerUrl();
|
|
1267
|
+
|
|
1268
|
+
const set$3 = async (url, contentSecurityPolicy) => {
|
|
1269
|
+
const pathName = new URL(url).pathname;
|
|
1270
|
+
await invoke$1('ExtensionHostWorkerContentSecurityPolicy.set', pathName, contentSecurityPolicy);
|
|
1179
1271
|
};
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
state$6.debugProviderMap[debugProvider.id] = debugProvider;
|
|
1272
|
+
|
|
1273
|
+
const rpcs$1 = Object.create(null);
|
|
1274
|
+
const add$1 = (id, rpc) => {
|
|
1275
|
+
rpcs$1[id] = rpc;
|
|
1185
1276
|
};
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1188
|
-
const handlePaused = params => {
|
|
1189
|
-
console.log('send paused', params);
|
|
1190
|
-
send('Debug.paused', params);
|
|
1191
|
-
};
|
|
1192
|
-
const handleResumed = () => {
|
|
1193
|
-
send('Debug.resumed');
|
|
1194
|
-
};
|
|
1195
|
-
const handleScriptParsed = parsedScript => {
|
|
1196
|
-
send('Debug.scriptParsed', parsedScript);
|
|
1197
|
-
};
|
|
1198
|
-
const provider = getDebugProvider(protocol);
|
|
1199
|
-
await provider.start({
|
|
1200
|
-
handlePaused,
|
|
1201
|
-
handleResumed,
|
|
1202
|
-
handleScriptParsed
|
|
1203
|
-
}, path);
|
|
1204
|
-
} catch (error) {
|
|
1205
|
-
throw new VError(error, 'Failed to execute debug provider');
|
|
1206
|
-
}
|
|
1277
|
+
const get$3 = id => {
|
|
1278
|
+
return rpcs$1[id];
|
|
1207
1279
|
};
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
return processes;
|
|
1214
|
-
} catch (error) {
|
|
1215
|
-
throw new VError(error, 'Failed to execute debug provider');
|
|
1216
|
-
}
|
|
1280
|
+
|
|
1281
|
+
const registry = Object.create(null);
|
|
1282
|
+
const rpcs = Object.create(null);
|
|
1283
|
+
const register$1 = (id, execute) => {
|
|
1284
|
+
registry[id] = execute;
|
|
1217
1285
|
};
|
|
1218
|
-
const
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
} catch (error) {
|
|
1223
|
-
throw new VError(error, 'Failed to execute debug provider');
|
|
1224
|
-
}
|
|
1286
|
+
const acquire = id => {
|
|
1287
|
+
const fn = registry[id];
|
|
1288
|
+
delete registry[id];
|
|
1289
|
+
return fn;
|
|
1225
1290
|
};
|
|
1226
|
-
const
|
|
1227
|
-
|
|
1228
|
-
const provider = getDebugProvider(protocol);
|
|
1229
|
-
return await provider.pause();
|
|
1230
|
-
} catch (error) {
|
|
1231
|
-
throw new VError(error, 'Failed to execute debug provider');
|
|
1232
|
-
}
|
|
1291
|
+
const get$2 = id => {
|
|
1292
|
+
return rpcs[id];
|
|
1233
1293
|
};
|
|
1234
|
-
const
|
|
1235
|
-
|
|
1236
|
-
const provider = getDebugProvider(protocol);
|
|
1237
|
-
return await provider.stepInto();
|
|
1238
|
-
} catch (error) {
|
|
1239
|
-
throw new VError(error, 'Failed to execute debug provider');
|
|
1240
|
-
}
|
|
1294
|
+
const set$2 = (id, rpc) => {
|
|
1295
|
+
rpcs[id] = rpc;
|
|
1241
1296
|
};
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
throw new
|
|
1297
|
+
|
|
1298
|
+
const createRpcWithId$1 = async id => {
|
|
1299
|
+
const fn = acquire(id);
|
|
1300
|
+
const info = get$3(id);
|
|
1301
|
+
if (!info) {
|
|
1302
|
+
throw new Error(`rpc with id ${id} not found`);
|
|
1248
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;
|
|
1249
1317
|
};
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
throw new VError(error, 'Failed to execute debug provider');
|
|
1318
|
+
|
|
1319
|
+
const getOrCreateRpc = async id => {
|
|
1320
|
+
const rpc = get$2(id);
|
|
1321
|
+
if (!rpc) {
|
|
1322
|
+
set$2(id, createRpcWithId$1(id));
|
|
1256
1323
|
}
|
|
1324
|
+
return get$2(id);
|
|
1257
1325
|
};
|
|
1258
|
-
const
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1326
|
+
const createRpcWithId = ({
|
|
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;
|
|
1265
1339
|
};
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
return await provider.getProperties(objectId);
|
|
1270
|
-
} catch (error) {
|
|
1271
|
-
throw new VError(error, 'Failed to execute debug provider');
|
|
1272
|
-
}
|
|
1340
|
+
|
|
1341
|
+
const defaultExecute = () => {
|
|
1342
|
+
throw new Error('not implemented');
|
|
1273
1343
|
};
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
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);
|
|
1280
1360
|
}
|
|
1361
|
+
const ipc = await create$9({
|
|
1362
|
+
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
1363
|
+
url: extensionHostSubWorkerUrl,
|
|
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;
|
|
1281
1373
|
};
|
|
1282
|
-
const
|
|
1374
|
+
const createRpc$1 = ({
|
|
1375
|
+
id,
|
|
1376
|
+
url,
|
|
1377
|
+
name,
|
|
1378
|
+
execute = defaultExecute,
|
|
1379
|
+
contentSecurityPolicy
|
|
1380
|
+
}) => {
|
|
1283
1381
|
try {
|
|
1284
|
-
|
|
1285
|
-
|
|
1382
|
+
if (id) {
|
|
1383
|
+
string(id);
|
|
1384
|
+
return createRpcWithId({
|
|
1385
|
+
id,
|
|
1386
|
+
execute
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
return createLegacyRpc({
|
|
1390
|
+
url,
|
|
1391
|
+
name,
|
|
1392
|
+
execute,
|
|
1393
|
+
contentSecurityPolicy
|
|
1394
|
+
});
|
|
1286
1395
|
} catch (error) {
|
|
1287
|
-
throw new VError(error,
|
|
1396
|
+
throw new VError(error, `Failed to create webworker rpc`);
|
|
1288
1397
|
}
|
|
1289
1398
|
};
|
|
1290
1399
|
|
|
1291
1400
|
const {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
reset: reset$
|
|
1295
|
-
} = create$
|
|
1296
|
-
name: '
|
|
1401
|
+
registerSelectionProvider,
|
|
1402
|
+
executeSelectionProvider,
|
|
1403
|
+
reset: reset$2
|
|
1404
|
+
} = create$a({
|
|
1405
|
+
name: 'Selection',
|
|
1297
1406
|
resultShape: {
|
|
1298
1407
|
allowUndefined: true,
|
|
1299
|
-
type: Object$1,
|
|
1300
|
-
properties: {
|
|
1301
|
-
uri: {
|
|
1302
|
-
type: String
|
|
1303
|
-
},
|
|
1304
|
-
startOffset: {
|
|
1305
|
-
type: Number
|
|
1306
|
-
},
|
|
1307
|
-
endOffset: {
|
|
1308
|
-
type: Number
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
|
|
1314
|
-
const {
|
|
1315
|
-
registerDiagnosticProvider,
|
|
1316
|
-
executeDiagnosticProvider
|
|
1317
|
-
} = create$9({
|
|
1318
|
-
name: 'Diagnostic',
|
|
1319
|
-
resultShape: {
|
|
1320
1408
|
type: Array$1,
|
|
1321
1409
|
items: {
|
|
1322
|
-
type:
|
|
1410
|
+
type: 'number'
|
|
1323
1411
|
}
|
|
1324
1412
|
}
|
|
1325
1413
|
});
|
|
1326
1414
|
|
|
1327
|
-
const
|
|
1328
|
-
|
|
1329
|
-
const result = invoke('ExtensionHostDialog.showInformationMessage', message);
|
|
1330
|
-
return result;
|
|
1415
|
+
const state$5 = {
|
|
1416
|
+
providers: Object.create(null)
|
|
1331
1417
|
};
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
const exec = async (command, args, options) => {
|
|
1336
|
-
throw new DepecratedError(`vscode.exec is deprecated, use createNodeRpc instead`);
|
|
1418
|
+
const registerSourceControlProvider = provider => {
|
|
1419
|
+
state$5.providers[provider.id] = provider;
|
|
1337
1420
|
};
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1421
|
+
const getFilesFromProvider = provider => {
|
|
1422
|
+
return provider.getChangedFiles();
|
|
1423
|
+
};
|
|
1424
|
+
const getChangedFiles = async providerId => {
|
|
1425
|
+
const provider = state$5.providers[providerId];
|
|
1342
1426
|
if (!provider) {
|
|
1343
|
-
|
|
1344
|
-
throw new VError(`no file system provider for protocol "${protocol}" found`);
|
|
1427
|
+
throw new Error('no source control provider found');
|
|
1345
1428
|
}
|
|
1346
|
-
|
|
1429
|
+
const changedFiles = await getFilesFromProvider(provider);
|
|
1430
|
+
const flattenedChangedFiles = changedFiles;
|
|
1431
|
+
return flattenedChangedFiles;
|
|
1347
1432
|
};
|
|
1348
|
-
const
|
|
1349
|
-
|
|
1350
|
-
|
|
1433
|
+
const getFileBefore = async (providerId, uri) => {
|
|
1434
|
+
string(providerId);
|
|
1435
|
+
string(uri);
|
|
1436
|
+
const provider = state$5.providers[providerId];
|
|
1437
|
+
if (!provider) {
|
|
1438
|
+
throw new Error('no source control provider found');
|
|
1351
1439
|
}
|
|
1352
|
-
|
|
1440
|
+
return provider.getFileBefore(uri);
|
|
1353
1441
|
};
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1442
|
+
const getGroupsFromProvider = async (provider, cwd) => {
|
|
1443
|
+
if (provider.getGroups) {
|
|
1444
|
+
return provider.getGroups(cwd);
|
|
1445
|
+
}
|
|
1446
|
+
if (provider.getChangedFiles) {
|
|
1447
|
+
const files = await provider.getChangedFiles();
|
|
1448
|
+
const groups = [{
|
|
1449
|
+
id: 'changes',
|
|
1450
|
+
label: 'Changes',
|
|
1451
|
+
items: files
|
|
1452
|
+
}];
|
|
1453
|
+
return groups;
|
|
1358
1454
|
}
|
|
1359
|
-
|
|
1455
|
+
throw new Error('source control provider is missing required function getGroups');
|
|
1360
1456
|
};
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
} catch (error) {
|
|
1366
|
-
throw new VError(error, 'Failed to execute file system provider');
|
|
1457
|
+
const getGroups = async (providerId, cwd) => {
|
|
1458
|
+
const provider = state$5.providers[providerId];
|
|
1459
|
+
if (!provider) {
|
|
1460
|
+
throw new Error('no source control provider found');
|
|
1367
1461
|
}
|
|
1462
|
+
const groups = await getGroupsFromProvider(provider, cwd);
|
|
1463
|
+
return groups;
|
|
1368
1464
|
};
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
} catch (error) {
|
|
1374
|
-
throw new VError(error, 'Failed to execute file system provider');
|
|
1465
|
+
const acceptInput = async (providerId, value) => {
|
|
1466
|
+
const provider = state$5.providers[providerId];
|
|
1467
|
+
if (!provider) {
|
|
1468
|
+
throw new Error('no source control provider found');
|
|
1375
1469
|
}
|
|
1470
|
+
await provider.acceptInput(value);
|
|
1376
1471
|
};
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
//
|
|
1383
|
-
|
|
1384
|
-
const content = await invoke('FileSystem.readFile', path);
|
|
1385
|
-
return content;
|
|
1472
|
+
const add = async path => {
|
|
1473
|
+
const provider = Object.values(state$5.providers)[0];
|
|
1474
|
+
if (!provider) {
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
// @ts-ignore
|
|
1478
|
+
await provider.add(path);
|
|
1386
1479
|
};
|
|
1387
|
-
const
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
//
|
|
1393
|
-
|
|
1394
|
-
const content = await invoke('FileSystem.readDirWithFileTypes', path);
|
|
1395
|
-
return content;
|
|
1480
|
+
const discard = async path => {
|
|
1481
|
+
const provider = Object.values(state$5.providers)[0];
|
|
1482
|
+
if (!provider) {
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
// @ts-ignore
|
|
1486
|
+
await provider.discard(path);
|
|
1396
1487
|
};
|
|
1397
|
-
const
|
|
1488
|
+
const getEnabledProviderIds = async (scheme, root) => {
|
|
1489
|
+
string(scheme);
|
|
1490
|
+
string(root);
|
|
1491
|
+
const providers = Object.values(state$5.providers);
|
|
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;
|
|
1506
|
+
};
|
|
1507
|
+
|
|
1508
|
+
const {
|
|
1509
|
+
registerTabCompletionProvider,
|
|
1510
|
+
executeTabCompletionProvider,
|
|
1511
|
+
reset: reset$1
|
|
1512
|
+
} = create$a({
|
|
1513
|
+
name: 'TabCompletion',
|
|
1514
|
+
resultShape: {
|
|
1515
|
+
type: Object$1,
|
|
1516
|
+
allowUndefined: true
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
const state$4 = {
|
|
1521
|
+
textSearchProviders: Object.create(null)
|
|
1522
|
+
};
|
|
1523
|
+
const registerTextSearchProvider = textSearchProvider => {
|
|
1398
1524
|
try {
|
|
1399
|
-
|
|
1400
|
-
|
|
1525
|
+
if (!textSearchProvider) {
|
|
1526
|
+
throw new Error('textSearchProvider is not defined');
|
|
1527
|
+
}
|
|
1528
|
+
if (!textSearchProvider.scheme) {
|
|
1529
|
+
throw new Error('textSearchProvider is missing scheme');
|
|
1530
|
+
}
|
|
1531
|
+
state$4.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
|
|
1401
1532
|
} catch (error) {
|
|
1402
|
-
throw new VError(error, 'Failed to
|
|
1533
|
+
throw new VError(error, 'Failed to register text search provider');
|
|
1403
1534
|
}
|
|
1404
1535
|
};
|
|
1405
|
-
const
|
|
1536
|
+
const executeTextSearchProvider = async (scheme, query) => {
|
|
1406
1537
|
try {
|
|
1407
|
-
const
|
|
1408
|
-
|
|
1538
|
+
const textSearchProvider = state$4.textSearchProviders[scheme];
|
|
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;
|
|
1409
1544
|
} catch (error) {
|
|
1410
|
-
throw new VError(error, 'Failed to execute
|
|
1545
|
+
throw new VError(error, 'Failed to execute text search provider');
|
|
1411
1546
|
}
|
|
1412
1547
|
};
|
|
1413
1548
|
|
|
1414
1549
|
const {
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
reset
|
|
1418
|
-
} = create$
|
|
1419
|
-
name: '
|
|
1420
|
-
executeKey: 'format',
|
|
1550
|
+
registerTypeDefinitionProvider,
|
|
1551
|
+
executeTypeDefinitionProvider,
|
|
1552
|
+
reset
|
|
1553
|
+
} = create$a({
|
|
1554
|
+
name: 'TypeDefinition',
|
|
1421
1555
|
resultShape: {
|
|
1422
1556
|
allowUndefined: true,
|
|
1423
|
-
type:
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
inserted: {
|
|
1434
|
-
type: String
|
|
1435
|
-
}
|
|
1557
|
+
type: Object$1,
|
|
1558
|
+
properties: {
|
|
1559
|
+
uri: {
|
|
1560
|
+
type: String$1
|
|
1561
|
+
},
|
|
1562
|
+
startOffset: {
|
|
1563
|
+
type: Number
|
|
1564
|
+
},
|
|
1565
|
+
endOffset: {
|
|
1566
|
+
type: Number
|
|
1436
1567
|
}
|
|
1437
1568
|
}
|
|
1438
1569
|
}
|
|
1439
1570
|
});
|
|
1440
1571
|
|
|
1441
|
-
const
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
offset = newLineIndex + 1;
|
|
1572
|
+
const RE_PROTOCOL = /^([a-z\-]+):\/\//;
|
|
1573
|
+
const getProtocol = uri => {
|
|
1574
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1575
|
+
if (protocolMatch) {
|
|
1576
|
+
return protocolMatch[1];
|
|
1447
1577
|
}
|
|
1448
|
-
|
|
1449
|
-
return offset;
|
|
1578
|
+
return '';
|
|
1450
1579
|
};
|
|
1451
1580
|
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
while (index < offset) {
|
|
1458
|
-
newLineIndex = text.indexOf('\n', index);
|
|
1459
|
-
if (newLineIndex === -1) {
|
|
1460
|
-
break;
|
|
1461
|
-
}
|
|
1462
|
-
const newIndex = newLineIndex + 1;
|
|
1463
|
-
if (newIndex > offset) {
|
|
1464
|
-
break;
|
|
1465
|
-
}
|
|
1466
|
-
index = newIndex;
|
|
1467
|
-
rowIndex++;
|
|
1468
|
-
}
|
|
1469
|
-
const columnIndex = offset - index;
|
|
1581
|
+
const getPortTuple = () => {
|
|
1582
|
+
const {
|
|
1583
|
+
port1,
|
|
1584
|
+
port2
|
|
1585
|
+
} = new MessageChannel();
|
|
1470
1586
|
return {
|
|
1471
|
-
|
|
1472
|
-
|
|
1587
|
+
port1,
|
|
1588
|
+
port2
|
|
1473
1589
|
};
|
|
1474
1590
|
};
|
|
1475
1591
|
|
|
1476
|
-
const
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1592
|
+
const Two = '2.0';
|
|
1593
|
+
const create$4$1 = (method, params) => {
|
|
1594
|
+
return {
|
|
1595
|
+
jsonrpc: Two,
|
|
1596
|
+
method,
|
|
1597
|
+
params
|
|
1598
|
+
};
|
|
1599
|
+
};
|
|
1600
|
+
const callbacks = Object.create(null);
|
|
1601
|
+
const set$1 = (id, fn) => {
|
|
1602
|
+
callbacks[id] = fn;
|
|
1603
|
+
};
|
|
1604
|
+
const get$1 = id => {
|
|
1605
|
+
return callbacks[id];
|
|
1606
|
+
};
|
|
1607
|
+
const remove = id => {
|
|
1608
|
+
delete callbacks[id];
|
|
1609
|
+
};
|
|
1610
|
+
let id = 0;
|
|
1611
|
+
const create$3$1 = () => {
|
|
1612
|
+
return ++id;
|
|
1613
|
+
};
|
|
1614
|
+
const registerPromise = () => {
|
|
1615
|
+
const id = create$3$1();
|
|
1616
|
+
const {
|
|
1617
|
+
resolve,
|
|
1618
|
+
promise
|
|
1619
|
+
} = Promise.withResolvers();
|
|
1620
|
+
set$1(id, resolve);
|
|
1621
|
+
return {
|
|
1622
|
+
id,
|
|
1623
|
+
promise
|
|
1624
|
+
};
|
|
1625
|
+
};
|
|
1626
|
+
const create$2$1 = (method, params) => {
|
|
1627
|
+
const {
|
|
1628
|
+
id,
|
|
1629
|
+
promise
|
|
1630
|
+
} = registerPromise();
|
|
1631
|
+
const message = {
|
|
1632
|
+
jsonrpc: Two,
|
|
1633
|
+
method,
|
|
1634
|
+
params,
|
|
1635
|
+
id
|
|
1636
|
+
};
|
|
1637
|
+
return {
|
|
1638
|
+
message,
|
|
1639
|
+
promise
|
|
1640
|
+
};
|
|
1641
|
+
};
|
|
1642
|
+
class JsonRpcError extends Error {
|
|
1643
|
+
constructor(message) {
|
|
1644
|
+
super(message);
|
|
1645
|
+
this.name = 'JsonRpcError';
|
|
1486
1646
|
}
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
const
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1647
|
+
}
|
|
1648
|
+
const NewLine$1 = '\n';
|
|
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;
|
|
1499
1666
|
}
|
|
1500
1667
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
const WebSocket$1 = 5;
|
|
1504
|
-
const ElectronMessagePort = 6;
|
|
1505
|
-
const ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1 = 7;
|
|
1506
|
-
|
|
1507
|
-
const getModule$3 = method => {
|
|
1508
|
-
switch (method) {
|
|
1509
|
-
case WebSocket$1:
|
|
1510
|
-
return Promise.resolve().then(function () { return IpcParentWithWebSocket; });
|
|
1511
|
-
case ElectronMessagePort:
|
|
1512
|
-
return Promise.resolve().then(function () { return IpcParentWithNode; });
|
|
1513
|
-
case ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1:
|
|
1514
|
-
return Promise.resolve().then(function () { return IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug; });
|
|
1515
|
-
default:
|
|
1516
|
-
throw new Error('unexpected ipc type');
|
|
1668
|
+
if (message.startsWith('TypeError: ')) {
|
|
1669
|
+
return TypeError;
|
|
1517
1670
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
const create$7 = async ({
|
|
1521
|
-
method,
|
|
1522
|
-
...options
|
|
1523
|
-
}) => {
|
|
1524
|
-
try {
|
|
1525
|
-
const module = await getModule$3(method);
|
|
1526
|
-
// @ts-ignore
|
|
1527
|
-
const rawIpc = await module.create(options);
|
|
1528
|
-
// @ts-ignore
|
|
1529
|
-
const ipc = module.wrap(rawIpc);
|
|
1530
|
-
return ipc;
|
|
1531
|
-
} catch (error) {
|
|
1532
|
-
throw new VError(error, `Failed to create ipc`);
|
|
1671
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
1672
|
+
return SyntaxError;
|
|
1533
1673
|
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
const JsonRpc = 1;
|
|
1537
|
-
|
|
1538
|
-
const getModule$2 = method => {
|
|
1539
|
-
switch (method) {
|
|
1540
|
-
case JsonRpc:
|
|
1541
|
-
return Promise.resolve().then(function () { return RpcParentWithJsonRpc; });
|
|
1542
|
-
default:
|
|
1543
|
-
throw new Error('unexpected rpc type');
|
|
1674
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
1675
|
+
return ReferenceError;
|
|
1544
1676
|
}
|
|
1677
|
+
return Error;
|
|
1545
1678
|
};
|
|
1546
|
-
|
|
1547
|
-
const
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1679
|
+
const constructError = (message, type, name) => {
|
|
1680
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
1681
|
+
if (ErrorConstructor === DOMException && name) {
|
|
1682
|
+
return new ErrorConstructor(message, name);
|
|
1683
|
+
}
|
|
1684
|
+
if (ErrorConstructor === Error) {
|
|
1685
|
+
const error = new Error(message);
|
|
1686
|
+
if (name && name !== 'VError') {
|
|
1687
|
+
error.name = name;
|
|
1688
|
+
}
|
|
1689
|
+
return error;
|
|
1690
|
+
}
|
|
1691
|
+
return new ErrorConstructor(message);
|
|
1555
1692
|
};
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
throw new Error('not implemented');
|
|
1693
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
1694
|
+
return string.indexOf(NewLine$1, startIndex);
|
|
1559
1695
|
};
|
|
1560
|
-
const
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
}) => {
|
|
1565
|
-
try {
|
|
1566
|
-
string(path);
|
|
1567
|
-
fn(execute);
|
|
1568
|
-
const ipc = await create$7({
|
|
1569
|
-
method: ElectronMessagePort,
|
|
1570
|
-
type: 'extension-host-helper-process',
|
|
1571
|
-
name
|
|
1572
|
-
});
|
|
1573
|
-
const rpc = await create$6({
|
|
1574
|
-
ipc,
|
|
1575
|
-
method: JsonRpc,
|
|
1576
|
-
execute
|
|
1577
|
-
});
|
|
1578
|
-
await rpc.invoke('LoadFile.loadFile', path);
|
|
1579
|
-
return rpc;
|
|
1580
|
-
} catch (error) {
|
|
1581
|
-
throw new VError(error, `Failed to create node rpc`);
|
|
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;
|
|
1582
1700
|
}
|
|
1701
|
+
return parentStack;
|
|
1583
1702
|
};
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
string(message);
|
|
1587
|
-
const result = invoke('ConfirmPrompt.prompt', message);
|
|
1588
|
-
return result;
|
|
1703
|
+
const joinLines$1 = lines => {
|
|
1704
|
+
return lines.join(NewLine$1);
|
|
1589
1705
|
};
|
|
1590
|
-
|
|
1591
|
-
const
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
getPicks,
|
|
1595
|
-
toPick
|
|
1596
|
-
}) => {
|
|
1597
|
-
const rawPicks = await getPicks();
|
|
1598
|
-
const picks = rawPicks.map(toPick);
|
|
1599
|
-
return invoke(ExtensionHostQuickPickShow, picks);
|
|
1706
|
+
const MethodNotFound = -32601;
|
|
1707
|
+
const Custom = -32001;
|
|
1708
|
+
const splitLines$2 = lines => {
|
|
1709
|
+
return lines.split(NewLine$1);
|
|
1600
1710
|
};
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1711
|
+
const restoreJsonRpcError = error => {
|
|
1712
|
+
if (error && error instanceof Error) {
|
|
1713
|
+
return error;
|
|
1714
|
+
}
|
|
1715
|
+
const currentStack = joinLines$1(splitLines$2(new Error().stack || '').slice(1));
|
|
1716
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
1717
|
+
const restoredError = new JsonRpcError(error.message);
|
|
1718
|
+
const parentStack = getParentStack(error);
|
|
1719
|
+
restoredError.stack = parentStack + NewLine$1 + currentStack;
|
|
1720
|
+
return restoredError;
|
|
1721
|
+
}
|
|
1722
|
+
if (error && error.message) {
|
|
1723
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
1724
|
+
if (error.data) {
|
|
1725
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
1726
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
|
|
1727
|
+
} else if (error.data.stack) {
|
|
1728
|
+
restoredError.stack = error.data.stack;
|
|
1729
|
+
}
|
|
1730
|
+
if (error.data.codeFrame) {
|
|
1731
|
+
// @ts-ignore
|
|
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;
|
|
1624
1754
|
}
|
|
1625
1755
|
}
|
|
1626
|
-
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
executeprepareRenameProvider,
|
|
1633
|
-
reset: reset$3
|
|
1634
|
-
} = create$9({
|
|
1635
|
-
name: 'Rename',
|
|
1636
|
-
resultShape: {
|
|
1637
|
-
type: Object$1,
|
|
1638
|
-
allowUndefined: true
|
|
1639
|
-
},
|
|
1640
|
-
additionalMethodNames: [
|
|
1641
|
-
// @ts-ignore
|
|
1642
|
-
{
|
|
1643
|
-
name: 'prepareRename',
|
|
1644
|
-
methodName: 'prepareRename',
|
|
1645
|
-
resultShape: {
|
|
1646
|
-
type: Object$1,
|
|
1647
|
-
allowUndefined: true
|
|
1648
|
-
}
|
|
1649
|
-
}]
|
|
1650
|
-
});
|
|
1651
|
-
|
|
1652
|
-
const getExtensionHostSubWorkerUrl = () => {
|
|
1653
|
-
return new URL('../../../../extension-host-sub-worker/src/extensionHostSubWorkerMain.js', import.meta.url).toString();
|
|
1654
|
-
};
|
|
1655
|
-
const extensionHostSubWorkerUrl = getExtensionHostSubWorkerUrl();
|
|
1656
|
-
|
|
1657
|
-
const set$2 = async (url, contentSecurityPolicy) => {
|
|
1658
|
-
const pathName = new URL(url).pathname;
|
|
1659
|
-
await invoke('ExtensionHostWorkerContentSecurityPolicy.set', pathName, contentSecurityPolicy);
|
|
1660
|
-
};
|
|
1661
|
-
|
|
1662
|
-
const rpcs$1 = Object.create(null);
|
|
1663
|
-
const add$1 = (id, rpc) => {
|
|
1664
|
-
rpcs$1[id] = rpc;
|
|
1665
|
-
};
|
|
1666
|
-
const get$2 = id => {
|
|
1667
|
-
return rpcs$1[id];
|
|
1668
|
-
};
|
|
1669
|
-
|
|
1670
|
-
const registry = Object.create(null);
|
|
1671
|
-
const rpcs = Object.create(null);
|
|
1672
|
-
const register = (id, execute) => {
|
|
1673
|
-
registry[id] = execute;
|
|
1674
|
-
};
|
|
1675
|
-
const acquire = id => {
|
|
1676
|
-
const fn = registry[id];
|
|
1677
|
-
delete registry[id];
|
|
1678
|
-
return fn;
|
|
1756
|
+
return restoredError;
|
|
1757
|
+
}
|
|
1758
|
+
if (typeof error === 'string') {
|
|
1759
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
1760
|
+
}
|
|
1761
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
1679
1762
|
};
|
|
1680
|
-
const
|
|
1681
|
-
|
|
1763
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
1764
|
+
if ('error' in responseMessage) {
|
|
1765
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
1766
|
+
throw restoredError;
|
|
1767
|
+
}
|
|
1768
|
+
if ('result' in responseMessage) {
|
|
1769
|
+
return responseMessage.result;
|
|
1770
|
+
}
|
|
1771
|
+
throw new JsonRpcError('unexpected response message');
|
|
1682
1772
|
};
|
|
1683
|
-
const
|
|
1684
|
-
|
|
1773
|
+
const warn = (...args) => {
|
|
1774
|
+
console.warn(...args);
|
|
1685
1775
|
};
|
|
1686
|
-
|
|
1687
|
-
const
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1776
|
+
const resolve = (id, response) => {
|
|
1777
|
+
const fn = get$1(id);
|
|
1778
|
+
if (!fn) {
|
|
1779
|
+
console.log(response);
|
|
1780
|
+
warn(`callback ${id} may already be disposed`);
|
|
1781
|
+
return;
|
|
1692
1782
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
url: extensionHostSubWorkerUrl,
|
|
1696
|
-
name: info.name
|
|
1697
|
-
});
|
|
1698
|
-
const newRpc = await create$6({
|
|
1699
|
-
ipc,
|
|
1700
|
-
method: JsonRpc,
|
|
1701
|
-
execute: fn
|
|
1702
|
-
});
|
|
1703
|
-
await newRpc.invoke('LoadFile.loadFile', info.url);
|
|
1704
|
-
set$1(id, newRpc);
|
|
1705
|
-
return newRpc;
|
|
1783
|
+
fn(response);
|
|
1784
|
+
remove(id);
|
|
1706
1785
|
};
|
|
1707
|
-
|
|
1708
|
-
const
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
set$1(id, createRpcWithId$1(id));
|
|
1786
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
1787
|
+
const getErrorType = prettyError => {
|
|
1788
|
+
if (prettyError && prettyError.type) {
|
|
1789
|
+
return prettyError.type;
|
|
1712
1790
|
}
|
|
1713
|
-
|
|
1791
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
1792
|
+
return prettyError.constructor.name;
|
|
1793
|
+
}
|
|
1794
|
+
return undefined;
|
|
1714
1795
|
};
|
|
1715
|
-
const
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1796
|
+
const getErrorProperty = (error, prettyError) => {
|
|
1797
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
1798
|
+
return {
|
|
1799
|
+
code: MethodNotFound,
|
|
1800
|
+
message: error.message,
|
|
1801
|
+
data: error.stack
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
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
|
|
1725
1813
|
}
|
|
1726
1814
|
};
|
|
1727
|
-
return lazyRpc;
|
|
1728
|
-
};
|
|
1729
|
-
|
|
1730
|
-
const defaultExecute = () => {
|
|
1731
|
-
throw new Error('not implemented');
|
|
1732
1815
|
};
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
url,
|
|
1740
|
-
name,
|
|
1741
|
-
execute = defaultExecute,
|
|
1742
|
-
contentSecurityPolicy
|
|
1743
|
-
}) => {
|
|
1744
|
-
string(url);
|
|
1745
|
-
string(name);
|
|
1746
|
-
fn(execute);
|
|
1747
|
-
if (contentSecurityPolicy) {
|
|
1748
|
-
await set$2(url, contentSecurityPolicy);
|
|
1749
|
-
}
|
|
1750
|
-
const ipc = await create$7({
|
|
1751
|
-
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
1752
|
-
url: extensionHostSubWorkerUrl,
|
|
1753
|
-
name
|
|
1754
|
-
});
|
|
1755
|
-
const rpc = await create$6({
|
|
1756
|
-
ipc,
|
|
1757
|
-
method: JsonRpc,
|
|
1758
|
-
execute
|
|
1759
|
-
});
|
|
1760
|
-
await rpc.invoke('LoadFile.loadFile', url);
|
|
1761
|
-
return rpc;
|
|
1762
|
-
};
|
|
1763
|
-
const createRpc = ({
|
|
1764
|
-
id,
|
|
1765
|
-
url,
|
|
1766
|
-
name,
|
|
1767
|
-
execute = defaultExecute,
|
|
1768
|
-
contentSecurityPolicy
|
|
1769
|
-
}) => {
|
|
1770
|
-
try {
|
|
1771
|
-
if (id) {
|
|
1772
|
-
string(id);
|
|
1773
|
-
return createRpcWithId({
|
|
1774
|
-
id,
|
|
1775
|
-
execute
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
return createLegacyRpc({
|
|
1779
|
-
url,
|
|
1780
|
-
name,
|
|
1781
|
-
execute,
|
|
1782
|
-
contentSecurityPolicy
|
|
1783
|
-
});
|
|
1784
|
-
} catch (error) {
|
|
1785
|
-
throw new VError(error, `Failed to create webworker rpc`);
|
|
1786
|
-
}
|
|
1816
|
+
const create$1$1 = (message, error) => {
|
|
1817
|
+
return {
|
|
1818
|
+
jsonrpc: Two,
|
|
1819
|
+
id: message.id,
|
|
1820
|
+
error
|
|
1821
|
+
};
|
|
1787
1822
|
};
|
|
1788
|
-
|
|
1789
|
-
const
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
} = create$9({
|
|
1794
|
-
name: 'Selection',
|
|
1795
|
-
resultShape: {
|
|
1796
|
-
allowUndefined: true,
|
|
1797
|
-
type: Array$1,
|
|
1798
|
-
items: {
|
|
1799
|
-
type: 'number'
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
});
|
|
1803
|
-
|
|
1804
|
-
const state$5 = {
|
|
1805
|
-
providers: Object.create(null)
|
|
1823
|
+
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
1824
|
+
const prettyError = preparePrettyError(error);
|
|
1825
|
+
logError(error, prettyError);
|
|
1826
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
1827
|
+
return create$1$1(message, errorProperty);
|
|
1806
1828
|
};
|
|
1807
|
-
const
|
|
1808
|
-
|
|
1829
|
+
const create$7 = (message, result) => {
|
|
1830
|
+
return {
|
|
1831
|
+
jsonrpc: Two,
|
|
1832
|
+
id: message.id,
|
|
1833
|
+
result: result ?? null
|
|
1834
|
+
};
|
|
1809
1835
|
};
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1836
|
+
const getSuccessResponse = (message, result) => {
|
|
1837
|
+
const resultProperty = result ?? null;
|
|
1838
|
+
return create$7(message, resultProperty);
|
|
1812
1839
|
};
|
|
1813
|
-
const
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
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);
|
|
1817
1846
|
}
|
|
1818
|
-
const changedFiles = await getFilesFromProvider(provider);
|
|
1819
|
-
const flattenedChangedFiles = changedFiles;
|
|
1820
|
-
return flattenedChangedFiles;
|
|
1821
1847
|
};
|
|
1822
|
-
const
|
|
1823
|
-
|
|
1824
|
-
string(uri);
|
|
1825
|
-
const provider = state$5.providers[providerId];
|
|
1826
|
-
if (!provider) {
|
|
1827
|
-
throw new Error('no source control provider found');
|
|
1828
|
-
}
|
|
1829
|
-
return provider.getFileBefore(uri);
|
|
1848
|
+
const defaultPreparePrettyError = error => {
|
|
1849
|
+
return error;
|
|
1830
1850
|
};
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
return provider.getGroups(cwd);
|
|
1834
|
-
}
|
|
1835
|
-
if (provider.getChangedFiles) {
|
|
1836
|
-
const files = await provider.getChangedFiles();
|
|
1837
|
-
const groups = [{
|
|
1838
|
-
id: 'changes',
|
|
1839
|
-
label: 'Changes',
|
|
1840
|
-
items: files
|
|
1841
|
-
}];
|
|
1842
|
-
return groups;
|
|
1843
|
-
}
|
|
1844
|
-
throw new Error('source control provider is missing required function getGroups');
|
|
1851
|
+
const defaultLogError = () => {
|
|
1852
|
+
// ignore
|
|
1845
1853
|
};
|
|
1846
|
-
const
|
|
1847
|
-
|
|
1848
|
-
if (!provider) {
|
|
1849
|
-
throw new Error('no source control provider found');
|
|
1850
|
-
}
|
|
1851
|
-
const groups = await getGroupsFromProvider(provider, cwd);
|
|
1852
|
-
return groups;
|
|
1854
|
+
const defaultRequiresSocket = () => {
|
|
1855
|
+
return false;
|
|
1853
1856
|
};
|
|
1854
|
-
const
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
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
|
+
};
|
|
1858
1872
|
}
|
|
1859
|
-
|
|
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
|
+
};
|
|
1860
1882
|
};
|
|
1861
|
-
const
|
|
1862
|
-
const
|
|
1863
|
-
|
|
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);
|
|
1864
1906
|
return;
|
|
1865
1907
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
};
|
|
1869
|
-
const discard = async path => {
|
|
1870
|
-
const provider = Object.values(state$5.providers)[0];
|
|
1871
|
-
if (!provider) {
|
|
1908
|
+
if ('method' in message) {
|
|
1909
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1872
1910
|
return;
|
|
1873
1911
|
}
|
|
1874
|
-
|
|
1875
|
-
await provider.discard(path);
|
|
1912
|
+
throw new JsonRpcError('unexpected message');
|
|
1876
1913
|
};
|
|
1877
|
-
const
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
}
|
|
1887
|
-
// @ts-ignore
|
|
1888
|
-
const isActive = await provider.isActive(scheme, root);
|
|
1889
|
-
if (isActive) {
|
|
1890
|
-
// @ts-ignore
|
|
1891
|
-
enabledIds.push(provider.id);
|
|
1892
|
-
}
|
|
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);
|
|
1893
1923
|
}
|
|
1894
|
-
|
|
1924
|
+
const responseMessage = await promise;
|
|
1925
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
1895
1926
|
};
|
|
1896
|
-
|
|
1897
|
-
const
|
|
1898
|
-
|
|
1899
|
-
executeTabCompletionProvider,
|
|
1900
|
-
reset: reset$1
|
|
1901
|
-
} = create$9({
|
|
1902
|
-
name: 'TabCompletion',
|
|
1903
|
-
resultShape: {
|
|
1904
|
-
type: Object$1,
|
|
1905
|
-
allowUndefined: true
|
|
1906
|
-
}
|
|
1907
|
-
});
|
|
1908
|
-
|
|
1909
|
-
const state$4 = {
|
|
1910
|
-
textSearchProviders: Object.create(null)
|
|
1927
|
+
const send = (transport, method, ...params) => {
|
|
1928
|
+
const message = create$4$1(method, params);
|
|
1929
|
+
transport.send(message);
|
|
1911
1930
|
};
|
|
1912
|
-
const
|
|
1913
|
-
|
|
1914
|
-
if (!textSearchProvider) {
|
|
1915
|
-
throw new Error('textSearchProvider is not defined');
|
|
1916
|
-
}
|
|
1917
|
-
if (!textSearchProvider.scheme) {
|
|
1918
|
-
throw new Error('textSearchProvider is missing scheme');
|
|
1919
|
-
}
|
|
1920
|
-
state$4.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
|
|
1921
|
-
} catch (error) {
|
|
1922
|
-
throw new VError(error, 'Failed to register text search provider');
|
|
1923
|
-
}
|
|
1931
|
+
const invoke = (ipc, method, ...params) => {
|
|
1932
|
+
return invokeHelper(ipc, method, params, false);
|
|
1924
1933
|
};
|
|
1925
|
-
const
|
|
1926
|
-
|
|
1927
|
-
const textSearchProvider = state$4.textSearchProviders[scheme];
|
|
1928
|
-
if (!textSearchProvider) {
|
|
1929
|
-
throw new Error(`No text search provider for ${scheme} found`);
|
|
1930
|
-
}
|
|
1931
|
-
const results = await textSearchProvider.provideTextSearchResults(query);
|
|
1932
|
-
return results;
|
|
1933
|
-
} catch (error) {
|
|
1934
|
-
throw new VError(error, 'Failed to execute text search provider');
|
|
1935
|
-
}
|
|
1934
|
+
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
1935
|
+
return invokeHelper(ipc, method, params, true);
|
|
1936
1936
|
};
|
|
1937
1937
|
|
|
1938
|
-
const
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
type: String
|
|
1950
|
-
},
|
|
1951
|
-
startOffset: {
|
|
1952
|
-
type: Number
|
|
1953
|
-
},
|
|
1954
|
-
endOffset: {
|
|
1955
|
-
type: Number
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
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}`);
|
|
1958
1949
|
}
|
|
1959
|
-
|
|
1950
|
+
return fn(...args);
|
|
1951
|
+
};
|
|
1960
1952
|
|
|
1961
|
-
const
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1953
|
+
const requiresSocket$2 = () => {
|
|
1954
|
+
return false;
|
|
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);
|
|
1968
1964
|
};
|
|
1969
1965
|
|
|
1970
|
-
const
|
|
1971
|
-
|
|
1972
|
-
port1,
|
|
1973
|
-
port2
|
|
1974
|
-
} = new MessageChannel();
|
|
1975
|
-
return {
|
|
1976
|
-
port1,
|
|
1977
|
-
port2
|
|
1978
|
-
};
|
|
1966
|
+
const handleIpc$1 = ipc => {
|
|
1967
|
+
ipc.addEventListener('message', handleMessage$1);
|
|
1979
1968
|
};
|
|
1980
1969
|
|
|
1981
1970
|
const createWebViewIpc = async webView => {
|
|
@@ -1991,7 +1980,7 @@ const createWebViewIpc = async webView => {
|
|
|
1991
1980
|
port2.onmessage = resolve;
|
|
1992
1981
|
});
|
|
1993
1982
|
const portType = 'test';
|
|
1994
|
-
await invokeAndTransfer('WebView.setPort', uid, port1, origin, portType);
|
|
1983
|
+
await invokeAndTransfer$1('WebView.setPort', uid, port1, origin, portType);
|
|
1995
1984
|
const event = await promise;
|
|
1996
1985
|
// @ts-ignore
|
|
1997
1986
|
if (event.data !== 'ready') {
|
|
@@ -2016,7 +2005,7 @@ const createWebViewIpc = async webView => {
|
|
|
2016
2005
|
};
|
|
2017
2006
|
// TODO maybe don't send a message port only to get object url?
|
|
2018
2007
|
// TODO dispose ipc to avoid memory leak
|
|
2019
|
-
handleIpc(ipc);
|
|
2008
|
+
handleIpc$1(ipc);
|
|
2020
2009
|
return ipc;
|
|
2021
2010
|
};
|
|
2022
2011
|
|
|
@@ -2050,8 +2039,8 @@ const getRemoteUrlForWebView = async (uri, options = {}) => {
|
|
|
2050
2039
|
if (!webView) {
|
|
2051
2040
|
throw new Error(`webview ${options.webViewId} not found`);
|
|
2052
2041
|
}
|
|
2053
|
-
const [ipc, blob] = await Promise.all([createWebViewIpc(webView), invoke('FileSystem.getBlob', uri)]);
|
|
2054
|
-
const objectUrl = await invoke
|
|
2042
|
+
const [ipc, blob] = await Promise.all([createWebViewIpc(webView), invoke$1('FileSystem.getBlob', uri)]);
|
|
2043
|
+
const objectUrl = await invoke(ipc, 'createObjectUrl', blob);
|
|
2055
2044
|
return objectUrl;
|
|
2056
2045
|
};
|
|
2057
2046
|
|
|
@@ -2081,18 +2070,26 @@ const getPlatform = () => {
|
|
|
2081
2070
|
const platform = getPlatform(); // TODO tree-shake this out in production
|
|
2082
2071
|
|
|
2083
2072
|
const getRemoteUrl = async (uri, options = {}) => {
|
|
2073
|
+
// TODO uri should always have protocol
|
|
2074
|
+
// then ask file system provider for remote url, for example disk file system provider or html file system provider
|
|
2084
2075
|
const protocol = getProtocol(uri);
|
|
2085
2076
|
if (platform === Remote && !protocol) {
|
|
2077
|
+
if (uri.startsWith('/')) {
|
|
2078
|
+
return `/remote${uri}`;
|
|
2079
|
+
}
|
|
2086
2080
|
return `/remote/${uri}`;
|
|
2087
2081
|
}
|
|
2088
2082
|
if (platform === Electron && !protocol) {
|
|
2083
|
+
if (uri.startsWith('/')) {
|
|
2084
|
+
return `/remote${uri}`;
|
|
2085
|
+
}
|
|
2089
2086
|
return `/remote/${uri}`;
|
|
2090
2087
|
}
|
|
2091
2088
|
if (options.webViewId) {
|
|
2092
2089
|
return getRemoteUrlForWebView(uri, options);
|
|
2093
2090
|
}
|
|
2094
2091
|
if (uri.startsWith('html://')) {
|
|
2095
|
-
const url = await invoke('Blob.getSrc', uri);
|
|
2092
|
+
const url = await invoke$1('Blob.getSrc', uri);
|
|
2096
2093
|
return url;
|
|
2097
2094
|
}
|
|
2098
2095
|
throw new Error(`unsupported platform for remote url`);
|
|
@@ -2185,6 +2182,14 @@ const disposeWebView = id => {
|
|
|
2185
2182
|
const registerWebViewProvider = provider => {
|
|
2186
2183
|
setProvider(provider.id, provider);
|
|
2187
2184
|
};
|
|
2185
|
+
const getWebViewInfo = providerId => {
|
|
2186
|
+
const webView = getWebView(providerId);
|
|
2187
|
+
return {
|
|
2188
|
+
uid: webView.uid,
|
|
2189
|
+
origin: webView.origin,
|
|
2190
|
+
uri: webView.uri
|
|
2191
|
+
};
|
|
2192
|
+
};
|
|
2188
2193
|
|
|
2189
2194
|
const createWorker = async ({
|
|
2190
2195
|
method,
|
|
@@ -2194,7 +2199,7 @@ const createWorker = async ({
|
|
|
2194
2199
|
string(method);
|
|
2195
2200
|
string(url);
|
|
2196
2201
|
string(name);
|
|
2197
|
-
const ipc = create$
|
|
2202
|
+
const ipc = create$9({
|
|
2198
2203
|
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
2199
2204
|
url,
|
|
2200
2205
|
name
|
|
@@ -2282,7 +2287,7 @@ const api = {
|
|
|
2282
2287
|
registerHoverProvider: registerHoverProvider,
|
|
2283
2288
|
executeHoverProvider: executeHoverProvider,
|
|
2284
2289
|
// Rpc
|
|
2285
|
-
createRpc: createRpc,
|
|
2290
|
+
createRpc: createRpc$1,
|
|
2286
2291
|
createNodeRpc: createNodeRpc,
|
|
2287
2292
|
// Implementation
|
|
2288
2293
|
registerImplementationProvider: registerImplementationProvider,
|
|
@@ -2325,967 +2330,1094 @@ const api = {
|
|
|
2325
2330
|
getWorkspaceFolder: getWorkspaceFolder
|
|
2326
2331
|
};
|
|
2327
2332
|
|
|
2328
|
-
const
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
2332
|
-
const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
|
|
2333
|
-
const DefinitionExecuteDefinitionProvider = 'ExtensionHostDefinition.executeDefinitionProvider';
|
|
2334
|
-
const DiagnosticExecuteDiagnosticProvider = 'ExtensionHost.executeDiagnosticProvider';
|
|
2335
|
-
const ExtensionActivate = 'ExtensionHostExtension.activate';
|
|
2336
|
-
const FileSystemGetPathSeparator = 'ExtensionHostFileSystem.getPathSeparator';
|
|
2337
|
-
const FileSystemReadDirWithFileTypes = 'ExtensionHostFileSystem.readDirWithFileTypes';
|
|
2338
|
-
const FileSystemReadFile = 'ExtensionHostFileSystem.readFile';
|
|
2339
|
-
const FileSystemWriteFile = 'ExtensionHostFileSystem.writeFile';
|
|
2340
|
-
const FormattingExecuteFormmattingProvider = 'ExtensionHostFormatting.executeFormattingProvider';
|
|
2341
|
-
const HoverExecute = 'ExtensionHostHover.execute';
|
|
2342
|
-
const ImplementationExecuteImplementationProvider = 'ExtensionHostImplementation.executeImplementationProvider';
|
|
2343
|
-
const MockExec = 'ExtensionHostMockExec.mockExec';
|
|
2344
|
-
const MockRpc = 'ExtensionHostMockRpc.mockRpc';
|
|
2345
|
-
const OrganizeImportsExecute = 'ExtensionHostOrganizeImports.execute';
|
|
2346
|
-
const ReferenceExecuteFileReferenceProvider = 'ExtensionHostReference.executeFileReferenceProvider';
|
|
2347
|
-
const ReferenceExecuteReferenceProvider = 'ExtensionHostReference.executeReferenceProvider';
|
|
2348
|
-
const SourceControlAcceptInput = 'ExtensionHostSourceControl.acceptInput';
|
|
2349
|
-
const SourceControlAdd = 'ExtensionHostSourceControl.add';
|
|
2350
|
-
const SourceControlDiscard = 'ExtensionHostSourceControl.discard';
|
|
2351
|
-
const SourceControlGetChangedFiles = 'ExtensionHost.sourceControlGetChangedFiles';
|
|
2352
|
-
const SourceControlGetEnabledProviderIds = 'ExtensionHostSourceControl.getEnabledProviderIds';
|
|
2353
|
-
const SourceControlGetFileBefore = 'ExtensionHostSourceControl.GetFileBefore';
|
|
2354
|
-
const SourceControlGetGroups = 'ExtensionHostSourceControl.getGroups';
|
|
2355
|
-
const StatusBarGetStatusBarItems = 'ExtensionHost.getStatusBarItems';
|
|
2356
|
-
const StatusBarRegisterChangeListener = 'ExtensionHostStatusBar.registerChangeListener';
|
|
2357
|
-
const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
|
|
2358
|
-
const TextDocumentSetLanguageId = 'ExtensionHostTextDocument.setLanguageId';
|
|
2359
|
-
const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
|
|
2360
|
-
const TextDocumentSyncIncremental = 'ExtensionHostTextDocument.syncIncremental';
|
|
2361
|
-
const TextSearchExecuteTextSearchProvider = 'ExtensionHostTextSearch.executeTextSearchProvider';
|
|
2362
|
-
const TypeDefinitionExecuteTypeDefinitionProvider = 'ExtensionHostTypeDefinition.executeTypeDefinitionProvider';
|
|
2363
|
-
const WorkspaceSetPath = 'Workspace.setWorkspacePath';
|
|
2364
|
-
const SelectionExecuteSelectionProvider = 'ExtensionHostSelection.executeSelectionProvider';
|
|
2365
|
-
const ConfigurationSetConfiguration = 'ExtensionHostConfiguration.setConfiguration';
|
|
2333
|
+
const handleError = async error => {
|
|
2334
|
+
console.error(error);
|
|
2335
|
+
};
|
|
2366
2336
|
|
|
2367
|
-
|
|
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);
|
|
2563
|
+
};
|
|
2564
|
+
const getDetails = lines => {
|
|
2565
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
2566
|
+
if (index === -1) {
|
|
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
|
+
}
|
|
2368
2578
|
return {
|
|
2369
|
-
|
|
2579
|
+
actualMessage: lines[index - 1],
|
|
2580
|
+
rest: lines.slice(index, lastIndex)
|
|
2370
2581
|
};
|
|
2371
2582
|
};
|
|
2372
|
-
const
|
|
2373
|
-
|
|
2583
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
2584
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
2585
|
+
return getNativeModuleErrorMessage(stderr);
|
|
2586
|
+
}
|
|
2587
|
+
if (isModulesSyntaxError(stderr)) {
|
|
2588
|
+
return getModuleSyntaxError();
|
|
2589
|
+
}
|
|
2590
|
+
if (isModuleNotFoundError(stderr)) {
|
|
2591
|
+
return getModuleNotFoundError(stderr);
|
|
2592
|
+
}
|
|
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
|
+
};
|
|
2374
2603
|
};
|
|
2375
|
-
|
|
2376
|
-
|
|
2604
|
+
let IpcError$1 = class IpcError extends VError {
|
|
2605
|
+
// @ts-ignore
|
|
2606
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
2607
|
+
if (stdout || stderr) {
|
|
2608
|
+
// @ts-ignore
|
|
2609
|
+
const {
|
|
2610
|
+
message,
|
|
2611
|
+
code,
|
|
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;
|
|
2628
|
+
}
|
|
2377
2629
|
};
|
|
2378
|
-
|
|
2379
|
-
const
|
|
2380
|
-
|
|
2381
|
-
return path.slice(slashIndex + 1);
|
|
2630
|
+
const readyMessage = 'ready';
|
|
2631
|
+
const getData$2 = event => {
|
|
2632
|
+
return event.data;
|
|
2382
2633
|
};
|
|
2383
|
-
const
|
|
2384
|
-
|
|
2385
|
-
|
|
2634
|
+
const listen$8 = ({
|
|
2635
|
+
port
|
|
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);
|
|
2386
2645
|
}
|
|
2387
|
-
|
|
2388
|
-
return
|
|
2646
|
+
getData(event) {
|
|
2647
|
+
return getData$2(event);
|
|
2389
2648
|
}
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
const getUrlPrefix = extensionPath => {
|
|
2394
|
-
if (extensionPath.startsWith('http://') || extensionPath.startsWith('https://')) {
|
|
2395
|
-
return extensionPath;
|
|
2649
|
+
send(message) {
|
|
2650
|
+
this._rawIpc.postMessage(message);
|
|
2396
2651
|
}
|
|
2397
|
-
|
|
2398
|
-
|
|
2652
|
+
sendAndTransfer(message) {
|
|
2653
|
+
const transfer = getTransferrables(message);
|
|
2654
|
+
this._rawIpc.postMessage(message, transfer);
|
|
2399
2655
|
}
|
|
2400
|
-
|
|
2401
|
-
|
|
2656
|
+
dispose() {
|
|
2657
|
+
// ignore
|
|
2402
2658
|
}
|
|
2403
|
-
|
|
2659
|
+
onClose(callback) {
|
|
2660
|
+
// ignore
|
|
2661
|
+
}
|
|
2662
|
+
onMessage(callback) {
|
|
2663
|
+
this._rawIpc.addEventListener('message', callback);
|
|
2664
|
+
this._rawIpc.start();
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
const wrap$f = port => {
|
|
2668
|
+
return new IpcChildWithMessagePort(port);
|
|
2404
2669
|
};
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
}
|
|
2416
|
-
if (!Array.isArray(rpcs)) {
|
|
2417
|
-
return;
|
|
2418
|
-
}
|
|
2419
|
-
for (const rpc of rpcs) {
|
|
2420
|
-
rpc.url = `${urlPrefix}/${rpc.url}`;
|
|
2421
|
-
add$1(rpc.id, rpc);
|
|
2422
|
-
}
|
|
2423
|
-
} catch (error) {
|
|
2424
|
-
console.warn(`Failed to handle extension rpcs: ${error}`);
|
|
2670
|
+
const IpcChildWithMessagePort$1 = {
|
|
2671
|
+
__proto__: null,
|
|
2672
|
+
listen: listen$8,
|
|
2673
|
+
signal: signal$8,
|
|
2674
|
+
wrap: wrap$f
|
|
2675
|
+
};
|
|
2676
|
+
const listen$7 = () => {
|
|
2677
|
+
// @ts-ignore
|
|
2678
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
2679
|
+
throw new TypeError('module is not in web worker scope');
|
|
2425
2680
|
}
|
|
2681
|
+
return globalThis;
|
|
2426
2682
|
};
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
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);
|
|
2439
2707
|
}
|
|
2440
2708
|
}
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
/**
|
|
2444
|
-
* @type {any[]}
|
|
2445
|
-
*/
|
|
2446
|
-
errors: []
|
|
2709
|
+
const wrap$e = global => {
|
|
2710
|
+
return new IpcChildWithModuleWorker(global);
|
|
2447
2711
|
};
|
|
2448
|
-
const
|
|
2712
|
+
const IpcChildWithModuleWorker$1 = {
|
|
2713
|
+
__proto__: null,
|
|
2714
|
+
listen: listen$7,
|
|
2715
|
+
signal: signal$7,
|
|
2716
|
+
wrap: wrap$e
|
|
2717
|
+
};
|
|
2718
|
+
const withResolvers$1 = () => {
|
|
2719
|
+
let _resolve;
|
|
2720
|
+
const promise = new Promise(resolve => {
|
|
2721
|
+
_resolve = resolve;
|
|
2722
|
+
});
|
|
2723
|
+
return {
|
|
2724
|
+
resolve: _resolve,
|
|
2725
|
+
promise
|
|
2726
|
+
};
|
|
2727
|
+
};
|
|
2728
|
+
const waitForFirstMessage = async port => {
|
|
2729
|
+
const {
|
|
2730
|
+
resolve,
|
|
2731
|
+
promise
|
|
2732
|
+
} = withResolvers$1();
|
|
2733
|
+
port.addEventListener('message', resolve, {
|
|
2734
|
+
once: true
|
|
2735
|
+
});
|
|
2736
|
+
const event = await promise;
|
|
2449
2737
|
// @ts-ignore
|
|
2450
|
-
|
|
2738
|
+
return event.data;
|
|
2451
2739
|
};
|
|
2452
|
-
const
|
|
2453
|
-
|
|
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
|
+
};
|
|
2761
|
+
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
2762
|
+
constructor(port) {
|
|
2763
|
+
super(port);
|
|
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();
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
const wrap$d = port => {
|
|
2789
|
+
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
2454
2790
|
};
|
|
2455
|
-
const
|
|
2456
|
-
|
|
2791
|
+
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
2792
|
+
__proto__: null,
|
|
2793
|
+
listen: listen$6,
|
|
2794
|
+
wrap: wrap$d
|
|
2457
2795
|
};
|
|
2458
2796
|
|
|
2459
|
-
const
|
|
2460
|
-
|
|
2797
|
+
const createRpc = ipc => {
|
|
2798
|
+
const rpc = {
|
|
2799
|
+
/**
|
|
2800
|
+
* @deprecated
|
|
2801
|
+
*/
|
|
2802
|
+
send(method, ...params) {
|
|
2803
|
+
send(ipc, method, ...params);
|
|
2804
|
+
},
|
|
2805
|
+
invoke(method, ...params) {
|
|
2806
|
+
return invoke(ipc, method, ...params);
|
|
2807
|
+
},
|
|
2808
|
+
invokeAndTransfer(method, ...params) {
|
|
2809
|
+
return invokeAndTransfer(ipc, method, ...params);
|
|
2810
|
+
}
|
|
2811
|
+
};
|
|
2812
|
+
return rpc;
|
|
2461
2813
|
};
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
return error && error instanceof TypeError && error.message === 'error loading dynamically imported module';
|
|
2814
|
+
const requiresSocket$1 = () => {
|
|
2815
|
+
return false;
|
|
2465
2816
|
};
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
return error instanceof SyntaxError;
|
|
2817
|
+
const preparePrettyError$1 = error => {
|
|
2818
|
+
return error;
|
|
2469
2819
|
};
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
return isImportErrorChrome(error) || isImportErrorFirefox(error) || isSyntaxError(error);
|
|
2820
|
+
const logError$1 = () => {
|
|
2821
|
+
// handled by renderer worker
|
|
2473
2822
|
};
|
|
2474
|
-
|
|
2475
|
-
const
|
|
2476
|
-
|
|
2477
|
-
setTimeout(resolve, duration);
|
|
2478
|
-
};
|
|
2479
|
-
return new Promise(promiseCallback);
|
|
2823
|
+
const handleMessage = event => {
|
|
2824
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
2825
|
+
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError$1, logError$1, actualRequiresSocket);
|
|
2480
2826
|
};
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
if (match) {
|
|
2488
|
-
return match[1].trim();
|
|
2827
|
+
const handleIpc = ipc => {
|
|
2828
|
+
if ('addEventListener' in ipc) {
|
|
2829
|
+
ipc.addEventListener('message', handleMessage);
|
|
2830
|
+
} else if ('on' in ipc) {
|
|
2831
|
+
// deprecated
|
|
2832
|
+
ipc.on('message', handleMessage);
|
|
2489
2833
|
}
|
|
2490
|
-
return message;
|
|
2491
2834
|
};
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
this.name = 'BabelParseError';
|
|
2497
|
-
// @ts-ignore
|
|
2498
|
-
const line = error.loc.line;
|
|
2499
|
-
// @ts-ignore
|
|
2500
|
-
const column = error.loc.column + 1;
|
|
2501
|
-
this.stack = `${message}
|
|
2502
|
-
at ${url}:${line}:${column}`;
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
|
|
2506
|
-
const getAssetDir = () => {
|
|
2507
|
-
// @ts-ignore
|
|
2508
|
-
if (typeof ASSET_DIR !== 'undefined') {
|
|
2509
|
-
// @ts-ignore
|
|
2510
|
-
return ASSET_DIR;
|
|
2511
|
-
}
|
|
2512
|
-
if (platform === Electron) {
|
|
2513
|
-
return '../../../../..';
|
|
2835
|
+
const listen$1 = async (module, options) => {
|
|
2836
|
+
const rawIpc = await module.listen(options);
|
|
2837
|
+
if (module.signal) {
|
|
2838
|
+
module.signal(rawIpc);
|
|
2514
2839
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
const assetDir = getAssetDir();
|
|
2518
|
-
|
|
2519
|
-
const loadBabelParser = () => {
|
|
2520
|
-
const url = `${assetDir}/js/babel-parser.js`;
|
|
2521
|
-
return import(url);
|
|
2840
|
+
const ipc = module.wrap(rawIpc);
|
|
2841
|
+
return ipc;
|
|
2522
2842
|
};
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2843
|
+
const create$6 = async ({
|
|
2844
|
+
commandMap
|
|
2845
|
+
}) => {
|
|
2846
|
+
// TODO create a commandMap per rpc instance
|
|
2847
|
+
register(commandMap);
|
|
2848
|
+
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
2849
|
+
handleIpc(ipc);
|
|
2850
|
+
const rpc = createRpc(ipc);
|
|
2851
|
+
return rpc;
|
|
2527
2852
|
};
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
const getLineAndColumn = (text, start, end) => {
|
|
2532
|
-
let index = -1;
|
|
2533
|
-
let line = 0;
|
|
2534
|
-
const column = 0;
|
|
2535
|
-
while ((index = text.indexOf('\n', index + 1)) !== -1) {
|
|
2536
|
-
line++;
|
|
2537
|
-
if (index >= start) {
|
|
2538
|
-
break;
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
return {
|
|
2542
|
-
line,
|
|
2543
|
-
column
|
|
2544
|
-
};
|
|
2853
|
+
const WebWorkerRpcClient = {
|
|
2854
|
+
__proto__: null,
|
|
2855
|
+
create: create$6
|
|
2545
2856
|
};
|
|
2546
2857
|
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
const
|
|
2560
|
-
const
|
|
2561
|
-
const
|
|
2562
|
-
const
|
|
2563
|
-
const
|
|
2564
|
-
const
|
|
2565
|
-
const
|
|
2566
|
-
const
|
|
2567
|
-
const
|
|
2568
|
-
const
|
|
2569
|
-
const
|
|
2570
|
-
const
|
|
2571
|
-
const
|
|
2572
|
-
const
|
|
2573
|
-
|
|
2574
|
-
const
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
case Program:
|
|
2590
|
-
walk(node.body, visitor);
|
|
2591
|
-
break;
|
|
2592
|
-
case ExportNamedDeclaration:
|
|
2593
|
-
walk(node.declaration, visitor);
|
|
2594
|
-
break;
|
|
2595
|
-
case VariableDeclaration:
|
|
2596
|
-
walk(node.declarations, visitor);
|
|
2597
|
-
break;
|
|
2598
|
-
case VariableDeclarator:
|
|
2599
|
-
walk(node.init, visitor);
|
|
2600
|
-
break;
|
|
2601
|
-
case ArrowFunctionExpression:
|
|
2602
|
-
walk(node.body, visitor);
|
|
2603
|
-
break;
|
|
2604
|
-
case BlockStatement:
|
|
2605
|
-
walk(node.body, visitor);
|
|
2606
|
-
break;
|
|
2607
|
-
case ExpressionStatement:
|
|
2608
|
-
walk(node.expression, visitor);
|
|
2609
|
-
break;
|
|
2610
|
-
case AwaitExpression:
|
|
2611
|
-
walk(node.argument, visitor);
|
|
2612
|
-
break;
|
|
2613
|
-
case CallExpression:
|
|
2614
|
-
walk(node.callee, visitor);
|
|
2615
|
-
break;
|
|
2616
|
-
}
|
|
2617
|
-
};
|
|
2618
|
-
const getBabelAstDependencies = (code, ast) => {
|
|
2619
|
-
const {
|
|
2620
|
-
program
|
|
2621
|
-
} = ast;
|
|
2622
|
-
const {
|
|
2623
|
-
body
|
|
2624
|
-
} = program;
|
|
2625
|
-
const dependencies = [];
|
|
2626
|
-
for (const node of body) {
|
|
2627
|
-
if (node.type === ImportDeclaration || node.type === ExportAllDeclaration) {
|
|
2628
|
-
const relativePath = node.source.extra.rawValue;
|
|
2629
|
-
const start = node.source.start;
|
|
2630
|
-
const end = node.source.end;
|
|
2631
|
-
// @ts-ignore
|
|
2632
|
-
dependencies.push({
|
|
2633
|
-
relativePath,
|
|
2634
|
-
code,
|
|
2635
|
-
start,
|
|
2636
|
-
end
|
|
2637
|
-
});
|
|
2638
|
-
} else if (node.type === VariableDeclaration && node.declarations && node.declarations[0] && node.declarations[0].type === VariableDeclarator && node.declarations[0].init && node.declarations[0].init.type === AwaitExpression && node.declarations[0].init.argument && node.declarations[0].init.argument.type === CallExpression && node.declarations[0].init.argument.callee && node.declarations[0].init.argument.callee.type === Import && node.declarations[0].init.argument.arguments && node.declarations[0].init.argument.arguments[0] && node.declarations[0].init.argument.arguments[0].type === StringLiteral) {
|
|
2639
|
-
const relativePath = node.declarations[0].init.argument.arguments[0].extra.rawValue;
|
|
2640
|
-
const start = node.declarations[0].init.argument.arguments[0].start;
|
|
2641
|
-
const end = node.declarations[0].init.argument.arguments[0].end;
|
|
2642
|
-
// @ts-ignore
|
|
2643
|
-
dependencies.push({
|
|
2644
|
-
relativePath,
|
|
2645
|
-
code,
|
|
2646
|
-
start,
|
|
2647
|
-
end
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
|
-
}
|
|
2651
|
-
const visitor = node => {
|
|
2652
|
-
if (node && node.type === CallExpression && node.callee && node.callee.type === Import && node.arguments && node.arguments[0] && node.arguments[0].type === StringLiteral) {
|
|
2653
|
-
const relativePath = node.arguments[0].extra.rawValue;
|
|
2654
|
-
const start = node.arguments[0].start;
|
|
2655
|
-
const end = node.arguments[0].end;
|
|
2656
|
-
// @ts-ignore
|
|
2657
|
-
dependencies.push({
|
|
2658
|
-
relativePath,
|
|
2659
|
-
code,
|
|
2660
|
-
start,
|
|
2661
|
-
end
|
|
2662
|
-
});
|
|
2663
|
-
}
|
|
2858
|
+
const BraceCompletionExecuteBraceCompletionProvider = 'ExtensionHostBraceCompletion.executeBraceCompletionProvider';
|
|
2859
|
+
const ClosingTagExecuteClosingTagProvider = 'ExtensionHostClosingTag.executeClosingTagProvider';
|
|
2860
|
+
const CommandExecute = 'ExtensionHostCommand.executeCommand';
|
|
2861
|
+
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
2862
|
+
const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
|
|
2863
|
+
const DefinitionExecuteDefinitionProvider = 'ExtensionHostDefinition.executeDefinitionProvider';
|
|
2864
|
+
const DiagnosticExecuteDiagnosticProvider = 'ExtensionHost.executeDiagnosticProvider';
|
|
2865
|
+
const ExtensionActivate = 'ExtensionHostExtension.activate';
|
|
2866
|
+
const FileSystemGetPathSeparator = 'ExtensionHostFileSystem.getPathSeparator';
|
|
2867
|
+
const FileSystemReadDirWithFileTypes = 'ExtensionHostFileSystem.readDirWithFileTypes';
|
|
2868
|
+
const FileSystemReadFile = 'ExtensionHostFileSystem.readFile';
|
|
2869
|
+
const FileSystemWriteFile = 'ExtensionHostFileSystem.writeFile';
|
|
2870
|
+
const FormattingExecuteFormmattingProvider = 'ExtensionHostFormatting.executeFormattingProvider';
|
|
2871
|
+
const HoverExecute = 'ExtensionHostHover.execute';
|
|
2872
|
+
const ImplementationExecuteImplementationProvider = 'ExtensionHostImplementation.executeImplementationProvider';
|
|
2873
|
+
const MockExec = 'ExtensionHostMockExec.mockExec';
|
|
2874
|
+
const MockRpc = 'ExtensionHostMockRpc.mockRpc';
|
|
2875
|
+
const OrganizeImportsExecute = 'ExtensionHostOrganizeImports.execute';
|
|
2876
|
+
const ReferenceExecuteFileReferenceProvider = 'ExtensionHostReference.executeFileReferenceProvider';
|
|
2877
|
+
const ReferenceExecuteReferenceProvider = 'ExtensionHostReference.executeReferenceProvider';
|
|
2878
|
+
const SourceControlAcceptInput = 'ExtensionHostSourceControl.acceptInput';
|
|
2879
|
+
const SourceControlAdd = 'ExtensionHostSourceControl.add';
|
|
2880
|
+
const SourceControlDiscard = 'ExtensionHostSourceControl.discard';
|
|
2881
|
+
const SourceControlGetChangedFiles = 'ExtensionHost.sourceControlGetChangedFiles';
|
|
2882
|
+
const SourceControlGetEnabledProviderIds = 'ExtensionHostSourceControl.getEnabledProviderIds';
|
|
2883
|
+
const SourceControlGetFileBefore = 'ExtensionHostSourceControl.GetFileBefore';
|
|
2884
|
+
const SourceControlGetGroups = 'ExtensionHostSourceControl.getGroups';
|
|
2885
|
+
const StatusBarGetStatusBarItems = 'ExtensionHost.getStatusBarItems';
|
|
2886
|
+
const StatusBarRegisterChangeListener = 'ExtensionHostStatusBar.registerChangeListener';
|
|
2887
|
+
const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
|
|
2888
|
+
const TextDocumentSetLanguageId = 'ExtensionHostTextDocument.setLanguageId';
|
|
2889
|
+
const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
|
|
2890
|
+
const TextDocumentSyncIncremental = 'ExtensionHostTextDocument.syncIncremental';
|
|
2891
|
+
const TextSearchExecuteTextSearchProvider = 'ExtensionHostTextSearch.executeTextSearchProvider';
|
|
2892
|
+
const TypeDefinitionExecuteTypeDefinitionProvider = 'ExtensionHostTypeDefinition.executeTypeDefinitionProvider';
|
|
2893
|
+
const WorkspaceSetPath = 'Workspace.setWorkspacePath';
|
|
2894
|
+
const SelectionExecuteSelectionProvider = 'ExtensionHostSelection.executeSelectionProvider';
|
|
2895
|
+
const ConfigurationSetConfiguration = 'ExtensionHostConfiguration.setConfiguration';
|
|
2896
|
+
|
|
2897
|
+
const create$5 = () => {
|
|
2898
|
+
return {
|
|
2899
|
+
finished: false
|
|
2664
2900
|
};
|
|
2665
|
-
walk(ast, visitor);
|
|
2666
|
-
return dependencies;
|
|
2667
2901
|
};
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
// @ts-ignore
|
|
2671
|
-
return isSyntaxError(error) && error.code === BABEL_PARSER_SYNTAX_ERROR;
|
|
2902
|
+
const cancel = token => {
|
|
2903
|
+
token.finished = true;
|
|
2672
2904
|
};
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
return location.origin;
|
|
2905
|
+
const isCanceled = token => {
|
|
2906
|
+
return token.finished;
|
|
2676
2907
|
};
|
|
2677
2908
|
|
|
2678
|
-
const
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
const absoluteSourceUrl = new URL(sourceUrl, origin).toString();
|
|
2682
|
-
return new URL(relativePath, absoluteSourceUrl).toString();
|
|
2683
|
-
}
|
|
2684
|
-
return new URL(relativePath, sourceUrl).toString();
|
|
2909
|
+
const baseName = path => {
|
|
2910
|
+
const slashIndex = path.lastIndexOf('/');
|
|
2911
|
+
return path.slice(slashIndex + 1);
|
|
2685
2912
|
};
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
return false;
|
|
2690
|
-
}
|
|
2691
|
-
if (url.startsWith(location.protocol)) {
|
|
2692
|
-
return false;
|
|
2913
|
+
const getExtensionId = extension => {
|
|
2914
|
+
if (extension && extension.id) {
|
|
2915
|
+
return extension.id;
|
|
2693
2916
|
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
const getErrorInDependencies = async (url, dependencies, seenUrls) => {
|
|
2697
|
-
for (const dependency of dependencies) {
|
|
2698
|
-
const dependencyUrl = getAbsoluteUrl(dependency.relativePath, url);
|
|
2699
|
-
if (isExternal(dependencyUrl) || seenUrls.includes(dependencyUrl)) {
|
|
2700
|
-
continue;
|
|
2701
|
-
}
|
|
2702
|
-
seenUrls.push(dependencyUrl);
|
|
2703
|
-
// let dependencyResponse
|
|
2704
|
-
// try {
|
|
2705
|
-
const dependencyResponse = await fetch(dependencyUrl);
|
|
2706
|
-
// } catch (error) {}
|
|
2707
|
-
if (dependencyResponse.ok) {
|
|
2708
|
-
await tryToGetActualErrorMessage(null, dependencyUrl, dependencyResponse, seenUrls);
|
|
2709
|
-
} else {
|
|
2710
|
-
switch (dependencyResponse.status) {
|
|
2711
|
-
case NotFound:
|
|
2712
|
-
throw new DependencyNotFoundError(dependency.code, dependency.start, dependency.end, dependency.relativePath, dependencyUrl, url);
|
|
2713
|
-
// return `Failed to import ${url}: ${error}`
|
|
2714
|
-
}
|
|
2715
|
-
}
|
|
2917
|
+
if (extension && extension.path) {
|
|
2918
|
+
return baseName(extension.path);
|
|
2716
2919
|
}
|
|
2920
|
+
return '<unknown>';
|
|
2717
2921
|
};
|
|
2718
2922
|
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
* @param {Response} response
|
|
2723
|
-
* @returns
|
|
2724
|
-
*/
|
|
2725
|
-
const tryToGetActualErrorMessage = async (error, url, response, seenUrls = []) => {
|
|
2726
|
-
let text;
|
|
2727
|
-
try {
|
|
2728
|
-
text = await response.text();
|
|
2729
|
-
} catch (error) {
|
|
2730
|
-
return `Failed to import ${url}: Unknown Network Error`;
|
|
2731
|
-
}
|
|
2732
|
-
let ast;
|
|
2733
|
-
try {
|
|
2734
|
-
ast = await parse(text, {
|
|
2735
|
-
sourceType: Module
|
|
2736
|
-
});
|
|
2737
|
-
} catch (error) {
|
|
2738
|
-
if (isBabelError(error)) {
|
|
2739
|
-
throw new BabelParseError(url, error);
|
|
2740
|
-
}
|
|
2741
|
-
throw error;
|
|
2923
|
+
const getUrlPrefix = extensionPath => {
|
|
2924
|
+
if (extensionPath.startsWith('http://') || extensionPath.startsWith('https://')) {
|
|
2925
|
+
return extensionPath;
|
|
2742
2926
|
}
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
if (hasRecentErrors()) {
|
|
2746
|
-
const recentError = getRecentError();
|
|
2747
|
-
// @ts-ignore
|
|
2748
|
-
throw new ContentSecurityPolicyError(recentError.violatedDirective, recentError.sourceFile, recentError.lineNumber, recentError.columnNumber);
|
|
2927
|
+
if (platform === Web) {
|
|
2928
|
+
return extensionPath;
|
|
2749
2929
|
}
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
return `Failed to import ${url}: Missing Content-Type header for javascript`;
|
|
2930
|
+
if (extensionPath.startsWith('/')) {
|
|
2931
|
+
return `/remote${extensionPath}`;
|
|
2753
2932
|
}
|
|
2754
|
-
return
|
|
2933
|
+
return `/remote/${extensionPath}`;
|
|
2755
2934
|
};
|
|
2756
2935
|
|
|
2757
|
-
const
|
|
2758
|
-
let response;
|
|
2936
|
+
const handleRpcInfos = extension => {
|
|
2759
2937
|
try {
|
|
2760
|
-
|
|
2938
|
+
if (!extension) {
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2941
|
+
const rpcs = extension.rpc;
|
|
2942
|
+
const urlPrefix = getUrlPrefix(extension.path);
|
|
2943
|
+
if (!rpcs) {
|
|
2944
|
+
return;
|
|
2945
|
+
}
|
|
2946
|
+
if (!Array.isArray(rpcs)) {
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
for (const rpc of rpcs) {
|
|
2950
|
+
rpc.url = `${urlPrefix}/${rpc.url}`;
|
|
2951
|
+
add$1(rpc.id, rpc);
|
|
2952
|
+
}
|
|
2761
2953
|
} catch (error) {
|
|
2762
|
-
|
|
2763
|
-
}
|
|
2764
|
-
if (response.ok) {
|
|
2765
|
-
return await tryToGetActualErrorMessage(error, url, response);
|
|
2766
|
-
}
|
|
2767
|
-
switch (response.status) {
|
|
2768
|
-
case NotFound:
|
|
2769
|
-
throw new Error(`Failed to import ${url}: Not found (404)`);
|
|
2770
|
-
default:
|
|
2771
|
-
return `Failed to import ${url}: ${error}`;
|
|
2954
|
+
console.warn(`Failed to handle extension rpcs: ${error}`);
|
|
2772
2955
|
}
|
|
2773
2956
|
};
|
|
2774
2957
|
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
if (
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
}
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
if (hasRecentErrors()) {
|
|
2786
|
-
const recentError = getRecentError();
|
|
2787
|
-
// @ts-ignore
|
|
2788
|
-
throw new ContentSecurityPolicyError(recentError.violatedDirective, recentError.sourceFile, recentError.lineNumber, recentError.columnNumber);
|
|
2958
|
+
class ContentSecurityPolicyError extends Error {
|
|
2959
|
+
constructor(violatedDirective, sourceFile, lineNumber, columnNumber) {
|
|
2960
|
+
super(`Content Security Policy Violation: ${violatedDirective}`);
|
|
2961
|
+
this.name = 'ContentSecurityPolicyError';
|
|
2962
|
+
if (sourceFile) {
|
|
2963
|
+
this.stack = `Content Security Policy Violation
|
|
2964
|
+
at ${sourceFile}:${lineNumber}:${columnNumber}`;
|
|
2965
|
+
} else {
|
|
2966
|
+
this.stack = `Content Security Policy Violation
|
|
2967
|
+
at <unknown>`;
|
|
2789
2968
|
}
|
|
2790
|
-
throw error;
|
|
2791
2969
|
}
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
const isImportErrorChrome = error => {
|
|
2973
|
+
return error && error instanceof Error && error.message.startsWith('Failed to fetch dynamically imported module');
|
|
2792
2974
|
};
|
|
2793
2975
|
|
|
2794
|
-
const
|
|
2795
|
-
|
|
2796
|
-
await sleep(timeout);
|
|
2797
|
-
if (isCanceled(token)) {
|
|
2798
|
-
return;
|
|
2799
|
-
}
|
|
2800
|
-
throw new Error(`Activation timeout of ${timeout}ms exceeded`);
|
|
2976
|
+
const isImportErrorFirefox = error => {
|
|
2977
|
+
return error && error instanceof TypeError && error.message === 'error loading dynamically imported module';
|
|
2801
2978
|
};
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
string(extension.browser);
|
|
2806
|
-
string(absolutePath);
|
|
2807
|
-
const module = await importScript(absolutePath);
|
|
2808
|
-
handleRpcInfos(extension);
|
|
2809
|
-
const token = create$5();
|
|
2810
|
-
try {
|
|
2811
|
-
await Promise.race([module.activate(extension), rejectAfterTimeout(activationTimeout, token)]);
|
|
2812
|
-
} catch (error) {
|
|
2813
|
-
if (isImportError(error)) {
|
|
2814
|
-
const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
|
|
2815
|
-
throw new Error(actualErrorMessage);
|
|
2816
|
-
}
|
|
2817
|
-
throw error;
|
|
2818
|
-
} finally {
|
|
2819
|
-
cancel(token);
|
|
2820
|
-
}
|
|
2821
|
-
} catch (error) {
|
|
2822
|
-
const id = getExtensionId(extension);
|
|
2823
|
-
throw new VError(error, `Failed to activate extension ${id}`);
|
|
2824
|
-
}
|
|
2825
|
-
// console.info('activated', path)
|
|
2979
|
+
|
|
2980
|
+
const isSyntaxError = error => {
|
|
2981
|
+
return error instanceof SyntaxError;
|
|
2826
2982
|
};
|
|
2827
2983
|
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
this.name = 'ExecError';
|
|
2832
|
-
// @ts-ignore
|
|
2833
|
-
this.stdout = stdout;
|
|
2834
|
-
// @ts-ignore
|
|
2835
|
-
this.stderr = stderr;
|
|
2836
|
-
// @ts-ignore
|
|
2837
|
-
this.exitCode = exitCode;
|
|
2838
|
-
}
|
|
2839
|
-
}
|
|
2984
|
+
const isImportError = error => {
|
|
2985
|
+
return isImportErrorChrome(error) || isImportErrorFirefox(error) || isSyntaxError(error);
|
|
2986
|
+
};
|
|
2840
2987
|
|
|
2841
|
-
const
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
stdout,
|
|
2856
|
-
stderr,
|
|
2857
|
-
exitCode
|
|
2858
|
-
};
|
|
2859
|
-
};
|
|
2860
|
-
} catch (error) {
|
|
2861
|
-
throw new VError(error, 'Failed to mock exec function');
|
|
2988
|
+
const sleep = duration => {
|
|
2989
|
+
const promiseCallback = (resolve, reject) => {
|
|
2990
|
+
setTimeout(resolve, duration);
|
|
2991
|
+
};
|
|
2992
|
+
return new Promise(promiseCallback);
|
|
2993
|
+
};
|
|
2994
|
+
|
|
2995
|
+
const NotFound = 404;
|
|
2996
|
+
|
|
2997
|
+
const RE_LINE_COLUMN = /(.*)(?:\(\d+\:\d+\))/;
|
|
2998
|
+
const getBabelErrorMessage = message => {
|
|
2999
|
+
const match = message.match(RE_LINE_COLUMN);
|
|
3000
|
+
if (match) {
|
|
3001
|
+
return match[1].trim();
|
|
2862
3002
|
}
|
|
3003
|
+
return message;
|
|
2863
3004
|
};
|
|
3005
|
+
class BabelParseError extends SyntaxError {
|
|
3006
|
+
constructor(url, error) {
|
|
3007
|
+
const message = getBabelErrorMessage(error.message);
|
|
3008
|
+
super(message);
|
|
3009
|
+
this.name = 'BabelParseError';
|
|
3010
|
+
// @ts-ignore
|
|
3011
|
+
const line = error.loc.line;
|
|
3012
|
+
// @ts-ignore
|
|
3013
|
+
const column = error.loc.column + 1;
|
|
3014
|
+
this.stack = `${message}
|
|
3015
|
+
at ${url}:${line}:${column}`;
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
2864
3018
|
|
|
2865
|
-
const
|
|
3019
|
+
const getAssetDir = () => {
|
|
2866
3020
|
// @ts-ignore
|
|
2867
|
-
|
|
2868
|
-
try {
|
|
2869
|
-
return {
|
|
2870
|
-
async invoke(method, ...params) {
|
|
2871
|
-
const result = await invoke('Test.executeMockRpcFunction', options.name, method, ...params);
|
|
2872
|
-
return result;
|
|
2873
|
-
}
|
|
2874
|
-
};
|
|
2875
|
-
} catch (error) {
|
|
2876
|
-
throw new VError(error, 'Failed to mock exec function');
|
|
2877
|
-
}
|
|
2878
|
-
};
|
|
2879
|
-
};
|
|
2880
|
-
|
|
2881
|
-
const getStatusBarItems = async () => {
|
|
2882
|
-
const providers = Object.values(state$5.providers);
|
|
2883
|
-
const statusBarItems = [];
|
|
2884
|
-
for (const provider of providers) {
|
|
3021
|
+
if (typeof ASSET_DIR !== 'undefined') {
|
|
2885
3022
|
// @ts-ignore
|
|
2886
|
-
|
|
2887
|
-
// @ts-ignore
|
|
2888
|
-
statusBarItems.push(...provider.statusBarCommands);
|
|
2889
|
-
}
|
|
3023
|
+
return ASSET_DIR;
|
|
2890
3024
|
}
|
|
2891
|
-
|
|
3025
|
+
if (platform === Electron) {
|
|
3026
|
+
return '../../../../..';
|
|
3027
|
+
}
|
|
3028
|
+
return '';
|
|
2892
3029
|
};
|
|
2893
|
-
const
|
|
2894
|
-
|
|
3030
|
+
const assetDir = getAssetDir();
|
|
3031
|
+
|
|
3032
|
+
const loadBabelParser = () => {
|
|
3033
|
+
const url = `${assetDir}/js/babel-parser.js`;
|
|
3034
|
+
return import(url);
|
|
2895
3035
|
};
|
|
2896
3036
|
|
|
2897
|
-
const
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
console.log('before unload');
|
|
3037
|
+
const parse = async (code, options) => {
|
|
3038
|
+
const BabelParse = await loadBabelParser();
|
|
3039
|
+
return BabelParse.parse(code, options);
|
|
2901
3040
|
};
|
|
2902
3041
|
|
|
2903
|
-
const
|
|
2904
|
-
|
|
2905
|
-
const
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
3042
|
+
const Module = 'module';
|
|
3043
|
+
|
|
3044
|
+
const getLineAndColumn = (text, start, end) => {
|
|
3045
|
+
let index = -1;
|
|
3046
|
+
let line = 0;
|
|
3047
|
+
const column = 0;
|
|
3048
|
+
while ((index = text.indexOf('\n', index + 1)) !== -1) {
|
|
3049
|
+
line++;
|
|
3050
|
+
if (index >= start) {
|
|
3051
|
+
break;
|
|
3052
|
+
}
|
|
2909
3053
|
}
|
|
2910
|
-
return
|
|
3054
|
+
return {
|
|
3055
|
+
line,
|
|
3056
|
+
column
|
|
3057
|
+
};
|
|
2911
3058
|
};
|
|
2912
3059
|
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
3060
|
+
class DependencyNotFoundError extends Error {
|
|
3061
|
+
constructor(code, start, end, dependencyRelativePath, dependencyUrl, sourceUrl) {
|
|
3062
|
+
super(`Module not found "${dependencyRelativePath}"`);
|
|
3063
|
+
const {
|
|
3064
|
+
line,
|
|
3065
|
+
column
|
|
3066
|
+
} = getLineAndColumn(code, start);
|
|
3067
|
+
this.stack = `${this.message}
|
|
3068
|
+
at Module (${sourceUrl}:${line}:${column})`;
|
|
2916
3069
|
}
|
|
2917
|
-
|
|
2918
|
-
|
|
3070
|
+
}
|
|
3071
|
+
|
|
3072
|
+
const ArrowFunctionExpression = 'ArrowFunctionExpression';
|
|
3073
|
+
const AwaitExpression = 'AwaitExpression';
|
|
3074
|
+
const BlockStatement = 'BlockStatement';
|
|
3075
|
+
const CallExpression = 'CallExpression';
|
|
3076
|
+
const ExportAllDeclaration = 'ExportAllDeclaration';
|
|
3077
|
+
const ExportNamedDeclaration = 'ExportNamedDeclaration';
|
|
3078
|
+
const ExpressionStatement = 'ExpressionStatement';
|
|
3079
|
+
const File$1 = 'File';
|
|
3080
|
+
const Import = 'Import';
|
|
3081
|
+
const ImportDeclaration = 'ImportDeclaration';
|
|
3082
|
+
const Program = 'Program';
|
|
3083
|
+
const StringLiteral = 'StringLiteral';
|
|
3084
|
+
const VariableDeclaration = 'VariableDeclaration';
|
|
3085
|
+
const VariableDeclarator = 'VariableDeclarator';
|
|
3086
|
+
|
|
3087
|
+
const walk = (node, visitor) => {
|
|
3088
|
+
if (!node) {
|
|
2919
3089
|
return;
|
|
2920
3090
|
}
|
|
2921
|
-
if (Array.isArray(
|
|
2922
|
-
for (const item of
|
|
2923
|
-
|
|
3091
|
+
if (Array.isArray(node)) {
|
|
3092
|
+
for (const item of node) {
|
|
3093
|
+
walk(item, visitor);
|
|
2924
3094
|
}
|
|
2925
3095
|
return;
|
|
2926
3096
|
}
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
3097
|
+
visitor(node);
|
|
3098
|
+
switch (node.type) {
|
|
3099
|
+
case File$1:
|
|
3100
|
+
walk(node.program, visitor);
|
|
3101
|
+
break;
|
|
3102
|
+
case Program:
|
|
3103
|
+
walk(node.body, visitor);
|
|
3104
|
+
break;
|
|
3105
|
+
case ExportNamedDeclaration:
|
|
3106
|
+
walk(node.declaration, visitor);
|
|
3107
|
+
break;
|
|
3108
|
+
case VariableDeclaration:
|
|
3109
|
+
walk(node.declarations, visitor);
|
|
3110
|
+
break;
|
|
3111
|
+
case VariableDeclarator:
|
|
3112
|
+
walk(node.init, visitor);
|
|
3113
|
+
break;
|
|
3114
|
+
case ArrowFunctionExpression:
|
|
3115
|
+
walk(node.body, visitor);
|
|
3116
|
+
break;
|
|
3117
|
+
case BlockStatement:
|
|
3118
|
+
walk(node.body, visitor);
|
|
3119
|
+
break;
|
|
3120
|
+
case ExpressionStatement:
|
|
3121
|
+
walk(node.expression, visitor);
|
|
3122
|
+
break;
|
|
3123
|
+
case AwaitExpression:
|
|
3124
|
+
walk(node.argument, visitor);
|
|
3125
|
+
break;
|
|
3126
|
+
case CallExpression:
|
|
3127
|
+
walk(node.callee, visitor);
|
|
3128
|
+
break;
|
|
2932
3129
|
}
|
|
2933
3130
|
};
|
|
2934
|
-
const
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
const
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
3131
|
+
const getBabelAstDependencies = (code, ast) => {
|
|
3132
|
+
const {
|
|
3133
|
+
program
|
|
3134
|
+
} = ast;
|
|
3135
|
+
const {
|
|
3136
|
+
body
|
|
3137
|
+
} = program;
|
|
3138
|
+
const dependencies = [];
|
|
3139
|
+
for (const node of body) {
|
|
3140
|
+
if (node.type === ImportDeclaration || node.type === ExportAllDeclaration) {
|
|
3141
|
+
const relativePath = node.source.extra.rawValue;
|
|
3142
|
+
const start = node.source.start;
|
|
3143
|
+
const end = node.source.end;
|
|
3144
|
+
// @ts-ignore
|
|
3145
|
+
dependencies.push({
|
|
3146
|
+
relativePath,
|
|
3147
|
+
code,
|
|
3148
|
+
start,
|
|
3149
|
+
end
|
|
3150
|
+
});
|
|
3151
|
+
} else if (node.type === VariableDeclaration && node.declarations && node.declarations[0] && node.declarations[0].type === VariableDeclarator && node.declarations[0].init && node.declarations[0].init.type === AwaitExpression && node.declarations[0].init.argument && node.declarations[0].init.argument.type === CallExpression && node.declarations[0].init.argument.callee && node.declarations[0].init.argument.callee.type === Import && node.declarations[0].init.argument.arguments && node.declarations[0].init.argument.arguments[0] && node.declarations[0].init.argument.arguments[0].type === StringLiteral) {
|
|
3152
|
+
const relativePath = node.declarations[0].init.argument.arguments[0].extra.rawValue;
|
|
3153
|
+
const start = node.declarations[0].init.argument.arguments[0].start;
|
|
3154
|
+
const end = node.declarations[0].init.argument.arguments[0].end;
|
|
3155
|
+
// @ts-ignore
|
|
3156
|
+
dependencies.push({
|
|
3157
|
+
relativePath,
|
|
3158
|
+
code,
|
|
3159
|
+
start,
|
|
3160
|
+
end
|
|
3161
|
+
});
|
|
2954
3162
|
}
|
|
2955
3163
|
}
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
const
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
}
|
|
2969
|
-
};
|
|
2970
|
-
that.onMessage(handleMessage);
|
|
2971
|
-
const handleClose = event => {
|
|
2972
|
-
that.dispatchEvent(new Event('close'));
|
|
2973
|
-
};
|
|
2974
|
-
that.onClose(handleClose);
|
|
2975
|
-
};
|
|
2976
|
-
class Ipc extends EventTarget {
|
|
2977
|
-
constructor(rawIpc) {
|
|
2978
|
-
super();
|
|
2979
|
-
this._rawIpc = rawIpc;
|
|
2980
|
-
attachEvents(this);
|
|
2981
|
-
}
|
|
2982
|
-
}
|
|
2983
|
-
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
2984
|
-
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
2985
|
-
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
2986
|
-
const NewLine = '\n';
|
|
2987
|
-
const joinLines = lines => {
|
|
2988
|
-
return lines.join(NewLine);
|
|
2989
|
-
};
|
|
2990
|
-
const splitLines$1 = lines => {
|
|
2991
|
-
return lines.split(NewLine);
|
|
2992
|
-
};
|
|
2993
|
-
const isModuleNotFoundMessage = line => {
|
|
2994
|
-
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
2995
|
-
};
|
|
2996
|
-
const getModuleNotFoundError = stderr => {
|
|
2997
|
-
const lines = splitLines$1(stderr);
|
|
2998
|
-
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
2999
|
-
const message = lines[messageIndex];
|
|
3000
|
-
return {
|
|
3001
|
-
message,
|
|
3002
|
-
code: ERR_MODULE_NOT_FOUND
|
|
3164
|
+
const visitor = node => {
|
|
3165
|
+
if (node && node.type === CallExpression && node.callee && node.callee.type === Import && node.arguments && node.arguments[0] && node.arguments[0].type === StringLiteral) {
|
|
3166
|
+
const relativePath = node.arguments[0].extra.rawValue;
|
|
3167
|
+
const start = node.arguments[0].start;
|
|
3168
|
+
const end = node.arguments[0].end;
|
|
3169
|
+
// @ts-ignore
|
|
3170
|
+
dependencies.push({
|
|
3171
|
+
relativePath,
|
|
3172
|
+
code,
|
|
3173
|
+
start,
|
|
3174
|
+
end
|
|
3175
|
+
});
|
|
3176
|
+
}
|
|
3003
3177
|
};
|
|
3178
|
+
walk(ast, visitor);
|
|
3179
|
+
return dependencies;
|
|
3004
3180
|
};
|
|
3005
|
-
|
|
3006
|
-
const
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
const RE_AT = /^\s+at/;
|
|
3010
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
3011
|
-
const isUnhelpfulNativeModuleError = stderr => {
|
|
3012
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
3013
|
-
};
|
|
3014
|
-
const isMessageCodeBlockStartIndex = line => {
|
|
3015
|
-
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
3016
|
-
};
|
|
3017
|
-
const isMessageCodeBlockEndIndex = line => {
|
|
3018
|
-
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
3181
|
+
|
|
3182
|
+
const isBabelError = error => {
|
|
3183
|
+
// @ts-ignore
|
|
3184
|
+
return isSyntaxError(error) && error.code === BABEL_PARSER_SYNTAX_ERROR;
|
|
3019
3185
|
};
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
3024
|
-
const relevantLines = lines.slice(startIndex, endIndex);
|
|
3025
|
-
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
3026
|
-
return relevantMessage;
|
|
3186
|
+
|
|
3187
|
+
const getOrigin = () => {
|
|
3188
|
+
return location.origin;
|
|
3027
3189
|
};
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3190
|
+
|
|
3191
|
+
const getAbsoluteUrl = (relativePath, sourceUrl) => {
|
|
3192
|
+
if (sourceUrl.startsWith('/')) {
|
|
3193
|
+
const origin = getOrigin();
|
|
3194
|
+
const absoluteSourceUrl = new URL(sourceUrl, origin).toString();
|
|
3195
|
+
return new URL(relativePath, absoluteSourceUrl).toString();
|
|
3196
|
+
}
|
|
3197
|
+
return new URL(relativePath, sourceUrl).toString();
|
|
3034
3198
|
};
|
|
3035
|
-
|
|
3036
|
-
|
|
3199
|
+
|
|
3200
|
+
const isExternal = url => {
|
|
3201
|
+
if (url.startsWith('/')) {
|
|
3037
3202
|
return false;
|
|
3038
3203
|
}
|
|
3039
|
-
|
|
3040
|
-
};
|
|
3041
|
-
const getModuleSyntaxError = () => {
|
|
3042
|
-
return {
|
|
3043
|
-
message: `ES Modules are not supported in electron`,
|
|
3044
|
-
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
3045
|
-
};
|
|
3046
|
-
};
|
|
3047
|
-
const isModuleNotFoundError = stderr => {
|
|
3048
|
-
if (!stderr) {
|
|
3204
|
+
if (url.startsWith(location.protocol)) {
|
|
3049
3205
|
return false;
|
|
3050
3206
|
}
|
|
3051
|
-
return
|
|
3052
|
-
};
|
|
3053
|
-
const isNormalStackLine = line => {
|
|
3054
|
-
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
3207
|
+
return true;
|
|
3055
3208
|
};
|
|
3056
|
-
const
|
|
3057
|
-
const
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
rest: []
|
|
3062
|
-
};
|
|
3063
|
-
}
|
|
3064
|
-
let lastIndex = index - 1;
|
|
3065
|
-
while (++lastIndex < lines.length) {
|
|
3066
|
-
if (!isNormalStackLine(lines[lastIndex])) {
|
|
3067
|
-
break;
|
|
3209
|
+
const getErrorInDependencies = async (url, dependencies, seenUrls) => {
|
|
3210
|
+
for (const dependency of dependencies) {
|
|
3211
|
+
const dependencyUrl = getAbsoluteUrl(dependency.relativePath, url);
|
|
3212
|
+
if (isExternal(dependencyUrl) || seenUrls.includes(dependencyUrl)) {
|
|
3213
|
+
continue;
|
|
3068
3214
|
}
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
3077
|
-
return getNativeModuleErrorMessage(stderr);
|
|
3078
|
-
}
|
|
3079
|
-
if (isModulesSyntaxError(stderr)) {
|
|
3080
|
-
return getModuleSyntaxError();
|
|
3081
|
-
}
|
|
3082
|
-
if (isModuleNotFoundError(stderr)) {
|
|
3083
|
-
return getModuleNotFoundError(stderr);
|
|
3084
|
-
}
|
|
3085
|
-
const lines = splitLines$1(stderr);
|
|
3086
|
-
const {
|
|
3087
|
-
actualMessage,
|
|
3088
|
-
rest
|
|
3089
|
-
} = getDetails(lines);
|
|
3090
|
-
return {
|
|
3091
|
-
message: `${actualMessage}`,
|
|
3092
|
-
code: '',
|
|
3093
|
-
stack: rest
|
|
3094
|
-
};
|
|
3095
|
-
};
|
|
3096
|
-
let IpcError$1 = class IpcError extends VError {
|
|
3097
|
-
// @ts-ignore
|
|
3098
|
-
constructor(betterMessage, stdout = '', stderr = '') {
|
|
3099
|
-
if (stdout || stderr) {
|
|
3100
|
-
// @ts-ignore
|
|
3101
|
-
const {
|
|
3102
|
-
message,
|
|
3103
|
-
code,
|
|
3104
|
-
stack
|
|
3105
|
-
} = getHelpfulChildProcessError(stdout, stderr);
|
|
3106
|
-
const cause = new Error(message);
|
|
3107
|
-
// @ts-ignore
|
|
3108
|
-
cause.code = code;
|
|
3109
|
-
cause.stack = stack;
|
|
3110
|
-
super(cause, betterMessage);
|
|
3215
|
+
seenUrls.push(dependencyUrl);
|
|
3216
|
+
// let dependencyResponse
|
|
3217
|
+
// try {
|
|
3218
|
+
const dependencyResponse = await fetch(dependencyUrl);
|
|
3219
|
+
// } catch (error) {}
|
|
3220
|
+
if (dependencyResponse.ok) {
|
|
3221
|
+
await tryToGetActualErrorMessage(null, dependencyUrl, dependencyResponse, seenUrls);
|
|
3111
3222
|
} else {
|
|
3112
|
-
|
|
3223
|
+
switch (dependencyResponse.status) {
|
|
3224
|
+
case NotFound:
|
|
3225
|
+
throw new DependencyNotFoundError(dependency.code, dependency.start, dependency.end, dependency.relativePath, dependencyUrl, url);
|
|
3226
|
+
// return `Failed to import ${url}: ${error}`
|
|
3227
|
+
}
|
|
3113
3228
|
}
|
|
3114
|
-
// @ts-ignore
|
|
3115
|
-
this.name = 'IpcError';
|
|
3116
|
-
// @ts-ignore
|
|
3117
|
-
this.stdout = stdout;
|
|
3118
|
-
// @ts-ignore
|
|
3119
|
-
this.stderr = stderr;
|
|
3120
3229
|
}
|
|
3121
3230
|
};
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
}
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
}
|
|
3134
|
-
|
|
3135
|
-
constructor(port) {
|
|
3136
|
-
super(port);
|
|
3231
|
+
|
|
3232
|
+
/**
|
|
3233
|
+
*
|
|
3234
|
+
* @param {string} url
|
|
3235
|
+
* @param {Response} response
|
|
3236
|
+
* @returns
|
|
3237
|
+
*/
|
|
3238
|
+
const tryToGetActualErrorMessage = async (error, url, response, seenUrls = []) => {
|
|
3239
|
+
let text;
|
|
3240
|
+
try {
|
|
3241
|
+
text = await response.text();
|
|
3242
|
+
} catch (error) {
|
|
3243
|
+
return `Failed to import ${url}: Unknown Network Error`;
|
|
3137
3244
|
}
|
|
3138
|
-
|
|
3139
|
-
|
|
3245
|
+
let ast;
|
|
3246
|
+
try {
|
|
3247
|
+
ast = await parse(text, {
|
|
3248
|
+
sourceType: Module
|
|
3249
|
+
});
|
|
3250
|
+
} catch (error) {
|
|
3251
|
+
if (isBabelError(error)) {
|
|
3252
|
+
throw new BabelParseError(url, error);
|
|
3253
|
+
}
|
|
3254
|
+
throw error;
|
|
3140
3255
|
}
|
|
3141
|
-
|
|
3142
|
-
|
|
3256
|
+
const dependencies = getBabelAstDependencies(text, ast);
|
|
3257
|
+
await getErrorInDependencies(url, dependencies, seenUrls);
|
|
3258
|
+
if (hasRecentErrors()) {
|
|
3259
|
+
const recentError = getRecentError();
|
|
3260
|
+
// @ts-ignore
|
|
3261
|
+
throw new ContentSecurityPolicyError(recentError.violatedDirective, recentError.sourceFile, recentError.lineNumber, recentError.columnNumber);
|
|
3143
3262
|
}
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3263
|
+
const contentType = response.headers.get('Content-Type');
|
|
3264
|
+
if (url.endsWith('.ts') && contentType === null) {
|
|
3265
|
+
return `Failed to import ${url}: Missing Content-Type header for javascript`;
|
|
3147
3266
|
}
|
|
3148
|
-
|
|
3149
|
-
|
|
3267
|
+
return `Failed to import ${url}: Unknown Network Error`;
|
|
3268
|
+
};
|
|
3269
|
+
|
|
3270
|
+
const tryToGetActualImportErrorMessage = async (url, error) => {
|
|
3271
|
+
let response;
|
|
3272
|
+
try {
|
|
3273
|
+
response = await fetch(url);
|
|
3274
|
+
} catch (error) {
|
|
3275
|
+
return `Failed to import ${url}: ${error}`;
|
|
3150
3276
|
}
|
|
3151
|
-
|
|
3152
|
-
|
|
3277
|
+
if (response.ok) {
|
|
3278
|
+
return await tryToGetActualErrorMessage(error, url, response);
|
|
3153
3279
|
}
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3280
|
+
switch (response.status) {
|
|
3281
|
+
case NotFound:
|
|
3282
|
+
throw new Error(`Failed to import ${url}: Not found (404)`);
|
|
3283
|
+
default:
|
|
3284
|
+
return `Failed to import ${url}: ${error}`;
|
|
3157
3285
|
}
|
|
3158
|
-
}
|
|
3159
|
-
const wrap$f = port => {
|
|
3160
|
-
return new IpcChildWithMessagePort(port);
|
|
3161
|
-
};
|
|
3162
|
-
const IpcChildWithMessagePort$1 = {
|
|
3163
|
-
__proto__: null,
|
|
3164
|
-
listen: listen$8,
|
|
3165
|
-
signal: signal$8,
|
|
3166
|
-
wrap: wrap$f
|
|
3167
3286
|
};
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3287
|
+
|
|
3288
|
+
const importScript = async url => {
|
|
3289
|
+
try {
|
|
3290
|
+
return await import(url);
|
|
3291
|
+
} catch (error) {
|
|
3292
|
+
if (isImportError(error)) {
|
|
3293
|
+
const actualErrorMessage = await tryToGetActualImportErrorMessage(url, error);
|
|
3294
|
+
throw new Error(actualErrorMessage);
|
|
3295
|
+
}
|
|
3296
|
+
// content security policy errors arrive a little bit later
|
|
3297
|
+
await sleep(0);
|
|
3298
|
+
if (hasRecentErrors()) {
|
|
3299
|
+
const recentError = getRecentError();
|
|
3300
|
+
// @ts-ignore
|
|
3301
|
+
throw new ContentSecurityPolicyError(recentError.violatedDirective, recentError.sourceFile, recentError.lineNumber, recentError.columnNumber);
|
|
3302
|
+
}
|
|
3303
|
+
throw error;
|
|
3172
3304
|
}
|
|
3173
|
-
return globalThis;
|
|
3174
3305
|
};
|
|
3175
|
-
|
|
3176
|
-
|
|
3306
|
+
|
|
3307
|
+
const activationTimeout = 10_000;
|
|
3308
|
+
const rejectAfterTimeout = async (timeout, token) => {
|
|
3309
|
+
await sleep(timeout);
|
|
3310
|
+
if (isCanceled(token)) {
|
|
3311
|
+
return;
|
|
3312
|
+
}
|
|
3313
|
+
throw new Error(`Activation timeout of ${timeout}ms exceeded`);
|
|
3177
3314
|
};
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3315
|
+
const activate = async (extension, absolutePath) => {
|
|
3316
|
+
try {
|
|
3317
|
+
string(extension.path);
|
|
3318
|
+
string(extension.browser);
|
|
3319
|
+
string(absolutePath);
|
|
3320
|
+
const module = await importScript(absolutePath);
|
|
3321
|
+
handleRpcInfos(extension);
|
|
3322
|
+
const token = create$5();
|
|
3323
|
+
try {
|
|
3324
|
+
await Promise.race([module.activate(extension), rejectAfterTimeout(activationTimeout, token)]);
|
|
3325
|
+
} catch (error) {
|
|
3326
|
+
if (isImportError(error)) {
|
|
3327
|
+
const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
|
|
3328
|
+
throw new Error(actualErrorMessage);
|
|
3329
|
+
}
|
|
3330
|
+
throw error;
|
|
3331
|
+
} finally {
|
|
3332
|
+
cancel(token);
|
|
3333
|
+
}
|
|
3334
|
+
} catch (error) {
|
|
3335
|
+
const id = getExtensionId(extension);
|
|
3336
|
+
throw new VError(error, `Failed to activate extension ${id}`);
|
|
3181
3337
|
}
|
|
3182
|
-
|
|
3338
|
+
// console.info('activated', path)
|
|
3339
|
+
};
|
|
3340
|
+
|
|
3341
|
+
class ExecError extends Error {
|
|
3342
|
+
constructor(command, args, stdout, stderr, exitCode) {
|
|
3343
|
+
super(`Failed to execute ${command}: process exited with code ${exitCode}`);
|
|
3344
|
+
this.name = 'ExecError';
|
|
3183
3345
|
// @ts-ignore
|
|
3184
|
-
this.
|
|
3185
|
-
}
|
|
3186
|
-
sendAndTransfer(message) {
|
|
3187
|
-
const transfer = getTransferrables(message);
|
|
3346
|
+
this.stdout = stdout;
|
|
3188
3347
|
// @ts-ignore
|
|
3189
|
-
this.
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
// ignore
|
|
3193
|
-
}
|
|
3194
|
-
onClose(callback) {
|
|
3195
|
-
// ignore
|
|
3196
|
-
}
|
|
3197
|
-
onMessage(callback) {
|
|
3198
|
-
this._rawIpc.addEventListener('message', callback);
|
|
3348
|
+
this.stderr = stderr;
|
|
3349
|
+
// @ts-ignore
|
|
3350
|
+
this.exitCode = exitCode;
|
|
3199
3351
|
}
|
|
3200
3352
|
}
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3353
|
+
|
|
3354
|
+
const mockExec = () => {
|
|
3355
|
+
try {
|
|
3356
|
+
// @ts-ignore
|
|
3357
|
+
api.exec = async (command, args, options) => {
|
|
3358
|
+
const result = await invoke$1('Test.executeMockExecFunction', command, args, options);
|
|
3359
|
+
const {
|
|
3360
|
+
stdout,
|
|
3361
|
+
stderr,
|
|
3362
|
+
exitCode
|
|
3363
|
+
} = result;
|
|
3364
|
+
if (exitCode !== 0) {
|
|
3365
|
+
throw new ExecError(command, args, stdout, stderr, exitCode);
|
|
3366
|
+
}
|
|
3367
|
+
return {
|
|
3368
|
+
stdout,
|
|
3369
|
+
stderr,
|
|
3370
|
+
exitCode
|
|
3371
|
+
};
|
|
3372
|
+
};
|
|
3373
|
+
} catch (error) {
|
|
3374
|
+
throw new VError(error, 'Failed to mock exec function');
|
|
3375
|
+
}
|
|
3219
3376
|
};
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
resolve,
|
|
3223
|
-
promise
|
|
3224
|
-
} = withResolvers$1();
|
|
3225
|
-
port.addEventListener('message', resolve, {
|
|
3226
|
-
once: true
|
|
3227
|
-
});
|
|
3228
|
-
const event = await promise;
|
|
3377
|
+
|
|
3378
|
+
const mockRpc = () => {
|
|
3229
3379
|
// @ts-ignore
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
parentIpc.send({
|
|
3243
|
-
jsonrpc: '2.0',
|
|
3244
|
-
id: firstMessage.id,
|
|
3245
|
-
result: null
|
|
3246
|
-
});
|
|
3247
|
-
parentIpc.dispose();
|
|
3248
|
-
const port = firstMessage.params[1];
|
|
3249
|
-
return port;
|
|
3250
|
-
}
|
|
3251
|
-
return globalThis;
|
|
3380
|
+
api.createNodeRpc = async options => {
|
|
3381
|
+
try {
|
|
3382
|
+
return {
|
|
3383
|
+
async invoke(method, ...params) {
|
|
3384
|
+
const result = await invoke$1('Test.executeMockRpcFunction', options.name, method, ...params);
|
|
3385
|
+
return result;
|
|
3386
|
+
}
|
|
3387
|
+
};
|
|
3388
|
+
} catch (error) {
|
|
3389
|
+
throw new VError(error, 'Failed to mock exec function');
|
|
3390
|
+
}
|
|
3391
|
+
};
|
|
3252
3392
|
};
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
}
|
|
3263
|
-
sendAndTransfer(message) {
|
|
3264
|
-
const transfer = getTransferrables(message);
|
|
3265
|
-
this._rawIpc.postMessage(message, transfer);
|
|
3266
|
-
}
|
|
3267
|
-
dispose() {
|
|
3268
|
-
if (this._rawIpc.close) {
|
|
3269
|
-
this._rawIpc.close();
|
|
3393
|
+
|
|
3394
|
+
const getStatusBarItems = async () => {
|
|
3395
|
+
const providers = Object.values(state$5.providers);
|
|
3396
|
+
const statusBarItems = [];
|
|
3397
|
+
for (const provider of providers) {
|
|
3398
|
+
// @ts-ignore
|
|
3399
|
+
if (provider && provider.statusBarCommands) {
|
|
3400
|
+
// @ts-ignore
|
|
3401
|
+
statusBarItems.push(...provider.statusBarCommands);
|
|
3270
3402
|
}
|
|
3271
3403
|
}
|
|
3272
|
-
|
|
3273
|
-
// ignore
|
|
3274
|
-
}
|
|
3275
|
-
onMessage(callback) {
|
|
3276
|
-
this._rawIpc.addEventListener('message', callback);
|
|
3277
|
-
this._rawIpc.start();
|
|
3278
|
-
}
|
|
3279
|
-
}
|
|
3280
|
-
const wrap$d = port => {
|
|
3281
|
-
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
3404
|
+
return statusBarItems;
|
|
3282
3405
|
};
|
|
3283
|
-
const
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3406
|
+
const registerChangeListener = () => {
|
|
3407
|
+
// TODO
|
|
3408
|
+
};
|
|
3409
|
+
|
|
3410
|
+
const handleBeforeUnload = () => {
|
|
3411
|
+
// TODO save all webviews in localstorage
|
|
3412
|
+
// cannot use indexeddb during unload
|
|
3413
|
+
console.log('before unload');
|
|
3287
3414
|
};
|
|
3288
3415
|
|
|
3416
|
+
const MessagePort$1 = 1;
|
|
3417
|
+
const ModuleWorker = 2;
|
|
3418
|
+
const ModuleWorkerWithMessagePort = 4;
|
|
3419
|
+
|
|
3420
|
+
// @ts-ignore
|
|
3289
3421
|
const getModule$1 = method => {
|
|
3290
3422
|
switch (method) {
|
|
3291
3423
|
case ModuleWorker:
|
|
@@ -3302,7 +3434,7 @@ const getModule$1 = method => {
|
|
|
3302
3434
|
const handleMessagePort = port => {
|
|
3303
3435
|
const module = getModule$1(MessagePort$1);
|
|
3304
3436
|
const ipc = module.wrap(port);
|
|
3305
|
-
handleIpc(ipc);
|
|
3437
|
+
handleIpc$1(ipc);
|
|
3306
3438
|
ipc.send('ready');
|
|
3307
3439
|
};
|
|
3308
3440
|
|
|
@@ -4032,6 +4164,7 @@ const commandMap = {
|
|
|
4032
4164
|
['ExtensionHostWebView.create']: createWebView,
|
|
4033
4165
|
['ExtensionHostWebView.dispose']: disposeWebView,
|
|
4034
4166
|
['ExtensionHostWebView.load']: load,
|
|
4167
|
+
['ExtensionHostWebView.getWebViewInfo']: getWebViewInfo,
|
|
4035
4168
|
['HandleBeforeUnload.handleBeforeUnload']: handleBeforeUnload,
|
|
4036
4169
|
['HandleMessagePort.handleMessagePort']: handleMessagePort,
|
|
4037
4170
|
['SaveState.saveState']: saveState,
|
|
@@ -4075,82 +4208,19 @@ const commandMap = {
|
|
|
4075
4208
|
[WorkspaceSetPath]: setWorkspacePath
|
|
4076
4209
|
};
|
|
4077
4210
|
|
|
4078
|
-
const
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
/**
|
|
4083
|
-
* @param {PromiseRejectionEvent} event
|
|
4084
|
-
*/
|
|
4085
|
-
const handleUnhandledRejection = async event => {
|
|
4086
|
-
try {
|
|
4087
|
-
event.preventDefault();
|
|
4088
|
-
await handleError(event.reason);
|
|
4089
|
-
} catch {
|
|
4090
|
-
console.error(event.reason);
|
|
4091
|
-
}
|
|
4092
|
-
};
|
|
4093
|
-
|
|
4094
|
-
/**
|
|
4095
|
-
* @param {ErrorEvent} event
|
|
4096
|
-
*/
|
|
4097
|
-
const handleUnhandledError = async event => {
|
|
4098
|
-
try {
|
|
4099
|
-
event.preventDefault();
|
|
4100
|
-
await handleError(event.error);
|
|
4101
|
-
} catch {
|
|
4102
|
-
console.error(event.error);
|
|
4103
|
-
}
|
|
4104
|
-
};
|
|
4105
|
-
|
|
4106
|
-
const handleContentSecurityPolicyViolation = event => {
|
|
4107
|
-
const {
|
|
4108
|
-
violatedDirective,
|
|
4109
|
-
sourceFile,
|
|
4110
|
-
lineNumber,
|
|
4111
|
-
columnNumber
|
|
4112
|
-
} = event;
|
|
4113
|
-
addError({
|
|
4114
|
-
violatedDirective,
|
|
4115
|
-
sourceFile,
|
|
4116
|
-
lineNumber,
|
|
4117
|
-
columnNumber
|
|
4211
|
+
const listen = async () => {
|
|
4212
|
+
const rpc = await WebWorkerRpcClient.create({
|
|
4213
|
+
commandMap: commandMap
|
|
4118
4214
|
});
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
const listen = async ({
|
|
4122
|
-
method
|
|
4123
|
-
}) => {
|
|
4124
|
-
const module = await getModule$1(method);
|
|
4125
|
-
const rawIpc = await module.listen();
|
|
4126
|
-
// @ts-ignore
|
|
4127
|
-
if (module.signal) {
|
|
4128
|
-
// @ts-ignore
|
|
4129
|
-
module.signal(rawIpc);
|
|
4130
|
-
}
|
|
4131
|
-
const ipc = module.wrap(rawIpc);
|
|
4132
|
-
return ipc;
|
|
4133
|
-
};
|
|
4134
|
-
|
|
4135
|
-
const setStackTraceLimit = value => {
|
|
4136
|
-
if (Error.stackTraceLimit && Error.stackTraceLimit < value) {
|
|
4137
|
-
Error.stackTraceLimit = value;
|
|
4138
|
-
}
|
|
4215
|
+
setRpc(rpc);
|
|
4139
4216
|
};
|
|
4140
4217
|
|
|
4141
4218
|
const main = async () => {
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
if ('SecurityPolicyViolationEvent' in self) {
|
|
4146
|
-
self.addEventListener('securitypolicyviolation', handleContentSecurityPolicyViolation);
|
|
4147
|
-
}
|
|
4148
|
-
globalThis.vscode = api;
|
|
4149
|
-
register$1(commandMap);
|
|
4150
|
-
const ipc = await listen({
|
|
4151
|
-
method: Auto()
|
|
4219
|
+
setup({
|
|
4220
|
+
errorConstructor: Error,
|
|
4221
|
+
global: globalThis
|
|
4152
4222
|
});
|
|
4153
|
-
listen
|
|
4223
|
+
await listen();
|
|
4154
4224
|
};
|
|
4155
4225
|
|
|
4156
4226
|
main();
|
|
@@ -4344,7 +4414,7 @@ const create$2 = async ({
|
|
|
4344
4414
|
port1,
|
|
4345
4415
|
port2
|
|
4346
4416
|
} = getPortTuple();
|
|
4347
|
-
await invokeAndTransfer('IpcParent.create', {
|
|
4417
|
+
await invokeAndTransfer$1('IpcParent.create', {
|
|
4348
4418
|
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
|
|
4349
4419
|
url,
|
|
4350
4420
|
name,
|
|
@@ -4421,7 +4491,7 @@ const create$1 = ({
|
|
|
4421
4491
|
return {
|
|
4422
4492
|
ipc,
|
|
4423
4493
|
invoke(method, ...params) {
|
|
4424
|
-
return invoke
|
|
4494
|
+
return invoke(this.ipc, method, ...params);
|
|
4425
4495
|
}
|
|
4426
4496
|
};
|
|
4427
4497
|
};
|
|
@@ -4432,7 +4502,7 @@ const RpcParentWithJsonRpc = {
|
|
|
4432
4502
|
};
|
|
4433
4503
|
|
|
4434
4504
|
const sendMessagePortToElectron = async (port, initialCommand) => {
|
|
4435
|
-
await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, initialCommand);
|
|
4505
|
+
await invokeAndTransfer$1('SendMessagePortToElectron.sendMessagePortToElectron', port, initialCommand);
|
|
4436
4506
|
};
|
|
4437
4507
|
|
|
4438
4508
|
const getPort = async type => {
|