@@ -4,20 +4,26 @@ import * as path from 'path';
44import { EnvironmentManagers , InternalEnvironmentManager } from '../../internal.api' ;
55import { CreateEnvironmentOptions } from '../../api' ;
66import { traceVerbose } from '../../common/logging' ;
7+ import { showQuickPickWithButtons } from '../../common/window.apis' ;
78
89/**
9- * Prompts the user to choose whether to create a new virtual environment (venv) for a package.
10+ * Prompts the user to choose whether to create a new virtual environment (venv) for a package, with a clearer return and early exit .
1011 * @returns {Promise<boolean | undefined> } Resolves to true if 'Yes' is selected, false if 'No', or undefined if cancelled.
1112 */
1213export async function promptForVenv ( ) : Promise < boolean | undefined > {
13- const venvChoice = await window . showQuickPick ( [ 'Yes' , 'No' ] , {
14+ const venvChoice = await showQuickPickWithButtons ( [ { label : 'Yes' } , { label : 'No' } ] , {
1415 placeHolder : 'Would you like to create a new virtual environment for this package?' ,
1516 ignoreFocusOut : true ,
17+ showBackButton : true ,
1618 } ) ;
1719 if ( ! venvChoice ) {
1820 return undefined ;
1921 }
20- return venvChoice === 'Yes' ;
22+ if ( Array . isArray ( venvChoice ) ) {
23+ // Should not happen for single selection, but handle just in case
24+ return venvChoice . some ( ( item ) => item . label === 'Yes' ) ;
25+ }
26+ return venvChoice . label === 'Yes' ;
2127}
2228
2329/**
@@ -36,14 +42,19 @@ export async function promptForCopilotInstructions(): Promise<boolean | undefine
3642 if ( ! isCopilotInstalled ( ) ) {
3743 return undefined ;
3844 }
39- const copilotChoice = await window . showQuickPick ( [ 'Yes' , 'No' ] , {
45+ const copilotChoice = await showQuickPickWithButtons ( [ { label : 'Yes' } , { label : 'No' } ] , {
4046 placeHolder : 'Would you like to create a Copilot instructions file?' ,
4147 ignoreFocusOut : true ,
48+ showBackButton : true ,
4249 } ) ;
4350 if ( ! copilotChoice ) {
4451 return undefined ;
4552 }
46- return copilotChoice === 'Yes' ;
53+ if ( Array . isArray ( copilotChoice ) ) {
54+ // Should not happen for single selection, but handle just in case
55+ return copilotChoice . some ( ( item ) => item . label === 'Yes' ) ;
56+ }
57+ return copilotChoice . label === 'Yes' ;
4758}
4859
4960/**
@@ -58,6 +69,9 @@ export async function removeCopilotInstructions(destFolder: string) {
5869 }
5970}
6071
72+ export async function insertCopilotInstructions ( ) { }
73+ export async function insertLaunchJson ( ) { }
74+
6175/**
6276 * Quickly creates a new Python virtual environment (venv) in the specified destination folder using the available environment managers.
6377 * Attempts to use the venv manager if available, otherwise falls back to any manager that supports environment creation.
@@ -66,37 +80,27 @@ export async function removeCopilotInstructions(destFolder: string) {
6680 * @returns {Promise<void> } Resolves when the environment is created or an error is shown.
6781 */
6882export async function quickCreateNewVenv ( envManagers : EnvironmentManagers , destFolder : string ) {
69- try {
70- // get the environment manager for venv
71- const envManager : InternalEnvironmentManager | undefined = envManagers . managers . find (
72- ( m ) => m . id === 'ms-python.python:venv' ,
73- ) ;
74- const destUri = Uri . parse ( destFolder ) ;
75- if ( envManager ?. supportsQuickCreate ) {
76- // with quickCreate enabled, user will not be prompted when creating the environment
77- const options : CreateEnvironmentOptions = { quickCreate : false } ;
78- if ( envManager . supportsQuickCreate ) {
79- options . quickCreate = true ;
80- }
81- const pyEnv = await envManager . create ( destUri , options ) ;
83+ // get the environment manager for venv, should always exist
84+ const envManager : InternalEnvironmentManager | undefined = envManagers . managers . find (
85+ ( m ) => m . id === 'ms-python.python:venv' ,
86+ ) ;
87+ const destinationUri = Uri . parse ( destFolder ) ;
88+ if ( envManager ?. supportsQuickCreate ) {
89+ // with quickCreate enabled, user will not be prompted when creating the environment
90+ const options : CreateEnvironmentOptions = { quickCreate : false } ;
91+ if ( envManager . supportsQuickCreate ) {
92+ options . quickCreate = true ;
93+ }
94+ const pyEnv = await envManager . create ( destinationUri , options ) ;
95+ // TODO: do I need to update to say this is the env for the file? Like set it?
96+ if ( ! pyEnv ) {
8297 // comes back as undefined if this doesn't work
83- traceVerbose ( `Created venv at: ${ pyEnv ?. environmentPath } using ${ envManager . name } `) ;
98+ window . showErrorMessage ( `Failed to create virtual environment, please create it manually. `) ;
8499 } else {
85- // // find an environment manager that supports create
86- // const envManager = envManagers.managers.find((m) => m.supportsCreate);
87- // if (envManager) {
88- // const options: CreateEnvironmentOptions = { quickCreate: true, additionalPackages: [] };
89- // const pyEnv = await envManager.create(destUri, options);
90- // traceVerbose(`Created venv at: ${pyEnv?.environmentPath} using ${envManager.name}`);
91- // }
92- // // If no environment manager supports create, show an error message
93- // window.showErrorMessage(
94- // `No environment manager found that supports creating a new environment, skipping...`,
95- // );
96- //TODO: just throw error
100+ traceVerbose ( `Created venv at: ${ pyEnv ?. environmentPath } ` ) ;
97101 }
98- } catch ( err ) {
99- window . showErrorMessage ( `Failed to create virtual environment: ${ err } ` ) ;
102+ } else {
103+ window . showErrorMessage ( `Failed to quick create virtual environment, please create it manually. ` ) ;
100104 }
101105}
102106
0 commit comments