Skip to content

Commit eb98edb

Browse files
committed
changes from review
1 parent c3275e4 commit eb98edb

File tree

1 file changed

+19
-36
lines changed

1 file changed

+19
-36
lines changed

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

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/
2727

2828
export abstract class EditModeStrategy {
2929

30-
constructor(protected readonly _editor: ICodeEditor) {
31-
this._initialPosition = this._editor.getPosition();
32-
}
33-
34-
protected _initialPosition: Position | null;
35-
3630
abstract dispose(): void;
3731

3832
abstract checkChanges(response: EditResponse): boolean;
@@ -49,7 +43,7 @@ export abstract class EditModeStrategy {
4943

5044
abstract hasFocus(): boolean;
5145

52-
abstract getWidgetPosition(initialRender: boolean, range: Range): Position | null;
46+
abstract getWidgetPosition(): Position | null;
5347
}
5448

5549
export class PreviewStrategy extends EditModeStrategy {
@@ -58,14 +52,13 @@ export class PreviewStrategy extends EditModeStrategy {
5852
private readonly _listener: IDisposable;
5953

6054
constructor(
61-
_editor: ICodeEditor,
6255
private readonly _session: Session,
6356
private readonly _widget: InlineChatWidget,
6457
@IContextKeyService contextKeyService: IContextKeyService,
6558
@IBulkEditService private readonly _bulkEditService: IBulkEditService,
6659
@IInstantiationService private readonly _instaService: IInstantiationService,
6760
) {
68-
super(_editor);
61+
super();
6962

7063
this._ctxDocumentChanged = CTX_INLINE_CHAT_DOCUMENT_CHANGED.bindTo(contextKeyService);
7164
this._listener = Event.debounce(_session.textModelN.onDidChangeContent.bind(_session.textModelN), () => { }, 350)(_ => {
@@ -138,8 +131,8 @@ export class PreviewStrategy extends EditModeStrategy {
138131
// nothing to do
139132
}
140133

141-
getWidgetPosition(_initialRender: boolean, _range: Range): Position | null {
142-
return this._initialPosition;
134+
getWidgetPosition(): Position | null {
135+
return null;
143136
}
144137

145138
hasFocus(): boolean {
@@ -225,16 +218,16 @@ export class LiveStrategy extends EditModeStrategy {
225218
private _editCount: number = 0;
226219

227220
constructor(
228-
_editor: ICodeEditor,
229221
protected readonly _session: Session,
222+
protected readonly _editor: ICodeEditor,
230223
protected readonly _widget: InlineChatWidget,
231224
@IContextKeyService contextKeyService: IContextKeyService,
232225
@IStorageService protected _storageService: IStorageService,
233226
@IBulkEditService protected readonly _bulkEditService: IBulkEditService,
234227
@IEditorWorkerService protected readonly _editorWorkerService: IEditorWorkerService,
235228
@IInstantiationService private readonly _instaService: IInstantiationService,
236229
) {
237-
super(_editor);
230+
super();
238231
this._diffEnabled = _storageService.getBoolean(LiveStrategy._inlineDiffStorageKey, StorageScope.PROFILE, true);
239232

240233
this._inlineDiffDecorations = new InlineDiffDecorations(this._editor, this._diffEnabled);
@@ -350,18 +343,13 @@ export class LiveStrategy extends EditModeStrategy {
350343
return lastLineOfLocalEdits;
351344
}
352345

353-
override getWidgetPosition(initialRender: boolean, _range: Range): Position | null {
354-
if (initialRender) {
355-
return this._initialPosition;
356-
} else {
357-
const isEditResponse = this._session.lastExchange?.response instanceof EditResponse;
358-
if (isEditResponse) {
359-
const lastLineOfLocalEdits = this._lastLineOfLocalEdits();
360-
return lastLineOfLocalEdits ? new Position(lastLineOfLocalEdits, 1) : this._initialPosition;
361-
} else {
362-
return this._initialPosition;
363-
}
346+
override getWidgetPosition(): Position | null {
347+
const isEditResponse = this._session.lastExchange?.response instanceof EditResponse;
348+
if (isEditResponse) {
349+
const lastLineOfLocalEdits = this._lastLineOfLocalEdits();
350+
return lastLineOfLocalEdits ? new Position(lastLineOfLocalEdits, 1) : null;
364351
}
352+
return null;
365353
}
366354

367355
hasFocus(): boolean {
@@ -375,16 +363,16 @@ export class LivePreviewStrategy extends LiveStrategy {
375363
private readonly _previewZone: InlineChatFileCreatePreviewWidget;
376364

377365
constructor(
378-
editor: ICodeEditor,
379366
session: Session,
367+
editor: ICodeEditor,
380368
widget: InlineChatWidget,
381369
@IContextKeyService contextKeyService: IContextKeyService,
382370
@IStorageService storageService: IStorageService,
383371
@IBulkEditService bulkEditService: IBulkEditService,
384372
@IEditorWorkerService editorWorkerService: IEditorWorkerService,
385373
@IInstantiationService instaService: IInstantiationService,
386374
) {
387-
super(editor, session, widget, contextKeyService, storageService, bulkEditService, editorWorkerService, instaService);
375+
super(session, editor, widget, contextKeyService, storageService, bulkEditService, editorWorkerService, instaService);
388376

389377
this._diffZone = instaService.createInstance(InlineChatLivePreviewWidget, editor, session);
390378
this._previewZone = instaService.createInstance(InlineChatFileCreatePreviewWidget, editor);
@@ -422,17 +410,12 @@ export class LivePreviewStrategy extends LiveStrategy {
422410
scrollState.restore(this._editor);
423411
}
424412

425-
override getWidgetPosition(initialRender: boolean, range: Range): Position | null {
426-
if (initialRender) {
427-
return this._initialPosition;
428-
} else {
429-
const isEditResponse = this._session.lastExchange?.response instanceof EditResponse;
430-
if (range && isEditResponse) {
431-
return range.getEndPosition();
432-
} else {
433-
return this._initialPosition;
434-
}
413+
override getWidgetPosition(): Position | null {
414+
const isEditResponse = this._session.lastExchange?.response instanceof EditResponse;
415+
if (isEditResponse) {
416+
return this._session.wholeRange.value.getEndPosition();
435417
}
418+
return null;
436419
}
437420

438421
override hasFocus(): boolean {

0 commit comments

Comments
 (0)