@@ -45,7 +45,7 @@ import { IModelDeltaDecoration, ITextModel, IValidEditOperation } from 'vs/edito
45
45
import { InlineChatContentWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatContentWidget' ;
46
46
import { MessageController } from 'vs/editor/contrib/message/browser/messageController' ;
47
47
import { tail } from 'vs/base/common/arrays' ;
48
- import { IChatRequestModel } from 'vs/workbench/contrib/chat/common/chatModel' ;
48
+ import { IChatRequestModel , IResponse } from 'vs/workbench/contrib/chat/common/chatModel' ;
49
49
import { InlineChatError } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl' ;
50
50
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures' ;
51
51
import { ChatInputPart } from 'vs/workbench/contrib/chat/browser/chatInputPart' ;
@@ -197,10 +197,9 @@ export class InlineChatController implements IEditorContribution {
197
197
198
198
dispose ( ) : void {
199
199
if ( this . _currentRun ) {
200
- this . _messages . fire ( ( this . _session ?. lastExchange
200
+ this . _messages . fire ( this . _session ?. chatModel . hasRequests
201
201
? Message . PAUSE_SESSION
202
- : Message . CANCEL_SESSION )
203
- ) ;
202
+ : Message . CANCEL_SESSION ) ;
204
203
}
205
204
this . _store . dispose ( ) ;
206
205
this . _isDisposed = true ;
@@ -381,10 +380,10 @@ export class InlineChatController implements IEditorContribution {
381
380
382
381
this . _zone . value . widget . updateInfo ( message ) ;
383
382
384
- this . _showWidget ( ! this . _session . lastExchange ) ;
383
+ this . _showWidget ( ! this . _session . chatModel . hasRequests ) ;
385
384
386
385
this . _sessionStore . add ( this . _editor . onDidChangeModel ( ( e ) => {
387
- const msg = this . _session ?. lastExchange
386
+ const msg = this . _session ?. chatModel . hasRequests
388
387
? Message . PAUSE_SESSION // pause when switching models/tabs and when having a previous exchange
389
388
: Message . CANCEL_SESSION ;
390
389
this . _log ( 'model changed, pause or cancel session' , msg , e ) ;
@@ -520,7 +519,7 @@ export class InlineChatController implements IEditorContribution {
520
519
521
520
//#endregion ------- DEBT
522
521
523
- if ( ! this . _session . lastExchange ) {
522
+ if ( ! this . _session . chatModel . hasRequests ) {
524
523
return State . WAIT_FOR_INPUT ;
525
524
} else if ( options . isUnstashed ) {
526
525
delete options . isUnstashed ;
@@ -646,7 +645,7 @@ export class InlineChatController implements IEditorContribution {
646
645
647
646
private async [ State . SHOW_REQUEST ] ( options : InlineChatRunOptions ) : Promise < State . APPLY_RESPONSE | State . CANCEL | State . PAUSE | State . ACCEPT > {
648
647
assertType ( this . _session ) ;
649
- assertType ( this . _session . lastInput ) ;
648
+ assertType ( this . _session . chatModel . requestInProgress ) ;
650
649
651
650
const request : IChatRequestModel | undefined = tail ( this . _session . chatModel . getRequests ( ) ) ;
652
651
@@ -789,12 +788,11 @@ export class InlineChatController implements IEditorContribution {
789
788
const { response } = this . _session . lastExchange ! ;
790
789
791
790
let responseTypes : InlineChatResponseTypes | undefined ;
792
- for ( const { response } of this . _session . exchanges ) {
793
-
794
- const thisType = response instanceof ReplyResponse
795
- ? response . responseType
796
- : undefined ;
797
-
791
+ for ( const request of this . _session . chatModel . getRequests ( ) ) {
792
+ if ( ! request . response ) {
793
+ continue ;
794
+ }
795
+ const thisType = asInlineChatResponseType ( request . response . response ) ;
798
796
if ( responseTypes === undefined ) {
799
797
responseTypes = thisType ;
800
798
} else if ( responseTypes !== thisType ) {
@@ -1144,7 +1142,7 @@ export class InlineChatController implements IEditorContribution {
1144
1142
}
1145
1143
1146
1144
feedbackLast ( kind : InlineChatResponseFeedbackKind ) {
1147
- if ( this . _session ?. lastExchange && this . _session . lastExchange . response instanceof ReplyResponse ) {
1145
+ if ( this . _session ?. lastExchange ? .response instanceof ReplyResponse ) {
1148
1146
this . _session . provider . handleInlineChatResponseFeedback ?.( this . _session . session , this . _session . lastExchange . response . raw , kind ) ;
1149
1147
switch ( kind ) {
1150
1148
case InlineChatResponseFeedbackKind . Helpful :
@@ -1167,7 +1165,7 @@ export class InlineChatController implements IEditorContribution {
1167
1165
}
1168
1166
1169
1167
acceptSession ( ) : void {
1170
- if ( this . _session ?. lastExchange && this . _session . lastExchange . response instanceof ReplyResponse ) {
1168
+ if ( this . _session ?. lastExchange ? .response instanceof ReplyResponse ) {
1171
1169
this . _session . provider . handleInlineChatResponseFeedback ?.( this . _session . session , this . _session . lastExchange . response . raw , InlineChatResponseFeedbackKind . Accepted ) ;
1172
1170
}
1173
1171
this . _messages . fire ( Message . ACCEPT_SESSION ) ;
@@ -1189,7 +1187,7 @@ export class InlineChatController implements IEditorContribution {
1189
1187
const diff = await this . _editorWorkerService . computeDiff ( this . _session . textModel0 . uri , this . _session . textModelN . uri , { ignoreTrimWhitespace : false , maxComputationTimeMs : 5000 , computeMoves : false } , 'advanced' ) ;
1190
1188
result = this . _session . asChangedText ( diff ?. changes ?? [ ] ) ;
1191
1189
1192
- if ( this . _session . lastExchange && this . _session . lastExchange . response instanceof ReplyResponse ) {
1190
+ if ( this . _session . lastExchange ? .response instanceof ReplyResponse ) {
1193
1191
this . _session . provider . handleInlineChatResponseFeedback ?.( this . _session . session , this . _session . lastExchange . response . raw , InlineChatResponseFeedbackKind . Undone ) ;
1194
1192
}
1195
1193
}
@@ -1253,3 +1251,25 @@ async function sendRequest(accessor: ServicesAccessor, query: string) {
1253
1251
widget . focusInput ( ) ;
1254
1252
widget . acceptInput ( query ) ;
1255
1253
}
1254
+
1255
+ function asInlineChatResponseType ( response : IResponse ) : InlineChatResponseTypes {
1256
+ let result : InlineChatResponseTypes | undefined ;
1257
+ for ( const item of response . value ) {
1258
+ let thisType : InlineChatResponseTypes ;
1259
+ switch ( item . kind ) {
1260
+ case 'textEdit' :
1261
+ thisType = InlineChatResponseTypes . OnlyEdits ;
1262
+ break ;
1263
+ case 'markdownContent' :
1264
+ default :
1265
+ thisType = InlineChatResponseTypes . OnlyMessages ;
1266
+ break ;
1267
+ }
1268
+ if ( result === undefined ) {
1269
+ result = thisType ;
1270
+ } else if ( result !== thisType ) {
1271
+ return InlineChatResponseTypes . Mixed ;
1272
+ }
1273
+ }
1274
+ return result ?? InlineChatResponseTypes . Empty ;
1275
+ }
0 commit comments