@@ -57,22 +57,13 @@ interface State {
5757 action ?: StartWorkAction ;
5858}
5959
60- type StartWorkStepState < T extends State = State > = RequireSome < StepState < T > , 'item' > ;
61-
6260export type StartWorkAction = 'start' ;
6361
6462export interface StartWorkCommandArgs {
6563 readonly command : 'startWork' ;
6664 source ?: Sources ;
6765}
6866
69- function assertsStartWorkStepState ( state : StepState < State > ) : asserts state is StartWorkStepState {
70- if ( state . item != null ) return ;
71-
72- debugger ;
73- throw new Error ( 'Missing item' ) ;
74- }
75-
7667export const supportedStartWorkIntegrations = [ HostingIntegrationId . GitHub ] ;
7768const instanceCounter = getScopedCounter ( ) ;
7869
@@ -133,47 +124,69 @@ export class StartWorkCommand extends QuickCommand<State> {
133124 }
134125 }
135126
136- await updateContextItems ( this . container , context ) ;
127+ if ( state . counter < 1 ) {
128+ const result = yield * this . selectCommandStep ( state ) ;
129+ if ( result === StepResultBreak ) continue ;
130+ state . action = result . action ;
131+ }
137132
138- if ( state . counter < 1 || state . item == null ) {
133+ if ( state . counter < 2 && ! state . action ) {
134+ await updateContextItems ( this . container , context ) ;
139135 const result = yield * this . pickIssueStep ( state , context ) ;
140136 if ( result === StepResultBreak ) continue ;
141137 state . item = result ;
138+ state . action = 'start' ;
142139 }
143140
144- assertsStartWorkStepState ( state ) ;
145- state . action = 'start' ;
146-
147- const issue = state . item . item . issue ;
148- const repo = await getOrOpenIssueRepository ( this . container , issue ) ;
141+ const issue = state . item ?. item ?. issue ;
142+ const repo = issue && ( await getOrOpenIssueRepository ( this . container , issue ) ) ;
149143
150144 if ( typeof state . action === 'string' ) {
151145 switch ( state . action ) {
152- case 'start' :
153- yield * getSteps (
146+ case 'start' : {
147+ const result = yield * getSteps (
154148 this . container ,
155149 {
156150 command : 'branch' ,
157151 state : {
158152 subcommand : 'create' ,
159153 repo : repo ,
160- name : slug ( `${ issue . id } -${ issue . title } ` ) ,
154+ name : issue ? slug ( `${ issue . id } -${ issue . title } ` ) : undefined ,
161155 suggestNameOnly : true ,
162156 suggestRepoOnly : true ,
163157 } ,
164158 } ,
165159 this . pickedVia ,
166160 ) ;
161+ if ( result === StepResultBreak ) {
162+ endSteps ( state ) ;
163+ } else {
164+ state . counter -- ;
165+ state . action = undefined ;
166+ }
167167 break ;
168+ }
168169 }
169170 }
170-
171- endSteps ( state ) ;
172171 }
173172
174173 return state . counter < 0 ? StepResultBreak : undefined ;
175174 }
176175
176+ private * selectCommandStep ( state : StepState < State > ) : StepResultGenerator < { action ?: StartWorkAction } > {
177+ const step = createPickStep ( {
178+ placeholder : 'Start work by creating a new branch' ,
179+ items : [
180+ createQuickPickItemOfT ( 'Create a branch' , {
181+ action : 'start' ,
182+ } ) ,
183+ createQuickPickItemOfT ( 'Create a branch from an issue' , { } ) ,
184+ ] ,
185+ } ) ;
186+ const selection : StepSelection < typeof step > = yield step ;
187+ return canPickStepContinue ( step , state , selection ) ? selection [ 0 ] . item : StepResultBreak ;
188+ }
189+
177190 private async * confirmLocalIntegrationConnectStep (
178191 state : StepState < State > ,
179192 context : Context ,
0 commit comments