@@ -52,22 +52,13 @@ interface State {
5252 action ?: StartWorkAction ;
5353}
5454
55- type StartWorkStepState < T extends State = State > = RequireSome < StepState < T > , 'item' > ;
56-
5755export type StartWorkAction = 'start' ;
5856
5957export interface StartWorkCommandArgs {
6058 readonly command : 'startWork' ;
6159 source ?: Sources ;
6260}
6361
64- function assertsStartWorkStepState ( state : StepState < State > ) : asserts state is StartWorkStepState {
65- if ( state . item != null ) return ;
66-
67- debugger ;
68- throw new Error ( 'Missing item' ) ;
69- }
70-
7162export const supportedStartWorkIntegrations = [ HostingIntegrationId . GitHub ] ;
7263const instanceCounter = getScopedCounter ( ) ;
7364
@@ -128,47 +119,69 @@ export class StartWorkCommand extends QuickCommand<State> {
128119 }
129120 }
130121
131- await updateContextItems ( this . container , context ) ;
122+ if ( state . counter < 1 ) {
123+ const result = yield * this . selectCommandStep ( state ) ;
124+ if ( result === StepResultBreak ) continue ;
125+ state . action = result . action ;
126+ }
132127
133- if ( state . counter < 1 || state . item == null ) {
128+ if ( state . counter < 2 && ! state . action ) {
129+ await updateContextItems ( this . container , context ) ;
134130 const result = yield * this . pickIssueStep ( state , context ) ;
135131 if ( result === StepResultBreak ) continue ;
136132 state . item = result ;
133+ state . action = 'start' ;
137134 }
138135
139- assertsStartWorkStepState ( state ) ;
140- state . action = 'start' ;
141-
142- const issue = state . item . item . issue ;
143- const repo = await getOrOpenIssueRepository ( this . container , issue ) ;
136+ const issue = state . item ?. item ?. issue ;
137+ const repo = issue && ( await getOrOpenIssueRepository ( this . container , issue ) ) ;
144138
145139 if ( typeof state . action === 'string' ) {
146140 switch ( state . action ) {
147- case 'start' :
148- yield * getSteps (
141+ case 'start' : {
142+ const result = yield * getSteps (
149143 this . container ,
150144 {
151145 command : 'branch' ,
152146 state : {
153147 subcommand : 'create' ,
154148 repo : repo ,
155- name : slug ( `${ issue . id } -${ issue . title } ` ) ,
149+ name : issue ? slug ( `${ issue . id } -${ issue . title } ` ) : undefined ,
156150 suggestNameOnly : true ,
157151 suggestRepoOnly : true ,
158152 } ,
159153 } ,
160154 this . pickedVia ,
161155 ) ;
156+ if ( result === StepResultBreak ) {
157+ endSteps ( state ) ;
158+ } else {
159+ state . counter -- ;
160+ state . action = undefined ;
161+ }
162162 break ;
163+ }
163164 }
164165 }
165-
166- endSteps ( state ) ;
167166 }
168167
169168 return state . counter < 0 ? StepResultBreak : undefined ;
170169 }
171170
171+ private * selectCommandStep ( state : StepState < State > ) : StepResultGenerator < { action ?: StartWorkAction } > {
172+ const step = createPickStep ( {
173+ placeholder : 'Start work by creating a new branch' ,
174+ items : [
175+ createQuickPickItemOfT ( 'Create a Branch' , {
176+ action : 'start' ,
177+ } ) ,
178+ createQuickPickItemOfT ( 'Create a Branch from an Issue' , { } ) ,
179+ ] ,
180+ } ) ;
181+ const selection : StepSelection < typeof step > = yield step ;
182+ return canPickStepContinue ( step , state , selection ) ? selection [ 0 ] . item : StepResultBreak ;
183+ }
184+
172185 private async * confirmLocalIntegrationConnectStep (
173186 state : StepState < State > ,
174187 context : Context ,
0 commit comments