Skip to content
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

Merged
merged 2 commits into from
Dec 4, 2018

Conversation

Duhemm
Copy link
Contributor

@Duhemm Duhemm commented Dec 1, 2018

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.

@Duhemm Duhemm added the area:ide label Dec 1, 2018
actualLine += 1
}
})
const _ = await vscode.workspace.applyEdit(addNewLinesEdit);
Copy link
Member

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)

@Duhemm Duhemm force-pushed the fix/worksheet-race-condition branch from cdb4c76 to ae2f513 Compare December 3, 2018 17:40
Duhemm and others added 2 commits December 3, 2018 18:44
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.
@smarter smarter force-pushed the fix/worksheet-race-condition branch from ae2f513 to 843d595 Compare December 3, 2018 17:51
@smarter
Copy link
Member

smarter commented Dec 3, 2018

@Duhemm After rebasing, this PR no longer was enough to fix the problem with multi-line output, it turns out that this is due to #5553, I've pushed a commit that should solve the issue, if you're happy with it then I'll merge this PR and make a release of vscode-dotty.

Copy link
Contributor Author

@Duhemm Duhemm left a 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.

👍 👍 👍

@smarter smarter merged commit 7e24f3f into scala:master Dec 4, 2018
@allanrenucci allanrenucci deleted the fix/worksheet-race-condition branch December 4, 2018 15:07
smarter added a commit to dotty-staging/dotty that referenced this pull request Dec 9, 2018
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.
smarter added a commit to dotty-staging/dotty that referenced this pull request Dec 10, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants