@@ -28,7 +28,7 @@ export class CodeActionOracle {
2828 constructor (
2929 private _editor : ICodeEditor ,
3030 private readonly _markerService : IMarkerService ,
31- private _signalChange : ( e : CodeActionsComputeEvent ) => any ,
31+ private _signalChange : ( newState : CodeActionsState ) => void ,
3232 private readonly _delay : number = 250 ,
3333 private readonly _progressService ?: IProgressService ,
3434 ) {
@@ -115,23 +115,13 @@ export class CodeActionOracle {
115115 private _createEventAndSignalChange ( trigger : CodeActionTrigger , selection : Selection | undefined ) : Promise < CodeAction [ ] | undefined > {
116116 if ( ! selection ) {
117117 // cancel
118- this . _signalChange ( {
119- trigger,
120- rangeOrSelection : undefined ,
121- position : undefined ,
122- actions : undefined ,
123- } ) ;
118+ this . _signalChange ( CodeActionsEmptyState ) ;
124119 return Promise . resolve ( undefined ) ;
125120 } else {
126121 const model = this . _editor . getModel ( ) ;
127122 if ( ! model ) {
128123 // cancel
129- this . _signalChange ( {
130- trigger,
131- rangeOrSelection : undefined ,
132- position : undefined ,
133- actions : undefined ,
134- } ) ;
124+ this . _signalChange ( CodeActionsEmptyState ) ;
135125 return Promise . resolve ( undefined ) ;
136126 }
137127
@@ -143,30 +133,39 @@ export class CodeActionOracle {
143133 this . _progressService . showWhile ( actions , 250 ) ;
144134 }
145135
146- this . _signalChange ( {
136+ this . _signalChange ( new CodeActionsTriggeredState (
147137 trigger ,
148- rangeOrSelection : selection ,
138+ selection ,
149139 position ,
150140 actions
151- } ) ;
141+ ) ) ;
152142 return actions ;
153143 }
154144 }
155145}
156146
157- export interface CodeActionsComputeEvent {
158- trigger : CodeActionTrigger ;
159- rangeOrSelection : Range | Selection | undefined ;
160- position : Position | undefined ;
161- actions : CancelablePromise < CodeAction [ ] > | undefined ;
147+ export const CodeActionsEmptyState = new class { readonly type = 'empty' ; } ;
148+
149+ export class CodeActionsTriggeredState {
150+ static readonly type = 'triggered' ;
151+ readonly type = CodeActionsTriggeredState . type ;
152+
153+ constructor (
154+ public readonly trigger : CodeActionTrigger ,
155+ public readonly rangeOrSelection : Range | Selection ,
156+ public readonly position : Position ,
157+ public readonly actions : CancelablePromise < CodeAction [ ] > ,
158+ ) { }
162159}
163160
161+ export type CodeActionsState = typeof CodeActionsEmptyState | CodeActionsTriggeredState ;
162+
164163export class CodeActionModel {
165164
166165 private _editor : ICodeEditor ;
167166 private _markerService : IMarkerService ;
168167 private _codeActionOracle ?: CodeActionOracle ;
169- private _onDidChangeFixes = new Emitter < CodeActionsComputeEvent > ( ) ;
168+ private _onDidChangeState = new Emitter < CodeActionsState > ( ) ;
170169 private _disposables : IDisposable [ ] = [ ] ;
171170 private readonly _supportedCodeActions : IContextKey < string > ;
172171
@@ -188,22 +187,23 @@ export class CodeActionModel {
188187 dispose ( this . _codeActionOracle ) ;
189188 }
190189
191- get onDidChangeFixes ( ) : Event < CodeActionsComputeEvent > {
192- return this . _onDidChangeFixes . event ;
190+ get onDidChangeState ( ) : Event < CodeActionsState > {
191+ return this . _onDidChangeState . event ;
193192 }
194193
195194 private _update ( ) : void {
196195
197196 if ( this . _codeActionOracle ) {
198197 this . _codeActionOracle . dispose ( ) ;
199198 this . _codeActionOracle = undefined ;
200- this . _onDidChangeFixes . fire ( undefined ) ;
199+ this . _onDidChangeState . fire ( CodeActionsEmptyState ) ;
201200 }
202201
203202 const model = this . _editor . getModel ( ) ;
204203 if ( model
205204 && CodeActionProviderRegistry . has ( model )
206- && ! this . _editor . getConfiguration ( ) . readOnly ) {
205+ && ! this . _editor . getConfiguration ( ) . readOnly
206+ ) {
207207
208208 const supportedActions : string [ ] = [ ] ;
209209 for ( const provider of CodeActionProviderRegistry . all ( model ) ) {
@@ -214,7 +214,7 @@ export class CodeActionModel {
214214
215215 this . _supportedCodeActions . set ( supportedActions . join ( ' ' ) ) ;
216216
217- this . _codeActionOracle = new CodeActionOracle ( this . _editor , this . _markerService , p => this . _onDidChangeFixes . fire ( p ) , undefined , this . _progressService ) ;
217+ this . _codeActionOracle = new CodeActionOracle ( this . _editor , this . _markerService , newState => this . _onDidChangeState . fire ( newState ) , undefined , this . _progressService ) ;
218218 this . _codeActionOracle . trigger ( { type : 'auto' } ) ;
219219 } else {
220220 this . _supportedCodeActions . reset ( ) ;
0 commit comments