| 74 | ) => Thenable<DeepPartial<State>> |
| 75 | |
| 76 | export class MultiStepInput { |
| 77 | public totalSteps: number |
| 78 | public title: string |
| 79 | |
| 80 | constructor(totalSteps: number, title: string) { |
| 81 | this.totalSteps = totalSteps |
| 82 | this.title = title |
| 83 | } |
| 84 | |
| 85 | private current?: QuickInput |
| 86 | private currentStepNumber: number = 1 |
| 87 | private steps: InputStep[] = [] |
| 88 | |
| 89 | async stepThrough(steps: [InputStep], state: DeepPartial<State>) { |
| 90 | for ( |
| 91 | this.currentStepNumber = 1; |
| 92 | this.currentStepNumber <= steps.length; |
| 93 | this.currentStepNumber++ |
| 94 | ) { |
| 95 | if (this.currentStepNumber <= 0) break |
| 96 | const step = steps[this.currentStepNumber - 1] |
| 97 | if (this.current) { |
| 98 | this.current.enabled = false |
| 99 | this.current.busy = true |
| 100 | } |
| 101 | try { |
| 102 | state = await step(this, state) |
| 103 | } catch (e) { |
| 104 | if (e instanceof InputFlowAction) { |
| 105 | if (e.message) window.showErrorMessage(e.message) |
| 106 | |
| 107 | switch (e.type) { |
| 108 | case "back": |
| 109 | this.currentStepNumber -= 2 |
| 110 | break |
| 111 | case "resume": |
| 112 | this.currentStepNumber-- |
| 113 | break |
| 114 | case "cancel": |
| 115 | this.currentStepNumber = Number.POSITIVE_INFINITY |
| 116 | break |
| 117 | } |
| 118 | } else { |
| 119 | console.error(e) |
| 120 | throw e |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | if (this.current) { |
| 125 | this.current.dispose() |
| 126 | } |
| 127 | return state |
| 128 | } |
| 129 | |
| 130 | async showQuickPick<T extends QuickPickItem>(items: [T]) { |
| 131 | const disposables: Disposable[] = [] |
| 132 | try { |
| 133 | return await new Promise<T>((resolve, reject) => { |
nothing calls this directly
no outgoing calls
no test coverage detected