Skip to content

Commit 4a5f3d7

Browse files
committed
Wrap wpc.getAllProcesses in a Promise
Replace use of util.promisify with an explicit Promise wrapper around wpc.getAllProcesses, removing the promisify import and adapting the call site to resolve with the process list. Update unit tests to match the changed callback shape (stubs now call callback(processList) and throw without an error-first parameter). This keeps Windows process enumeration working while aligning with the windows-process-tree callback behavior.
1 parent ac58e46 commit 4a5f3d7

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/extension/debugger/attachQuickPick/provider.ts

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

44
'use strict';
55

6-
import { promisify } from 'util';
76
import { l10n } from 'vscode';
87
import * as wpc from '@vscode/windows-process-tree';
98
import { getOSType, OSType } from '../../common/platform';
@@ -64,8 +63,9 @@ export class AttachProcessProvider implements IAttachProcessProvider {
6463

6564
if (osType === OSType.Windows) {
6665
try {
67-
const getAllProcesses = promisify(wpc.getAllProcesses);
68-
const processList = await getAllProcesses(wpc.ProcessDataFlag.CommandLine);
66+
const processList = await new Promise<wpc.IProcessInfo[]>((resolve) => {
67+
wpc.getAllProcesses((processes) => resolve(processes), wpc.ProcessDataFlag.CommandLine);
68+
});
6969
return processList.map((p) => ({
7070
label: p.name,
7171
description: String(p.pid),

src/test/unittest/attachQuickPick/provider.unit.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ suite('Attach to process - process provider', () => {
169169
},
170170
];
171171
getOSTypeStub.returns(platform.OSType.Windows);
172-
getAllProcessesStub.callsFake((_flag: any,callback: Function) => callback(null,processList));
172+
getAllProcessesStub.callsFake((callback: Function) => callback(processList));
173173

174174
const attachItems = await provider._getInternalProcessEntries();
175175
sinon.assert.notCalled(plainExecStub);
@@ -330,7 +330,7 @@ suite('Attach to process - process provider', () => {
330330
},
331331
];
332332

333-
getAllProcessesStub.callsFake((_flag: any,callback: Function) => callback(null,processList));
333+
getAllProcessesStub.callsFake((callback: Function) => callback(processList));
334334

335335
const output = await provider.getAttachItems();
336336

@@ -416,7 +416,7 @@ suite('Attach to process - process provider', () => {
416416
},
417417
];
418418

419-
getAllProcessesStub.callsFake((_flag: any,callback: Function) => callback(null,processList));
419+
getAllProcessesStub.callsFake((callback: Function) => callback(processList));
420420

421421
const output = await provider.getAttachItems();
422422

@@ -430,7 +430,7 @@ suite('Attach to process - process provider', () => {
430430
});
431431

432432
test('Should fall back to wmic when getAllProcesses fails', async () => {
433-
getAllProcessesStub.callsFake((_flag: any,_callback: Function) => {
433+
getAllProcessesStub.callsFake((_callback: Function) => {
434434
throw new Error('windows-process-tree unavailable');
435435
});
436436
const windowsOutput = `CommandLine=\r
@@ -484,7 +484,7 @@ ProcessId=5912\r
484484
});
485485

486486
test('Items returned by getAttachItems via wmic fallback should be sorted alphabetically', async () => {
487-
getAllProcessesStub.callsFake((_flag: any,_callback: Function) => {
487+
getAllProcessesStub.callsFake((_callback: Function) => {
488488
throw new Error('windows-process-tree unavailable');
489489
});
490490
const windowsOutput = `CommandLine=\r
@@ -538,7 +538,7 @@ ProcessId=5728\r
538538
});
539539

540540
test('Python processes should be at the top of the list returned by getAttachItems via wmic fallback', async () => {
541-
getAllProcessesStub.callsFake((_flag: any,_callback: Function) => {
541+
getAllProcessesStub.callsFake((_callback: Function) => {
542542
throw new Error('windows-process-tree unavailable');
543543
});
544544
const windowsOutput = `CommandLine=\r

0 commit comments

Comments
 (0)