@@ -39,8 +39,9 @@ import { IChatAccessibilityService, IChatWidgetService } from 'vs/workbench/cont
39
39
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents' ;
40
40
import { chatAgentLeader , chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes' ;
41
41
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService' ;
42
- import { IInlineChatSavingService } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSaving' ;
43
- import { EmptyResponse , ErrorResponse , ExpansionState , IInlineChatSessionService , ReplyResponse , Session , SessionExchange , SessionPrompt } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession' ;
42
+ import { IInlineChatSavingService } from './inlineChatSavingService' ;
43
+ import { EmptyResponse , ErrorResponse , ExpansionState , ReplyResponse , Session , SessionExchange , SessionPrompt } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession' ;
44
+ import { IInlineChatSessionService } from './inlineChatSessionService' ;
44
45
import { EditModeStrategy , LivePreviewStrategy , LiveStrategy , PreviewStrategy , ProgressingEditsOptions } from 'vs/workbench/contrib/inlineChat/browser/inlineChatStrategies' ;
45
46
import { IInlineChatMessageAppender , InlineChatZoneWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatWidget' ;
46
47
import { CTX_INLINE_CHAT_DID_EDIT , CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST , CTX_INLINE_CHAT_LAST_FEEDBACK , CTX_INLINE_CHAT_RESPONSE_TYPES , CTX_INLINE_CHAT_SUPPORT_ISSUE_REPORTING , CTX_INLINE_CHAT_USER_DID_EDIT , EditMode , IInlineChatProgressItem , IInlineChatRequest , IInlineChatResponse , INLINE_CHAT_ID , InlineChatConfigKeys , InlineChatResponseFeedbackKind , InlineChatResponseTypes } from 'vs/workbench/contrib/inlineChat/common/inlineChat' ;
@@ -122,7 +123,7 @@ export class InlineChatController implements IEditorContribution {
122
123
readonly onDidCancelInput = Event . filter ( this . _messages . event , m => m === Message . CANCEL_INPUT || m === Message . CANCEL_SESSION , this . _store ) ;
123
124
124
125
private readonly _sessionStore : DisposableStore = this . _store . add ( new DisposableStore ( ) ) ;
125
- private readonly _pausedStrategies = new Map < Session , EditModeStrategy > ( ) ;
126
+
126
127
private _session ?: Session ;
127
128
private _strategy ?: EditModeStrategy ;
128
129
private _ignoreModelContentChanged = false ;
@@ -161,17 +162,19 @@ export class InlineChatController implements IEditorContribution {
161
162
return ;
162
163
}
163
164
164
- this . _log ( 'session RESUMING' , e ) ;
165
+ this . _log ( 'session RESUMING after model change ' , e ) ;
165
166
await this . run ( { existingSession } ) ;
166
- this . _log ( 'session done or paused' ) ;
167
167
} ) ) ;
168
- this . _log ( 'NEW controller' ) ;
169
168
170
- this . _store . add ( this . _inlineChatSessionService . onDidEndSession ( e => {
171
- this . _pausedStrategies . get ( e . session ) ?. dispose ( ) ;
172
- this . _pausedStrategies . delete ( e . session ) ;
169
+ this . _store . add ( this . _inlineChatSessionService . onDidMoveSession ( async e => {
170
+ if ( e . editor === this . _editor ) {
171
+ this . _log ( 'session RESUMING after move' , e ) ;
172
+ await this . run ( { existingSession : e . session } ) ;
173
+ }
173
174
} ) ) ;
174
175
176
+ this . _log ( 'NEW controller' ) ;
177
+
175
178
InlineChatController . _promptHistory = JSON . parse ( _storageService . get ( InlineChatController . _storageKey , StorageScope . PROFILE , '[]' ) ) ;
176
179
this . _historyUpdate = ( prompt : string ) => {
177
180
const idx = InlineChatController . _promptHistory . indexOf ( prompt ) ;
@@ -264,7 +267,7 @@ export class InlineChatController implements IEditorContribution {
264
267
}
265
268
}
266
269
267
- private async [ State . CREATE_SESSION ] ( options : InlineChatRunOptions ) : Promise < State . CANCEL | State . INIT_UI | State . PAUSE > {
270
+ private async [ State . CREATE_SESSION ] ( options : InlineChatRunOptions ) : Promise < State . CANCEL | State . INIT_UI > {
268
271
assertType ( this . _session === undefined ) ;
269
272
assertType ( this . _editor . hasModel ( ) ) ;
270
273
@@ -305,7 +308,10 @@ export class InlineChatController implements IEditorContribution {
305
308
msgListener . dispose ( ) ;
306
309
307
310
if ( createSessionCts . token . isCancellationRequested ) {
308
- return State . PAUSE ;
311
+ if ( session ) {
312
+ this . _inlineChatSessionService . releaseSession ( session ) ;
313
+ }
314
+ return State . CANCEL ;
309
315
}
310
316
}
311
317
@@ -317,24 +323,18 @@ export class InlineChatController implements IEditorContribution {
317
323
return State . CANCEL ;
318
324
}
319
325
320
- if ( this . _pausedStrategies . has ( session ) ) {
321
- // maybe a strategy was previously paused, use it
322
- this . _strategy = this . _pausedStrategies . get ( session ) ! ;
323
- this . _pausedStrategies . delete ( session ) ;
324
- } else {
325
- // create a new strategy
326
- switch ( session . editMode ) {
327
- case EditMode . Live :
328
- this . _strategy = this . _instaService . createInstance ( LiveStrategy , session , this . _editor , this . _zone . value ) ;
329
- break ;
330
- case EditMode . Preview :
331
- this . _strategy = this . _instaService . createInstance ( PreviewStrategy , session , this . _zone . value ) ;
332
- break ;
333
- case EditMode . LivePreview :
334
- default :
335
- this . _strategy = this . _instaService . createInstance ( LivePreviewStrategy , session , this . _editor , this . _zone . value ) ;
336
- break ;
337
- }
326
+ // create a new strategy
327
+ switch ( session . editMode ) {
328
+ case EditMode . Live :
329
+ this . _strategy = this . _instaService . createInstance ( LiveStrategy , session , this . _editor , this . _zone . value ) ;
330
+ break ;
331
+ case EditMode . Preview :
332
+ this . _strategy = this . _instaService . createInstance ( PreviewStrategy , session , this . _zone . value ) ;
333
+ break ;
334
+ case EditMode . LivePreview :
335
+ default :
336
+ this . _strategy = this . _instaService . createInstance ( LivePreviewStrategy , session , this . _editor , this . _zone . value ) ;
337
+ break ;
338
338
}
339
339
340
340
this . _session = session ;
@@ -690,7 +690,13 @@ export class InlineChatController implements IEditorContribution {
690
690
msgListener . dispose ( ) ;
691
691
typeListener . dispose ( ) ;
692
692
693
- if ( request . live && ! ( response instanceof ReplyResponse ) ) {
693
+ if ( response instanceof ReplyResponse ) {
694
+ // update hunks after a reply response
695
+ await this . _session . hunkData . recompute ( ) ;
696
+
697
+ } else if ( request . live ) {
698
+ // undo changes that might have been made when not
699
+ // having a reply response
694
700
this . _strategy ?. undoChanges ( modelAltVersionIdNow ) ;
695
701
}
696
702
@@ -803,7 +809,6 @@ export class InlineChatController implements IEditorContribution {
803
809
804
810
this . _resetWidget ( ) ;
805
811
806
- this . _pausedStrategies . set ( this . _session , this . _strategy ) ;
807
812
this . _strategy . pause ?.( ) ;
808
813
this . _session = undefined ;
809
814
}
@@ -831,21 +836,22 @@ export class InlineChatController implements IEditorContribution {
831
836
}
832
837
833
838
private async [ State . CANCEL ] ( ) {
834
- assertType ( this . _session ) ;
835
- assertType ( this . _strategy ) ;
836
- this . _sessionStore . clear ( ) ;
837
-
838
- try {
839
- await this . _strategy . cancel ( ) ;
840
- } catch ( err ) {
841
- this . _dialogService . error ( localize ( 'err.discard' , "Failed to discard changes." , toErrorMessage ( err ) ) ) ;
842
- this . _log ( 'FAILED to discard changes' ) ;
843
- this . _log ( err ) ;
839
+ if ( this . _session ) {
840
+ // assertType(this._session);
841
+ assertType ( this . _strategy ) ;
842
+ this . _sessionStore . clear ( ) ;
843
+
844
+ try {
845
+ await this . _strategy . cancel ( ) ;
846
+ } catch ( err ) {
847
+ this . _dialogService . error ( localize ( 'err.discard' , "Failed to discard changes." , toErrorMessage ( err ) ) ) ;
848
+ this . _log ( 'FAILED to discard changes' ) ;
849
+ this . _log ( err ) ;
850
+ }
851
+ this . _inlineChatSessionService . releaseSession ( this . _session ) ;
844
852
}
845
853
846
854
this . _resetWidget ( ) ;
847
- this . _inlineChatSessionService . releaseSession ( this . _session ) ;
848
-
849
855
850
856
this . _strategy ?. dispose ( ) ;
851
857
this . _strategy = undefined ;
0 commit comments