|
4 | 4 | 'use strict'; |
5 | 5 |
|
6 | 6 | import { l10n } from 'vscode'; |
| 7 | +import * as wpc from '@vscode/windows-process-tree'; |
7 | 8 | import { getOSType, OSType } from '../../common/platform'; |
8 | 9 | import { PsProcessParser } from './psProcessParser'; |
9 | 10 | import { IAttachItem, IAttachProcessProvider, ProcessListCommand } from './types'; |
@@ -58,24 +59,46 @@ export class AttachProcessProvider implements IAttachProcessProvider { |
58 | 59 | } |
59 | 60 |
|
60 | 61 | public async _getInternalProcessEntries(): Promise<IAttachItem[]> { |
61 | | - let processCmd: ProcessListCommand; |
62 | 62 | const osType = getOSType(); |
| 63 | + |
| 64 | + if (osType === OSType.Windows) { |
| 65 | + try { |
| 66 | + const processList = await new Promise<wpc.IProcessInfo[]>((resolve) => { |
| 67 | + wpc.getAllProcesses((processes) => resolve(processes), wpc.ProcessDataFlag.CommandLine); |
| 68 | + }); |
| 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; |
63 | 91 | if (osType === OSType.OSX) { |
64 | 92 | processCmd = PsProcessParser.psDarwinCommand; |
65 | 93 | } else if (osType === OSType.Linux) { |
66 | 94 | processCmd = PsProcessParser.psLinuxCommand; |
67 | | - } else if (osType === OSType.Windows) { |
68 | | - processCmd = WmicProcessParser.wmicCommand; |
69 | 95 | } else { |
70 | 96 | throw new Error(l10n.t("Operating system '{0}' not supported.", osType)); |
71 | 97 | } |
72 | 98 |
|
73 | 99 | const customEnvVars = await getEnvironmentVariables(); |
74 | 100 | const output = await plainExec(processCmd.command, processCmd.args, { throwOnStdErr: true }, customEnvVars); |
75 | 101 | 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); |
80 | 103 | } |
81 | 104 | } |
0 commit comments