44 *--------------------------------------------------------------------------------------------*/
55
66import { RunOnceScheduler , timeout } from '../../../../../base/common/async.js' ;
7+ import { Emitter } from '../../../../../base/common/event.js' ;
78import { Disposable , IReference , toDisposable } from '../../../../../base/common/lifecycle.js' ;
89import { IObservable , ITransaction , observableValue , transaction } from '../../../../../base/common/observable.js' ;
910import { themeColorFromId } from '../../../../../base/common/themables.js' ;
@@ -24,10 +25,11 @@ import { IModelService } from '../../../../../editor/common/services/model.js';
2425import { IResolvedTextEditorModel , ITextModelService } from '../../../../../editor/common/services/resolverService.js' ;
2526import { IModelContentChange , IModelContentChangedEvent } from '../../../../../editor/common/textModelEvents.js' ;
2627import { localize } from '../../../../../nls.js' ;
28+ import { IFileService } from '../../../../../platform/files/common/files.js' ;
2729import { editorSelectionBackground } from '../../../../../platform/theme/common/colorRegistry.js' ;
2830import { IUndoRedoService } from '../../../../../platform/undoRedo/common/undoRedo.js' ;
2931import { IChatAgentResult } from '../../common/chatAgents.js' ;
30- import { IModifiedFileEntry , WorkingSetEntryState } from '../../common/chatEditingService.js' ;
32+ import { ChatEditKind , IModifiedFileEntry , WorkingSetEntryState } from '../../common/chatEditingService.js' ;
3133import { IChatService } from '../../common/chatService.js' ;
3234import { ChatEditingSnapshotTextModelContentProvider , ChatEditingTextModelContentProvider } from './chatEditingTextModelContentProviders.js' ;
3335
@@ -40,6 +42,11 @@ export class ChatEditingModifiedFileEntry extends Disposable implements IModifie
4042 public readonly docSnapshot : ITextModel ;
4143 private readonly doc : ITextModel ;
4244
45+ private readonly _onDidDelete = this . _register ( new Emitter < void > ( ) ) ;
46+ public get onDidDelete ( ) {
47+ return this . _onDidDelete . event ;
48+ }
49+
4350 get originalURI ( ) : URI {
4451 return this . docSnapshot . uri ;
4552 }
@@ -95,6 +102,8 @@ export class ChatEditingModifiedFileEntry extends Disposable implements IModifie
95102 return this . _telemetryInfo ;
96103 }
97104
105+ readonly createdInRequestId : string | undefined ;
106+
98107 get lastModifyingRequestId ( ) {
99108 return this . _telemetryInfo . requestId ;
100109 }
@@ -104,15 +113,20 @@ export class ChatEditingModifiedFileEntry extends Disposable implements IModifie
104113 resourceRef : IReference < IResolvedTextEditorModel > ,
105114 private readonly _multiDiffEntryDelegate : { collapse : ( transaction : ITransaction | undefined ) => void } ,
106115 private _telemetryInfo : IModifiedEntryTelemetryInfo ,
116+ kind : ChatEditKind ,
107117 @IModelService modelService : IModelService ,
108118 @ITextModelService textModelService : ITextModelService ,
109119 @ILanguageService languageService : ILanguageService ,
110120 @IBulkEditService public readonly bulkEditService : IBulkEditService ,
111121 @IChatService private readonly _chatService : IChatService ,
112122 @IEditorWorkerService private readonly _editorWorkerService : IEditorWorkerService ,
113- @IUndoRedoService private readonly _undoRedoService : IUndoRedoService
123+ @IUndoRedoService private readonly _undoRedoService : IUndoRedoService ,
124+ @IFileService private readonly _fileService : IFileService ,
114125 ) {
115126 super ( ) ;
127+ if ( kind === ChatEditKind . Created ) {
128+ this . createdInRequestId = this . _telemetryInfo . requestId ;
129+ }
116130 this . doc = resourceRef . object . textEditorModel ;
117131 const docSnapshot = this . docSnapshot = this . _register (
118132 modelService . createModel (
@@ -316,11 +330,16 @@ export class ChatEditingModifiedFileEntry extends Disposable implements IModifie
316330 return ;
317331 }
318332
319- this . _setDocValue ( this . docSnapshot . getValue ( ) ) ;
320-
321333 this . _stateObs . set ( WorkingSetEntryState . Rejected , transaction ) ;
322- await this . collapse ( transaction ) ;
323334 this . _notifyAction ( 'rejected' ) ;
335+ if ( this . createdInRequestId === this . _telemetryInfo . requestId ) {
336+ await this . _fileService . del ( this . resource ) ;
337+ this . _onDidDelete . fire ( ) ;
338+ this . dispose ( ) ;
339+ } else {
340+ this . _setDocValue ( this . docSnapshot . getValue ( ) ) ;
341+ await this . collapse ( transaction ) ;
342+ }
324343 }
325344
326345 private _setDocValue ( value : string ) : void {
0 commit comments