Skip to content

Commit f1b2a3a

Browse files
authored
Use Lazy for creating diff and preview zone so that they don't block startup (microsoft#185041)
microsoft#185034
1 parent 470b6ef commit f1b2a3a

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Event } from 'vs/base/common/event';
7+
import { Lazy } from 'vs/base/common/lazy';
78
import { IDisposable } from 'vs/base/common/lifecycle';
89
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
910
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
@@ -347,8 +348,8 @@ export class LiveStrategy extends EditModeStrategy {
347348

348349
export class LivePreviewStrategy extends LiveStrategy {
349350

350-
private readonly _diffZone: InlineChatLivePreviewWidget;
351-
private readonly _previewZone: InlineChatFileCreatePreviewWidget;
351+
private readonly _diffZone: Lazy<InlineChatLivePreviewWidget>;
352+
private readonly _previewZone: Lazy<InlineChatFileCreatePreviewWidget>;
352353

353354
constructor(
354355
session: Session,
@@ -362,49 +363,49 @@ export class LivePreviewStrategy extends LiveStrategy {
362363
) {
363364
super(session, editor, widget, contextKeyService, storageService, bulkEditService, editorWorkerService, instaService);
364365

365-
this._diffZone = instaService.createInstance(InlineChatLivePreviewWidget, editor, session);
366-
this._previewZone = instaService.createInstance(InlineChatFileCreatePreviewWidget, editor);
366+
this._diffZone = new Lazy(() => instaService.createInstance(InlineChatLivePreviewWidget, editor, session));
367+
this._previewZone = new Lazy(() => instaService.createInstance(InlineChatFileCreatePreviewWidget, editor));
367368
}
368369

369370
override dispose(): void {
370-
this._diffZone.hide();
371-
this._diffZone.dispose();
372-
this._previewZone.hide();
373-
this._previewZone.dispose();
371+
this._diffZone.rawValue?.hide();
372+
this._diffZone.rawValue?.dispose();
373+
this._previewZone.rawValue?.hide();
374+
this._previewZone.rawValue?.dispose();
374375
super.dispose();
375376
}
376377

377378
override async renderChanges(response: EditResponse) {
378379

379380
this._updateSummaryMessage();
380381
if (this._diffEnabled) {
381-
this._diffZone.show();
382+
this._diffZone.value.show();
382383
}
383384

384385
if (response.singleCreateFileEdit) {
385-
this._previewZone.showCreation(this._session.wholeRange.value, response.singleCreateFileEdit.uri, await Promise.all(response.singleCreateFileEdit.edits));
386+
this._previewZone.value.showCreation(this._session.wholeRange.value, response.singleCreateFileEdit.uri, await Promise.all(response.singleCreateFileEdit.edits));
386387
} else {
387-
this._previewZone.hide();
388+
this._previewZone.value.hide();
388389
}
389390
}
390391

391392
override async undoChanges(response: EditResponse): Promise<void> {
392-
this._diffZone.lockToDiff();
393+
this._diffZone.value.lockToDiff();
393394
super.undoChanges(response);
394395
}
395396

396397
protected override _doToggleDiff(): void {
397398
const scrollState = StableEditorScrollState.capture(this._editor);
398399
if (this._diffEnabled) {
399-
this._diffZone.show();
400+
this._diffZone.value.show();
400401
} else {
401-
this._diffZone.hide();
402+
this._diffZone.value.hide();
402403
}
403404
scrollState.restore(this._editor);
404405
}
405406

406407
override hasFocus(): boolean {
407-
return super.hasFocus() || this._diffZone.hasFocus() || this._previewZone.hasFocus();
408+
return super.hasFocus() || this._diffZone.value.hasFocus() || this._previewZone.value.hasFocus();
408409
}
409410
}
410411

0 commit comments

Comments
 (0)