@lvce-editor/text-search-worker 5.0.0 → 5.1.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.
@@ -591,7 +591,7 @@ const callbacks = Object.create(null);
591
591
  const set$4 = (id, fn) => {
592
592
  callbacks[id] = fn;
593
593
  };
594
- const get$2 = id => {
594
+ const get$3 = id => {
595
595
  return callbacks[id];
596
596
  };
597
597
  const remove$1 = id => {
@@ -771,7 +771,7 @@ const warn = (...args) => {
771
771
  console.warn(...args);
772
772
  };
773
773
  const resolve = (id, response) => {
774
- const fn = get$2(id);
774
+ const fn = get$3(id);
775
775
  if (!fn) {
776
776
  console.log(response);
777
777
  warn(`callback ${id} may already be disposed`);
@@ -1144,7 +1144,7 @@ const rpcs = Object.create(null);
1144
1144
  const set$g = (id, rpc) => {
1145
1145
  rpcs[id] = rpc;
1146
1146
  };
1147
- const get$1 = id => {
1147
+ const get$2 = id => {
1148
1148
  return rpcs[id];
1149
1149
  };
1150
1150
 
@@ -1154,13 +1154,13 @@ const create$3 = rpcId => {
1154
1154
  return {
1155
1155
  // @ts-ignore
1156
1156
  invoke(method, ...params) {
1157
- const rpc = get$1(rpcId);
1157
+ const rpc = get$2(rpcId);
1158
1158
  // @ts-ignore
1159
1159
  return rpc.invoke(method, ...params);
1160
1160
  },
1161
1161
  // @ts-ignore
1162
1162
  invokeAndTransfer(method, ...params) {
1163
- const rpc = get$1(rpcId);
1163
+ const rpc = get$2(rpcId);
1164
1164
  // @ts-ignore
1165
1165
  return rpc.invokeAndTransfer(method, ...params);
1166
1166
  },
@@ -1168,7 +1168,7 @@ const create$3 = rpcId => {
1168
1168
  set$g(rpcId, rpc);
1169
1169
  },
1170
1170
  async dispose() {
1171
- const rpc = get$1(rpcId);
1171
+ const rpc = get$2(rpcId);
1172
1172
  await rpc.dispose();
1173
1173
  }
1174
1174
  };
@@ -1275,7 +1275,7 @@ const create$2 = () => {
1275
1275
  };
1276
1276
 
1277
1277
  const {
1278
- get,
1278
+ get: get$1,
1279
1279
  set: set$1,
1280
1280
  wrapCommand
1281
1281
  } = create$2();
@@ -1417,7 +1417,7 @@ const diff2 = uid => {
1417
1417
  const {
1418
1418
  oldState,
1419
1419
  newState
1420
- } = get(uid);
1420
+ } = get$1(uid);
1421
1421
  const diffResult = diff$1(oldState, newState);
1422
1422
  return diffResult;
1423
1423
  };
@@ -2070,142 +2070,23 @@ const getScrollBarOffset$1 = (delta, finalDelta, size, scrollBarSize) => {
2070
2070
  };
2071
2071
  const getScrollBarY$1 = getScrollBarOffset$1;
2072
2072
 
2073
- const textSearch$6 = async (scheme, root, query) => {
2074
- string(scheme);
2075
- string(query);
2076
- const result = await invoke$1('ExtensionHostTextSearch.executeTextSearchProvider', scheme, query);
2077
- return result;
2078
- };
2079
-
2080
- const textSearch$5 = async (scheme, root, query, options, assetDir) => {
2081
- return invoke$1('ExtensionHostTextSearch.textSearchFetch', scheme, root, query, options, assetDir);
2073
+ const providers = Object.create(null);
2074
+ const add = providerMap => {
2075
+ Object.assign(providers, providerMap);
2082
2076
  };
2083
-
2084
- const textSearch$4 = async (scheme, root, query) => {
2085
- return invoke$1('ExtensionHostTextSearch.textSearchHtml', scheme, root, query);
2086
- };
2087
-
2088
- const textSearch$3 = async (scheme, root, query, options, assetDir) => {
2089
- return invoke$1('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
2077
+ const get = protocol => {
2078
+ return providers[protocol] || providers['default'];
2090
2079
  };
2091
2080
 
2092
- const getRipGrepArgs = ({
2093
- threads,
2094
- isCaseSensitive,
2095
- searchString,
2096
- useRegularExpression
2097
- }) => {
2098
- const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json'];
2099
- ripGrepArgs.push('--threads', `${threads}`);
2100
- if (isCaseSensitive) {
2101
- ripGrepArgs.push('--case-sensitive');
2102
- } else {
2103
- ripGrepArgs.push('--ignore-case');
2104
- }
2105
- if (useRegularExpression) {
2106
- ripGrepArgs.push('--regexp', searchString);
2107
- } else {
2108
- ripGrepArgs.push('--fixed-strings');
2109
- ripGrepArgs.push('--');
2110
- ripGrepArgs.push(searchString);
2111
- }
2112
- ripGrepArgs.push('.');
2113
- return ripGrepArgs;
2081
+ const getTextSearchProvider = scheme => {
2082
+ return get(scheme);
2114
2083
  };
2115
2084
 
2116
- const Electron = 2;
2117
- const Remote = 3;
2118
-
2119
- const createLazyRpc = rpcId => {
2120
- let rpcPromise;
2121
- let factory;
2122
- const createRpc = async () => {
2123
- const rpc = await factory();
2124
- set$g(rpcId, rpc);
2125
- };
2126
- const ensureRpc = async () => {
2127
- if (!rpcPromise) {
2128
- rpcPromise = createRpc();
2129
- }
2130
- await rpcPromise;
2131
- };
2132
- return {
2133
- setFactory(value) {
2134
- factory = value;
2135
- },
2136
- async invoke(method, ...params) {
2137
- await ensureRpc();
2138
- const rpc = get$1(rpcId);
2139
- return rpc.invoke(method, ...params);
2140
- }
2141
- };
2142
- };
2143
-
2144
- const {
2145
- set} = SearchProcess;
2146
- const {
2147
- invoke,
2148
- setFactory
2149
- } = createLazyRpc(RpcId.SearchProcess);
2150
-
2151
- const textSearch$2 = async (scheme, root, query, options, assetDir, platform) => {
2152
- const ripGrepArgs = getRipGrepArgs({
2153
- ...options,
2154
- searchString: query
2155
- });
2156
- const actualOptions = {
2157
- ripGrepArgs,
2158
- searchDir: root
2159
- };
2160
- if (platform === Remote || platform === Electron) {
2161
- const result = await invoke('TextSearch.search', actualOptions);
2162
- // TODO api is weird
2163
- // @ts-ignore
2164
- return result.results;
2165
- }
2166
- const results = await invoke$1('SearchProcess.invoke', 'TextSearch.search', actualOptions);
2167
- // TODO api is weird
2168
- return results.results;
2169
- };
2170
-
2171
- const textSearch$1 = async (scheme, root, query) => {
2172
- // TODO ask renderer worker for files
2173
- const entries = Object.entries({});
2174
- const results = [];
2175
- for (const [key, value] of entries) {
2176
- // @ts-ignore
2177
- if (value.includes(query)) {
2178
- results.push([key, [{
2179
- absoluteOffset: 0,
2180
- preview: value
2181
- }]]);
2182
- }
2183
- }
2184
- return results;
2185
- };
2186
-
2187
- const getProvider = scheme => {
2188
- switch (scheme) {
2189
- case '':
2190
- return textSearch$2;
2191
- case 'web':
2192
- return textSearch$1;
2193
- case 'fetch':
2194
- return textSearch$5;
2195
- case 'html':
2196
- return textSearch$4;
2197
- case 'memfs':
2198
- return textSearch$3;
2199
- default:
2200
- return textSearch$6;
2201
- }
2202
- };
2203
-
2204
- const textSearch = async (root, query, options, assetDir, platform) => {
2085
+ const textSearch$6 = async (root, query, options, assetDir, platform) => {
2205
2086
  string(root);
2206
2087
  string(query);
2207
2088
  const scheme = getProtocol$1(root);
2208
- const provider = getProvider(scheme);
2089
+ const provider = getTextSearchProvider(scheme);
2209
2090
  const results = await provider(scheme, root, query, options, assetDir, platform);
2210
2091
  return results;
2211
2092
  };
@@ -2224,23 +2105,25 @@ const handleUpdateFull = async (state, update) => {
2224
2105
  value,
2225
2106
  threads,
2226
2107
  includeValue,
2227
- excludeValue
2108
+ excludeValue,
2109
+ assetDir,
2110
+ platform
2228
2111
  } = partialNewState;
2229
2112
  const root = state.workspacePath;
2230
2113
  const scheme = getProtocol$1(root);
2231
- const results = await textSearch(root, value, {
2114
+ const results = await textSearch$6(root, value, {
2232
2115
  threads,
2233
2116
  isCaseSensitive: Boolean(flags & MatchCase$2),
2234
2117
  useRegularExpression: Boolean(flags & UseRegularExpression$2),
2235
2118
  exclude: excludeValue,
2236
2119
  include: includeValue,
2237
- assetDir: state.assetDir,
2120
+ assetDir: assetDir,
2238
2121
  root,
2239
2122
  query: value,
2240
2123
  scheme,
2241
2124
  flags,
2242
2125
  matchWholeWord: Boolean(flags & MatchWholeWord$2)
2243
- }, state.assetDir, state.platform);
2126
+ }, assetDir, platform);
2244
2127
  if (!Array.isArray(results)) {
2245
2128
  throw new TypeError('results must be of type array');
2246
2129
  }
@@ -2278,6 +2161,62 @@ const handleUpdateFull = async (state, update) => {
2278
2161
  };
2279
2162
  };
2280
2163
 
2164
+ const getRipGrepArgs = ({
2165
+ threads,
2166
+ isCaseSensitive,
2167
+ searchString,
2168
+ useRegularExpression
2169
+ }) => {
2170
+ const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json'];
2171
+ ripGrepArgs.push('--threads', `${threads}`);
2172
+ if (isCaseSensitive) {
2173
+ ripGrepArgs.push('--case-sensitive');
2174
+ } else {
2175
+ ripGrepArgs.push('--ignore-case');
2176
+ }
2177
+ if (useRegularExpression) {
2178
+ ripGrepArgs.push('--regexp', searchString);
2179
+ } else {
2180
+ ripGrepArgs.push('--fixed-strings');
2181
+ ripGrepArgs.push('--');
2182
+ ripGrepArgs.push(searchString);
2183
+ }
2184
+ ripGrepArgs.push('.');
2185
+ return ripGrepArgs;
2186
+ };
2187
+
2188
+ const createLazyRpc = rpcId => {
2189
+ let rpcPromise;
2190
+ let factory;
2191
+ const createRpc = async () => {
2192
+ const rpc = await factory();
2193
+ set$g(rpcId, rpc);
2194
+ };
2195
+ const ensureRpc = async () => {
2196
+ if (!rpcPromise) {
2197
+ rpcPromise = createRpc();
2198
+ }
2199
+ await rpcPromise;
2200
+ };
2201
+ return {
2202
+ setFactory(value) {
2203
+ factory = value;
2204
+ },
2205
+ async invoke(method, ...params) {
2206
+ await ensureRpc();
2207
+ const rpc = get$2(rpcId);
2208
+ return rpc.invoke(method, ...params);
2209
+ }
2210
+ };
2211
+ };
2212
+
2213
+ const {
2214
+ set} = SearchProcess;
2215
+ const {
2216
+ invoke,
2217
+ setFactory
2218
+ } = createLazyRpc(RpcId.SearchProcess);
2219
+
2281
2220
  const waitForNextFrame = async () => {
2282
2221
  await new Promise(r => {
2283
2222
  requestAnimationFrame(r);
@@ -2297,7 +2236,7 @@ const textSearchIncremental = async (root, query, options, assetDir, platform, s
2297
2236
  };
2298
2237
  const resultPromise = invoke('TextSearch.searchIncremental', actualOptions);
2299
2238
  for (let i = 0; i < 100; i++) {
2300
- const latest = get(uid);
2239
+ const latest = get$1(uid);
2301
2240
  const {
2302
2241
  newState
2303
2242
  } = latest;
@@ -2310,7 +2249,7 @@ const textSearchIncremental = async (root, query, options, assetDir, platform, s
2310
2249
  const listHeight = height - headerHeight;
2311
2250
  const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
2312
2251
  const visible = await invoke('TextSearch.getIncrementalResults', searchId, minLineY, minLineY + numberOfVisible);
2313
- const latest2 = get(uid);
2252
+ const latest2 = get$1(uid);
2314
2253
  if (!latest2 || latest2.newState.searchId !== searchId) {
2315
2254
  return;
2316
2255
  }
@@ -2347,7 +2286,7 @@ const handleUpdateIncremental = async (state, update) => {
2347
2286
  const root = state.workspacePath;
2348
2287
  const scheme = getProtocol$1(root);
2349
2288
  const searchId = crypto.randomUUID(); // TODO try to avoid side effect
2350
- const latest1 = get(uid);
2289
+ const latest1 = get$1(uid);
2351
2290
  const updatedState1 = {
2352
2291
  ...latest1.newState,
2353
2292
  ...partialNewState,
@@ -2763,6 +2702,9 @@ const launchSearchProcessNode = async () => {
2763
2702
  return rpc;
2764
2703
  };
2765
2704
 
2705
+ const Electron = 2;
2706
+ const Remote = 3;
2707
+
2766
2708
  const initialize = async platform => {
2767
2709
  if (platform === Electron) {
2768
2710
  setFactory(launchSearchProcessElectron);
@@ -4507,7 +4449,7 @@ const render2 = (uid, diffResult) => {
4507
4449
  const {
4508
4450
  oldState,
4509
4451
  newState
4510
- } = get(uid);
4452
+ } = get$1(uid);
4511
4453
  set$1(uid, newState, newState);
4512
4454
  const commands = applyRender(oldState, newState, diffResult);
4513
4455
  return commands;
@@ -4667,7 +4609,7 @@ const renderIncremental = uid => {
4667
4609
  const {
4668
4610
  oldState,
4669
4611
  newState
4670
- } = get(uid);
4612
+ } = get$1(uid);
4671
4613
  const oldDom = getDom(oldState);
4672
4614
  const newDom = getDom(newState);
4673
4615
  const patches = diff(oldDom, newDom);
@@ -4727,7 +4669,7 @@ const rerender = state => {
4727
4669
  const saveState = uid => {
4728
4670
  const {
4729
4671
  newState
4730
- } = get(uid);
4672
+ } = get$1(uid);
4731
4673
  const {
4732
4674
  value,
4733
4675
  replacement,
@@ -4986,10 +4928,75 @@ const commandMap = {
4986
4928
  'TextSearch.renderActions': renderActions,
4987
4929
  // TODO needed?
4988
4930
  'TextSearch.replaceAllAndPrompt': replaceAllAndPrompt,
4989
- 'TextSearch.textSearch': textSearch
4931
+ 'TextSearch.textSearch': textSearch$6
4932
+ };
4933
+
4934
+ const textSearch$5 = async (scheme, root, query) => {
4935
+ string(scheme);
4936
+ string(query);
4937
+ const result = await invoke$1('ExtensionHostTextSearch.executeTextSearchProvider', scheme, query);
4938
+ return result;
4939
+ };
4940
+
4941
+ const textSearch$4 = async (scheme, root, query, options, assetDir) => {
4942
+ return invoke$1('ExtensionHostTextSearch.textSearchFetch', scheme, root, query, options, assetDir);
4943
+ };
4944
+
4945
+ const textSearch$3 = async (scheme, root, query) => {
4946
+ return invoke$1('ExtensionHostTextSearch.textSearchHtml', scheme, root, query);
4947
+ };
4948
+
4949
+ const textSearch$2 = async (scheme, root, query, options, assetDir) => {
4950
+ return invoke$1('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
4951
+ };
4952
+
4953
+ const textSearch$1 = async (scheme, root, query, options, assetDir, platform) => {
4954
+ const ripGrepArgs = getRipGrepArgs({
4955
+ ...options,
4956
+ searchString: query
4957
+ });
4958
+ const actualOptions = {
4959
+ ripGrepArgs,
4960
+ searchDir: root
4961
+ };
4962
+ if (platform === Remote || platform === Electron) {
4963
+ const result = await invoke('TextSearch.search', actualOptions);
4964
+ // TODO api is weird
4965
+ // @ts-ignore
4966
+ return result.results;
4967
+ }
4968
+ const results = await invoke$1('SearchProcess.invoke', 'TextSearch.search', actualOptions);
4969
+ // TODO api is weird
4970
+ return results.results;
4971
+ };
4972
+
4973
+ const textSearch = async (scheme, root, query) => {
4974
+ // TODO ask renderer worker for files
4975
+ const entries = Object.entries({});
4976
+ const results = [];
4977
+ for (const [key, value] of entries) {
4978
+ // @ts-ignore
4979
+ if (value.includes(query)) {
4980
+ results.push([key, [{
4981
+ absoluteOffset: 0,
4982
+ preview: value
4983
+ }]]);
4984
+ }
4985
+ }
4986
+ return results;
4987
+ };
4988
+
4989
+ const textSearchProviderMap = {
4990
+ '': textSearch$1,
4991
+ web: textSearch,
4992
+ fetch: textSearch$4,
4993
+ html: textSearch$3,
4994
+ memfs: textSearch$2,
4995
+ default: textSearch$5
4990
4996
  };
4991
4997
 
4992
4998
  const listen = async () => {
4999
+ add(textSearchProviderMap);
4993
5000
  const rpc = await WebWorkerRpcClient.create({
4994
5001
  commandMap: commandMap
4995
5002
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"