@lvce-editor/extension-host-worker 1.5.0 → 1.7.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.
@@ -89,7 +89,7 @@ const fn = value => {
89
89
  }
90
90
  };
91
91
 
92
- const state$b = {
92
+ const state$9 = {
93
93
  /** @type{any[]} */
94
94
  onDidOpenEditorListeners: [],
95
95
  /** @type{any[]} */
@@ -101,19 +101,19 @@ const state$b = {
101
101
  textDocuments: Object.create(null)
102
102
  };
103
103
  const setDocument = (textDocumentId, textDocument) => {
104
- state$b.textDocuments[textDocumentId] = textDocument;
104
+ state$9.textDocuments[textDocumentId] = textDocument;
105
105
  };
106
106
  const getDidOpenListeners = () => {
107
- return state$b.onDidSaveTextDocumentListeners;
107
+ return state$9.onDidSaveTextDocumentListeners;
108
108
  };
109
109
  const getWillChangeListeners = () => {
110
- return state$b.onWillChangeEditorListeners;
110
+ return state$9.onWillChangeEditorListeners;
111
111
  };
112
112
  const getDidChangeListeners = () => {
113
- return state$b.onDidChangeTextDocumentListeners;
113
+ return state$9.onDidChangeTextDocumentListeners;
114
114
  };
115
115
  const getDocument = textDocumentId => {
116
- return state$b.textDocuments[textDocumentId];
116
+ return state$9.textDocuments[textDocumentId];
117
117
  };
118
118
 
119
119
  const getOffset$1 = (textDocument, position) => {
@@ -303,7 +303,7 @@ const syncIncremental = (textDocumentId, changes) => {
303
303
  textDocument.text = before + syntheticChange.inserted + after;
304
304
  runListenersSafe(getDidChangeListeners(), textDocument, syntheticChanges);
305
305
  };
306
- const get$4 = textDocumentId => {
306
+ const get$5 = textDocumentId => {
307
307
  const textDocument = getDocument(textDocumentId);
308
308
  return textDocument;
309
309
  };
@@ -320,7 +320,6 @@ const setLanguageId = (textDocumentId, languageId) => {
320
320
  };
321
321
 
322
322
  const BABEL_PARSER_SYNTAX_ERROR = 'BABEL_PARSER_SYNTAX_ERROR';
323
- const E_COMMAND_NOT_FOUND$1 = 'E_COMMAND_NOT_FOUND';
324
323
  const E_NO_PROVIDER_FOUND = 'E_NO_PROVIDER_FOUND';
325
324
 
326
325
  class NoProviderFoundError extends Error {
@@ -536,7 +535,7 @@ const registerMethod = ({
536
535
  }) => {
537
536
  context[`execute${name}Provider`] = async function (textDocumentId, ...params) {
538
537
  try {
539
- const textDocument = get$4(textDocumentId);
538
+ const textDocument = get$5(textDocumentId);
540
539
  if (!textDocument) {
541
540
  throw new Error(`textDocument with id ${textDocumentId} not found`);
542
541
  }
@@ -671,12 +670,12 @@ const executeOrganizeImports = async uid => {
671
670
  if (!organizeImportsAction) {
672
671
  return [];
673
672
  }
674
- const textDocument = get$4(uid);
673
+ const textDocument = get$5(uid);
675
674
  const edits = await organizeImportsAction.execute(textDocument);
676
675
  return edits;
677
676
  };
678
677
 
679
- const state$a = {
678
+ const state$8 = {
680
679
  commands: Object.create(null)
681
680
  };
682
681
  const getCommandDisplay = command => {
@@ -685,7 +684,7 @@ const getCommandDisplay = command => {
685
684
  }
686
685
  return '';
687
686
  };
688
- const registerCommand = command => {
687
+ const registerCommand$1 = command => {
689
688
  try {
690
689
  if (!command) {
691
690
  if (command === null) {
@@ -699,10 +698,10 @@ const registerCommand = command => {
699
698
  if (!command.execute) {
700
699
  throw new Error('command is missing execute function');
701
700
  }
702
- if (command.id in state$a.commands) {
701
+ if (command.id in state$8.commands) {
703
702
  throw new Error(`command cannot be registered multiple times`);
704
703
  }
705
- state$a.commands[command.id] = command;
704
+ state$8.commands[command.id] = command;
706
705
  } catch (error) {
707
706
  const commandDisplayId = getCommandDisplay(command);
708
707
  throw new VError$1(error, `Failed to register command${commandDisplayId}`);
@@ -710,7 +709,7 @@ const registerCommand = command => {
710
709
  };
711
710
  const executeCommand = async (id, ...args) => {
712
711
  try {
713
- const command = state$a.commands[id];
712
+ const command = state$8.commands[id];
714
713
  if (!command) {
715
714
  throw new Error(`command ${id} not found`);
716
715
  }
@@ -749,14 +748,14 @@ const {
749
748
  }]
750
749
  });
751
750
 
752
- const state$9 = {
751
+ const state$7 = {
753
752
  configuration: Object.create(null)
754
753
  };
755
754
  const getConfiguration = key => {
756
- return state$9.configuration[key] ?? '';
755
+ return state$7.configuration[key] ?? '';
757
756
  };
758
757
  const setConfigurations = preferences => {
759
- state$9.configuration = preferences;
758
+ state$7.configuration = preferences;
760
759
  };
761
760
 
762
761
  const Two = '2.0';
@@ -804,20 +803,20 @@ const number = value => {
804
803
  const state$1$1 = {
805
804
  callbacks: Object.create(null)
806
805
  };
807
- const set$3 = (id, fn) => {
806
+ const set$4 = (id, fn) => {
808
807
  state$1$1.callbacks[id] = fn;
809
808
  };
810
- const get$3 = id => {
809
+ const get$4 = id => {
811
810
  return state$1$1.callbacks[id];
812
811
  };
813
812
  const remove = id => {
814
813
  delete state$1$1.callbacks[id];
815
814
  };
816
- const state$8 = {
815
+ const state$6 = {
817
816
  id: 0
818
817
  };
819
818
  const create$3$1 = () => {
820
- return ++state$8.id;
819
+ return ++state$6.id;
821
820
  };
822
821
  const warn = (...args) => {
823
822
  console.warn(...args);
@@ -841,7 +840,7 @@ const registerPromise = () => {
841
840
  resolve,
842
841
  promise
843
842
  } = withResolvers$2();
844
- set$3(id, resolve);
843
+ set$4(id, resolve);
845
844
  return {
846
845
  id,
847
846
  promise
@@ -849,7 +848,7 @@ const registerPromise = () => {
849
848
  };
850
849
  const resolve = (id, args) => {
851
850
  number(id);
852
- const fn = get$3(id);
851
+ const fn = get$4(id);
853
852
  if (!fn) {
854
853
  console.log(args);
855
854
  warn(`callback ${id} may already be disposed`);
@@ -1148,30 +1147,24 @@ const invokeAndTransfer$1 = async (ipc, method, ...params) => {
1148
1147
  return result;
1149
1148
  };
1150
1149
 
1151
- const processName = `extension host worker`;
1152
-
1153
- class CommandNotFoundError extends Error {
1154
- constructor(id) {
1155
- super(`Command "${id}" not found (${processName})`);
1156
- this.name = 'CommandNotFoundError';
1157
- // @ts-ignore
1158
- this.code = E_COMMAND_NOT_FOUND$1;
1159
- }
1160
- }
1161
-
1162
- const state$7 = {};
1150
+ const commands = Object.create(null);
1151
+ const registerCommand = (key, fn) => {
1152
+ commands[key] = fn;
1153
+ };
1163
1154
  const register$1 = commandMap => {
1164
- Object.assign(state$7, commandMap);
1155
+ for (const [key, value] of Object.entries(commandMap)) {
1156
+ registerCommand(key, value);
1157
+ }
1165
1158
  };
1166
- const execute = (method, ...params) => {
1167
- // @ts-ignore
1168
- const fn = state$7[method];
1169
- // @ts-ignore
1159
+ const getCommand = key => {
1160
+ return commands[key];
1161
+ };
1162
+ const execute = (command, ...args) => {
1163
+ const fn = getCommand(command);
1170
1164
  if (!fn) {
1171
- throw new CommandNotFoundError(method);
1165
+ throw new Error(`command not found ${command}`);
1172
1166
  }
1173
- // @ts-ignore
1174
- return fn(...params);
1167
+ return fn(...args);
1175
1168
  };
1176
1169
 
1177
1170
  const requiresSocket$1 = () => {
@@ -1191,41 +1184,41 @@ const handleIpc = ipc => {
1191
1184
  ipc.addEventListener('message', handleMessage);
1192
1185
  };
1193
1186
 
1194
- const state$6 = {
1187
+ const state$5 = {
1195
1188
  /**
1196
1189
  * @type {any}
1197
1190
  */
1198
1191
  ipc: undefined
1199
1192
  };
1200
- const get$2 = () => {
1201
- return state$6.ipc;
1193
+ const get$3 = () => {
1194
+ return state$5.ipc;
1202
1195
  };
1203
- const set$2 = ipc => {
1204
- state$6.ipc = ipc;
1196
+ const set$3 = ipc => {
1197
+ state$5.ipc = ipc;
1205
1198
  };
1206
1199
 
1207
1200
  const send = (method, ...params) => {
1208
- const ipc = get$2();
1201
+ const ipc = get$3();
1209
1202
  send$1(ipc, method, ...params);
1210
1203
  };
1211
1204
  const invoke = (method, ...params) => {
1212
- const ipc = get$2();
1205
+ const ipc = get$3();
1213
1206
  return invoke$1(ipc, method, ...params);
1214
1207
  };
1215
1208
  const invokeAndTransfer = (method, ...params) => {
1216
- const ipc = get$2();
1209
+ const ipc = get$3();
1217
1210
  return invokeAndTransfer$1(ipc, method, ...params);
1218
1211
  };
1219
1212
  const listen$2 = ipc => {
1220
1213
  handleIpc(ipc);
1221
- set$2(ipc);
1214
+ set$3(ipc);
1222
1215
  };
1223
1216
 
1224
- const state$5 = {
1217
+ const state$4 = {
1225
1218
  debugProviderMap: Object.create(null)
1226
1219
  };
1227
1220
  const getDebugProvider = id => {
1228
- const provider = state$5.debugProviderMap[id];
1221
+ const provider = state$4.debugProviderMap[id];
1229
1222
  if (!provider) {
1230
1223
  // @ts-ignore
1231
1224
  throw new VError$1(`no debug provider "${id}" found`);
@@ -1236,7 +1229,7 @@ const registerDebugProvider = debugProvider => {
1236
1229
  if (!debugProvider.id) {
1237
1230
  throw new Error('Failed to register debug system provider: missing id');
1238
1231
  }
1239
- state$5.debugProviderMap[debugProvider.id] = debugProvider;
1232
+ state$4.debugProviderMap[debugProvider.id] = debugProvider;
1240
1233
  };
1241
1234
  const start = async (protocol, path) => {
1242
1235
  try {
@@ -1391,26 +1384,31 @@ const exec = async (command, args, options) => {
1391
1384
  throw new DepecratedError(`vscode.exec is deprecated, use createNodeRpc instead`);
1392
1385
  };
1393
1386
 
1394
- const state$4 = {
1395
- fileSystemProviderMap: Object.create(null)
1396
- };
1397
- const getFileSystemProvider = protocol => {
1398
- const provider = state$4.fileSystemProviderMap[protocol];
1387
+ const fileSystemProviderMap = Object.create(null);
1388
+ const get$2 = protocol => {
1389
+ const provider = fileSystemProviderMap[protocol];
1399
1390
  if (!provider) {
1400
1391
  // @ts-ignore
1401
1392
  throw new VError$1(`no file system provider for protocol "${protocol}" found`);
1402
1393
  }
1403
1394
  return provider;
1404
1395
  };
1396
+ const set$2 = (id, provider) => {
1397
+ if (!id) {
1398
+ throw new Error('Failed to register file system provider: missing id');
1399
+ }
1400
+ fileSystemProviderMap[id] = provider;
1401
+ };
1402
+
1405
1403
  const registerFileSystemProvider = fileSystemProvider => {
1406
1404
  if (!fileSystemProvider.id) {
1407
1405
  throw new Error('Failed to register file system provider: missing id');
1408
1406
  }
1409
- state$4.fileSystemProviderMap[fileSystemProvider.id] = fileSystemProvider;
1407
+ set$2(fileSystemProvider.id, fileSystemProvider);
1410
1408
  };
1411
1409
  const readDirWithFileTypes = async (protocol, path) => {
1412
1410
  try {
1413
- const provider = getFileSystemProvider(protocol);
1411
+ const provider = get$2(protocol);
1414
1412
  return await provider.readDirWithFileTypes(path);
1415
1413
  } catch (error) {
1416
1414
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1418,7 +1416,7 @@ const readDirWithFileTypes = async (protocol, path) => {
1418
1416
  };
1419
1417
  const readFile = async (protocol, path) => {
1420
1418
  try {
1421
- const provider = getFileSystemProvider(protocol);
1419
+ const provider = get$2(protocol);
1422
1420
  return await provider.readFile(path);
1423
1421
  } catch (error) {
1424
1422
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1434,9 +1432,19 @@ const readFileExternal = async path => {
1434
1432
  const content = await invoke('FileSystem.readFile', path);
1435
1433
  return content;
1436
1434
  };
1435
+ const readDirWithFileTypesExternal = async path => {
1436
+ // TODO when file is local,
1437
+ // don't ask renderer worker
1438
+ // instead read file directly from shared process
1439
+ // this avoid parsing the potentially large message
1440
+ // and improve performance by not blocking the renderer worker
1441
+ // when reading / writing large files
1442
+ const content = await invoke('FileSystem.readDirWithFileTypes', path);
1443
+ return content;
1444
+ };
1437
1445
  const writeFile = async (protocol, uri, content) => {
1438
1446
  try {
1439
- const provider = getFileSystemProvider(protocol);
1447
+ const provider = get$2(protocol);
1440
1448
  return await provider.writeFile(uri, content);
1441
1449
  } catch (error) {
1442
1450
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1444,7 +1452,7 @@ const writeFile = async (protocol, uri, content) => {
1444
1452
  };
1445
1453
  const getPathSeparator = protocol => {
1446
1454
  try {
1447
- const provider = getFileSystemProvider(protocol);
1455
+ const provider = get$2(protocol);
1448
1456
  return provider.pathSeparator;
1449
1457
  } catch (error) {
1450
1458
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -2258,7 +2266,7 @@ const api = {
2258
2266
  // Code Action
2259
2267
  registerCodeActionsProvider: registerCodeActionProvider,
2260
2268
  // Command
2261
- registerCommand: registerCommand,
2269
+ registerCommand: registerCommand$1,
2262
2270
  executeCommand: executeCommand,
2263
2271
  // Completion
2264
2272
  registerCompletionProvider: registerCompletionProvider,
@@ -2286,7 +2294,7 @@ const api = {
2286
2294
  // File System
2287
2295
  registerFileSystemProvider: registerFileSystemProvider,
2288
2296
  readFile: readFileExternal,
2289
- readDirWithFileType: readDirWithFileTypes,
2297
+ readDirWithFileTypes: readDirWithFileTypesExternal,
2290
2298
  // Formatting
2291
2299
  registerFormattingProvider: registerFormattingProvider,
2292
2300
  executeFormattingProvider: executeFormattingProvider,
@@ -2910,6 +2918,12 @@ const registerChangeListener = () => {
2910
2918
  // TODO
2911
2919
  };
2912
2920
 
2921
+ const handleBeforeUnload = () => {
2922
+ // TODO save all webviews in localstorage
2923
+ // cannot use indexeddb during unload
2924
+ console.log('before unload');
2925
+ };
2926
+
2913
2927
  const MessagePort$1 = 1;
2914
2928
  const ModuleWorker = 2;
2915
2929
  const ModuleWorkerWithMessagePort = 4;
@@ -3371,6 +3385,13 @@ const handleMessagePort = port => {
3371
3385
  ipc.send('ready');
3372
3386
  };
3373
3387
 
3388
+ const saveState = () => {
3389
+ console.log('TODO save state');
3390
+ return {
3391
+ x: 1
3392
+ };
3393
+ };
3394
+
3374
3395
  const commandMap = {
3375
3396
  ['ExtensionHostDebug.evaluate']: evaluate,
3376
3397
  ['ExtensionHostDebug.getProperties']: getProperties,
@@ -3386,7 +3407,9 @@ const commandMap = {
3386
3407
  ['ExtensionHostWebView.create']: createWebView,
3387
3408
  ['ExtensionHostWebView.dispose']: disposeWebView,
3388
3409
  ['ExtensionHostWebView.load']: load,
3410
+ ['HandleBeforeUnload.handleBeforeUnload']: handleBeforeUnload,
3389
3411
  ['HandleMessagePort.handleMessagePort']: handleMessagePort,
3412
+ ['SaveState.saveState']: saveState,
3390
3413
  [BraceCompletionExecuteBraceCompletionProvider]: executeBraceCompletionProvider,
3391
3414
  [ClosingTagExecuteClosingTagProvider]: executeClosingTagProvider,
3392
3415
  [CommandExecute]: executeCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",