【问题标题】:How to show a yes / no dialog from vs code extension api如何从 vs 代码扩展 api 显示是/否对话框
【发布时间】:2020-12-25 14:41:41
【问题描述】:

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

【问题讨论】:

  • 使用信息消息,您可以添加按钮,这些按钮将是 Thenable showInformationMessage() 的结果
  • @LexLi 链接已损坏
  • @Ani 原始文档可以在code.visualstudio.com/api/references/… 中找到示例代码可以在 GitHub 代码搜索中找到(因为那里托管了很多扩展)。

标签: visual-studio-code vscode-extensions


【解决方案1】:

似乎您正在寻找vscode.window.showInformationMessage 女巫需要两个参数message...items(有关更多信息,请参阅API reference。可以在此示例中使用:

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

【讨论】:

    猜你喜欢
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    相关资源
    最近更新 更多