Skip to content

Commit b2c0382

Browse files
allow filtering processes by program
1 parent daf2618 commit b2c0382

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

lldb/tools/lldb-dap/src-ts/commands/pick-process.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as vscode from "vscode";
33
import { createProcessTree } from "../process-tree";
44

55
interface ProcessQuickPick extends vscode.QuickPickItem {
6-
processId: number;
6+
processId?: number;
77
}
88

99
/**
@@ -13,30 +13,45 @@ interface ProcessQuickPick extends vscode.QuickPickItem {
1313
* string substitution infrastructure. The value will eventually be converted
1414
* to a number by the debug configuration provider.
1515
*
16+
* @param configuration The related debug configuration, if any
1617
* @returns The pid of the process as a string or undefined if cancelled.
1718
*/
18-
export async function pickProcess(): Promise<string | undefined> {
19+
export async function pickProcess(
20+
configuration?: vscode.DebugConfiguration,
21+
): Promise<string | undefined> {
1922
const processTree = createProcessTree();
2023
const selectedProcess = await vscode.window.showQuickPick<ProcessQuickPick>(
2124
processTree.listAllProcesses().then((processes): ProcessQuickPick[] => {
22-
return processes
23-
.sort((a, b) => b.start - a.start) // Sort by start date in descending order
24-
.map((proc) => {
25-
return {
26-
processId: proc.id,
27-
label: path.basename(proc.command),
28-
description: proc.id.toString(),
29-
detail: proc.arguments,
30-
} satisfies ProcessQuickPick;
31-
});
25+
// Sort by start date in descending order
26+
processes.sort((a, b) => b.start - a.start);
27+
// Filter by program if requested
28+
if (typeof configuration?.program === "string") {
29+
processes = processes.filter(
30+
(proc) => proc.command === configuration.program,
31+
);
32+
// Show a better message if all processes were filtered out
33+
if (processes.length === 0) {
34+
return [
35+
{
36+
label: "No processes matched the debug configuration's program",
37+
},
38+
];
39+
}
40+
}
41+
// Convert to a QuickPickItem
42+
return processes.map((proc) => {
43+
return {
44+
processId: proc.id,
45+
label: path.basename(proc.command),
46+
description: proc.id.toString(),
47+
detail: proc.arguments,
48+
} satisfies ProcessQuickPick;
49+
});
3250
}),
3351
{
3452
placeHolder: "Select a process to attach the debugger to",
3553
matchOnDetail: true,
3654
},
3755
);
38-
if (!selectedProcess) {
39-
return;
40-
}
41-
return selectedProcess.processId.toString();
56+
return selectedProcess?.processId?.toString();
4257
}

0 commit comments

Comments
 (0)