0
我正在監聽onWillSaveTextDocument
並獲取用於文件內容和文件路徑信息的vscode.TextDocument
實例。vscode - 有沒有辦法創建`vscode.TextDocument`的實例?
只需創建此對象的新實例,而不是重新創建文件路徑中的所有信息將會很方便。
我希望能有這樣的:
const document = new TextDocument(myFilePath);
我正在監聽onWillSaveTextDocument
並獲取用於文件內容和文件路徑信息的vscode.TextDocument
實例。vscode - 有沒有辦法創建`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。
我擔心這實際上會在編輯器中打開該文件,但事實並非如此。它的工作方式完全如我所願。謝謝!太棒了。 :) –