vscode: showTextDocument returned the wrong editor when called multiple times concurrently
It seems like there may be some race condition in showTextDocument where if it’s called multiple times before the previous has completed, each call returns the last editor to be opened.
Here I have an array of two items short_test.dart and short2_test.dart and I call openTextDocument and showTextDocument for each. However the resulting editors both point at short2_test.dart:
The results from openTextDocument are correct in both cases, it’s only showTextDocument that seems to be misbehaving.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (17 by maintainers)
Commits related to this issue
- editors - return `undefined` from `openEditor` when operation cancelled (fix #134786) — committed to microsoft/vscode by bpasero 3 years ago
I pushed a change to return
undefinedwhenopenEditoroperation is cancelled by another operation.Given the sample code in this issue, I see that we now throw an exception back to the extension:
Originating from:
https://github.com/microsoft/vscode/blob/f523f65f3985eb6493cae5d219de35f1d7ba6f7a/src/vs/workbench/api/common/extHostTextEditors.ts#L91
I suppose extensions had to deal with this error before already as it is not a new error, but it may appear now in more cases.
Yeah, I tried that one first too, but it also worked (did the thing I wanted, without exceptions). I don’t know if that really verifies the fix or not though, but I certainly can’t reproduce any bug now 😃
I think an easier fix that doesn’t involve overloads is to simply return
undefinedwhen we detect that theopenEditorcall was cancelled. Since we already spec it that way, callers should be able to handle that.Pushing to November though to get this out in debt week given it may still break something.