@lvce-editor/shared-process 0.15.30 → 0.15.32
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/config/builtinCommands.json +1 -1
- package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +7 -1
- package/extensions/builtin.theme-cobalt2/color-theme.json +3 -1
- package/package.json +5 -5
- package/src/parts/AddAccurateMemoryUsage/AddAccurateMemoryUsage.js +9 -0
- package/src/parts/ByteSize/ByteSize.js +4 -0
- package/src/parts/Cli/Cli.js +4 -21
- package/src/parts/CliCommandType/CliCommandType.js +1 -0
- package/src/parts/CliModule/CliModule.js +22 -0
- package/src/parts/CliStatus/CliStatus.js +6 -0
- package/src/parts/EncodingType/EncodingType.js +1 -0
- package/src/parts/Env/Env.js +16 -0
- package/src/parts/ErrorCodes/ErrorCodes.js +1 -0
- package/src/parts/GetAccurateMemoryUsage/GetAccurateMemoryUsage.js +4 -4
- package/src/parts/GetAppImagePath/GetAppImagePath.js +3 -1
- package/src/parts/GetErrorResponse/GetErrorResponse.js +27 -40
- package/src/parts/GetStatusString/GetStatusString.js +70 -0
- package/src/parts/GetSuccessResponse/GetSuccessResponse.js +3 -6
- package/src/parts/HandleCliArgs/HandleCliArgs.js +3 -3
- package/src/parts/HasPositiveMemoryUsage/HasPositiveMemoryUsage.js +3 -0
- package/src/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +0 -1
- package/src/parts/IpcChildWithNodeWorker/IpcChildWithNodeWorker.js +0 -1
- package/src/parts/IsElectron/IsElectron.js +3 -1
- package/src/parts/IsEnoentError/IsEnoentError.js +13 -0
- package/src/parts/JsonRpcErrorResponse/JsonRpcErrorResponse.js +9 -0
- package/src/parts/JsonRpcSuccessResponse/JsonSuccessResponse.js +9 -0
- package/src/parts/ListProcessesWithMemoryUsageUnix/ListProcessesWithMemoryUsageUnix.js +4 -15
- package/src/parts/ModuleMap/ModuleMap.js +5 -0
- package/src/parts/ParsePsOutput/ParsePsOutput.js +2 -1
- package/src/parts/Platform/Platform.ipc.js +3 -1
- package/src/parts/Platform/Platform.js +17 -1
- package/src/parts/Process/Process.ipc.js +2 -0
- package/src/parts/Process/Process.js +15 -1
- package/src/parts/ProcessExitEventType/ProcessExitEventType.js +2 -0
- package/src/parts/RipGrep/RipGrep.js +24 -14
- package/src/parts/SearchFile/SearchFile.js +12 -24
- package/src/parts/ShouldLogError/ShouldLogError.js +8 -0
- package/src/parts/TextSearch/TextSearch.js +15 -26
- package/src/parts/TextSearchError/TextSearchError.js +15 -0
- package/src/parts/ToTextSearchResult/ToTextSearchResult.js +34 -10
- package/src/parts/Trace/Trace.js +3 -1
- package/src/parts/WaitForProcessToExit/WaitForProcessToExit.js +29 -0
- package/README.md +0 -41
- package/mocks/windows-process-tree.js +0 -1
- package/src/parts/GetTextSearchRipGrepArgs/GetTextSearchRipGrepArgs.js +0 -14
|
@@ -74,7 +74,8 @@ const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"\\]+/
|
|
|
74
74
|
const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
|
|
75
75
|
const RE_STRING_BACKTICK_QUOTE_CONTENT = /^[^`]+/
|
|
76
76
|
const RE_KEYWORD =
|
|
77
|
-
/^(?:7z|7za|7zr|alias|anacron|apk|apt-get|ar|asciidoctor|awk|base64|basename|bash|bg|bind|blkid|break|brew|brotli|builtin|bunzip|bunzip2|caller|cargo|case|cat|catdoc|cd|chmod|chown|circleci|clear|cmp|command|compgen|complete|continue|cp|cryptsetup|curl|curl|cut|cygstart|dde-open|defaults|deno|diff|dirname|dirs|disown|do|docker|done|done|dpkg-trigger|dpkg|du|echo|egrep|elif|else|emulate|enable|enlightenment_open|esac|eval|eval_gettext|exec|exit|expr|false|fc|fg|fi|find|for|free|function|fuzzponent|fzf|g\+\+|gatsby|gcc|gcloud|gdbus|getopts|gio|git|gnome-open|google-chrome-beta|google-chrome|grep|groupadd|grub-mount|gs|gulp|gvfs-open|gzip|hash|hdiutil|head|help|hexdump|history|identity|if|ifconfig|in|install-plugin|install|ip|jobs|jq|kbd_mode|kde-open|kdialog|kfmclient|kill|killall|ldconfig|less|let|lha|ln|loadkeys|local|logout|ls|ls|lunzip|lzip|lzma|makepkg|miniunz|miniunzip|mkdir|mktemp|mount|mpicc|mv|node|nohup|npm|npx|open|pacman|pcmanfm|pdftotext|pkg|plutil|pnpm|popd|prezip-bin|printf|println|ps|pushd|pwd|python3|rar|read|readlink|readonly|realpath|return|rm|route|rpm|rsync|sed|set|setfont|sh|sha256sum|shift|shopt|sleep|snap|sort|source|sponge|start-stop-daemon|stty|sudo|suspend|tail|tar|tee|test|texi2dvi|then|times|touch|trap|true|tty|tune2fs|type|ulimit|umask|umask|unalias|unarj|unmkinitramfs|unmount|unrar|unset|unwrapdiff|unzip|unzoo|update-alternatives|update-desktop-database|update-mime-database|useradd|vim|wait|wc|wget|which|while|wp|xargs|xprop|xz|yarn|yum|zenity|zip|zoo|zsh|zstd)\b/
|
|
77
|
+
/^(?:7z|7za|7zr|Xdialog|alias|anacron|apk|apt-get|ar|asciidoctor|awk|base64|basename|bash|bg|bind|blkid|break|brew|brotli|builtin|bunzip|bunzip2|caller|cargo|case|cat|catdoc|cd|chmod|chown|circleci|clear|cmp|command|compgen|complete|continue|cp|cryptsetup|curl|curl|cut|cygstart|dde-open|defaults|deno|diff|dirname|dirs|disown|do|docker|done|done|dpkg-trigger|dpkg|du|echo|egrep|elif|else|emulate|enable|enlightenment_open|esac|eval|eval_gettext|exec|exit|expr|false|fc|fg|fi|find|for|free|function|fuzzponent|fzf|g\+\+|gatsby|gcc|gcloud|gdbus|getopts|gio|git|gnome-open|google-chrome-beta|google-chrome|grep|groupadd|grub-mount|gs|gulp|gvfs-open|gzip|hash|hdiutil|head|help|hexdump|history|identity|if|ifconfig|in|install-plugin|install|ip|jobs|jq|kbd_mode|kde-open|kdialog|kfmclient|kill|killall|ldconfig|less|let|lha|ln|loadkeys|local|logout|ls|ls|lunzip|lzip|lzma|makepkg|miniunz|miniunzip|mkdir|mktemp|mount|mpicc|mv|node|nohup|npm|npx|open|pacman|pcmanfm|pdftotext|pkg|plutil|pnpm|popd|prezip-bin|printf|println|ps|pushd|pwd|python3|rar|read|readlink|readonly|realpath|return|rm|route|rpm|rsync|sed|set|setfont|sh|sha256sum|shift|shopt|sleep|snap|sort|source|sponge|start-stop-daemon|stty|sudo|suspend|tail|tar|tee|test|texi2dvi|then|times|touch|trap|true|tty|tune2fs|type|ulimit|umask|umask|unalias|unarj|unmkinitramfs|unmount|unrar|unset|unwrapdiff|unzip|unzoo|update-alternatives|update-desktop-database|update-mime-database|useradd|vim|wait|wc|wget|which|while|wp|xargs|xprop|xz|yarn|yum|zenity|zip|zoo|zsh|zstd)\b/
|
|
78
|
+
|
|
78
79
|
const RE_VARIABLE_NAME = /^[a-zA-Z\_\/\-\$][a-zA-Z\_\/\-\$#\d\-]*/
|
|
79
80
|
const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)<>\!\|\+\&\>\)]/
|
|
80
81
|
const RE_NUMERIC = /^\d+(?=\s|$)/
|
|
@@ -83,6 +84,7 @@ const RE_EOF_START = /^<<\s*([\w\!]+)/
|
|
|
83
84
|
const RE_EOF_CONTENT = /.*/s
|
|
84
85
|
const RE_STRING_ESCAPE = /^\\./
|
|
85
86
|
const RE_BACKSLASH_AT_END = /^\\$/
|
|
87
|
+
const RE_OR = /\|\|/
|
|
86
88
|
|
|
87
89
|
export const initialLineState = {
|
|
88
90
|
state: State.TopLevelContent,
|
|
@@ -353,6 +355,7 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
353
355
|
case 'zoo':
|
|
354
356
|
case 'zsh':
|
|
355
357
|
case 'zstd':
|
|
358
|
+
case 'Xdialog':
|
|
356
359
|
token = TokenType.Function
|
|
357
360
|
state = State.AfterFunctionName
|
|
358
361
|
break
|
|
@@ -491,6 +494,9 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
491
494
|
token = TokenType.Punctuation
|
|
492
495
|
state = State.InsideEof
|
|
493
496
|
stringEnd = next[1]
|
|
497
|
+
} else if ((next = part.match(RE_OR))) {
|
|
498
|
+
token = TokenType.Punctuation
|
|
499
|
+
state = State.TopLevelContent
|
|
494
500
|
} else if ((next = part.match(RE_PUNCTUATION))) {
|
|
495
501
|
token = TokenType.Punctuation
|
|
496
502
|
state = State.AfterFunctionName
|
|
@@ -65,7 +65,9 @@
|
|
|
65
65
|
"TitleBarColorInactive": "rgba(204, 204, 204, 0.6)",
|
|
66
66
|
"TitleBarActiveBackground": "#15232D",
|
|
67
67
|
"TitleBarForeground": "rgba(255, 255, 255, 0.2)",
|
|
68
|
-
"TitleBarForegroundActive": "rgb(255, 255, 255)"
|
|
68
|
+
"TitleBarForegroundActive": "rgb(255, 255, 255)",
|
|
69
|
+
|
|
70
|
+
"WorkbenchForeground": "rgb(197, 197, 197)"
|
|
69
71
|
},
|
|
70
72
|
"tokenColors": [
|
|
71
73
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.32",
|
|
4
4
|
"description": "Utility package for @lvce-editor/server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/code-frame": "^7.22.5",
|
|
20
|
-
"@lvce-editor/extension-host": "0.15.
|
|
21
|
-
"@lvce-editor/extension-host-helper-process": "0.15.
|
|
22
|
-
"@lvce-editor/pty-host": "0.15.
|
|
20
|
+
"@lvce-editor/extension-host": "0.15.32",
|
|
21
|
+
"@lvce-editor/extension-host-helper-process": "0.15.32",
|
|
22
|
+
"@lvce-editor/pty-host": "0.15.32",
|
|
23
23
|
"debug": "^4.3.4",
|
|
24
24
|
"execa": "^7.1.1",
|
|
25
25
|
"exit-hook": "^3.2.0",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lines-and-columns": "^2.0.3",
|
|
29
29
|
"p-queue": "^7.3.4",
|
|
30
30
|
"parse-json": "^7.0.0",
|
|
31
|
-
"tar-fs": "^
|
|
31
|
+
"tar-fs": "^3.0.3",
|
|
32
32
|
"ws": "^8.13.0",
|
|
33
33
|
"xdg-basedir": "^5.1.0"
|
|
34
34
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as GetAccurateMemoryUsage from '../GetAccurateMemoryUsage/GetAccurateMemoryUsage.js'
|
|
2
|
+
|
|
3
|
+
export const addAccurateMemoryUsage = async (process) => {
|
|
4
|
+
const accurateMemoryUsage = await GetAccurateMemoryUsage.getAccurateMemoryUsage(process.pid)
|
|
5
|
+
return {
|
|
6
|
+
...process,
|
|
7
|
+
memory: accurateMemoryUsage,
|
|
8
|
+
}
|
|
9
|
+
}
|
package/src/parts/Cli/Cli.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as CliModule from '../CliModule/CliModule.js'
|
|
2
2
|
import * as Logger from '../Logger/Logger.js'
|
|
3
3
|
import * as Process from '../Process/Process.js'
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
case CliCommandType.Install:
|
|
8
|
-
return import('../CliInstall/CliInstall.js')
|
|
9
|
-
case CliCommandType.List:
|
|
10
|
-
return import('../CliList/CliList.js')
|
|
11
|
-
case CliCommandType.Link:
|
|
12
|
-
return import('../CliLink/CliLink.js')
|
|
13
|
-
case CliCommandType.Unlink:
|
|
14
|
-
return import('../CliUnlink/CliUnlink.js')
|
|
15
|
-
default:
|
|
16
|
-
throw new Error(`command not found ${argv0}`)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const handleCliArgs = async (argv) => {
|
|
21
|
-
const argv0 = argv[0]
|
|
22
|
-
const module = await getModule(argv0)
|
|
23
|
-
// console.log('handle cli args')
|
|
5
|
+
export const handleCliArgs = async (parsedArgs) => {
|
|
6
|
+
const module = await CliModule.getModule(parsedArgs)
|
|
24
7
|
try {
|
|
25
|
-
await module.handleCliArgs(
|
|
8
|
+
await module.handleCliArgs(parsedArgs._)
|
|
26
9
|
} catch (error) {
|
|
27
10
|
Logger.error(error)
|
|
28
11
|
Process.setExitCode(1)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as Assert from '../Assert/Assert.js'
|
|
2
|
+
import * as CliCommandType from '../CliCommandType/CliCommandType.js'
|
|
3
|
+
|
|
4
|
+
export const getModule = (parsedArgs) => {
|
|
5
|
+
Assert.object(parsedArgs)
|
|
6
|
+
if (parsedArgs[CliCommandType.Status]) {
|
|
7
|
+
return import('../CliStatus/CliStatus.js')
|
|
8
|
+
}
|
|
9
|
+
const argv0 = parsedArgs._[0]
|
|
10
|
+
switch (argv0) {
|
|
11
|
+
case CliCommandType.Install:
|
|
12
|
+
return import('../CliInstall/CliInstall.js')
|
|
13
|
+
case CliCommandType.List:
|
|
14
|
+
return import('../CliList/CliList.js')
|
|
15
|
+
case CliCommandType.Link:
|
|
16
|
+
return import('../CliLink/CliLink.js')
|
|
17
|
+
case CliCommandType.Unlink:
|
|
18
|
+
return import('../CliUnlink/CliUnlink.js')
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`command not found ${argv0}`)
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/parts/Env/Env.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
export const getFolder = () => {
|
|
2
2
|
return process.env.FOLDER || process.cwd()
|
|
3
3
|
}
|
|
4
|
+
|
|
5
|
+
export const getAppImagePath = () => {
|
|
6
|
+
return process.env.APPIMAGE
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const getElectronRunAsNode = () => {
|
|
10
|
+
return process.env.ELECTRON_RUN_AS_NODE
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const getNodeEnv = () => {
|
|
14
|
+
return process.env.NODE_ENV
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getRipGrepPath = () => {
|
|
18
|
+
return process.env.RIP_GREP_PATH
|
|
19
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { join } from 'node:path'
|
|
2
1
|
import { readFile } from 'node:fs/promises'
|
|
3
|
-
import {
|
|
2
|
+
import { join } from 'node:path'
|
|
4
3
|
import * as Assert from '../Assert/Assert.js'
|
|
4
|
+
import * as Character from '../Character/Character.js'
|
|
5
5
|
import * as EncodingType from '../EncodingType/EncodingType.js'
|
|
6
6
|
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
7
|
+
import { VError } from '../VError/VError.js'
|
|
7
8
|
|
|
8
9
|
export const getAccurateMemoryUsage = async (pid) => {
|
|
9
10
|
Assert.number(pid)
|
|
@@ -25,14 +26,13 @@ export const getAccurateMemoryUsage = async (pid) => {
|
|
|
25
26
|
throw error
|
|
26
27
|
}
|
|
27
28
|
const trimmedContent = content.trim()
|
|
28
|
-
const numberBlocks = trimmedContent.split(
|
|
29
|
+
const numberBlocks = trimmedContent.split(Character.Space)
|
|
29
30
|
const pageSize = 4096
|
|
30
31
|
const rss = Number.parseInt(numberBlocks[1]) * pageSize
|
|
31
32
|
const shared = Number.parseInt(numberBlocks[2]) * pageSize
|
|
32
33
|
const memory = rss - shared
|
|
33
34
|
return memory
|
|
34
35
|
} catch (error) {
|
|
35
|
-
// @ts-ignore
|
|
36
36
|
throw new VError(error, 'Failed to get accurate memory usage')
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -1,58 +1,45 @@
|
|
|
1
1
|
import { CommandNotFoundError } from '../CommandNotFoundError/CommandNotFoundError.js'
|
|
2
2
|
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
3
3
|
import * as JsonRpcErrorCode from '../JsonRpcErrorCode/JsonRpcErrorCode.js'
|
|
4
|
-
import * as
|
|
4
|
+
import * as JsonRpcErrorResponse from '../JsonRpcErrorResponse/JsonRpcErrorResponse.js'
|
|
5
5
|
import * as PrettyError from '../PrettyError/PrettyError.js'
|
|
6
6
|
import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js'
|
|
7
|
+
import * as ShouldLogError from '../ShouldLogError/ShouldLogError.js'
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
-
if (error && error.code === ErrorCodes.ENOENT) {
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
return true
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const getErrorResponse = (message, error, ipc) => {
|
|
16
|
-
const prettyError = PrettyError.prepare(error)
|
|
17
|
-
if (shouldLogError(error) && (!ipc || ipc.shouldLogError !== false)) {
|
|
18
|
-
PrintPrettyError.printPrettyError(prettyError, `[shared-process] `)
|
|
19
|
-
}
|
|
9
|
+
const getErrorProperty = (error, prettyError) => {
|
|
20
10
|
if (error && error instanceof CommandNotFoundError) {
|
|
21
11
|
return {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
code: JsonRpcErrorCode.MethodNotFound,
|
|
26
|
-
message: error.message,
|
|
27
|
-
data: error.stack,
|
|
28
|
-
},
|
|
12
|
+
code: JsonRpcErrorCode.MethodNotFound,
|
|
13
|
+
message: error.message,
|
|
14
|
+
data: error.stack,
|
|
29
15
|
}
|
|
30
16
|
}
|
|
31
|
-
if (!shouldLogError(error)) {
|
|
17
|
+
if (!ShouldLogError.shouldLogError(error)) {
|
|
32
18
|
return {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
code:
|
|
37
|
-
message: `${error}`,
|
|
38
|
-
data: {
|
|
39
|
-
code: error.code,
|
|
40
|
-
},
|
|
19
|
+
code: JsonRpcErrorCode.Custom,
|
|
20
|
+
message: `${error}`,
|
|
21
|
+
data: {
|
|
22
|
+
code: error.code,
|
|
41
23
|
},
|
|
42
24
|
}
|
|
43
25
|
}
|
|
44
26
|
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
codeFrame: prettyError.codeFrame,
|
|
53
|
-
type: prettyError.type,
|
|
54
|
-
code: prettyError.code,
|
|
55
|
-
},
|
|
27
|
+
code: JsonRpcErrorCode.Custom,
|
|
28
|
+
message: prettyError.message,
|
|
29
|
+
data: {
|
|
30
|
+
stack: prettyError.stack,
|
|
31
|
+
codeFrame: prettyError.codeFrame,
|
|
32
|
+
type: prettyError.type,
|
|
33
|
+
code: prettyError.code,
|
|
56
34
|
},
|
|
57
35
|
}
|
|
58
36
|
}
|
|
37
|
+
|
|
38
|
+
export const getErrorResponse = (message, error, ipc) => {
|
|
39
|
+
const prettyError = PrettyError.prepare(error)
|
|
40
|
+
if (ShouldLogError.shouldLogError(error)) {
|
|
41
|
+
PrintPrettyError.printPrettyError(prettyError, `[shared-process] `)
|
|
42
|
+
}
|
|
43
|
+
const errorProperty = getErrorProperty(error, prettyError)
|
|
44
|
+
return JsonRpcErrorResponse.create(message, errorProperty)
|
|
45
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as Platform from '../Platform/Platform.js'
|
|
2
|
+
import * as ByteSize from '../ByteSize/ByteSize.js'
|
|
3
|
+
import * as Os from 'node:os'
|
|
4
|
+
|
|
5
|
+
const UiStrings = {
|
|
6
|
+
OsVersion: 'Os Version',
|
|
7
|
+
Cpus: 'CPUs',
|
|
8
|
+
Memory: 'Memory (System)',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const visitVersion = {
|
|
12
|
+
key: UiStrings.OsVersion,
|
|
13
|
+
getValue() {
|
|
14
|
+
const version = Platform.version
|
|
15
|
+
return version
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const visitCpus = {
|
|
20
|
+
key: UiStrings.Cpus,
|
|
21
|
+
getValue() {
|
|
22
|
+
const cpus = Os.cpus()
|
|
23
|
+
if (!cpus || cpus.length === 0) {
|
|
24
|
+
return ''
|
|
25
|
+
}
|
|
26
|
+
const firstCpu = cpus[0]
|
|
27
|
+
const model = firstCpu.model
|
|
28
|
+
const cpuLength = cpus.length
|
|
29
|
+
const speed = firstCpu.speed
|
|
30
|
+
return `${model} (${cpuLength} x ${speed})`
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const visitMemory = {
|
|
35
|
+
key: UiStrings.Memory,
|
|
36
|
+
getValue() {
|
|
37
|
+
const totalMemory = Os.totalmem()
|
|
38
|
+
const freeMemory = Os.freemem()
|
|
39
|
+
const totalGb = totalMemory / ByteSize.GB
|
|
40
|
+
const freeGb = freeMemory / ByteSize.GB
|
|
41
|
+
const totalGbShort = totalGb.toFixed(2)
|
|
42
|
+
const freeGbShort = freeGb.toFixed(2)
|
|
43
|
+
return `${totalGbShort} GB (${freeGbShort} GB free)`
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const getKeyLength = (visitor) => {
|
|
48
|
+
return visitor.key.length
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getLongestKeyLength = (visitors) => {
|
|
52
|
+
return Math.max(...visitors.map(getKeyLength))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const combineVisitors = (visitors) => {
|
|
56
|
+
const longestKeyLength = getLongestKeyLength(visitors)
|
|
57
|
+
const result = []
|
|
58
|
+
for (const visitor of visitors) {
|
|
59
|
+
const key = visitor.key
|
|
60
|
+
const value = visitor.getValue()
|
|
61
|
+
result.push(`${key}: ${value}`)
|
|
62
|
+
}
|
|
63
|
+
return result.join('\n')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const getStatusString = async () => {
|
|
67
|
+
const visitors = [visitVersion, visitCpus, visitMemory]
|
|
68
|
+
const result = combineVisitors(visitors)
|
|
69
|
+
return result
|
|
70
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as JsonRpcSuccessResponse from '../JsonRpcSuccessResponse/JsonSuccessResponse.js'
|
|
2
2
|
|
|
3
3
|
export const getSuccessResponse = (message, result) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
id: message.id,
|
|
7
|
-
result: result ?? null,
|
|
8
|
-
}
|
|
4
|
+
const resultProperty = result ?? null
|
|
5
|
+
return JsonRpcSuccessResponse.create(message, resultProperty)
|
|
9
6
|
}
|
|
@@ -2,10 +2,10 @@ import * as Assert from '../Assert/Assert.js'
|
|
|
2
2
|
import * as Cli from '../Cli/Cli.js'
|
|
3
3
|
import { VError } from '../VError/VError.js'
|
|
4
4
|
|
|
5
|
-
export const handleCliArgs = async (
|
|
5
|
+
export const handleCliArgs = async (parsedArgs) => {
|
|
6
6
|
try {
|
|
7
|
-
Assert.
|
|
8
|
-
await Cli.handleCliArgs(
|
|
7
|
+
Assert.object(parsedArgs)
|
|
8
|
+
await Cli.handleCliArgs(parsedArgs)
|
|
9
9
|
} catch (error) {
|
|
10
10
|
throw new VError(error, `Failed to execute cli command`)
|
|
11
11
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
2
|
+
import * as IsEnoentErrorWindows from '../IsEnoentErrorWindows/IsEnoentErrorWindows.js'
|
|
3
|
+
|
|
4
|
+
const isEnoentErrorLinux = (error) => {
|
|
5
|
+
return error.code === ErrorCodes.ENOENT
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const isEnoentError = (error) => {
|
|
9
|
+
if (!error) {
|
|
10
|
+
return false
|
|
11
|
+
}
|
|
12
|
+
return isEnoentErrorLinux(error) || IsEnoentErrorWindows.isEnoentErrorWindows(error)
|
|
13
|
+
}
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
+
import * as AddAccurateMemoryUsage from '../AddAccurateMemoryUsage/AddAccurateMemoryUsage.js'
|
|
1
2
|
import * as CreatePidMap from '../CreatePidMap/CreatePidMap.js'
|
|
2
|
-
import * as GetAccurateMemoryUsage from '../GetAccurateMemoryUsage/GetAccurateMemoryUsage.js'
|
|
3
3
|
import * as GetPsOutput from '../GetPsOutput/GetPsOutput.js'
|
|
4
|
+
import * as HasPositiveMemoryUsage from '../HasPositiveMemoryUsage/HasPositiveMemoryUsage.js'
|
|
4
5
|
import * as ParsePsOutput from '../ParsePsOutput/ParsePsOutput.js'
|
|
5
6
|
|
|
6
|
-
const addAccurateMemoryUsage = async (process) => {
|
|
7
|
-
const accurateMemoryUsage = await GetAccurateMemoryUsage.getAccurateMemoryUsage(process.pid)
|
|
8
|
-
return {
|
|
9
|
-
...process,
|
|
10
|
-
memory: accurateMemoryUsage,
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const hasPositiveMemoryUsage = (process) => {
|
|
15
|
-
return process.memory >= 0
|
|
16
|
-
}
|
|
17
|
-
|
|
18
7
|
export const listProcessesWithMemoryUsage = async (rootPid) => {
|
|
19
8
|
// console.time('getPsOutput')
|
|
20
9
|
const stdout = await GetPsOutput.getPsOutput()
|
|
@@ -25,8 +14,8 @@ export const listProcessesWithMemoryUsage = async (rootPid) => {
|
|
|
25
14
|
const parsed = ParsePsOutput.parsePsOutput(stdout, rootPid, pidMap)
|
|
26
15
|
// console.timeEnd('parsePsOutput')
|
|
27
16
|
// console.time('addAccurateMemoryUsage')
|
|
28
|
-
const parsedWithAccurateMemoryUsage = await Promise.all(parsed.map(addAccurateMemoryUsage))
|
|
17
|
+
const parsedWithAccurateMemoryUsage = await Promise.all(parsed.map(AddAccurateMemoryUsage.addAccurateMemoryUsage))
|
|
29
18
|
// console.timeEnd('addAccurateMemoryUsage')
|
|
30
|
-
const filtered = parsedWithAccurateMemoryUsage.filter(hasPositiveMemoryUsage)
|
|
19
|
+
const filtered = parsedWithAccurateMemoryUsage.filter(HasPositiveMemoryUsage.hasPositiveMemoryUsage)
|
|
31
20
|
return filtered
|
|
32
21
|
}
|
|
@@ -144,6 +144,9 @@ export const getModuleId = (commandId) => {
|
|
|
144
144
|
case 'Platform.getTestPath':
|
|
145
145
|
case 'Platform.getUserSettingsPath':
|
|
146
146
|
case 'Platform.setEnvironmentVariables':
|
|
147
|
+
case 'Platform.getCommit':
|
|
148
|
+
case 'Platform.getVersion':
|
|
149
|
+
case 'Platform.getDate':
|
|
147
150
|
return ModuleId.Platform
|
|
148
151
|
case 'Preferences.getAll':
|
|
149
152
|
return ModuleId.Preferences
|
|
@@ -169,6 +172,8 @@ export const getModuleId = (commandId) => {
|
|
|
169
172
|
return ModuleId.RebuildNodePty
|
|
170
173
|
case 'Process.getPid':
|
|
171
174
|
case 'Process.kill':
|
|
175
|
+
case 'Process.getV8Version':
|
|
176
|
+
case 'Process.getNodeVersion':
|
|
172
177
|
return ModuleId.Process
|
|
173
178
|
case 'HandleNodeMessagePort.handleNodeMessagePort':
|
|
174
179
|
return ModuleId.HandleNodeMessagePort
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// parse ps output based on vscode https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/node/ps.ts (License MIT)
|
|
2
2
|
|
|
3
3
|
import * as Assert from '../Assert/Assert.js'
|
|
4
|
+
import * as Character from '../Character/Character.js'
|
|
4
5
|
import * as ListProcessGetName from '../ListProcessGetName/ListProcessGetName.js'
|
|
5
6
|
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
6
7
|
|
|
@@ -25,7 +26,7 @@ export const parsePsOutput = (stdout, rootPid, pidMap) => {
|
|
|
25
26
|
Assert.string(stdout)
|
|
26
27
|
Assert.number(rootPid)
|
|
27
28
|
Assert.object(pidMap)
|
|
28
|
-
if (stdout ===
|
|
29
|
+
if (stdout === Character.EmptyString) {
|
|
29
30
|
return []
|
|
30
31
|
}
|
|
31
32
|
const lines = SplitLines.splitLines(stdout)
|
|
@@ -2,12 +2,12 @@ import * as Platform from '../Platform/Platform.js'
|
|
|
2
2
|
|
|
3
3
|
export const name = 'Platform'
|
|
4
4
|
|
|
5
|
-
// prettier-ignore
|
|
6
5
|
export const Commands = {
|
|
7
6
|
getAppDir: Platform.getAppDir,
|
|
8
7
|
getBuiltinExtensionsPath: Platform.getBuiltinExtensionsPath,
|
|
9
8
|
getCachedExtensionsPath: Platform.getCachedExtensionsPath,
|
|
10
9
|
getCacheDir: Platform.getCacheDir,
|
|
10
|
+
getCommit: Platform.getCommit,
|
|
11
11
|
getConfigDir: Platform.getConfigDir,
|
|
12
12
|
getDataDir: Platform.getDataDir,
|
|
13
13
|
getDisabledExtensionsPath: Platform.getDisabledExtensionsPath,
|
|
@@ -21,5 +21,7 @@ export const Commands = {
|
|
|
21
21
|
getTestPath: Platform.getTestPath,
|
|
22
22
|
getTmpDir: Platform.getTmpDir,
|
|
23
23
|
getUserSettingsPath: Platform.getUserSettingsPath,
|
|
24
|
+
getVersion: Platform.getVersion,
|
|
24
25
|
setEnvironmentVariables: Platform.setEnvironmentVariables,
|
|
26
|
+
getDate: Platform.getDate,
|
|
25
27
|
}
|
|
@@ -165,4 +165,20 @@ export const getSetupName = () => {
|
|
|
165
165
|
return 'Lvce-Setup'
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
export const version = '0.
|
|
168
|
+
export const version = '0.15.32'
|
|
169
|
+
|
|
170
|
+
export const commit = '4913b6f'
|
|
171
|
+
|
|
172
|
+
export const date = '2023-06-21T10:02:09.000Z'
|
|
173
|
+
|
|
174
|
+
export const getVersion = () => {
|
|
175
|
+
return version
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const getCommit = () => {
|
|
179
|
+
return commit
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const getDate = () => {
|
|
183
|
+
return date
|
|
184
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { VError } from '../VError/VError.js'
|
|
2
|
+
|
|
1
3
|
export const crash = (message) => {
|
|
2
4
|
throw new Error(message)
|
|
3
5
|
}
|
|
@@ -29,7 +31,11 @@ export const isConnected = () => {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export const kill = (pid, signal) => {
|
|
32
|
-
|
|
34
|
+
try {
|
|
35
|
+
process.kill(pid, signal)
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw new VError(error, `Failed to kill process ${pid} with signal ${signal}`)
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
export const getPid = () => {
|
|
@@ -37,3 +43,11 @@ export const getPid = () => {
|
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
export const { platform } = process
|
|
46
|
+
|
|
47
|
+
export const getV8Version = () => {
|
|
48
|
+
return process.versions.v8
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const getNodeVersion = () => {
|
|
52
|
+
return process.versions.node
|
|
53
|
+
}
|
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
import * as NodeChildProcess from 'node:child_process'
|
|
2
2
|
import * as Assert from '../Assert/Assert.js'
|
|
3
|
+
import * as Env from '../Env/Env.js'
|
|
3
4
|
import * as Exec from '../Exec/Exec.js'
|
|
4
5
|
import * as RgPath from '../RipGrepPath/RipGrepPath.js'
|
|
6
|
+
import { VError } from '../VError/VError.js'
|
|
5
7
|
|
|
6
|
-
export const ripGrepPath =
|
|
8
|
+
export const ripGrepPath = Env.getRipGrepPath() || RgPath.rgPath
|
|
7
9
|
|
|
8
10
|
export const spawn = (args, options) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
childProcess
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
try {
|
|
12
|
+
const childProcess = NodeChildProcess.spawn(RgPath.rgPath, args, options)
|
|
13
|
+
return {
|
|
14
|
+
childProcess,
|
|
15
|
+
on(event, listener) {
|
|
16
|
+
this.childProcess.on(event, listener)
|
|
17
|
+
},
|
|
18
|
+
off(event, listener) {
|
|
19
|
+
this.childProcess.off(event, listener)
|
|
20
|
+
},
|
|
21
|
+
once(event, listener) {
|
|
22
|
+
this.childProcess.once(event, listener)
|
|
23
|
+
},
|
|
24
|
+
stdout: childProcess.stdout,
|
|
25
|
+
stderr: childProcess.stderr,
|
|
26
|
+
kill() {
|
|
27
|
+
this.childProcess.kill()
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new VError(error, `Failed to spawn ripgrep`)
|
|
22
32
|
}
|
|
23
33
|
}
|
|
24
34
|
|
|
@@ -1,47 +1,35 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as Character from '../Character/Character.js'
|
|
3
|
+
import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
|
|
4
4
|
import * as LimitString from '../LimitString/LimitString.js'
|
|
5
5
|
import * as Logger from '../Logger/Logger.js'
|
|
6
6
|
import * as RipGrep from '../RipGrep/RipGrep.js'
|
|
7
7
|
|
|
8
|
-
const isEnoentErrorLinux = (error) => {
|
|
9
|
-
return error.code === ErrorCodes.ENOENT
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const isEnoentError = (error) => {
|
|
13
|
-
if (!error) {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
16
|
-
return isEnoentErrorLinux(error) || IsEnoentErrorWindows.isEnoentErrorWindows(error)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
8
|
// TODO don't necessarily need ripgrep to list all the files,
|
|
20
9
|
// maybe also a faster c program can do it
|
|
21
10
|
// another option would be to cache the results in renderer-worker and
|
|
22
11
|
// do a delta comparison, so the first time it would send 100kB
|
|
23
12
|
// but the second time only a few hundred bytes of changes
|
|
24
13
|
|
|
25
|
-
export const searchFile = async (
|
|
14
|
+
export const searchFile = async ({ searchPath = '', limit = 100, ripGrepArgs = [] }) => {
|
|
26
15
|
try {
|
|
27
|
-
Assert.string(
|
|
28
|
-
Assert.
|
|
16
|
+
Assert.string(searchPath)
|
|
17
|
+
Assert.array(ripGrepArgs)
|
|
29
18
|
Assert.number(limit)
|
|
30
|
-
const { stdout, stderr } = await RipGrep.exec(
|
|
31
|
-
cwd:
|
|
19
|
+
const { stdout, stderr } = await RipGrep.exec(ripGrepArgs, {
|
|
20
|
+
cwd: searchPath,
|
|
32
21
|
})
|
|
33
22
|
return LimitString.limitString(stdout, limit)
|
|
34
23
|
} catch (error) {
|
|
35
|
-
|
|
36
|
-
if (isEnoentError(error)) {
|
|
24
|
+
if (IsEnoentError.isEnoentError(error)) {
|
|
37
25
|
Logger.info(`[shared-process] ripgrep could not be found at "${RipGrep.ripGrepPath}"`)
|
|
38
|
-
return
|
|
26
|
+
return Character.EmptyString
|
|
39
27
|
}
|
|
40
28
|
// @ts-ignore
|
|
41
|
-
if (error && error.stderr ===
|
|
42
|
-
return
|
|
29
|
+
if (error && error.stderr === Character.EmptyString) {
|
|
30
|
+
return Character.EmptyString
|
|
43
31
|
}
|
|
44
32
|
Logger.error(error)
|
|
45
|
-
return
|
|
33
|
+
return Character.EmptyString
|
|
46
34
|
}
|
|
47
35
|
}
|
|
@@ -2,11 +2,13 @@ import { Writable } from 'node:stream'
|
|
|
2
2
|
import { pipeline } from 'node:stream/promises'
|
|
3
3
|
import * as EncodingType from '../EncodingType/EncodingType.js'
|
|
4
4
|
import * as GetNewLineIndex from '../GetNewLineIndex/GetNewLineIndex.js'
|
|
5
|
-
import * as
|
|
5
|
+
import * as ProcessExitEventType from '../ProcessExitEventType/ProcessExitEventType.js'
|
|
6
6
|
import * as RipGrep from '../RipGrep/RipGrep.js'
|
|
7
7
|
import * as RipGrepParsedLineType from '../RipGrepParsedLineType/RipGrepParsedLineType.js'
|
|
8
|
+
import { TextSearchError } from '../TextSearchError/TextSearchError.js'
|
|
8
9
|
import * as TextSearchResultType from '../TextSearchResultType/TextSearchResultType.js'
|
|
9
10
|
import * as ToTextSearchResult from '../ToTextSearchResult/ToTextSearchResult.js'
|
|
11
|
+
import * as WaitForProcessToExit from '../WaitForProcessToExit/WaitForProcessToExit.js'
|
|
10
12
|
// TODO update vscode-ripgrep when https://github.com/mhinz/vim-grepper/issues/244, https://github.com/BurntSushi/ripgrep/issues/1892 is fixed
|
|
11
13
|
|
|
12
14
|
// need to use '.' as last argument for ripgrep
|
|
@@ -18,7 +20,7 @@ import * as ToTextSearchResult from '../ToTextSearchResult/ToTextSearchResult.js
|
|
|
18
20
|
// TODO update client
|
|
19
21
|
// TODO not always run nice, maybe configure nice via flag/options
|
|
20
22
|
|
|
21
|
-
const collectStdout = async (childProcess, maxSearchResults) => {
|
|
23
|
+
const collectStdout = async (childProcess, maxSearchResults, charsBefore, charsAfter) => {
|
|
22
24
|
const allSearchResults = Object.create(null)
|
|
23
25
|
let buffer = ''
|
|
24
26
|
let stats = {}
|
|
@@ -43,7 +45,7 @@ const collectStdout = async (childProcess, maxSearchResults) => {
|
|
|
43
45
|
break
|
|
44
46
|
case RipGrepParsedLineType.Match:
|
|
45
47
|
const remaining = maxSearchResults - numberOfResults
|
|
46
|
-
const matches = ToTextSearchResult.toTextSearchResult(parsedLine, remaining)
|
|
48
|
+
const matches = ToTextSearchResult.toTextSearchResult(parsedLine, remaining, charsBefore, charsAfter)
|
|
47
49
|
numberOfResults += matches.length
|
|
48
50
|
allSearchResults[parsedLine.data.path.text].push(...matches)
|
|
49
51
|
break
|
|
@@ -103,30 +105,17 @@ const collectStdout = async (childProcess, maxSearchResults) => {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
export const search = async (
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
isCaseSensitive,
|
|
110
|
-
searchString,
|
|
111
|
-
})
|
|
108
|
+
export const search = async ({ searchDir = '', maxSearchResults = 20_000, ripGrepArgs = [] } = {}) => {
|
|
109
|
+
const charsBefore = 26
|
|
110
|
+
const charsAfter = 50
|
|
112
111
|
const childProcess = RipGrep.spawn(ripGrepArgs, {
|
|
113
112
|
cwd: searchDir,
|
|
114
113
|
})
|
|
115
|
-
const pipeLinePromise = collectStdout(childProcess, maxSearchResults)
|
|
116
|
-
const closePromise =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// TODO check type of error
|
|
123
|
-
console.error(error)
|
|
124
|
-
resolve(undefined)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
childProcess.once('close', handleClose)
|
|
128
|
-
childProcess.once('error', handleError)
|
|
129
|
-
})
|
|
130
|
-
await Promise.all([pipeLinePromise, closePromise])
|
|
131
|
-
return await pipeLinePromise
|
|
114
|
+
const pipeLinePromise = collectStdout(childProcess, maxSearchResults, charsBefore, charsAfter)
|
|
115
|
+
const closePromise = WaitForProcessToExit.waitForProcessToExit(childProcess)
|
|
116
|
+
const [pipeLineResult, exitResult] = await Promise.all([pipeLinePromise, closePromise])
|
|
117
|
+
if (exitResult.type === ProcessExitEventType.Error) {
|
|
118
|
+
throw new TextSearchError(exitResult.event)
|
|
119
|
+
}
|
|
120
|
+
return pipeLineResult
|
|
132
121
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
2
|
+
import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
|
|
3
|
+
|
|
4
|
+
export class TextSearchError extends Error {
|
|
5
|
+
constructor(cause) {
|
|
6
|
+
if (IsEnoentError.isEnoentError(cause)) {
|
|
7
|
+
super(`ripgrep path not found: ${cause}`)
|
|
8
|
+
this.code = ErrorCodes.E_RIP_GREP_NOT_FOUND
|
|
9
|
+
} else {
|
|
10
|
+
super(`ripgrep process error: ${cause}`)
|
|
11
|
+
this.code = cause.code
|
|
12
|
+
}
|
|
13
|
+
this.name = 'TextSearchError'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import * as EncodingType from '../EncodingType/EncodingType.js'
|
|
1
2
|
import * as TextSearchResultType from '../TextSearchResultType/TextSearchResultType.js'
|
|
2
3
|
|
|
3
|
-
const CHARS_BEFORE = 20
|
|
4
|
-
const CHARS_AFTER = 50
|
|
5
|
-
|
|
6
4
|
const getLines = (parsedLineData) => {
|
|
7
5
|
if (parsedLineData.lines.text) {
|
|
8
6
|
return parsedLineData.lines.text
|
|
9
7
|
}
|
|
10
8
|
if (parsedLineData.lines.bytes) {
|
|
11
|
-
return Buffer.from(parsedLineData.lines.bytes,
|
|
9
|
+
return Buffer.from(parsedLineData.lines.bytes, EncodingType.Base64).toString()
|
|
12
10
|
}
|
|
13
11
|
throw new Error(`unable to parse line data`)
|
|
14
12
|
}
|
|
@@ -20,20 +18,46 @@ const getRemainingSubMatches = (submatches, remaining) => {
|
|
|
20
18
|
return submatches.slice(0, remaining)
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
const RE_WORD = /\b/g
|
|
22
|
+
|
|
23
|
+
const leftCut = (text, final, charsBefore) => {
|
|
24
|
+
if (text.length < charsBefore) {
|
|
25
|
+
return text.length
|
|
26
|
+
}
|
|
27
|
+
let i = 0
|
|
28
|
+
while (RE_WORD.test(text)) {
|
|
29
|
+
if (final - RE_WORD.lastIndex < charsBefore) {
|
|
30
|
+
break
|
|
31
|
+
}
|
|
32
|
+
i = RE_WORD.lastIndex
|
|
33
|
+
RE_WORD.lastIndex++
|
|
34
|
+
}
|
|
35
|
+
RE_WORD.lastIndex = 0
|
|
36
|
+
if (final - i > charsBefore + 10) {
|
|
37
|
+
return final - charsBefore
|
|
38
|
+
}
|
|
39
|
+
return i
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const toTextSearchResult = (parsedLine, remaining, charsBefore, charsAfter) => {
|
|
24
43
|
const results = []
|
|
25
44
|
const parsedLineData = parsedLine.data
|
|
26
45
|
const lines = getLines(parsedLineData)
|
|
27
46
|
const lineNumber = parsedLineData.line_number
|
|
28
47
|
const submatches = parsedLineData.submatches
|
|
48
|
+
const linesLength = lines.length
|
|
29
49
|
for (const submatch of submatches) {
|
|
30
|
-
const previewStart = Math.max(submatch.start -
|
|
31
|
-
|
|
32
|
-
|
|
50
|
+
const previewStart = Math.max(submatch.start - charsBefore, 0)
|
|
51
|
+
let actualStart = previewStart
|
|
52
|
+
if (actualStart > 0) {
|
|
53
|
+
actualStart = leftCut(lines, submatch.start, charsBefore)
|
|
54
|
+
}
|
|
55
|
+
const previewEnd = Math.min(submatch.end + charsAfter, linesLength)
|
|
56
|
+
const previewText = lines.slice(actualStart, previewEnd)
|
|
33
57
|
results.push({
|
|
34
58
|
type: TextSearchResultType.Match,
|
|
35
|
-
start: submatch.start -
|
|
36
|
-
end: submatch.end -
|
|
59
|
+
start: submatch.start - actualStart,
|
|
60
|
+
end: submatch.end - actualStart,
|
|
37
61
|
lineNumber,
|
|
38
62
|
text: previewText,
|
|
39
63
|
})
|
package/src/parts/Trace/Trace.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as Env from '../Env/Env.js'
|
|
2
|
+
|
|
1
3
|
export const LEVEL = {
|
|
2
4
|
DEFAULT: 1,
|
|
3
5
|
VERBOSE: 2,
|
|
@@ -8,7 +10,7 @@ export const state = {
|
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export const trace =
|
|
11
|
-
|
|
13
|
+
Env.getNodeEnv() === 'test'
|
|
12
14
|
? () => {}
|
|
13
15
|
: (...args) => {
|
|
14
16
|
console.info('[Trace]', ...args)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as ProcessExitEventType from '../ProcessExitEventType/ProcessExitEventType.js'
|
|
2
|
+
|
|
3
|
+
export const waitForProcessToExit = async (childProcess) => {
|
|
4
|
+
const { type, event } = await new Promise((resolve, reject) => {
|
|
5
|
+
const cleanup = (value) => {
|
|
6
|
+
childProcess.off('close', handleClose)
|
|
7
|
+
childProcess.off('error', handleError)
|
|
8
|
+
resolve(value)
|
|
9
|
+
}
|
|
10
|
+
const handleClose = (event) => {
|
|
11
|
+
cleanup({
|
|
12
|
+
type: ProcessExitEventType.Exit,
|
|
13
|
+
event,
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
const handleError = (event) => {
|
|
17
|
+
cleanup({
|
|
18
|
+
type: ProcessExitEventType.Error,
|
|
19
|
+
event,
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
childProcess.on('close', handleClose)
|
|
23
|
+
childProcess.on('error', handleError)
|
|
24
|
+
})
|
|
25
|
+
return {
|
|
26
|
+
type,
|
|
27
|
+
event,
|
|
28
|
+
}
|
|
29
|
+
}
|
package/README.md
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# shared process
|
|
2
|
-
|
|
3
|
-
The `shared-process` is a NodeJS process that is used for sending files to the Browser via WebSockets.
|
|
4
|
-
|
|
5
|
-
- `shared-process` is created by the `web` process
|
|
6
|
-
- `shared-process` launches the `extension-host`
|
|
7
|
-
- `shared-process` communicates with `renderer-worker` via WebSockets
|
|
8
|
-
|
|
9
|
-
<!--
|
|
10
|
-
For example, this is how readFile is implemented in renderer-worker:
|
|
11
|
-
|
|
12
|
-
```js
|
|
13
|
-
export const readFile = (path) => {
|
|
14
|
-
return SharedProcess.invoke(/* readFile */ 101, /* path */ path)
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
This will be send to the shared-process
|
|
19
|
-
|
|
20
|
-
```json
|
|
21
|
-
{
|
|
22
|
-
"jsonrpc": "2.0",
|
|
23
|
-
"method": 101,
|
|
24
|
-
"params": ["/tmp/index.css"],
|
|
25
|
-
"id": 19
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
And the shared-process will send back
|
|
30
|
-
|
|
31
|
-
````json
|
|
32
|
-
{
|
|
33
|
-
"jsonrpc": "2.0",
|
|
34
|
-
"result": "h1 {\n font-size: 20px;\n}\n",
|
|
35
|
-
"id": 19
|
|
36
|
-
}
|
|
37
|
-
``` -->
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const getRipGrepArgs = ({ threads, isCaseSensitive, searchString }) => {
|
|
2
|
-
const ripGrepArgs = ['--smart-case', '--stats', '--json']
|
|
3
|
-
ripGrepArgs.push('--threads', `${threads}`)
|
|
4
|
-
if (isCaseSensitive) {
|
|
5
|
-
ripGrepArgs.push('--case-sensitive')
|
|
6
|
-
} else {
|
|
7
|
-
ripGrepArgs.push('--ignore-case')
|
|
8
|
-
}
|
|
9
|
-
ripGrepArgs.push('--fixed-strings')
|
|
10
|
-
ripGrepArgs.push('--')
|
|
11
|
-
ripGrepArgs.push(searchString)
|
|
12
|
-
ripGrepArgs.push('.')
|
|
13
|
-
return ripGrepArgs
|
|
14
|
-
}
|