【问题标题】:vscode - Is there a way to create an instance of `vscode.TextDocument`?vscode - 有没有办法创建 `vscode.TextDocument` 的实例?
【发布时间】:2017-03-09 20:29:26
【问题描述】:

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

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

我希望有类似的东西:

const document = new TextDocument(myFilePath);

【问题讨论】:

    标签: visual-studio-code vscode-extensions


    【解决方案1】:

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

    一个例子是:

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

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

    【讨论】:

    • 我担心这实际上会在编辑器中打开文件,但事实并非如此。它完全按照我希望的方式工作。谢谢!太棒了。 :)
    猜你喜欢
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    相关资源
    最近更新 更多