11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4+ /* eslint-disable max-classes-per-file */
5+
46'use strict' ;
57
68import { inject , injectable } from 'inversify' ;
@@ -12,11 +14,17 @@ import { IApplicationShell } from '../application/types';
1214
1315export class InputFlowAction {
1416 public static back = new InputFlowAction ( ) ;
17+
1518 public static cancel = new InputFlowAction ( ) ;
19+
1620 public static resume = new InputFlowAction ( ) ;
17- private constructor ( ) { }
21+
22+ private constructor ( ) {
23+ /** No body. */
24+ }
1825}
1926
27+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2028export type InputStep < T extends any > = ( input : MultiStepInput < T > , state : T ) => Promise < InputStep < T > | void > ;
2129
2230export interface IQuickPickParameters < T extends QuickPickItem > {
@@ -31,7 +39,6 @@ export interface IQuickPickParameters<T extends QuickPickItem> {
3139 matchOnDescription ?: boolean ;
3240 matchOnDetail ?: boolean ;
3341 acceptFilterBoxTextAsSelection ?: boolean ;
34- shouldResume ?( ) : Promise < boolean > ;
3542}
3643
3744export interface InputBoxParameters {
@@ -43,11 +50,10 @@ export interface InputBoxParameters {
4350 prompt : string ;
4451 buttons ?: QuickInputButton [ ] ;
4552 validate ( value : string ) : Promise < string | undefined > ;
46- shouldResume ?( ) : Promise < boolean > ;
4753}
4854
49- type MultiStepInputQuickPicResponseType < T , P > = T | ( P extends { buttons : ( infer I ) [ ] } ? I : never ) ;
50- type MultiStepInputInputBoxResponseType < P > = string | ( P extends { buttons : ( infer I ) [ ] } ? I : never ) ;
55+ type MultiStepInputQuickPicResponseType < T , P > = T | ( P extends { buttons : ( infer I ) [ ] } ? I : never ) | undefined ;
56+ type MultiStepInputInputBoxResponseType < P > = string | ( P extends { buttons : ( infer I ) [ ] } ? I : never ) | undefined ;
5157export interface IMultiStepInput < S > {
5258 run ( start : InputStep < S > , state : S ) : Promise < void > ;
5359 showQuickPick < T extends QuickPickItem , P extends IQuickPickParameters < T > > ( {
@@ -58,7 +64,6 @@ export interface IMultiStepInput<S> {
5864 activeItem,
5965 placeholder,
6066 buttons,
61- shouldResume,
6267 } : P ) : Promise < MultiStepInputQuickPicResponseType < T , P > > ;
6368 showInputBox < P extends InputBoxParameters > ( {
6469 title,
@@ -68,15 +73,17 @@ export interface IMultiStepInput<S> {
6873 prompt,
6974 validate,
7075 buttons,
71- shouldResume,
7276 } : P ) : Promise < MultiStepInputInputBoxResponseType < P > > ;
7377}
7478
7579export class MultiStepInput < S > implements IMultiStepInput < S > {
7680 private current ?: QuickInput ;
81+
7782 private steps : InputStep < S > [ ] = [ ] ;
83+
7884 constructor ( private readonly shell : IApplicationShell ) { }
79- public run ( start : InputStep < S > , state : S ) {
85+
86+ public run ( start : InputStep < S > , state : S ) : Promise < void > {
8087 return this . stepThrough ( start , state ) ;
8188 }
8289
@@ -88,7 +95,6 @@ export class MultiStepInput<S> implements IMultiStepInput<S> {
8895 activeItem,
8996 placeholder,
9097 buttons,
91- shouldResume,
9298 matchOnDescription,
9399 matchOnDetail,
94100 acceptFilterBoxTextAsSelection,
@@ -116,24 +122,20 @@ export class MultiStepInput<S> implements IMultiStepInput<S> {
116122 if ( item === QuickInputButtons . Back ) {
117123 reject ( InputFlowAction . back ) ;
118124 } else {
119- resolve ( < any > item ) ;
125+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
126+ resolve ( item as any ) ;
120127 }
121128 } ) ,
122129 input . onDidChangeSelection ( ( selectedItems ) => resolve ( selectedItems [ 0 ] ) ) ,
123130 input . onDidHide ( ( ) => {
124- ( async ( ) => {
125- reject (
126- shouldResume && ( await shouldResume ( ) )
127- ? InputFlowAction . resume
128- : InputFlowAction . cancel ,
129- ) ;
130- } ) ( ) . catch ( reject ) ;
131+ resolve ( undefined ) ;
131132 } ) ,
132133 ) ;
133134 if ( acceptFilterBoxTextAsSelection ) {
134135 disposables . push (
135136 input . onDidAccept ( ( ) => {
136- resolve ( < any > input . value ) ;
137+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
138+ resolve ( input . value as any ) ;
137139 } ) ,
138140 ) ;
139141 }
@@ -157,7 +159,6 @@ export class MultiStepInput<S> implements IMultiStepInput<S> {
157159 validate,
158160 password,
159161 buttons,
160- shouldResume,
161162 } : P ) : Promise < MultiStepInputInputBoxResponseType < P > > {
162163 const disposables : Disposable [ ] = [ ] ;
163164 try {
@@ -166,7 +167,7 @@ export class MultiStepInput<S> implements IMultiStepInput<S> {
166167 input . title = title ;
167168 input . step = step ;
168169 input . totalSteps = totalSteps ;
169- input . password = password ? true : false ;
170+ input . password = ! ! password ;
170171 input . value = value || '' ;
171172 input . prompt = prompt ;
172173 input . ignoreFocusOut = true ;
@@ -177,7 +178,8 @@ export class MultiStepInput<S> implements IMultiStepInput<S> {
177178 if ( item === QuickInputButtons . Back ) {
178179 reject ( InputFlowAction . back ) ;
179180 } else {
180- resolve ( < any > item ) ;
181+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
182+ resolve ( item as any ) ;
181183 }
182184 } ) ,
183185 input . onDidAccept ( async ( ) => {
@@ -199,13 +201,7 @@ export class MultiStepInput<S> implements IMultiStepInput<S> {
199201 }
200202 } ) ,
201203 input . onDidHide ( ( ) => {
202- ( async ( ) => {
203- reject (
204- shouldResume && ( await shouldResume ( ) )
205- ? InputFlowAction . resume
206- : InputFlowAction . cancel ,
207- ) ;
208- } ) ( ) . catch ( reject ) ;
204+ resolve ( undefined ) ;
209205 } ) ,
210206 ) ;
211207 if ( this . current ) {
@@ -254,6 +250,7 @@ export interface IMultiStepInputFactory {
254250@injectable ( )
255251export class MultiStepInputFactory {
256252 constructor ( @inject ( IApplicationShell ) private readonly shell : IApplicationShell ) { }
253+
257254 public create < S > ( ) : IMultiStepInput < S > {
258255 return new MultiStepInput < S > ( this . shell ) ;
259256 }
0 commit comments