@lvce-editor/shared-process 0.11.2 → 0.11.4
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/extensions/builtin.language-basics-xml/README.md +1 -1
- package/extensions/builtin.language-basics-xml/extension.json +14 -12
- package/extensions/builtin.language-basics-xml/src/tokenizeXml.js +6 -6
- package/package.json +7 -6
- package/src/parts/Command/Command.js +23 -17
- package/src/parts/ExtensionInstall/ExtensionInstall.ipc.js +3 -1
- package/src/parts/GetResponse/GetResponse.js +60 -0
- package/src/parts/GitLsFiles/GitLsFiles.ipc.js +7 -0
- package/src/parts/GitLsFiles/GitLsFiles.js +9 -0
- package/src/parts/JoinLines/JoinLines.js +3 -0
- package/src/parts/JsonRpc/JsonRpc.js +4 -0
- package/src/parts/LimitString/LimitString.js +15 -0
- package/src/parts/Module/Module.js +2 -0
- package/src/parts/ModuleId/ModuleId.js +1 -0
- package/src/parts/ModuleMap/ModuleMap.js +3 -1
- package/src/parts/ParentIpc/ParentIpc.js +9 -82
- package/src/parts/Process/Process.ipc.js +4 -2
- package/src/parts/SearchFile/SearchFile.js +10 -5
- package/src/parts/Socket/Socket.js +3 -55
- package/src/parts/Terminal/Terminal.js +1 -1
- package/src/parts/WebSocketServer/WebSocketServer.ipc.js +3 -1
- package/src/parts/Workspace/Workspace.ipc.js +4 -2
- package/src/sharedProcessMain.js +3 -0
|
@@ -6,23 +6,20 @@
|
|
|
6
6
|
{
|
|
7
7
|
"id": "xml",
|
|
8
8
|
"extensions": [
|
|
9
|
-
".xml",
|
|
10
|
-
".xsd",
|
|
11
9
|
".ascx",
|
|
12
10
|
".atom",
|
|
13
|
-
".axml",
|
|
14
11
|
".axaml",
|
|
12
|
+
".axml",
|
|
15
13
|
".bpmn",
|
|
16
14
|
".cpt",
|
|
17
15
|
".csl",
|
|
18
|
-
".csproj",
|
|
19
16
|
".csproj.user",
|
|
17
|
+
".csproj",
|
|
20
18
|
".dita",
|
|
21
19
|
".ditamap",
|
|
22
20
|
".dtd",
|
|
23
|
-
".ent",
|
|
24
|
-
".mod",
|
|
25
21
|
".dtml",
|
|
22
|
+
".ent",
|
|
26
23
|
".fsproj",
|
|
27
24
|
".fxml",
|
|
28
25
|
".iml",
|
|
@@ -30,16 +27,18 @@
|
|
|
30
27
|
".jmx",
|
|
31
28
|
".launch",
|
|
32
29
|
".menu",
|
|
30
|
+
".mod",
|
|
33
31
|
".mxml",
|
|
34
32
|
".nuspec",
|
|
35
33
|
".opml",
|
|
36
34
|
".owl",
|
|
35
|
+
".plist",
|
|
37
36
|
".proj",
|
|
38
37
|
".props",
|
|
39
38
|
".pt",
|
|
40
39
|
".publishsettings",
|
|
41
|
-
".pubxml",
|
|
42
40
|
".pubxml.user",
|
|
41
|
+
".pubxml",
|
|
43
42
|
".rbxlx",
|
|
44
43
|
".rbxmx",
|
|
45
44
|
".rdf",
|
|
@@ -51,10 +50,11 @@
|
|
|
51
50
|
".targets",
|
|
52
51
|
".tld",
|
|
53
52
|
".tmx",
|
|
54
|
-
".vbproj",
|
|
55
53
|
".vbproj.user",
|
|
56
|
-
".
|
|
54
|
+
".vbproj",
|
|
57
55
|
".vcxproj.filters",
|
|
56
|
+
".vcxproj",
|
|
57
|
+
".vsixmanifest",
|
|
58
58
|
".wsdl",
|
|
59
59
|
".wxi",
|
|
60
60
|
".wxl",
|
|
@@ -64,11 +64,13 @@
|
|
|
64
64
|
".xib",
|
|
65
65
|
".xlf",
|
|
66
66
|
".xliff",
|
|
67
|
-
".
|
|
68
|
-
".xul",
|
|
67
|
+
".xml",
|
|
69
68
|
".xoml",
|
|
70
|
-
".
|
|
69
|
+
".xpdl",
|
|
70
|
+
".xsd",
|
|
71
|
+
".xul"
|
|
71
72
|
],
|
|
73
|
+
"fileNames": [".project"],
|
|
72
74
|
"tokenize": "src/tokenizeXml.js"
|
|
73
75
|
}
|
|
74
76
|
]
|
|
@@ -58,7 +58,7 @@ const RE_ANGLE_BRACKET_ONLY = /^</
|
|
|
58
58
|
const RE_ANGLE_BRACKET_OPEN = /^</
|
|
59
59
|
const RE_ANGLE_BRACKET_OPEN_TAG = /^<(?!\s)/
|
|
60
60
|
const RE_ANY_TEXT = /^[^\n]+/
|
|
61
|
-
const RE_ATTRIBUTE_NAME = /^[a-zA-Z\d
|
|
61
|
+
const RE_ATTRIBUTE_NAME = /^[a-zA-Z\d\-\:]+/
|
|
62
62
|
const RE_BLOCK_COMMENT_CONTENT = /^.(?:.*?)(?=-->|$)/s
|
|
63
63
|
const RE_BLOCK_COMMENT_END = /^-->/
|
|
64
64
|
const RE_BLOCK_COMMENT_START = /^<!--/
|
|
@@ -98,6 +98,8 @@ export const isLineStateEqual = (lineStateA, lineStateB) => {
|
|
|
98
98
|
return lineStateA.state === lineStateB.state
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
export const hasArrayReturn = true
|
|
102
|
+
|
|
101
103
|
/**
|
|
102
104
|
*
|
|
103
105
|
* @param {string} line
|
|
@@ -285,11 +287,9 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
285
287
|
state
|
|
286
288
|
throw new Error('no')
|
|
287
289
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
length: next[0].length,
|
|
292
|
-
})
|
|
290
|
+
const tokenLength = next[0].length
|
|
291
|
+
index += tokenLength
|
|
292
|
+
tokens.push(token, tokenLength)
|
|
293
293
|
}
|
|
294
294
|
return {
|
|
295
295
|
state,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"description": "Utility package for @lvce-editor/server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
"node": ">=16"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@lvce-editor/extension-host
|
|
21
|
-
"@lvce-editor/
|
|
19
|
+
"@babel/code-frame": "^7.18.6",
|
|
20
|
+
"@lvce-editor/extension-host": "0.11.4",
|
|
21
|
+
"@lvce-editor/extension-host-helper-process": "0.11.4",
|
|
22
|
+
"@lvce-editor/pty-host": "0.11.4",
|
|
22
23
|
"debug": "^4.3.4",
|
|
23
24
|
"execa": "^6.1.0",
|
|
24
25
|
"exit-hook": "^3.1.2",
|
|
@@ -37,8 +38,8 @@
|
|
|
37
38
|
"xdg-basedir": "^5.1.0"
|
|
38
39
|
},
|
|
39
40
|
"optionalDependencies": {
|
|
41
|
+
"extract-zip": "^2.0.1",
|
|
40
42
|
"keytar": "^7.9.0",
|
|
41
|
-
"vscode-ripgrep-with-github-api-error-fix": "^2.6.0"
|
|
42
|
-
"extract-zip": "^2.0.1"
|
|
43
|
+
"vscode-ripgrep-with-github-api-error-fix": "^2.6.0"
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import * as Module from '../Module/Module.js'
|
|
2
1
|
import * as ModuleMap from '../ModuleMap/ModuleMap.js'
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export const state = {
|
|
4
|
+
commands: Object.create(null),
|
|
5
|
+
invocables: Object.create(null),
|
|
6
|
+
pendingModules: Object.create(null),
|
|
7
|
+
async load(moduleId) {},
|
|
8
|
+
}
|
|
7
9
|
|
|
8
10
|
const initializeModule = (module) => {
|
|
9
11
|
if (module.Commands) {
|
|
@@ -21,49 +23,49 @@ const initializeModule = (module) => {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const getOrLoadModule = (moduleId) => {
|
|
24
|
-
if (!pendingModules[moduleId]) {
|
|
25
|
-
const importPromise =
|
|
26
|
-
pendingModules[moduleId] = importPromise
|
|
26
|
+
if (!state.pendingModules[moduleId]) {
|
|
27
|
+
const importPromise = state.load(moduleId)
|
|
28
|
+
state.pendingModules[moduleId] = importPromise
|
|
27
29
|
.then(initializeModule)
|
|
28
30
|
.catch((error) => {
|
|
29
31
|
console.error(error)
|
|
30
32
|
})
|
|
31
33
|
}
|
|
32
|
-
return pendingModules[moduleId]
|
|
34
|
+
return state.pendingModules[moduleId]
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const loadCommand = (command) => getOrLoadModule(ModuleMap.getModuleId(command))
|
|
36
38
|
|
|
37
39
|
export const register = (commandId, listener) => {
|
|
38
|
-
commands[commandId] = listener
|
|
40
|
+
state.commands[commandId] = listener
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export const registerInvocable = (commandId, listener) => {
|
|
42
|
-
invocables[commandId] = listener
|
|
44
|
+
state.invocables[commandId] = listener
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export const invoke = async (command, ...args) => {
|
|
46
|
-
if (!(command in commands)) {
|
|
48
|
+
if (!(command in state.commands)) {
|
|
47
49
|
await loadCommand(command)
|
|
48
|
-
if (!(command in commands)) {
|
|
50
|
+
if (!(command in state.commands)) {
|
|
49
51
|
console.warn(`[shared process] Unknown command "${command}"`)
|
|
50
52
|
throw new Error(`Command ${command} not found`)
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
|
-
if (typeof commands[command] !== 'function') {
|
|
55
|
+
if (typeof state.commands[command] !== 'function') {
|
|
54
56
|
throw new TypeError(`Command ${command} is not a function`)
|
|
55
57
|
}
|
|
56
|
-
return commands[command](...args)
|
|
58
|
+
return state.commands[command](...args)
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
export const execute = (command, ...args) => {
|
|
60
|
-
if (command in commands) {
|
|
61
|
-
commands[command](...args)
|
|
62
|
+
if (command in state.commands) {
|
|
63
|
+
state.commands[command](...args)
|
|
62
64
|
} else {
|
|
63
65
|
loadCommand(command)
|
|
64
66
|
// TODO can skip then block in prod (only to prevent endless loop in dev)
|
|
65
67
|
.then(() => {
|
|
66
|
-
if (!(command in commands)) {
|
|
68
|
+
if (!(command in state.commands)) {
|
|
67
69
|
console.warn(`Unknown command "${command}"`)
|
|
68
70
|
return
|
|
69
71
|
}
|
|
@@ -79,3 +81,7 @@ export const execute = (command, ...args) => {
|
|
|
79
81
|
})
|
|
80
82
|
}
|
|
81
83
|
}
|
|
84
|
+
|
|
85
|
+
export const setLoad = (load) => {
|
|
86
|
+
state.load = load
|
|
87
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as Command from '../Command/Command.js'
|
|
2
|
+
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
3
|
+
import * as JsonRpc from '../JsonRpc/JsonRpc.js'
|
|
4
|
+
import * as PrettyError from '../PrettyError/PrettyError.js'
|
|
5
|
+
import { requiresSocket } from '../RequiresSocket/RequiresSocket.js'
|
|
6
|
+
|
|
7
|
+
export const getResponse = async (message, handle) => {
|
|
8
|
+
try {
|
|
9
|
+
const result = requiresSocket(message.method)
|
|
10
|
+
? await Command.invoke(message.method, handle, ...message.params)
|
|
11
|
+
: await Command.invoke(message.method, ...message.params)
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
jsonrpc: JsonRpc.Version,
|
|
15
|
+
id: message.id,
|
|
16
|
+
result: result ?? null,
|
|
17
|
+
}
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (
|
|
20
|
+
error &&
|
|
21
|
+
error instanceof Error &&
|
|
22
|
+
error.message &&
|
|
23
|
+
error.message.startsWith('method not found')
|
|
24
|
+
) {
|
|
25
|
+
return {
|
|
26
|
+
jsonrpc: JsonRpc.Version,
|
|
27
|
+
id: message.id,
|
|
28
|
+
error: {
|
|
29
|
+
code: JsonRpc.ErrorMethodNotFound,
|
|
30
|
+
message: error.message,
|
|
31
|
+
data: error.stack,
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (error && error instanceof Error && error.code === ErrorCodes.ENOENT) {
|
|
36
|
+
return {
|
|
37
|
+
jsonrpc: JsonRpc.Version,
|
|
38
|
+
id: message.id,
|
|
39
|
+
error: {
|
|
40
|
+
code: -32001,
|
|
41
|
+
message: `${error}`,
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const prettyError = PrettyError.prepare(error)
|
|
46
|
+
PrettyError.print(prettyError)
|
|
47
|
+
return {
|
|
48
|
+
jsonrpc: JsonRpc.Version,
|
|
49
|
+
id: message.id,
|
|
50
|
+
error: {
|
|
51
|
+
code: -32001,
|
|
52
|
+
message: prettyError.message,
|
|
53
|
+
data: {
|
|
54
|
+
stack: prettyError.stack,
|
|
55
|
+
codeFrame: prettyError.codeFrame,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const limitString = (string, limit) => {
|
|
2
|
+
let lines = 0
|
|
3
|
+
let i = 0
|
|
4
|
+
while (i !== -1 && lines < limit) {
|
|
5
|
+
i = string.indexOf('\n', i + 1)
|
|
6
|
+
if (i === -1) {
|
|
7
|
+
break
|
|
8
|
+
}
|
|
9
|
+
lines++
|
|
10
|
+
}
|
|
11
|
+
if (i === -1) {
|
|
12
|
+
return string
|
|
13
|
+
}
|
|
14
|
+
return string.slice(0, i)
|
|
15
|
+
}
|
|
@@ -16,6 +16,8 @@ export const load = (moduleId) => {
|
|
|
16
16
|
return import('../ExtensionManagement/ExtensionManagement.ipc.js')
|
|
17
17
|
case ModuleId.FileSystem:
|
|
18
18
|
return import('../FileSystem/FileSystem.ipc.js')
|
|
19
|
+
case ModuleId.GitLsFiles:
|
|
20
|
+
return import('../GitLsFiles/GitLsFiles.ipc.js')
|
|
19
21
|
case ModuleId.Native:
|
|
20
22
|
return import('../Native/Native.ipc.js')
|
|
21
23
|
case ModuleId.OutputChannel:
|
|
@@ -92,6 +92,8 @@ export const getModuleId = (commandId) => {
|
|
|
92
92
|
case 'FileSystem.rename':
|
|
93
93
|
case 'FileSystem.writeFile':
|
|
94
94
|
return ModuleId.FileSystem
|
|
95
|
+
case 'GitLsFiles.gitLsFiles':
|
|
96
|
+
return ModuleId.GitLsFiles
|
|
95
97
|
case 'Native.openFolder':
|
|
96
98
|
return ModuleId.Native
|
|
97
99
|
case 'OutputChannel.close':
|
|
@@ -129,7 +131,7 @@ export const getModuleId = (commandId) => {
|
|
|
129
131
|
return ModuleId.Terminal
|
|
130
132
|
case 4820:
|
|
131
133
|
return ModuleId.TextDocument
|
|
132
|
-
case
|
|
134
|
+
case 'WebSocketServer.handleUpgrade':
|
|
133
135
|
return ModuleId.WebSocketServer
|
|
134
136
|
case 'Workspace.getHomeDir':
|
|
135
137
|
case 'Workspace.resolveRoot':
|
|
@@ -3,12 +3,11 @@ import VError from 'verror'
|
|
|
3
3
|
import * as Callback from '../Callback/Callback.js'
|
|
4
4
|
import * as Command from '../Command/Command.js'
|
|
5
5
|
import * as Debug from '../Debug/Debug.js'
|
|
6
|
-
import * as
|
|
7
|
-
import { requiresSocket } from '../RequiresSocket/RequiresSocket.js'
|
|
8
|
-
import * as Platform from '../Platform/Platform.js'
|
|
6
|
+
import * as ExtensionHostHelperProcessIpc from '../ExtensionHostHelperProcessIpc/ExtensionHostHelperProcessIpc.js'
|
|
9
7
|
import * as ExtensionHostIpc from '../ExtensionHostIpc/ExtensionHostIpc.js'
|
|
10
8
|
import * as ExtensionHostRpc from '../ExtensionHostRpc/ExtensionHostRpc.js'
|
|
11
|
-
import * as
|
|
9
|
+
import * as GetResponse from '../GetResponse/GetResponse.js'
|
|
10
|
+
|
|
12
11
|
// TODO add tests for this
|
|
13
12
|
|
|
14
13
|
// TODO handle structure: one shared process multiple extension hosts
|
|
@@ -43,7 +42,7 @@ const handleWebSocketSharedProcess = (message, handle) => {
|
|
|
43
42
|
console.info('[info shared process: handle error]', error)
|
|
44
43
|
})
|
|
45
44
|
Command.execute(
|
|
46
|
-
/* WebSocketServer.handleUpgrade */
|
|
45
|
+
/* WebSocketServer.handleUpgrade */ 'WebSocketServer.handleUpgrade',
|
|
47
46
|
/* message */ message,
|
|
48
47
|
/* handle */ handle
|
|
49
48
|
)
|
|
@@ -84,7 +83,7 @@ const handleWebSocket = (message, handle) => {
|
|
|
84
83
|
case 'lvce.extension-host-helper-process':
|
|
85
84
|
return handleWebSocketExtensionHostHelperProcess(message, handle)
|
|
86
85
|
default:
|
|
87
|
-
|
|
86
|
+
console.warn(`unsupported sec-websocket-procotol ${protocol}`)
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
89
|
|
|
@@ -94,27 +93,8 @@ const handleJsonRpcResult = (message) => {
|
|
|
94
93
|
|
|
95
94
|
const handleJsonRpcMessage = async (message, handle) => {
|
|
96
95
|
if (message.id) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
? await Command.invoke(message.method, handle, ...message.params)
|
|
100
|
-
: await Command.invoke(message.method, ...message.params)
|
|
101
|
-
electronSend({
|
|
102
|
-
jsonrpc: '2.0',
|
|
103
|
-
id: message.id,
|
|
104
|
-
result: result ?? null,
|
|
105
|
-
})
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.error('[shared process] command failed to execute')
|
|
108
|
-
console.error(error)
|
|
109
|
-
electronSend({
|
|
110
|
-
jsonrpc: '2.0',
|
|
111
|
-
code: /* ExpectedError */ -32000,
|
|
112
|
-
id: message.id,
|
|
113
|
-
error: 'ExpectedError',
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
data: error.toString(),
|
|
116
|
-
})
|
|
117
|
-
}
|
|
96
|
+
const response = await GetResponse.getResponse(message, handle)
|
|
97
|
+
electronSend(response)
|
|
118
98
|
} else {
|
|
119
99
|
// TODO handle error
|
|
120
100
|
Command.execute(message.method, null, ...message.params)
|
|
@@ -163,61 +143,8 @@ const electronInitialize = (initializeMessage) => {
|
|
|
163
143
|
Callback.resolve(message.id, message.result)
|
|
164
144
|
} else if (message.method) {
|
|
165
145
|
if (message.id) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
? await Command.invoke(
|
|
169
|
-
message.method,
|
|
170
|
-
fakeSocket,
|
|
171
|
-
...message.params
|
|
172
|
-
)
|
|
173
|
-
: await Command.invoke(message.method, ...message.params)
|
|
174
|
-
|
|
175
|
-
port.postMessage({
|
|
176
|
-
jsonrpc: '2.0',
|
|
177
|
-
id: message.id,
|
|
178
|
-
result: result ?? null,
|
|
179
|
-
})
|
|
180
|
-
} catch (error) {
|
|
181
|
-
// TODO duplicate code with Socket.js, clean this up
|
|
182
|
-
if (error instanceof Error.OperationalError) {
|
|
183
|
-
// console.log({ error })
|
|
184
|
-
const rawCause = error.cause()
|
|
185
|
-
const errorCause = rawCause ? rawCause.message : ''
|
|
186
|
-
const errorMessage = rawCause
|
|
187
|
-
? error.message.slice(0, error.message.indexOf(errorCause))
|
|
188
|
-
: ''
|
|
189
|
-
|
|
190
|
-
// console.info('expected error', error)
|
|
191
|
-
port.postMessage({
|
|
192
|
-
jsonrpc: '2.0',
|
|
193
|
-
id: message.id,
|
|
194
|
-
error: {
|
|
195
|
-
code: /* ExpectedError */ -32000,
|
|
196
|
-
message: error.message,
|
|
197
|
-
data: {
|
|
198
|
-
stack: error.originalStack,
|
|
199
|
-
codeFrame: error.originalCodeFrame,
|
|
200
|
-
category: error.category,
|
|
201
|
-
// @ts-ignore
|
|
202
|
-
stderr: error.stderr,
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
})
|
|
206
|
-
} else {
|
|
207
|
-
console.error('[shared process] command failed to execute')
|
|
208
|
-
console.error(error)
|
|
209
|
-
// TODO check if socket is active
|
|
210
|
-
port.postMessage({
|
|
211
|
-
jsonrpc: '2.0',
|
|
212
|
-
id: message.id,
|
|
213
|
-
error: {
|
|
214
|
-
code: /* UnexpectedError */ -32001,
|
|
215
|
-
// @ts-ignore
|
|
216
|
-
message: error.toString(),
|
|
217
|
-
},
|
|
218
|
-
})
|
|
219
|
-
}
|
|
220
|
-
}
|
|
146
|
+
const response = await GetResponse.getResponse(message, fakeSocket)
|
|
147
|
+
port.postMessage(response)
|
|
221
148
|
} else {
|
|
222
149
|
Command.execute(message.method, fakeSocket, ...message.params)
|
|
223
150
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Assert from '../Assert/Assert.js'
|
|
2
|
+
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
2
3
|
import * as Exec from '../Exec/Exec.js'
|
|
4
|
+
import * as LimitString from '../LimitString/LimitString.js'
|
|
5
|
+
import * as RgPath from '../RgPath/RgPath.js'
|
|
3
6
|
|
|
4
7
|
const ripGrepPath = process.env.RIP_GREP_PATH || RgPath.rgPath
|
|
5
8
|
|
|
6
9
|
const isEnoentErrorLinux = (error) => {
|
|
7
|
-
return error.code ===
|
|
10
|
+
return error.code === ErrorCodes.ENOENT
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
const isEnoentErrorWindows = (error) => {
|
|
@@ -24,8 +27,11 @@ const isEnoentError = (error) => {
|
|
|
24
27
|
// do a delta comparison, so the first time it would send 100kB
|
|
25
28
|
// but the second time only a few hundred bytes of changes
|
|
26
29
|
|
|
27
|
-
export const searchFile = async (path, searchTerm) => {
|
|
30
|
+
export const searchFile = async (path, searchTerm, limit) => {
|
|
28
31
|
try {
|
|
32
|
+
Assert.string(path)
|
|
33
|
+
Assert.string(searchTerm)
|
|
34
|
+
Assert.number(limit)
|
|
29
35
|
const { stdout, stderr } = await Exec.exec(
|
|
30
36
|
ripGrepPath,
|
|
31
37
|
['--files', '--sort-files'],
|
|
@@ -33,8 +39,7 @@ export const searchFile = async (path, searchTerm) => {
|
|
|
33
39
|
cwd: path,
|
|
34
40
|
}
|
|
35
41
|
)
|
|
36
|
-
|
|
37
|
-
return lines
|
|
42
|
+
return LimitString.limitString(stdout, limit)
|
|
38
43
|
} catch (error) {
|
|
39
44
|
// @ts-ignore
|
|
40
45
|
if (isEnoentError(error)) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import VError from 'verror'
|
|
2
2
|
import * as Command from '../Command/Command.js'
|
|
3
|
-
import * as
|
|
4
|
-
import { requiresSocket } from '../RequiresSocket/RequiresSocket.js'
|
|
3
|
+
import * as GetResponse from '../GetResponse/GetResponse.js'
|
|
5
4
|
|
|
6
5
|
export const state = {
|
|
7
6
|
/**
|
|
@@ -30,59 +29,8 @@ const handleMessage = async (event) => {
|
|
|
30
29
|
)
|
|
31
30
|
return
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
result = requiresSocket(object.method)
|
|
36
|
-
? await Command.invoke(object.method, state.socket, ...object.params)
|
|
37
|
-
: await Command.invoke(object.method, ...object.params)
|
|
38
|
-
} catch (error) {
|
|
39
|
-
if (error instanceof Error.OperationalError) {
|
|
40
|
-
// console.log({ error })
|
|
41
|
-
const rawCause = error.cause()
|
|
42
|
-
const errorCause = rawCause ? rawCause.message : ''
|
|
43
|
-
const errorMessage = rawCause
|
|
44
|
-
? error.message.slice(0, error.message.indexOf(errorCause))
|
|
45
|
-
: ''
|
|
46
|
-
|
|
47
|
-
// console.info('expected error', error)
|
|
48
|
-
send({
|
|
49
|
-
jsonrpc: '2.0',
|
|
50
|
-
id: object.id,
|
|
51
|
-
error: {
|
|
52
|
-
code: /* ExpectedError */ -32000,
|
|
53
|
-
message: error.message,
|
|
54
|
-
data: {
|
|
55
|
-
stack: error.originalStack,
|
|
56
|
-
codeFrame: error.originalCodeFrame,
|
|
57
|
-
category: error.category,
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
stderr: error.stderr,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
})
|
|
63
|
-
} else {
|
|
64
|
-
console.error(error)
|
|
65
|
-
// TODO check if socket is active
|
|
66
|
-
send({
|
|
67
|
-
jsonrpc: '2.0',
|
|
68
|
-
id: object.id,
|
|
69
|
-
error: {
|
|
70
|
-
code: /* UnexpectedError */ -32001,
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
message: error.toString(),
|
|
73
|
-
data: {
|
|
74
|
-
code: error.code,
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
send({
|
|
82
|
-
jsonrpc: '2.0',
|
|
83
|
-
result,
|
|
84
|
-
id: object.id,
|
|
85
|
-
})
|
|
32
|
+
const response = await GetResponse.getResponse(object, state.socket)
|
|
33
|
+
send(response)
|
|
86
34
|
} else {
|
|
87
35
|
if (!object.params) {
|
|
88
36
|
console.warn('invalid message', typeof object, object.params, object)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as Workspace from './Workspace.js'
|
|
2
2
|
|
|
3
|
+
export const name = 'Workspace'
|
|
4
|
+
|
|
3
5
|
export const Commands = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
getHomeDir: Workspace.getHomeDir,
|
|
7
|
+
resolveRoot: Workspace.resolveRoot,
|
|
6
8
|
}
|
package/src/sharedProcessMain.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as Command from './parts/Command/Command.js'
|
|
2
|
+
import * as Module from './parts/Module/Module.js'
|
|
1
3
|
import * as ParentIpc from './parts/ParentIpc/ParentIpc.js'
|
|
2
4
|
import * as PrettyError from './parts/PrettyError/PrettyError.js'
|
|
3
5
|
|
|
@@ -48,6 +50,7 @@ const handleSigTerm = () => {
|
|
|
48
50
|
const knownCliArgs = ['install', 'list', 'link', 'unlink']
|
|
49
51
|
|
|
50
52
|
const main = async () => {
|
|
53
|
+
Command.setLoad(Module.load)
|
|
51
54
|
const argv = process.argv.slice(2)
|
|
52
55
|
const argv0 = argv[0]
|
|
53
56
|
if (knownCliArgs.includes(argv0)) {
|