@@ -1169,6 +1169,50 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
11691169 }
11701170 return true ;
11711171 }
1172+
1173+ private async findProcessByProgramName (
1174+ programPath : string ,
1175+ config : CppDebugConfiguration ,
1176+ token ?: vscode . CancellationToken
1177+ ) : Promise < string | undefined > {
1178+ const programBaseName : string = path . basename ( programPath ) ;
1179+ let processes : AttachItem [ ] ;
1180+
1181+ // Get process list using the same logic as interactive attach
1182+ if ( config . pipeTransport || config . useExtendedRemote ) {
1183+ // For remote attach, we need to use RemoteAttachPicker's methods
1184+ void logger . getOutputChannelLogger ( ) . showErrorMessage (
1185+ "Finding process by program name is not yet supported for remote attach. Please use processId instead."
1186+ ) ;
1187+ return undefined ;
1188+ } else {
1189+ const attachItemsProvider : AttachItemsProvider = NativeAttachItemsProviderFactory . Get ( ) ;
1190+ processes = await attachItemsProvider . getAttachItems ( token ) ;
1191+ }
1192+
1193+ // Find processes matching the program name
1194+ const matchingProcesses : AttachItem [ ] = processes . filter ( p => {
1195+ const processName : string = p . label . toLowerCase ( ) ;
1196+ const targetName : string = programBaseName . toLowerCase ( ) ;
1197+ // Match if the process name exactly matches or starts with the target name
1198+ return processName === targetName || processName . startsWith ( targetName ) ;
1199+ } ) ;
1200+
1201+ if ( matchingProcesses . length === 0 ) {
1202+ return undefined ;
1203+ } else if ( matchingProcesses . length === 1 ) {
1204+ void logger . getOutputChannelLogger ( ) . appendLine (
1205+ `Found process "${ matchingProcesses [ 0 ] . label } " with PID ${ matchingProcesses [ 0 ] . id } `
1206+ ) ;
1207+ return matchingProcesses [ 0 ] . id ;
1208+ } else {
1209+ // Multiple matches - let user choose
1210+ void logger . getOutputChannelLogger ( ) . appendLine (
1211+ `Multiple processes found matching "${ programBaseName } ". Please select one:`
1212+ ) ;
1213+ return showQuickPick ( ( ) => Promise . resolve ( matchingProcesses ) ) ;
1214+ }
1215+ }
11721216}
11731217
11741218export interface IConfigurationAssetProvider {
@@ -1336,48 +1380,4 @@ export class ConfigurationSnippetProvider implements vscode.CompletionItemProvid
13361380
13371381 return Promise . resolve ( new vscode . CompletionList ( items , true ) ) ;
13381382 }
1339-
1340- private async findProcessByProgramName (
1341- programPath : string ,
1342- config : CppDebugConfiguration ,
1343- token ?: vscode . CancellationToken
1344- ) : Promise < string | undefined > {
1345- const programBaseName : string = path . basename ( programPath ) ;
1346- let processes : AttachItem [ ] ;
1347-
1348- // Get process list using the same logic as interactive attach
1349- if ( config . pipeTransport || config . useExtendedRemote ) {
1350- // For remote attach, we need to use RemoteAttachPicker's methods
1351- void logger . getOutputChannelLogger ( ) . showErrorMessage (
1352- "Finding process by program name is not yet supported for remote attach. Please use processId instead."
1353- ) ;
1354- return undefined ;
1355- } else {
1356- const attachItemsProvider : AttachItemsProvider = NativeAttachItemsProviderFactory . Get ( ) ;
1357- processes = await attachItemsProvider . getAttachItems ( token ) ;
1358- }
1359-
1360- // Find processes matching the program name
1361- const matchingProcesses : AttachItem [ ] = processes . filter ( p => {
1362- const processName : string = p . label . toLowerCase ( ) ;
1363- const targetName : string = programBaseName . toLowerCase ( ) ;
1364- // Match if the process name exactly matches or starts with the target name
1365- return processName === targetName || processName . startsWith ( targetName ) ;
1366- } ) ;
1367-
1368- if ( matchingProcesses . length === 0 ) {
1369- return undefined ;
1370- } else if ( matchingProcesses . length === 1 ) {
1371- void logger . getOutputChannelLogger ( ) . appendLine (
1372- `Found process "${ matchingProcesses [ 0 ] . label } " with PID ${ matchingProcesses [ 0 ] . id } `
1373- ) ;
1374- return matchingProcesses [ 0 ] . id ;
1375- } else {
1376- // Multiple matches - let user choose
1377- void logger . getOutputChannelLogger ( ) . appendLine (
1378- `Multiple processes found matching "${ programBaseName } ". Please select one:`
1379- ) ;
1380- return showQuickPick ( ( ) => Promise . resolve ( matchingProcesses ) ) ;
1381- }
1382- }
13831383}
0 commit comments