@lvce-editor/completion-worker 2.0.0 → 3.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.
@@ -518,56 +518,35 @@ const IpcParentWithMessagePort$1 = {
518
518
  wrap: wrap$5
519
519
  };
520
520
 
521
- const Two = '2.0';
522
- const create$4$1 = (method, params) => {
523
- return {
524
- jsonrpc: Two,
525
- method,
526
- params
527
- };
521
+ class CommandNotFoundError extends Error {
522
+ constructor(command) {
523
+ super(`Command not found ${command}`);
524
+ this.name = 'CommandNotFoundError';
525
+ }
526
+ }
527
+ const commands = Object.create(null);
528
+ const register = commandMap => {
529
+ Object.assign(commands, commandMap);
528
530
  };
529
- const callbacks = Object.create(null);
530
- const set$5 = (id, fn) => {
531
- callbacks[id] = fn;
531
+ const getCommand$1 = key => {
532
+ return commands[key];
532
533
  };
534
+ const execute$1 = (command, ...args) => {
535
+ const fn = getCommand$1(command);
536
+ if (!fn) {
537
+ throw new CommandNotFoundError(command);
538
+ }
539
+ return fn(...args);
540
+ };
541
+
542
+ const Two$1 = '2.0';
543
+ const callbacks = Object.create(null);
533
544
  const get$2 = id => {
534
545
  return callbacks[id];
535
546
  };
536
- const remove = id => {
547
+ const remove$1 = id => {
537
548
  delete callbacks[id];
538
549
  };
539
- let id = 0;
540
- const create$3$1 = () => {
541
- return ++id;
542
- };
543
- const registerPromise = () => {
544
- const id = create$3$1();
545
- const {
546
- resolve,
547
- promise
548
- } = Promise.withResolvers();
549
- set$5(id, resolve);
550
- return {
551
- id,
552
- promise
553
- };
554
- };
555
- const create$2$1 = (method, params) => {
556
- const {
557
- id,
558
- promise
559
- } = registerPromise();
560
- const message = {
561
- jsonrpc: Two,
562
- method,
563
- params,
564
- id
565
- };
566
- return {
567
- message,
568
- promise
569
- };
570
- };
571
550
  class JsonRpcError extends Error {
572
551
  constructor(message) {
573
552
  super(message);
@@ -584,12 +563,12 @@ const getErrorConstructor = (message, type) => {
584
563
  switch (type) {
585
564
  case DomException:
586
565
  return DOMException;
587
- case TypeError$1:
588
- return TypeError;
589
- case SyntaxError$1:
590
- return SyntaxError;
591
566
  case ReferenceError$1:
592
567
  return ReferenceError;
568
+ case SyntaxError$1:
569
+ return SyntaxError;
570
+ case TypeError$1:
571
+ return TypeError;
593
572
  default:
594
573
  return Error;
595
574
  }
@@ -718,7 +697,7 @@ const resolve = (id, response) => {
718
697
  return;
719
698
  }
720
699
  fn(response);
721
- remove(id);
700
+ remove$1(id);
722
701
  };
723
702
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
724
703
  const getErrorType = prettyError => {
@@ -745,27 +724,27 @@ const getErrorProperty = (error, prettyError) => {
745
724
  if (error && error.code === E_COMMAND_NOT_FOUND) {
746
725
  return {
747
726
  code: MethodNotFound,
748
- message: error.message,
749
- data: error.stack
727
+ data: error.stack,
728
+ message: error.message
750
729
  };
751
730
  }
752
731
  return {
753
732
  code: Custom,
754
- message: prettyError.message,
755
733
  data: {
756
- stack: getStack(prettyError),
757
- codeFrame: prettyError.codeFrame,
758
- type: getErrorType(prettyError),
759
734
  code: prettyError.code,
760
- name: prettyError.name
761
- }
735
+ codeFrame: prettyError.codeFrame,
736
+ name: prettyError.name,
737
+ stack: getStack(prettyError),
738
+ type: getErrorType(prettyError)
739
+ },
740
+ message: prettyError.message
762
741
  };
763
742
  };
764
743
  const create$1$1 = (id, error) => {
765
744
  return {
766
- jsonrpc: Two,
745
+ error,
767
746
  id,
768
- error
747
+ jsonrpc: Two$1
769
748
  };
770
749
  };
771
750
  const getErrorResponse = (id, error, preparePrettyError, logError) => {
@@ -774,27 +753,27 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
774
753
  const errorProperty = getErrorProperty(error, prettyError);
775
754
  return create$1$1(id, errorProperty);
776
755
  };
777
- const create$6 = (message, result) => {
756
+ const create$9 = (message, result) => {
778
757
  return {
779
- jsonrpc: Two,
780
758
  id: message.id,
759
+ jsonrpc: Two$1,
781
760
  result: result ?? null
782
761
  };
783
762
  };
784
763
  const getSuccessResponse = (message, result) => {
785
764
  const resultProperty = result ?? null;
786
- return create$6(message, resultProperty);
765
+ return create$9(message, resultProperty);
787
766
  };
788
767
  const getErrorResponseSimple = (id, error) => {
789
768
  return {
790
- jsonrpc: Two,
791
- id,
792
769
  error: {
793
770
  code: Custom,
771
+ data: error,
794
772
  // @ts-ignore
795
- message: error.message,
796
- data: error
797
- }
773
+ message: error.message
774
+ },
775
+ id,
776
+ jsonrpc: Two$1
798
777
  };
799
778
  };
800
779
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
@@ -824,35 +803,35 @@ const normalizeParams = args => {
824
803
  if (args.length === 1) {
825
804
  const options = args[0];
826
805
  return {
806
+ execute: options.execute,
827
807
  ipc: options.ipc,
808
+ logError: options.logError || defaultLogError,
828
809
  message: options.message,
829
- execute: options.execute,
830
- resolve: options.resolve || defaultResolve,
831
810
  preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
832
- logError: options.logError || defaultLogError,
833
- requiresSocket: options.requiresSocket || defaultRequiresSocket
811
+ requiresSocket: options.requiresSocket || defaultRequiresSocket,
812
+ resolve: options.resolve || defaultResolve
834
813
  };
835
814
  }
836
815
  return {
816
+ execute: args[2],
837
817
  ipc: args[0],
818
+ logError: args[5],
838
819
  message: args[1],
839
- execute: args[2],
840
- resolve: args[3],
841
820
  preparePrettyError: args[4],
842
- logError: args[5],
843
- requiresSocket: args[6]
821
+ requiresSocket: args[6],
822
+ resolve: args[3]
844
823
  };
845
824
  };
846
825
  const handleJsonRpcMessage = async (...args) => {
847
826
  const options = normalizeParams(args);
848
827
  const {
849
- message,
850
- ipc,
851
828
  execute,
852
- resolve,
853
- preparePrettyError,
829
+ ipc,
854
830
  logError,
855
- requiresSocket
831
+ message,
832
+ preparePrettyError,
833
+ requiresSocket,
834
+ resolve
856
835
  } = options;
857
836
  if ('id' in message) {
858
837
  if ('method' in message) {
@@ -874,11 +853,51 @@ const handleJsonRpcMessage = async (...args) => {
874
853
  }
875
854
  throw new JsonRpcError('unexpected message');
876
855
  };
877
- const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
856
+
857
+ const Two = '2.0';
858
+
859
+ const create$8 = (method, params) => {
860
+ return {
861
+ jsonrpc: Two,
862
+ method,
863
+ params
864
+ };
865
+ };
866
+
867
+ const create$7 = (id, method, params) => {
868
+ const message = {
869
+ id,
870
+ jsonrpc: Two,
871
+ method,
872
+ params
873
+ };
874
+ return message;
875
+ };
876
+
877
+ let id = 0;
878
+ const create$6 = () => {
879
+ return ++id;
880
+ };
881
+
882
+ const registerPromise = map => {
883
+ const id = create$6();
878
884
  const {
879
- message,
885
+ promise,
886
+ resolve
887
+ } = Promise.withResolvers();
888
+ map[id] = resolve;
889
+ return {
890
+ id,
880
891
  promise
881
- } = create$2$1(method, params);
892
+ };
893
+ };
894
+
895
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
896
+ const {
897
+ id,
898
+ promise
899
+ } = registerPromise(callbacks);
900
+ const message = create$7(id, method, params);
882
901
  if (useSendAndTransfer && ipc.sendAndTransfer) {
883
902
  ipc.sendAndTransfer(message);
884
903
  } else {
@@ -887,60 +906,40 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
887
906
  const responseMessage = await promise;
888
907
  return unwrapJsonRpcResult(responseMessage);
889
908
  };
890
- const send = (transport, method, ...params) => {
891
- const message = create$4$1(method, params);
892
- transport.send(message);
893
- };
894
- const invoke$2 = (ipc, method, ...params) => {
895
- return invokeHelper(ipc, method, params, false);
896
- };
897
- const invokeAndTransfer$1 = (ipc, method, ...params) => {
898
- return invokeHelper(ipc, method, params, true);
899
- };
900
-
901
- class CommandNotFoundError extends Error {
902
- constructor(command) {
903
- super(`Command not found ${command}`);
904
- this.name = 'CommandNotFoundError';
905
- }
906
- }
907
- const commands = Object.create(null);
908
- const register = commandMap => {
909
- Object.assign(commands, commandMap);
910
- };
911
- const getCommand$1 = key => {
912
- return commands[key];
913
- };
914
- const execute$1 = (command, ...args) => {
915
- const fn = getCommand$1(command);
916
- if (!fn) {
917
- throw new CommandNotFoundError(command);
918
- }
919
- return fn(...args);
920
- };
921
-
922
909
  const createRpc = ipc => {
910
+ const callbacks = Object.create(null);
911
+ ipc._resolve = (id, response) => {
912
+ const fn = callbacks[id];
913
+ if (!fn) {
914
+ console.warn(`callback ${id} may already be disposed`);
915
+ return;
916
+ }
917
+ fn(response);
918
+ delete callbacks[id];
919
+ };
923
920
  const rpc = {
921
+ async dispose() {
922
+ await ipc?.dispose();
923
+ },
924
+ invoke(method, ...params) {
925
+ return invokeHelper(callbacks, ipc, method, params, false);
926
+ },
927
+ invokeAndTransfer(method, ...params) {
928
+ return invokeHelper(callbacks, ipc, method, params, true);
929
+ },
924
930
  // @ts-ignore
925
931
  ipc,
926
932
  /**
927
933
  * @deprecated
928
934
  */
929
935
  send(method, ...params) {
930
- send(ipc, method, ...params);
931
- },
932
- invoke(method, ...params) {
933
- return invoke$2(ipc, method, ...params);
934
- },
935
- invokeAndTransfer(method, ...params) {
936
- return invokeAndTransfer$1(ipc, method, ...params);
937
- },
938
- async dispose() {
939
- await ipc?.dispose();
936
+ const message = create$8(method, params);
937
+ ipc.send(message);
940
938
  }
941
939
  };
942
940
  return rpc;
943
941
  };
942
+
944
943
  const requiresSocket = () => {
945
944
  return false;
946
945
  };
@@ -953,8 +952,9 @@ const logError = () => {
953
952
  const handleMessage = event => {
954
953
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
955
954
  const actualExecute = event?.target?.execute || execute$1;
956
- return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
955
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
957
956
  };
957
+
958
958
  const handleIpc = ipc => {
959
959
  if ('addEventListener' in ipc) {
960
960
  ipc.addEventListener('message', handleMessage);
@@ -963,6 +963,7 @@ const handleIpc = ipc => {
963
963
  ipc.on('message', handleMessage);
964
964
  }
965
965
  };
966
+
966
967
  const listen$1 = async (module, options) => {
967
968
  const rawIpc = await module.listen(options);
968
969
  if (module.signal) {
@@ -971,15 +972,17 @@ const listen$1 = async (module, options) => {
971
972
  const ipc = module.wrap(rawIpc);
972
973
  return ipc;
973
974
  };
975
+
974
976
  const create$5 = async ({
975
977
  commandMap,
978
+ isMessagePortOpen = true,
976
979
  messagePort
977
980
  }) => {
978
981
  // TODO create a commandMap per rpc instance
979
982
  register(commandMap);
980
983
  const rawIpc = await IpcParentWithMessagePort$1.create({
981
- messagePort,
982
- isMessagePortOpen: true
984
+ isMessagePortOpen,
985
+ messagePort
983
986
  });
984
987
  const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
985
988
  handleIpc(ipc);
@@ -987,8 +990,10 @@ const create$5 = async ({
987
990
  messagePort.start();
988
991
  return rpc;
989
992
  };
990
- const create$3 = async ({
993
+
994
+ const create$4 = async ({
991
995
  commandMap,
996
+ isMessagePortOpen,
992
997
  send
993
998
  }) => {
994
999
  const {
@@ -998,14 +1003,12 @@ const create$3 = async ({
998
1003
  await send(port1);
999
1004
  return create$5({
1000
1005
  commandMap,
1006
+ isMessagePortOpen,
1001
1007
  messagePort: port2
1002
1008
  });
1003
1009
  };
1004
- const TransferMessagePortRpcParent = {
1005
- __proto__: null,
1006
- create: create$3
1007
- };
1008
- const create$4 = async ({
1010
+
1011
+ const create$3 = async ({
1009
1012
  commandMap
1010
1013
  }) => {
1011
1014
  // TODO create a commandMap per rpc instance
@@ -1015,108 +1018,40 @@ const create$4 = async ({
1015
1018
  const rpc = createRpc(ipc);
1016
1019
  return rpc;
1017
1020
  };
1018
- const WebWorkerRpcClient = {
1019
- __proto__: null,
1020
- create: create$4
1021
- };
1022
1021
 
1023
- const toCommandId = key => {
1024
- const dotIndex = key.indexOf('.');
1025
- return key.slice(dotIndex + 1);
1026
- };
1027
- const create$2 = () => {
1028
- const states = Object.create(null);
1029
- const commandMapRef = {};
1030
- return {
1031
- get(uid) {
1032
- return states[uid];
1033
- },
1034
- set(uid, oldState, newState) {
1035
- states[uid] = {
1036
- oldState,
1037
- newState
1038
- };
1039
- },
1040
- dispose(uid) {
1041
- delete states[uid];
1042
- },
1043
- getKeys() {
1044
- return Object.keys(states).map(key => {
1045
- return Number.parseInt(key);
1046
- });
1047
- },
1048
- clear() {
1049
- for (const key of Object.keys(states)) {
1050
- delete states[key];
1051
- }
1052
- },
1053
- wrapCommand(fn) {
1054
- const wrapped = async (uid, ...args) => {
1055
- const {
1056
- oldState,
1057
- newState
1058
- } = states[uid];
1059
- const newerState = await fn(newState, ...args);
1060
- if (oldState === newerState || newState === newerState) {
1061
- return;
1062
- }
1063
- const latest = states[uid];
1064
- states[uid] = {
1065
- oldState: latest.oldState,
1066
- newState: newerState
1067
- };
1068
- };
1069
- return wrapped;
1070
- },
1071
- wrapGetter(fn) {
1072
- const wrapped = (uid, ...args) => {
1073
- const {
1074
- newState
1075
- } = states[uid];
1076
- return fn(newState, ...args);
1077
- };
1078
- return wrapped;
1079
- },
1080
- diff(uid, modules, numbers) {
1081
- const {
1082
- oldState,
1083
- newState
1084
- } = states[uid];
1085
- const diffResult = [];
1086
- for (let i = 0; i < modules.length; i++) {
1087
- const fn = modules[i];
1088
- if (!fn(oldState, newState)) {
1089
- diffResult.push(numbers[i]);
1090
- }
1091
- }
1092
- return diffResult;
1093
- },
1094
- getCommandIds() {
1095
- const keys = Object.keys(commandMapRef);
1096
- const ids = keys.map(toCommandId);
1097
- return ids;
1098
- },
1099
- registerCommands(commandMap) {
1100
- Object.assign(commandMapRef, commandMap);
1022
+ const createMockRpc = ({
1023
+ commandMap
1024
+ }) => {
1025
+ const invocations = [];
1026
+ const invoke = (method, ...params) => {
1027
+ invocations.push([method, ...params]);
1028
+ const command = commandMap[method];
1029
+ if (!command) {
1030
+ throw new Error(`command ${method} not found`);
1101
1031
  }
1032
+ return command(...params);
1102
1033
  };
1034
+ const mockRpc = {
1035
+ invocations,
1036
+ invoke,
1037
+ invokeAndTransfer: invoke
1038
+ };
1039
+ return mockRpc;
1103
1040
  };
1104
- const terminate = () => {
1105
- globalThis.close();
1106
- };
1107
-
1108
- const EditorWorker$2 = 99;
1109
- const ExtensionHostWorker = 44;
1110
1041
 
1111
1042
  const rpcs = Object.create(null);
1112
- const set$4 = (id, rpc) => {
1043
+ const set$3 = (id, rpc) => {
1113
1044
  rpcs[id] = rpc;
1114
1045
  };
1115
1046
  const get$1 = id => {
1116
1047
  return rpcs[id];
1117
1048
  };
1049
+ const remove = id => {
1050
+ delete rpcs[id];
1051
+ };
1118
1052
 
1119
- const create$1 = rpcId => {
1053
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1054
+ const create$2 = rpcId => {
1120
1055
  return {
1121
1056
  async dispose() {
1122
1057
  const rpc = get$1(rpcId);
@@ -1134,158 +1069,97 @@ const create$1 = rpcId => {
1134
1069
  // @ts-ignore
1135
1070
  return rpc.invokeAndTransfer(method, ...params);
1136
1071
  },
1072
+ registerMockRpc(commandMap) {
1073
+ const mockRpc = createMockRpc({
1074
+ commandMap
1075
+ });
1076
+ set$3(rpcId, mockRpc);
1077
+ // @ts-ignore
1078
+ mockRpc[Symbol.dispose] = () => {
1079
+ remove(rpcId);
1080
+ };
1081
+ // @ts-ignore
1082
+ return mockRpc;
1083
+ },
1137
1084
  set(rpc) {
1138
- set$4(rpcId, rpc);
1085
+ set$3(rpcId, rpc);
1139
1086
  }
1140
1087
  };
1141
1088
  };
1142
1089
 
1143
- const createMockRpc = ({
1144
- commandMap
1145
- }) => {
1146
- const invocations = [];
1147
- const invoke = (method, ...params) => {
1148
- invocations.push([method, ...params]);
1149
- const command = commandMap[method];
1150
- if (!command) {
1151
- throw new Error(`command ${method} not found`);
1152
- }
1153
- return command(...params);
1154
- };
1155
- const mockRpc = {
1156
- invocations,
1157
- invoke,
1158
- invokeAndTransfer: invoke
1159
- };
1160
- return mockRpc;
1161
- };
1090
+ const Div = 4;
1091
+ const Span = 8;
1092
+ const Text = 12;
1093
+ const Img = 17;
1094
+
1095
+ const ClientX = 'event.clientX';
1096
+ const ClientY = 'event.clientY';
1097
+ const DeltaMode = 'event.deltaMode';
1098
+ const DeltaY = 'event.deltaY';
1099
+
1100
+ const Enter = 3;
1101
+ const Escape = 8;
1102
+ const Space$1 = 9;
1103
+ const End = 255;
1104
+ const Home = 12;
1105
+ const UpArrow = 14;
1106
+ const DownArrow = 16;
1107
+
1108
+ const CtrlCmd = 1 << 11 >>> 0;
1109
+
1110
+ const EditorWorker$1 = 99;
1111
+ const ExtensionHostWorker = 44;
1162
1112
 
1163
1113
  const {
1164
- dispose: dispose$2,
1165
1114
  invoke: invoke$1,
1166
1115
  invokeAndTransfer,
1167
- set: set$3
1168
- } = create$1(EditorWorker$2);
1169
- const sendMessagePortToExtensionHostWorker$2 = async port => {
1116
+ set: set$2
1117
+ } = create$2(EditorWorker$1);
1118
+ const sendMessagePortToExtensionHostWorker$1 = async port => {
1170
1119
  const command = 'HandleMessagePort.handleMessagePort2';
1171
1120
  await invokeAndTransfer(
1172
1121
  // @ts-ignore
1173
1122
  'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0);
1174
1123
  };
1175
1124
  // TODO add tests for this
1176
- const activateByEvent$2 = async event => {
1125
+ const activateByEvent = async event => {
1177
1126
  // @ts-ignore
1178
1127
  await invoke$1('ActivateByEvent.activateByEvent', event);
1179
1128
  };
1180
- const applyEdit$2 = async (editorUid, changes) => {
1129
+ const applyEdit$1 = async (editorUid, changes) => {
1181
1130
  // @ts-ignore
1182
1131
  await invoke$1('Editor.applyEdit2', editorUid, changes);
1183
1132
  };
1184
- const applyWorkspaceEdit = async (editorUid, changes) => {
1185
- // @ts-ignore
1186
- await invoke$1('Editor.applyWorkspaceEdit', editorUid, changes);
1187
- };
1188
- const closeWidget$1 = async (editorUid, widgetId, widgetName, focusId) => {
1133
+ const closeWidget = async (editorUid, widgetId, widgetName, focusId) => {
1189
1134
  // @ts-ignore
1190
1135
  await invoke$1('Editor.closeWidget2', editorUid, widgetId, widgetName, focusId);
1191
1136
  };
1192
- const getWordAt = async (uid, rowIndex, columnIndex) => {
1193
- // @ts-ignore
1194
- const word = await invoke$1('Editor.getWordAt2', uid, rowIndex, columnIndex);
1195
- return word;
1196
- };
1197
- const getLines$2 = async editorUid => {
1137
+ const getLines$1 = async editorUid => {
1198
1138
  const lines = await invoke$1('Editor.getLines2', editorUid);
1199
1139
  return lines;
1200
1140
  };
1201
- const getPositionAtCursor$2 = async parentUid => {
1141
+ const getPositionAtCursor$1 = async parentUid => {
1202
1142
  const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
1203
1143
  return position;
1204
1144
  };
1205
- const getOffsetAtCursor$2 = async editorId => {
1145
+ const getOffsetAtCursor$1 = async editorId => {
1206
1146
  // @ts-ignore
1207
1147
  return await invoke$1('Editor.getOffsetAtCursor', editorId);
1208
1148
  };
1209
- const getSelections$2 = async editorUid => {
1149
+ const getSelections$1 = async editorUid => {
1210
1150
  const selections = await invoke$1('Editor.getSelections2', editorUid);
1211
1151
  return selections;
1212
1152
  };
1213
- const getWordAtOffset2$1 = async editorUid => {
1153
+ const getWordAtOffset2 = async editorUid => {
1214
1154
  return invoke$1('Editor.getWordAtOffset2', editorUid);
1215
1155
  };
1216
- const getWordBefore$2 = async (editorUid, rowIndex, columnIndex) => {
1156
+ const getWordBefore$1 = async (editorUid, rowIndex, columnIndex) => {
1217
1157
  return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1218
1158
  };
1219
- const updateDebugInfo = async info => {
1220
- await invoke$1('Editor.updateDebugInfo', info);
1221
- };
1222
- const getUri = async editorUid => {
1223
- // @ts-ignore
1224
- return invoke$1('Editor.getUri', editorUid);
1225
- };
1226
- const getLanguageId = async editorUid => {
1227
- // @ts-ignore
1228
- return invoke$1('Editor.getLanguageId', editorUid);
1229
- };
1230
- const getProblems = async () => {
1231
- // @ts-ignore
1232
- return invoke$1('Editor.getProblems');
1233
- };
1234
- const registerMockRpc = commandMap => {
1235
- const mockRpc = createMockRpc({
1236
- commandMap
1237
- });
1238
- set$3(mockRpc);
1239
- return mockRpc;
1240
- };
1241
-
1242
- const EditorWorker$1 = {
1243
- __proto__: null,
1244
- activateByEvent: activateByEvent$2,
1245
- applyEdit: applyEdit$2,
1246
- applyWorkspaceEdit,
1247
- closeWidget: closeWidget$1,
1248
- dispose: dispose$2,
1249
- getLanguageId,
1250
- getLines: getLines$2,
1251
- getOffsetAtCursor: getOffsetAtCursor$2,
1252
- getPositionAtCursor: getPositionAtCursor$2,
1253
- getProblems,
1254
- getSelections: getSelections$2,
1255
- getUri,
1256
- getWordAt,
1257
- getWordAtOffset2: getWordAtOffset2$1,
1258
- getWordBefore: getWordBefore$2,
1259
- invoke: invoke$1,
1260
- invokeAndTransfer,
1261
- registerMockRpc,
1262
- sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$2,
1263
- set: set$3,
1264
- updateDebugInfo
1265
- };
1266
-
1267
- const {
1268
- invoke,
1269
- set: set$2
1270
- } = create$1(ExtensionHostWorker);
1271
-
1272
- const {
1273
- activateByEvent: activateByEvent$1,
1274
- applyEdit: applyEdit$1,
1275
- closeWidget,
1276
- getLines: getLines$1,
1277
- getOffsetAtCursor: getOffsetAtCursor$1,
1278
- getPositionAtCursor: getPositionAtCursor$1,
1279
- getSelections: getSelections$1,
1280
- getWordAtOffset2,
1281
- getWordBefore: getWordBefore$1,
1282
- sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1283
- set: set$1
1284
- } = EditorWorker$1;
1285
1159
 
1286
1160
  const EditorWorker = {
1287
1161
  __proto__: null,
1288
- activateByEvent: activateByEvent$1,
1162
+ activateByEvent,
1289
1163
  applyEdit: applyEdit$1,
1290
1164
  closeWidget,
1291
1165
  getLines: getLines$1,
@@ -1294,8 +1168,135 @@ const EditorWorker = {
1294
1168
  getSelections: getSelections$1,
1295
1169
  getWordAtOffset2,
1296
1170
  getWordBefore: getWordBefore$1,
1171
+ invoke: invoke$1,
1172
+ invokeAndTransfer,
1297
1173
  sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1174
+ set: set$2
1175
+ };
1176
+
1177
+ const {
1178
+ invoke,
1298
1179
  set: set$1
1180
+ } = create$2(ExtensionHostWorker);
1181
+
1182
+ const toCommandId = key => {
1183
+ const dotIndex = key.indexOf('.');
1184
+ return key.slice(dotIndex + 1);
1185
+ };
1186
+ const create$1 = () => {
1187
+ const states = Object.create(null);
1188
+ const commandMapRef = {};
1189
+ return {
1190
+ clear() {
1191
+ for (const key of Object.keys(states)) {
1192
+ delete states[key];
1193
+ }
1194
+ },
1195
+ diff(uid, modules, numbers) {
1196
+ const {
1197
+ newState,
1198
+ oldState
1199
+ } = states[uid];
1200
+ const diffResult = [];
1201
+ for (let i = 0; i < modules.length; i++) {
1202
+ const fn = modules[i];
1203
+ if (!fn(oldState, newState)) {
1204
+ diffResult.push(numbers[i]);
1205
+ }
1206
+ }
1207
+ return diffResult;
1208
+ },
1209
+ dispose(uid) {
1210
+ delete states[uid];
1211
+ },
1212
+ get(uid) {
1213
+ return states[uid];
1214
+ },
1215
+ getCommandIds() {
1216
+ const keys = Object.keys(commandMapRef);
1217
+ const ids = keys.map(toCommandId);
1218
+ return ids;
1219
+ },
1220
+ getKeys() {
1221
+ return Object.keys(states).map(key => {
1222
+ return Number.parseFloat(key);
1223
+ });
1224
+ },
1225
+ registerCommands(commandMap) {
1226
+ Object.assign(commandMapRef, commandMap);
1227
+ },
1228
+ set(uid, oldState, newState) {
1229
+ states[uid] = {
1230
+ newState,
1231
+ oldState
1232
+ };
1233
+ },
1234
+ wrapCommand(fn) {
1235
+ const wrapped = async (uid, ...args) => {
1236
+ const {
1237
+ newState,
1238
+ oldState
1239
+ } = states[uid];
1240
+ const newerState = await fn(newState, ...args);
1241
+ if (oldState === newerState || newState === newerState) {
1242
+ return;
1243
+ }
1244
+ const latestOld = states[uid];
1245
+ const latestNew = {
1246
+ ...latestOld.newState,
1247
+ ...newerState
1248
+ };
1249
+ states[uid] = {
1250
+ newState: latestNew,
1251
+ oldState: latestOld.oldState
1252
+ };
1253
+ };
1254
+ return wrapped;
1255
+ },
1256
+ wrapGetter(fn) {
1257
+ const wrapped = (uid, ...args) => {
1258
+ const {
1259
+ newState
1260
+ } = states[uid];
1261
+ return fn(newState, ...args);
1262
+ };
1263
+ return wrapped;
1264
+ },
1265
+ wrapLoadContent(fn) {
1266
+ const wrapped = async (uid, ...args) => {
1267
+ const {
1268
+ newState,
1269
+ oldState
1270
+ } = states[uid];
1271
+ const result = await fn(newState, ...args);
1272
+ const {
1273
+ error,
1274
+ state
1275
+ } = result;
1276
+ if (oldState === state || newState === state) {
1277
+ return {
1278
+ error
1279
+ };
1280
+ }
1281
+ const latestOld = states[uid];
1282
+ const latestNew = {
1283
+ ...latestOld.newState,
1284
+ ...state
1285
+ };
1286
+ states[uid] = {
1287
+ newState: latestNew,
1288
+ oldState: latestOld.oldState
1289
+ };
1290
+ return {
1291
+ error
1292
+ };
1293
+ };
1294
+ return wrapped;
1295
+ }
1296
+ };
1297
+ };
1298
+ const terminate = () => {
1299
+ globalThis.close();
1299
1300
  };
1300
1301
 
1301
1302
  const FocusEditorCompletions = 9;
@@ -1316,7 +1317,7 @@ const {
1316
1317
  get,
1317
1318
  set,
1318
1319
  wrapCommand
1319
- } = create$2();
1320
+ } = create$1();
1320
1321
 
1321
1322
  const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1322
1323
  const state = {
@@ -1499,10 +1500,6 @@ const OnCompletion = 'onCompletion';
1499
1500
  const CompletionExecute = 'ExtensionHostCompletion.execute';
1500
1501
  const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
1501
1502
 
1502
- const {
1503
- activateByEvent
1504
- } = EditorWorker;
1505
-
1506
1503
  const execute = async ({
1507
1504
  args,
1508
1505
  editorLanguageId,
@@ -1602,26 +1599,6 @@ const getCommandIds = () => {
1602
1599
  return commandIds;
1603
1600
  };
1604
1601
 
1605
- const Div = 4;
1606
- const Span = 8;
1607
- const Text = 12;
1608
- const Img = 17;
1609
-
1610
- const ClientX = 'event.clientX';
1611
- const ClientY = 'event.clientY';
1612
- const DeltaMode = 'event.deltaMode';
1613
- const DeltaY = 'event.deltaY';
1614
-
1615
- const Enter = 3;
1616
- const Escape = 8;
1617
- const Space$1 = 9;
1618
- const End = 255;
1619
- const Home = 12;
1620
- const UpArrow = 14;
1621
- const DownArrow = 16;
1622
-
1623
- const CtrlCmd = 1 << 11 >>> 0;
1624
-
1625
1602
  const mergeClassNames = (...classNames) => {
1626
1603
  return classNames.filter(Boolean).join(' ');
1627
1604
  };
@@ -1635,9 +1612,9 @@ const position = (x, y) => {
1635
1612
 
1636
1613
  const text = data => {
1637
1614
  return {
1638
- type: Text,
1615
+ childCount: 0,
1639
1616
  text: data,
1640
- childCount: 0
1617
+ type: Text
1641
1618
  };
1642
1619
  };
1643
1620
 
@@ -1889,9 +1866,7 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
1889
1866
  return Math.min(totalHeight, maxHeight);
1890
1867
  };
1891
1868
 
1892
- const {
1893
- getPositionAtCursor
1894
- } = EditorWorker;
1869
+ const getPositionAtCursor = getPositionAtCursor$1;
1895
1870
 
1896
1871
  const getWordAtOffset = getWordAtOffset2;
1897
1872
 
@@ -2060,7 +2035,7 @@ const {
2060
2035
 
2061
2036
  const createExtensionHostRpc = async () => {
2062
2037
  try {
2063
- const rpc = await TransferMessagePortRpcParent.create({
2038
+ const rpc = await create$4({
2064
2039
  commandMap: {},
2065
2040
  send: sendMessagePortToExtensionHostWorker
2066
2041
  });
@@ -2072,7 +2047,7 @@ const createExtensionHostRpc = async () => {
2072
2047
 
2073
2048
  const initialize = async () => {
2074
2049
  const rpc = await createExtensionHostRpc();
2075
- set$2(rpc);
2050
+ set$1(rpc);
2076
2051
  };
2077
2052
 
2078
2053
  const error = message => {
@@ -2296,6 +2271,18 @@ const getHighlightedLabelDom = (label, highlights) => {
2296
2271
  return dom;
2297
2272
  };
2298
2273
 
2274
+ const getCompletionItemClassName = (focused, deprecated) => {
2275
+ if (focused && deprecated) {
2276
+ return mergeClassNames(EditorCompletionItem, EditorCompletionItemFocused, EditorCompletionItemDeprecated);
2277
+ }
2278
+ if (focused) {
2279
+ return mergeClassNames(EditorCompletionItem, EditorCompletionItemFocused);
2280
+ }
2281
+ if (deprecated) {
2282
+ return mergeClassNames(EditorCompletionItem, EditorCompletionItemDeprecated);
2283
+ }
2284
+ return EditorCompletionItem;
2285
+ };
2299
2286
  const getCompletionItemVirtualDom = visibleItem => {
2300
2287
  const {
2301
2288
  deprecated,
@@ -2306,13 +2293,7 @@ const getCompletionItemVirtualDom = visibleItem => {
2306
2293
  symbolName,
2307
2294
  top
2308
2295
  } = visibleItem;
2309
- let className = EditorCompletionItem;
2310
- if (focused) {
2311
- className += ' ' + EditorCompletionItemFocused;
2312
- }
2313
- if (deprecated) {
2314
- className += ' ' + EditorCompletionItemDeprecated;
2315
- }
2296
+ const className = getCompletionItemClassName(focused, deprecated);
2316
2297
  return [{
2317
2298
  childCount: 2,
2318
2299
  className,
@@ -2572,11 +2553,15 @@ const commandMap = {
2572
2553
  'Completions.terminate': terminate
2573
2554
  };
2574
2555
 
2575
- const listen = async () => {
2576
- const rpc = await WebWorkerRpcClient.create({
2556
+ const initializeEditorWorker = async () => {
2557
+ const rpc = await create$3({
2577
2558
  commandMap: commandMap
2578
2559
  });
2579
- set$1(rpc);
2560
+ set$2(rpc);
2561
+ };
2562
+
2563
+ const listen = async () => {
2564
+ await initializeEditorWorker();
2580
2565
  };
2581
2566
 
2582
2567
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/completion-worker",
3
- "version": "2.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Web Worker for the completion widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",