@@ -4,20 +4,26 @@ import * as path from 'path';
4
4
import { EnvironmentManagers , InternalEnvironmentManager } from '../../internal.api' ;
5
5
import { CreateEnvironmentOptions } from '../../api' ;
6
6
import { traceVerbose } from '../../common/logging' ;
7
+ import { showQuickPickWithButtons } from '../../common/window.apis' ;
7
8
8
9
/**
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 .
10
11
* @returns {Promise<boolean | undefined> } Resolves to true if 'Yes' is selected, false if 'No', or undefined if cancelled.
11
12
*/
12
13
export async function promptForVenv ( ) : Promise < boolean | undefined > {
13
- const venvChoice = await window . showQuickPick ( [ 'Yes' , 'No' ] , {
14
+ const venvChoice = await showQuickPickWithButtons ( [ { label : 'Yes' } , { label : 'No' } ] , {
14
15
placeHolder : 'Would you like to create a new virtual environment for this package?' ,
15
16
ignoreFocusOut : true ,
17
+ showBackButton : true ,
16
18
} ) ;
17
19
if ( ! venvChoice ) {
18
20
return undefined ;
19
21
}
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' ;
21
27
}
22
28
23
29
/**
@@ -36,14 +42,19 @@ export async function promptForCopilotInstructions(): Promise<boolean | undefine
36
42
if ( ! isCopilotInstalled ( ) ) {
37
43
return undefined ;
38
44
}
39
- const copilotChoice = await window . showQuickPick ( [ 'Yes' , 'No' ] , {
45
+ const copilotChoice = await showQuickPickWithButtons ( [ { label : 'Yes' } , { label : 'No' } ] , {
40
46
placeHolder : 'Would you like to create a Copilot instructions file?' ,
41
47
ignoreFocusOut : true ,
48
+ showBackButton : true ,
42
49
} ) ;
43
50
if ( ! copilotChoice ) {
44
51
return undefined ;
45
52
}
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' ;
47
58
}
48
59
49
60
/**
@@ -58,6 +69,9 @@ export async function removeCopilotInstructions(destFolder: string) {
58
69
}
59
70
}
60
71
72
+ export async function insertCopilotInstructions ( ) { }
73
+ export async function insertLaunchJson ( ) { }
74
+
61
75
/**
62
76
* Quickly creates a new Python virtual environment (venv) in the specified destination folder using the available environment managers.
63
77
* 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) {
66
80
* @returns {Promise<void> } Resolves when the environment is created or an error is shown.
67
81
*/
68
82
export 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 ) {
82
97
// 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. `) ;
84
99
} 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 } ` ) ;
97
101
}
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. ` ) ;
100
104
}
101
105
}
102
106
0 commit comments