@@ -49,8 +49,12 @@ export class CodeActionOracle {
4949 }
5050
5151 private _onMarkerChanges ( resources : URI [ ] ) : void {
52- const { uri } = this . _editor . getModel ( ) ;
53- if ( resources . some ( resource => resource . toString ( ) === uri . toString ( ) ) ) {
52+ const model = this . _editor . getModel ( ) ;
53+ if ( ! model ) {
54+ return ;
55+ }
56+
57+ if ( resources . some ( resource => resource . toString ( ) === model . uri . toString ( ) ) ) {
5458 this . _autoTriggerTimer . cancelAndSet ( ( ) => {
5559 this . trigger ( { type : 'auto' } ) ;
5660 } , this . _delay ) ;
@@ -63,8 +67,11 @@ export class CodeActionOracle {
6367 } , this . _delay ) ;
6468 }
6569
66- private _getRangeOfMarker ( selection : Selection ) : Range {
70+ private _getRangeOfMarker ( selection : Selection ) : Range | undefined {
6771 const model = this . _editor . getModel ( ) ;
72+ if ( ! model ) {
73+ return undefined ;
74+ }
6875 for ( const marker of this . _markerService . read ( { resource : model . uri } ) ) {
6976 if ( Range . intersectRanges ( marker , selection ) ) {
7077 return Range . lift ( marker ) ;
@@ -76,7 +83,7 @@ export class CodeActionOracle {
7683 private _getRangeOfSelectionUnlessWhitespaceEnclosed ( trigger : CodeActionTrigger ) : Selection | undefined {
7784 const model = this . _editor . getModel ( ) ;
7885 const selection = this . _editor . getSelection ( ) ;
79- if ( selection . isEmpty ( ) && ! ( trigger . filter && trigger . filter . includeSourceActions ) ) {
86+ if ( model && selection && selection . isEmpty ( ) && ! ( trigger . filter && trigger . filter . includeSourceActions ) ) {
8087 const { lineNumber, column } = selection . getPosition ( ) ;
8188 const line = model . getLineContent ( lineNumber ) ;
8289 if ( line . length === 0 ) {
@@ -99,7 +106,7 @@ export class CodeActionOracle {
99106 }
100107 }
101108 }
102- return selection ;
109+ return selection ? selection : undefined ;
103110 }
104111
105112 private _createEventAndSignalChange ( trigger : CodeActionTrigger , selection : Selection | undefined ) : Thenable < CodeAction [ ] | undefined > {
@@ -114,6 +121,17 @@ export class CodeActionOracle {
114121 return Promise . resolve ( undefined ) ;
115122 } else {
116123 const model = this . _editor . getModel ( ) ;
124+ if ( ! model ) {
125+ // cancel
126+ this . _signalChange ( {
127+ trigger,
128+ rangeOrSelection : undefined ,
129+ position : undefined ,
130+ actions : undefined ,
131+ } ) ;
132+ return Promise . resolve ( undefined ) ;
133+ }
134+
117135 const markerRange = this . _getRangeOfMarker ( selection ) ;
118136 const position = markerRange ? markerRange . getStartPosition ( ) : selection . getStartPosition ( ) ;
119137 const actions = createCancelablePromise ( token => getCodeActions ( model , selection , trigger , token ) ) ;
@@ -135,16 +153,16 @@ export class CodeActionOracle {
135153
136154export interface CodeActionsComputeEvent {
137155 trigger : CodeActionTrigger ;
138- rangeOrSelection : Range | Selection ;
139- position : Position ;
140- actions : CancelablePromise < CodeAction [ ] > ;
156+ rangeOrSelection : Range | Selection | undefined ;
157+ position : Position | undefined ;
158+ actions : CancelablePromise < CodeAction [ ] > | undefined ;
141159}
142160
143161export class CodeActionModel {
144162
145163 private _editor : ICodeEditor ;
146164 private _markerService : IMarkerService ;
147- private _codeActionOracle : CodeActionOracle ;
165+ private _codeActionOracle ? : CodeActionOracle ;
148166 private _onDidChangeFixes = new Emitter < CodeActionsComputeEvent > ( ) ;
149167 private _disposables : IDisposable [ ] = [ ] ;
150168 private readonly _supportedCodeActions : IContextKey < string > ;
@@ -179,12 +197,13 @@ export class CodeActionModel {
179197 this . _onDidChangeFixes . fire ( undefined ) ;
180198 }
181199
182- if ( this . _editor . getModel ( )
183- && CodeActionProviderRegistry . has ( this . _editor . getModel ( ) )
200+ const model = this . _editor . getModel ( ) ;
201+ if ( model
202+ && CodeActionProviderRegistry . has ( model )
184203 && ! this . _editor . getConfiguration ( ) . readOnly ) {
185204
186205 const supportedActions : string [ ] = [ ] ;
187- for ( const provider of CodeActionProviderRegistry . all ( this . _editor . getModel ( ) ) ) {
206+ for ( const provider of CodeActionProviderRegistry . all ( model ) ) {
188207 if ( Array . isArray ( provider . providedCodeActionKinds ) ) {
189208 supportedActions . push ( ...provider . providedCodeActionKinds ) ;
190209 }
0 commit comments