如何在 VS Code 中关闭 TextDocument?

How to close TextDocument in VS Code?

我正在写 vscode 扩展。

我用 vscode.window.showTextDocument 打开了一个 TextDocument,想稍后关闭它。但是我找不到 api 来关闭它。最后我找到了 this commit,它删除了 closeTextDocument。我现在该怎么办?

我遇到了同样的问题。我设法做到这一点的唯一方法是通过 workbench.action.closeActiveEditor,正如 TextEditor.hide 的内联文档所推荐的那样。

这很黑 - 基本上是在编辑器中显示文档,然后关闭活动编辑器:

vscode.window.showTextDocument(entry.uri, {preview: true, preserveFocus: false})
    .then(() => {
        return vscode.commands.executeCommand('workbench.action.closeActiveEditor');
    });