Skip to content

Commit 9a33329

Browse files
committed
Use windows-process-tree on Windows for process listing
Add @vscode/windows-process-tree as a dependency and use it on Windows to enumerate processes (via promisified getAllProcesses). Fall back to the existing WMIC parser when windows-process-tree is unavailable. Update provider logic to return parsed process items from the native API on Windows and keep PS-based listing for macOS/Linux. Update unit tests to stub and exercise the new getAllProcesses flow and the WMIC fallback, and add webpack externals entry for the new native module.
1 parent 1af35f6 commit 9a33329

File tree

5 files changed

+276
-34
lines changed

5 files changed

+276
-34
lines changed

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@
682682
"@vscode/debugprotocol": "^1.65.0",
683683
"@vscode/extension-telemetry": "^0.8.4",
684684
"@vscode/python-extension": "^1.0.6",
685+
"@vscode/windows-process-tree": "^0.7.0",
685686
"fs-extra": "^11.2.0",
686687
"iconv-lite": "^0.6.3",
687688
"jsonc-parser": "^3.0.0",

src/extension/debugger/attachQuickPick/provider.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
'use strict';
55

6+
import { promisify } from 'util';
67
import { l10n } from 'vscode';
8+
import * as wpc from '@vscode/windows-process-tree';
79
import { getOSType, OSType } from '../../common/platform';
810
import { PsProcessParser } from './psProcessParser';
911
import { IAttachItem, IAttachProcessProvider, ProcessListCommand } from './types';
@@ -58,24 +60,45 @@ export class AttachProcessProvider implements IAttachProcessProvider {
5860
}
5961

6062
public async _getInternalProcessEntries(): Promise<IAttachItem[]> {
61-
let processCmd: ProcessListCommand;
6263
const osType = getOSType();
64+
65+
if (osType === OSType.Windows) {
66+
try {
67+
const getAllProcesses = promisify(wpc.getAllProcesses);
68+
const processList = await getAllProcesses(wpc.ProcessDataFlag.CommandLine);
69+
return processList.map((p) => ({
70+
label: p.name,
71+
description: String(p.pid),
72+
detail: p.commandLine || '',
73+
id: String(p.pid),
74+
processName: p.name,
75+
commandLine: p.commandLine || '',
76+
}));
77+
} catch {
78+
const customEnvVars = await getEnvironmentVariables();
79+
const output = await plainExec(
80+
WmicProcessParser.wmicCommand.command,
81+
WmicProcessParser.wmicCommand.args,
82+
{ throwOnStdErr: true },
83+
customEnvVars,
84+
);
85+
logProcess(WmicProcessParser.wmicCommand.command, WmicProcessParser.wmicCommand.args, { throwOnStdErr: true });
86+
return WmicProcessParser.parseProcesses(output.stdout);
87+
}
88+
}
89+
90+
let processCmd: ProcessListCommand;
6391
if (osType === OSType.OSX) {
6492
processCmd = PsProcessParser.psDarwinCommand;
6593
} else if (osType === OSType.Linux) {
6694
processCmd = PsProcessParser.psLinuxCommand;
67-
} else if (osType === OSType.Windows) {
68-
processCmd = WmicProcessParser.wmicCommand;
6995
} else {
7096
throw new Error(l10n.t("Operating system '{0}' not supported.", osType));
7197
}
7298

7399
const customEnvVars = await getEnvironmentVariables();
74100
const output = await plainExec(processCmd.command, processCmd.args, { throwOnStdErr: true }, customEnvVars);
75101
logProcess(processCmd.command, processCmd.args, { throwOnStdErr: true });
76-
77-
return osType === OSType.Windows
78-
? WmicProcessParser.parseProcesses(output.stdout)
79-
: PsProcessParser.parseProcesses(output.stdout);
102+
return PsProcessParser.parseProcesses(output.stdout);
80103
}
81104
}

0 commit comments

Comments
 (0)