@@ -28,7 +28,7 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
28
28
import { IDialogService } from 'vs/platform/dialogs/common/dialogs' ;
29
29
import { IInstantiationService , ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
30
30
import { ILogService } from 'vs/platform/log/common/log' ;
31
- import { EditResponse , EmptyResponse , ErrorResponse , ExpansionState , IInlineChatSessionService , MarkdownResponse , Session , SessionExchange } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession' ;
31
+ import { EditResponse , EmptyResponse , ErrorResponse , ExpansionState , IInlineChatSessionService , MarkdownResponse , Session , SessionExchange , SessionPrompt } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession' ;
32
32
import { EditModeStrategy , LivePreviewStrategy , LiveStrategy , PreviewStrategy } from 'vs/workbench/contrib/inlineChat/browser/inlineChatStrategies' ;
33
33
import { InlineChatZoneWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatWidget' ;
34
34
import { CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST , CTX_INLINE_CHAT_LAST_FEEDBACK , IInlineChatRequest , IInlineChatResponse , INLINE_CHAT_ID , EditMode , InlineChatResponseFeedbackKind , CTX_INLINE_CHAT_LAST_RESPONSE_TYPE , InlineChatResponseType , CTX_INLINE_CHAT_DID_EDIT , CTX_INLINE_CHAT_HAS_STASHED_SESSION } from 'vs/workbench/contrib/inlineChat/common/inlineChat' ;
@@ -58,7 +58,8 @@ const enum Message {
58
58
PAUSE_SESSION = 1 << 2 ,
59
59
CANCEL_REQUEST = 1 << 3 ,
60
60
CANCEL_INPUT = 1 << 4 ,
61
- ACCEPT_INPUT = 1 << 5
61
+ ACCEPT_INPUT = 1 << 5 ,
62
+ RERUN_INPUT = 1 << 6 ,
62
63
}
63
64
64
65
export interface InlineChatRunOptions {
@@ -267,7 +268,7 @@ export class InlineChatController implements IEditorContribution {
267
268
268
269
this . _zone . value . widget . updateSlashCommands ( this . _activeSession . session . slashCommands ?? [ ] ) ;
269
270
this . _zone . value . widget . placeholder = this . _getPlaceholderText ( ) ;
270
- this . _zone . value . widget . value = this . _activeSession . lastInput ?? '' ;
271
+ this . _zone . value . widget . value = this . _activeSession . lastInput ?. value ?? '' ;
271
272
this . _zone . value . widget . updateInfo ( this . _activeSession . session . message ?? localize ( 'welcome.1' , "AI-generated code may be incorrect" ) ) ;
272
273
this . _zone . value . show ( this . _activeSession . wholeRange . value . getEndPosition ( ) ) ;
273
274
this . _zone . value . widget . preferredExpansionState = this . _activeSession . lastExpansionState ;
@@ -357,6 +358,7 @@ export class InlineChatController implements IEditorContribution {
357
358
358
359
private async [ State . WAIT_FOR_INPUT ] ( options : InlineChatRunOptions | undefined ) : Promise < State . ACCEPT | State . CANCEL | State . PAUSE | State . WAIT_FOR_INPUT | State . MAKE_REQUEST > {
359
360
assertType ( this . _activeSession ) ;
361
+ assertType ( this . _strategy ) ;
360
362
361
363
this . _zone . value . widget . placeholder = this . _getPlaceholderText ( ) ;
362
364
this . _zone . value . show ( this . _activeSession . wholeRange . value . getEndPosition ( ) ) ;
@@ -397,6 +399,15 @@ export class InlineChatController implements IEditorContribution {
397
399
return State . PAUSE ;
398
400
}
399
401
402
+ if ( message & Message . RERUN_INPUT && this . _activeSession . lastExchange ) {
403
+ const { lastExchange } = this . _activeSession ;
404
+ this . _activeSession . addInput ( lastExchange . prompt . retry ( ) ) ;
405
+ if ( lastExchange . response instanceof EditResponse ) {
406
+ await this . _strategy . undoChanges ( lastExchange . response ) ;
407
+ }
408
+ return State . MAKE_REQUEST ;
409
+ }
410
+
400
411
if ( ! this . _zone . value . widget . value ) {
401
412
return State . WAIT_FOR_INPUT ;
402
413
}
@@ -420,7 +431,7 @@ export class InlineChatController implements IEditorContribution {
420
431
return State . WAIT_FOR_INPUT ;
421
432
}
422
433
423
- this . _activeSession . addInput ( input ) ;
434
+ this . _activeSession . addInput ( new SessionPrompt ( input ) ) ;
424
435
return State . MAKE_REQUEST ;
425
436
}
426
437
@@ -444,10 +455,10 @@ export class InlineChatController implements IEditorContribution {
444
455
445
456
const sw = StopWatch . create ( ) ;
446
457
const request : IInlineChatRequest = {
447
- prompt : this . _activeSession . lastInput ,
458
+ prompt : this . _activeSession . lastInput . value ,
459
+ attempt : this . _activeSession . lastInput . attempt ,
448
460
selection : this . _editor . getSelection ( ) ,
449
461
wholeRange : this . _activeSession . wholeRange . value ,
450
- attempt : 0 ,
451
462
} ;
452
463
const task = this . _activeSession . provider . provideResponse ( this . _activeSession . session , request , requestCts . token ) ;
453
464
this . _log ( 'request started' , this . _activeSession . provider . debugName , this . _activeSession . session , request ) ;
@@ -463,7 +474,7 @@ export class InlineChatController implements IEditorContribution {
463
474
if ( reply ?. type === 'message' ) {
464
475
response = new MarkdownResponse ( this . _activeSession . textModelN . uri , reply ) ;
465
476
} else if ( reply ) {
466
- response = new EditResponse ( this . _activeSession . textModelN . uri , reply ) ;
477
+ response = new EditResponse ( this . _activeSession . textModelN . uri , this . _activeSession . textModelN . getAlternativeVersionId ( ) , reply ) ;
467
478
} else {
468
479
response = new EmptyResponse ( ) ;
469
480
}
@@ -483,7 +494,7 @@ export class InlineChatController implements IEditorContribution {
483
494
msgListener . dispose ( ) ;
484
495
typeListener . dispose ( ) ;
485
496
486
- this . _activeSession . addExchange ( new SessionExchange ( request . prompt , response ) ) ;
497
+ this . _activeSession . addExchange ( new SessionExchange ( this . _activeSession . lastInput , response ) ) ;
487
498
488
499
if ( message & Message . CANCEL_SESSION ) {
489
500
return State . CANCEL ;
@@ -646,6 +657,10 @@ export class InlineChatController implements IEditorContribution {
646
657
this . _messages . fire ( Message . ACCEPT_INPUT ) ;
647
658
}
648
659
660
+ regenerate ( ) : void {
661
+ this . _messages . fire ( Message . RERUN_INPUT ) ;
662
+ }
663
+
649
664
cancelCurrentRequest ( ) : void {
650
665
this . _messages . fire ( Message . CANCEL_INPUT | Message . CANCEL_REQUEST ) ;
651
666
}
@@ -683,7 +698,7 @@ export class InlineChatController implements IEditorContribution {
683
698
684
699
viewInChat ( ) {
685
700
if ( this . _activeSession ?. lastExchange ?. response instanceof MarkdownResponse ) {
686
- this . _instaService . invokeFunction ( showMessageResponse , this . _activeSession . lastExchange . prompt , this . _activeSession . lastExchange . response . raw . message . value ) ;
701
+ this . _instaService . invokeFunction ( showMessageResponse , this . _activeSession . lastExchange . prompt . value , this . _activeSession . lastExchange . response . raw . message . value ) ;
687
702
}
688
703
}
689
704
0 commit comments