@lvce-editor/extension-host-worker 1.14.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,
@@ -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,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
 
@@ -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,187 @@ 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';
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
+
3761
3931
  const commandMap = {
3762
3932
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
3763
3933
  'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
3764
3934
  'IndexedDb.addHandle': addHandle,
3765
3935
  'IndexedDb.get': get,
3766
- 'IndexedDb.getHandle': getHandle,
3936
+ 'IndexedDb.getHandle': getHandle$1,
3767
3937
  'IndexedDb.getValues': getValues,
3768
3938
  'IndexedDb.getValuesByIndexName': getValuesByIndexName,
3769
3939
  'IndexedDb.saveValue': saveValue,
3770
3940
  'IndexedDb.set': set,
3941
+ 'TextSearchHtml.textSearch': textSearch,
3771
3942
  ['ExtensionHostDebug.evaluate']: evaluate,
3772
3943
  ['ExtensionHostDebug.getProperties']: getProperties,
3773
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.14.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",