@lvce-editor/shared-process 0.15.16 → 0.15.18

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.
Files changed (80) hide show
  1. package/config/builtinCommands.json +8 -0
  2. package/config/defaultSettings.json +2 -0
  3. package/extensions/builtin.language-basics-python/extension.json +1 -1
  4. package/extensions/builtin.language-basics-xml/extension.json +2 -1
  5. package/extensions/builtin.language-basics-xml/src/tokenizeXml.js +1 -1
  6. package/extensions/builtin.theme-atom-one-dark/color-theme.json +4 -0
  7. package/package.json +4 -4
  8. package/src/parts/AttachDebugger/AttachDebugger.ipc.js +7 -0
  9. package/src/parts/AttachDebugger/AttachDebugger.js +6 -0
  10. package/src/parts/Callback/Callback.js +17 -26
  11. package/src/parts/ChildProcessError/ChildProcessError.js +4 -1
  12. package/src/parts/CleanStack/CleanStack.js +4 -0
  13. package/src/parts/CommandNotFoundError/CommandNotFoundError.js +2 -1
  14. package/src/parts/CreateCpuProfile/CreateCpuProfile.js +59 -0
  15. package/src/parts/DestroySocket/DestroySocket.js +5 -0
  16. package/src/parts/DevtoolsProtocolRpc/DevtoolsProtocolRpc.js +32 -0
  17. package/src/parts/ElectronInitialize/ElectronInitialize.ipc.js +8 -0
  18. package/src/parts/ElectronInitialize/ElectronInitialize.js +11 -0
  19. package/src/parts/ErrorCodes/ErrorCodes.js +2 -0
  20. package/src/parts/ErrorHandling/ErrorHandling.js +12 -14
  21. package/src/parts/FirstWebSocketEventType/FirstWebSocketEventType.js +2 -0
  22. package/src/parts/GetActualPath/GetActualPath.js +8 -0
  23. package/src/parts/GetErrorResponse/GetErrorResponse.js +6 -3
  24. package/src/parts/GetFirstWebSocketEvent/GetFirstWebSocketEvent.js +41 -0
  25. package/src/parts/GetHelpfulChildProcessError/GetHelpfulChildProcessError.js +13 -3
  26. package/src/parts/GetResponse/GetResponse.js +3 -3
  27. package/src/parts/HandleElectronMessagePort/HandleElectronMessagePort.ipc.js +7 -0
  28. package/src/parts/HandleElectronMessagePort/HandleElectronMessagePort.js +14 -0
  29. package/src/parts/HandleIpc/HandleIpc.js +30 -0
  30. package/src/parts/HandleNodeMessagePort/HandleNodeMessagePort.ipc.js +7 -0
  31. package/src/parts/HandleNodeMessagePort/HandleNodeMessagePort.js +12 -0
  32. package/src/parts/HandleWebSocket/HandleWebSocket.ipc.js +7 -0
  33. package/src/parts/HandleWebSocket/HandleWebSocket.js +26 -0
  34. package/src/parts/HandleWebSocketForExtensionHost/HandleWebSocketForExtensionHost.js +15 -0
  35. package/src/parts/HandleWebSocketForExtensionHostHelperProcess/HandleWebSocketForExtensionHostHelperProcess.js +6 -0
  36. package/src/parts/HandleWebSocketForSharedProcess/HandleWebSocketForSharedProcess.js +23 -0
  37. package/src/parts/HandleWebSocketForTerminalProcess/HandleWebSocketForTerminalProcess.js +22 -0
  38. package/src/parts/HandleWebSocketForUnknown/HandleWebSocketForUnknown.js +10 -0
  39. package/src/parts/HandleWebSocketModule/HandleWebSocketModule.js +20 -0
  40. package/src/parts/Id/Id.js +7 -0
  41. package/src/parts/IpcChild/IpcChild.js +5 -2
  42. package/src/parts/IpcChildModule/IpcChildModule.js +8 -0
  43. package/src/parts/IpcChildType/IpcChildType.js +7 -0
  44. package/src/parts/IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js +41 -0
  45. package/src/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +51 -0
  46. package/src/parts/IpcChildWithNodeForkedProcess/IpcChildWithNodeForkedProcess.js +25 -1
  47. package/src/parts/IpcChildWithNodeMessagePort/IpcChildWithNodeMessagePort.js +41 -0
  48. package/src/parts/IpcChildWithNodeWorker/IpcChildWithNodeWorker.js +17 -1
  49. package/src/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js +51 -0
  50. package/src/parts/IpcError/IpcError.js +6 -0
  51. package/src/parts/IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js +7 -3
  52. package/src/parts/IsElectron/IsElectron.js +3 -0
  53. package/src/parts/IsMessagePort/IsMessagePort.js +3 -0
  54. package/src/parts/IsMessagePortMain/IsMessagePortMain.js +3 -0
  55. package/src/parts/IsSocket/IsSocket.js +5 -0
  56. package/src/parts/IsWebSocketOpen/IsWebSocketOpen.js +5 -0
  57. package/src/parts/JsonRpc/JsonRpc.js +19 -7
  58. package/src/parts/Module/Module.js +14 -0
  59. package/src/parts/ModuleId/ModuleId.js +7 -0
  60. package/src/parts/ModuleMap/ModuleMap.js +18 -0
  61. package/src/parts/ParentIpc/ParentIpc.js +10 -188
  62. package/src/parts/PrettyError/PrettyError.js +4 -19
  63. package/src/parts/Process/Process.ipc.js +1 -0
  64. package/src/parts/Process/Process.js +8 -0
  65. package/src/parts/ProcessDisplayName/ProcessDisplayName.js +1 -0
  66. package/src/parts/ProtocolType/ProtocolType.js +2 -1
  67. package/src/parts/PtyHost/PtyHost.js +81 -0
  68. package/src/parts/RebuildNodePty/RebuildNodePty.ipc.js +7 -0
  69. package/src/parts/RebuildNodePty/RebuildNodePty.js +48 -0
  70. package/src/parts/Signal/Signal.js +2 -0
  71. package/src/parts/Terminal/Terminal.js +52 -130
  72. package/src/parts/TerminalState/TerminalState.js +15 -0
  73. package/src/parts/WebSocketServer/WebSocketServer.js +11 -25
  74. package/src/sharedProcessMain.cjs +1 -0
  75. package/src/sharedProcessMain.js +3 -2
  76. package/extensions/builtin.language-basics-json5/README.md +0 -16
  77. package/extensions/builtin.language-basics-json5/extension.json +0 -12
  78. package/extensions/builtin.language-basics-json5/src/tokenizeJson5.js +0 -321
  79. package/src/parts/Socket/Socket.js +0 -77
  80. /package/src/parts/{GetWindowsNsisDOwnloadUrl → GetWindowsNsisDownloadUrl}/GetWindowsNsisDownloadUrl.js +0 -0
@@ -0,0 +1,15 @@
1
+ import * as ExtensionHostIpc from '../ExtensionHostIpc/ExtensionHostIpc.js'
2
+ import * as ExtensionHostRpc from '../ExtensionHostRpc/ExtensionHostRpc.js'
3
+
4
+ // TODO lazyload modules for spawning extension host, they are only needed later
5
+ export const handleWebSocket = async (message, handle) => {
6
+ // console.log('[shared-process] received extension host websocket', message)
7
+ const ipc = await ExtensionHostIpc.create()
8
+ console.info('[sharedprocess] creating extension ipc')
9
+ const rpc = await ExtensionHostRpc.create(ipc, handle)
10
+ console.info('[sharedprocess] created extension host rpc')
11
+ ipc._process.send(message, handle)
12
+ // rpc.send(message)
13
+ // console.log('spawned extension host')
14
+ // console.log(rpc)
15
+ }
@@ -0,0 +1,6 @@
1
+ import * as ExtensionHostHelperProcessIpc from '../ExtensionHostHelperProcessIpc/ExtensionHostHelperProcessIpc.js'
2
+
3
+ export const handleWebSocket = async (message, handle) => {
4
+ const ipc = await ExtensionHostHelperProcessIpc.create()
5
+ ipc._process.send(message, handle)
6
+ }
@@ -0,0 +1,23 @@
1
+ import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
+ import * as HandleIpc from '../HandleIpc/HandleIpc.js'
3
+ import * as IpcChild from '../IpcChild/IpcChild.js'
4
+ import * as IpcChildType from '../IpcChildType/IpcChildType.js'
5
+ import * as Logger from '../Logger/Logger.js'
6
+ import * as WebSocketServer from '../WebSocketServer/WebSocketServer.js'
7
+
8
+ const handleSocketError = (error) => {
9
+ if (error && error.code === ErrorCodes.ECONNRESET) {
10
+ return
11
+ }
12
+ Logger.info('[info shared process: handle error]', error)
13
+ }
14
+
15
+ export const handleWebSocket = async (message, handle) => {
16
+ handle.on('error', handleSocketError)
17
+ const webSocket = await WebSocketServer.handleUpgrade(message, handle)
18
+ const ipc = await IpcChild.listen({
19
+ method: IpcChildType.WebSocket,
20
+ webSocket,
21
+ })
22
+ HandleIpc.handleIpc(ipc)
23
+ }
@@ -0,0 +1,22 @@
1
+ import * as PtyHost from '../PtyHost/PtyHost.js'
2
+
3
+ export const handleWebSocket = async (message, handle) => {
4
+ const instance = await PtyHost.getOrCreate()
5
+ instance.sendAndTransfer(
6
+ {
7
+ jsonrpc: '2.0',
8
+ method: 'HandleWebSocket.handleWebSocket',
9
+ params: [message],
10
+ },
11
+ handle
12
+ )
13
+ // console.log({ instance })
14
+ // const ipc = await PtyHost.getOrCreate()
15
+ // console.info('[sharedprocess] creating extension ipc')
16
+ // const rpc = await ExtensionHostRpc.create(ipc, handle)
17
+ // console.info('[sharedprocess] created extension host rpc')
18
+ // ipc._process.send(message, handle)
19
+ // rpc.send(message)
20
+ // console.log('spawned extension host')
21
+ // console.log(rpc)
22
+ }
@@ -0,0 +1,10 @@
1
+ import * as Logger from '../Logger/Logger.js'
2
+
3
+ export const handleWebSocket = (message, handle, protocol) => {
4
+ Logger.warn(`[shared-process] unsupported sec-websocket-procotol ${protocol}`)
5
+ try {
6
+ handle.destroy()
7
+ } catch {
8
+ // ignore
9
+ }
10
+ }
@@ -0,0 +1,20 @@
1
+ import * as ProtocolType from '../ProtocolType/ProtocolType.js'
2
+ import { VError } from '../VError/VError.js'
3
+
4
+ export const load = (protocol) => {
5
+ if (!protocol) {
6
+ throw new VError('missing sec websocket protocol header')
7
+ }
8
+ switch (protocol) {
9
+ case ProtocolType.SharedProcess:
10
+ return import('../HandleWebSocketForSharedProcess/HandleWebSocketForSharedProcess.js')
11
+ case ProtocolType.ExtensionHost:
12
+ return import('../HandleWebSocketForExtensionHost/HandleWebSocketForExtensionHost.js')
13
+ case ProtocolType.ExtensionHostHelperProcess:
14
+ return import('../HandleWebSocketForExtensionHostHelperProcess/HandleWebSocketForExtensionHostHelperProcess.js')
15
+ case ProtocolType.TerminalProcess:
16
+ return import('../HandleWebSocketForTerminalProcess/HandleWebSocketForTerminalProcess.js')
17
+ default:
18
+ return import('../HandleWebSocketForUnknown/HandleWebSocketForUnknown.js')
19
+ }
20
+ }
@@ -0,0 +1,7 @@
1
+ export const state = {
2
+ id: 0,
3
+ }
4
+
5
+ export const create = () => {
6
+ return ++state.id
7
+ }
@@ -1,6 +1,9 @@
1
1
  import * as IpcChildModule from '../IpcChildModule/IpcChildModule.js'
2
2
 
3
- export const listen = async ({ method }) => {
3
+ export const listen = async ({ method, ...params }) => {
4
4
  const module = await IpcChildModule.getModule(method)
5
- return module.listen()
5
+ // @ts-ignore
6
+ const rawIpc = await module.listen(params)
7
+ const ipc = module.wrap(rawIpc)
8
+ return ipc
6
9
  }
@@ -6,6 +6,14 @@ export const getModule = (method) => {
6
6
  return import('../IpcChildWithNodeForkedProcess/IpcChildWithNodeForkedProcess.js')
7
7
  case IpcChildType.NodeWorker:
8
8
  return import('../IpcChildWithNodeWorker/IpcChildWithNodeWorker.js')
9
+ case IpcChildType.ElectronUtilityProcess:
10
+ return import('../IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js')
11
+ case IpcChildType.ElectronMessagePort:
12
+ return import('../IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js')
13
+ case IpcChildType.NodeMessagePort:
14
+ return import('../IpcChildWithNodeMessagePort/IpcChildWithNodeMessagePort.js')
15
+ case IpcChildType.WebSocket:
16
+ return import('../IpcChildWithWebSocket/IpcChildWithWebSocket.js')
9
17
  default:
10
18
  throw new Error('unexpected ipc type')
11
19
  }
@@ -1,5 +1,9 @@
1
1
  export const NodeWorker = 1
2
2
  export const NodeForkedProcess = 2
3
+ export const ElectronUtilityProcess = 3
4
+ export const ElectronMessagePort = 4
5
+ export const NodeMessagePort = 5
6
+ export const WebSocket = 6
3
7
 
4
8
  export const Auto = () => {
5
9
  const { argv } = process
@@ -9,5 +13,8 @@ export const Auto = () => {
9
13
  if (argv.includes('--ipc-type=node-forked-process')) {
10
14
  return NodeForkedProcess
11
15
  }
16
+ if (argv.includes('--ipc-type=electron-utility-process')) {
17
+ return ElectronUtilityProcess
18
+ }
12
19
  throw new Error(`[shared-process] unknown ipc type`)
13
20
  }
@@ -0,0 +1,41 @@
1
+ import { IpcError } from '../IpcError/IpcError.js'
2
+ import * as IsMessagePortMain from '../IsMessagePortMain/IsMessagePortMain.js'
3
+
4
+ export const listen = ({ messagePort }) => {
5
+ if (!IsMessagePortMain.isMessagePortMain(messagePort)) {
6
+ throw new IpcError('port must be of type MessagePortMain')
7
+ }
8
+ return messagePort
9
+ }
10
+
11
+ const getActualData = (event) => {
12
+ return event.data
13
+ }
14
+
15
+ export const wrap = (messagePort) => {
16
+ return {
17
+ messagePort,
18
+ on(event, listener) {
19
+ if (event === 'message') {
20
+ const wrappedListener = (event) => {
21
+ const actualData = getActualData(event)
22
+ listener(actualData)
23
+ }
24
+ this.messagePort.on(event, wrappedListener)
25
+ } else if (event === 'close') {
26
+ this.messagePort.on('close', listener)
27
+ } else {
28
+ throw new Error('unsupported event type')
29
+ }
30
+ },
31
+ off(event, listener) {
32
+ this.messagePort.off(event, listener)
33
+ },
34
+ send(message) {
35
+ this.messagePort.postMessage(message)
36
+ },
37
+ dispose() {
38
+ this.messagePort.close()
39
+ },
40
+ }
41
+ }
@@ -0,0 +1,51 @@
1
+ import * as IsElectron from '../IsElectron/IsElectron.js'
2
+
3
+ export const listen = () => {
4
+ // @ts-ignore
5
+ const parentPort = process.parentPort
6
+ if (!parentPort) {
7
+ throw new Error('parent port must be defined')
8
+ }
9
+ parentPort.postMessage('ready')
10
+ return parentPort
11
+ }
12
+
13
+ const getActualData = (event) => {
14
+ const { data, ports } = event
15
+ if (ports.length === 0) {
16
+ return data
17
+ }
18
+ return {
19
+ ...data,
20
+ params: [...data.params, ...ports],
21
+ }
22
+ }
23
+
24
+ export const wrap = (parentPort) => {
25
+ return {
26
+ shouldLogError: !IsElectron.isElectron(),
27
+ parentPort,
28
+ on(event, listener) {
29
+ if (event === 'message') {
30
+ const wrappedListener = (event) => {
31
+ const actualData = getActualData(event)
32
+ listener(actualData)
33
+ }
34
+ this.parentPort.on(event, wrappedListener)
35
+ } else if (event === 'close') {
36
+ this.parentPort.on('close', listener)
37
+ } else {
38
+ throw new Error('unsupported event type')
39
+ }
40
+ },
41
+ off(event, listener) {
42
+ this.parentPort.off(event, listener)
43
+ },
44
+ send(message) {
45
+ this.parentPort.postMessage(message)
46
+ },
47
+ dispose() {
48
+ this.parentPort.close()
49
+ },
50
+ }
51
+ }
@@ -1,12 +1,36 @@
1
1
  export const listen = async () => {
2
+ if (!process.send) {
3
+ throw new Error('process.send must be defined')
4
+ }
5
+ process.send('ready')
2
6
  return process
3
7
  }
4
8
 
9
+ const getActualData = (message, handle) => {
10
+ if (handle) {
11
+ return {
12
+ ...message,
13
+ params: [...message.params, handle],
14
+ }
15
+ }
16
+ return message
17
+ }
18
+
5
19
  export const wrap = (process) => {
6
20
  return {
7
21
  process,
8
22
  on(event, listener) {
9
- this.process.on(event, listener)
23
+ if (event === 'message') {
24
+ const wrappedListener = (event, handle) => {
25
+ const actualData = getActualData(event, handle)
26
+ listener(actualData)
27
+ }
28
+ this.process.on(event, wrappedListener)
29
+ } else if (event === 'close') {
30
+ this.process.on('close', listener)
31
+ } else {
32
+ throw new Error('unsupported event type')
33
+ }
10
34
  },
11
35
  off(event, listener) {
12
36
  this.process.off(event, listener)
@@ -0,0 +1,41 @@
1
+ import { IpcError } from '../IpcError/IpcError.js'
2
+ import * as IsMessagePort from '../IsMessagePort/IsMessagePort.js'
3
+
4
+ export const listen = ({ messagePort }) => {
5
+ if (!IsMessagePort.isMessagePort(messagePort)) {
6
+ throw new IpcError('port must be of type MessagePort')
7
+ }
8
+ return messagePort
9
+ }
10
+
11
+ const getActualData = (message) => {
12
+ return message
13
+ }
14
+
15
+ export const wrap = (messagePort) => {
16
+ return {
17
+ messagePort,
18
+ on(event, listener) {
19
+ if (event === 'message') {
20
+ const wrappedListener = (event) => {
21
+ const actualData = getActualData(event)
22
+ listener(actualData)
23
+ }
24
+ this.messagePort.on(event, wrappedListener)
25
+ } else if (event === 'close') {
26
+ this.messagePort.on('close', listener)
27
+ } else {
28
+ throw new Error(`unsupported event type ${event}`)
29
+ }
30
+ },
31
+ off(event, listener) {
32
+ this.messagePort.off(event, listener)
33
+ },
34
+ send(message) {
35
+ this.messagePort.postMessage(message)
36
+ },
37
+ dispose() {
38
+ this.messagePort.close()
39
+ },
40
+ }
41
+ }
@@ -1,4 +1,5 @@
1
1
  import { parentPort } from 'node:worker_threads'
2
+ import * as IsElectron from '../IsElectron/IsElectron.js'
2
3
 
3
4
  export const listen = async () => {
4
5
  if (!parentPort) {
@@ -8,11 +9,26 @@ export const listen = async () => {
8
9
  return parentPort
9
10
  }
10
11
 
12
+ const getActualData = (message) => {
13
+ return message
14
+ }
15
+
11
16
  export const wrap = (parentPort) => {
12
17
  return {
18
+ shouldLogError: !IsElectron.isElectron(),
13
19
  parentPort,
14
20
  on(event, listener) {
15
- this.parentPort.on(event, listener)
21
+ if (event === 'message') {
22
+ const wrappedListener = (event) => {
23
+ const actualData = getActualData(event)
24
+ listener(actualData)
25
+ }
26
+ this.parentPort.on(event, wrappedListener)
27
+ } else if (event === 'close') {
28
+ this.parentPort.on('close', listener)
29
+ } else {
30
+ throw new Error('unsupported event type')
31
+ }
16
32
  },
17
33
  off(event, listener) {
18
34
  this.parentPort.off(event, listener)
@@ -0,0 +1,51 @@
1
+ import * as GetFirstWebSocketEvent from '../GetFirstWebSocketEvent/GetFirstWebSocketEvent.js'
2
+ import * as IsWebSocketOpen from '../IsWebSocketOpen/IsWebSocketOpen.js'
3
+
4
+ export const listen = async ({ webSocket }) => {
5
+ if (!IsWebSocketOpen.isWebSocketOpen(webSocket)) {
6
+ const { type, event } = await GetFirstWebSocketEvent.getFirstWebSocketEvent(webSocket)
7
+ console.log({ type, event })
8
+ }
9
+ return webSocket
10
+ }
11
+
12
+ const getActualData = (message) => {
13
+ const data = JSON.parse(message.toString())
14
+ return data
15
+ }
16
+
17
+ export const wrap = (webSocket) => {
18
+ return {
19
+ webSocket,
20
+ /**
21
+ * @type {any}
22
+ */
23
+ wrappedListener: undefined,
24
+ on(event, listener) {
25
+ switch (event) {
26
+ case 'message':
27
+ const wrappedListener = (message) => {
28
+ const data = getActualData(message)
29
+ listener(data)
30
+ }
31
+ webSocket.on('message', wrappedListener)
32
+ break
33
+ case 'close':
34
+ webSocket.on('close', listener)
35
+ break
36
+ default:
37
+ throw new Error('unknown event listener type')
38
+ }
39
+ },
40
+ off(event, listener) {
41
+ this.webSocket.off(event, listener)
42
+ },
43
+ send(message) {
44
+ const stringifiedMessage = JSON.stringify(message)
45
+ this.webSocket.send(stringifiedMessage)
46
+ },
47
+ dispose() {
48
+ this.webSocket.close()
49
+ },
50
+ }
51
+ }
@@ -0,0 +1,6 @@
1
+ export class IpcError extends Error {
2
+ constructor(message) {
3
+ super(message)
4
+ this.name = 'IpcError'
5
+ }
6
+ }
@@ -8,7 +8,8 @@ import { VError } from '../VError/VError.js'
8
8
  export const create = async ({ path, argv = [], env, execArgv = [], stdio = 'inherit', name = 'child process' }) => {
9
9
  try {
10
10
  Assert.string(path)
11
- const childProcess = fork(path, argv, {
11
+ const actualArgv = ['--ipc-type=node-forked-process', ...argv]
12
+ const childProcess = fork(path, actualArgv, {
12
13
  env,
13
14
  execArgv,
14
15
  stdio: 'pipe',
@@ -36,11 +37,14 @@ export const wrap = (childProcess) => {
36
37
  on(event, listener) {
37
38
  this.childProcess.on(event, listener)
38
39
  },
40
+ off(event, listener) {
41
+ this.childProcess.off(event, listener)
42
+ },
39
43
  send(message) {
40
44
  this.childProcess.send(message)
41
45
  },
42
- sendAndTransfer(message, transfer) {
43
- throw new Error('transfer is not supported')
46
+ sendAndTransfer(message, handle) {
47
+ this.childProcess.send(message, handle)
44
48
  },
45
49
  dispose() {
46
50
  this.childProcess.kill()
@@ -0,0 +1,3 @@
1
+ export const isElectron = () => {
2
+ return Boolean(process.env.ELECTRON_RUN_AS_NODE)
3
+ }
@@ -0,0 +1,3 @@
1
+ export const isMessagePort = (value) => {
2
+ return value && value instanceof MessagePort
3
+ }
@@ -0,0 +1,3 @@
1
+ export const isMessagePortMain = (value) => {
2
+ return value && value.constructor && value.constructor.name === 'MessagePortMain'
3
+ }
@@ -0,0 +1,5 @@
1
+ import { Socket } from 'node:net'
2
+
3
+ export const isSocket = (value) => {
4
+ return value instanceof Socket
5
+ }
@@ -0,0 +1,5 @@
1
+ import { WebSocket } from 'ws'
2
+
3
+ export const isWebSocketOpen = (webSocket) => {
4
+ return webSocket.readyState === WebSocket.OPEN
5
+ }
@@ -10,14 +10,26 @@ export const send = (transport, method, ...params) => {
10
10
  }
11
11
 
12
12
  export const invoke = (ipc, method, ...params) => {
13
- return new Promise((resolve, reject) => {
14
- // TODO use one map instead of two
15
- const callbackId = Callback.register(resolve, reject)
16
- ipc.send({
13
+ const { id, promise } = Callback.registerPromise()
14
+ ipc.send({
15
+ jsonrpc: JsonRpcVersion.Two,
16
+ method,
17
+ params,
18
+ id,
19
+ })
20
+ return promise
21
+ }
22
+
23
+ export const invokeAndTransfer = (ipc, handle, method, ...params) => {
24
+ const { id, promise } = Callback.registerPromise()
25
+ ipc.sendAndTransfer(
26
+ {
17
27
  jsonrpc: JsonRpcVersion.Two,
18
28
  method,
19
29
  params,
20
- id: callbackId,
21
- })
22
- })
30
+ id,
31
+ },
32
+ handle
33
+ )
34
+ return promise
23
35
  }
@@ -2,6 +2,8 @@ import * as ModuleId from '../ModuleId/ModuleId.js'
2
2
 
3
3
  export const load = (moduleId) => {
4
4
  switch (moduleId) {
5
+ case ModuleId.AttachDebugger:
6
+ return import('../AttachDebugger/AttachDebugger.ipc.js')
5
7
  case ModuleId.AutoUpdater:
6
8
  return import('../AutoUpdater/AutoUpdater.ipc.js')
7
9
  case ModuleId.AutoUpdaterAppImage:
@@ -20,6 +22,8 @@ export const load = (moduleId) => {
20
22
  return import('../Download/Download.ipc.js')
21
23
  case ModuleId.ExtensionHost:
22
24
  return import('../ExtensionHost/ExtensionHost.ipc.js')
25
+ case ModuleId.ElectronInitialize:
26
+ return import('../ElectronInitialize/ElectronInitialize.ipc.js')
23
27
  case ModuleId.ExtensionManagement:
24
28
  return import('../ExtensionManagement/ExtensionManagement.ipc.js')
25
29
  case ModuleId.FileSystem:
@@ -38,6 +42,8 @@ export const load = (moduleId) => {
38
42
  return import('../Platform/Platform.ipc.js')
39
43
  case ModuleId.Preferences:
40
44
  return import('../Preferences/Preferences.ipc.js')
45
+ case ModuleId.Process:
46
+ return import('../Process/Process.ipc.js')
41
47
  case ModuleId.RecentlyOpened:
42
48
  return import('../RecentlyOpened/RecentlyOpened.ipc.js')
43
49
  case ModuleId.SearchFile:
@@ -52,6 +58,14 @@ export const load = (moduleId) => {
52
58
  return import('../WebSocketServer/WebSocketServer.ipc.js')
53
59
  case ModuleId.Workspace:
54
60
  return import('../Workspace/Workspace.ipc.js')
61
+ case ModuleId.RebuildNodePty:
62
+ return import('../RebuildNodePty/RebuildNodePty.ipc.js')
63
+ case ModuleId.HandleWebSocket:
64
+ return import('../HandleWebSocket/HandleWebSocket.ipc.js')
65
+ case ModuleId.HandleElectronMessagePort:
66
+ return import('../HandleElectronMessagePort/HandleElectronMessagePort.ipc.js')
67
+ case ModuleId.HandleNodeMessagePort:
68
+ return import('../HandleNodeMessagePort/HandleNodeMessagePort.ipc.js')
55
69
  default:
56
70
  throw new Error(`module ${moduleId} not found`)
57
71
  }
@@ -23,3 +23,10 @@ export const AutoUpdater = 22
23
23
  export const IsAutoUpdateSupported = 23
24
24
  export const AutoUpdaterAppImage = 24
25
25
  export const AutoUpdaterWindowsNsis = 25
26
+ export const RebuildNodePty = 26
27
+ export const ElectronInitialize = 27
28
+ export const HandleWebSocket = 28
29
+ export const Process = 29
30
+ export const AttachDebugger = 30
31
+ export const HandleElectronMessagePort = 31
32
+ export const HandleNodeMessagePort = 32
@@ -3,6 +3,8 @@ import * as ModuleId from '../ModuleId/ModuleId.js'
3
3
 
4
4
  export const getModuleId = (commandId) => {
5
5
  switch (commandId) {
6
+ case 'AttachDebugger.attachDebugger':
7
+ return ModuleId.AttachDebugger
6
8
  case 'AutoUpdater.getAutoUpdateType':
7
9
  case 'AutoUpdater.getLatestVersion':
8
10
  return ModuleId.AutoUpdater
@@ -31,6 +33,8 @@ export const getModuleId = (commandId) => {
31
33
  return ModuleId.Developer
32
34
  case 'Download.download':
33
35
  return ModuleId.Download
36
+ case 'ElectronInitialize.electronInitialize':
37
+ return ModuleId.ElectronInitialize
34
38
  case 'ExtensionHost.dispose':
35
39
  case 'ExtensionHost.enableExtension':
36
40
  case 'ExtensionHost.executeCommand':
@@ -108,6 +112,12 @@ export const getModuleId = (commandId) => {
108
112
  case 'GitLsFiles.gitLsFilesHash':
109
113
  case 'GitLsFiles.resolveGit':
110
114
  return ModuleId.GitLsFiles
115
+ case 'HandleWebSocket.handleWebSocket':
116
+ return ModuleId.HandleWebSocket
117
+ case 'HandleElectronMessagePort.handleElectronMessagePort':
118
+ return ModuleId.HandleElectronMessagePort
119
+ case 'HandleNodeMessagePort.handleNodeMessagePort':
120
+ return ModuleId.HandleNodeMessagePort
111
121
  case 'InstallExtension.installExtension':
112
122
  return ModuleId.InstallExtension
113
123
  case 'IsAutoUpdateSupported.isAutoUpdateSupported':
@@ -155,6 +165,14 @@ export const getModuleId = (commandId) => {
155
165
  case 'Workspace.getHomeDir':
156
166
  case 'Workspace.resolveRoot':
157
167
  return ModuleId.Workspace
168
+ case 'RebuildNodePty.rebuildNodePty':
169
+ return ModuleId.RebuildNodePty
170
+ case 'Process.getPid':
171
+ return ModuleId.Process
172
+ case 'HandleNodeMessagePort.handleNodeMessagePort':
173
+ return ModuleId.HandleNodeMessagePort
174
+ case 'HandleElectronMessagePort.handleElectronMessagePort':
175
+ return ModuleId.HandleElectronMessagePort
158
176
  default:
159
177
  throw new CommandNotFoundError(commandId)
160
178
  }