gpt4 book ai didi

typescript - 如何在 vscode 中实现忙碌指示器?

转载 作者:搜寻专家 更新时间:2023-10-30 21:39:57 25 4
gpt4 key购买 nike

对于长时间运行的进程,我想在 Visual Studio Code 中显示一个忙碌指示器。拥有类似 typescript 扩展使用的东西就已经足够了:

enter image description here

然而,使用正常的状态栏项目并没有像预期的那样工作。我什至无法在开始操作之前立即显示该项目,因为它似乎需要将控制权返回给 vscode。

我试过的是这样的:

...
busyIndicator = window.createStatusBarItem(StatusBarAlignment.Left, 1000);
busyIndicator.text = "##";
busyIndicator.show();

...

workspace.onDidSaveTextDocument((doc: TextDocument) => {
if (doc.languageId === "antlr") {
//busyIndicator.show();
busyIndicator.text = "X";
let tempPath = Utils.createTempFolder();
let result = backend.generate(doc.fileName, { outputDir: tempPath, listeners: false, visitors: false });
Utils.deleteFolderRecursive(tempPath);
//busyIndicator.hide();
busyIndicator.text = "Y";
}
});

值 X 永远不会显示,Y 在操作结束时出现(如预期)。如果连简单的文本更新都不起作用,我怎么能显示动画呢?

最佳答案

我无法弄清楚何时添加了对在状态栏中使用 withProgress 的支持,但我今天可以执行以下操作。

编辑 我发现添加对此的支持时是 2017 年 4 月。请参阅 vscode 发行说明 here

 vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
cancellable: false,
title: 'Loading customers'
}, async (progress) => {

progress.report({ increment: 0 });

await Promise.resolve();

progress.report({ increment: 100 });
});

在下图中查看它的实际效果

gif

关于typescript - 如何在 vscode 中实现忙碌指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43695200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com