【问题标题】:Editor extension onDidCloseTerminal() causes editor to freeze编辑器扩展 onDidCloseTerminal() 导致编辑器冻结
【发布时间】:2020-11-15 12:49:48
【问题描述】:

我正在尝试为 vscode 编写扩展程序,并且我正在尝试处理终端的关闭,但是每当我单击终端上的垃圾箱以删除终端时,编辑器就会冻结。这是我处理编辑器关闭方式的方式。我是不是做错了什么?

我有多个终端,我正在打开一个未命名为 Server Terminal 的终端,它被称为 Add Package,因此它不会进入 if 语句,这正是我在这种情况下想要的。那么,是什么导致编辑器卡住了呢?我尝试添加else { t.dispose() },但编辑器仍然冻结。

export function activate(context: ExtensionContext) {
    window.onDidCloseTerminal(t => {
        // Watch for when the server terminal closes.
        if (t.name === 'Server Terminal') {
            Serve.server = undefined
            showMessage(`The server has been stopped on "http://${Serve.host}:${Serve.port}"`)
        }
    })
}

【问题讨论】:

  • 如果您使用的是 Windows 操作系统,则存在一个已知错误 github.com/microsoft/vscode/issues/76548
  • 我实际上找到了造成这种情况的原因。我能够通过在回调中终止在终端中运行的进程来阻止这种情况的发生
  • 通过这样做,似乎可以解决问题:const id = await terminal.processId; id && kill(id)

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


【解决方案1】:

所以,对我来说,似乎要解决这个问题我需要先手动终止进程,然后我可以将Serve.server 设置为undefined。这似乎解决了编辑器冻结的问题:

window.onDidCloseTerminal(async t => {
    // Watch for when the server terminal closes.
    if (t.name === 'Server Terminal') {
        const id = await t.processId 
        id && kill(id)
        Serve.server = undefined
    }
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    相关资源
    最近更新 更多