如何从 VS Code 扩展 api 显示是/否对话框

Gan*_*y M 8 visual-studio-code vscode-extensions

我正在 vscode 中开发一个扩展,有时我需要请求用户确认某些代码操作。
我想提示一个对话框并得到“是”或“现在”,我无法在 vscode api 中找到任何类似确认或警报的方法,您可以帮忙吗

the*_*itz 18

似乎您正在寻找vscode.window.showInformationMessage需要两个参数的 witchmessage...items(有关更多信息,请参阅API 参考)。可以像本例中那样使用:

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