Skip to content

Commit 45ad77c

Browse files
authored
don't re-show the inline chat widget on each progress chunk (microsoft#196596)
fixes microsoft#196562 fixes microsoft/vscode-copilot#2288
1 parent 8c01863 commit 45ad77c

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,21 @@ export class InlineChatController implements IEditorContribution {
239239
private _showWidget(initialRender: boolean = false, position?: Position) {
240240
assertType(this._editor.hasModel());
241241

242-
let widgetPosition = position
243-
?? this._zone.value.position
244-
?? this._editor.getSelection().getStartPosition().delta(-1);
242+
let widgetPosition: Position;
243+
if (position) {
244+
// explicit position wins
245+
widgetPosition = position;
246+
} else if (this._zone.value.position) {
247+
// already showing - special case of line 1
248+
if (this._zone.value.position.lineNumber === 1) {
249+
widgetPosition = this._zone.value.position.delta(-1);
250+
} else {
251+
widgetPosition = this._zone.value.position;
252+
}
253+
} else {
254+
// default to ABOVE the selection
255+
widgetPosition = this._editor.getSelection().getStartPosition().delta(-1);
256+
}
245257

246258
let needsMargin = false;
247259
if (initialRender) {
@@ -590,20 +602,27 @@ export class InlineChatController implements IEditorContribution {
590602
if (!request.live) {
591603
throw new Error('Progress in NOT supported in non-live mode');
592604
}
593-
console.log(JSON.stringify(data.edits, undefined, 2));
594605
progressEdits.push(data.edits);
595606
progressiveEditsAvgDuration.update(progressiveEditsClock.elapsed());
596607
progressiveEditsClock.reset();
597608

598609
progressiveEditsQueue.queue(async () => {
610+
611+
const startThen = this._activeSession!.wholeRange.value.getStartPosition();
612+
599613
// making changes goes into a queue because otherwise the async-progress time will
600614
// influence the time it takes to receive the changes and progressive typing will
601615
// become infinitely fast
602616
await this._makeChanges(data.edits!, data.editsShouldBeInstant
603617
? undefined
604618
: { duration: progressiveEditsAvgDuration.value, round: round++, token: progressiveEditsCts.token }
605619
);
606-
this._showWidget(false);
620+
621+
// reshow the widget if the start position changed or shows at the wrong position
622+
const startNow = this._activeSession!.wholeRange.value.getStartPosition();
623+
if (!startNow.equals(startThen) || !this._zone.value.position?.equals(startNow)) {
624+
this._showWidget(false, startNow.delta(-1));
625+
}
607626
});
608627
}
609628
if (data.markdownFragment) {

0 commit comments

Comments
 (0)