Skip to content

Commit d48f1b3

Browse files
committed
add option in dev menu to start processes
1 parent 53aaeef commit d48f1b3

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

packages/core/src/dev/activation.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { getSessionId } from '../shared/telemetry/util'
2424
import { NotificationsController } from '../notifications/controller'
2525
import { DevNotificationsState } from '../notifications/types'
2626
import { QuickPickItem } from 'vscode'
27+
import { ChildProcess } from '../shared/utilities/processUtils'
2728

2829
interface MenuOption {
2930
readonly label: string
@@ -44,6 +45,7 @@ export type DevFunction =
4445
| 'editAuthConnections'
4546
| 'notificationsSend'
4647
| 'forceIdeCrash'
48+
| 'startChildProcess'
4749

4850
export type DevOptions = {
4951
context: vscode.ExtensionContext
@@ -126,6 +128,11 @@ const menuOptions: () => Record<DevFunction, MenuOption> = () => {
126128
detail: `Will SIGKILL ExtHost, { pid: ${process.pid}, sessionId: '${getSessionId().slice(0, 8)}-...' }, but the IDE itself will not crash.`,
127129
executor: forceQuitIde,
128130
},
131+
startChildProcess: {
132+
label: 'ChildProcess: Start child process',
133+
detail: 'start a ChildProcess manually that is invoked through our wrapper',
134+
executor: startChildProcess,
135+
},
129136
}
130137
}
131138

@@ -578,3 +585,15 @@ async function editNotifications() {
578585
await targetNotificationsController.pollForEmergencies()
579586
})
580587
}
588+
589+
async function startChildProcess() {
590+
const result = await createInputBox({
591+
title: 'Enter a command',
592+
}).prompt()
593+
if (result) {
594+
const [command, ...args] = result?.toString().split(' ') ?? []
595+
getLogger().info(`Starting child process: '${command}'`)
596+
const processResult = await ChildProcess.run(command, args, { collect: true })
597+
getLogger().info(`Child process exited with code ${processResult.exitCode}`)
598+
}
599+
}

packages/core/src/shared/utilities/processUtils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ export interface ChildProcessResult {
6363

6464
export const eof = Symbol('EOF')
6565

66-
export class ChildProcessTracker extends Map<number, ChildProcess> {
67-
static pollingInterval: number = 5000
66+
class ChildProcessTracker extends Map<number, ChildProcess> {
67+
static pollingInterval: number = 1000
6868
#processPoller: PollingSet<number>
6969

7070
public constructor() {
7171
super()
72-
this.#processPoller = new PollingSet(ChildProcessTracker.pollingInterval, () => {})
72+
this.#processPoller = new PollingSet(ChildProcessTracker.pollingInterval, () => this.monitorProcesses())
73+
getLogger().debug(`ChildProcessTracker created with polling interval: ${ChildProcessTracker.pollingInterval}`)
7374
}
7475

7576
private cleanUpProcesses() {
@@ -94,7 +95,7 @@ export class ChildProcessTracker extends Map<number, ChildProcess> {
9495
}
9596

9697
public override set(key: number, value: ChildProcess): this {
97-
this.#processPoller.add(key)
98+
this.#processPoller.start(key)
9899
super.set(key, value)
99100
return this
100101
}

0 commit comments

Comments
 (0)