@lvce-editor/search-process 12.1.0 → 13.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.
- package/dist/index.js +42 -53
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,35 +10,35 @@ import { pipeline } from 'node:stream/promises';
|
|
|
10
10
|
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
11
11
|
|
|
12
12
|
const searches$1 = Object.create(null);
|
|
13
|
-
const get$
|
|
13
|
+
const get$2 = id => {
|
|
14
14
|
return searches$1[id];
|
|
15
15
|
};
|
|
16
|
-
const set$
|
|
16
|
+
const set$2 = (id, search) => {
|
|
17
17
|
searches$1[id] = search;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
// @deprecated use TextSearch.getPullResults instead
|
|
21
21
|
const getIncrementalResults = (id, minLineY, maxLineY) => {
|
|
22
|
-
const item = get$
|
|
22
|
+
const item = get$2(id);
|
|
23
23
|
const visibleItems = item.getItems(minLineY, maxLineY);
|
|
24
24
|
return visibleItems;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const searches = Object.create(null);
|
|
28
|
-
const get$
|
|
28
|
+
const get$1 = id => {
|
|
29
29
|
return searches[id];
|
|
30
30
|
};
|
|
31
|
-
const set$
|
|
31
|
+
const set$1 = (id, search) => {
|
|
32
32
|
searches[id] = search;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const getPullProgress = id => {
|
|
36
|
-
const item = get$
|
|
36
|
+
const item = get$1(id);
|
|
37
37
|
return item.getProgress();
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
const getPullResults = id => {
|
|
41
|
-
const item = get$
|
|
41
|
+
const item = get$1(id);
|
|
42
42
|
const newItems = item.getNewItems();
|
|
43
43
|
return newItems;
|
|
44
44
|
};
|
|
@@ -799,10 +799,10 @@ const create$4 = (method, params) => {
|
|
|
799
799
|
};
|
|
800
800
|
};
|
|
801
801
|
const callbacks = Object.create(null);
|
|
802
|
-
const set
|
|
802
|
+
const set = (id, fn) => {
|
|
803
803
|
callbacks[id] = fn;
|
|
804
804
|
};
|
|
805
|
-
const get
|
|
805
|
+
const get = id => {
|
|
806
806
|
return callbacks[id];
|
|
807
807
|
};
|
|
808
808
|
const remove = id => {
|
|
@@ -818,7 +818,7 @@ const registerPromise = () => {
|
|
|
818
818
|
resolve,
|
|
819
819
|
promise
|
|
820
820
|
} = Promise.withResolvers();
|
|
821
|
-
set
|
|
821
|
+
set(id, resolve);
|
|
822
822
|
return {
|
|
823
823
|
id,
|
|
824
824
|
promise
|
|
@@ -983,7 +983,7 @@ const warn = (...args) => {
|
|
|
983
983
|
console.warn(...args);
|
|
984
984
|
};
|
|
985
985
|
const resolve = (id, response) => {
|
|
986
|
-
const fn = get
|
|
986
|
+
const fn = get(id);
|
|
987
987
|
if (!fn) {
|
|
988
988
|
console.log(response);
|
|
989
989
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -1213,7 +1213,7 @@ const createRpc = ipc => {
|
|
|
1213
1213
|
};
|
|
1214
1214
|
return rpc;
|
|
1215
1215
|
};
|
|
1216
|
-
const requiresSocket = () => {
|
|
1216
|
+
const requiresSocket$1 = () => {
|
|
1217
1217
|
return false;
|
|
1218
1218
|
};
|
|
1219
1219
|
const preparePrettyError = error => {
|
|
@@ -1223,7 +1223,7 @@ const logError = () => {
|
|
|
1223
1223
|
// handled by renderer worker
|
|
1224
1224
|
};
|
|
1225
1225
|
const handleMessage = event => {
|
|
1226
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1226
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
1227
1227
|
const actualExecute = event?.target?.execute || execute;
|
|
1228
1228
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1229
1229
|
};
|
|
@@ -1330,11 +1330,16 @@ const NodeWorkerRpcClient = {
|
|
|
1330
1330
|
create: create$7
|
|
1331
1331
|
};
|
|
1332
1332
|
|
|
1333
|
+
const requiresSocket = method => {
|
|
1334
|
+
return method === 'TextSearch.searchPull';
|
|
1335
|
+
};
|
|
1336
|
+
|
|
1333
1337
|
const handleElectronMessagePort = async messagePort => {
|
|
1334
1338
|
object(messagePort);
|
|
1335
1339
|
await ElectronMessagePortRpcClient.create({
|
|
1336
1340
|
commandMap: {},
|
|
1337
|
-
messagePort
|
|
1341
|
+
messagePort,
|
|
1342
|
+
requiresSocket
|
|
1338
1343
|
});
|
|
1339
1344
|
};
|
|
1340
1345
|
|
|
@@ -1348,7 +1353,8 @@ const handleWebSocket = async (handle, request) => {
|
|
|
1348
1353
|
await NodeWebSocketRpcClient.create({
|
|
1349
1354
|
commandMap: {},
|
|
1350
1355
|
handle,
|
|
1351
|
-
request
|
|
1356
|
+
request,
|
|
1357
|
+
requiresSocket
|
|
1352
1358
|
});
|
|
1353
1359
|
};
|
|
1354
1360
|
|
|
@@ -1773,7 +1779,7 @@ const collectStdoutIncremental = async (id, stdout, kill, maxSearchResults, char
|
|
|
1773
1779
|
return numberOfResults;
|
|
1774
1780
|
}
|
|
1775
1781
|
};
|
|
1776
|
-
set$
|
|
1782
|
+
set$2(id, search);
|
|
1777
1783
|
stdout.setEncoding(Utf8);
|
|
1778
1784
|
const handleLine = line => {
|
|
1779
1785
|
const parsedLine = JSON.parse(line);
|
|
@@ -1860,13 +1866,12 @@ const textSearchIncremental = async ({
|
|
|
1860
1866
|
return pipeLineResult;
|
|
1861
1867
|
};
|
|
1862
1868
|
|
|
1863
|
-
const collectStdoutPull = async (
|
|
1864
|
-
|
|
1869
|
+
const collectStdoutPull = async (searchId, stdout, kill, maxSearchResults, charsBefore, charsAfter, notifyResultsFound) => {
|
|
1870
|
+
let allSearchResults = [];
|
|
1865
1871
|
let buffer = '';
|
|
1866
1872
|
let stats = {};
|
|
1867
1873
|
let limitHit = false;
|
|
1868
1874
|
let done = false;
|
|
1869
|
-
let nextResultIndex = 0;
|
|
1870
1875
|
let hasUnfetchedResults = false;
|
|
1871
1876
|
let numberOfResults = 0;
|
|
1872
1877
|
const maybeNotifyResultsFound = () => {
|
|
@@ -1881,8 +1886,8 @@ const collectStdoutPull = async (id, stdout, kill, maxSearchResults, charsBefore
|
|
|
1881
1886
|
kill();
|
|
1882
1887
|
},
|
|
1883
1888
|
getNewItems() {
|
|
1884
|
-
const newItems = allSearchResults
|
|
1885
|
-
|
|
1889
|
+
const newItems = allSearchResults;
|
|
1890
|
+
allSearchResults = [];
|
|
1886
1891
|
hasUnfetchedResults = false;
|
|
1887
1892
|
return newItems;
|
|
1888
1893
|
},
|
|
@@ -1895,7 +1900,7 @@ const collectStdoutPull = async (id, stdout, kill, maxSearchResults, charsBefore
|
|
|
1895
1900
|
};
|
|
1896
1901
|
}
|
|
1897
1902
|
};
|
|
1898
|
-
set$
|
|
1903
|
+
set$1(searchId, search);
|
|
1899
1904
|
stdout.setEncoding(Utf8);
|
|
1900
1905
|
const handleLine = line => {
|
|
1901
1906
|
const parsedLine = JSON.parse(line);
|
|
@@ -1957,49 +1962,34 @@ const collectStdoutPull = async (id, stdout, kill, maxSearchResults, charsBefore
|
|
|
1957
1962
|
};
|
|
1958
1963
|
};
|
|
1959
1964
|
|
|
1960
|
-
let rpc = undefined;
|
|
1961
1965
|
const rpcMap = new Map();
|
|
1962
|
-
const get = () => {
|
|
1963
|
-
return rpc;
|
|
1964
|
-
};
|
|
1965
|
-
const set = value => {
|
|
1966
|
-
rpc = value;
|
|
1967
|
-
};
|
|
1968
|
-
const getById = id => {
|
|
1969
|
-
return rpcMap.get(id);
|
|
1970
|
-
};
|
|
1971
|
-
const setById = (id, value) => {
|
|
1972
|
-
rpcMap.set(id, value);
|
|
1973
|
-
};
|
|
1974
1966
|
const removeById = id => {
|
|
1975
1967
|
rpcMap.delete(id);
|
|
1976
1968
|
};
|
|
1977
1969
|
|
|
1978
|
-
const textSearchPull = async ({
|
|
1970
|
+
const textSearchPull = async (rpc, {
|
|
1971
|
+
charsAfter,
|
|
1972
|
+
charsBefore,
|
|
1979
1973
|
id,
|
|
1980
1974
|
maxSearchResults = 20_000,
|
|
1981
|
-
resultsFoundMethod,
|
|
1982
1975
|
ripGrepArgs = [],
|
|
1983
|
-
searchDir = ''
|
|
1976
|
+
searchDir = '',
|
|
1977
|
+
searchId,
|
|
1978
|
+
uid
|
|
1984
1979
|
}) => {
|
|
1985
|
-
const charsBefore = 26;
|
|
1986
|
-
const charsAfter = 50;
|
|
1987
|
-
const initialRpc = get();
|
|
1988
|
-
if (initialRpc) {
|
|
1989
|
-
setById(id, initialRpc);
|
|
1990
|
-
}
|
|
1991
1980
|
const childProcess = spawn(ripGrepArgs, {
|
|
1992
1981
|
cwd: searchDir
|
|
1993
1982
|
});
|
|
1994
1983
|
const notifyResultsFound = () => {
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
1984
|
+
// @ts-ignore
|
|
1985
|
+
rpc.send({
|
|
1986
|
+
jsonrpc: '2.0',
|
|
1987
|
+
method: 'TextSearch.handlePullResultsFound',
|
|
1988
|
+
params: [uid, searchId]
|
|
1989
|
+
});
|
|
2000
1990
|
};
|
|
2001
1991
|
try {
|
|
2002
|
-
const pipeLinePromise = collectStdoutPull(
|
|
1992
|
+
const pipeLinePromise = collectStdoutPull(searchId, childProcess.stdout, childProcess.kill, maxSearchResults, charsBefore, charsAfter, notifyResultsFound);
|
|
2003
1993
|
const closePromise = waitForProcessToExit(childProcess);
|
|
2004
1994
|
const [pipeLineResult, exitResult] = await Promise.all([pipeLinePromise, closePromise]);
|
|
2005
1995
|
if (exitResult.type === Error$1) {
|
|
@@ -2010,7 +2000,7 @@ const textSearchPull = async ({
|
|
|
2010
2000
|
}
|
|
2011
2001
|
return pipeLineResult;
|
|
2012
2002
|
} finally {
|
|
2013
|
-
removeById(
|
|
2003
|
+
removeById(searchId);
|
|
2014
2004
|
}
|
|
2015
2005
|
};
|
|
2016
2006
|
|
|
@@ -2064,10 +2054,9 @@ const getModule = method => {
|
|
|
2064
2054
|
const listen = async argv => {
|
|
2065
2055
|
const method = Auto(argv);
|
|
2066
2056
|
const create = getModule(method);
|
|
2067
|
-
|
|
2057
|
+
await create({
|
|
2068
2058
|
commandMap: commandMap
|
|
2069
2059
|
});
|
|
2070
|
-
set(rpc);
|
|
2071
2060
|
};
|
|
2072
2061
|
|
|
2073
2062
|
const main = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/search-process",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.1.0",
|
|
4
4
|
"description": "Search Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
"@lvce-editor/ripgrep": "^4.0.0"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=24"
|
|
30
30
|
}
|
|
31
31
|
}
|