4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import { renderMarkdown } from 'vs/base/browser/markdownRenderer' ;
7
- import { Barrier , raceCancellationError } from 'vs/base/common/async' ;
7
+ import { Barrier , IdleValue , raceCancellationError } from 'vs/base/common/async' ;
8
8
import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
9
9
import { toErrorMessage } from 'vs/base/common/errorMessage' ;
10
10
import { Emitter , Event } from 'vs/base/common/event' ;
@@ -86,7 +86,7 @@ export class InteractiveEditorController implements IEditorContribution {
86
86
private _historyOffset : number = - 1 ;
87
87
88
88
private readonly _store = new DisposableStore ( ) ;
89
- private readonly _zone : InteractiveEditorZoneWidget ;
89
+ private readonly _zone : IdleValue < InteractiveEditorZoneWidget > ;
90
90
private readonly _ctxHasActiveRequest : IContextKey < boolean > ;
91
91
private readonly _ctxLastResponseType : IContextKey < undefined | InteractiveEditorResponseType > ;
92
92
private readonly _ctxDidEdit : IContextKey < boolean > ;
@@ -118,7 +118,7 @@ export class InteractiveEditorController implements IEditorContribution {
118
118
this . _ctxDidEdit = CTX_INTERACTIVE_EDITOR_DID_EDIT . bindTo ( contextKeyService ) ;
119
119
this . _ctxLastResponseType = CTX_INTERACTIVE_EDITOR_LAST_RESPONSE_TYPE . bindTo ( contextKeyService ) ;
120
120
this . _ctxLastFeedbackKind = CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK . bindTo ( contextKeyService ) ;
121
- this . _zone = this . _store . add ( _instaService . createInstance ( InteractiveEditorZoneWidget , this . _editor ) ) ;
121
+ this . _zone = new IdleValue ( ( ) => this . _store . add ( _instaService . createInstance ( InteractiveEditorZoneWidget , this . _editor ) ) ) ;
122
122
123
123
this . _store . add ( this . _editor . onDidChangeModel ( async e => {
124
124
if ( this . _activeSession || ! e . newModelUrl ) {
@@ -167,7 +167,7 @@ export class InteractiveEditorController implements IEditorContribution {
167
167
}
168
168
169
169
getWidgetPosition ( ) : Position | undefined {
170
- return this . _zone . position ;
170
+ return this . _zone . value . position ;
171
171
}
172
172
173
173
async run ( options : InteractiveEditorRunOptions | undefined ) : Promise < void > {
@@ -234,14 +234,14 @@ export class InteractiveEditorController implements IEditorContribution {
234
234
235
235
switch ( session . editMode ) {
236
236
case EditMode . Live :
237
- this . _strategy = this . _instaService . createInstance ( LiveStrategy , session , this . _editor , this . _zone . widget ) ;
237
+ this . _strategy = this . _instaService . createInstance ( LiveStrategy , session , this . _editor , this . _zone . value . widget ) ;
238
238
break ;
239
239
case EditMode . Preview :
240
- this . _strategy = this . _instaService . createInstance ( PreviewStrategy , session , this . _zone . widget ) ;
240
+ this . _strategy = this . _instaService . createInstance ( PreviewStrategy , session , this . _zone . value . widget ) ;
241
241
break ;
242
242
case EditMode . LivePreview :
243
243
default :
244
- this . _strategy = this . _instaService . createInstance ( LivePreviewStrategy , session , this . _editor , this . _zone . widget ) ;
244
+ this . _strategy = this . _instaService . createInstance ( LivePreviewStrategy , session , this . _editor , this . _zone . value . widget ) ;
245
245
break ;
246
246
}
247
247
@@ -265,11 +265,11 @@ export class InteractiveEditorController implements IEditorContribution {
265
265
} ] ) ;
266
266
this . _sessionStore . add ( toDisposable ( ( ) => wholeRangeDecoration . clear ( ) ) ) ;
267
267
268
- this . _zone . widget . updateSlashCommands ( this . _activeSession . session . slashCommands ?? [ ] ) ;
269
- this . _zone . widget . placeholder = this . _getPlaceholderText ( ) ;
270
- this . _zone . widget . value = this . _activeSession . lastInput ?? '' ;
271
- this . _zone . widget . updateInfo ( this . _activeSession . session . message ?? localize ( 'welcome.1' , "AI-generated code may be incorrect" ) ) ;
272
- this . _zone . show ( this . _activeSession . wholeRange . getEndPosition ( ) ) ;
268
+ this . _zone . value . widget . updateSlashCommands ( this . _activeSession . session . slashCommands ?? [ ] ) ;
269
+ this . _zone . value . widget . placeholder = this . _getPlaceholderText ( ) ;
270
+ this . _zone . value . widget . value = this . _activeSession . lastInput ?? '' ;
271
+ 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 . getEndPosition ( ) ) ;
273
273
274
274
this . _sessionStore . add ( this . _editor . onDidChangeModel ( ( e ) => {
275
275
const msg = this . _activeSession ?. lastExchange
@@ -357,12 +357,12 @@ export class InteractiveEditorController implements IEditorContribution {
357
357
private async [ State . WAIT_FOR_INPUT ] ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . ACCEPT | State . CANCEL | State . PAUSE | State . WAIT_FOR_INPUT | State . MAKE_REQUEST > {
358
358
assertType ( this . _activeSession ) ;
359
359
360
- this . _zone . widget . placeholder = this . _getPlaceholderText ( ) ;
361
- this . _zone . show ( this . _activeSession . wholeRange . getEndPosition ( ) ) ;
360
+ this . _zone . value . widget . placeholder = this . _getPlaceholderText ( ) ;
361
+ this . _zone . value . show ( this . _activeSession . wholeRange . getEndPosition ( ) ) ;
362
362
363
363
if ( options ?. message ) {
364
- this . _zone . widget . value = options ?. message ;
365
- this . _zone . widget . selectAll ( ) ;
364
+ this . _zone . value . widget . value = options ?. message ;
365
+ this . _zone . value . widget . selectAll ( ) ;
366
366
delete options ?. message ;
367
367
}
368
368
@@ -382,7 +382,7 @@ export class InteractiveEditorController implements IEditorContribution {
382
382
msgListener . dispose ( ) ;
383
383
}
384
384
385
- this . _zone . widget . selectAll ( ) ;
385
+ this . _zone . value . widget . selectAll ( ) ;
386
386
387
387
if ( message & ( Message . CANCEL_INPUT | Message . CANCEL_SESSION ) ) {
388
388
return State . CANCEL ;
@@ -396,11 +396,11 @@ export class InteractiveEditorController implements IEditorContribution {
396
396
return State . PAUSE ;
397
397
}
398
398
399
- if ( ! this . _zone . widget . value ) {
399
+ if ( ! this . _zone . value . widget . value ) {
400
400
return State . WAIT_FOR_INPUT ;
401
401
}
402
402
403
- const input = this . _zone . widget . value ;
403
+ const input = this . _zone . value . widget . value ;
404
404
405
405
if ( ! InteractiveEditorController . _promptHistory . includes ( input ) ) {
406
406
InteractiveEditorController . _promptHistory . unshift ( input ) ;
@@ -437,7 +437,7 @@ export class InteractiveEditorController implements IEditorContribution {
437
437
requestCts . cancel ( ) ;
438
438
} ) ;
439
439
440
- const typeListener = this . _zone . widget . onDidChangeInput ( ( ) => {
440
+ const typeListener = this . _zone . value . widget . onDidChangeInput ( ( ) => {
441
441
requestCts . cancel ( ) ;
442
442
} ) ;
443
443
@@ -454,8 +454,8 @@ export class InteractiveEditorController implements IEditorContribution {
454
454
let response : EditResponse | MarkdownResponse | ErrorResponse | EmptyResponse ;
455
455
let reply : IInteractiveEditorResponse | null | undefined ;
456
456
try {
457
- this . _zone . widget . updateProgress ( true ) ;
458
- this . _zone . widget . updateInfo ( ! this . _activeSession . lastExchange ? localize ( 'thinking' , "Thinking\u2026" ) : '' ) ;
457
+ this . _zone . value . widget . updateProgress ( true ) ;
458
+ this . _zone . value . widget . updateInfo ( ! this . _activeSession . lastExchange ? localize ( 'thinking' , "Thinking\u2026" ) : '' ) ;
459
459
this . _ctxHasActiveRequest . set ( true ) ;
460
460
reply = await raceCancellationError ( Promise . resolve ( task ) , requestCts . token ) ;
461
461
@@ -472,8 +472,8 @@ export class InteractiveEditorController implements IEditorContribution {
472
472
473
473
} finally {
474
474
this . _ctxHasActiveRequest . set ( false ) ;
475
- this . _zone . widget . updateProgress ( false ) ;
476
- this . _zone . widget . updateInfo ( '' ) ;
475
+ this . _zone . value . widget . updateProgress ( false ) ;
476
+ this . _zone . value . widget . updateInfo ( '' ) ;
477
477
this . _log ( 'request took' , sw . elapsed ( ) , this . _activeSession . provider . debugName ) ;
478
478
479
479
}
@@ -500,7 +500,7 @@ export class InteractiveEditorController implements IEditorContribution {
500
500
const { response } = this . _activeSession . lastExchange ! ;
501
501
if ( response instanceof EditResponse ) {
502
502
// edit response -> complex...
503
- this . _zone . widget . updateMarkdownMessage ( undefined ) ;
503
+ this . _zone . value . widget . updateMarkdownMessage ( undefined ) ;
504
504
505
505
const canContinue = this . _strategy . checkChanges ( response ) ;
506
506
if ( ! canContinue ) {
@@ -540,27 +540,27 @@ export class InteractiveEditorController implements IEditorContribution {
540
540
541
541
if ( response instanceof EmptyResponse ) {
542
542
// show status message
543
- this . _zone . widget . updateStatus ( localize ( 'empty' , "No results, please refine your input and try again" ) , { classes : [ 'warn' ] } ) ;
543
+ this . _zone . value . widget . updateStatus ( localize ( 'empty' , "No results, please refine your input and try again" ) , { classes : [ 'warn' ] } ) ;
544
544
return State . WAIT_FOR_INPUT ;
545
545
546
546
} else if ( response instanceof ErrorResponse ) {
547
547
// show error
548
548
if ( ! response . isCancellation ) {
549
- this . _zone . widget . updateStatus ( response . message , { classes : [ 'error' ] } ) ;
549
+ this . _zone . value . widget . updateStatus ( response . message , { classes : [ 'error' ] } ) ;
550
550
}
551
551
552
552
} else if ( response instanceof MarkdownResponse ) {
553
553
// clear status, show MD message
554
554
const renderedMarkdown = renderMarkdown ( response . raw . message , { inline : true } ) ;
555
- this . _zone . widget . updateStatus ( '' ) ;
556
- this . _zone . widget . updateMarkdownMessage ( renderedMarkdown . element ) ;
557
- this . _zone . widget . updateToolbar ( true ) ;
558
- this . _zone . widget . updateMarkdownMessageExpansionState ( this . _activeSession . lastExpansionState ) ;
555
+ this . _zone . value . widget . updateStatus ( '' ) ;
556
+ this . _zone . value . widget . updateMarkdownMessage ( renderedMarkdown . element ) ;
557
+ this . _zone . value . widget . updateToolbar ( true ) ;
558
+ this . _zone . value . widget . updateMarkdownMessageExpansionState ( this . _activeSession . lastExpansionState ) ;
559
559
560
560
} else if ( response instanceof EditResponse ) {
561
561
// edit response -> complex...
562
- this . _zone . widget . updateMarkdownMessage ( undefined ) ;
563
- this . _zone . widget . updateToolbar ( true ) ;
562
+ this . _zone . value . widget . updateMarkdownMessage ( undefined ) ;
563
+ this . _zone . value . widget . updateToolbar ( true ) ;
564
564
565
565
const canContinue = this . _strategy . checkChanges ( response ) ;
566
566
if ( ! canContinue ) {
@@ -586,7 +586,7 @@ export class InteractiveEditorController implements IEditorContribution {
586
586
this . _ctxLastResponseType . reset ( ) ;
587
587
this . _ctxLastFeedbackKind . reset ( ) ;
588
588
589
- this . _zone . hide ( ) ;
589
+ this . _zone . value . hide ( ) ;
590
590
591
591
// Return focus to the editor only if the current focus is within the editor widget
592
592
if ( this . _editor . hasWidgetFocus ( ) ) {
@@ -627,9 +627,9 @@ export class InteractiveEditorController implements IEditorContribution {
627
627
}
628
628
629
629
arrowOut ( up : boolean ) : void {
630
- if ( this . _zone . position && this . _editor . hasModel ( ) ) {
630
+ if ( this . _zone . value . position && this . _editor . hasModel ( ) ) {
631
631
const { column } = this . _editor . getPosition ( ) ;
632
- const { lineNumber } = this . _zone . position ;
632
+ const { lineNumber } = this . _zone . value . position ;
633
633
const newLine = up ? lineNumber : lineNumber + 1 ;
634
634
this . _editor . setPosition ( { lineNumber : newLine , column } ) ;
635
635
this . _editor . focus ( ) ;
@@ -641,7 +641,7 @@ export class InteractiveEditorController implements IEditorContribution {
641
641
}
642
642
643
643
focus ( ) : void {
644
- this . _zone . widget . focus ( ) ;
644
+ this . _zone . value . widget . focus ( ) ;
645
645
}
646
646
647
647
populateHistory ( up : boolean ) {
@@ -652,8 +652,8 @@ export class InteractiveEditorController implements IEditorContribution {
652
652
const pos = ( len + this . _historyOffset + ( up ? 1 : - 1 ) ) % len ;
653
653
const entry = InteractiveEditorController . _promptHistory [ pos ] ;
654
654
655
- this . _zone . widget . value = entry ;
656
- this . _zone . widget . selectAll ( ) ;
655
+ this . _zone . value . widget . value = entry ;
656
+ this . _zone . value . widget . selectAll ( ) ;
657
657
this . _historyOffset = pos ;
658
658
}
659
659
@@ -665,7 +665,7 @@ export class InteractiveEditorController implements IEditorContribution {
665
665
666
666
updateExpansionState ( expand : boolean ) {
667
667
if ( this . _activeSession ) {
668
- this . _zone . widget . updateMarkdownMessageExpansionState ( expand ) ;
668
+ this . _zone . value . widget . updateMarkdownMessageExpansionState ( expand ) ;
669
669
this . _activeSession . lastExpansionState = expand ;
670
670
}
671
671
}
@@ -675,7 +675,7 @@ export class InteractiveEditorController implements IEditorContribution {
675
675
const kind = helpful ? InteractiveEditorResponseFeedbackKind . Helpful : InteractiveEditorResponseFeedbackKind . Unhelpful ;
676
676
this . _activeSession . provider . handleInteractiveEditorResponseFeedback ?.( this . _activeSession . session , this . _activeSession . lastExchange . response . raw , kind ) ;
677
677
this . _ctxLastFeedbackKind . set ( helpful ? 'helpful' : 'unhelpful' ) ;
678
- this . _zone . widget . updateStatus ( 'Thank you for your feedback!' , { resetAfter : 1250 } ) ;
678
+ this . _zone . value . widget . updateStatus ( 'Thank you for your feedback!' , { resetAfter : 1250 } ) ;
679
679
}
680
680
}
681
681
0 commit comments