@@ -51,6 +51,9 @@ export class DefinitionAction extends EditorAction {
5151 }
5252
5353 public run ( accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
54+ if ( ! editor . hasModel ( ) ) {
55+ return Promise . resolve ( undefined ) ;
56+ }
5457 const notificationService = accessor . get ( INotificationService ) ;
5558 const editorService = accessor . get ( ICodeEditorService ) ;
5659 const progressService = accessor . get ( IProgressService ) ;
@@ -112,14 +115,14 @@ export class DefinitionAction extends EditorAction {
112115 return getDefinitionsAtPosition ( model , position , token ) ;
113116 }
114117
115- protected _getNoResultFoundMessage ( info ? : IWordAtPosition ) : string {
118+ protected _getNoResultFoundMessage ( info : IWordAtPosition | null ) : string {
116119 return info && info . word
117120 ? nls . localize ( 'noResultWord' , "No definition found for '{0}'" , info . word )
118121 : nls . localize ( 'generic.noResults' , "No definition found" ) ;
119122 }
120123
121124 protected _getMetaTitle ( model : ReferencesModel ) : string {
122- return model . references . length > 1 && nls . localize ( 'meta.title' , " – {0} definitions" , model . references . length ) ;
125+ return model . references . length > 1 ? nls . localize ( 'meta.title' , " – {0} definitions" , model . references . length ) : '' ;
123126 }
124127
125128 private async _onResult ( editorService : ICodeEditorService , editor : ICodeEditor , model : ReferencesModel ) : Promise < void > {
@@ -129,21 +132,23 @@ export class DefinitionAction extends EditorAction {
129132
130133 if ( this . _configuration . openInPeek ) {
131134 this . _openInPeek ( editorService , editor , model ) ;
132- } else {
135+ } else if ( editor . hasModel ( ) ) {
133136 const next = model . nearestReference ( editor . getModel ( ) . uri , editor . getPosition ( ) ) ;
134- const targetEditor = await this . _openReference ( editor , editorService , next , this . _configuration . openToSide ) ;
135- if ( targetEditor && model . references . length > 1 ) {
136- this . _openInPeek ( editorService , targetEditor , model ) ;
137- } else {
138- model . dispose ( ) ;
137+ if ( next ) {
138+ const targetEditor = await this . _openReference ( editor , editorService , next , this . _configuration . openToSide ) ;
139+ if ( targetEditor && model . references . length > 1 ) {
140+ this . _openInPeek ( editorService , targetEditor , model ) ;
141+ } else {
142+ model . dispose ( ) ;
143+ }
139144 }
140145 }
141146 }
142147
143- private _openReference ( editor : ICodeEditor , editorService : ICodeEditorService , reference : Location | LocationLink , sideBySide : boolean ) : Promise < ICodeEditor > {
148+ private _openReference ( editor : ICodeEditor , editorService : ICodeEditorService , reference : Location | LocationLink , sideBySide : boolean ) : Promise < ICodeEditor | null > {
144149 // range is the target-selection-range when we have one
145150 // and the the fallback is the 'full' range
146- let range : IRange = undefined ;
151+ let range : IRange | undefined = undefined ;
147152 if ( isLocationLink ( reference ) ) {
148153 range = reference . targetSelectionRange ;
149154 }
@@ -265,14 +270,14 @@ export class DeclarationAction extends DefinitionAction {
265270 return getDeclarationsAtPosition ( model , position , token ) ;
266271 }
267272
268- protected _getNoResultFoundMessage ( info ? : IWordAtPosition ) : string {
273+ protected _getNoResultFoundMessage ( info : IWordAtPosition | null ) : string {
269274 return info && info . word
270275 ? nls . localize ( 'decl.noResultWord' , "No declaration found for '{0}'" , info . word )
271276 : nls . localize ( 'decl.generic.noResults' , "No declaration found" ) ;
272277 }
273278
274279 protected _getMetaTitle ( model : ReferencesModel ) : string {
275- return model . references . length > 1 && nls . localize ( 'decl.meta.title' , " – {0} declarations" , model . references . length ) ;
280+ return model . references . length > 1 ? nls . localize ( 'decl.meta.title' , " – {0} declarations" , model . references . length ) : '' ;
276281 }
277282}
278283
@@ -295,14 +300,14 @@ export class GoToDeclarationAction extends DeclarationAction {
295300 } ) ;
296301 }
297302
298- protected _getNoResultFoundMessage ( info ? : IWordAtPosition ) : string {
303+ protected _getNoResultFoundMessage ( info : IWordAtPosition | null ) : string {
299304 return info && info . word
300305 ? nls . localize ( 'decl.noResultWord' , "No declaration found for '{0}'" , info . word )
301306 : nls . localize ( 'decl.generic.noResults' , "No declaration found" ) ;
302307 }
303308
304309 protected _getMetaTitle ( model : ReferencesModel ) : string {
305- return model . references . length > 1 && nls . localize ( 'decl.meta.title' , " – {0} declarations" , model . references . length ) ;
310+ return model . references . length > 1 ? nls . localize ( 'decl.meta.title' , " – {0} declarations" , model . references . length ) : '' ;
306311 }
307312}
308313
@@ -329,14 +334,14 @@ export class ImplementationAction extends DefinitionAction {
329334 return getImplementationsAtPosition ( model , position , token ) ;
330335 }
331336
332- protected _getNoResultFoundMessage ( info ? : IWordAtPosition ) : string {
337+ protected _getNoResultFoundMessage ( info : IWordAtPosition | null ) : string {
333338 return info && info . word
334339 ? nls . localize ( 'goToImplementation.noResultWord' , "No implementation found for '{0}'" , info . word )
335340 : nls . localize ( 'goToImplementation.generic.noResults' , "No implementation found" ) ;
336341 }
337342
338343 protected _getMetaTitle ( model : ReferencesModel ) : string {
339- return model . references . length > 1 && nls . localize ( 'meta.implementations.title' , " – {0} implementations" , model . references . length ) ;
344+ return model . references . length > 1 ? nls . localize ( 'meta.implementations.title' , " – {0} implementations" , model . references . length ) : '' ;
340345 }
341346}
342347
@@ -387,14 +392,14 @@ export class TypeDefinitionAction extends DefinitionAction {
387392 return getTypeDefinitionsAtPosition ( model , position , token ) ;
388393 }
389394
390- protected _getNoResultFoundMessage ( info ? : IWordAtPosition ) : string {
395+ protected _getNoResultFoundMessage ( info : IWordAtPosition | null ) : string {
391396 return info && info . word
392397 ? nls . localize ( 'goToTypeDefinition.noResultWord' , "No type definition found for '{0}'" , info . word )
393398 : nls . localize ( 'goToTypeDefinition.generic.noResults' , "No type definition found" ) ;
394399 }
395400
396401 protected _getMetaTitle ( model : ReferencesModel ) : string {
397- return model . references . length > 1 && nls . localize ( 'meta.typeDefinitions.title' , " – {0} type definitions" , model . references . length ) ;
402+ return model . references . length > 1 ? nls . localize ( 'meta.typeDefinitions.title' , " – {0} type definitions" , model . references . length ) : '' ;
398403 }
399404}
400405
0 commit comments