@lvce-editor/extension-host-worker 1.13.0 → 1.15.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.
@@ -4,13 +4,13 @@ const Function = 3;
4
4
  const Variable = 4;
5
5
  const Keyword = 5;
6
6
  const Folder = 6;
7
- const File$2 = 7;
7
+ const File$3 = 7;
8
8
  const Field = 8;
9
9
 
10
10
  const EditorCompletionType = {
11
11
  __proto__: null,
12
12
  Field,
13
- File: File$2,
13
+ File: File$3,
14
14
  Folder,
15
15
  Function,
16
16
  Keyword,
@@ -89,7 +89,7 @@ const fn = value => {
89
89
  }
90
90
  };
91
91
 
92
- const state$9 = {
92
+ const state$a = {
93
93
  /** @type{any[]} */
94
94
  onDidOpenEditorListeners: [],
95
95
  /** @type{any[]} */
@@ -101,19 +101,19 @@ const state$9 = {
101
101
  textDocuments: Object.create(null)
102
102
  };
103
103
  const setDocument = (textDocumentId, textDocument) => {
104
- state$9.textDocuments[textDocumentId] = textDocument;
104
+ state$a.textDocuments[textDocumentId] = textDocument;
105
105
  };
106
106
  const getDidOpenListeners = () => {
107
- return state$9.onDidSaveTextDocumentListeners;
107
+ return state$a.onDidSaveTextDocumentListeners;
108
108
  };
109
109
  const getWillChangeListeners = () => {
110
- return state$9.onWillChangeEditorListeners;
110
+ return state$a.onWillChangeEditorListeners;
111
111
  };
112
112
  const getDidChangeListeners = () => {
113
- return state$9.onDidChangeTextDocumentListeners;
113
+ return state$a.onDidChangeTextDocumentListeners;
114
114
  };
115
115
  const getDocument = textDocumentId => {
116
- return state$9.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$5 = textDocumentId => {
306
+ const get$6 = textDocumentId => {
307
307
  const textDocument = getDocument(textDocumentId);
308
308
  return textDocument;
309
309
  };
@@ -535,7 +535,7 @@ const registerMethod = ({
535
535
  }) => {
536
536
  context[`execute${name}Provider`] = async function (textDocumentId, ...params) {
537
537
  try {
538
- const textDocument = get$5(textDocumentId);
538
+ const textDocument = get$6(textDocumentId);
539
539
  if (!textDocument) {
540
540
  throw new Error(`textDocument with id ${textDocumentId} not found`);
541
541
  }
@@ -670,12 +670,12 @@ const executeOrganizeImports = async uid => {
670
670
  if (!organizeImportsAction) {
671
671
  return [];
672
672
  }
673
- const textDocument = get$5(uid);
673
+ const textDocument = get$6(uid);
674
674
  const edits = await organizeImportsAction.execute(textDocument);
675
675
  return edits;
676
676
  };
677
677
 
678
- const state$8 = {
678
+ const state$9 = {
679
679
  commands: Object.create(null)
680
680
  };
681
681
  const getCommandDisplay = command => {
@@ -698,10 +698,10 @@ const registerCommand = command => {
698
698
  if (!command.execute) {
699
699
  throw new Error('command is missing execute function');
700
700
  }
701
- if (command.id in state$8.commands) {
701
+ if (command.id in state$9.commands) {
702
702
  throw new Error(`command cannot be registered multiple times`);
703
703
  }
704
- state$8.commands[command.id] = command;
704
+ state$9.commands[command.id] = command;
705
705
  } catch (error) {
706
706
  const commandDisplayId = getCommandDisplay(command);
707
707
  throw new VError$1(error, `Failed to register command${commandDisplayId}`);
@@ -709,7 +709,7 @@ const registerCommand = command => {
709
709
  };
710
710
  const executeCommand = async (id, ...args) => {
711
711
  try {
712
- const command = state$8.commands[id];
712
+ const command = state$9.commands[id];
713
713
  if (!command) {
714
714
  throw new Error(`command ${id} not found`);
715
715
  }
@@ -748,14 +748,14 @@ const {
748
748
  }]
749
749
  });
750
750
 
751
- const state$7 = {
751
+ const state$8 = {
752
752
  configuration: Object.create(null)
753
753
  };
754
754
  const getConfiguration = key => {
755
- return state$7.configuration[key] ?? '';
755
+ return state$8.configuration[key] ?? '';
756
756
  };
757
757
  const setConfigurations = preferences => {
758
- state$7.configuration = preferences;
758
+ state$8.configuration = preferences;
759
759
  };
760
760
 
761
761
  const Two = '2.0';
@@ -767,10 +767,10 @@ const create$4$1 = (method, params) => {
767
767
  };
768
768
  };
769
769
  const callbacks = Object.create(null);
770
- const set$4 = (id, fn) => {
770
+ const set$5 = (id, fn) => {
771
771
  callbacks[id] = fn;
772
772
  };
773
- const get$4 = id => {
773
+ const get$5 = id => {
774
774
  return callbacks[id];
775
775
  };
776
776
  const remove = id => {
@@ -789,14 +789,14 @@ const registerPromise = () => {
789
789
  resolve,
790
790
  promise
791
791
  } = Promise.withResolvers();
792
- set$4(id, resolve);
792
+ set$5(id, resolve);
793
793
  return {
794
794
  id,
795
795
  promise
796
796
  };
797
797
  };
798
798
  const resolve = (id, response) => {
799
- const fn = get$4(id);
799
+ const fn = get$5(id);
800
800
  if (!fn) {
801
801
  console.log(response);
802
802
  warn(`callback ${id} may already be disposed`);
@@ -887,14 +887,14 @@ const joinLines$1 = lines => {
887
887
  };
888
888
  const MethodNotFound = -32601;
889
889
  const Custom = -32001;
890
- const splitLines$1 = lines => {
890
+ const splitLines$2 = lines => {
891
891
  return lines.split(NewLine$2);
892
892
  };
893
893
  const restoreJsonRpcError = error => {
894
894
  if (error && error instanceof Error) {
895
895
  return error;
896
896
  }
897
- const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(1));
897
+ const currentStack = joinLines$1(splitLines$2(new Error().stack || '').slice(1));
898
898
  if (error && error.code && error.code === MethodNotFound) {
899
899
  const restoredError = new JsonRpcError(error.message);
900
900
  const parentStack = getParentStack(error);
@@ -1136,41 +1136,41 @@ const handleIpc = ipc => {
1136
1136
  ipc.addEventListener('message', handleMessage);
1137
1137
  };
1138
1138
 
1139
- const state$6 = {
1139
+ const state$7 = {
1140
1140
  /**
1141
1141
  * @type {any}
1142
1142
  */
1143
1143
  ipc: undefined
1144
1144
  };
1145
- const get$3 = () => {
1146
- return state$6.ipc;
1145
+ const get$4 = () => {
1146
+ return state$7.ipc;
1147
1147
  };
1148
- const set$3 = ipc => {
1149
- state$6.ipc = ipc;
1148
+ const set$4 = ipc => {
1149
+ state$7.ipc = ipc;
1150
1150
  };
1151
1151
 
1152
1152
  const send = (method, ...params) => {
1153
- const ipc = get$3();
1153
+ const ipc = get$4();
1154
1154
  send$1(ipc, method, ...params);
1155
1155
  };
1156
1156
  const invoke = (method, ...params) => {
1157
- const ipc = get$3();
1157
+ const ipc = get$4();
1158
1158
  return invoke$1(ipc, method, ...params);
1159
1159
  };
1160
1160
  const invokeAndTransfer = (method, ...params) => {
1161
- const ipc = get$3();
1161
+ const ipc = get$4();
1162
1162
  return invokeAndTransfer$1(ipc, method, ...params);
1163
1163
  };
1164
1164
  const listen$4 = ipc => {
1165
1165
  handleIpc(ipc);
1166
- set$3(ipc);
1166
+ set$4(ipc);
1167
1167
  };
1168
1168
 
1169
- const state$5 = {
1169
+ const state$6 = {
1170
1170
  debugProviderMap: Object.create(null)
1171
1171
  };
1172
1172
  const getDebugProvider = id => {
1173
- const provider = state$5.debugProviderMap[id];
1173
+ const provider = state$6.debugProviderMap[id];
1174
1174
  if (!provider) {
1175
1175
  // @ts-ignore
1176
1176
  throw new VError$1(`no debug provider "${id}" found`);
@@ -1181,7 +1181,7 @@ const registerDebugProvider = debugProvider => {
1181
1181
  if (!debugProvider.id) {
1182
1182
  throw new Error('Failed to register debug system provider: missing id');
1183
1183
  }
1184
- state$5.debugProviderMap[debugProvider.id] = debugProvider;
1184
+ state$6.debugProviderMap[debugProvider.id] = debugProvider;
1185
1185
  };
1186
1186
  const start = async (protocol, path) => {
1187
1187
  try {
@@ -1337,7 +1337,7 @@ const exec = async (command, args, options) => {
1337
1337
  };
1338
1338
 
1339
1339
  const fileSystemProviderMap = Object.create(null);
1340
- const get$2 = protocol => {
1340
+ const get$3 = protocol => {
1341
1341
  const provider = fileSystemProviderMap[protocol];
1342
1342
  if (!provider) {
1343
1343
  // @ts-ignore
@@ -1345,7 +1345,7 @@ const get$2 = protocol => {
1345
1345
  }
1346
1346
  return provider;
1347
1347
  };
1348
- const set$2 = (id, provider) => {
1348
+ const set$3 = (id, provider) => {
1349
1349
  if (!id) {
1350
1350
  throw new Error('Failed to register file system provider: missing id');
1351
1351
  }
@@ -1356,11 +1356,11 @@ const registerFileSystemProvider = fileSystemProvider => {
1356
1356
  if (!fileSystemProvider.id) {
1357
1357
  throw new Error('Failed to register file system provider: missing id');
1358
1358
  }
1359
- set$2(fileSystemProvider.id, fileSystemProvider);
1359
+ set$3(fileSystemProvider.id, fileSystemProvider);
1360
1360
  };
1361
1361
  const readDirWithFileTypes = async (protocol, path) => {
1362
1362
  try {
1363
- const provider = get$2(protocol);
1363
+ const provider = get$3(protocol);
1364
1364
  return await provider.readDirWithFileTypes(path);
1365
1365
  } catch (error) {
1366
1366
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1368,7 +1368,7 @@ const readDirWithFileTypes = async (protocol, path) => {
1368
1368
  };
1369
1369
  const readFile = async (protocol, path) => {
1370
1370
  try {
1371
- const provider = get$2(protocol);
1371
+ const provider = get$3(protocol);
1372
1372
  return await provider.readFile(path);
1373
1373
  } catch (error) {
1374
1374
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1396,7 +1396,7 @@ const readDirWithFileTypesExternal = async path => {
1396
1396
  };
1397
1397
  const writeFile = async (protocol, uri, content) => {
1398
1398
  try {
1399
- const provider = get$2(protocol);
1399
+ const provider = get$3(protocol);
1400
1400
  return await provider.writeFile(uri, content);
1401
1401
  } catch (error) {
1402
1402
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1404,7 +1404,7 @@ const writeFile = async (protocol, uri, content) => {
1404
1404
  };
1405
1405
  const getPathSeparator = protocol => {
1406
1406
  try {
1407
- const provider = get$2(protocol);
1407
+ const provider = get$3(protocol);
1408
1408
  return provider.pathSeparator;
1409
1409
  } catch (error) {
1410
1410
  throw new VError$1(error, 'Failed to execute file system provider');
@@ -1654,7 +1654,7 @@ const getExtensionHostSubWorkerUrl = () => {
1654
1654
  };
1655
1655
  const extensionHostSubWorkerUrl = getExtensionHostSubWorkerUrl();
1656
1656
 
1657
- const set$1 = async (url, contentSecurityPolicy) => {
1657
+ const set$2 = async (url, contentSecurityPolicy) => {
1658
1658
  const pathName = new URL(url).pathname;
1659
1659
  await invoke('ExtensionHostWorkerContentSecurityPolicy.set', pathName, contentSecurityPolicy);
1660
1660
  };
@@ -1663,7 +1663,7 @@ const rpcs$1 = Object.create(null);
1663
1663
  const add$1 = (id, rpc) => {
1664
1664
  rpcs$1[id] = rpc;
1665
1665
  };
1666
- const get$1 = id => {
1666
+ const get$2 = id => {
1667
1667
  return rpcs$1[id];
1668
1668
  };
1669
1669
 
@@ -1677,16 +1677,16 @@ const acquire = id => {
1677
1677
  delete registry[id];
1678
1678
  return fn;
1679
1679
  };
1680
- const get = id => {
1680
+ const get$1 = id => {
1681
1681
  return rpcs[id];
1682
1682
  };
1683
- const set = (id, rpc) => {
1683
+ const set$1 = (id, rpc) => {
1684
1684
  rpcs[id] = rpc;
1685
1685
  };
1686
1686
 
1687
1687
  const createRpcWithId$1 = async id => {
1688
1688
  const fn = acquire(id);
1689
- const info = get$1(id);
1689
+ const info = get$2(id);
1690
1690
  if (!info) {
1691
1691
  throw new Error(`rpc with id ${id} not found`);
1692
1692
  }
@@ -1701,16 +1701,16 @@ const createRpcWithId$1 = async id => {
1701
1701
  execute: fn
1702
1702
  });
1703
1703
  await newRpc.invoke('LoadFile.loadFile', info.url);
1704
- set(id, newRpc);
1704
+ set$1(id, newRpc);
1705
1705
  return newRpc;
1706
1706
  };
1707
1707
 
1708
1708
  const getOrCreateRpc = async id => {
1709
- const rpc = get(id);
1709
+ const rpc = get$1(id);
1710
1710
  if (!rpc) {
1711
- set(id, createRpcWithId$1(id));
1711
+ set$1(id, createRpcWithId$1(id));
1712
1712
  }
1713
- return get(id);
1713
+ return get$1(id);
1714
1714
  };
1715
1715
  const createRpcWithId = ({
1716
1716
  id,
@@ -1745,7 +1745,7 @@ const createLegacyRpc = async ({
1745
1745
  string(name);
1746
1746
  fn(execute);
1747
1747
  if (contentSecurityPolicy) {
1748
- await set$1(url, contentSecurityPolicy);
1748
+ await set$2(url, contentSecurityPolicy);
1749
1749
  }
1750
1750
  const ipc = await create$7({
1751
1751
  method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
@@ -1801,17 +1801,17 @@ const {
1801
1801
  }
1802
1802
  });
1803
1803
 
1804
- const state$4 = {
1804
+ const state$5 = {
1805
1805
  providers: Object.create(null)
1806
1806
  };
1807
1807
  const registerSourceControlProvider = provider => {
1808
- state$4.providers[provider.id] = provider;
1808
+ state$5.providers[provider.id] = provider;
1809
1809
  };
1810
1810
  const getFilesFromProvider = provider => {
1811
1811
  return provider.getChangedFiles();
1812
1812
  };
1813
1813
  const getChangedFiles = async providerId => {
1814
- const provider = state$4.providers[providerId];
1814
+ const provider = state$5.providers[providerId];
1815
1815
  if (!provider) {
1816
1816
  throw new Error('no source control provider found');
1817
1817
  }
@@ -1822,7 +1822,7 @@ const getChangedFiles = async providerId => {
1822
1822
  const getFileBefore = async (providerId, uri) => {
1823
1823
  string(providerId);
1824
1824
  string(uri);
1825
- const provider = state$4.providers[providerId];
1825
+ const provider = state$5.providers[providerId];
1826
1826
  if (!provider) {
1827
1827
  throw new Error('no source control provider found');
1828
1828
  }
@@ -1844,7 +1844,7 @@ const getGroupsFromProvider = async (provider, cwd) => {
1844
1844
  throw new Error('source control provider is missing required function getGroups');
1845
1845
  };
1846
1846
  const getGroups = async (providerId, cwd) => {
1847
- const provider = state$4.providers[providerId];
1847
+ const provider = state$5.providers[providerId];
1848
1848
  if (!provider) {
1849
1849
  throw new Error('no source control provider found');
1850
1850
  }
@@ -1852,14 +1852,14 @@ const getGroups = async (providerId, cwd) => {
1852
1852
  return groups;
1853
1853
  };
1854
1854
  const acceptInput = async (providerId, value) => {
1855
- const provider = state$4.providers[providerId];
1855
+ const provider = state$5.providers[providerId];
1856
1856
  if (!provider) {
1857
1857
  throw new Error('no source control provider found');
1858
1858
  }
1859
1859
  await provider.acceptInput(value);
1860
1860
  };
1861
1861
  const add = async path => {
1862
- const provider = Object.values(state$4.providers)[0];
1862
+ const provider = Object.values(state$5.providers)[0];
1863
1863
  if (!provider) {
1864
1864
  return;
1865
1865
  }
@@ -1867,7 +1867,7 @@ const add = async path => {
1867
1867
  await provider.add(path);
1868
1868
  };
1869
1869
  const discard = async path => {
1870
- const provider = Object.values(state$4.providers)[0];
1870
+ const provider = Object.values(state$5.providers)[0];
1871
1871
  if (!provider) {
1872
1872
  return;
1873
1873
  }
@@ -1877,7 +1877,7 @@ const discard = async path => {
1877
1877
  const getEnabledProviderIds = async (scheme, root) => {
1878
1878
  string(scheme);
1879
1879
  string(root);
1880
- const providers = Object.values(state$4.providers);
1880
+ const providers = Object.values(state$5.providers);
1881
1881
  const enabledIds = [];
1882
1882
  for (const provider of providers) {
1883
1883
  // @ts-ignore
@@ -1906,7 +1906,7 @@ const {
1906
1906
  }
1907
1907
  });
1908
1908
 
1909
- const state$3 = {
1909
+ const state$4 = {
1910
1910
  textSearchProviders: Object.create(null)
1911
1911
  };
1912
1912
  const registerTextSearchProvider = textSearchProvider => {
@@ -1917,14 +1917,14 @@ const registerTextSearchProvider = textSearchProvider => {
1917
1917
  if (!textSearchProvider.scheme) {
1918
1918
  throw new Error('textSearchProvider is missing scheme');
1919
1919
  }
1920
- state$3.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
1920
+ state$4.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
1921
1921
  } catch (error) {
1922
1922
  throw new VError$1(error, 'Failed to register text search provider');
1923
1923
  }
1924
1924
  };
1925
1925
  const executeTextSearchProvider = async (scheme, query) => {
1926
1926
  try {
1927
- const textSearchProvider = state$3.textSearchProviders[scheme];
1927
+ const textSearchProvider = state$4.textSearchProviders[scheme];
1928
1928
  if (!textSearchProvider) {
1929
1929
  throw new Error(`No text search provider for ${scheme} found`);
1930
1930
  }
@@ -2181,14 +2181,14 @@ const createWorker = async ({
2181
2181
  return ipc;
2182
2182
  };
2183
2183
 
2184
- const state$2 = {
2184
+ const state$3 = {
2185
2185
  workspacePath: ''
2186
2186
  };
2187
2187
  const setWorkspacePath = path => {
2188
- state$2.workspacePath = path;
2188
+ state$3.workspacePath = path;
2189
2189
  };
2190
2190
  const getWorkspaceFolder = path => {
2191
- return state$2.workspacePath;
2191
+ return state$3.workspacePath;
2192
2192
  };
2193
2193
 
2194
2194
  class FormattingError extends Error {
@@ -2200,12 +2200,12 @@ class FormattingError extends Error {
2200
2200
  }
2201
2201
  }
2202
2202
 
2203
- const File$1 = 1;
2203
+ const File$2 = 1;
2204
2204
  const Match = 2;
2205
2205
 
2206
2206
  const TextSearchResultType = {
2207
2207
  __proto__: null,
2208
- File: File$1,
2208
+ File: File$2,
2209
2209
  Match
2210
2210
  };
2211
2211
 
@@ -2418,7 +2418,7 @@ class ContentSecurityPolicyError extends Error {
2418
2418
  }
2419
2419
  }
2420
2420
 
2421
- const state$1 = {
2421
+ const state$2 = {
2422
2422
  /**
2423
2423
  * @type {any[]}
2424
2424
  */
@@ -2426,13 +2426,13 @@ const state$1 = {
2426
2426
  };
2427
2427
  const addError = error => {
2428
2428
  // @ts-ignore
2429
- state$1.errors.push(error);
2429
+ state$2.errors.push(error);
2430
2430
  };
2431
2431
  const hasRecentErrors = () => {
2432
- return state$1.errors.length > 0;
2432
+ return state$2.errors.length > 0;
2433
2433
  };
2434
2434
  const getRecentError = () => {
2435
- return state$1.errors.at(-1);
2435
+ return state$2.errors.at(-1);
2436
2436
  };
2437
2437
 
2438
2438
  const isImportErrorChrome = error => {
@@ -2542,7 +2542,7 @@ const CallExpression = 'CallExpression';
2542
2542
  const ExportAllDeclaration = 'ExportAllDeclaration';
2543
2543
  const ExportNamedDeclaration = 'ExportNamedDeclaration';
2544
2544
  const ExpressionStatement = 'ExpressionStatement';
2545
- const File = 'File';
2545
+ const File$1 = 'File';
2546
2546
  const Import = 'Import';
2547
2547
  const ImportDeclaration = 'ImportDeclaration';
2548
2548
  const Program = 'Program';
@@ -2562,7 +2562,7 @@ const walk = (node, visitor) => {
2562
2562
  }
2563
2563
  visitor(node);
2564
2564
  switch (node.type) {
2565
- case File:
2565
+ case File$1:
2566
2566
  walk(node.program, visitor);
2567
2567
  break;
2568
2568
  case Program:
@@ -2858,7 +2858,7 @@ const mockRpc = () => {
2858
2858
  };
2859
2859
 
2860
2860
  const getStatusBarItems = async () => {
2861
- const providers = Object.values(state$4.providers);
2861
+ const providers = Object.values(state$5.providers);
2862
2862
  const statusBarItems = [];
2863
2863
  for (const provider of providers) {
2864
2864
  // @ts-ignore
@@ -3054,14 +3054,14 @@ const NewLine$1 = '\n';
3054
3054
  const joinLines = lines => {
3055
3055
  return lines.join(NewLine$1);
3056
3056
  };
3057
- const splitLines = lines => {
3057
+ const splitLines$1 = lines => {
3058
3058
  return lines.split(NewLine$1);
3059
3059
  };
3060
3060
  const isModuleNotFoundMessage = line => {
3061
3061
  return line.includes('[ERR_MODULE_NOT_FOUND]');
3062
3062
  };
3063
3063
  const getModuleNotFoundError = stderr => {
3064
- const lines = splitLines(stderr);
3064
+ const lines = splitLines$1(stderr);
3065
3065
  const messageIndex = lines.findIndex(isModuleNotFoundMessage);
3066
3066
  const message = lines[messageIndex];
3067
3067
  return {
@@ -3085,7 +3085,7 @@ const isMessageCodeBlockEndIndex = line => {
3085
3085
  return RE_MESSAGE_CODE_BLOCK_END.test(line);
3086
3086
  };
3087
3087
  const getMessageCodeBlock = stderr => {
3088
- const lines = splitLines(stderr);
3088
+ const lines = splitLines$1(stderr);
3089
3089
  const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
3090
3090
  const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
3091
3091
  const relevantLines = lines.slice(startIndex, endIndex);
@@ -3149,7 +3149,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
3149
3149
  if (isModuleNotFoundError(stderr)) {
3150
3150
  return getModuleNotFoundError(stderr);
3151
3151
  }
3152
- const lines = splitLines(stderr);
3152
+ const lines = splitLines$1(stderr);
3153
3153
  const {
3154
3154
  actualMessage,
3155
3155
  rest
@@ -3340,35 +3340,6 @@ const handleMessagePort = port => {
3340
3340
  ipc.send('ready');
3341
3341
  };
3342
3342
 
3343
- const serializeWebView = async webView => {
3344
- if (webView && webView.provider && webView.provider.saveState) {
3345
- const saved = await webView.provider.saveState();
3346
- return {
3347
- uri: webView.uri,
3348
- state: saved
3349
- };
3350
- }
3351
- return undefined;
3352
- };
3353
- const serializeWebViews = async webViews => {
3354
- const serialized = [];
3355
- for (const [key, value] of Object.entries(webViews)) {
3356
- const serializedValue = await serializeWebView(value);
3357
- if (serializedValue) {
3358
- serialized.push({
3359
- key,
3360
- value: serializedValue
3361
- });
3362
- }
3363
- }
3364
- return serialized;
3365
- };
3366
- const saveState = async () => {
3367
- const webViews = getWebViews();
3368
- const serialized = await serializeWebViews(webViews);
3369
- return serialized;
3370
- };
3371
-
3372
3343
  const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
3373
3344
  let idbProxyableTypes;
3374
3345
  let cursorAdvanceMethods;
@@ -3623,7 +3594,7 @@ replaceTraps(oldTraps => ({
3623
3594
  }
3624
3595
  }));
3625
3596
 
3626
- const state = {
3597
+ const state$1 = {
3627
3598
  databases: Object.create(null),
3628
3599
  eventId: 0,
3629
3600
  dbVersion: 1,
@@ -3639,9 +3610,9 @@ const isDataCloneError = error => {
3639
3610
 
3640
3611
  // TODO high memory usage in idb because of transactionDoneMap
3641
3612
 
3642
- const getDb = async () => {
3613
+ const getDb$1 = async () => {
3643
3614
  // @ts-ignore
3644
- const db = await openDB('session', state.dbVersion, {
3615
+ const db = await openDB('session', state$1.dbVersion, {
3645
3616
  async upgrade(db, oldVersion) {
3646
3617
  if (!db.objectStoreNames.contains('session')) {
3647
3618
  const objectStore = await db.createObjectStore('session', {
@@ -3655,13 +3626,13 @@ const getDb = async () => {
3655
3626
  });
3656
3627
  return db;
3657
3628
  };
3658
- const getDbMemoized = async () => {
3659
- state.cachedDb ||= await getDb();
3660
- return state.cachedDb;
3629
+ const getDbMemoized$1 = async () => {
3630
+ state$1.cachedDb ||= await getDb$1();
3631
+ return state$1.cachedDb;
3661
3632
  };
3662
3633
  const saveValue = async (storeId, value) => {
3663
3634
  try {
3664
- const db = await getDbMemoized();
3635
+ const db = await getDbMemoized$1();
3665
3636
  await db.add('session', value);
3666
3637
  } catch (error) {
3667
3638
  if (isDataCloneError(error)) {
@@ -3673,7 +3644,7 @@ const saveValue = async (storeId, value) => {
3673
3644
  };
3674
3645
  const getValues = async storeId => {
3675
3646
  try {
3676
- const db = await getDbMemoized();
3647
+ const db = await getDbMemoized$1();
3677
3648
  const tx = db.transaction(storeId, 'readwrite');
3678
3649
  const [objects] = await Promise.all([tx.store.getAll(), tx.done]);
3679
3650
  console.log({
@@ -3685,7 +3656,7 @@ const getValues = async storeId => {
3685
3656
  }
3686
3657
  };
3687
3658
  const getValuesByIndexName = async (storeId, indexName, only) => {
3688
- const db = await getDbMemoized();
3659
+ const db = await getDbMemoized$1();
3689
3660
  const transaction = db.transaction(storeId);
3690
3661
  const index = transaction.store.index(indexName);
3691
3662
  const iterator = index.iterate(only);
@@ -3696,7 +3667,7 @@ const getValuesByIndexName = async (storeId, indexName, only) => {
3696
3667
  return objects;
3697
3668
  };
3698
3669
  const getHandleDb = async () => {
3699
- const db = await openDB('handle', state.dbVersion, {
3670
+ const db = await openDB('handle', state$1.dbVersion, {
3700
3671
  async upgrade(db, oldVersion) {
3701
3672
  if (!db.objectStoreNames.contains('file-handles-store')) {
3702
3673
  // @ts-ignore
@@ -3710,20 +3681,264 @@ const addHandle = async (uri, handle) => {
3710
3681
  const handleDb = await getHandleDb();
3711
3682
  await handleDb.put('file-handles-store', handle, uri);
3712
3683
  };
3713
- const getHandle = async uri => {
3684
+ const getHandle$1 = async uri => {
3714
3685
  const handleDb = await getHandleDb();
3715
3686
  const handle = await handleDb.get('file-handles-store', uri);
3716
3687
  return handle;
3717
3688
  };
3718
3689
 
3690
+ // TODO high memory usage in idb because of transactionDoneMap
3691
+
3692
+ const state = {
3693
+ databases: Object.create(null),
3694
+ dbVersion: 2,
3695
+ cachedDb: undefined
3696
+ };
3697
+ const storeId = 'lvce-keyvalue';
3698
+ const getDb = async () => {
3699
+ const db = await openDB(storeId, state.dbVersion, {
3700
+ async upgrade(db, oldVersion) {
3701
+ if (!db.objectStoreNames.contains(storeId)) {
3702
+ await db.createObjectStore(storeId, {
3703
+ autoIncrement: true
3704
+ });
3705
+ }
3706
+ }
3707
+ });
3708
+ return db;
3709
+ };
3710
+ const getDbMemoized = async () => {
3711
+ state.cachedDb ||= await getDb();
3712
+ return state.cachedDb;
3713
+ };
3714
+ const set = async (key, value) => {
3715
+ try {
3716
+ const db = await getDbMemoized();
3717
+ await db.put(storeId, value, key);
3718
+ } catch (error) {
3719
+ throw new VError$1(error, 'Failed to save value to indexed db');
3720
+ }
3721
+ };
3722
+ const get = async key => {
3723
+ try {
3724
+ const db = await getDbMemoized();
3725
+ const value = db.get(storeId, key);
3726
+ return value;
3727
+ } catch (error) {
3728
+ throw new VError$1(error, 'Failed to get value from indexed db');
3729
+ }
3730
+ };
3731
+
3732
+ const serializeWebView = async webView => {
3733
+ if (webView && webView.provider && webView.provider.saveState) {
3734
+ const saved = await webView.provider.saveState();
3735
+ return {
3736
+ uri: webView.uri,
3737
+ state: saved
3738
+ };
3739
+ }
3740
+ return undefined;
3741
+ };
3742
+ const serializeWebViews = async webViews => {
3743
+ const serialized = [];
3744
+ for (const [key, value] of Object.entries(webViews)) {
3745
+ const serializedValue = await serializeWebView(value);
3746
+ if (serializedValue) {
3747
+ serialized.push({
3748
+ key,
3749
+ value: serializedValue
3750
+ });
3751
+ }
3752
+ }
3753
+ return serialized;
3754
+ };
3755
+ const saveState = async () => {
3756
+ const webViews = getWebViews();
3757
+ const serialized = await serializeWebViews(webViews);
3758
+ return serialized;
3759
+ };
3760
+
3761
+ class FileNotFoundError extends Error {
3762
+ constructor(message) {
3763
+ super(message);
3764
+ this.name = 'FileNotFoundError';
3765
+ }
3766
+ }
3767
+
3768
+ const Directory = 'directory';
3769
+ const File = 'file';
3770
+
3771
+ // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
3772
+
3773
+ const insertInto = (array, start, newItems) => {
3774
+ const originalLength = array.length;
3775
+ const newItemsLength = newItems.length;
3776
+ array.length = originalLength + newItemsLength;
3777
+ // Move the items after the start index, start from the end so that we don't overwrite any value.
3778
+ for (let i = originalLength - 1; i >= start; i--) {
3779
+ array[i + newItemsLength] = array[i];
3780
+ }
3781
+ for (let i = 0; i < newItemsLength; i++) {
3782
+ array[i + start] = newItems[i];
3783
+ }
3784
+ };
3785
+ const push = (array, newItems) => {
3786
+ insertInto(array, array.length, newItems);
3787
+ };
3788
+ const fromAsync = async asyncIterable => {
3789
+ const children = [];
3790
+ for await (const value of asyncIterable) {
3791
+ children.push(value);
3792
+ }
3793
+ return children;
3794
+ };
3795
+
3796
+ const getChildHandles$1 = async handle => {
3797
+ object(handle);
3798
+ // @ts-ignore
3799
+ const childHandles = handle.values();
3800
+ const handles = await fromAsync(childHandles);
3801
+ return handles;
3802
+ };
3803
+
3804
+ const getChildHandles = async handle => {
3805
+ try {
3806
+ return await getChildHandles$1(handle);
3807
+ } catch (error) {
3808
+ throw new VError$1(error, 'failed to get child handles');
3809
+ }
3810
+ };
3811
+
3812
+ const dirname = (pathSeparator, path) => {
3813
+ const index = path.lastIndexOf(pathSeparator);
3814
+ if (index === -1) {
3815
+ return path;
3816
+ }
3817
+ return path.slice(0, index);
3818
+ };
3819
+
3820
+ const getHandle = async uri => {
3821
+ try {
3822
+ // TODO retrieve handle from state or from indexeddb
3823
+ // TODO if not found, throw error
3824
+ const handle = await getHandle$1(uri);
3825
+ return handle;
3826
+ } catch (error) {
3827
+ throw new VError$1(error, 'Failed to get handle');
3828
+ }
3829
+ };
3830
+
3831
+ const getDirectoryHandle = async uri => {
3832
+ const handle = await getHandle(uri);
3833
+ if (handle) {
3834
+ return handle;
3835
+ }
3836
+ const dirname$1 = dirname('/', uri);
3837
+ if (uri === dirname$1) {
3838
+ return undefined;
3839
+ }
3840
+ return getDirectoryHandle(dirname$1);
3841
+ };
3842
+
3843
+ const NotReadableError = 'NotReadableError';
3844
+
3845
+ const isNotReadableError = error => {
3846
+ return error && error.name === NotReadableError;
3847
+ };
3848
+
3849
+ const getFile = handle => {
3850
+ return handle.getFile();
3851
+ };
3852
+
3853
+ const splitLines = lines => {
3854
+ return lines.split('\n');
3855
+ };
3856
+
3857
+ const textSearchInText = (file, content, query) => {
3858
+ const results = [];
3859
+ const lines = splitLines(content);
3860
+ for (let i = 0; i < lines.length; i++) {
3861
+ const line = lines[i];
3862
+ const index = line.indexOf(query);
3863
+ if (index !== -1) {
3864
+ results.push({
3865
+ type: Match,
3866
+ text: line,
3867
+ start: index,
3868
+ end: index + query.length,
3869
+ lineNumber: i
3870
+ });
3871
+ }
3872
+ }
3873
+ if (results.length > 0) {
3874
+ results.unshift({
3875
+ type: File$2,
3876
+ text: file,
3877
+ start: 0,
3878
+ end: 0,
3879
+ lineNumber: 0
3880
+ });
3881
+ }
3882
+ return results;
3883
+ };
3884
+
3885
+ const textSearchInFile = async (all, handle, absolutePath, query) => {
3886
+ try {
3887
+ const file = await getFile(handle);
3888
+ const content = await file.text();
3889
+ const results = textSearchInText(absolutePath, content, query);
3890
+ push(all, results);
3891
+ } catch (error) {
3892
+ if (isNotReadableError(error)) {
3893
+ // ignore
3894
+ return;
3895
+ }
3896
+ throw error;
3897
+ }
3898
+ };
3899
+
3900
+ const textSearchRecursively = async (all, parent, handle, query) => {
3901
+ const childHandles = await getChildHandles(handle);
3902
+ const promises = [];
3903
+ for (const childHandle of childHandles) {
3904
+ const absolutePath = parent + '/' + childHandle.name;
3905
+ switch (childHandle.kind) {
3906
+ case Directory:
3907
+ promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
3908
+ break;
3909
+ case File:
3910
+ // @ts-ignore
3911
+ promises.push(textSearchInFile(all, childHandle, absolutePath, query));
3912
+ break;
3913
+ }
3914
+ }
3915
+ await Promise.all(promises);
3916
+ };
3917
+ const textSearch = async (scheme, root, query) => {
3918
+ string(scheme);
3919
+ string(root);
3920
+ string(query);
3921
+ const relativeRoot = root.slice('html://'.length);
3922
+ const handle = await getDirectoryHandle(relativeRoot);
3923
+ if (!handle) {
3924
+ throw new FileNotFoundError(`Folder not found: ${relativeRoot}`);
3925
+ }
3926
+ const all = [];
3927
+ await textSearchRecursively(all, '', handle, query);
3928
+ return all;
3929
+ };
3930
+
3719
3931
  const commandMap = {
3720
3932
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
3721
3933
  'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
3722
3934
  'IndexedDb.addHandle': addHandle,
3723
- 'IndexedDb.getHandle': getHandle,
3935
+ 'IndexedDb.get': get,
3936
+ 'IndexedDb.getHandle': getHandle$1,
3724
3937
  'IndexedDb.getValues': getValues,
3725
3938
  'IndexedDb.getValuesByIndexName': getValuesByIndexName,
3726
3939
  'IndexedDb.saveValue': saveValue,
3940
+ 'IndexedDb.set': set,
3941
+ 'TextSearchHtml.textSearch': textSearch,
3727
3942
  ['ExtensionHostDebug.evaluate']: evaluate,
3728
3943
  ['ExtensionHostDebug.getProperties']: getProperties,
3729
3944
  ['ExtensionHostDebug.listProcesses']: listProcesses,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",