【问题标题】:"rejected promise not handled within 1 second" vscode API“拒绝承诺未在 1 秒内处理” vscode API
【发布时间】:2019-07-08 12:22:54
【问题描述】:

所以我一直在开发我的第一个 vscode 扩展,一切都很顺利,直到调试器停止执行我的扩展。

我对 javascript 还很陌生,所以也许我在“thenables”上遗漏了一些东西,但这是我的问题。

我使用键盘快捷键运行我的扩展程序,例如。 "ctrl + alt + o" 运行良好,但是当我更改 "activeTextEditor" 时,我得到 "rejected promise nothanded in 1 seconds ”在我的调试控制台中。

可疑部分是这样的:

    const checkOutHeader = (history) => {
    console.log("Path: checkOutHeader");
    activeTextEditor.edit((editor) => {
        editor.replace(new vscode.Range(0,0,10,100), commentHeader(
            populateCheckOutHeader(head.out, history).substring(1), languageId));
    }).then((none)=>{
        console.log("We are here!");
        saveFile();
    });
};

这是基于我的扩展在调试控制台中记录的路径:

CheckoutHeader: Now active!
Path: getHeaderConfig
lang: makefile
Path: supportHeaderLanguage
Path: checkInHandler
Path: getCurrentHeader
Path: getHistoryFileStatus
Path: getHeaderHistory
Path: getHistoryFileName
Path: getHistoryFileStatus
Path: getHistoryTimeIn
Path: getHistoryInBy
Path: getHistoryTimeOut
Path: getHistoryOutBy
Path: checkInHeader
rejected promise not handled within 1 second

我读到有人声称它是 c++tools,但我没有安装该扩展。

谢谢!

【问题讨论】:

  • 你可能在then(之后需要catch((e) =>
  • 哪个 promise 被拒绝了,错误信息是什么?
  • @jcbuic 我试过了,但似乎没有用。
  • @Bergi 我不知道它只说“拒绝承诺未在 1 秒内处理”
  • @Bergi,感谢您的建议,我花了一些时间寻找答案,发现很多人遇到此问题,随机出现此错误,许多人已经报告了它。感谢您尝试提供帮助。

标签: javascript api visual-studio-code vscode-extensions


【解决方案1】:

事实证明,尽管有调试反馈,但承诺从来都不是问题。

我在文件顶部设置了全局变量

const activeTextEditor = vscode.window.activeTextEditor;
const document = activeTextEditor.document;
const languageId = document.languageId;

为了更方便地访问 API,但由于它们仅在我第一次运行扩展程序时才会启动,每当我更改“activeTextEditor”时,该变量仍将包含旧信息导致崩溃..

【讨论】:

    猜你喜欢
    • 2018-10-11
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多