@@ -67,6 +67,7 @@ export interface InteractiveEditorRunOptions {
67
67
autoSend ?: boolean ;
68
68
existingSession ?: Session ;
69
69
isUnstashed ?: boolean ;
70
+ initialRender ?: boolean ;
70
71
}
71
72
72
73
export class InteractiveEditorController implements IEditorContribution {
@@ -99,6 +100,8 @@ export class InteractiveEditorController implements IEditorContribution {
99
100
private _activeSession ?: Session ;
100
101
private _strategy ?: EditModeStrategy ;
101
102
private _ignoreModelContentChanged = false ;
103
+ private _initialRender ?: boolean = true ;
104
+ private _updateEditMode ?: boolean = false ;
102
105
103
106
constructor (
104
107
private readonly _editor : ICodeEditor ,
@@ -232,26 +235,55 @@ export class InteractiveEditorController implements IEditorContribution {
232
235
return State . CANCEL ;
233
236
}
234
237
238
+ this . _initializeStratetgy ( session ) ;
239
+ this . _activeSession = session ;
240
+ this . _store . add ( this . _configurationService . onDidChangeConfiguration ( ( e ) => {
241
+ console . log ( 'e : ' , e ) ;
242
+ console . log ( 'e.affectsConfiguration(interactiveEditor.editModes) : ' , e . affectsConfiguration ( 'interactiveEditor.editMode' ) ) ;
243
+ console . log ( 'this._activeSession : ' , this . _activeSession ) ;
244
+ if ( e . affectsConfiguration ( 'interactiveEditor.editMode' ) ) {
245
+ console . log ( 'entered into inner if loop of onDidChangeConfiguration' ) ;
246
+ console . log ( 'this._getMode() : ' , this . _getMode ( ) ) ;
247
+ this . _updateEditMode = true ;
248
+ }
249
+ } ) ) ;
250
+
251
+ return State . INIT_UI ;
252
+ }
253
+
254
+ private _initializeStratetgy ( session : Session ) : void {
255
+ console . log ( 'inside of initial strategy' ) ;
235
256
switch ( session . editMode ) {
236
257
case EditMode . Live :
237
258
this . _strategy = this . _instaService . createInstance ( LiveStrategy , session , this . _editor , this . _zone . value . widget ) ;
238
259
break ;
239
260
case EditMode . Preview :
240
- this . _strategy = this . _instaService . createInstance ( PreviewStrategy , session , this . _zone . value . widget ) ;
261
+ this . _strategy = this . _instaService . createInstance ( PreviewStrategy , session , this . _editor , this . _zone . value . widget ) ;
241
262
break ;
242
263
case EditMode . LivePreview :
243
264
default :
244
265
this . _strategy = this . _instaService . createInstance ( LivePreviewStrategy , session , this . _editor , this . _zone . value . widget ) ;
245
266
break ;
246
267
}
268
+ }
247
269
248
- this . _activeSession = session ;
249
- return State . INIT_UI ;
270
+ private _showWidget ( initialRender : boolean = false ) {
271
+ console . log ( 'inside of _showWidget' ) ;
272
+ console . log ( 'initialRender : ' , initialRender ) ;
273
+ assertType ( this . _activeSession ) ;
274
+ const selectionRange = this . _activeSession . wholeRange . value ;
275
+ this . _zone . value . showWidget ( selectionRange , this . _strategy ?. getWidgetPosition ( initialRender , selectionRange ) ) ;
250
276
}
251
277
252
278
private async [ State . INIT_UI ] ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . WAIT_FOR_INPUT | State . SHOW_RESPONSE | State . APPLY_RESPONSE > {
253
279
assertType ( this . _activeSession ) ;
254
280
281
+ if ( this . _updateEditMode ) {
282
+ this . _activeSession . editMode = this . _getMode ( ) ;
283
+ this . _initializeStratetgy ( this . _activeSession ) ;
284
+ this . _updateEditMode = false ;
285
+ }
286
+
255
287
// hide/cancel inline completions when invoking IE
256
288
InlineCompletionsController . get ( this . _editor ) ?. hide ( ) ;
257
289
@@ -269,8 +301,10 @@ export class InteractiveEditorController implements IEditorContribution {
269
301
this . _zone . value . widget . placeholder = this . _getPlaceholderText ( ) ;
270
302
this . _zone . value . widget . value = this . _activeSession . lastInput ?? '' ;
271
303
this . _zone . value . widget . updateInfo ( this . _activeSession . session . message ?? localize ( 'welcome.1' , "AI-generated code may be incorrect" ) ) ;
272
- this . _zone . value . show ( this . _activeSession . wholeRange . value ) ;
273
304
this . _zone . value . widget . preferredExpansionState = this . _activeSession . lastExpansionState ;
305
+ console . log ( 'inside of init ui before show widget' ) ;
306
+ this . _initialRender = true ;
307
+ this . _showWidget ( this . _initialRender ) ;
274
308
275
309
this . _sessionStore . add ( this . _editor . onDidChangeModel ( ( e ) => {
276
310
const msg = this . _activeSession ?. lastExchange
@@ -358,8 +392,10 @@ export class InteractiveEditorController implements IEditorContribution {
358
392
private async [ State . WAIT_FOR_INPUT ] ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . ACCEPT | State . CANCEL | State . PAUSE | State . WAIT_FOR_INPUT | State . MAKE_REQUEST > {
359
393
assertType ( this . _activeSession ) ;
360
394
395
+ console . log ( 'inside of wait for input' ) ;
361
396
this . _zone . value . widget . placeholder = this . _getPlaceholderText ( ) ;
362
- this . _zone . value . show ( this . _activeSession . wholeRange . value ) ;
397
+ this . _showWidget ( this . _initialRender ) ;
398
+ this . _initialRender = false ;
363
399
364
400
if ( options ?. message ) {
365
401
this . _zone . value . widget . value = options ?. message ;
@@ -398,6 +434,7 @@ export class InteractiveEditorController implements IEditorContribution {
398
434
}
399
435
400
436
if ( ! this . _zone . value . widget . value ) {
437
+ console . log ( 'before the case when we call WAIT_FOR_INPUT' ) ;
401
438
return State . WAIT_FOR_INPUT ;
402
439
}
403
440
@@ -427,6 +464,7 @@ export class InteractiveEditorController implements IEditorContribution {
427
464
private async [ State . MAKE_REQUEST ] ( ) : Promise < State . APPLY_RESPONSE | State . PAUSE | State . CANCEL | State . ACCEPT > {
428
465
assertType ( this . _editor . hasModel ( ) ) ;
429
466
assertType ( this . _activeSession ) ;
467
+ console . log ( 'this._activeSession.lastInput : ' , this . _activeSession . lastInput ) ;
430
468
assertType ( this . _activeSession . lastInput ) ;
431
469
432
470
const requestCts = new CancellationTokenSource ( ) ;
0 commit comments