@@ -10,30 +10,36 @@ import {
10
10
showQuickPickWithBack ,
11
11
} from '../../common/vscodeApis/windowApis' ;
12
12
import { traceError , traceVerbose } from '../../logging' ;
13
- import { CreateEnvironmentOptions , CreateEnvironmentProvider , CreateEnvironmentResult } from './types' ;
13
+ import {
14
+ CreateEnvironmentExitedEventArgs ,
15
+ CreateEnvironmentOptions ,
16
+ CreateEnvironmentProvider ,
17
+ CreateEnvironmentResult ,
18
+ CreateEnvironmentStartedEventArgs ,
19
+ } from './types' ;
14
20
15
- const onCreateEnvironmentStartedEvent = new EventEmitter < void > ( ) ;
16
- const onCreateEnvironmentExitedEvent = new EventEmitter < CreateEnvironmentResult | undefined > ( ) ;
21
+ const onCreateEnvironmentStartedEvent = new EventEmitter < CreateEnvironmentStartedEventArgs > ( ) ;
22
+ const onCreateEnvironmentExitedEvent = new EventEmitter < CreateEnvironmentExitedEventArgs > ( ) ;
17
23
18
24
let startedEventCount = 0 ;
19
25
20
26
function isBusyCreatingEnvironment ( ) : boolean {
21
27
return startedEventCount > 0 ;
22
28
}
23
29
24
- function fireStartedEvent ( ) : void {
25
- onCreateEnvironmentStartedEvent . fire ( ) ;
30
+ function fireStartedEvent ( options ?: CreateEnvironmentOptions ) : void {
31
+ onCreateEnvironmentStartedEvent . fire ( { options } ) ;
26
32
startedEventCount += 1 ;
27
33
}
28
34
29
- function fireExitedEvent ( result : CreateEnvironmentResult | undefined ) : void {
30
- onCreateEnvironmentExitedEvent . fire ( result ) ;
35
+ function fireExitedEvent ( result ? : CreateEnvironmentResult , options ?: CreateEnvironmentOptions , error ?: unknown ) : void {
36
+ onCreateEnvironmentExitedEvent . fire ( { result, options , error } ) ;
31
37
startedEventCount -= 1 ;
32
38
}
33
39
34
40
export function getCreationEvents ( ) : {
35
- onCreateEnvironmentStarted : Event < void > ;
36
- onCreateEnvironmentExited : Event < CreateEnvironmentResult | undefined > ;
41
+ onCreateEnvironmentStarted : Event < CreateEnvironmentStartedEventArgs > ;
42
+ onCreateEnvironmentExited : Event < CreateEnvironmentExitedEventArgs > ;
37
43
isCreatingEnvironment : ( ) => boolean ;
38
44
} {
39
45
return {
@@ -45,14 +51,12 @@ export function getCreationEvents(): {
45
51
46
52
async function createEnvironment (
47
53
provider : CreateEnvironmentProvider ,
48
- options : CreateEnvironmentOptions = {
49
- ignoreSourceControl : true ,
50
- installPackages : true ,
51
- } ,
54
+ options : CreateEnvironmentOptions ,
52
55
) : Promise < CreateEnvironmentResult | undefined > {
53
56
let result : CreateEnvironmentResult | undefined ;
57
+ let err : unknown | undefined ;
54
58
try {
55
- fireStartedEvent ( ) ;
59
+ fireStartedEvent ( options ) ;
56
60
result = await provider . createEnvironment ( options ) ;
57
61
} catch ( ex ) {
58
62
if ( ex === QuickInputButtons . Back ) {
@@ -61,9 +65,10 @@ async function createEnvironment(
61
65
return undefined ;
62
66
}
63
67
}
64
- throw ex ;
68
+ err = ex ;
69
+ throw err ;
65
70
} finally {
66
- fireExitedEvent ( result ) ;
71
+ fireExitedEvent ( result , options , err ) ;
67
72
}
68
73
return result ;
69
74
}
@@ -110,17 +115,28 @@ async function showCreateEnvironmentQuickPick(
110
115
return undefined ;
111
116
}
112
117
118
+ function getOptionsWithDefaults ( options ?: CreateEnvironmentOptions ) : CreateEnvironmentOptions {
119
+ return {
120
+ installPackages : true ,
121
+ ignoreSourceControl : true ,
122
+ showBackButton : false ,
123
+ selectEnvironment : true ,
124
+ ...options ,
125
+ } ;
126
+ }
127
+
113
128
export async function handleCreateEnvironmentCommand (
114
129
providers : readonly CreateEnvironmentProvider [ ] ,
115
130
options ?: CreateEnvironmentOptions ,
116
131
) : Promise < CreateEnvironmentResult | undefined > {
132
+ const optionsWithDefaults = getOptionsWithDefaults ( options ) ;
117
133
let selectedProvider : CreateEnvironmentProvider | undefined ;
118
134
const envTypeStep = new MultiStepNode (
119
135
undefined ,
120
136
async ( context ?: MultiStepAction ) => {
121
137
if ( providers . length > 0 ) {
122
138
try {
123
- selectedProvider = await showCreateEnvironmentQuickPick ( providers , options ) ;
139
+ selectedProvider = await showCreateEnvironmentQuickPick ( providers , optionsWithDefaults ) ;
124
140
} catch ( ex ) {
125
141
if ( ex === MultiStepAction . Back || ex === MultiStepAction . Cancel ) {
126
142
return ex ;
@@ -152,7 +168,7 @@ export async function handleCreateEnvironmentCommand(
152
168
}
153
169
if ( selectedProvider ) {
154
170
try {
155
- result = await createEnvironment ( selectedProvider , options ) ;
171
+ result = await createEnvironment ( selectedProvider , optionsWithDefaults ) ;
156
172
} catch ( ex ) {
157
173
if ( ex === MultiStepAction . Back || ex === MultiStepAction . Cancel ) {
158
174
return ex ;
0 commit comments