-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix race condition in worksheet output #5552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition in worksheet output #5552
Conversation
vscode-dotty/src/worksheet.ts
Outdated
actualLine += 1 | ||
} | ||
}) | ||
const _ = await vscode.workspace.applyEdit(addNewLinesEdit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will actually create a value named _
, I think you can just do await vscode.workspace.applyEdit(addNewLinesEdit)
cdb4c76
to
ae2f513
Compare
Sometimes, the `ApplyEdits` that we use in the worksheet to insert blank lines so that the worksheet output fits were reordered. The lead to some output of the worksheet being lost, with decorations being inserted after the end of the file. We know keep track of the edits that we want to apply to the worksheet and ensure that they are executed in the same order as the messages were received.
In 23785e6, we moved worksheet.run() from didSave to willSave since didSave is not called when the document is not dirty, unfortunately this gives the wrong behavior when the document _is_ dirty: it means we're going to send a run worksheet request to the server before the server has seen all the changes to the document, in particular with multi-line output this means that the server will see the output with the added empty lines, which means the line numbers in worksheet/publishOutput will be wrong. To avoid this issue we now run the worksheet either on willSave or didSave depending on whether the document is dirty or not. To reproduce the issue, you can create a worksheet with: ``` val x = """ """ "hi" ``` in it, then save the document multiple times.
ae2f513
to
843d595
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're going to send a run worksheet
request to the server before the server has seen all the changes to the
document, in particular with multi-line output this means that the
server will see the output with the added empty lines, which means the
line numbers in worksheet/publishOutput will be wrong.
👍 👍 👍
Even after scala#5552 there were still situations were the worksheet output was not displayed properly due to all the complications needed to handle multi-line output. Getting this right seems hopeless until vscode gets some better API (microsoft/vscode#63600), so instead in this commit we avoid the problem by only displaying the first line of multi-line output. The complete output is still available by hovering over the decoration which should be good enough.
Even after scala#5552 there were still situations were the worksheet output was not displayed properly due to all the complications needed to handle multi-line output. Getting this right seems hopeless until vscode gets some better API (microsoft/vscode#63600), so instead in this commit we avoid the problem by only displaying the first line of multi-line output. The complete output is still available by hovering over the decoration which should be good enough.
Sometimes, the
ApplyEdits
that we use in the worksheet to insert blanklines so that the worksheet output fits were reordered. The lead to some
output of the worksheet being lost, with decorations being inserted
after the end of the file.
We know keep track of the edits that we want to apply to the worksheet
and ensure that they are executed in the same order as the messages were
received.