2016-06-10 26 views
0

我想添加到vscode的擴展中,現在正在嘗試爲我完成的代碼編寫測試腳本。我是新來的TypeScript和我的工作,但我只是不知道如何打開一個文件,我保存&用我寫的命令關閉,然後打開文件備份並檢查測試用例中的內容。在VSCode中測試文件的內容TypeScript

有人可以幫忙嗎?

回答

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(); 
相關問題