-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Bug: documents opened by EH: vscode.workspace.openTextDocument() are not disposed correctly #291739
Description
- VS Code Version: 1.108.2
- OS Version: Windows 11
This was noticed by the fact that diagnostic entries of the file being closed doesn't get removed from Problems View, if a file was opened from extension by vscode.workspace.openTextDocument(), which differs from opening files from Explorer panel, in which case diagnostic entries are removed on file close.
Reproduction steps:
- Open a file which contains problems, using
vscode.workspace.openTextDocument()call from extension - Ensure that problems appear in Problems View
- Close file
- Observe that diagnostics remains in Problems View
- Additionally, if you give VS Code several minutes to idle, at some point it triggers resource cleanup, removing giagnostics from Problems View unexpectedly
Also, when using a watcher task with problems matcher, diagnostics does not get replaced by task's diagnostics outputs when file is closed.
Not necessarily, you can check the video I have posted in #256118 (comment) to demonstrate diagnostics vanishing (ignore that there I blame getDiagnostics() for this, since now it is clear that the source is different). Another place I mention this issue is #290278 (comment)
I tried to fix it and found something, but I'm not sure how to complete it. Here are my results
- First, I have found that for the file opened from EH, ModelService.onModelRemoved is not fired on close
- The reason for this turned out to be that the
reference.counterof model equals2when the dispose is called on close, and that differs for the files opened from Explorer panel, which is1in that case - Found that, what adds additional reference, is ExtHostDocuments._proxy.$tryOpenDocument, which end up here const ref = await this._textModelResolverService.createModelReference(uri); and is seems that it doesn't get disposed on close
- I have tested what if I reduce counter by 1 manually for the file opened from EH. It gets disposed then, and diagnostics removed from Problems View as it should, but diagnostics does not get replaced by running task's problem matcher outputs