@lvce-editor/hover-worker 2.16.0 → 2.18.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/hoverWorkerMain.js +332 -116
- package/package.json +1 -1
package/dist/hoverWorkerMain.js
CHANGED
|
@@ -63,7 +63,7 @@ class AssertionError extends Error {
|
|
|
63
63
|
const Object$1 = 1;
|
|
64
64
|
const Number$1 = 2;
|
|
65
65
|
const Array$1 = 3;
|
|
66
|
-
const String = 4;
|
|
66
|
+
const String$1 = 4;
|
|
67
67
|
const Boolean$1 = 5;
|
|
68
68
|
const Function = 6;
|
|
69
69
|
const Null = 7;
|
|
@@ -75,7 +75,7 @@ const getType = value => {
|
|
|
75
75
|
case 'function':
|
|
76
76
|
return Function;
|
|
77
77
|
case 'string':
|
|
78
|
-
return String;
|
|
78
|
+
return String$1;
|
|
79
79
|
case 'object':
|
|
80
80
|
if (value === null) {
|
|
81
81
|
return Null;
|
|
@@ -525,7 +525,7 @@ const register = commandMap => {
|
|
|
525
525
|
const getCommand$1 = key => {
|
|
526
526
|
return commands[key];
|
|
527
527
|
};
|
|
528
|
-
const execute
|
|
528
|
+
const execute = (command, ...args) => {
|
|
529
529
|
const fn = getCommand$1(command);
|
|
530
530
|
if (!fn) {
|
|
531
531
|
throw new CommandNotFoundError(command);
|
|
@@ -645,6 +645,9 @@ const restoreExistingError = (error, currentStack) => {
|
|
|
645
645
|
};
|
|
646
646
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
647
647
|
const restoredError = new JsonRpcError(error.message);
|
|
648
|
+
Object.assign(restoredError, {
|
|
649
|
+
code: error.code
|
|
650
|
+
});
|
|
648
651
|
const parentStack = getParentStack(error);
|
|
649
652
|
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
650
653
|
return restoredError;
|
|
@@ -664,9 +667,13 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
664
667
|
// @ts-ignore
|
|
665
668
|
restoredError.codeFrame = error.data.codeFrame;
|
|
666
669
|
}
|
|
667
|
-
if (error.data.code) {
|
|
670
|
+
if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
|
|
668
671
|
// @ts-ignore
|
|
669
|
-
restoredError
|
|
672
|
+
Object.defineProperty(restoredError, 'code', {
|
|
673
|
+
configurable: true,
|
|
674
|
+
value: error.data.code,
|
|
675
|
+
writable: true
|
|
676
|
+
});
|
|
670
677
|
}
|
|
671
678
|
if (error.data.type) {
|
|
672
679
|
// @ts-ignore
|
|
@@ -687,7 +694,14 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
687
694
|
}
|
|
688
695
|
};
|
|
689
696
|
const restoreMessageError = (error, _currentStack) => {
|
|
690
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
697
|
+
const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
|
|
698
|
+
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
699
|
+
Object.defineProperty(restoredError, 'code', {
|
|
700
|
+
configurable: true,
|
|
701
|
+
value: error.code,
|
|
702
|
+
writable: true
|
|
703
|
+
});
|
|
704
|
+
}
|
|
691
705
|
if (error.data) {
|
|
692
706
|
applyDataProperties(restoredError, error);
|
|
693
707
|
} else {
|
|
@@ -695,6 +709,23 @@ const restoreMessageError = (error, _currentStack) => {
|
|
|
695
709
|
}
|
|
696
710
|
return restoredError;
|
|
697
711
|
};
|
|
712
|
+
const getFallbackMessage = error => {
|
|
713
|
+
if (error && typeof error.message === 'string' && error.message) {
|
|
714
|
+
return error.message;
|
|
715
|
+
}
|
|
716
|
+
if (error && error.data) {
|
|
717
|
+
return getFallbackMessage(error.data);
|
|
718
|
+
}
|
|
719
|
+
const stringified = String(error);
|
|
720
|
+
if (stringified !== '[object Object]') {
|
|
721
|
+
return stringified;
|
|
722
|
+
}
|
|
723
|
+
try {
|
|
724
|
+
return JSON.stringify(error);
|
|
725
|
+
} catch {
|
|
726
|
+
return stringified;
|
|
727
|
+
}
|
|
728
|
+
};
|
|
698
729
|
const restoreJsonRpcError = error => {
|
|
699
730
|
const currentStack = getCurrentStack();
|
|
700
731
|
if (error && error instanceof Error) {
|
|
@@ -703,13 +734,13 @@ const restoreJsonRpcError = error => {
|
|
|
703
734
|
if (error && error.code && error.code === MethodNotFound) {
|
|
704
735
|
return restoreMethodNotFoundError(error, currentStack);
|
|
705
736
|
}
|
|
737
|
+
if (error && error.error) {
|
|
738
|
+
return restoreJsonRpcError(error.error);
|
|
739
|
+
}
|
|
706
740
|
if (error && error.message) {
|
|
707
741
|
return restoreMessageError(error);
|
|
708
742
|
}
|
|
709
|
-
|
|
710
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
711
|
-
}
|
|
712
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
743
|
+
return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
|
|
713
744
|
};
|
|
714
745
|
const unwrapJsonRpcResult = responseMessage => {
|
|
715
746
|
if ('error' in responseMessage) {
|
|
@@ -766,9 +797,9 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
766
797
|
return {
|
|
767
798
|
code: Custom,
|
|
768
799
|
data: {
|
|
769
|
-
code: prettyError.code,
|
|
800
|
+
code: prettyError.code ?? error?.code,
|
|
770
801
|
codeFrame: prettyError.codeFrame,
|
|
771
|
-
name: prettyError.name,
|
|
802
|
+
name: prettyError.name ?? error?.name,
|
|
772
803
|
stack: getStack(prettyError),
|
|
773
804
|
type: getErrorType(prettyError)
|
|
774
805
|
},
|
|
@@ -788,7 +819,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
788
819
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
789
820
|
return create$1$1(id, errorProperty);
|
|
790
821
|
};
|
|
791
|
-
const create$
|
|
822
|
+
const create$a = (message, result) => {
|
|
792
823
|
return {
|
|
793
824
|
id: message.id,
|
|
794
825
|
jsonrpc: Two$1,
|
|
@@ -797,13 +828,18 @@ const create$9 = (message, result) => {
|
|
|
797
828
|
};
|
|
798
829
|
const getSuccessResponse = (message, result) => {
|
|
799
830
|
const resultProperty = result ?? null;
|
|
800
|
-
return create$
|
|
831
|
+
return create$a(message, resultProperty);
|
|
801
832
|
};
|
|
802
833
|
const getErrorResponseSimple = (id, error) => {
|
|
803
834
|
return {
|
|
804
835
|
error: {
|
|
805
836
|
code: Custom,
|
|
806
|
-
data: error
|
|
837
|
+
data: error instanceof Error ? {
|
|
838
|
+
...error,
|
|
839
|
+
code: 'code' in error ? error.code : undefined,
|
|
840
|
+
stack: error.stack,
|
|
841
|
+
type: error.name
|
|
842
|
+
} : error,
|
|
807
843
|
// @ts-ignore
|
|
808
844
|
message: error.message
|
|
809
845
|
},
|
|
@@ -891,7 +927,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
891
927
|
|
|
892
928
|
const Two = '2.0';
|
|
893
929
|
|
|
894
|
-
const create$
|
|
930
|
+
const create$9 = (method, params) => {
|
|
895
931
|
return {
|
|
896
932
|
jsonrpc: Two,
|
|
897
933
|
method,
|
|
@@ -899,7 +935,7 @@ const create$8 = (method, params) => {
|
|
|
899
935
|
};
|
|
900
936
|
};
|
|
901
937
|
|
|
902
|
-
const create$
|
|
938
|
+
const create$8 = (id, method, params) => {
|
|
903
939
|
const message = {
|
|
904
940
|
id,
|
|
905
941
|
jsonrpc: Two,
|
|
@@ -910,12 +946,12 @@ const create$7 = (id, method, params) => {
|
|
|
910
946
|
};
|
|
911
947
|
|
|
912
948
|
let id = 0;
|
|
913
|
-
const create$
|
|
949
|
+
const create$7 = () => {
|
|
914
950
|
return ++id;
|
|
915
951
|
};
|
|
916
952
|
|
|
917
953
|
const registerPromise = map => {
|
|
918
|
-
const id = create$
|
|
954
|
+
const id = create$7();
|
|
919
955
|
const {
|
|
920
956
|
promise,
|
|
921
957
|
resolve
|
|
@@ -932,7 +968,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
932
968
|
id,
|
|
933
969
|
promise
|
|
934
970
|
} = registerPromise(callbacks);
|
|
935
|
-
const message = create$
|
|
971
|
+
const message = create$8(id, method, params);
|
|
936
972
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
937
973
|
ipc.sendAndTransfer(message);
|
|
938
974
|
} else {
|
|
@@ -968,7 +1004,7 @@ const createRpc = ipc => {
|
|
|
968
1004
|
* @deprecated
|
|
969
1005
|
*/
|
|
970
1006
|
send(method, ...params) {
|
|
971
|
-
const message = create$
|
|
1007
|
+
const message = create$9(method, params);
|
|
972
1008
|
ipc.send(message);
|
|
973
1009
|
}
|
|
974
1010
|
};
|
|
@@ -985,8 +1021,11 @@ const logError = () => {
|
|
|
985
1021
|
// handled by renderer worker
|
|
986
1022
|
};
|
|
987
1023
|
const handleMessage = event => {
|
|
1024
|
+
if (event.data === 'ready') {
|
|
1025
|
+
return Promise.resolve();
|
|
1026
|
+
}
|
|
988
1027
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
989
|
-
const actualExecute = event?.target?.execute || execute
|
|
1028
|
+
const actualExecute = event?.target?.execute || execute;
|
|
990
1029
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
991
1030
|
};
|
|
992
1031
|
|
|
@@ -1008,7 +1047,35 @@ const listen$1 = async (module, options) => {
|
|
|
1008
1047
|
return ipc;
|
|
1009
1048
|
};
|
|
1010
1049
|
|
|
1011
|
-
const
|
|
1050
|
+
const createSharedLazyRpc = factory => {
|
|
1051
|
+
let rpcPromise;
|
|
1052
|
+
const getOrCreate = () => {
|
|
1053
|
+
if (!rpcPromise) {
|
|
1054
|
+
rpcPromise = factory();
|
|
1055
|
+
}
|
|
1056
|
+
return rpcPromise;
|
|
1057
|
+
};
|
|
1058
|
+
return {
|
|
1059
|
+
async dispose() {
|
|
1060
|
+
const rpc = await getOrCreate();
|
|
1061
|
+
await rpc.dispose();
|
|
1062
|
+
},
|
|
1063
|
+
async invoke(method, ...params) {
|
|
1064
|
+
const rpc = await getOrCreate();
|
|
1065
|
+
return rpc.invoke(method, ...params);
|
|
1066
|
+
},
|
|
1067
|
+
async invokeAndTransfer(method, ...params) {
|
|
1068
|
+
const rpc = await getOrCreate();
|
|
1069
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1070
|
+
},
|
|
1071
|
+
async send(method, ...params) {
|
|
1072
|
+
const rpc = await getOrCreate();
|
|
1073
|
+
rpc.send(method, ...params);
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1078
|
+
const create$6 = async ({
|
|
1012
1079
|
commandMap,
|
|
1013
1080
|
isMessagePortOpen = true,
|
|
1014
1081
|
messagePort
|
|
@@ -1026,7 +1093,7 @@ const create$5 = async ({
|
|
|
1026
1093
|
return rpc;
|
|
1027
1094
|
};
|
|
1028
1095
|
|
|
1029
|
-
const create$
|
|
1096
|
+
const create$5 = async ({
|
|
1030
1097
|
commandMap,
|
|
1031
1098
|
isMessagePortOpen,
|
|
1032
1099
|
send
|
|
@@ -1036,13 +1103,27 @@ const create$4 = async ({
|
|
|
1036
1103
|
port2
|
|
1037
1104
|
} = new MessageChannel();
|
|
1038
1105
|
await send(port1);
|
|
1039
|
-
return create$
|
|
1106
|
+
return create$6({
|
|
1040
1107
|
commandMap,
|
|
1041
1108
|
isMessagePortOpen,
|
|
1042
1109
|
messagePort: port2
|
|
1043
1110
|
});
|
|
1044
1111
|
};
|
|
1045
1112
|
|
|
1113
|
+
const create$4 = async ({
|
|
1114
|
+
commandMap,
|
|
1115
|
+
isMessagePortOpen,
|
|
1116
|
+
send
|
|
1117
|
+
}) => {
|
|
1118
|
+
return createSharedLazyRpc(() => {
|
|
1119
|
+
return create$5({
|
|
1120
|
+
commandMap,
|
|
1121
|
+
isMessagePortOpen,
|
|
1122
|
+
send
|
|
1123
|
+
});
|
|
1124
|
+
});
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1046
1127
|
const create$3 = async ({
|
|
1047
1128
|
commandMap
|
|
1048
1129
|
}) => {
|
|
@@ -1079,29 +1160,100 @@ const toCommandId = key => {
|
|
|
1079
1160
|
return key.slice(dotIndex + 1);
|
|
1080
1161
|
};
|
|
1081
1162
|
const create$2 = () => {
|
|
1163
|
+
const commandQueues = new Map();
|
|
1164
|
+
const generations = Object.create(null);
|
|
1082
1165
|
const states = Object.create(null);
|
|
1083
|
-
const commandMapRef =
|
|
1166
|
+
const commandMapRef = Object.create(null);
|
|
1167
|
+
const commandsById = Object.create(null);
|
|
1168
|
+
const getGeneration = uid => generations[uid] || 0;
|
|
1169
|
+
const isCurrentGeneration = (uid, generation) => {
|
|
1170
|
+
return states[uid] !== undefined && getGeneration(uid) === generation;
|
|
1171
|
+
};
|
|
1172
|
+
const updateState = (uid, generation, fallbackState, updater) => {
|
|
1173
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1174
|
+
return Promise.resolve(fallbackState);
|
|
1175
|
+
}
|
|
1176
|
+
const current = states[uid];
|
|
1177
|
+
const updatedState = updater(current.newState);
|
|
1178
|
+
if (updatedState !== current.newState) {
|
|
1179
|
+
states[uid] = {
|
|
1180
|
+
newState: updatedState,
|
|
1181
|
+
oldState: current.oldState,
|
|
1182
|
+
scheduledState: updatedState
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
return Promise.resolve(updatedState);
|
|
1186
|
+
};
|
|
1187
|
+
const createAsyncCommandContext = (uid, generation) => {
|
|
1188
|
+
let latestState = states[uid].newState;
|
|
1189
|
+
return {
|
|
1190
|
+
getState: () => {
|
|
1191
|
+
if (isCurrentGeneration(uid, generation)) {
|
|
1192
|
+
latestState = states[uid].newState;
|
|
1193
|
+
}
|
|
1194
|
+
return latestState;
|
|
1195
|
+
},
|
|
1196
|
+
updateState: async updater => {
|
|
1197
|
+
latestState = await updateState(uid, generation, latestState, updater);
|
|
1198
|
+
return latestState;
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
};
|
|
1202
|
+
const enqueueCommand = async (uid, command) => {
|
|
1203
|
+
const previous = commandQueues.get(uid) || Promise.resolve();
|
|
1204
|
+
const run = async () => {
|
|
1205
|
+
try {
|
|
1206
|
+
await previous;
|
|
1207
|
+
} catch {
|
|
1208
|
+
// The previous caller receives its error; later commands must still run.
|
|
1209
|
+
}
|
|
1210
|
+
await command();
|
|
1211
|
+
};
|
|
1212
|
+
const current = run();
|
|
1213
|
+
commandQueues.set(uid, current);
|
|
1214
|
+
try {
|
|
1215
|
+
await current;
|
|
1216
|
+
} finally {
|
|
1217
|
+
if (commandQueues.get(uid) === current) {
|
|
1218
|
+
commandQueues.delete(uid);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1084
1222
|
return {
|
|
1085
1223
|
clear() {
|
|
1224
|
+
commandQueues.clear();
|
|
1086
1225
|
for (const key of Object.keys(states)) {
|
|
1087
1226
|
delete states[key];
|
|
1088
1227
|
}
|
|
1089
1228
|
},
|
|
1229
|
+
createDirectEventCommandMap(requestRender) {
|
|
1230
|
+
return {
|
|
1231
|
+
async 'Viewlet.executeViewletCommand'(uid, command, ...args) {
|
|
1232
|
+
const fn = commandsById[command];
|
|
1233
|
+
if (!fn) {
|
|
1234
|
+
throw new Error(`Viewlet command not found: ${command}`);
|
|
1235
|
+
}
|
|
1236
|
+
await fn(uid, ...args);
|
|
1237
|
+
await requestRender(uid);
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
},
|
|
1090
1241
|
diff(uid, modules, numbers) {
|
|
1091
1242
|
const {
|
|
1092
|
-
|
|
1093
|
-
|
|
1243
|
+
oldState,
|
|
1244
|
+
scheduledState
|
|
1094
1245
|
} = states[uid];
|
|
1095
1246
|
const diffResult = [];
|
|
1096
1247
|
for (let i = 0; i < modules.length; i++) {
|
|
1097
1248
|
const fn = modules[i];
|
|
1098
|
-
if (!fn(oldState,
|
|
1249
|
+
if (!fn(oldState, scheduledState)) {
|
|
1099
1250
|
diffResult.push(numbers[i]);
|
|
1100
1251
|
}
|
|
1101
1252
|
}
|
|
1102
1253
|
return diffResult;
|
|
1103
1254
|
},
|
|
1104
1255
|
dispose(uid) {
|
|
1256
|
+
commandQueues.delete(uid);
|
|
1105
1257
|
delete states[uid];
|
|
1106
1258
|
},
|
|
1107
1259
|
get(uid) {
|
|
@@ -1113,21 +1265,36 @@ const create$2 = () => {
|
|
|
1113
1265
|
return ids;
|
|
1114
1266
|
},
|
|
1115
1267
|
getKeys() {
|
|
1116
|
-
return Object.keys(states).map(
|
|
1117
|
-
return Number.parseFloat(key);
|
|
1118
|
-
});
|
|
1268
|
+
return Object.keys(states).map(Number);
|
|
1119
1269
|
},
|
|
1120
1270
|
registerCommands(commandMap) {
|
|
1121
1271
|
Object.assign(commandMapRef, commandMap);
|
|
1272
|
+
for (const [key, fn] of Object.entries(commandMap)) {
|
|
1273
|
+
commandsById[toCommandId(key)] = fn;
|
|
1274
|
+
}
|
|
1122
1275
|
},
|
|
1123
|
-
set(uid, oldState, newState) {
|
|
1276
|
+
set(uid, oldState, newState, scheduledState) {
|
|
1277
|
+
const current = states[uid];
|
|
1278
|
+
if (!current || oldState === newState && newState !== current.newState) {
|
|
1279
|
+
generations[uid] = getGeneration(uid) + 1;
|
|
1280
|
+
}
|
|
1124
1281
|
states[uid] = {
|
|
1125
1282
|
newState,
|
|
1126
|
-
oldState
|
|
1283
|
+
oldState,
|
|
1284
|
+
scheduledState: scheduledState ?? newState
|
|
1285
|
+
};
|
|
1286
|
+
},
|
|
1287
|
+
wrapAsyncCommand(fn) {
|
|
1288
|
+
const wrapped = async (uid, ...args) => {
|
|
1289
|
+
const generation = getGeneration(uid);
|
|
1290
|
+
const context = createAsyncCommandContext(uid, generation);
|
|
1291
|
+
await fn(context, ...args);
|
|
1127
1292
|
};
|
|
1293
|
+
return wrapped;
|
|
1128
1294
|
},
|
|
1129
1295
|
wrapCommand(fn) {
|
|
1130
1296
|
const wrapped = async (uid, ...args) => {
|
|
1297
|
+
const generation = getGeneration(uid);
|
|
1131
1298
|
const {
|
|
1132
1299
|
newState,
|
|
1133
1300
|
oldState
|
|
@@ -1136,6 +1303,9 @@ const create$2 = () => {
|
|
|
1136
1303
|
if (oldState === newerState || newState === newerState) {
|
|
1137
1304
|
return;
|
|
1138
1305
|
}
|
|
1306
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1139
1309
|
const latestOld = states[uid];
|
|
1140
1310
|
const latestNew = {
|
|
1141
1311
|
...latestOld.newState,
|
|
@@ -1143,7 +1313,8 @@ const create$2 = () => {
|
|
|
1143
1313
|
};
|
|
1144
1314
|
states[uid] = {
|
|
1145
1315
|
newState: latestNew,
|
|
1146
|
-
oldState: latestOld.oldState
|
|
1316
|
+
oldState: latestOld.oldState,
|
|
1317
|
+
scheduledState: latestNew
|
|
1147
1318
|
};
|
|
1148
1319
|
};
|
|
1149
1320
|
return wrapped;
|
|
@@ -1159,6 +1330,7 @@ const create$2 = () => {
|
|
|
1159
1330
|
},
|
|
1160
1331
|
wrapLoadContent(fn) {
|
|
1161
1332
|
const wrapped = async (uid, ...args) => {
|
|
1333
|
+
const generation = getGeneration(uid);
|
|
1162
1334
|
const {
|
|
1163
1335
|
newState,
|
|
1164
1336
|
oldState
|
|
@@ -1173,6 +1345,11 @@ const create$2 = () => {
|
|
|
1173
1345
|
error
|
|
1174
1346
|
};
|
|
1175
1347
|
}
|
|
1348
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1349
|
+
return {
|
|
1350
|
+
error
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1176
1353
|
const latestOld = states[uid];
|
|
1177
1354
|
const latestNew = {
|
|
1178
1355
|
...latestOld.newState,
|
|
@@ -1180,13 +1357,59 @@ const create$2 = () => {
|
|
|
1180
1357
|
};
|
|
1181
1358
|
states[uid] = {
|
|
1182
1359
|
newState: latestNew,
|
|
1183
|
-
oldState: latestOld.oldState
|
|
1360
|
+
oldState: latestOld.oldState,
|
|
1361
|
+
scheduledState: latestNew
|
|
1184
1362
|
};
|
|
1185
1363
|
return {
|
|
1186
1364
|
error
|
|
1187
1365
|
};
|
|
1188
1366
|
};
|
|
1189
1367
|
return wrapped;
|
|
1368
|
+
},
|
|
1369
|
+
wrapSerialAsyncCommand(fn) {
|
|
1370
|
+
const wrapped = async (uid, ...args) => {
|
|
1371
|
+
await enqueueCommand(uid, async () => {
|
|
1372
|
+
if (!states[uid]) {
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
const generation = getGeneration(uid);
|
|
1376
|
+
const context = createAsyncCommandContext(uid, generation);
|
|
1377
|
+
await fn(context, ...args);
|
|
1378
|
+
});
|
|
1379
|
+
};
|
|
1380
|
+
return wrapped;
|
|
1381
|
+
},
|
|
1382
|
+
wrapSerialCommand(fn) {
|
|
1383
|
+
const wrapped = async (uid, ...args) => {
|
|
1384
|
+
await enqueueCommand(uid, async () => {
|
|
1385
|
+
if (!states[uid]) {
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
const generation = getGeneration(uid);
|
|
1389
|
+
const {
|
|
1390
|
+
newState,
|
|
1391
|
+
oldState
|
|
1392
|
+
} = states[uid];
|
|
1393
|
+
const newerState = await fn(newState, ...args);
|
|
1394
|
+
if (oldState === newerState || newState === newerState) {
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1397
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
const latestOld = states[uid];
|
|
1401
|
+
const latestNew = {
|
|
1402
|
+
...latestOld.newState,
|
|
1403
|
+
...newerState
|
|
1404
|
+
};
|
|
1405
|
+
states[uid] = {
|
|
1406
|
+
newState: latestNew,
|
|
1407
|
+
oldState: latestOld.oldState,
|
|
1408
|
+
scheduledState: latestNew
|
|
1409
|
+
};
|
|
1410
|
+
});
|
|
1411
|
+
};
|
|
1412
|
+
return wrapped;
|
|
1190
1413
|
}
|
|
1191
1414
|
};
|
|
1192
1415
|
};
|
|
@@ -1195,7 +1418,7 @@ const terminate = () => {
|
|
|
1195
1418
|
};
|
|
1196
1419
|
|
|
1197
1420
|
const rpcs = Object.create(null);
|
|
1198
|
-
const set$
|
|
1421
|
+
const set$6 = (id, rpc) => {
|
|
1199
1422
|
rpcs[id] = rpc;
|
|
1200
1423
|
};
|
|
1201
1424
|
const get$1 = id => {
|
|
@@ -1228,7 +1451,7 @@ const create$1 = rpcId => {
|
|
|
1228
1451
|
const mockRpc = createMockRpc({
|
|
1229
1452
|
commandMap
|
|
1230
1453
|
});
|
|
1231
|
-
set$
|
|
1454
|
+
set$6(rpcId, mockRpc);
|
|
1232
1455
|
// @ts-ignore
|
|
1233
1456
|
mockRpc[Symbol.dispose] = () => {
|
|
1234
1457
|
remove(rpcId);
|
|
@@ -1237,61 +1460,58 @@ const create$1 = rpcId => {
|
|
|
1237
1460
|
return mockRpc;
|
|
1238
1461
|
},
|
|
1239
1462
|
set(rpc) {
|
|
1240
|
-
set$
|
|
1463
|
+
set$6(rpcId, rpc);
|
|
1241
1464
|
}
|
|
1242
1465
|
};
|
|
1243
1466
|
};
|
|
1244
1467
|
|
|
1245
1468
|
const Text = 12;
|
|
1246
1469
|
|
|
1247
|
-
const EditorWorker
|
|
1470
|
+
const EditorWorker = 99;
|
|
1248
1471
|
const ExtensionHostWorker = 44;
|
|
1472
|
+
const ExtensionManagementWorker = 9006;
|
|
1249
1473
|
|
|
1250
1474
|
const SetFocusContext = 'Viewlet.setFocusContext';
|
|
1251
1475
|
|
|
1252
1476
|
const {
|
|
1253
|
-
invoke: invoke$
|
|
1477
|
+
invoke: invoke$2,
|
|
1254
1478
|
invokeAndTransfer,
|
|
1255
|
-
set: set$
|
|
1256
|
-
} = create$1(EditorWorker
|
|
1479
|
+
set: set$5
|
|
1480
|
+
} = create$1(EditorWorker);
|
|
1257
1481
|
const sendMessagePortToExtensionManagementWorker$1 = async port => {
|
|
1258
1482
|
await invokeAndTransfer('SendMessagePortToExtensionManagementWorker.sendMessagePortToExtensionManagementWorker', port, 0);
|
|
1259
1483
|
};
|
|
1484
|
+
const getLines$1 = async editorUid => {
|
|
1485
|
+
const lines = await invoke$2('Editor.getLines2', editorUid);
|
|
1486
|
+
return lines;
|
|
1487
|
+
};
|
|
1260
1488
|
const getWordAtOffset2$1 = async editorUid => {
|
|
1261
|
-
return invoke$
|
|
1489
|
+
return invoke$2('Editor.getWordAtOffset2', editorUid);
|
|
1262
1490
|
};
|
|
1263
1491
|
const getWordBefore$1 = async (editorUid, rowIndex, columnIndex) => {
|
|
1264
|
-
return invoke$
|
|
1492
|
+
return invoke$2('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
|
|
1265
1493
|
};
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
getWordAtOffset2: getWordAtOffset2$1,
|
|
1270
|
-
getWordBefore: getWordBefore$1,
|
|
1271
|
-
invoke: invoke$3,
|
|
1272
|
-
invokeAndTransfer,
|
|
1273
|
-
sendMessagePortToExtensionManagementWorker: sendMessagePortToExtensionManagementWorker$1,
|
|
1274
|
-
set: set$4
|
|
1494
|
+
const getUri$1 = async editorUid => {
|
|
1495
|
+
// @ts-ignore
|
|
1496
|
+
return invoke$2('Editor.getUri', editorUid);
|
|
1275
1497
|
};
|
|
1276
1498
|
|
|
1277
1499
|
const {
|
|
1278
|
-
|
|
1279
|
-
set: set$3
|
|
1500
|
+
set: set$4
|
|
1280
1501
|
} = create$1(ExtensionHostWorker);
|
|
1281
1502
|
|
|
1282
|
-
const ExtensionHost = {
|
|
1283
|
-
__proto__: null,
|
|
1284
|
-
invoke: invoke$2,
|
|
1285
|
-
set: set$3
|
|
1286
|
-
};
|
|
1287
|
-
|
|
1288
1503
|
const {
|
|
1289
|
-
getWordAtOffset2,
|
|
1290
|
-
getWordBefore,
|
|
1291
1504
|
invoke: invoke$1,
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1505
|
+
set: set$3
|
|
1506
|
+
} = create$1(ExtensionManagementWorker);
|
|
1507
|
+
|
|
1508
|
+
const getLines = (...args) => getLines$1(...args);
|
|
1509
|
+
const getUri = (...args) => getUri$1(...args);
|
|
1510
|
+
const getWordAtOffset2 = (...args) => getWordAtOffset2$1(...args);
|
|
1511
|
+
const getWordBefore = (...args) => getWordBefore$1(...args);
|
|
1512
|
+
const invoke = (...args) => invoke$2(...args);
|
|
1513
|
+
const sendMessagePortToExtensionManagementWorker = (...args) => sendMessagePortToExtensionManagementWorker$1(...args);
|
|
1514
|
+
const set$2 = (...args) => set$5(...args);
|
|
1295
1515
|
|
|
1296
1516
|
const FocusEditorHovers = 9;
|
|
1297
1517
|
const FocusEditorRename = 11;
|
|
@@ -1303,7 +1523,7 @@ const close = async state => {
|
|
|
1303
1523
|
editorUid
|
|
1304
1524
|
} = state;
|
|
1305
1525
|
// @ts-ignore
|
|
1306
|
-
await invoke
|
|
1526
|
+
await invoke('Editor.closeWidget2', editorUid, Hover, 'Hovers', FocusEditorHovers);
|
|
1307
1527
|
return state;
|
|
1308
1528
|
};
|
|
1309
1529
|
|
|
@@ -1470,7 +1690,7 @@ const sendMessagePortToExtensionHostWorker = async port => {
|
|
|
1470
1690
|
|
|
1471
1691
|
const createExtensionHostRpc = async () => {
|
|
1472
1692
|
try {
|
|
1473
|
-
const rpc = await create$
|
|
1693
|
+
const rpc = await create$5({
|
|
1474
1694
|
commandMap: {},
|
|
1475
1695
|
send: sendMessagePortToExtensionHostWorker
|
|
1476
1696
|
});
|
|
@@ -1480,10 +1700,7 @@ const createExtensionHostRpc = async () => {
|
|
|
1480
1700
|
}
|
|
1481
1701
|
};
|
|
1482
1702
|
|
|
1483
|
-
const
|
|
1484
|
-
invoke,
|
|
1485
|
-
set
|
|
1486
|
-
} = ExtensionHost;
|
|
1703
|
+
const set = (...args) => set$4(...args);
|
|
1487
1704
|
|
|
1488
1705
|
const initialize = async () => {
|
|
1489
1706
|
const rpc = await createExtensionHostRpc();
|
|
@@ -1508,9 +1725,8 @@ const getHoverDetails = async (hover, error, hoverFullWidth, hoverPaddingLeft, h
|
|
|
1508
1725
|
lineInfos: []
|
|
1509
1726
|
};
|
|
1510
1727
|
}
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1513
|
-
} = hover;
|
|
1728
|
+
const hoverText = typeof hover.text === 'string' && hover.text.trim() ? hover.text : '';
|
|
1729
|
+
const documentation = typeof hover.documentation === 'string' && hover.documentation.trim() ? hover.documentation : hoverText;
|
|
1514
1730
|
const lineInfos = await tokenizeCodeBlock();
|
|
1515
1731
|
const documentationHeight = await measureTextBlockHeight();
|
|
1516
1732
|
return {
|
|
@@ -1561,52 +1777,28 @@ const getOffsetAtCursor = editorUid => {
|
|
|
1561
1777
|
};
|
|
1562
1778
|
|
|
1563
1779
|
const getPositionAtCursor = async editorUid => {
|
|
1564
|
-
const position = await invoke
|
|
1780
|
+
const position = await invoke('Editor.getPositionAtCursor', editorUid);
|
|
1565
1781
|
return position;
|
|
1566
1782
|
};
|
|
1567
1783
|
|
|
1568
|
-
const
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
};
|
|
1577
|
-
|
|
1578
|
-
const execute = async ({
|
|
1579
|
-
args,
|
|
1580
|
-
editorLanguageId,
|
|
1581
|
-
editorUid,
|
|
1582
|
-
event,
|
|
1583
|
-
method,
|
|
1584
|
-
noProviderFoundMessage,
|
|
1585
|
-
noProviderFoundResult = undefined
|
|
1586
|
-
}) => {
|
|
1587
|
-
const fullEvent = `${event}:${editorLanguageId}`;
|
|
1588
|
-
await activateByEvent(fullEvent);
|
|
1589
|
-
const result = await invoke(method, editorUid, ...args);
|
|
1590
|
-
return result;
|
|
1784
|
+
const getTextDocument = async (editorUid, languageId) => {
|
|
1785
|
+
const [lines, uri] = await Promise.all([getLines(editorUid), getUri(editorUid)]);
|
|
1786
|
+
return {
|
|
1787
|
+
documentId: editorUid,
|
|
1788
|
+
languageId,
|
|
1789
|
+
text: lines.join('\n'),
|
|
1790
|
+
uri
|
|
1791
|
+
};
|
|
1591
1792
|
};
|
|
1592
|
-
|
|
1593
1793
|
const executeHoverProvider = async (editorUid, editorLanguageId, offset) => {
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
return execute({
|
|
1597
|
-
args: [offset],
|
|
1598
|
-
editorUid,
|
|
1599
|
-
event: OnHover,
|
|
1600
|
-
method: HoverExecute,
|
|
1601
|
-
noProviderFoundMessage: 'No hover provider found'
|
|
1602
|
-
});
|
|
1794
|
+
const textDocument = await getTextDocument(editorUid, editorLanguageId);
|
|
1795
|
+
return invoke$1('Extensions.executeHoverProvider', textDocument, offset);
|
|
1603
1796
|
};
|
|
1604
1797
|
|
|
1605
1798
|
const getHover = async (editorUid, editorLanguageId, offset) => {
|
|
1606
1799
|
try {
|
|
1607
1800
|
number(editorUid);
|
|
1608
1801
|
number(offset);
|
|
1609
|
-
// TODO invoke extension host worker directly
|
|
1610
1802
|
const hover = await executeHoverProvider(editorUid, editorLanguageId, offset);
|
|
1611
1803
|
return {
|
|
1612
1804
|
error: undefined,
|
|
@@ -1638,7 +1830,7 @@ const getEditorHoverInfo = async (editorUid, editorLanguageId, hoverFullWidth, h
|
|
|
1638
1830
|
const offset = getOffsetAtCursor();
|
|
1639
1831
|
|
|
1640
1832
|
// @ts-ignore
|
|
1641
|
-
const diagnostics = await invoke
|
|
1833
|
+
const diagnostics = await invoke('Editor.getDiagnostics', editorUid);
|
|
1642
1834
|
const wordPart = await getWordBefore(editorUid, rowIndex, columnIndex);
|
|
1643
1835
|
const wordStart = columnIndex - wordPart.length;
|
|
1644
1836
|
|
|
@@ -1655,6 +1847,9 @@ const getEditorHoverInfo = async (editorUid, editorLanguageId, hoverFullWidth, h
|
|
|
1655
1847
|
hover
|
|
1656
1848
|
} = await getHover(editorUid, editorLanguageId, offset);
|
|
1657
1849
|
if (!hover) {
|
|
1850
|
+
if (matchingDiagnostics.length === 0) {
|
|
1851
|
+
return undefined;
|
|
1852
|
+
}
|
|
1658
1853
|
return {
|
|
1659
1854
|
documentation: '',
|
|
1660
1855
|
lineInfos: [],
|
|
@@ -1667,6 +1862,9 @@ const getEditorHoverInfo = async (editorUid, editorLanguageId, hoverFullWidth, h
|
|
|
1667
1862
|
documentation,
|
|
1668
1863
|
lineInfos
|
|
1669
1864
|
} = await getHoverDetails(hover, error);
|
|
1865
|
+
if (!documentation && lineInfos.length === 0 && matchingDiagnostics.length === 0) {
|
|
1866
|
+
return undefined;
|
|
1867
|
+
}
|
|
1670
1868
|
return {
|
|
1671
1869
|
documentation,
|
|
1672
1870
|
lineInfos,
|
|
@@ -1689,15 +1887,16 @@ const loadContent = async state => {
|
|
|
1689
1887
|
} = await getPositionAtCursor(editorUid);
|
|
1690
1888
|
const info = await getEditorHoverInfo(editorUid, editorLanguageId);
|
|
1691
1889
|
if (!info) {
|
|
1692
|
-
return
|
|
1693
|
-
...state
|
|
1694
|
-
};
|
|
1890
|
+
return close(state);
|
|
1695
1891
|
}
|
|
1696
1892
|
const {
|
|
1697
1893
|
documentation,
|
|
1698
1894
|
lineInfos,
|
|
1699
1895
|
matchingDiagnostics
|
|
1700
1896
|
} = info;
|
|
1897
|
+
if (!documentation && lineInfos.length === 0 && matchingDiagnostics.length === 0) {
|
|
1898
|
+
return close(state);
|
|
1899
|
+
}
|
|
1701
1900
|
return {
|
|
1702
1901
|
...state,
|
|
1703
1902
|
documentation,
|
|
@@ -1831,9 +2030,14 @@ const sash = {
|
|
|
1831
2030
|
};
|
|
1832
2031
|
const getChildCount = (lineInfos, documentation, diagnostics) => {
|
|
1833
2032
|
const diagnosticsCount = diagnostics && diagnostics.length > 0 ? 1 : 0;
|
|
1834
|
-
|
|
2033
|
+
const lineInfosCount = lineInfos.length > 0 ? 1 : 0;
|
|
2034
|
+
const documentationCount = documentation ? 1 : 0;
|
|
2035
|
+
return lineInfosCount + documentationCount + diagnosticsCount;
|
|
1835
2036
|
};
|
|
1836
2037
|
const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
|
|
2038
|
+
if (lineInfos.length === 0 && !documentation && diagnostics.length === 0) {
|
|
2039
|
+
return [];
|
|
2040
|
+
}
|
|
1837
2041
|
const dom = [];
|
|
1838
2042
|
dom.push({
|
|
1839
2043
|
childCount: getChildCount(lineInfos, documentation, diagnostics) + 1,
|
|
@@ -1938,11 +2142,23 @@ const commandMap = {
|
|
|
1938
2142
|
'Hover.terminate': terminate
|
|
1939
2143
|
};
|
|
1940
2144
|
|
|
2145
|
+
const send = async port => {
|
|
2146
|
+
await sendMessagePortToExtensionManagementWorker(port);
|
|
2147
|
+
};
|
|
2148
|
+
const initializeExtensionManagementWorker = async () => {
|
|
2149
|
+
const rpc = await create$4({
|
|
2150
|
+
commandMap: commandMap,
|
|
2151
|
+
send
|
|
2152
|
+
});
|
|
2153
|
+
set$3(rpc);
|
|
2154
|
+
};
|
|
2155
|
+
|
|
1941
2156
|
const listen = async () => {
|
|
1942
2157
|
const rpc = await create$3({
|
|
1943
2158
|
commandMap: commandMap
|
|
1944
2159
|
});
|
|
1945
2160
|
set$2(rpc);
|
|
2161
|
+
await initializeExtensionManagementWorker();
|
|
1946
2162
|
};
|
|
1947
2163
|
|
|
1948
2164
|
const main = async () => {
|