How to show a yes / no dialog from vs code extension api

Viewed 2415

I am developing a extension in vscode and at some point i need to ask confirmation from user for some code action.
I would like to prompt a dialog and get either yes or now, i am not able to find any method like confirm or alert in vscode api Can you some one help

1 Answers

Seems like you're looking for vscode.window.showInformationMessage witch takes two parameters message and ...items (for more info see API reference. Can be used as in this example:

vscode.window
  .showInformationMessage("Do you want to do this?", "Yes", "No")
  .then(answer => {
    if (answer === "Yes") {
      // Run function
    }
  })
Related