Skip to content

Commit 1ad238a

Browse files
authored
Merge pull request microsoft#184598 from microsoft/aiday/positioningInlineChat
Adapt positioning of the inline chat
2 parents 8e26c33 + d037fad commit 1ad238a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ export class InlineChatController implements IEditorContribution {
194194

195195
// ---- state machine
196196

197+
private _showWidget(initialRender: boolean = false) {
198+
assertType(this._activeSession);
199+
assertType(this._strategy);
200+
assertType(this._editor.hasModel());
201+
202+
let widgetPosition: Position | undefined;
203+
if (initialRender) {
204+
widgetPosition = this._editor.getPosition();
205+
} else {
206+
widgetPosition = this._strategy.getWidgetPosition() ?? this._zone.value.position ?? this._activeSession.wholeRange.value.getEndPosition();
207+
}
208+
this._zone.value.show(widgetPosition);
209+
}
210+
197211
protected async _nextState(state: State, options: InlineChatRunOptions | undefined): Promise<void> {
198212
this._log('setState to ', state);
199213
const nextState = await this[state](options);
@@ -270,8 +284,8 @@ export class InlineChatController implements IEditorContribution {
270284
this._zone.value.widget.placeholder = this._getPlaceholderText();
271285
this._zone.value.widget.value = this._activeSession.lastInput?.value ?? '';
272286
this._zone.value.widget.updateInfo(this._activeSession.session.message ?? localize('welcome.1', "AI-generated code may be incorrect"));
273-
this._zone.value.show(this._activeSession.wholeRange.value.getEndPosition());
274287
this._zone.value.widget.preferredExpansionState = this._activeSession.lastExpansionState;
288+
this._showWidget(true);
275289

276290
this._sessionStore.add(this._editor.onDidChangeModel((e) => {
277291
const msg = this._activeSession?.lastExchange
@@ -361,7 +375,6 @@ export class InlineChatController implements IEditorContribution {
361375
assertType(this._strategy);
362376

363377
this._zone.value.widget.placeholder = this._getPlaceholderText();
364-
this._zone.value.show(this._activeSession.wholeRange.value.getEndPosition());
365378

366379
if (options?.message) {
367380
this._zone.value.widget.value = options?.message;
@@ -548,6 +561,7 @@ export class InlineChatController implements IEditorContribution {
548561
assertType(this._strategy);
549562

550563
const { response } = this._activeSession.lastExchange!;
564+
this._showWidget(false);
551565

552566
this._ctxLastResponseType.set(response instanceof EditResponse || response instanceof MarkdownResponse
553567
? response.raw.type

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export abstract class EditModeStrategy {
4545
abstract toggleDiff(): void;
4646

4747
abstract hasFocus(): boolean;
48+
49+
abstract getWidgetPosition(): Position | undefined;
4850
}
4951

5052
export class PreviewStrategy extends EditModeStrategy {
@@ -136,6 +138,10 @@ export class PreviewStrategy extends EditModeStrategy {
136138
// nothing to do
137139
}
138140

141+
getWidgetPosition(): Position | undefined {
142+
return;
143+
}
144+
139145
hasFocus(): boolean {
140146
return this._widget.hasFocus();
141147
}
@@ -341,6 +347,18 @@ export class LiveStrategy extends EditModeStrategy {
341347
this._widget.updateStatus(message);
342348
}
343349

350+
override getWidgetPosition(): Position | undefined {
351+
const lastTextModelChanges = this._session.lastTextModelChanges;
352+
let lastLineOfLocalEdits: number | undefined;
353+
for (const change of lastTextModelChanges) {
354+
const changeEndLineNumber = change.modifiedRange.endLineNumberExclusive - 1;
355+
if (typeof lastLineOfLocalEdits === 'undefined' || lastLineOfLocalEdits < changeEndLineNumber) {
356+
lastLineOfLocalEdits = changeEndLineNumber;
357+
}
358+
}
359+
return lastLineOfLocalEdits ? new Position(lastLineOfLocalEdits, 1) : undefined;
360+
}
361+
344362
hasFocus(): boolean {
345363
return this._widget.hasFocus();
346364
}

0 commit comments

Comments
 (0)