@@ -569,7 +569,10 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand implem
569569 * @returns true when an interpreter was set, undefined if the user cancelled the quickpick.
570570 */
571571 @captureTelemetry ( EventName . SELECT_INTERPRETER )
572- public async setInterpreter ( ) : Promise < true | undefined > {
572+ public async setInterpreter ( options ?: {
573+ hideCreateVenv ?: boolean ;
574+ showBackButton ?: boolean ;
575+ } ) : Promise < SelectEnvironmentResult | undefined > {
573576 const targetConfig = await this . getConfigTargets ( ) ;
574577 if ( ! targetConfig ) {
575578 return ;
@@ -578,11 +581,25 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand implem
578581 const wkspace = targetConfig [ 0 ] . folderUri ;
579582 const interpreterState : InterpreterStateArgs = { path : undefined , workspace : wkspace } ;
580583 const multiStep = this . multiStepFactory . create < InterpreterStateArgs > ( ) ;
581- await multiStep . run (
582- ( input , s ) => this . _pickInterpreter ( input , s , undefined , { showCreateEnvironment : true } ) ,
583- interpreterState ,
584- ) ;
585-
584+ try {
585+ await multiStep . run (
586+ ( input , s ) =>
587+ this . _pickInterpreter ( input , s , undefined , {
588+ showCreateEnvironment : ! options ?. hideCreateVenv ,
589+ showBackButton : options ?. showBackButton ,
590+ } ) ,
591+ interpreterState ,
592+ ) ;
593+ } catch ( ex ) {
594+ if ( ex === InputFlowAction . back ) {
595+ // User clicked back button, so we need to return this action.
596+ return { action : 'Back' } ;
597+ }
598+ if ( ex === InputFlowAction . cancel ) {
599+ // User clicked cancel button, so we need to return this action.
600+ return { action : 'Cancel' } ;
601+ }
602+ }
586603 if ( interpreterState . path !== undefined ) {
587604 // User may choose to have an empty string stored, so variable `interpreterState.path` may be
588605 // an empty string, in which case we should update.
@@ -591,7 +608,7 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand implem
591608 if ( useEnvExtension ( ) ) {
592609 await setInterpreterLegacy ( interpreterState . path , wkspace ) ;
593610 }
594- return true ;
611+ return { path : interpreterState . path } ;
595612 }
596613 }
597614
@@ -692,3 +709,14 @@ function getGroup(item: IInterpreterQuickPickItem, workspacePath?: string) {
692709 return EnvGroups [ item . interpreter . envType ] ;
693710 }
694711}
712+
713+ export type SelectEnvironmentResult = {
714+ /**
715+ * Path to the executable python in the environment
716+ */
717+ readonly path ?: string ;
718+ /*
719+ * User action that resulted in exit from the create environment flow.
720+ */
721+ readonly action ?: 'Back' | 'Cancel' ;
722+ } ;
0 commit comments