@lvce-editor/shared-process 0.15.29 → 0.15.31
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 +4 -4
- 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/GetAccurateMemoryUsage/GetAccurateMemoryUsage.js +4 -4
- package/src/parts/GetErrorResponse/GetErrorResponse.js +25 -32
- 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/IsEnoentError/IsEnoentError.js +13 -0
- package/src/parts/JsonRpc/JsonRpc.js +8 -24
- package/src/parts/JsonRpcErrorResponse/JsonRpcErrorResponse.js +9 -0
- package/src/parts/JsonRpcEvent/JsonRpcEvent.js +9 -0
- package/src/parts/JsonRpcRequest/JsonRpcRequest.js +16 -0
- package/src/parts/JsonRpcSuccessResponse/JsonSuccessResponse.js +9 -0
- package/src/parts/ListProcessesWithMemoryUsageUnix/ListProcessesWithMemoryUsageUnix.js +4 -15
- package/src/parts/ModuleMap/ModuleMap.js +4 -0
- package/src/parts/OutputChannel/OutputChannel.ipc.js +5 -11
- package/src/parts/ParsePsOutput/ParsePsOutput.js +2 -1
- package/src/parts/Platform/Platform.ipc.js +2 -1
- package/src/parts/Platform/Platform.js +11 -1
- package/src/parts/Process/Process.ipc.js +2 -0
- package/src/parts/Process/Process.js +15 -1
- package/src/parts/SearchFile/SearchFile.js +2 -15
- package/src/parts/Terminal/Terminal.js +7 -16
- package/src/parts/TextSearch/TextSearch.js +5 -3
- package/src/parts/ToTextSearchResult/ToTextSearchResult.js +34 -10
- package/README.md +0 -41
- package/mocks/windows-process-tree.js +0 -1
|
@@ -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.31",
|
|
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.31",
|
|
21
|
+
"@lvce-editor/extension-host-helper-process": "0.15.31",
|
|
22
|
+
"@lvce-editor/pty-host": "0.15.31",
|
|
23
23
|
"debug": "^4.3.4",
|
|
24
24
|
"execa": "^7.1.1",
|
|
25
25
|
"exit-hook": "^3.2.0",
|
|
@@ -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
|
+
}
|
|
@@ -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,7 +1,7 @@
|
|
|
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
7
|
|
|
@@ -12,47 +12,40 @@ const shouldLogError = (error) => {
|
|
|
12
12
|
return true
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
const prettyError = PrettyError.prepare(error)
|
|
17
|
-
if (shouldLogError(error) && (!ipc || ipc.shouldLogError !== false)) {
|
|
18
|
-
PrintPrettyError.printPrettyError(prettyError, `[shared-process] `)
|
|
19
|
-
}
|
|
15
|
+
const getErrorProperty = (error, prettyError) => {
|
|
20
16
|
if (error && error instanceof CommandNotFoundError) {
|
|
21
17
|
return {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
code: JsonRpcErrorCode.MethodNotFound,
|
|
26
|
-
message: error.message,
|
|
27
|
-
data: error.stack,
|
|
28
|
-
},
|
|
18
|
+
code: JsonRpcErrorCode.MethodNotFound,
|
|
19
|
+
message: error.message,
|
|
20
|
+
data: error.stack,
|
|
29
21
|
}
|
|
30
22
|
}
|
|
31
23
|
if (!shouldLogError(error)) {
|
|
32
24
|
return {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
code:
|
|
37
|
-
message: `${error}`,
|
|
38
|
-
data: {
|
|
39
|
-
code: error.code,
|
|
40
|
-
},
|
|
25
|
+
code: JsonRpcErrorCode.Custom,
|
|
26
|
+
message: `${error}`,
|
|
27
|
+
data: {
|
|
28
|
+
code: error.code,
|
|
41
29
|
},
|
|
42
30
|
}
|
|
43
31
|
}
|
|
44
32
|
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
codeFrame: prettyError.codeFrame,
|
|
53
|
-
type: prettyError.type,
|
|
54
|
-
code: prettyError.code,
|
|
55
|
-
},
|
|
33
|
+
code: JsonRpcErrorCode.Custom,
|
|
34
|
+
message: prettyError.message,
|
|
35
|
+
data: {
|
|
36
|
+
stack: prettyError.stack,
|
|
37
|
+
codeFrame: prettyError.codeFrame,
|
|
38
|
+
type: prettyError.type,
|
|
39
|
+
code: prettyError.code,
|
|
56
40
|
},
|
|
57
41
|
}
|
|
58
42
|
}
|
|
43
|
+
|
|
44
|
+
export const getErrorResponse = (message, error, ipc) => {
|
|
45
|
+
const prettyError = PrettyError.prepare(error)
|
|
46
|
+
if (shouldLogError(error)) {
|
|
47
|
+
PrintPrettyError.printPrettyError(prettyError, `[shared-process] `)
|
|
48
|
+
}
|
|
49
|
+
const errorProperty = getErrorProperty(error, prettyError)
|
|
50
|
+
return JsonRpcErrorResponse.create(message, errorProperty)
|
|
51
|
+
}
|
|
@@ -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,39 +1,23 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as JsonRpcEvent from '../JsonRpcEvent/JsonRpcEvent.js'
|
|
2
|
+
import * as JsonRpcRequest from '../JsonRpcRequest/JsonRpcRequest.js'
|
|
3
3
|
import * as UnwrapJsonRpcResult from '../UnwrapJsonRpcResult/UnwrapJsonRpcResult.js'
|
|
4
4
|
|
|
5
5
|
export const send = (transport, method, ...params) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
method,
|
|
9
|
-
params,
|
|
10
|
-
})
|
|
6
|
+
const message = JsonRpcEvent.create(method, params)
|
|
7
|
+
transport.send(message)
|
|
11
8
|
}
|
|
12
9
|
|
|
13
10
|
export const invoke = async (ipc, method, ...params) => {
|
|
14
|
-
const {
|
|
15
|
-
ipc.send(
|
|
16
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
17
|
-
method,
|
|
18
|
-
params,
|
|
19
|
-
id,
|
|
20
|
-
})
|
|
11
|
+
const { message, promise } = JsonRpcRequest.create(method, params)
|
|
12
|
+
ipc.send(message)
|
|
21
13
|
const responseMessage = await promise
|
|
22
14
|
const result = UnwrapJsonRpcResult.unwrapJsonRpcResult(responseMessage)
|
|
23
15
|
return result
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
export const invokeAndTransfer = async (ipc, handle, method, ...params) => {
|
|
27
|
-
const {
|
|
28
|
-
ipc.sendAndTransfer(
|
|
29
|
-
{
|
|
30
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
31
|
-
method,
|
|
32
|
-
params,
|
|
33
|
-
id,
|
|
34
|
-
},
|
|
35
|
-
handle
|
|
36
|
-
)
|
|
19
|
+
const { message, promise } = JsonRpcRequest.create(method, params)
|
|
20
|
+
ipc.sendAndTransfer(message, handle)
|
|
37
21
|
const responseMessage = await promise
|
|
38
22
|
const result = UnwrapJsonRpcResult.unwrapJsonRpcResult(responseMessage)
|
|
39
23
|
return result
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Callback from '../Callback/Callback.js'
|
|
2
|
+
import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
|
|
3
|
+
|
|
4
|
+
export const create = (method, params) => {
|
|
5
|
+
const { id, promise } = Callback.registerPromise()
|
|
6
|
+
const message = {
|
|
7
|
+
jsonrpc: JsonRpcVersion.Two,
|
|
8
|
+
method,
|
|
9
|
+
params,
|
|
10
|
+
id,
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
message,
|
|
14
|
+
promise,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -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,8 @@ 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':
|
|
147
149
|
return ModuleId.Platform
|
|
148
150
|
case 'Preferences.getAll':
|
|
149
151
|
return ModuleId.Preferences
|
|
@@ -169,6 +171,8 @@ export const getModuleId = (commandId) => {
|
|
|
169
171
|
return ModuleId.RebuildNodePty
|
|
170
172
|
case 'Process.getPid':
|
|
171
173
|
case 'Process.kill':
|
|
174
|
+
case 'Process.getV8Version':
|
|
175
|
+
case 'Process.getNodeVersion':
|
|
172
176
|
return ModuleId.Process
|
|
173
177
|
case 'HandleNodeMessagePort.handleNodeMessagePort':
|
|
174
178
|
return ModuleId.HandleNodeMessagePort
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import * as
|
|
2
|
+
import * as JsonRpcEvent from '../JsonRpcEvent/JsonRpcEvent.js'
|
|
3
3
|
import * as OutputChannelState from '../OutputChannelState/OutputChannelState.js'
|
|
4
4
|
import * as OutputChannel from './OutputChannel.js'
|
|
5
5
|
|
|
@@ -17,19 +17,13 @@ const open = (socket, id, path) => {
|
|
|
17
17
|
}
|
|
18
18
|
const onData = (data) => {
|
|
19
19
|
console.log('send data', data)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
method: 'Output.handleData',
|
|
23
|
-
params: [data],
|
|
24
|
-
})
|
|
20
|
+
const message = JsonRpcEvent.create('Output.handleData', [data])
|
|
21
|
+
socket.send(message)
|
|
25
22
|
}
|
|
26
23
|
const onError = (error) => {
|
|
27
24
|
console.info(`[shared process] output channel error: ${error}`)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
method: 'Output.handleError',
|
|
31
|
-
params: [error],
|
|
32
|
-
})
|
|
25
|
+
const message = JsonRpcEvent.create('Output.handleError', [error])
|
|
26
|
+
socket.send(message)
|
|
33
27
|
}
|
|
34
28
|
const outputChannel = OutputChannel.open(path, onData, onError)
|
|
35
29
|
OutputChannelState.set(id, outputChannel)
|
|
@@ -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,6 @@ 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,
|
|
25
26
|
}
|
|
@@ -165,4 +165,14 @@ export const getSetupName = () => {
|
|
|
165
165
|
return 'Lvce-Setup'
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
export const version = '0.
|
|
168
|
+
export const version = '0.15.31'
|
|
169
|
+
|
|
170
|
+
export const commit = '85343c2'
|
|
171
|
+
|
|
172
|
+
export const getVersion = () => {
|
|
173
|
+
return version
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const getCommit = () => {
|
|
177
|
+
return commit
|
|
178
|
+
}
|
|
@@ -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,21 +1,9 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import * as
|
|
3
|
-
import * as IsEnoentErrorWindows from '../IsEnoentErrorWindows/IsEnoentErrorWindows.js'
|
|
2
|
+
import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
|
|
4
3
|
import * as LimitString from '../LimitString/LimitString.js'
|
|
5
4
|
import * as Logger from '../Logger/Logger.js'
|
|
6
5
|
import * as RipGrep from '../RipGrep/RipGrep.js'
|
|
7
6
|
|
|
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
7
|
// TODO don't necessarily need ripgrep to list all the files,
|
|
20
8
|
// maybe also a faster c program can do it
|
|
21
9
|
// another option would be to cache the results in renderer-worker and
|
|
@@ -32,8 +20,7 @@ export const searchFile = async (path, searchTerm, limit) => {
|
|
|
32
20
|
})
|
|
33
21
|
return LimitString.limitString(stdout, limit)
|
|
34
22
|
} catch (error) {
|
|
35
|
-
|
|
36
|
-
if (isEnoentError(error)) {
|
|
23
|
+
if (IsEnoentError.isEnoentError(error)) {
|
|
37
24
|
Logger.info(`[shared-process] ripgrep could not be found at "${RipGrep.ripGrepPath}"`)
|
|
38
25
|
return ``
|
|
39
26
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import * as
|
|
2
|
+
import * as JsonRpcEvent from '../JsonRpcEvent/JsonRpcEvent.js'
|
|
3
3
|
import * as PtyHost from '../PtyHost/PtyHost.js'
|
|
4
4
|
import * as TerminalState from '../TerminalState/TerminalState.js'
|
|
5
5
|
import { VError } from '../VError/VError.js'
|
|
@@ -38,11 +38,8 @@ export const create = async (ipc, id, cwd, command, args) => {
|
|
|
38
38
|
const terminal = createTerminal(ptyHost, ipc)
|
|
39
39
|
TerminalState.add(id, terminal)
|
|
40
40
|
// TODO use invoke
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
method: 'Terminal.create',
|
|
44
|
-
params: [id, cwd, command, args],
|
|
45
|
-
})
|
|
41
|
+
const message = JsonRpcEvent.create('Terminal.create', [id, cwd, command, args])
|
|
42
|
+
ptyHost.send(message)
|
|
46
43
|
} catch (error) {
|
|
47
44
|
throw new VError(error, `Failed to create terminal`)
|
|
48
45
|
}
|
|
@@ -57,11 +54,8 @@ export const write = (id, data) => {
|
|
|
57
54
|
return
|
|
58
55
|
}
|
|
59
56
|
// TODO should use invoke
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
method: 'Terminal.write',
|
|
63
|
-
params: [id, data],
|
|
64
|
-
})
|
|
57
|
+
const message = JsonRpcEvent.create('Terminal.write', [id, data])
|
|
58
|
+
ptyHost.send(message)
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
export const resize = (state, columns, rows) => {
|
|
@@ -73,12 +67,9 @@ export const dispose = async (id) => {
|
|
|
73
67
|
terminal.dispose()
|
|
74
68
|
TerminalState.remove(id)
|
|
75
69
|
const ptyHost = await PtyHost.getOrCreate()
|
|
70
|
+
const message = JsonRpcEvent.create('Terminal.dispose', [id])
|
|
76
71
|
// TODO use invoke
|
|
77
|
-
ptyHost.send(
|
|
78
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
79
|
-
method: 'Terminal.dispose',
|
|
80
|
-
params: [id],
|
|
81
|
-
})
|
|
72
|
+
ptyHost.send(message)
|
|
82
73
|
}
|
|
83
74
|
|
|
84
75
|
export const disposeAll = () => {
|
|
@@ -18,7 +18,7 @@ import * as ToTextSearchResult from '../ToTextSearchResult/ToTextSearchResult.js
|
|
|
18
18
|
// TODO update client
|
|
19
19
|
// TODO not always run nice, maybe configure nice via flag/options
|
|
20
20
|
|
|
21
|
-
const collectStdout = async (childProcess, maxSearchResults) => {
|
|
21
|
+
const collectStdout = async (childProcess, maxSearchResults, charsBefore, charsAfter) => {
|
|
22
22
|
const allSearchResults = Object.create(null)
|
|
23
23
|
let buffer = ''
|
|
24
24
|
let stats = {}
|
|
@@ -43,7 +43,7 @@ const collectStdout = async (childProcess, maxSearchResults) => {
|
|
|
43
43
|
break
|
|
44
44
|
case RipGrepParsedLineType.Match:
|
|
45
45
|
const remaining = maxSearchResults - numberOfResults
|
|
46
|
-
const matches = ToTextSearchResult.toTextSearchResult(parsedLine, remaining)
|
|
46
|
+
const matches = ToTextSearchResult.toTextSearchResult(parsedLine, remaining, charsBefore, charsAfter)
|
|
47
47
|
numberOfResults += matches.length
|
|
48
48
|
allSearchResults[parsedLine.data.path.text].push(...matches)
|
|
49
49
|
break
|
|
@@ -104,6 +104,8 @@ const collectStdout = async (childProcess, maxSearchResults) => {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
export const search = async (searchDir, searchString, { threads = 1, maxSearchResults = 20_000, isCaseSensitive = false } = {}) => {
|
|
107
|
+
const charsBefore = 26
|
|
108
|
+
const charsAfter = 50
|
|
107
109
|
const ripGrepArgs = GetTextSearchRipGrepArgs.getRipGrepArgs({
|
|
108
110
|
threads,
|
|
109
111
|
isCaseSensitive,
|
|
@@ -112,7 +114,7 @@ export const search = async (searchDir, searchString, { threads = 1, maxSearchRe
|
|
|
112
114
|
const childProcess = RipGrep.spawn(ripGrepArgs, {
|
|
113
115
|
cwd: searchDir,
|
|
114
116
|
})
|
|
115
|
-
const pipeLinePromise = collectStdout(childProcess, maxSearchResults)
|
|
117
|
+
const pipeLinePromise = collectStdout(childProcess, maxSearchResults, charsBefore, charsAfter)
|
|
116
118
|
const closePromise = new Promise((resolve, reject) => {
|
|
117
119
|
// TODO use pipeline / transform stream maybe
|
|
118
120
|
const handleClose = () => {
|
|
@@ -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/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 {}
|