@lvce-editor/extension-host-worker 1.14.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.
@@ -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,
@@ -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) => {
@@ -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);
@@ -2200,18 +2200,18 @@ 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
 
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,
@@ -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:
@@ -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
@@ -3681,7 +3681,7 @@ const addHandle = async (uri, handle) => {
3681
3681
  const handleDb = await getHandleDb();
3682
3682
  await handleDb.put('file-handles-store', handle, uri);
3683
3683
  };
3684
- const getHandle = async uri => {
3684
+ const getHandle$1 = async uri => {
3685
3685
  const handleDb = await getHandleDb();
3686
3686
  const handle = await handleDb.get('file-handles-store', uri);
3687
3687
  return handle;
@@ -3758,16 +3758,300 @@ const saveState = async () => {
3758
3758
  return serialized;
3759
3759
  };
3760
3760
 
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`);
3773
+ }
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
+ };
3796
+
3797
+ const Directory = 'directory';
3798
+ const File = 'file';
3799
+
3800
+ // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
3801
+
3802
+ const insertInto = (array, start, newItems) => {
3803
+ const originalLength = array.length;
3804
+ const newItemsLength = newItems.length;
3805
+ array.length = originalLength + newItemsLength;
3806
+ // Move the items after the start index, start from the end so that we don't overwrite any value.
3807
+ for (let i = originalLength - 1; i >= start; i--) {
3808
+ array[i + newItemsLength] = array[i];
3809
+ }
3810
+ for (let i = 0; i < newItemsLength; i++) {
3811
+ array[i + start] = newItems[i];
3812
+ }
3813
+ };
3814
+ const push = (array, newItems) => {
3815
+ insertInto(array, array.length, newItems);
3816
+ };
3817
+ const fromAsync = async asyncIterable => {
3818
+ const children = [];
3819
+ for await (const value of asyncIterable) {
3820
+ children.push(value);
3821
+ }
3822
+ return children;
3823
+ };
3824
+
3825
+ const getChildHandles$1 = async handle => {
3826
+ object(handle);
3827
+ // @ts-ignore
3828
+ const childHandles = handle.values();
3829
+ const handles = await fromAsync(childHandles);
3830
+ return handles;
3831
+ };
3832
+
3833
+ const dirname = (pathSeparator, path) => {
3834
+ const index = path.lastIndexOf(pathSeparator);
3835
+ if (index === -1) {
3836
+ return path;
3837
+ }
3838
+ return path.slice(0, index);
3839
+ };
3840
+
3841
+ const getHandle = async uri => {
3842
+ try {
3843
+ // TODO retrieve handle from state or from indexeddb
3844
+ // TODO if not found, throw error
3845
+ const handle = await getHandle$1(uri);
3846
+ return handle;
3847
+ } catch (error) {
3848
+ throw new VError$1(error, 'Failed to get handle');
3849
+ }
3850
+ };
3851
+
3852
+ const getDirectoryHandle$1 = async uri => {
3853
+ const handle = await getHandle(uri);
3854
+ if (handle) {
3855
+ return handle;
3856
+ }
3857
+ const dirname$1 = dirname('/', uri);
3858
+ if (uri === dirname$1) {
3859
+ return undefined;
3860
+ }
3861
+ return getDirectoryHandle$1(dirname$1);
3862
+ };
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;
3893
+ };
3894
+
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
+ }
3906
+ };
3907
+
3908
+ const splitLines = lines => {
3909
+ return lines.split('\n');
3910
+ };
3911
+
3912
+ const textSearchInText = (file, content, query) => {
3913
+ const results = [];
3914
+ const lines = splitLines(content);
3915
+ for (let i = 0; i < lines.length; i++) {
3916
+ const line = lines[i];
3917
+ const index = line.indexOf(query);
3918
+ if (index !== -1) {
3919
+ results.push({
3920
+ type: Match,
3921
+ text: line,
3922
+ start: index,
3923
+ end: index + query.length,
3924
+ lineNumber: i
3925
+ });
3926
+ }
3927
+ }
3928
+ if (results.length > 0) {
3929
+ results.unshift({
3930
+ type: File$2,
3931
+ text: file,
3932
+ start: 0,
3933
+ end: 0,
3934
+ lineNumber: 0
3935
+ });
3936
+ }
3937
+ return results;
3938
+ };
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
+
3995
+ const textSearchInFile = async (all, handle, absolutePath, query) => {
3996
+ try {
3997
+ const file = await getFile(handle);
3998
+ const content = await file.text();
3999
+ const results = textSearchInText(absolutePath, content, query);
4000
+ push(all, results);
4001
+ } catch (error) {
4002
+ if (isNotReadableError(error)) {
4003
+ // ignore
4004
+ return;
4005
+ }
4006
+ throw error;
4007
+ }
4008
+ };
4009
+
4010
+ const textSearchRecursively = async (all, parent, handle, query) => {
4011
+ const childHandles = await getChildHandles(handle);
4012
+ const promises = [];
4013
+ for (const childHandle of childHandles) {
4014
+ const absolutePath = parent + '/' + childHandle.name;
4015
+ switch (childHandle.kind) {
4016
+ case Directory:
4017
+ promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
4018
+ break;
4019
+ case File:
4020
+ // @ts-ignore
4021
+ promises.push(textSearchInFile(all, childHandle, absolutePath, query));
4022
+ break;
4023
+ }
4024
+ }
4025
+ await Promise.all(promises);
4026
+ };
4027
+ const textSearch = async (scheme, root, query) => {
4028
+ string(scheme);
4029
+ string(root);
4030
+ string(query);
4031
+ const relativeRoot = root.slice('html://'.length);
4032
+ const handle = await getDirectoryHandle(relativeRoot);
4033
+ if (!handle) {
4034
+ throw new FileNotFoundError(`Folder not found: ${relativeRoot}`);
4035
+ }
4036
+ const all = [];
4037
+ await textSearchRecursively(all, '', handle, query);
4038
+ return all;
4039
+ };
4040
+
3761
4041
  const commandMap = {
3762
4042
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
3763
4043
  'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
3764
4044
  'IndexedDb.addHandle': addHandle,
3765
4045
  'IndexedDb.get': get,
3766
- 'IndexedDb.getHandle': getHandle,
4046
+ 'IndexedDb.getHandle': getHandle$1,
3767
4047
  'IndexedDb.getValues': getValues,
3768
4048
  'IndexedDb.getValuesByIndexName': getValuesByIndexName,
3769
4049
  'IndexedDb.saveValue': saveValue,
3770
4050
  'IndexedDb.set': set,
4051
+ 'SearchFileWithFetch.searchFileWithFetch': searchFile$1,
4052
+ 'SearchFileWithHtml.searchFileWithHtml': searchFile,
4053
+ 'TextSearchFetch.textSearch': textSearch$1,
4054
+ 'TextSearchHtml.textSearch': textSearch,
3771
4055
  ['ExtensionHostDebug.evaluate']: evaluate,
3772
4056
  ['ExtensionHostDebug.getProperties']: getProperties,
3773
4057
  ['ExtensionHostDebug.listProcesses']: listProcesses,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "1.14.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",