Callback function of vscode.workspace.onDidCloseTextDocument is working at development but not after packaging to vsix

感情迁移 提交于 2019-12-11 14:30:35

问题


In my extension, I'm opening a local file using vscode.workspace.openTextDocument and then vscode.window.showTextDocument and vscode.workspace.onDidCloseTextDocument to close the file.

This seems to be working fine if run the extension using the code.

Now I have created the vsix file using vsce package. Here comes the tricky thing

Both vscode.workspace.onDidOpenTextDocument and vscode.workspace.onDidSaveTextDocument callbacks are called as expected. However vscode.workspace.onDidCloseTextDocument callback is not called when I close the file in the UI.(I am facing this issue when the extension is installed.)

Am I missing anything?

Steps to Reproduce:

1) Open the file using vscode.workspace.openTextDocument and then vscode.window.showTextDocument.

2) Listen for events in vscode.workspace.onDidCloseTextDocument.

3) Close the file in the editor.

4) Check that vscode.workspace.onDidCloseTextDocument callback is not called as expected.

Code is present in this git repo https://github.com/akhilravuri1/hellovscode, please clone the code and create vsix package by typing vsce package command in the cmd. Install the extension using vsix file and select the hello world command then it will open a file but when you close it just closes but I expect a select option with YES or NO at command palette.

Thanks in Advance.


回答1:


I tried your extension.

I get the OnClose-event when the Welcome Screen text editor closes and ddl.txt is loaded.

The docs say you should use the vscode.window on-events but they do not allow to monitor a document close.

Very strange that the OnClose-event is fired on language change (this happens). You can't tell if it is a language change or document close.

When I open the ddl.txt with File > Open and close it I get the OnClose-event.

I get the OnClose-event on all files opened with File > Open.

It looks like files opened with vscode.workspace.openTextDocument and vscode.window.showTextDocument do not fire an OnClose-event.

You should file a bug because these calls generate a normal TextDocument.



来源:https://stackoverflow.com/questions/57498434/callback-function-of-vscode-workspace-ondidclosetextdocument-is-working-at-devel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!