0

我正在尝试添加到vscode中的扩展,现在正在尝试为我完成的代码编写测试脚本。我是 TypeScript 的新手,我所拥有的确实有效,但我只是不知道如何打开我保存并使用我编写的命令关闭的文件,然后打开文件备份并检查测试用例中的内容。

有人可以帮忙吗?

4

1 回答 1

1

我知道这个问题比较老,我希望你在此期间解决了你的问题,但你可以尝试使用你的 uri 或文件路径打开它,你将文件保存到:

import * as vscode from 'vscode';
function openDocument(uri: vscode.Uri|string): Promise<vscode.TextDocument> {
    if(typeof uri === "string")
        uri = vscode.Uri.parse(uri);
   return await vscode.workspace.openTextDocument(uri as vscode.Uri);
}

然后你可以得到文档上的文本:

let mydoc = await openDocument("file:///c:/myuser/myfolder/myfile.txt");
let text = mydoc.getText();
于 2016-11-28T07:21:01.933 回答