vscode - 有没有办法创建 `vscode.TextDocument` 的实例?

vscode - Is there a way to create an instance of `vscode.TextDocument`?

我正在侦听 onWillSaveTextDocument 并获取 vscode.TextDocument 的实例,我将其用于文件内容和文件路径信息。

创建此对象的新实例会很方便,而不是从文件路径重新创建所有信息。

我希望有这样的东西:

const document = new TextDocument(myFilePath);

您可以简单地使用 vscode.workspace.openTextDocument 方法来创建 TextDocument 实例。

例如:

    vscode.workspace.openTextDocument( {
        language: 'text'
    } )
    .then( doc => {
        // Do something useful with the document.
    });

如果您想在上下文中使用它,请随时查看 this part of code