@@ -3,7 +3,7 @@ import * as vscode from "vscode";
3
3
import { createProcessTree } from "../process-tree" ;
4
4
5
5
interface ProcessQuickPick extends vscode . QuickPickItem {
6
- processId : number ;
6
+ processId ? : number ;
7
7
}
8
8
9
9
/**
@@ -13,30 +13,45 @@ interface ProcessQuickPick extends vscode.QuickPickItem {
13
13
* string substitution infrastructure. The value will eventually be converted
14
14
* to a number by the debug configuration provider.
15
15
*
16
+ * @param configuration The related debug configuration, if any
16
17
* @returns The pid of the process as a string or undefined if cancelled.
17
18
*/
18
- export async function pickProcess ( ) : Promise < string | undefined > {
19
+ export async function pickProcess (
20
+ configuration ?: vscode . DebugConfiguration ,
21
+ ) : Promise < string | undefined > {
19
22
const processTree = createProcessTree ( ) ;
20
23
const selectedProcess = await vscode . window . showQuickPick < ProcessQuickPick > (
21
24
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
+ } ) ;
32
50
} ) ,
33
51
{
34
52
placeHolder : "Select a process to attach the debugger to" ,
35
53
matchOnDetail : true ,
36
54
} ,
37
55
) ;
38
- if ( ! selectedProcess ) {
39
- return ;
40
- }
41
- return selectedProcess . processId . toString ( ) ;
56
+ return selectedProcess ?. processId ?. toString ( ) ;
42
57
}
0 commit comments