-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Test explorer: leaves open files in the LSP session following on-disk changes #2570
Comments
I think this is one of the problematic logic - vscode-go/src/goTest/explore.ts Line 261 in 7df32c8
When switching branches and noticing new files, vscode fires onDidCreateFile events. I also observed that when branch switch causes folder move or deletion, the tests under deleted folder should be removed but don't since currently the code relies on |
Relevant upstream discussion about extensions wanting to get file contents without sending didOpen notifications to language servers: microsoft/vscode#15723. The conclusion from that thread was that the API is fine as is and this is just the way the world works. The interesting thing is that we don't get see the 'didOpen' notifications in the language server for non-test files even though we called openTextDocument on those as well. Maybe its because we aren't holding on to them for long enough or it may be some way that we use the TextDocument later in the code. Edit: Right, never mind. The reason we are only seeing the didOpen is because the TestExplorer is only watching for test files. |
I think it's still a bug that the files remain open after being read, causing subsequent errors when switching branches. Furthermore, a didOpen is not a no-op for gopls: the set of open files is significant to gopls (for example, to warn about orphaned files). If we could avoid the didOpen notifications altogether, that would be ideal. |
We don't need to read the file contents at all until the file is actually open by the user and vscode fires a When initializing the tests explorer runs
Making the onDidCreateFile handler not attempt to inspect the file content is consistent with the behavior and I think that can be a short term solution to improve the stability. It looks like Test explorer needs the contents because it needs to call DocumentSymbol provider which is still partly implemented on the extension side and run the code that filters/processes document symbol results vscode-go/src/goTest/resolve.ts Line 408 in 7df32c8
testify and other popular test utilities, etc. This is actually the same code used to place the test code lenses in vscode-go.
As a long term solution, I think we need this test function identification logic to be implemented inside gopls properly. |
Change https://go.dev/cl/458999 mentions this issue: |
Change https://go.dev/cl/462376 mentions this issue: |
Change https://go.dev/cl/462376 mentions this issue: |
The Test Explorer watches all _test.go files in the workspace in order to keep the list of tests updated in the test explorer ui. On branch switches, there may be many test files that are created, causing the test explorer to process these. Previously, part of the processing resulted in opening the file. This led to issues due to the interaction with the language server. This change updates the logic on file creation, to add the parent test item only, which will not require opening the document. Fixes #2570 Change-Id: I595f34daee257c85bafd3e5706176f73f891fdf1 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/458999 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Suzy Mueller <suzmue@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/462376 Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Robert Findley <rfindley@google.com>
Just observed this behavior very reliably when testing branch switches in vscode-go:
When I switch branches, vscode-go sends a lot of didOpen notifications to gopls for test files (_test.go). This can lead to spurious "no packages for open file foo_test.go" diagnostics from gopls. Worse, switching branches again leaves the open file state, which can lead to type-checking errors as the open contents no longer compile.
Setting
"go.testExplorer.enable": false
reliably avoids these problems.The text was updated successfully, but these errors were encountered: