aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.52k stars 443 forks source link

arch(wizards): support async bindPrompter functions (ContextOptions) #6094

Open justinmk3 opened 5 hours ago

justinmk3 commented 5 hours ago

Problem

  1. showWhen clause does not support async function provider for operation like file lookup (skip prompter)
  2. setDefault in both ContextOptions and FormElement support async function provider

Background: historically the ContextOptions functions were non-async because they are called in constructors. But now that we have async init() (example) as an "async" way to construct Wizards, the door is open to support async variants of these wizard ContextOptions.

Expected behavior

Support async variants of the ContextOptions functions:

  1. change their signatures to optionally return a Promise. example:
    showWhen?: (state: WizardState<TState>) => boolean | Promise<boolean>
  2. in the Wizard / prompter base class(es), check if (result instanceof Promise) (example) to decide how to handle the async variants:
    • if async, require that init() is used to construct the Wizard. It is an error to define async ContextOptions on a wizard that calls bindPrompter in its constructor (where async functions cannot be awaited).
  3. await the functions inf bindPrompter

Note

This is just a proposal. If it turns out that bindPrompter can safely accept async ContextOptions functions that can be await'd just-in-time when the Wizard is run, then we can more easily support this without needing to care about "regular constructor vs init()".