@lvce-editor/extension-host-worker 1.15.0 → 1.16.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.
@@ -26,7 +26,7 @@ class DepecratedError extends Error {
26
26
  }
27
27
  }
28
28
 
29
- const getJson = async url => {
29
+ const getJson$1 = async url => {
30
30
  throw new DepecratedError(`vscode.getJson is deprecated, use createNodeRpc instead`);
31
31
  };
32
32
 
@@ -307,7 +307,7 @@ const get$6 = textDocumentId => {
307
307
  const textDocument = getDocument(textDocumentId);
308
308
  return textDocument;
309
309
  };
310
- const getText = textDocument => {
310
+ const getText$1 = textDocument => {
311
311
  return textDocument.text;
312
312
  };
313
313
  const setLanguageId = (textDocumentId, languageId) => {
@@ -2211,7 +2211,7 @@ const TextSearchResultType = {
2211
2211
 
2212
2212
  const api = {
2213
2213
  // Ajax
2214
- getJson: getJson,
2214
+ getJson: getJson$1,
2215
2215
  // Brace Completion
2216
2216
  registerBraceCompletionProvider: registerBraceCompletionProvider,
2217
2217
  executeBraceCompletionProvider: executeBraceCompletionProvider,
@@ -2286,7 +2286,7 @@ const api = {
2286
2286
  registerTabCompletionProvider: registerTabCompletionProvider,
2287
2287
  executeTabCompletionProvider: executeTabCompletionProvider,
2288
2288
  // Text Document
2289
- getTextFromTextDocument: getText,
2289
+ getTextFromTextDocument: getText$1,
2290
2290
  // Text Search
2291
2291
  registerTextSearchProvider: registerTextSearchProvider,
2292
2292
  executeTextSearchProvider: executeTextSearchProvider,
@@ -3758,12 +3758,41 @@ const saveState = async () => {
3758
3758
  return serialized;
3759
3759
  };
3760
3760
 
3761
- class FileNotFoundError extends Error {
3762
- constructor(message) {
3763
- super(message);
3764
- this.name = 'FileNotFoundError';
3761
+ const fileMapUrl = `${assetDir}/config/fileMap.json`;
3762
+
3763
+ const getJson = async url => {
3764
+ try {
3765
+ const response = await fetch(url);
3766
+ if (!response.ok) {
3767
+ throw new Error(response.statusText);
3768
+ }
3769
+ const json = await response.json();
3770
+ return json;
3771
+ } catch (error) {
3772
+ throw new VError$1(error, `Failed to get json`);
3765
3773
  }
3766
- }
3774
+ };
3775
+
3776
+ const removeLeadingSlash = path => {
3777
+ if (path.startsWith('/')) {
3778
+ return path.slice(1);
3779
+ }
3780
+ return path;
3781
+ };
3782
+
3783
+ // TODO simplify code
3784
+ // 1. don't have playground prefix in fileMap json
3785
+ // 2. remove code here that removes the prefix
3786
+ const searchFile$1 = async path => {
3787
+ const fileList = await getJson(fileMapUrl);
3788
+ const result = fileList.map(removeLeadingSlash);
3789
+ const prefixLength = path.length - 'file:///'.length;
3790
+ const final = [];
3791
+ for (const item of result) {
3792
+ final.push(item.slice(prefixLength));
3793
+ }
3794
+ return final;
3795
+ };
3767
3796
 
3768
3797
  const Directory = 'directory';
3769
3798
  const File = 'file';
@@ -3801,14 +3830,6 @@ const getChildHandles$1 = async handle => {
3801
3830
  return handles;
3802
3831
  };
3803
3832
 
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
3833
  const dirname = (pathSeparator, path) => {
3813
3834
  const index = path.lastIndexOf(pathSeparator);
3814
3835
  if (index === -1) {
@@ -3828,7 +3849,7 @@ const getHandle = async uri => {
3828
3849
  }
3829
3850
  };
3830
3851
 
3831
- const getDirectoryHandle = async uri => {
3852
+ const getDirectoryHandle$1 = async uri => {
3832
3853
  const handle = await getHandle(uri);
3833
3854
  if (handle) {
3834
3855
  return handle;
@@ -3837,17 +3858,51 @@ const getDirectoryHandle = async uri => {
3837
3858
  if (uri === dirname$1) {
3838
3859
  return undefined;
3839
3860
  }
3840
- return getDirectoryHandle(dirname$1);
3861
+ return getDirectoryHandle$1(dirname$1);
3841
3862
  };
3842
-
3843
- const NotReadableError = 'NotReadableError';
3844
-
3845
- const isNotReadableError = error => {
3846
- return error && error.name === NotReadableError;
3863
+ const toIgnore = ['.git', 'node_modules', 'dist', 'dist2'];
3864
+ const searchFilesRecursively = async (all, parent, handle) => {
3865
+ const childHandles = await getChildHandles$1(handle);
3866
+ const promises = [];
3867
+ for (const childHandle of childHandles) {
3868
+ if (toIgnore.includes(childHandle.name)) {
3869
+ continue;
3870
+ }
3871
+ const absolutePath = parent + '/' + childHandle.name;
3872
+ switch (childHandle.kind) {
3873
+ case Directory:
3874
+ promises.push(searchFilesRecursively(all, absolutePath, childHandle));
3875
+ break;
3876
+ case File:
3877
+ all.push(absolutePath);
3878
+ break;
3879
+ }
3880
+ }
3881
+ await Promise.all(promises);
3882
+ };
3883
+ const searchFile = async uri => {
3884
+ const path = uri.slice('html://'.length);
3885
+ const handle = await getDirectoryHandle$1(path);
3886
+ if (!handle) {
3887
+ // @ts-ignore
3888
+ throw new VError$1(`Folder not found ${uri}`);
3889
+ }
3890
+ const all = [];
3891
+ await searchFilesRecursively(all, '', handle);
3892
+ return all;
3847
3893
  };
3848
3894
 
3849
- const getFile = handle => {
3850
- return handle.getFile();
3895
+ const getText = async url => {
3896
+ try {
3897
+ const response = await fetch(url);
3898
+ if (!response.ok) {
3899
+ throw new Error(response.statusText);
3900
+ }
3901
+ const text = await response.text();
3902
+ return text;
3903
+ } catch (error) {
3904
+ throw new VError$1(error, `Failed to get text`);
3905
+ }
3851
3906
  };
3852
3907
 
3853
3908
  const splitLines = lines => {
@@ -3882,6 +3937,61 @@ const textSearchInText = (file, content, query) => {
3882
3937
  return results;
3883
3938
  };
3884
3939
 
3940
+ const textSearch$1 = async (scheme, root, query, options, assetDir) => {
3941
+ string(scheme);
3942
+ string(root);
3943
+ string(query);
3944
+ const fetchUri = `${assetDir}/config/fileMap.json`;
3945
+ const fileList = await getJson(fetchUri);
3946
+ const allResults = [];
3947
+ const relativeRoot = root.slice('fetch://'.length);
3948
+ for (const uri of fileList) {
3949
+ const fetchUri = `${assetDir}${uri}`;
3950
+ const content = await getText(fetchUri);
3951
+ const relativeUri = uri.slice(relativeRoot.length + 1);
3952
+ const results = textSearchInText(relativeUri, content, query);
3953
+ allResults.push(...results);
3954
+ }
3955
+ return allResults;
3956
+ };
3957
+
3958
+ class FileNotFoundError extends Error {
3959
+ constructor(message) {
3960
+ super(message);
3961
+ this.name = 'FileNotFoundError';
3962
+ }
3963
+ }
3964
+
3965
+ const getChildHandles = async handle => {
3966
+ try {
3967
+ return await getChildHandles$1(handle);
3968
+ } catch (error) {
3969
+ throw new VError$1(error, 'failed to get child handles');
3970
+ }
3971
+ };
3972
+
3973
+ const getDirectoryHandle = async uri => {
3974
+ const handle = await getHandle(uri);
3975
+ if (handle) {
3976
+ return handle;
3977
+ }
3978
+ const dirname$1 = dirname('/', uri);
3979
+ if (uri === dirname$1) {
3980
+ return undefined;
3981
+ }
3982
+ return getDirectoryHandle(dirname$1);
3983
+ };
3984
+
3985
+ const NotReadableError = 'NotReadableError';
3986
+
3987
+ const isNotReadableError = error => {
3988
+ return error && error.name === NotReadableError;
3989
+ };
3990
+
3991
+ const getFile = handle => {
3992
+ return handle.getFile();
3993
+ };
3994
+
3885
3995
  const textSearchInFile = async (all, handle, absolutePath, query) => {
3886
3996
  try {
3887
3997
  const file = await getFile(handle);
@@ -3938,6 +4048,9 @@ const commandMap = {
3938
4048
  'IndexedDb.getValuesByIndexName': getValuesByIndexName,
3939
4049
  'IndexedDb.saveValue': saveValue,
3940
4050
  'IndexedDb.set': set,
4051
+ 'SearchFileWithFetch.searchFileWithFetch': searchFile$1,
4052
+ 'SearchFileWithHtml.searchFileWithHtml': searchFile,
4053
+ 'TextSearchFetch.textSearch': textSearch$1,
3941
4054
  'TextSearchHtml.textSearch': textSearch,
3942
4055
  ['ExtensionHostDebug.evaluate']: evaluate,
3943
4056
  ['ExtensionHostDebug.getProperties']: getProperties,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",