@lvce-editor/extension-host-worker 1.2.0 → 1.3.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.
@@ -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$3 = textDocumentId => {
306
+ const get$4 = 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$3(textDocumentId);
539
+ const textDocument = get$4(textDocumentId);
540
540
  if (!textDocument) {
541
541
  throw new Error(`textDocument with id ${textDocumentId} not found`);
542
542
  }
@@ -671,7 +671,7 @@ const executeOrganizeImports = async uid => {
671
671
  if (!organizeImportsAction) {
672
672
  return [];
673
673
  }
674
- const textDocument = get$3(uid);
674
+ const textDocument = get$4(uid);
675
675
  const edits = await organizeImportsAction.execute(textDocument);
676
676
  return edits;
677
677
  };
@@ -804,10 +804,10 @@ const number = value => {
804
804
  const state$1$1 = {
805
805
  callbacks: Object.create(null)
806
806
  };
807
- const set$2 = (id, fn) => {
807
+ const set$3 = (id, fn) => {
808
808
  state$1$1.callbacks[id] = fn;
809
809
  };
810
- const get$2 = id => {
810
+ const get$3 = id => {
811
811
  return state$1$1.callbacks[id];
812
812
  };
813
813
  const remove = id => {
@@ -841,7 +841,7 @@ const registerPromise = () => {
841
841
  resolve,
842
842
  promise
843
843
  } = withResolvers$2();
844
- set$2(id, resolve);
844
+ set$3(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$2(id);
852
+ const fn = get$3(id);
853
853
  if (!fn) {
854
854
  console.log(args);
855
855
  warn(`callback ${id} may already be disposed`);
@@ -1160,7 +1160,7 @@ class CommandNotFoundError extends Error {
1160
1160
  }
1161
1161
 
1162
1162
  const state$7 = {};
1163
- const register = commandMap => {
1163
+ const register$1 = commandMap => {
1164
1164
  Object.assign(state$7, commandMap);
1165
1165
  };
1166
1166
  const execute = (method, ...params) => {
@@ -1197,28 +1197,28 @@ const state$6 = {
1197
1197
  */
1198
1198
  ipc: undefined
1199
1199
  };
1200
- const get$1 = () => {
1200
+ const get$2 = () => {
1201
1201
  return state$6.ipc;
1202
1202
  };
1203
- const set$1 = ipc => {
1203
+ const set$2 = ipc => {
1204
1204
  state$6.ipc = ipc;
1205
1205
  };
1206
1206
 
1207
1207
  const send = (method, ...params) => {
1208
- const ipc = get$1();
1208
+ const ipc = get$2();
1209
1209
  send$1(ipc, method, ...params);
1210
1210
  };
1211
1211
  const invoke = (method, ...params) => {
1212
- const ipc = get$1();
1212
+ const ipc = get$2();
1213
1213
  return invoke$1(ipc, method, ...params);
1214
1214
  };
1215
1215
  const invokeAndTransfer = (method, ...params) => {
1216
- const ipc = get$1();
1216
+ const ipc = get$2();
1217
1217
  return invokeAndTransfer$1(ipc, method, ...params);
1218
1218
  };
1219
1219
  const listen$2 = ipc => {
1220
1220
  handleIpc(ipc);
1221
- set$1(ipc);
1221
+ set$2(ipc);
1222
1222
  };
1223
1223
 
1224
1224
  const state$5 = {
@@ -1771,25 +1771,44 @@ const {
1771
1771
  }]
1772
1772
  });
1773
1773
 
1774
- const rpcs = Object.create(null);
1774
+ const getExtensionHostSubWorkerUrl = () => {
1775
+ return new URL('../../../../extension-host-sub-worker/src/extensionHostSubWorkerMain.js', import.meta.url).toString();
1776
+ };
1777
+ const extensionHostSubWorkerUrl = getExtensionHostSubWorkerUrl();
1778
+
1779
+ const set$1 = async (url, contentSecurityPolicy) => {
1780
+ const pathName = new URL(url).pathname;
1781
+ await invoke('ExtensionHostWorkerContentSecurityPolicy.set', pathName, contentSecurityPolicy);
1782
+ };
1783
+
1784
+ const rpcs$1 = Object.create(null);
1775
1785
  const add$1 = (id, rpc) => {
1776
- rpcs[id] = rpc;
1786
+ rpcs$1[id] = rpc;
1787
+ };
1788
+ const get$1 = id => {
1789
+ return rpcs$1[id];
1790
+ };
1791
+
1792
+ const registry = Object.create(null);
1793
+ const rpcs = Object.create(null);
1794
+ const register = (id, execute) => {
1795
+ registry[id] = execute;
1796
+ };
1797
+ const acquire = id => {
1798
+ const fn = registry[id];
1799
+ delete registry[id];
1800
+ return fn;
1777
1801
  };
1778
1802
  const get = id => {
1779
1803
  return rpcs[id];
1780
1804
  };
1781
-
1782
- const getExtensionHostSubWorkerUrl = () => {
1783
- return new URL('../../../../extension-host-sub-worker/src/extensionHostSubWorkerMain.js', import.meta.url).toString();
1805
+ const set = (id, rpc) => {
1806
+ rpcs[id] = rpc;
1784
1807
  };
1785
- const extensionHostSubWorkerUrl = getExtensionHostSubWorkerUrl();
1786
1808
 
1787
- const createRpcWithId = async ({
1788
- id,
1789
- execute
1790
- }) => {
1791
- string(id);
1792
- const info = get(id);
1809
+ const createRpcWithId$1 = async id => {
1810
+ const fn = acquire(id);
1811
+ const info = get$1(id);
1793
1812
  if (!info) {
1794
1813
  throw new Error(`rpc with id ${id} not found`);
1795
1814
  }
@@ -1798,24 +1817,72 @@ const createRpcWithId = async ({
1798
1817
  url: extensionHostSubWorkerUrl,
1799
1818
  name: info.name
1800
1819
  });
1801
- const rpc = await create$6({
1820
+ const newRpc = await create$6({
1802
1821
  ipc,
1803
1822
  method: JsonRpc,
1804
- execute
1823
+ execute: fn
1805
1824
  });
1806
- await rpc.invoke('LoadFile.loadFile', info.url);
1807
- return rpc;
1825
+ await newRpc.invoke('LoadFile.loadFile', info.url);
1826
+ set(id, newRpc);
1827
+ return newRpc;
1808
1828
  };
1809
1829
 
1810
- const set = async (url, contentSecurityPolicy) => {
1811
- const pathName = new URL(url).pathname;
1812
- await invoke('ExtensionHostWorkerContentSecurityPolicy.set', pathName, contentSecurityPolicy);
1830
+ const getOrCreateRpc = async id => {
1831
+ const rpc = get(id);
1832
+ if (!rpc) {
1833
+ set(id, createRpcWithId$1(id));
1834
+ }
1835
+ return get(id);
1836
+ };
1837
+ const createRpcWithId = ({
1838
+ id,
1839
+ execute
1840
+ }) => {
1841
+ string(id);
1842
+ register(id, execute);
1843
+ const lazyRpc = {
1844
+ async invoke(method, ...params) {
1845
+ const rpc = await getOrCreateRpc(id);
1846
+ await rpc.invoke(method, ...params);
1847
+ }
1848
+ };
1849
+ return lazyRpc;
1813
1850
  };
1814
1851
 
1815
1852
  const defaultExecute = () => {
1816
1853
  throw new Error('not implemented');
1817
1854
  };
1818
- const createRpc = async ({
1855
+
1856
+ /**
1857
+ *
1858
+ * @deprecated
1859
+ */
1860
+ const createLegacyRpc = async ({
1861
+ url,
1862
+ name,
1863
+ execute = defaultExecute,
1864
+ contentSecurityPolicy
1865
+ }) => {
1866
+ string(url);
1867
+ string(name);
1868
+ fn(execute);
1869
+ if (contentSecurityPolicy) {
1870
+ await set$1(url, contentSecurityPolicy);
1871
+ }
1872
+ const ipc = await create$7({
1873
+ method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
1874
+ url: extensionHostSubWorkerUrl,
1875
+ name
1876
+ });
1877
+ const rpc = await create$6({
1878
+ ipc,
1879
+ method: JsonRpc,
1880
+ execute
1881
+ });
1882
+ await rpc.invoke('LoadFile.loadFile', url);
1883
+ return rpc;
1884
+ };
1885
+ const createRpc = ({
1819
1886
  id,
1820
1887
  url,
1821
1888
  name,
@@ -1825,32 +1892,17 @@ const createRpc = async ({
1825
1892
  try {
1826
1893
  if (id) {
1827
1894
  string(id);
1828
- const rpc = await createRpcWithId({
1895
+ return createRpcWithId({
1829
1896
  id,
1830
1897
  execute
1831
1898
  });
1832
- return rpc;
1833
- }
1834
-
1835
- // deprecated
1836
- string(url);
1837
- string(name);
1838
- fn(execute);
1839
- if (contentSecurityPolicy) {
1840
- await set(url, contentSecurityPolicy);
1841
1899
  }
1842
- const ipc = await create$7({
1843
- method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
1844
- url: extensionHostSubWorkerUrl,
1845
- name
1900
+ return createLegacyRpc({
1901
+ url,
1902
+ name,
1903
+ execute,
1904
+ contentSecurityPolicy
1846
1905
  });
1847
- const rpc = await create$6({
1848
- ipc,
1849
- method: JsonRpc,
1850
- execute
1851
- });
1852
- await rpc.invoke('LoadFile.loadFile', url);
1853
- return rpc;
1854
1906
  } catch (error) {
1855
1907
  throw new VError$1(error, `Failed to create webworker rpc`);
1856
1908
  }
@@ -3434,7 +3486,7 @@ const main = async () => {
3434
3486
  self.addEventListener('securitypolicyviolation', handleContentSecurityPolicyViolation);
3435
3487
  }
3436
3488
  globalThis.vscode = api;
3437
- register(commandMap);
3489
+ register$1(commandMap);
3438
3490
  const ipc = await listen({
3439
3491
  method: Auto()
3440
3492
  });
@@ -3632,7 +3684,7 @@ const create$2 = async ({
3632
3684
  port1,
3633
3685
  port2
3634
3686
  } = getPortTuple();
3635
- await invokeAndTransfer([port1], 'IpcParent.create', {
3687
+ await invokeAndTransfer('IpcParent.create', {
3636
3688
  method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
3637
3689
  url,
3638
3690
  name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",