Eri*_*ase 8 typescript visual-studio-code vscode-extensions
我刚刚开始学习vscode扩展,我想知道是否有一种简单的方法以编程方式关闭通过生成的信息消息框vscode.window.showInformationMessage()
.如果你想重现,我在这里开始使用WordCount演示,在复制/粘贴后extension.ts
,如教程中所述,我做了一些修改,activate()
就像这样......
export function activate(context: ExtensionContext) {
let wordCounter = new WordCounter();
let wcTimeout = null;
let setWCTimeout = function() {
clearWCTimeout();
wcTimeout = setTimeout(clearWCTimeout, 1000);
};
let clearWCTimeout = function() {
if (wcTimeout !== null) {
clearTimeout(wcTimeout);
wcTimeout = null;
// clear/hide the message box here, but how?
}
};
let disposable = commands.registerCommand('extension.sayHello', () => {
wordCounter.updateWordCount();
setWCTimeout();
vscode.window
.showInformationMessage(wordCounter._getWordCount(window.activeTextEditor.document).toString())
.then(clearWCTimeout);
});
// Add to a list of disposables which are disposed when this extension is deactivated.
context.subscriptions.push(wordCounter);
context.subscriptions.push(wcTimeout);
context.subscriptions.push(disposable);
}
Run Code Online (Sandbox Code Playgroud)
我尝试或考虑过的:
vscode.window.showInformationMessage()
使用both null
和空字符串调用- 什么都不做,除了null
空字符串之外的任何内容都会导致出现新的信息消息框附注:我很感兴趣,在这种模式中的最佳实践.例如,是否有一个流行的节点库包装了我可能想要考虑使用的js计时器?但是,这不是我对这篇文章的主要关注.如果你要评论延迟机制(setTimeout()/clearTimeout()
),请在这个环境/范例中的最佳实践(超出"那个丑陋的"或"那不是[你个人]会这样做")的建设性.
K. *_*bol 13
尽管该消息似乎没有显式关闭 API ( https://github.com/Microsoft/vscode/issues/2732 ),但我的解决方法是使用进度来模拟自动关闭通知:
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: 'Finding ...',
cancellable: false,
},
async (progress, token) => {
for (let i = 0; i < 10; i++) {
setTimeout(() => {
progress.report({ increment: i*10, message: title })
}, 10000)
}
}
)
Run Code Online (Sandbox Code Playgroud)
目前还不可能.
在github上针对vscode提出了一个相关问题:https://github.com/Microsoft/vscode/issues/2732
在不允许关闭信息消息的响应中给出的推理是"他们的意图是用户必须对它们作出反应".
建议使用状态栏查看需要更新/关闭的消息作为推荐方法.
归档时间: |
|
查看次数: |
1133 次 |
最近记录: |