@@ -130,16 +130,26 @@ export class InteractiveEditorController implements IEditorContribution {
130
130
return ;
131
131
}
132
132
133
- this . _logService . trace ( '[IE] session RESUMING') ;
133
+ this . _log ( ' session RESUMING', e ) ;
134
134
await this . _nextState ( State . CREATE_SESSION , { existingSession } ) ;
135
- this . _logService . trace ( '[IE] session done or paused') ;
135
+ this . _log ( ' session done or paused') ;
136
136
} ) ) ;
137
+ this . _log ( 'NEW controller' ) ;
137
138
}
138
139
139
140
dispose ( ) : void {
140
141
this . _stashedSession . clear ( ) ;
141
142
this . _finishExistingSession ( ) ;
142
143
this . _store . dispose ( ) ;
144
+ this . _log ( 'controller disposed' ) ;
145
+ }
146
+
147
+ private _log ( message : string | Error , ...more : any [ ] ) : void {
148
+ if ( message instanceof Error ) {
149
+ this . _logService . error ( message , ...more ) ;
150
+ } else {
151
+ this . _logService . trace ( `[IE] (editor:${ this . _editor . getId ( ) } )${ message } ` , ...more ) ;
152
+ }
143
153
}
144
154
145
155
getId ( ) : string {
@@ -161,21 +171,21 @@ export class InteractiveEditorController implements IEditorContribution {
161
171
}
162
172
163
173
async run ( options : InteractiveEditorRunOptions | undefined ) : Promise < void > {
164
- this . _logService . trace ( '[IE] session starting') ;
174
+ this . _log ( ' session starting') ;
165
175
await this . _finishExistingSession ( ) ;
166
176
this . _stashedSession . clear ( ) ;
167
177
168
178
await this . _nextState ( State . CREATE_SESSION , options ) ;
169
- this . _logService . trace ( '[IE] session done or paused') ;
179
+ this . _log ( ' session done or paused') ;
170
180
}
171
181
172
182
private async _finishExistingSession ( ) : Promise < void > {
173
183
if ( this . _activeSession ) {
174
184
if ( this . _activeSession . editMode === EditMode . Preview ) {
175
- this . _logService . trace ( '[IE] finishing existing session, using CANCEL', this . _activeSession . editMode ) ;
185
+ this . _log ( ' finishing existing session, using CANCEL', this . _activeSession . editMode ) ;
176
186
await this . cancelSession ( ) ;
177
187
} else {
178
- this . _logService . trace ( '[IE] finishing existing session, using APPLY', this . _activeSession . editMode ) ;
188
+ this . _log ( ' finishing existing session, using APPLY', this . _activeSession . editMode ) ;
179
189
await this . applyChanges ( ) ;
180
190
}
181
191
}
@@ -184,7 +194,7 @@ export class InteractiveEditorController implements IEditorContribution {
184
194
// ---- state machine
185
195
186
196
protected async _nextState ( state : State , options : InteractiveEditorRunOptions | undefined ) : Promise < void > {
187
- this . _logService . trace ( '[IE] setState to ', state ) ;
197
+ this . _log ( ' setState to ', state ) ;
188
198
const nextState = await this [ state ] ( options ) ;
189
199
if ( nextState ) {
190
200
await this . _nextState ( nextState , options ) ;
@@ -200,7 +210,7 @@ export class InteractiveEditorController implements IEditorContribution {
200
210
if ( ! session ) {
201
211
const createSessionCts = new CancellationTokenSource ( ) ;
202
212
const msgListener = Event . once ( this . _messages . event ) ( m => {
203
- this . _logService . trace ( '[IE]( state=_createSession) message received', m ) ;
213
+ this . _log ( ' state=_createSession) message received', m ) ;
204
214
createSessionCts . cancel ( ) ;
205
215
} ) ;
206
216
@@ -261,11 +271,12 @@ export class InteractiveEditorController implements IEditorContribution {
261
271
this . _zone . widget . updateInfo ( this . _activeSession . session . message ?? localize ( 'welcome.1' , "AI-generated code may be incorrect" ) ) ;
262
272
this . _zone . show ( this . _activeSession . wholeRange . getEndPosition ( ) ) ;
263
273
264
- this . _sessionStore . add ( this . _editor . onDidChangeModel ( ( ) => {
265
- this . _messages . fire ( this . _activeSession ?. lastExchange
274
+ this . _sessionStore . add ( this . _editor . onDidChangeModel ( ( e ) => {
275
+ const msg = this . _activeSession ?. lastExchange
266
276
? Message . PAUSE_SESSION // pause when switching models/tabs and when having a previous exchange
267
- : Message . CANCEL_SESSION
268
- ) ;
277
+ : Message . CANCEL_SESSION ;
278
+ this . _log ( 'model changed, pause or cancel session' , msg , e ) ;
279
+ this . _messages . fire ( msg ) ;
269
280
} ) ) ;
270
281
271
282
this . _sessionStore . add ( this . _editor . onDidChangeModelContent ( e => {
@@ -282,7 +293,7 @@ export class InteractiveEditorController implements IEditorContribution {
282
293
this . _activeSession ! . recordExternalEditOccurred ( editIsOutsideOfWholeRange ) ;
283
294
284
295
if ( editIsOutsideOfWholeRange ) {
285
- this . _logService . info ( '[IE] text changed outside of whole range, FINISH session') ;
296
+ this . _log ( ' text changed outside of whole range, FINISH session') ;
286
297
this . _finishExistingSession ( ) ;
287
298
}
288
299
} ) ) ;
@@ -363,7 +374,7 @@ export class InteractiveEditorController implements IEditorContribution {
363
374
} else {
364
375
const barrier = new Barrier ( ) ;
365
376
const msgListener = Event . once ( this . _messages . event ) ( m => {
366
- this . _logService . trace ( '[IE]( state=_waitForInput) message received', m ) ;
377
+ this . _log ( ' state=_waitForInput) message received', m ) ;
367
378
message = m ;
368
379
barrier . open ( ) ;
369
380
} ) ;
@@ -397,7 +408,7 @@ export class InteractiveEditorController implements IEditorContribution {
397
408
398
409
const refer = this . _activeSession . session . slashCommands ?. some ( value => value . refer && input ! . startsWith ( `/${ value . command } ` ) ) ;
399
410
if ( refer ) {
400
- this . _logService . info ( '[IE] seeing refer command, continuing outside editor' , this . _activeSession . provider . debugName ) ;
411
+ this . _log ( '[IE] seeing refer command, continuing outside editor' , this . _activeSession . provider . debugName ) ;
401
412
this . _editor . setSelection ( this . _activeSession . wholeRange ) ;
402
413
this . _instaService . invokeFunction ( sendRequest , input ) ;
403
414
@@ -421,7 +432,7 @@ export class InteractiveEditorController implements IEditorContribution {
421
432
422
433
let message = Message . NONE ;
423
434
const msgListener = Event . once ( this . _messages . event ) ( m => {
424
- this . _logService . trace ( '[IE]( state=_makeRequest) message received', m ) ;
435
+ this . _log ( ' state=_makeRequest) message received', m ) ;
425
436
message = m ;
426
437
requestCts . cancel ( ) ;
427
438
} ) ;
@@ -438,7 +449,7 @@ export class InteractiveEditorController implements IEditorContribution {
438
449
attempt : 0 ,
439
450
} ;
440
451
const task = this . _activeSession . provider . provideResponse ( this . _activeSession . session , request , requestCts . token ) ;
441
- this . _logService . trace ( '[IE] request started', this . _activeSession . provider . debugName , this . _activeSession . session , request ) ;
452
+ this . _log ( ' request started', this . _activeSession . provider . debugName , this . _activeSession . session , request ) ;
442
453
443
454
let response : EditResponse | MarkdownResponse | ErrorResponse | EmptyResponse ;
444
455
let reply : IInteractiveEditorResponse | null | undefined ;
@@ -463,7 +474,7 @@ export class InteractiveEditorController implements IEditorContribution {
463
474
this . _ctxHasActiveRequest . set ( false ) ;
464
475
this . _zone . widget . updateProgress ( false ) ;
465
476
this . _zone . widget . updateInfo ( '' ) ;
466
- this . _logService . trace ( '[IE] request took', sw . elapsed ( ) , this . _activeSession . provider . debugName ) ;
477
+ this . _log ( ' request took', sw . elapsed ( ) , this . _activeSession . provider . debugName ) ;
467
478
468
479
}
469
480
@@ -497,7 +508,7 @@ export class InteractiveEditorController implements IEditorContribution {
497
508
}
498
509
const moreMinimalEdits = ( await this . _editorWorkerService . computeHumanReadableDiff ( this . _activeSession . textModelN . uri , response . localEdits ) ) ;
499
510
const editOperations = ( moreMinimalEdits ?? response . localEdits ) . map ( edit => EditOperation . replace ( Range . lift ( edit . range ) , edit . text ) ) ;
500
- this . _logService . trace ( '[IE] edits from PROVIDER and after making them MORE MINIMAL', this . _activeSession . provider . debugName , response . localEdits , moreMinimalEdits ) ;
511
+ this . _log ( ' edits from PROVIDER and after making them MORE MINIMAL', this . _activeSession . provider . debugName , response . localEdits , moreMinimalEdits ) ;
501
512
502
513
const textModelNplus1 = this . _modelService . createModel ( createTextBufferFactoryFromSnapshot ( this . _activeSession . textModelN . createSnapshot ( ) ) , null , undefined , true ) ;
503
514
textModelNplus1 . applyEdits ( editOperations ) ;
@@ -682,8 +693,8 @@ export class InteractiveEditorController implements IEditorContribution {
682
693
await strategy ?. apply ( ) ;
683
694
} catch ( err ) {
684
695
this . _dialogService . error ( localize ( 'err.apply' , "Failed to apply changes." , toErrorMessage ( err ) ) ) ;
685
- this . _logService . error ( '[IE] FAILED to apply changes') ;
686
- this . _logService . error ( err ) ;
696
+ this . _log ( ' FAILED to apply changes') ;
697
+ this . _log ( err ) ;
687
698
}
688
699
strategy ?. dispose ( ) ;
689
700
this . _messages . fire ( Message . ACCEPT_SESSION ) ;
@@ -702,8 +713,8 @@ export class InteractiveEditorController implements IEditorContribution {
702
713
await strategy ?. cancel ( ) ;
703
714
} catch ( err ) {
704
715
this . _dialogService . error ( localize ( 'err.discard' , "Failed to discard changes." , toErrorMessage ( err ) ) ) ;
705
- this . _logService . error ( '[IE] FAILED to discard changes') ;
706
- this . _logService . error ( err ) ;
716
+ this . _log ( ' FAILED to discard changes') ;
717
+ this . _log ( err ) ;
707
718
}
708
719
strategy ?. dispose ( ) ;
709
720
this . _messages . fire ( Message . CANCEL_SESSION ) ;
0 commit comments