2017-03-09 53 views
0

我正在workspace.onWillSaveTextDocument处理程序上运行回调。它提供了vscode.TextDocument,这对于我想在这个活动中做的工作是必要的。vscode - 有没有办法手动触发事件?

在某些情况下,我想将其他文件(当前未打开)视为它们刚刚被保存。

只要创建一个新的vscode.TextDocument实例就足够了,但我无法弄清楚。

有没有办法做这样的事情:

workspace.pretendThisWasSavedJustNow('/path/to/other/file.ts'); 

回答

1

我对VSCode工作,虽然我不知道你的确切使用情况下,我相信你正在寻找workspace.openTextDocument

要使用相同的功能workspace.onWillSaveTextDocument和您的扩展触发一些其他事件,你可以试试:

// Actual save 
workspace.onWillSaveTextDocument(e => onDocumentSave(e.document)) 

// Emulated save 
setInterval(() => { 
    workspace.openTextDocument('path/to/other/file.ts') 
     .then(document => onDocumentSave(document)) 
}, 5000) 

// Common save handling implementation 
function onDocumentSave(document: TextDocument) { ... } 
相关问题