@@ -38,23 +38,23 @@ import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/se
38
38
import { CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
39
39
40
40
const enum State {
41
- CREATE_SESSION ,
42
- INIT_UI ,
43
- WAIT_FOR_INPUT ,
44
- MAKE_REQUEST ,
45
- APPLY_RESPONSE ,
46
- SHOW_RESPONSE ,
47
- PAUSE ,
48
- DONE ,
41
+ CREATE_SESSION = 'CREATE_SESSION' ,
42
+ INIT_UI = 'INIT_UI' ,
43
+ WAIT_FOR_INPUT = 'WAIT_FOR_INPUT' ,
44
+ MAKE_REQUEST = 'MAKE_REQUEST' ,
45
+ APPLY_RESPONSE = 'APPLY_RESPONSE' ,
46
+ SHOW_RESPONSE = 'SHOW_RESPONSE' ,
47
+ PAUSE = 'PAUSE' ,
48
+ DONE = 'DONE' ,
49
49
}
50
50
51
51
const enum Message {
52
52
NONE = 0 ,
53
- END_SESSION = 2 ** 0 ,
54
- PAUSE_SESSION = 2 ** 1 ,
55
- CANCEL_REQUEST = 2 ** 2 ,
56
- CANCEL_INPUT = 2 ** 3 ,
57
- ACCEPT_INPUT = 2 ** 4
53
+ END_SESSION = 1 << 0 ,
54
+ PAUSE_SESSION = 1 << 1 ,
55
+ CANCEL_REQUEST = 1 << 2 ,
56
+ CANCEL_INPUT = 1 << 3 ,
57
+ ACCEPT_INPUT = 1 << 4
58
58
}
59
59
60
60
export interface InteractiveEditorRunOptions {
@@ -151,39 +151,13 @@ export class InteractiveEditorController implements IEditorContribution {
151
151
152
152
private async _nextState ( state : State , options : InteractiveEditorRunOptions | undefined ) : Promise < void > {
153
153
this . _logService . trace ( '[IE] setState to ' , state ) ;
154
- let nextState : State | undefined ;
155
- switch ( state ) {
156
- case State . CREATE_SESSION :
157
- nextState = await this . _createSession ( options ) ;
158
- break ;
159
- case State . INIT_UI :
160
- nextState = await this . _initUI ( ) ;
161
- break ;
162
- case State . WAIT_FOR_INPUT :
163
- nextState = await this . _waitForInput ( options ) ;
164
- break ;
165
- case State . MAKE_REQUEST :
166
- nextState = await this . _makeRequest ( ) ;
167
- break ;
168
- case State . APPLY_RESPONSE :
169
- nextState = await this . _applyResponse ( ) ;
170
- break ;
171
- case State . SHOW_RESPONSE :
172
- nextState = await this . _showResponse ( ) ;
173
- break ;
174
- case State . PAUSE :
175
- this . _pause ( ) ;
176
- break ;
177
- case State . DONE :
178
- this . _done ( ) ;
179
- break ;
180
- }
154
+ const nextState = await this [ state ] ( options ) ;
181
155
if ( nextState ) {
182
156
this . _nextState ( nextState , options ) ;
183
157
}
184
158
}
185
159
186
- private async _createSession ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . DONE | State . INIT_UI > {
160
+ private async [ State . CREATE_SESSION ] ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . DONE | State . INIT_UI > {
187
161
assertType ( this . _editor . hasModel ( ) ) ;
188
162
189
163
let session : Session | undefined = options ?. existingSession ;
@@ -228,7 +202,7 @@ export class InteractiveEditorController implements IEditorContribution {
228
202
return State . INIT_UI ;
229
203
}
230
204
231
- private async _initUI ( ) : Promise < State . WAIT_FOR_INPUT | State . SHOW_RESPONSE > {
205
+ private async [ State . INIT_UI ] ( ) : Promise < State . WAIT_FOR_INPUT | State . SHOW_RESPONSE > {
232
206
assertType ( this . _activeSession ) ;
233
207
234
208
// hide/cancel inline completions when invoking IE
@@ -299,7 +273,7 @@ export class InteractiveEditorController implements IEditorContribution {
299
273
}
300
274
}
301
275
302
- private async _waitForInput ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . DONE | State . PAUSE | State . WAIT_FOR_INPUT | State . MAKE_REQUEST > {
276
+ private async [ State . WAIT_FOR_INPUT ] ( options : InteractiveEditorRunOptions | undefined ) : Promise < State . DONE | State . PAUSE | State . WAIT_FOR_INPUT | State . MAKE_REQUEST > {
303
277
assertType ( this . _activeSession ) ;
304
278
305
279
this . _zone . show ( this . _activeSession . wholeRange . getEndPosition ( ) ) ;
@@ -363,7 +337,7 @@ export class InteractiveEditorController implements IEditorContribution {
363
337
return State . MAKE_REQUEST ;
364
338
}
365
339
366
- private async _makeRequest ( ) : Promise < State . APPLY_RESPONSE | State . PAUSE | State . DONE > {
340
+ private async [ State . MAKE_REQUEST ] ( ) : Promise < State . APPLY_RESPONSE | State . PAUSE | State . DONE > {
367
341
assertType ( this . _editor . hasModel ( ) ) ;
368
342
assertType ( this . _activeSession ) ;
369
343
assertType ( this . _activeSession . lastInput ) ;
@@ -430,7 +404,7 @@ export class InteractiveEditorController implements IEditorContribution {
430
404
}
431
405
}
432
406
433
- private async _applyResponse ( ) : Promise < State . SHOW_RESPONSE | State . DONE > {
407
+ private async [ State . APPLY_RESPONSE ] ( ) : Promise < State . SHOW_RESPONSE | State . DONE > {
434
408
assertType ( this . _activeSession ) ;
435
409
assertType ( this . _strategy ) ;
436
410
@@ -464,7 +438,7 @@ export class InteractiveEditorController implements IEditorContribution {
464
438
return State . SHOW_RESPONSE ;
465
439
}
466
440
467
- private async _showResponse ( ) : Promise < State . WAIT_FOR_INPUT | State . DONE > {
441
+ private async [ State . SHOW_RESPONSE ] ( ) : Promise < State . WAIT_FOR_INPUT | State . DONE > {
468
442
assertType ( this . _activeSession ) ;
469
443
assertType ( this . _strategy ) ;
470
444
@@ -513,7 +487,7 @@ export class InteractiveEditorController implements IEditorContribution {
513
487
return State . WAIT_FOR_INPUT ;
514
488
}
515
489
516
- private async _pause ( ) {
490
+ private async [ State . PAUSE ] ( ) {
517
491
assertType ( this . _activeSession ) ;
518
492
519
493
this . _ctxLastEditKind . reset ( ) ;
@@ -531,10 +505,10 @@ export class InteractiveEditorController implements IEditorContribution {
531
505
this . _activeSession = undefined ;
532
506
}
533
507
534
- private async _done ( ) {
508
+ private async [ State . DONE ] ( ) {
535
509
assertType ( this . _activeSession ) ;
536
510
this . _interactiveEditorSessionService . releaseSession ( this . _activeSession ) ;
537
- this . _pause ( ) ;
511
+ this [ State . PAUSE ] ( ) ;
538
512
}
539
513
540
514
// ---- controller API
0 commit comments