@lvce-editor/hover-worker 1.5.0 → 2.1.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.
@@ -225,8 +225,8 @@ const getModuleNotFoundError = stderr => {
225
225
  const messageIndex = lines.findIndex(isModuleNotFoundMessage);
226
226
  const message = lines[messageIndex];
227
227
  return {
228
- message,
229
- code: ERR_MODULE_NOT_FOUND
228
+ code: ERR_MODULE_NOT_FOUND,
229
+ message
230
230
  };
231
231
  };
232
232
  const isModuleNotFoundError = stderr => {
@@ -249,14 +249,14 @@ const isUnhelpfulNativeModuleError = stderr => {
249
249
  const getNativeModuleErrorMessage = stderr => {
250
250
  const message = getMessageCodeBlock(stderr);
251
251
  return {
252
- message: `Incompatible native node module: ${message}`,
253
- code: E_INCOMPATIBLE_NATIVE_MODULE
252
+ code: E_INCOMPATIBLE_NATIVE_MODULE,
253
+ message: `Incompatible native node module: ${message}`
254
254
  };
255
255
  };
256
256
  const getModuleSyntaxError = () => {
257
257
  return {
258
- message: `ES Modules are not supported in electron`,
259
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
258
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
259
+ message: `ES Modules are not supported in electron`
260
260
  };
261
261
  };
262
262
  const getHelpfulChildProcessError = (stdout, stderr) => {
@@ -275,8 +275,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
275
275
  rest
276
276
  } = getDetails(lines);
277
277
  return {
278
- message: actualMessage,
279
278
  code: '',
279
+ message: actualMessage,
280
280
  stack: rest
281
281
  };
282
282
  };
@@ -286,8 +286,8 @@ class IpcError extends VError {
286
286
  if (stdout || stderr) {
287
287
  // @ts-ignore
288
288
  const {
289
- message,
290
289
  code,
290
+ message,
291
291
  stack
292
292
  } = getHelpfulChildProcessError(stdout, stderr);
293
293
  const cause = new Error(message);
@@ -348,8 +348,8 @@ const wrap$f = global => {
348
348
  };
349
349
  const waitForFirstMessage = async port => {
350
350
  const {
351
- resolve,
352
- promise
351
+ promise,
352
+ resolve
353
353
  } = Promise.withResolvers();
354
354
  port.addEventListener('message', resolve, {
355
355
  once: true
@@ -369,8 +369,8 @@ const listen$6 = async () => {
369
369
  const type = firstMessage.params[0];
370
370
  if (type === 'message-port') {
371
371
  parentIpc.send({
372
- jsonrpc: '2.0',
373
372
  id: firstMessage.id,
373
+ jsonrpc: '2.0',
374
374
  result: null
375
375
  });
376
376
  parentIpc.dispose();
@@ -427,8 +427,8 @@ const removeListener = (emitter, type, callback) => {
427
427
  };
428
428
  const getFirstEvent = (eventEmitter, eventMap) => {
429
429
  const {
430
- resolve,
431
- promise
430
+ promise,
431
+ resolve
432
432
  } = Promise.withResolvers();
433
433
  const listenerMap = Object.create(null);
434
434
  const cleanup = value => {
@@ -440,8 +440,8 @@ const getFirstEvent = (eventEmitter, eventMap) => {
440
440
  for (const [event, type] of Object.entries(eventMap)) {
441
441
  const listener = event => {
442
442
  cleanup({
443
- type,
444
- event
443
+ event,
444
+ type
445
445
  });
446
446
  };
447
447
  addListener(eventEmitter, event, listener);
@@ -450,9 +450,9 @@ const getFirstEvent = (eventEmitter, eventMap) => {
450
450
  return promise;
451
451
  };
452
452
  const Message$1 = 3;
453
- const create$5$1 = async ({
454
- messagePort,
455
- isMessagePortOpen
453
+ const create$5 = async ({
454
+ isMessagePortOpen,
455
+ messagePort
456
456
  }) => {
457
457
  if (!isMessagePort(messagePort)) {
458
458
  throw new IpcError('port must be of type MessagePort');
@@ -465,8 +465,8 @@ const create$5$1 = async ({
465
465
  });
466
466
  messagePort.start();
467
467
  const {
468
- type,
469
- event
468
+ event,
469
+ type
470
470
  } = await eventPromise;
471
471
  if (type !== Message$1) {
472
472
  throw new IpcError('Failed to wait for ipc message');
@@ -501,61 +501,19 @@ const wrap$5 = messagePort => {
501
501
  };
502
502
  const IpcParentWithMessagePort$1 = {
503
503
  __proto__: null,
504
- create: create$5$1,
504
+ create: create$5,
505
505
  signal: signal$1,
506
506
  wrap: wrap$5
507
507
  };
508
508
 
509
- const Two = '2.0';
510
- const create$4$1 = (method, params) => {
511
- return {
512
- jsonrpc: Two,
513
- method,
514
- params
515
- };
516
- };
509
+ const Two$1 = '2.0';
517
510
  const callbacks = Object.create(null);
518
- const set$6 = (id, fn) => {
519
- callbacks[id] = fn;
520
- };
521
511
  const get$2 = id => {
522
512
  return callbacks[id];
523
513
  };
524
- const remove = id => {
514
+ const remove$1 = id => {
525
515
  delete callbacks[id];
526
516
  };
527
- let id = 0;
528
- const create$3$1 = () => {
529
- return ++id;
530
- };
531
- const registerPromise = () => {
532
- const id = create$3$1();
533
- const {
534
- resolve,
535
- promise
536
- } = Promise.withResolvers();
537
- set$6(id, resolve);
538
- return {
539
- id,
540
- promise
541
- };
542
- };
543
- const create$2$1 = (method, params) => {
544
- const {
545
- id,
546
- promise
547
- } = registerPromise();
548
- const message = {
549
- jsonrpc: Two,
550
- method,
551
- params,
552
- id
553
- };
554
- return {
555
- message,
556
- promise
557
- };
558
- };
559
517
  class JsonRpcError extends Error {
560
518
  constructor(message) {
561
519
  super(message);
@@ -706,7 +664,7 @@ const resolve = (id, response) => {
706
664
  return;
707
665
  }
708
666
  fn(response);
709
- remove(id);
667
+ remove$1(id);
710
668
  };
711
669
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
712
670
  const getErrorType = prettyError => {
@@ -749,9 +707,9 @@ const getErrorProperty = (error, prettyError) => {
749
707
  }
750
708
  };
751
709
  };
752
- const create$1$1 = (id, error) => {
710
+ const create$1$2 = (id, error) => {
753
711
  return {
754
- jsonrpc: Two,
712
+ jsonrpc: Two$1,
755
713
  id,
756
714
  error
757
715
  };
@@ -760,22 +718,22 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
760
718
  const prettyError = preparePrettyError(error);
761
719
  logError(error, prettyError);
762
720
  const errorProperty = getErrorProperty(error, prettyError);
763
- return create$1$1(id, errorProperty);
721
+ return create$1$2(id, errorProperty);
764
722
  };
765
- const create$6 = (message, result) => {
723
+ const create$3 = (message, result) => {
766
724
  return {
767
- jsonrpc: Two,
725
+ jsonrpc: Two$1,
768
726
  id: message.id,
769
727
  result: result ?? null
770
728
  };
771
729
  };
772
730
  const getSuccessResponse = (message, result) => {
773
731
  const resultProperty = result ?? null;
774
- return create$6(message, resultProperty);
732
+ return create$3(message, resultProperty);
775
733
  };
776
734
  const getErrorResponseSimple = (id, error) => {
777
735
  return {
778
- jsonrpc: Two,
736
+ jsonrpc: Two$1,
779
737
  id,
780
738
  error: {
781
739
  code: Custom,
@@ -862,29 +820,6 @@ const handleJsonRpcMessage = async (...args) => {
862
820
  }
863
821
  throw new JsonRpcError('unexpected message');
864
822
  };
865
- const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
866
- const {
867
- message,
868
- promise
869
- } = create$2$1(method, params);
870
- if (useSendAndTransfer && ipc.sendAndTransfer) {
871
- ipc.sendAndTransfer(message);
872
- } else {
873
- ipc.send(message);
874
- }
875
- const responseMessage = await promise;
876
- return unwrapJsonRpcResult(responseMessage);
877
- };
878
- const send = (transport, method, ...params) => {
879
- const message = create$4$1(method, params);
880
- transport.send(message);
881
- };
882
- const invoke$4 = (ipc, method, ...params) => {
883
- return invokeHelper(ipc, method, params, false);
884
- };
885
- const invokeAndTransfer$3 = (ipc, method, ...params) => {
886
- return invokeHelper(ipc, method, params, true);
887
- };
888
823
 
889
824
  class CommandNotFoundError extends Error {
890
825
  constructor(command) {
@@ -907,24 +842,87 @@ const execute$1 = (command, ...args) => {
907
842
  return fn(...args);
908
843
  };
909
844
 
845
+ const Two = '2.0';
846
+ const create$s = (method, params) => {
847
+ return {
848
+ jsonrpc: Two,
849
+ method,
850
+ params
851
+ };
852
+ };
853
+ const create$r = (id, method, params) => {
854
+ const message = {
855
+ id,
856
+ jsonrpc: Two,
857
+ method,
858
+ params
859
+ };
860
+ return message;
861
+ };
862
+ let id = 0;
863
+ const create$q = () => {
864
+ return ++id;
865
+ };
866
+
867
+ /* eslint-disable n/no-unsupported-features/es-syntax */
868
+
869
+ const registerPromise = map => {
870
+ const id = create$q();
871
+ const {
872
+ promise,
873
+ resolve
874
+ } = Promise.withResolvers();
875
+ map[id] = resolve;
876
+ return {
877
+ id,
878
+ promise
879
+ };
880
+ };
881
+
882
+ // @ts-ignore
883
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
884
+ const {
885
+ id,
886
+ promise
887
+ } = registerPromise(callbacks);
888
+ const message = create$r(id, method, params);
889
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
890
+ ipc.sendAndTransfer(message);
891
+ } else {
892
+ ipc.send(message);
893
+ }
894
+ const responseMessage = await promise;
895
+ return unwrapJsonRpcResult(responseMessage);
896
+ };
910
897
  const createRpc = ipc => {
898
+ const callbacks = Object.create(null);
899
+ ipc._resolve = (id, response) => {
900
+ const fn = callbacks[id];
901
+ if (!fn) {
902
+ console.warn(`callback ${id} may already be disposed`);
903
+ return;
904
+ }
905
+ fn(response);
906
+ delete callbacks[id];
907
+ };
911
908
  const rpc = {
909
+ async dispose() {
910
+ await ipc?.dispose();
911
+ },
912
+ invoke(method, ...params) {
913
+ return invokeHelper(callbacks, ipc, method, params, false);
914
+ },
915
+ invokeAndTransfer(method, ...params) {
916
+ return invokeHelper(callbacks, ipc, method, params, true);
917
+ },
912
918
  // @ts-ignore
913
919
  ipc,
914
920
  /**
915
921
  * @deprecated
916
922
  */
917
923
  send(method, ...params) {
918
- send(ipc, method, ...params);
919
- },
920
- invoke(method, ...params) {
921
- return invoke$4(ipc, method, ...params);
922
- },
923
- invokeAndTransfer(method, ...params) {
924
- return invokeAndTransfer$3(ipc, method, ...params);
925
- },
926
- async dispose() {
927
- await ipc?.dispose();
924
+ const message = create$s(method, params);
925
+ ipc.send(message);
928
926
  }
929
927
  };
930
928
  return rpc;
@@ -941,7 +939,7 @@ const logError = () => {
941
939
  const handleMessage = event => {
942
940
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
943
941
  const actualExecute = event?.target?.execute || execute$1;
944
- return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
942
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
945
943
  };
946
944
  const handleIpc = ipc => {
947
945
  if ('addEventListener' in ipc) {
@@ -959,15 +957,16 @@ const listen$1 = async (module, options) => {
959
957
  const ipc = module.wrap(rawIpc);
960
958
  return ipc;
961
959
  };
962
- const create$5 = async ({
960
+ const create$4 = async ({
963
961
  commandMap,
962
+ isMessagePortOpen = true,
964
963
  messagePort
965
964
  }) => {
966
965
  // TODO create a commandMap per rpc instance
967
966
  register(commandMap);
968
967
  const rawIpc = await IpcParentWithMessagePort$1.create({
969
- messagePort,
970
- isMessagePortOpen: true
968
+ isMessagePortOpen,
969
+ messagePort
971
970
  });
972
971
  const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
973
972
  handleIpc(ipc);
@@ -975,20 +974,27 @@ const create$5 = async ({
975
974
  messagePort.start();
976
975
  return rpc;
977
976
  };
978
- const create$4 = async ({
977
+ const create$2$1 = async ({
979
978
  commandMap,
980
- messagePort
979
+ isMessagePortOpen,
980
+ send
981
981
  }) => {
982
- return create$5({
982
+ const {
983
+ port1,
984
+ port2
985
+ } = new MessageChannel();
986
+ await send(port1);
987
+ return create$4({
983
988
  commandMap,
984
- messagePort
989
+ isMessagePortOpen,
990
+ messagePort: port2
985
991
  });
986
992
  };
987
- const PlainMessagePortRpcParent = {
993
+ const TransferMessagePortRpcParent = {
988
994
  __proto__: null,
989
- create: create$4
995
+ create: create$2$1
990
996
  };
991
- const create$3 = async ({
997
+ const create$1$1 = async ({
992
998
  commandMap
993
999
  }) => {
994
1000
  // TODO create a commandMap per rpc instance
@@ -1000,7 +1006,7 @@ const create$3 = async ({
1000
1006
  };
1001
1007
  const WebWorkerRpcClient = {
1002
1008
  __proto__: null,
1003
- create: create$3
1009
+ create: create$1$1
1004
1010
  };
1005
1011
  const createMockRpc = ({
1006
1012
  commandMap
@@ -1015,13 +1021,98 @@ const createMockRpc = ({
1015
1021
  return command(...params);
1016
1022
  };
1017
1023
  const mockRpc = {
1024
+ invocations,
1018
1025
  invoke,
1019
- invokeAndTransfer: invoke,
1020
- invocations
1026
+ invokeAndTransfer: invoke
1021
1027
  };
1022
1028
  return mockRpc;
1023
1029
  };
1024
1030
 
1031
+ const toCommandId = key => {
1032
+ const dotIndex = key.indexOf('.');
1033
+ return key.slice(dotIndex + 1);
1034
+ };
1035
+ const create$2 = () => {
1036
+ const states = Object.create(null);
1037
+ const commandMapRef = {};
1038
+ return {
1039
+ get(uid) {
1040
+ return states[uid];
1041
+ },
1042
+ set(uid, oldState, newState) {
1043
+ states[uid] = {
1044
+ oldState,
1045
+ newState
1046
+ };
1047
+ },
1048
+ dispose(uid) {
1049
+ delete states[uid];
1050
+ },
1051
+ getKeys() {
1052
+ return Object.keys(states).map(key => {
1053
+ return Number.parseInt(key);
1054
+ });
1055
+ },
1056
+ clear() {
1057
+ for (const key of Object.keys(states)) {
1058
+ delete states[key];
1059
+ }
1060
+ },
1061
+ wrapCommand(fn) {
1062
+ const wrapped = async (uid, ...args) => {
1063
+ const {
1064
+ oldState,
1065
+ newState
1066
+ } = states[uid];
1067
+ const newerState = await fn(newState, ...args);
1068
+ if (oldState === newerState || newState === newerState) {
1069
+ return;
1070
+ }
1071
+ const latest = states[uid];
1072
+ states[uid] = {
1073
+ oldState: latest.oldState,
1074
+ newState: newerState
1075
+ };
1076
+ };
1077
+ return wrapped;
1078
+ },
1079
+ wrapGetter(fn) {
1080
+ const wrapped = (uid, ...args) => {
1081
+ const {
1082
+ newState
1083
+ } = states[uid];
1084
+ return fn(newState, ...args);
1085
+ };
1086
+ return wrapped;
1087
+ },
1088
+ diff(uid, modules, numbers) {
1089
+ const {
1090
+ oldState,
1091
+ newState
1092
+ } = states[uid];
1093
+ const diffResult = [];
1094
+ for (let i = 0; i < modules.length; i++) {
1095
+ const fn = modules[i];
1096
+ if (!fn(oldState, newState)) {
1097
+ diffResult.push(numbers[i]);
1098
+ }
1099
+ }
1100
+ return diffResult;
1101
+ },
1102
+ getCommandIds() {
1103
+ const keys = Object.keys(commandMapRef);
1104
+ const ids = keys.map(toCommandId);
1105
+ return ids;
1106
+ },
1107
+ registerCommands(commandMap) {
1108
+ Object.assign(commandMapRef, commandMap);
1109
+ }
1110
+ };
1111
+ };
1112
+ const terminate = () => {
1113
+ globalThis.close();
1114
+ };
1115
+
1025
1116
  const Text = 12;
1026
1117
 
1027
1118
  const EditorWorker$1 = 99;
@@ -1036,9 +1127,17 @@ const set$5 = (id, rpc) => {
1036
1127
  const get$1 = id => {
1037
1128
  return rpcs[id];
1038
1129
  };
1130
+ const remove = id => {
1131
+ delete rpcs[id];
1132
+ };
1039
1133
 
1040
- const create$2 = rpcId => {
1134
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1135
+ const create$1 = rpcId => {
1041
1136
  return {
1137
+ async dispose() {
1138
+ const rpc = get$1(rpcId);
1139
+ await rpc.dispose();
1140
+ },
1042
1141
  // @ts-ignore
1043
1142
  invoke(method, ...params) {
1044
1143
  const rpc = get$1(rpcId);
@@ -1051,25 +1150,34 @@ const create$2 = rpcId => {
1051
1150
  // @ts-ignore
1052
1151
  return rpc.invokeAndTransfer(method, ...params);
1053
1152
  },
1153
+ registerMockRpc(commandMap) {
1154
+ const mockRpc = createMockRpc({
1155
+ commandMap
1156
+ });
1157
+ set$5(rpcId, mockRpc);
1158
+ // @ts-ignore
1159
+ mockRpc[Symbol.dispose] = () => {
1160
+ remove(rpcId);
1161
+ };
1162
+ // @ts-ignore
1163
+ return mockRpc;
1164
+ },
1054
1165
  set(rpc) {
1055
1166
  set$5(rpcId, rpc);
1056
- },
1057
- async dispose() {
1058
- const rpc = get$1(rpcId);
1059
- await rpc.dispose();
1060
1167
  }
1061
1168
  };
1062
1169
  };
1063
1170
 
1064
1171
  const {
1172
+ dispose: dispose$3,
1065
1173
  invoke: invoke$3,
1066
- invokeAndTransfer: invokeAndTransfer$2,
1067
- set: set$4,
1068
- dispose: dispose$3
1069
- } = create$2(EditorWorker$1);
1070
- const sendMessagePortToExtensionHostWorker$1 = async port => {
1174
+ invokeAndTransfer: invokeAndTransfer$1,
1175
+ registerMockRpc: registerMockRpc$1,
1176
+ set: set$4
1177
+ } = create$1(EditorWorker$1);
1178
+ const sendMessagePortToExtensionHostWorker$2 = async port => {
1071
1179
  const command = 'HandleMessagePort.handleMessagePort2';
1072
- await invokeAndTransfer$2(
1180
+ await invokeAndTransfer$1(
1073
1181
  // @ts-ignore
1074
1182
  'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0);
1075
1183
  };
@@ -1082,6 +1190,10 @@ const applyEdit = async (editorUid, changes) => {
1082
1190
  // @ts-ignore
1083
1191
  await invoke$3('Editor.applyEdit2', editorUid, changes);
1084
1192
  };
1193
+ const applyDocumentEdits = async (editorUid, changes) => {
1194
+ // @ts-ignore
1195
+ await invoke$3('Editor.applyDocumentEdits', editorUid, changes);
1196
+ };
1085
1197
  const applyWorkspaceEdit = async (editorUid, changes) => {
1086
1198
  // @ts-ignore
1087
1199
  await invoke$3('Editor.applyWorkspaceEdit', editorUid, changes);
@@ -1114,7 +1226,10 @@ const getSelections = async editorUid => {
1114
1226
  const getWordAtOffset2$1 = async editorUid => {
1115
1227
  return invoke$3('Editor.getWordAtOffset2', editorUid);
1116
1228
  };
1117
- const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
1229
+ const closeFind2 = async editorUid => {
1230
+ return invoke$3('Editor.closeFind2', editorUid);
1231
+ };
1232
+ const getWordBefore$1 = async (editorUid, rowIndex, columnIndex) => {
1118
1233
  return invoke$3('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1119
1234
  };
1120
1235
  const updateDebugInfo = async info => {
@@ -1132,19 +1247,14 @@ const getProblems = async () => {
1132
1247
  // @ts-ignore
1133
1248
  return invoke$3('Editor.getProblems');
1134
1249
  };
1135
- const registerMockRpc$1 = commandMap => {
1136
- const mockRpc = createMockRpc({
1137
- commandMap
1138
- });
1139
- set$4(mockRpc);
1140
- return mockRpc;
1141
- };
1142
1250
 
1143
1251
  const EditorWorker = {
1144
1252
  __proto__: null,
1145
1253
  activateByEvent: activateByEvent$1,
1254
+ applyDocumentEdits,
1146
1255
  applyEdit,
1147
1256
  applyWorkspaceEdit,
1257
+ closeFind2,
1148
1258
  closeWidget,
1149
1259
  dispose: dispose$3,
1150
1260
  getLanguageId,
@@ -1156,21 +1266,22 @@ const EditorWorker = {
1156
1266
  getUri,
1157
1267
  getWordAt,
1158
1268
  getWordAtOffset2: getWordAtOffset2$1,
1159
- getWordBefore,
1269
+ getWordBefore: getWordBefore$1,
1160
1270
  invoke: invoke$3,
1161
- invokeAndTransfer: invokeAndTransfer$2,
1271
+ invokeAndTransfer: invokeAndTransfer$1,
1162
1272
  registerMockRpc: registerMockRpc$1,
1163
- sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1273
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$2,
1164
1274
  set: set$4,
1165
1275
  updateDebugInfo
1166
1276
  };
1167
1277
 
1168
1278
  const {
1279
+ dispose: dispose$2,
1169
1280
  invoke: invoke$2,
1170
- invokeAndTransfer: invokeAndTransfer$1,
1171
- set: set$3,
1172
- dispose: dispose$2
1173
- } = create$2(ExtensionHostWorker);
1281
+ invokeAndTransfer,
1282
+ registerMockRpc,
1283
+ set: set$3
1284
+ } = create$1(ExtensionHostWorker);
1174
1285
  const executeReferenceProvider = async (id, offset) => {
1175
1286
  // @ts-ignore
1176
1287
  return invoke$2('ExtensionHostReference.executeReferenceProvider', id, offset);
@@ -1183,12 +1294,9 @@ const getRuntimeStatus = async extensionId => {
1183
1294
  // @ts-ignore
1184
1295
  return invoke$2('ExtensionHost.getRuntimeStatus', extensionId);
1185
1296
  };
1186
- const registerMockRpc = commandMap => {
1187
- const mockRpc = createMockRpc({
1188
- commandMap
1189
- });
1190
- set$3(mockRpc);
1191
- return mockRpc;
1297
+ const getEnabledOutputProviderIds = async () => {
1298
+ const channels = await invoke$2('Output.getEnabledProviders');
1299
+ return channels;
1192
1300
  };
1193
1301
 
1194
1302
  const ExtensionHost = {
@@ -1196,18 +1304,20 @@ const ExtensionHost = {
1196
1304
  dispose: dispose$2,
1197
1305
  executeFileReferenceProvider,
1198
1306
  executeReferenceProvider,
1307
+ getEnabledOutputProviderIds,
1199
1308
  getRuntimeStatus,
1200
1309
  invoke: invoke$2,
1201
- invokeAndTransfer: invokeAndTransfer$1,
1310
+ invokeAndTransfer,
1202
1311
  registerMockRpc,
1203
1312
  set: set$3
1204
1313
  };
1205
1314
 
1206
1315
  const {
1316
+ getWordAtOffset2,
1317
+ getWordBefore,
1207
1318
  invoke: invoke$1,
1208
- set: set$2,
1209
- invokeAndTransfer,
1210
- getWordAtOffset2
1319
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1320
+ set: set$2
1211
1321
  } = EditorWorker;
1212
1322
 
1213
1323
  const FocusEditorHovers = 9;
@@ -1224,119 +1334,39 @@ const close = async state => {
1224
1334
  return state;
1225
1335
  };
1226
1336
 
1227
- const toCommandId = key => {
1228
- const dotIndex = key.indexOf('.');
1229
- return key.slice(dotIndex + 1);
1230
- };
1231
- const create$1 = () => {
1232
- const states = Object.create(null);
1233
- const commandMapRef = {};
1234
- return {
1235
- get(uid) {
1236
- return states[uid];
1237
- },
1238
- set(uid, oldState, newState) {
1239
- states[uid] = {
1240
- oldState,
1241
- newState
1242
- };
1243
- },
1244
- dispose(uid) {
1245
- delete states[uid];
1246
- },
1247
- getKeys() {
1248
- return Object.keys(states).map(key => {
1249
- return Number.parseInt(key);
1250
- });
1251
- },
1252
- clear() {
1253
- for (const key of Object.keys(states)) {
1254
- delete states[key];
1255
- }
1256
- },
1257
- wrapCommand(fn) {
1258
- const wrapped = async (uid, ...args) => {
1259
- const {
1260
- newState
1261
- } = states[uid];
1262
- const newerState = await fn(newState, ...args);
1263
- if (newState === newerState) {
1264
- return;
1265
- }
1266
- const latest = states[uid];
1267
- states[uid] = {
1268
- oldState: latest.oldState,
1269
- newState: newerState
1270
- };
1271
- };
1272
- return wrapped;
1273
- },
1274
- wrapGetter(fn) {
1275
- const wrapped = (uid, ...args) => {
1276
- const {
1277
- newState
1278
- } = states[uid];
1279
- return fn(newState, ...args);
1280
- };
1281
- return wrapped;
1282
- },
1283
- diff(uid, modules, numbers) {
1284
- const {
1285
- oldState,
1286
- newState
1287
- } = states[uid];
1288
- const diffResult = [];
1289
- for (let i = 0; i < modules.length; i++) {
1290
- const fn = modules[i];
1291
- if (!fn(oldState, newState)) {
1292
- diffResult.push(numbers[i]);
1293
- }
1294
- }
1295
- return diffResult;
1296
- },
1297
- getCommandIds() {
1298
- const keys = Object.keys(commandMapRef);
1299
- const ids = keys.map(toCommandId);
1300
- return ids;
1301
- },
1302
- registerCommands(commandMap) {
1303
- Object.assign(commandMapRef, commandMap);
1304
- }
1305
- };
1306
- };
1307
-
1308
1337
  const {
1338
+ dispose: dispose$1,
1309
1339
  get,
1310
1340
  set: set$1,
1311
- wrapCommand,
1312
- dispose: dispose$1
1313
- } = create$1();
1341
+ wrapCommand
1342
+ } = create$2();
1314
1343
 
1315
1344
  const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1316
1345
  const state = {
1317
- uid,
1318
- focusedIndex: -1,
1319
- x: 0,
1320
- y: 0,
1321
- width: 0,
1322
- height: 0,
1323
- focused: false,
1324
- leadingWord: '',
1325
- version: 0,
1326
- editorUid,
1346
+ documentation: '',
1327
1347
  editorLanguageId,
1348
+ editorUid,
1328
1349
  fallbackDisplayStringLanguageId: 'typescript',
1329
- hoverDocumentationFontSize: 15,
1330
- hoverDocumentationFontFamily: 'Fira Code',
1331
- hoverDocumentationLineHeight: '1.33333',
1350
+ focused: false,
1351
+ focusedIndex: -1,
1352
+ height: 0,
1332
1353
  hoverBorderLeft: 1,
1333
1354
  hoverBorderRight: 1,
1355
+ hoverDocumentationFontFamily: 'Fira Code',
1356
+ // TODO make it configurable
1357
+ hoverDocumentationFontSize: 15,
1358
+ hoverDocumentationLineHeight: '1.33333',
1359
+ hoverFullWidth: 400,
1334
1360
  hoverPaddingLeft: 8,
1335
1361
  hoverPaddingRight: 8,
1336
- hoverFullWidth: 400,
1337
- documentation: '',
1362
+ leadingWord: '',
1338
1363
  lineInfos: [],
1339
- matchingDiagnostics: []
1364
+ matchingDiagnostics: [],
1365
+ uid,
1366
+ version: 0,
1367
+ width: 0,
1368
+ x: 0,
1369
+ y: 0
1340
1370
  };
1341
1371
  set$1(uid, state, state);
1342
1372
  };
@@ -1384,8 +1414,8 @@ const diff = (oldState, newState) => {
1384
1414
 
1385
1415
  const diff2 = uid => {
1386
1416
  const {
1387
- oldState,
1388
- newState
1417
+ newState,
1418
+ oldState
1389
1419
  } = get(uid);
1390
1420
  const diffResult = diff(oldState, newState);
1391
1421
  return diffResult;
@@ -1413,8 +1443,8 @@ const CtrlCmd = 1 << 11 >>> 0;
1413
1443
 
1414
1444
  const getCommand = shortId => {
1415
1445
  return {
1416
- command: 'Editor.executeWidgetCommand',
1417
- args: ['Hovers', `Hovers.${shortId}`, 0, Hover]
1446
+ args: ['Hovers', `Hovers.${shortId}`, 0, Hover],
1447
+ command: 'Editor.executeWidgetCommand'
1418
1448
  };
1419
1449
  };
1420
1450
  const getKeyBindings = () => {
@@ -1461,36 +1491,16 @@ const handleSashPointerUp = (state, eventX, eventY) => {
1461
1491
  return state;
1462
1492
  };
1463
1493
 
1464
- const getPortTuple = () => {
1465
- const {
1466
- port1,
1467
- port2
1468
- } = new MessageChannel();
1469
- return {
1470
- port1,
1471
- port2
1472
- };
1473
- };
1474
-
1475
1494
  const sendMessagePortToExtensionHostWorker = async port => {
1476
- const command = 'HandleMessagePort.handleMessagePort2';
1477
1495
  // @ts-ignore
1478
- await invokeAndTransfer(
1479
- // @ts-ignore
1480
- 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0 // TODO
1481
- );
1496
+ await sendMessagePortToExtensionHostWorker$1(port);
1482
1497
  };
1483
1498
 
1484
1499
  const createExtensionHostRpc = async () => {
1485
1500
  try {
1486
- const {
1487
- port1,
1488
- port2
1489
- } = getPortTuple();
1490
- await sendMessagePortToExtensionHostWorker(port2);
1491
- const rpc = await PlainMessagePortRpcParent.create({
1501
+ const rpc = await TransferMessagePortRpcParent.create({
1492
1502
  commandMap: {},
1493
- messagePort: port1
1503
+ send: sendMessagePortToExtensionHostWorker
1494
1504
  });
1495
1505
  return rpc;
1496
1506
  } catch (error) {
@@ -1508,6 +1518,36 @@ const initialize = async () => {
1508
1518
  set(rpc);
1509
1519
  };
1510
1520
 
1521
+ const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
1522
+ // TODO ask editor worker or renderer process
1523
+ return 100;
1524
+ };
1525
+
1526
+ const tokenizeCodeBlock = async (codeBlock, languageId, tokenizerPath) => {
1527
+ // TODO maybe use syntax highlighting worker for this or another worker
1528
+ return [];
1529
+ };
1530
+
1531
+ const getHoverDetails = async (hover, error, hoverFullWidth, hoverPaddingLeft, hoverPaddingRight, hoverBorderLeft, hoverBorderRight, hoverDocumentationFontFamily, hoverDocumentationFontSize, hoverDocumentationLineHeight, fallbackDisplayStringLanguageId) => {
1532
+ if (error) {
1533
+ return {
1534
+ documentation: '',
1535
+ documentationHeight: 0,
1536
+ lineInfos: []
1537
+ };
1538
+ }
1539
+ const {
1540
+ documentation
1541
+ } = hover;
1542
+ const lineInfos = await tokenizeCodeBlock();
1543
+ const documentationHeight = await measureTextBlockHeight();
1544
+ return {
1545
+ documentation,
1546
+ documentationHeight,
1547
+ lineInfos
1548
+ };
1549
+ };
1550
+
1511
1551
  // @deprecated this doesn't work for variable width characters (unicode/emoji).
1512
1552
  // Use position computation in renderer process instead
1513
1553
 
@@ -1534,7 +1574,7 @@ const y = (editor, rowIndex) => {
1534
1574
  return offsetY;
1535
1575
  };
1536
1576
 
1537
- const getHoverPositionXy = (editor, rowIndex, wordStart, documentationHeight) => {
1577
+ const getHoverPositionXy = (editor, rowIndex, wordStart) => {
1538
1578
  const x$1 = x(editor, rowIndex, wordStart);
1539
1579
  const y$1 = editor.height - y(editor, rowIndex) + editor.y + 40;
1540
1580
  return {
@@ -1564,9 +1604,9 @@ const activateByEvent = async event => {
1564
1604
  };
1565
1605
 
1566
1606
  const execute = async ({
1607
+ args,
1567
1608
  editorLanguageId,
1568
1609
  editorUid,
1569
- args,
1570
1610
  event,
1571
1611
  method,
1572
1612
  noProviderFoundMessage,
@@ -1582,30 +1622,30 @@ const executeHoverProvider = async (editorUid, editorLanguageId, offset) => {
1582
1622
  number(editorUid);
1583
1623
  number(offset);
1584
1624
  return execute({
1585
- event: OnHover,
1625
+ args: [offset],
1586
1626
  editorUid,
1627
+ event: OnHover,
1587
1628
  method: HoverExecute,
1588
- args: [offset],
1589
1629
  noProviderFoundMessage: 'No hover provider found'
1590
1630
  });
1591
1631
  };
1592
1632
 
1593
1633
  const getHover = async (editorUid, editorLanguageId, offset) => {
1594
- number(editorUid);
1595
- number(offset);
1596
- // TODO invoke extension host worker directly
1597
- const hover = await executeHoverProvider(editorUid, editorLanguageId, offset);
1598
- return hover;
1599
- };
1600
-
1601
- const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
1602
- // TODO ask editor worker or renderer process
1603
- return 100;
1604
- };
1605
-
1606
- const tokenizeCodeBlock = async (codeBlock, languageId, tokenizerPath) => {
1607
- // TODO maybe use syntax highlighting worker for this or another worker
1608
- return [];
1634
+ try {
1635
+ number(editorUid);
1636
+ number(offset);
1637
+ // TODO invoke extension host worker directly
1638
+ const hover = await executeHoverProvider(editorUid, editorLanguageId, offset);
1639
+ return {
1640
+ error: undefined,
1641
+ hover
1642
+ };
1643
+ } catch (error) {
1644
+ return {
1645
+ error,
1646
+ hover: undefined
1647
+ };
1648
+ }
1609
1649
  };
1610
1650
 
1611
1651
  const getMatchingDiagnostics = (diagnostics, rowIndex, columnIndex) => {
@@ -1620,20 +1660,16 @@ const getMatchingDiagnostics = (diagnostics, rowIndex, columnIndex) => {
1620
1660
  const getEditorHoverInfo = async (editorUid, editorLanguageId, hoverFullWidth, hoverPaddingLeft, hoverPaddingRight, hoverBorderLeft, hoverBorderRight, hoverDocumentationFontFamily, hoverDocumentationFontSize, hoverDocumentationLineHeight, fallbackDisplayStringLanguageId) => {
1621
1661
  number(editorUid);
1622
1662
  const {
1623
- rowIndex,
1624
- columnIndex
1663
+ columnIndex,
1664
+ rowIndex
1625
1665
  } = await getPositionAtCursor(editorUid);
1626
1666
  const offset = getOffsetAtCursor();
1627
- const hover = await getHover(editorUid, editorLanguageId, offset);
1628
- if (!hover) {
1629
- return undefined;
1630
- }
1631
- const {
1632
- documentation} = hover;
1633
- const lineInfos = await tokenizeCodeBlock();
1667
+
1668
+ // @ts-ignore
1669
+ const diagnostics = await invoke$1('Editor.getDiagnostics', editorUid);
1634
1670
  const wordPart = await getWordBefore(editorUid, rowIndex, columnIndex);
1635
1671
  const wordStart = columnIndex - wordPart.length;
1636
- await measureTextBlockHeight();
1672
+
1637
1673
  // TODO
1638
1674
  const editor = {};
1639
1675
  const {
@@ -1641,14 +1677,30 @@ const getEditorHoverInfo = async (editorUid, editorLanguageId, hoverFullWidth, h
1641
1677
  y
1642
1678
  } = getHoverPositionXy(editor, rowIndex, wordStart);
1643
1679
  // @ts-ignore
1644
- const diagnostics = editor.diagnostics || [];
1645
1680
  const matchingDiagnostics = getMatchingDiagnostics(diagnostics, rowIndex);
1681
+ const {
1682
+ error,
1683
+ hover
1684
+ } = await getHover(editorUid, editorLanguageId, offset);
1685
+ if (!hover) {
1686
+ return {
1687
+ documentation: '',
1688
+ lineInfos: [],
1689
+ matchingDiagnostics,
1690
+ x,
1691
+ y
1692
+ };
1693
+ }
1694
+ const {
1695
+ documentation,
1696
+ lineInfos
1697
+ } = await getHoverDetails(hover, error);
1646
1698
  return {
1647
- lineInfos,
1648
1699
  documentation,
1700
+ lineInfos,
1701
+ matchingDiagnostics,
1649
1702
  x,
1650
- y,
1651
- matchingDiagnostics
1703
+ y
1652
1704
  };
1653
1705
  };
1654
1706
 
@@ -1676,13 +1728,13 @@ const loadContent = async state => {
1676
1728
  } = info;
1677
1729
  return {
1678
1730
  ...state,
1679
- leadingWord: wordAtOffset,
1680
- x,
1681
- y,
1682
1731
  documentation,
1732
+ leadingWord: wordAtOffset,
1683
1733
  lineInfos,
1684
1734
  matchingDiagnostics,
1685
- width: 300
1735
+ width: 300,
1736
+ x,
1737
+ y
1686
1738
  };
1687
1739
  };
1688
1740
 
@@ -1693,11 +1745,11 @@ const SetEventListeners = 'Viewlet.registerEventListeners';
1693
1745
 
1694
1746
  const renderBounds = (oldState, newState) => {
1695
1747
  const {
1696
- x,
1697
- y,
1698
- width,
1699
1748
  height,
1700
- uid
1749
+ uid,
1750
+ width,
1751
+ x,
1752
+ y
1701
1753
  } = newState;
1702
1754
  return [SetBounds, uid, x, y, width, height];
1703
1755
  };
@@ -1745,25 +1797,25 @@ const Span = 8;
1745
1797
 
1746
1798
  const text = data => {
1747
1799
  return {
1748
- type: Text,
1800
+ childCount: 0,
1749
1801
  text: data,
1750
- childCount: 0
1802
+ type: Text
1751
1803
  };
1752
1804
  };
1753
1805
 
1754
1806
  const getLineInfoVirtualDom = lineInfo => {
1755
1807
  const dom = [{
1756
- type: Div,
1808
+ childCount: lineInfo.length / 2,
1757
1809
  className: HoverEditorRow,
1758
- childCount: lineInfo.length / 2
1810
+ type: Div
1759
1811
  }];
1760
1812
  for (let i = 0; i < lineInfo.length; i += 2) {
1761
1813
  const tokenText = lineInfo[i];
1762
1814
  const tokenClass = lineInfo[i + 1];
1763
1815
  dom.push({
1764
- type: Span,
1816
+ childCount: 1,
1765
1817
  className: tokenClass,
1766
- childCount: 1
1818
+ type: Span
1767
1819
  }, text(tokenText));
1768
1820
  }
1769
1821
  return dom;
@@ -1773,15 +1825,17 @@ const getLineInfosVirtualDom = lineInfos => {
1773
1825
  return dom;
1774
1826
  };
1775
1827
 
1828
+ /* eslint-disable unicorn/no-immediate-mutation */
1829
+
1776
1830
  const hoverProblemMessage = {
1777
- type: Span,
1831
+ childCount: 1,
1778
1832
  className: HoverProblemMessage,
1779
- childCount: 1
1833
+ type: Span
1780
1834
  };
1781
1835
  const hoverProblemDetail = {
1782
- type: Span,
1836
+ childCount: 1,
1783
1837
  className: HoverProblemDetail,
1784
- childCount: 1
1838
+ type: Span
1785
1839
  };
1786
1840
  const getChildCount = (lineInfos, documentation, diagnostics) => {
1787
1841
  const diagnosticsCount = diagnostics && diagnostics.length > 0 ? 1 : 0;
@@ -1790,15 +1844,15 @@ const getChildCount = (lineInfos, documentation, diagnostics) => {
1790
1844
  const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
1791
1845
  const dom = [];
1792
1846
  dom.push({
1793
- type: Div,
1847
+ childCount: getChildCount(lineInfos, documentation, diagnostics) + 1,
1794
1848
  className: 'Viewlet EditorHover',
1795
- childCount: getChildCount(lineInfos, documentation, diagnostics) + 1
1849
+ type: Div
1796
1850
  });
1797
1851
  if (diagnostics && diagnostics.length > 0) {
1798
1852
  dom.push({
1799
- type: Div,
1853
+ childCount: diagnostics.length * 2,
1800
1854
  className: `${HoverDisplayString} ${HoverProblem}`,
1801
- childCount: diagnostics.length * 2
1855
+ type: Div
1802
1856
  });
1803
1857
  for (const diagnostic of diagnostics) {
1804
1858
  dom.push(hoverProblemMessage, text(diagnostic.message), hoverProblemDetail, text(`${diagnostic.source} (${diagnostic.code})`));
@@ -1807,33 +1861,33 @@ const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
1807
1861
  if (lineInfos.length > 0) {
1808
1862
  const lineInfosDom = getLineInfosVirtualDom(lineInfos);
1809
1863
  dom.push({
1810
- type: Div,
1864
+ childCount: lineInfos.length,
1811
1865
  className: HoverDisplayString,
1812
- childCount: lineInfos.length
1866
+ type: Div
1813
1867
  }, ...lineInfosDom);
1814
1868
  }
1815
1869
  if (documentation) {
1816
1870
  dom.push({
1817
- type: Div,
1871
+ childCount: 1,
1818
1872
  className: HoverDocumentation,
1819
- childCount: 1
1873
+ type: Div
1820
1874
  }, text(documentation));
1821
1875
  }
1822
1876
  dom.push({
1823
- type: Div,
1824
- className: 'Sash SashVertical SashResize',
1825
1877
  childCount: 0,
1826
- onPointerDown: HandleSashPointerDown
1878
+ className: 'Sash SashVertical SashResize',
1879
+ onPointerDown: HandleSashPointerDown,
1880
+ type: Div
1827
1881
  });
1828
1882
  return dom;
1829
1883
  };
1830
1884
 
1831
1885
  const renderItems = (oldState, newState) => {
1832
1886
  const {
1833
- uid,
1834
- matchingDiagnostics,
1835
1887
  documentation,
1836
- lineInfos
1888
+ lineInfos,
1889
+ matchingDiagnostics,
1890
+ uid
1837
1891
  } = newState;
1838
1892
  const dom = getHoverVirtualDom(lineInfos, documentation, matchingDiagnostics);
1839
1893
  return [/* method */'Viewlet.setDom2', uid, dom];
@@ -1841,26 +1895,26 @@ const renderItems = (oldState, newState) => {
1841
1895
 
1842
1896
  const renderUid = (oldState, newState) => {
1843
1897
  const {
1844
- uid,
1845
- editorUid
1898
+ editorUid,
1899
+ uid
1846
1900
  } = newState;
1847
1901
  return [SetUid, uid, editorUid];
1848
1902
  };
1849
1903
 
1850
1904
  const getRenderer = diffType => {
1851
1905
  switch (diffType) {
1852
- case RenderContent:
1853
- return renderContent;
1854
1906
  case RenderBounds:
1855
1907
  return renderBounds;
1908
+ case RenderContent:
1909
+ return renderContent;
1856
1910
  case RenderEventListeners:
1857
1911
  return renderEventListeners;
1858
- case RenderUid:
1859
- return renderUid;
1860
1912
  case RenderFocusContext:
1861
1913
  return renderFocusContext;
1862
1914
  case RenderItems:
1863
1915
  return renderItems;
1916
+ case RenderUid:
1917
+ return renderUid;
1864
1918
  default:
1865
1919
  throw new Error('unknown renderer');
1866
1920
  }
@@ -1877,18 +1931,14 @@ const applyRender = (oldState, newState, diffResult) => {
1877
1931
 
1878
1932
  const render2 = (uid, diffResult) => {
1879
1933
  const {
1880
- oldState,
1881
- newState
1934
+ newState,
1935
+ oldState
1882
1936
  } = get(uid);
1883
1937
  set$1(uid, newState, newState);
1884
1938
  const commands = applyRender(oldState, newState, diffResult);
1885
1939
  return commands;
1886
1940
  };
1887
1941
 
1888
- const terminate = () => {
1889
- globalThis.close();
1890
- };
1891
-
1892
1942
  const commandMap = {
1893
1943
  'Hover.close': wrapCommand(close),
1894
1944
  'Hover.create': create,
@@ -1896,12 +1946,12 @@ const commandMap = {
1896
1946
  'Hover.dispose': dispose,
1897
1947
  'Hover.getCommandIds': getCommandIds,
1898
1948
  'Hover.getKeyBindings': getKeyBindings,
1949
+ 'Hover.handleSashPointerDown': wrapCommand(handleSashPointerDown),
1950
+ 'Hover.handleSashPointerMove': wrapCommand(handleSashPointerMove),
1951
+ 'Hover.handleSashPointerUp': wrapCommand(handleSashPointerUp),
1899
1952
  'Hover.initialize': initialize,
1900
1953
  'Hover.loadContent': wrapCommand(loadContent),
1901
1954
  'Hover.render2': render2,
1902
- 'Hover.handleSashPointerUp': wrapCommand(handleSashPointerUp),
1903
- 'Hover.handleSashPointerDown': wrapCommand(handleSashPointerDown),
1904
- 'Hover.handleSashPointerMove': wrapCommand(handleSashPointerMove),
1905
1955
  'Hover.terminate': terminate
1906
1956
  };
1907
1957
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/hover-worker",
3
- "version": "1.5.0",
3
+ "version": "2.1.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",