[VS Code] Code suggestion streaming causes Undo to not work afterwards
Checklist
-
I'm using the latest version of the extension (see the latest version in the right column of this page) - Extension version: Put your extension version here
-
I'm using the latest VS Code version (find the latest version here) - VS Code version: Put your VS Code version here
-
I'm using a supported version of GitLab (see README for the supported version) - GitLab version: Put your GitLab version here, or say "happens on
gitlab.com"
- GitLab version: Put your GitLab version here, or say "happens on
Summary
Note - this has been an issue since the introduction of streaming, around %17.0.
Code suggestion streaming (aka code generation) involves repeatedly triggering no-op edits on the page to cause VS Code to fire off multiple inline suggestion events in succession.
This no-op edit fills up the undo history with multiple edits (that do nothing), leaving the user unable to use the 'Undo' functionality easily. They need to hit undo enough times to go back over all of the no-op edit events - something like 10-20 times for a medium sized code generation result.
Thanks @elwyn-gitlab for the idea during a sync discussion.
Steps to reproduce
- Open a file with GitLab Workflow enabled and set up.
- Trigger a code generation (e.g. pressing Return after a comment)
- Wait for the result to finish streaming.
- Do not accept the suggestion (optional, but makes the result clearer).
- Press 'Undo' (e.g. "Cmd + Z") multiple times.
What is the current bug behavior?
Nothing happens, until the user presses Undo as many times as there were individual 'chunks' loading in during the streaming process.
What is the expected correct behavior?
The last text change performed by the user is undone.
Relevant logs and/or screenshots
Possible fixes
The code here is responsible:
// forceTriggerInlineCompletion
const prevCharPosition = document.positionAt(activeOffset - 1);
const replaceRange = new vscode.Range(prevCharPosition, activePosition);
const value = document.getText(replaceRange);
await editor.edit(edit => edit.replace(replaceRange, value));