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 some edge cases in shell integration conpty handling #145346

Merged
merged 1 commit into from
Mar 17, 2022
Merged

Conversation

Tyriar
Copy link
Member

@Tyriar Tyriar commented Mar 17, 2022

This starts to listen for cursor moves on the next frame to avoid listening when
the cursor is on the wrong line (if conpty renders the sequence in the wrong spot).
There is also some handling for when that handler doesn't trigger before command
finished does.

Fixes #143894


This fix seems pretty reliable, the only place I could break it is rarely this would happen for skipped commands:

image

Typed commands seemed to pretty much always work.

This starts to listen for cursor moves on the next frame to avoid listening when
the cursor is on the wrong line (if conpty renders the sequence in the wrong spot).
There is also some handling for when that handler doesn't trigger before command
finished does.

Fixes #143894
@Tyriar Tyriar added this to the March 2022 milestone Mar 17, 2022
@Tyriar Tyriar requested a review from meganrogge March 17, 2022 19:25
@Tyriar Tyriar self-assigned this Mar 17, 2022
// HACK: Fire command started on the following frame on Windows to allow the cursor
// position to update as conpty often prints the sequence on a different line to the
// actual line the command started on.
timeout(0).then(() => {
if (!this._currentCommand.commandExecutedMarker) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if conpty does fire command started for the actual line it was started on, are there any consequences of this happening again?

I think we dispose of the placeholder decoration every time register decoration is called, which should prevent duplicates

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only want to listen to cursor moves between start and executed, doing it outside that would be a waste as we wouldn't use it.

if (this._commandMarkers.length === 0) {
// If the command start timeout doesn't happen before command finished, just use the
// current marker.
if (!this._currentCommand.commandStartMarker) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the timeout is 0, when will this happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may happen when running a command while another is running, I don't think it does in practice currently due to event loop related things in node-pty/conpty where data but it might and could in the future.

@Tyriar Tyriar merged commit 3d05a39 into main Mar 17, 2022
@Tyriar Tyriar deleted the tyriar/143894 branch March 17, 2022 20:18
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command decorations after starting are moving up incorrectly
2 participants