Write TCP server port to a tempfile instead of using env var #3452
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The strategy of passing the port to LSP reporter via environment variable is a bit weak. For example, if you reload VS Code and then proceed to run tests manually in a terminal that we set up, you will get a connection refused error because we never updated the port variable in that old terminal.
I think we can be a lot more reliable by writing the port to a file.
Implementation
Every workspace reports test results through the same port, so my idea is to write a temporary file with the port information that the LSP reporter can read on its own.
That way, every time the extension reloads, we update the port in the file and, every time the tests are executed (regardless if it's manual or through the explorer), we will read that value again ensuring that we're using the right port.
Finally, I noticed one more hurdle. When running tests manually through the terminal, we were receiving the connection okay, but there was no
run
object to use for reporting the items' statuses. We need to create arun
object on demand when not running through the explorer, otherwise the statuses won't appear as expected.