| 167 | } |
| 168 | |
| 169 | class MultiStepInput { |
| 170 | |
| 171 | static async run(start: InputStep) { |
| 172 | const input = new MultiStepInput(); |
| 173 | return input.stepThrough(start); |
| 174 | } |
| 175 | |
| 176 | private current?: QuickInput; |
| 177 | private steps: InputStep[] = []; |
| 178 | |
| 179 | private async stepThrough(start: InputStep) { |
| 180 | let step: InputStep | void = start; |
| 181 | while (step) { |
| 182 | this.steps.push(step); |
| 183 | if (this.current) { |
| 184 | this.current.enabled = false; |
| 185 | this.current.busy = true; |
| 186 | } |
| 187 | try { |
| 188 | step = await step(this); |
| 189 | } catch (err) { |
| 190 | if (err === InputFlowAction.back) { |
| 191 | this.steps.pop(); |
| 192 | step = this.steps.pop(); |
| 193 | } else if (err === InputFlowAction.resume) { |
| 194 | step = this.steps.pop(); |
| 195 | } else if (err === InputFlowAction.cancel) { |
| 196 | step = undefined; |
| 197 | } else { |
| 198 | throw err; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | if (this.current) { |
| 203 | this.current.dispose(); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | async showQuickPick<T extends QuickPickItem, P extends QuickPickParameters<T>>({ title, step, totalSteps, items, activeItem, ignoreFocusOut, placeholder, buttons, shouldResume }: P) { |
| 208 | const disposables: Disposable[] = []; |
| 209 | try { |
| 210 | return await new Promise<T | (P extends { buttons: (infer I)[] } ? I : never)>((resolve, reject) => { |
| 211 | const input = window.createQuickPick<T>(); |
| 212 | input.title = title; |
| 213 | input.step = step; |
| 214 | input.totalSteps = totalSteps; |
| 215 | input.ignoreFocusOut = ignoreFocusOut ?? false; |
| 216 | input.placeholder = placeholder; |
| 217 | input.items = items; |
| 218 | if (activeItem) { |
| 219 | input.activeItems = [activeItem]; |
| 220 | } |
| 221 | input.buttons = [ |
| 222 | ...(this.steps.length > 1 ? [QuickInputButtons.Back] : []), |
| 223 | ...(buttons || []) |
| 224 | ]; |
| 225 | disposables.push( |
| 226 | input.onDidTriggerButton(item => { |
nothing calls this directly
no outgoing calls
no test coverage detected