Skip to content

Commit 8f03d83

Browse files
authored
Keep a model reference around to avoid snapshots getting disposed (microsoft#230296)
1 parent cc7ba25 commit 8f03d83

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/vs/workbench/contrib/chat/browser/chatEditingService.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,19 +619,26 @@ class ModifiedFileEntry extends Disposable implements IModifiedFileEntry {
619619
resourceRef: IReference<IResolvedTextEditorModel>,
620620
private readonly _multiDiffEntryDelegate: { collapse: (transaction: ITransaction | undefined) => void },
621621
@IModelService modelService: IModelService,
622+
@ITextModelService textModelService: ITextModelService,
622623
@ILanguageService languageService: ILanguageService,
623624
@IBulkEditService public readonly _bulkEditService: IBulkEditService,
624625
) {
625626
super();
626627
this.doc = resourceRef.object.textEditorModel;
627-
this.docSnapshot = this._register(
628+
const docSnapshot = this.docSnapshot = this._register(
628629
modelService.createModel(
629630
createTextBufferFactoryFromSnapshot(this.doc.createSnapshot()),
630631
languageService.createById(this.doc.getLanguageId()),
631632
ChatEditingTextModelContentProvider.getFileURI(this.entryId, resource.path),
632633
false
633634
)
634635
);
636+
637+
// Create a reference to this model to avoid it being disposed from under our nose
638+
(async () => {
639+
this._register(await textModelService.createModelReference(docSnapshot.uri));
640+
})();
641+
635642
this._register(resourceRef);
636643
}
637644

0 commit comments

Comments
 (0)