@@ -10,30 +10,36 @@ import {
1010 showQuickPickWithBack ,
1111} from '../../common/vscodeApis/windowApis' ;
1212import { 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' ;
1420
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 > ( ) ;
1723
1824let startedEventCount = 0 ;
1925
2026function isBusyCreatingEnvironment ( ) : boolean {
2127 return startedEventCount > 0 ;
2228}
2329
24- function fireStartedEvent ( ) : void {
25- onCreateEnvironmentStartedEvent . fire ( ) ;
30+ function fireStartedEvent ( options ?: CreateEnvironmentOptions ) : void {
31+ onCreateEnvironmentStartedEvent . fire ( { options } ) ;
2632 startedEventCount += 1 ;
2733}
2834
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 } ) ;
3137 startedEventCount -= 1 ;
3238}
3339
3440export function getCreationEvents ( ) : {
35- onCreateEnvironmentStarted : Event < void > ;
36- onCreateEnvironmentExited : Event < CreateEnvironmentResult | undefined > ;
41+ onCreateEnvironmentStarted : Event < CreateEnvironmentStartedEventArgs > ;
42+ onCreateEnvironmentExited : Event < CreateEnvironmentExitedEventArgs > ;
3743 isCreatingEnvironment : ( ) => boolean ;
3844} {
3945 return {
@@ -45,14 +51,12 @@ export function getCreationEvents(): {
4551
4652async function createEnvironment (
4753 provider : CreateEnvironmentProvider ,
48- options : CreateEnvironmentOptions = {
49- ignoreSourceControl : true ,
50- installPackages : true ,
51- } ,
54+ options : CreateEnvironmentOptions ,
5255) : Promise < CreateEnvironmentResult | undefined > {
5356 let result : CreateEnvironmentResult | undefined ;
57+ let err : unknown | undefined ;
5458 try {
55- fireStartedEvent ( ) ;
59+ fireStartedEvent ( options ) ;
5660 result = await provider . createEnvironment ( options ) ;
5761 } catch ( ex ) {
5862 if ( ex === QuickInputButtons . Back ) {
@@ -61,9 +65,10 @@ async function createEnvironment(
6165 return undefined ;
6266 }
6367 }
64- throw ex ;
68+ err = ex ;
69+ throw err ;
6570 } finally {
66- fireExitedEvent ( result ) ;
71+ fireExitedEvent ( result , options , err ) ;
6772 }
6873 return result ;
6974}
@@ -110,17 +115,28 @@ async function showCreateEnvironmentQuickPick(
110115 return undefined ;
111116}
112117
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+
113128export async function handleCreateEnvironmentCommand (
114129 providers : readonly CreateEnvironmentProvider [ ] ,
115130 options ?: CreateEnvironmentOptions ,
116131) : Promise < CreateEnvironmentResult | undefined > {
132+ const optionsWithDefaults = getOptionsWithDefaults ( options ) ;
117133 let selectedProvider : CreateEnvironmentProvider | undefined ;
118134 const envTypeStep = new MultiStepNode (
119135 undefined ,
120136 async ( context ?: MultiStepAction ) => {
121137 if ( providers . length > 0 ) {
122138 try {
123- selectedProvider = await showCreateEnvironmentQuickPick ( providers , options ) ;
139+ selectedProvider = await showCreateEnvironmentQuickPick ( providers , optionsWithDefaults ) ;
124140 } catch ( ex ) {
125141 if ( ex === MultiStepAction . Back || ex === MultiStepAction . Cancel ) {
126142 return ex ;
@@ -152,7 +168,7 @@ export async function handleCreateEnvironmentCommand(
152168 }
153169 if ( selectedProvider ) {
154170 try {
155- result = await createEnvironment ( selectedProvider , options ) ;
171+ result = await createEnvironment ( selectedProvider , optionsWithDefaults ) ;
156172 } catch ( ex ) {
157173 if ( ex === MultiStepAction . Back || ex === MultiStepAction . Cancel ) {
158174 return ex ;
0 commit comments