@lvce-editor/extension-host-worker 1.4.2 → 1.6.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$a = {
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$a.textDocuments[textDocumentId] = textDocument;
105
105
  };
106
106
  const getDidOpenListeners = () => {
107
- return state$b.onDidSaveTextDocumentListeners;
107
+ return state$a.onDidSaveTextDocumentListeners;
108
108
  };
109
109
  const getWillChangeListeners = () => {
110
- return state$b.onWillChangeEditorListeners;
110
+ return state$a.onWillChangeEditorListeners;
111
111
  };
112
112
  const getDidChangeListeners = () => {
113
- return state$b.onDidChangeTextDocumentListeners;
113
+ return state$a.onDidChangeTextDocumentListeners;
114
114
  };
115
115
  const getDocument = textDocumentId => {
116
- return state$b.textDocuments[textDocumentId];
116
+ return state$a.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
  };
@@ -536,7 +536,7 @@ const registerMethod = ({
536
536
  }) => {
537
537
  context[`execute${name}Provider`] = async function (textDocumentId, ...params) {
538
538
  try {
539
- const textDocument = get$4(textDocumentId);
539
+ const textDocument = get$5(textDocumentId);
540
540
  if (!textDocument) {
541
541
  throw new Error(`textDocument with id ${textDocumentId} not found`);
542
542
  }
@@ -671,12 +671,12 @@ const executeOrganizeImports = async uid => {
671
671
  if (!organizeImportsAction) {
672
672
  return [];
673
673
  }
674
- const textDocument = get$4(uid);
674
+ const textDocument = get$5(uid);
675
675
  const edits = await organizeImportsAction.execute(textDocument);
676
676
  return edits;
677
677
  };
678
678
 
679
- const state$a = {
679
+ const state$9 = {
680
680
  commands: Object.create(null)
681
681
  };
682
682
  const getCommandDisplay = command => {
@@ -699,10 +699,10 @@ const registerCommand = command => {
699
699
  if (!command.execute) {
700
700
  throw new Error('command is missing execute function');
701
701
  }
702
- if (command.id in state$a.commands) {
702
+ if (command.id in state$9.commands) {
703
703
  throw new Error(`command cannot be registered multiple times`);
704
704
  }
705
- state$a.commands[command.id] = command;
705
+ state$9.commands[command.id] = command;
706
706
  } catch (error) {
707
707
  const commandDisplayId = getCommandDisplay(command);
708
708
  throw new VError$1(error, `Failed to register command${commandDisplayId}`);
@@ -710,7 +710,7 @@ const registerCommand = command => {
710
710
  };
711
711
  const executeCommand = async (id, ...args) => {
712
712
  try {
713
- const command = state$a.commands[id];
713
+ const command = state$9.commands[id];
714
714
  if (!command) {
715
715
  throw new Error(`command ${id} not found`);
716
716
  }
@@ -749,14 +749,14 @@ const {
749
749
  }]
750
750
  });
751
751
 
752
- const state$9 = {
752
+ const state$8 = {
753
753
  configuration: Object.create(null)
754
754
  };
755
755
  const getConfiguration = key => {
756
- return state$9.configuration[key] ?? '';
756
+ return state$8.configuration[key] ?? '';
757
757
  };
758
758
  const setConfigurations = preferences => {
759
- state$9.configuration = preferences;
759
+ state$8.configuration = preferences;
760
760
  };
761
761
 
762
762
  const Two = '2.0';
@@ -804,20 +804,20 @@ const number = value => {
804
804
  const state$1$1 = {
805
805
  callbacks: Object.create(null)
806
806
  };
807
- const set$3 = (id, fn) => {
807
+ const set$4 = (id, fn) => {
808
808
  state$1$1.callbacks[id] = fn;
809
809
  };
810
- const get$3 = id => {
810
+ const get$4 = id => {
811
811
  return state$1$1.callbacks[id];
812
812
  };
813
813
  const remove = id => {
814
814
  delete state$1$1.callbacks[id];
815
815
  };
816
- const state$8 = {
816
+ const state$7 = {
817
817
  id: 0
818
818
  };
819
819
  const create$3$1 = () => {
820
- return ++state$8.id;
820
+ return ++state$7.id;
821
821
  };
822
822
  const warn = (...args) => {
823
823
  console.warn(...args);
@@ -841,7 +841,7 @@ const registerPromise = () => {
841
841
  resolve,
842
842
  promise
843
843
  } = withResolvers$2();
844
- set$3(id, resolve);
844
+ set$4(id, resolve);
845
845
  return {
846
846
  id,
847
847
  promise
@@ -849,7 +849,7 @@ const registerPromise = () => {
849
849
  };
850
850
  const resolve = (id, args) => {
851
851
  number(id);
852
- const fn = get$3(id);
852
+ const fn = get$4(id);
853
853
  if (!fn) {
854
854
  console.log(args);
855
855
  warn(`callback ${id} may already be disposed`);
@@ -1159,13 +1159,13 @@ class CommandNotFoundError extends Error {
1159
1159
  }
1160
1160
  }
1161
1161
 
1162
- const state$7 = {};
1162
+ const state$6 = {};
1163
1163
  const register$1 = commandMap => {
1164
- Object.assign(state$7, commandMap);
1164
+ Object.assign(state$6, commandMap);
1165
1165
  };
1166
1166
  const execute = (method, ...params) => {
1167
1167
  // @ts-ignore
1168
- const fn = state$7[method];
1168
+ const fn = state$6[method];
1169
1169
  // @ts-ignore
1170
1170
  if (!fn) {
1171
1171
  throw new CommandNotFoundError(method);
@@ -1191,41 +1191,41 @@ const handleIpc = ipc => {
1191
1191
  ipc.addEventListener('message', handleMessage);
1192
1192
  };
1193
1193
 
1194
- const state$6 = {
1194
+ const state$5 = {
1195
1195
  /**
1196
1196
  * @type {any}
1197
1197
  */
1198
1198
  ipc: undefined
1199
1199
  };
1200
- const get$2 = () => {
1201
- return state$6.ipc;
1200
+ const get$3 = () => {
1201
+ return state$5.ipc;
1202
1202
  };
1203
- const set$2 = ipc => {
1204
- state$6.ipc = ipc;
1203
+ const set$3 = ipc => {
1204
+ state$5.ipc = ipc;
1205
1205
  };
1206
1206
 
1207
1207
  const send = (method, ...params) => {
1208
- const ipc = get$2();
1208
+ const ipc = get$3();
1209
1209
  send$1(ipc, method, ...params);
1210
1210
  };
1211
1211
  const invoke = (method, ...params) => {
1212
- const ipc = get$2();
1212
+ const ipc = get$3();
1213
1213
  return invoke$1(ipc, method, ...params);
1214
1214
  };
1215
1215
  const invokeAndTransfer = (method, ...params) => {
1216
- const ipc = get$2();
1216
+ const ipc = get$3();
1217
1217
  return invokeAndTransfer$1(ipc, method, ...params);
1218
1218
  };
1219
1219
  const listen$2 = ipc => {
1220
1220
  handleIpc(ipc);
1221
- set$2(ipc);
1221
+ set$3(ipc);
1222
1222
  };
1223
1223
 
1224
- const state$5 = {
1224
+ const state$4 = {
1225
1225
  debugProviderMap: Object.create(null)
1226
1226
  };
1227
1227
  const getDebugProvider = id => {
1228
- const provider = state$5.debugProviderMap[id];
1228
+ const provider = state$4.debugProviderMap[id];
1229
1229
  if (!provider) {
1230
1230
  // @ts-ignore
1231
1231
  throw new VError$1(`no debug provider "${id}" found`);
@@ -1236,7 +1236,7 @@ const registerDebugProvider = debugProvider => {
1236
1236
  if (!debugProvider.id) {
1237
1237
  throw new Error('Failed to register debug system provider: missing id');
1238
1238
  }
1239
- state$5.debugProviderMap[debugProvider.id] = debugProvider;
1239
+ state$4.debugProviderMap[debugProvider.id] = debugProvider;
1240
1240
  };
1241
1241
  const start = async (protocol, path) => {
1242
1242
  try {
@@ -1391,26 +1391,31 @@ const exec = async (command, args, options) => {
1391
1391
  throw new DepecratedError(`vscode.exec is deprecated, use createNodeRpc instead`);
1392
1392
  };
1393
1393
 
1394
- const state$4 = {
1395
- fileSystemProviderMap: Object.create(null)
1396
- };
1397
- const getFileSystemProvider = protocol => {
1398
- const provider = state$4.fileSystemProviderMap[protocol];
1394
+ const fileSystemProviderMap = Object.create(null);
1395
+ const get$2 = protocol => {
1396
+ const provider = fileSystemProviderMap[protocol];
1399
1397
  if (!provider) {
1400
1398
  // @ts-ignore
1401
1399
  throw new VError$1(`no file system provider for protocol "${protocol}" found`);
1402
1400
  }
1403
1401
  return provider;
1404
1402
  };
1403
+ const set$2 = (id, provider) => {
1404
+ if (!id) {
1405
+ throw new Error('Failed to register file system provider: missing id');
1406
+ }
1407
+ fileSystemProviderMap[id] = provider;
1408
+ };
1409
+
1405
1410
  const registerFileSystemProvider = fileSystemProvider => {
1406
1411
  if (!fileSystemProvider.id) {
1407
1412
  throw new Error('Failed to register file system provider: missing id');
1408
1413
  }
1409
- state$4.fileSystemProviderMap[fileSystemProvider.id] = fileSystemProvider;
1414
+ set$2(fileSystemProvider.id, fileSystemProvider);
1410
1415
  };
1411
1416
  const readDirWithFileTypes = async (protocol, path) => {
1412
1417
  try {
1413
- const provider = getFileSystemProvider(protocol);
1418
+ const provider = get$2(protocol);
1414
1419
  return await provider.readDirWithFileTypes(path);
1415
1420
  } catch (error) {
1416
1421
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1418,7 +1423,7 @@ const readDirWithFileTypes = async (protocol, path) => {
1418
1423
  };
1419
1424
  const readFile = async (protocol, path) => {
1420
1425
  try {
1421
- const provider = getFileSystemProvider(protocol);
1426
+ const provider = get$2(protocol);
1422
1427
  return await provider.readFile(path);
1423
1428
  } catch (error) {
1424
1429
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1434,9 +1439,19 @@ const readFileExternal = async path => {
1434
1439
  const content = await invoke('FileSystem.readFile', path);
1435
1440
  return content;
1436
1441
  };
1442
+ const readDirWithFileTypesExternal = async path => {
1443
+ // TODO when file is local,
1444
+ // don't ask renderer worker
1445
+ // instead read file directly from shared process
1446
+ // this avoid parsing the potentially large message
1447
+ // and improve performance by not blocking the renderer worker
1448
+ // when reading / writing large files
1449
+ const content = await invoke('FileSystem.readDirWithFileTypes', path);
1450
+ return content;
1451
+ };
1437
1452
  const writeFile = async (protocol, uri, content) => {
1438
1453
  try {
1439
- const provider = getFileSystemProvider(protocol);
1454
+ const provider = get$2(protocol);
1440
1455
  return await provider.writeFile(uri, content);
1441
1456
  } catch (error) {
1442
1457
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1444,95 +1459,13 @@ const writeFile = async (protocol, uri, content) => {
1444
1459
  };
1445
1460
  const getPathSeparator = protocol => {
1446
1461
  try {
1447
- const provider = getFileSystemProvider(protocol);
1462
+ const provider = get$2(protocol);
1448
1463
  return provider.pathSeparator;
1449
1464
  } catch (error) {
1450
1465
  throw new VError$1(error, 'Failed to execute file system provider');
1451
1466
  }
1452
1467
  };
1453
1468
 
1454
- const webViews = Object.create(null);
1455
- const webViewProviders = Object.create(null);
1456
- const getProvider = providerId => {
1457
- return webViewProviders[providerId];
1458
- };
1459
- const setProvider = (providerId, provider) => {
1460
- webViewProviders[providerId] = provider;
1461
- };
1462
- const getWebView = id => {
1463
- return webViews[id];
1464
- };
1465
- const setWebView = (id, webView) => {
1466
- webViews[id] = webView;
1467
- };
1468
-
1469
- // TODO pass uuid to allow having multiple webviews open at the same time
1470
- const createWebView = async (providerId, port, uri, uid, origin) => {
1471
- const provider = getProvider(providerId);
1472
- if (!provider) {
1473
- throw new Error(`webview provider ${providerId} not found`);
1474
- }
1475
-
1476
- // TODO cancel promise when webview is disposed before sending message
1477
- // TODO handle case when webview doesn't send ready message
1478
- // TODO handle error
1479
- await new Promise(resolve => {
1480
- port.onmessage = resolve;
1481
- });
1482
-
1483
- // TODO use ipc module
1484
- const handlePortMessage = async event => {
1485
- const {
1486
- data,
1487
- target
1488
- } = event;
1489
- const {
1490
- method,
1491
- params,
1492
- id
1493
- } = data;
1494
- if (provider && provider.commands && provider.commands[method]) {
1495
- const fn = provider.commands[method];
1496
- const result = await fn(...params);
1497
- if (id) {
1498
- target.postMessage({
1499
- jsonrpc: '2.0',
1500
- id,
1501
- result
1502
- });
1503
- }
1504
- }
1505
- };
1506
- port.onmessage = handlePortMessage;
1507
- const rpc = {
1508
- uri,
1509
- provider,
1510
- uid,
1511
- origin,
1512
- invoke(method, ...params) {
1513
- // TODO return promise with result
1514
- port.postMessage({
1515
- jsonrpc: '2.0',
1516
- method,
1517
- params
1518
- });
1519
- }
1520
- };
1521
- // TODO allow creating multiple webviews per provider
1522
- setWebView(providerId, rpc);
1523
- };
1524
- const load = async providerId => {
1525
- const rpc = getWebView(providerId);
1526
- await rpc.provider.create(rpc, rpc.uri);
1527
- };
1528
- const disposeWebView = id => {
1529
- // TODO race condition
1530
- // const webView=webViews[id]
1531
- };
1532
- const registerWebViewProvider = provider => {
1533
- setProvider(provider.id, provider);
1534
- };
1535
-
1536
1469
  const {
1537
1470
  registerFormattingProvider,
1538
1471
  executeFormattingProvider,
@@ -2080,32 +2013,6 @@ const {
2080
2013
  }
2081
2014
  });
2082
2015
 
2083
- const createWorker = async ({
2084
- method,
2085
- url,
2086
- name
2087
- }) => {
2088
- string(method);
2089
- string(url);
2090
- string(name);
2091
- const ipc = create$7({
2092
- method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
2093
- url,
2094
- name
2095
- });
2096
- return ipc;
2097
- };
2098
-
2099
- const state$1 = {
2100
- workspacePath: ''
2101
- };
2102
- const setWorkspacePath = path => {
2103
- state$1.workspacePath = path;
2104
- };
2105
- const getWorkspaceFolder = path => {
2106
- return state$1.workspacePath;
2107
- };
2108
-
2109
2016
  const RE_PROTOCOL = /^([a-z\-]+):\/\//;
2110
2017
  const getProtocol = uri => {
2111
2018
  const protocolMatch = uri.match(RE_PROTOCOL);
@@ -2168,6 +2075,21 @@ const createWebViewIpc = async webView => {
2168
2075
  return ipc;
2169
2076
  };
2170
2077
 
2078
+ const webViews = Object.create(null);
2079
+ const webViewProviders = Object.create(null);
2080
+ const getProvider = providerId => {
2081
+ return webViewProviders[providerId];
2082
+ };
2083
+ const setProvider = (providerId, provider) => {
2084
+ webViewProviders[providerId] = provider;
2085
+ };
2086
+ const getWebView = id => {
2087
+ return webViews[id];
2088
+ };
2089
+ const setWebView = (id, webView) => {
2090
+ webViews[id] = webView;
2091
+ };
2092
+
2171
2093
  // TODO if webViewId is provided,
2172
2094
  // 1. read file as blob
2173
2095
  // 2. send blob to webview
@@ -2228,6 +2150,99 @@ const getRemoteUrl = async (uri, options = {}) => {
2228
2150
  throw new Error(`unsupported platform for remote url`);
2229
2151
  };
2230
2152
 
2153
+ // TODO pass uuid to allow having multiple webviews open at the same time
2154
+ const createWebView = async (providerId, port, uri, uid, origin) => {
2155
+ const provider = getProvider(providerId);
2156
+ if (!provider) {
2157
+ throw new Error(`webview provider ${providerId} not found`);
2158
+ }
2159
+
2160
+ // TODO cancel promise when webview is disposed before sending message
2161
+ // TODO handle case when webview doesn't send ready message
2162
+ // TODO handle error
2163
+ await new Promise(resolve => {
2164
+ port.onmessage = resolve;
2165
+ });
2166
+
2167
+ // TODO use ipc module
2168
+ const handlePortMessage = async event => {
2169
+ const {
2170
+ data,
2171
+ target
2172
+ } = event;
2173
+ const {
2174
+ method,
2175
+ params,
2176
+ id
2177
+ } = data;
2178
+ if (provider && provider.commands && provider.commands[method]) {
2179
+ const fn = provider.commands[method];
2180
+ const result = await fn(...params);
2181
+ if (id) {
2182
+ target.postMessage({
2183
+ jsonrpc: '2.0',
2184
+ id,
2185
+ result
2186
+ });
2187
+ }
2188
+ }
2189
+ };
2190
+ port.onmessage = handlePortMessage;
2191
+ const rpc = {
2192
+ uri,
2193
+ provider,
2194
+ uid,
2195
+ origin,
2196
+ invoke(method, ...params) {
2197
+ // TODO return promise with result
2198
+ port.postMessage({
2199
+ jsonrpc: '2.0',
2200
+ method,
2201
+ params
2202
+ });
2203
+ }
2204
+ };
2205
+ // TODO allow creating multiple webviews per provider
2206
+ setWebView(providerId, rpc);
2207
+ };
2208
+ const load = async providerId => {
2209
+ const rpc = getWebView(providerId);
2210
+ await rpc.provider.create(rpc, rpc.uri);
2211
+ };
2212
+ const disposeWebView = id => {
2213
+ // TODO race condition
2214
+ // const webView=webViews[id]
2215
+ };
2216
+ const registerWebViewProvider = provider => {
2217
+ setProvider(provider.id, provider);
2218
+ };
2219
+
2220
+ const createWorker = async ({
2221
+ method,
2222
+ url,
2223
+ name
2224
+ }) => {
2225
+ string(method);
2226
+ string(url);
2227
+ string(name);
2228
+ const ipc = create$7({
2229
+ method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
2230
+ url,
2231
+ name
2232
+ });
2233
+ return ipc;
2234
+ };
2235
+
2236
+ const state$1 = {
2237
+ workspacePath: ''
2238
+ };
2239
+ const setWorkspacePath = path => {
2240
+ state$1.workspacePath = path;
2241
+ };
2242
+ const getWorkspaceFolder = path => {
2243
+ return state$1.workspacePath;
2244
+ };
2245
+
2231
2246
  class FormattingError extends Error {
2232
2247
  constructor(message, codeFrame) {
2233
2248
  super(message);
@@ -2286,6 +2301,7 @@ const api = {
2286
2301
  // File System
2287
2302
  registerFileSystemProvider: registerFileSystemProvider,
2288
2303
  readFile: readFileExternal,
2304
+ readDirWithFileTypes: readDirWithFileTypesExternal,
2289
2305
  // Formatting
2290
2306
  registerFormattingProvider: registerFormattingProvider,
2291
2307
  executeFormattingProvider: executeFormattingProvider,
@@ -2909,6 +2925,12 @@ const registerChangeListener = () => {
2909
2925
  // TODO
2910
2926
  };
2911
2927
 
2928
+ const handleBeforeUnload = () => {
2929
+ // TODO save all webviews in localstorage
2930
+ // cannot use indexeddb during unload
2931
+ console.log('before unload');
2932
+ };
2933
+
2912
2934
  const MessagePort$1 = 1;
2913
2935
  const ModuleWorker = 2;
2914
2936
  const ModuleWorkerWithMessagePort = 4;
@@ -3385,6 +3407,7 @@ const commandMap = {
3385
3407
  ['ExtensionHostWebView.create']: createWebView,
3386
3408
  ['ExtensionHostWebView.dispose']: disposeWebView,
3387
3409
  ['ExtensionHostWebView.load']: load,
3410
+ ['HandleBeforeUnload.handleBeforeUnload']: handleBeforeUnload,
3388
3411
  ['HandleMessagePort.handleMessagePort']: handleMessagePort,
3389
3412
  [BraceCompletionExecuteBraceCompletionProvider]: executeBraceCompletionProvider,
3390
3413
  [ClosingTagExecuteClosingTagProvider]: executeClosingTagProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "1.4.2",
3
+ "version": "1.6.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",