@@ -99,8 +99,6 @@ export class InteractiveEditorController implements IEditorContribution {
99
99
private _activeSession ?: Session ;
100
100
private _strategy ?: EditModeStrategy ;
101
101
private _ignoreModelContentChanged = false ;
102
- private _initialRender ?: boolean = true ;
103
- private _updateEditMode ?: boolean = false ;
104
102
105
103
constructor (
106
104
private readonly _editor : ICodeEditor ,
@@ -195,6 +193,13 @@ export class InteractiveEditorController implements IEditorContribution {
195
193
196
194
// ---- state machine
197
195
196
+ private _showWidget ( initialRender : boolean = false , hasEditResponse : boolean = false ) {
197
+ assertType ( this . _activeSession ) ;
198
+ const selectionRange = this . _activeSession . wholeRange . value ;
199
+ const widgetPosition = this . _strategy ?. getWidgetPosition ( initialRender , selectionRange , hasEditResponse ) ;
200
+ this . _zone . value . showWidget ( selectionRange , widgetPosition ) ;
201
+ }
202
+
198
203
protected async _nextState ( state : State , options : InteractiveEditorRunOptions | undefined ) : Promise < void > {
199
204
this . _log ( 'setState to ' , state ) ;
200
205
const nextState = await this [ state ] ( options ) ;
@@ -234,30 +239,7 @@ export class InteractiveEditorController implements IEditorContribution {
234
239
return State . CANCEL ;
235
240
}
236
241
237
- this . _initializeStratetgy ( session ) ;
238
- this . _activeSession = session ;
239
- this . _store . add ( this . _configurationService . onDidChangeConfiguration ( ( e ) => {
240
-
241
- console . log ( 'e : ' , e ) ;
242
- console . log ( 'e.affectsConfiguration(interactiveEditor.editModes) : ' , e . affectsConfiguration ( 'interactiveEditor.editMode' ) ) ;
243
- console . log ( 'this._activeSession : ' , this . _activeSession ) ;
244
-
245
- if ( e . affectsConfiguration ( 'interactiveEditor.editMode' ) ) {
246
-
247
- console . log ( 'entered into inner if loop of onDidChangeConfiguration' ) ;
248
- console . log ( 'this._getMode() : ' , this . _getMode ( ) ) ;
249
-
250
- this . _updateEditMode = true ;
251
- }
252
- } ) ) ;
253
-
254
- return State . INIT_UI ;
255
- }
256
-
257
- private _initializeStratetgy ( session : Session ) : void {
258
-
259
- console . log ( 'inside of initial strategy' ) ;
260
-
242
+ session . editMode = this . _getMode ( ) ;
261
243
switch ( session . editMode ) {
262
244
case EditMode . Live :
263
245
this . _strategy = this . _instaService . createInstance ( LiveStrategy , session , this . _editor , this . _zone . value . widget ) ;
@@ -270,64 +252,14 @@ export class InteractiveEditorController implements IEditorContribution {
270
252
this . _strategy = this . _instaService . createInstance ( LivePreviewStrategy , session , this . _editor , this . _zone . value . widget ) ;
271
253
break ;
272
254
}
273
- }
274
-
275
- private _showWidget ( initialRender : boolean = false , updateEditMode : boolean = false ) {
276
-
277
- console . log ( 'inside of _showWidget' ) ;
278
- console . log ( 'initialRender : ' , initialRender ) ;
279
- console . log ( 'updateEditMode : ' , updateEditMode ) ;
280
255
281
- assertType ( this . _activeSession ) ;
282
- const selectionRange = this . _activeSession . wholeRange . value ;
283
-
284
- if ( ! initialRender ) {
285
- console . log ( 'initial render is false' ) ;
286
- console . log ( 'this._activeSession.lastPosition : ' , this . _activeSession . lastPosition ) ;
287
- if ( this . _activeSession . lastPosition ) {
288
- console . log ( 'inside if' ) ;
289
- if ( updateEditMode ) {
290
- console . log ( 'inside if' ) ;
291
- this . _zone . value . showWidget ( selectionRange , this . _strategy ?. getWidgetPosition ( initialRender , selectionRange ) ) ;
292
- } else {
293
- console . log ( 'inside else' ) ;
294
- this . _zone . value . showWidget ( selectionRange , this . _activeSession . lastPosition ) ;
295
- }
296
- } else {
297
- console . log ( 'inside else' ) ;
298
- const widgetPosition = this . _strategy ?. getWidgetPosition ( initialRender , selectionRange ) ;
299
- this . _activeSession . lastPosition = widgetPosition ;
300
- this . _zone . value . showWidget ( selectionRange , widgetPosition ) ;
301
- }
302
- } else {
303
- console . log ( 'initial render is true' ) ;
304
- console . log ( 'this._activeSession.lastPosition : ' , this . _activeSession . lastPosition ) ;
305
-
306
- if ( this . _activeSession . lastPosition ) {
307
- console . log ( 'inside if' ) ;
308
- if ( updateEditMode ) {
309
- console . log ( 'inside if' ) ;
310
- this . _zone . value . showWidget ( selectionRange , this . _strategy ?. getWidgetPosition ( initialRender , selectionRange ) ) ;
311
- this . _activeSession . lastPosition = undefined ;
312
- } else {
313
- console . log ( 'inside else' ) ;
314
- this . _zone . value . showWidget ( selectionRange , this . _activeSession . lastPosition ) ;
315
- }
316
- } else {
317
- console . log ( 'inside else' ) ;
318
- this . _zone . value . showWidget ( selectionRange , this . _strategy ?. getWidgetPosition ( initialRender , selectionRange ) ) ;
319
- }
320
- }
256
+ this . _activeSession = session ;
257
+ return State . INIT_UI ;
321
258
}
322
259
323
260
private async [ State . INIT_UI ] ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . WAIT_FOR_INPUT | State . SHOW_RESPONSE | State . APPLY_RESPONSE > {
324
261
assertType ( this . _activeSession ) ;
325
262
326
- if ( this . _updateEditMode ) {
327
- this . _activeSession . editMode = this . _getMode ( ) ;
328
- this . _initializeStratetgy ( this . _activeSession ) ;
329
- }
330
-
331
263
// hide/cancel inline completions when invoking IE
332
264
InlineCompletionsController . get ( this . _editor ) ?. hide ( ) ;
333
265
@@ -346,11 +278,7 @@ export class InteractiveEditorController implements IEditorContribution {
346
278
this . _zone . value . widget . value = this . _activeSession . lastInput ?? '' ;
347
279
this . _zone . value . widget . updateInfo ( this . _activeSession . session . message ?? localize ( 'welcome.1' , "AI-generated code may be incorrect" ) ) ;
348
280
this . _zone . value . widget . preferredExpansionState = this . _activeSession . lastExpansionState ;
349
-
350
- console . log ( 'inside of init ui before show widget' ) ;
351
-
352
- this . _initialRender = true ;
353
- this . _showWidget ( this . _initialRender , this . _updateEditMode ) ;
281
+ this . _showWidget ( true ) ;
354
282
355
283
this . _sessionStore . add ( this . _editor . onDidChangeModel ( ( e ) => {
356
284
const msg = this . _activeSession ?. lastExchange
@@ -438,13 +366,7 @@ export class InteractiveEditorController implements IEditorContribution {
438
366
private async [ State . WAIT_FOR_INPUT ] ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . ACCEPT | State . CANCEL | State . PAUSE | State . WAIT_FOR_INPUT | State . MAKE_REQUEST > {
439
367
assertType ( this . _activeSession ) ;
440
368
441
-
442
- console . log ( 'inside of wait for input' ) ;
443
-
444
369
this . _zone . value . widget . placeholder = this . _getPlaceholderText ( ) ;
445
- this . _showWidget ( this . _initialRender , this . _updateEditMode ) ;
446
- this . _initialRender = false ;
447
- this . _updateEditMode = false ;
448
370
449
371
if ( options ?. message ) {
450
372
this . _zone . value . widget . value = options ?. message ;
@@ -483,9 +405,6 @@ export class InteractiveEditorController implements IEditorContribution {
483
405
}
484
406
485
407
if ( ! this . _zone . value . widget . value ) {
486
-
487
- console . log ( 'before the case when we call WAIT_FOR_INPUT' ) ;
488
-
489
408
return State . WAIT_FOR_INPUT ;
490
409
}
491
410
@@ -515,9 +434,6 @@ export class InteractiveEditorController implements IEditorContribution {
515
434
private async [ State . MAKE_REQUEST ] ( ) : Promise < State . APPLY_RESPONSE | State . PAUSE | State . CANCEL | State . ACCEPT > {
516
435
assertType ( this . _editor . hasModel ( ) ) ;
517
436
assertType ( this . _activeSession ) ;
518
-
519
- console . log ( 'this._activeSession.lastInput : ' , this . _activeSession . lastInput ) ;
520
-
521
437
assertType ( this . _activeSession . lastInput ) ;
522
438
523
439
const requestCts = new CancellationTokenSource ( ) ;
@@ -628,6 +544,7 @@ export class InteractiveEditorController implements IEditorContribution {
628
544
assertType ( this . _strategy ) ;
629
545
630
546
const { response } = this . _activeSession . lastExchange ! ;
547
+ this . _showWidget ( false , response instanceof EditResponse ) ; // this._updateEditMode, r
631
548
632
549
this . _ctxLastResponseType . set ( response instanceof EditResponse || response instanceof MarkdownResponse
633
550
? response . raw . type
0 commit comments