@@ -27,7 +27,7 @@ import { isCodeEditor, isDiffEditor, ICodeEditor, IDiffEditor } from 'vs/editor/
2727import { IEditorGroupView , IEditorOpeningEvent , EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor' ;
2828import { ILabelService } from 'vs/platform/label/common/label' ;
2929import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
30- import { withNullAsUndefined } from 'vs/base/common/types' ;
30+ import { withNullAsUndefined , withUndefinedAsNull } from 'vs/base/common/types' ;
3131
3232type ICachedEditorInput = ResourceEditorInput | IFileEditorInput | DataUriEditorInput ;
3333
@@ -148,7 +148,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
148148 for ( const handler of this . openEditorHandlers ) {
149149 const result = handler ( event . editor , event . options , group ) ;
150150 if ( result && result . override ) {
151- event . prevent ( ( ( ) => result . override ) ) ;
151+ event . prevent ( ( ( ) => result . override ! . then ( editor => withNullAsUndefined ( editor ) ) ) ) ;
152152 break ;
153153 }
154154 }
@@ -359,12 +359,12 @@ export class EditorService extends Disposable implements EditorServiceImpl {
359359 }
360360
361361 // Open in targets
362- const result : Promise < IEditor > [ ] = [ ] ;
362+ const result : Promise < IEditor | null > [ ] = [ ] ;
363363 mapGroupToEditors . forEach ( ( editorsWithOptions , group ) => {
364364 result . push ( group . openEditors ( editorsWithOptions ) ) ;
365365 } ) ;
366366
367- return Promise . all ( result ) ;
367+ return Promise . all ( result ) . then ( editors => coalesce ( editors ) ) ;
368368 }
369369
370370 //#endregion
@@ -393,7 +393,10 @@ export class EditorService extends Disposable implements EditorServiceImpl {
393393
394394 let groups : IEditorGroup [ ] = [ ] ;
395395 if ( typeof group === 'number' ) {
396- groups . push ( this . editorGroupService . getGroup ( group ) ) ;
396+ const groupView = this . editorGroupService . getGroup ( group ) ;
397+ if ( groupView ) {
398+ groups . push ( groupView ) ;
399+ }
397400 } else if ( group ) {
398401 groups . push ( group ) ;
399402 } else {
@@ -455,7 +458,11 @@ export class EditorService extends Disposable implements EditorServiceImpl {
455458 } ) ;
456459
457460 const targetGroup = typeof group === 'number' ? this . editorGroupService . getGroup ( group ) : group ;
458- return targetGroup . replaceEditors ( typedEditors ) ;
461+ if ( targetGroup ) {
462+ return targetGroup . replaceEditors ( typedEditors ) ;
463+ }
464+
465+ return Promise . resolve ( ) ;
459466 }
460467
461468 //#endregion
@@ -480,7 +487,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
480487
481488 //#region createInput()
482489
483- createInput ( input : IEditorInputWithOptions | IEditorInput | IResourceEditor ) : EditorInput | null {
490+ createInput ( input : IEditorInputWithOptions | IEditorInput | IResourceEditor ) : EditorInput {
484491
485492 // Typed Editor Input Support (EditorInput)
486493 if ( input instanceof EditorInput ) {
@@ -498,9 +505,10 @@ export class EditorService extends Disposable implements EditorServiceImpl {
498505 if ( resourceSideBySideInput . masterResource && resourceSideBySideInput . detailResource ) {
499506 const masterInput = this . createInput ( { resource : resourceSideBySideInput . masterResource , forceFile : resourceSideBySideInput . forceFile } ) ;
500507 const detailInput = this . createInput ( { resource : resourceSideBySideInput . detailResource , forceFile : resourceSideBySideInput . forceFile } ) ;
508+ const label = resourceSideBySideInput . label || masterInput . getName ( ) || localize ( 'sideBySideLabels' , "{0} - {1}" , this . toDiffLabel ( masterInput ) , this . toDiffLabel ( detailInput ) ) ;
501509
502510 return new SideBySideEditorInput (
503- resourceSideBySideInput . label || masterInput . getName ( ) ,
511+ label ,
504512 typeof resourceSideBySideInput . description === 'string' ? resourceSideBySideInput . description : masterInput . getDescription ( ) ,
505513 detailInput ,
506514 masterInput
@@ -514,7 +522,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
514522 const rightInput = this . createInput ( { resource : resourceDiffInput . rightResource , forceFile : resourceDiffInput . forceFile } ) ;
515523 const label = resourceDiffInput . label || localize ( 'compareLabels' , "{0} ↔ {1}" , this . toDiffLabel ( leftInput ) , this . toDiffLabel ( rightInput ) ) ;
516524
517- return new DiffEditorInput ( label , resourceDiffInput . description , leftInput , rightInput ) ;
525+ return new DiffEditorInput ( label , withUndefinedAsNull ( resourceDiffInput . description ) , leftInput , rightInput ) ;
518526 }
519527
520528 // Untitled file support
@@ -539,17 +547,24 @@ export class EditorService extends Disposable implements EditorServiceImpl {
539547 return this . createOrGet ( resourceInput . resource , this . instantiationService , label , resourceInput . description , resourceInput . encoding , resourceInput . forceFile ) as EditorInput ;
540548 }
541549
542- return null ;
550+ throw new Error ( 'Unknown input type' ) ;
543551 }
544552
545- private createOrGet ( resource : URI , instantiationService : IInstantiationService , label : string , description : string , encoding ? : string , forceFile ? : boolean ) : ICachedEditorInput {
553+ private createOrGet ( resource : URI , instantiationService : IInstantiationService , label : string | undefined , description : string | undefined , encoding : string | undefined , forceFile : boolean | undefined ) : ICachedEditorInput {
546554 if ( EditorService . CACHE . has ( resource ) ) {
547- const input = EditorService . CACHE . get ( resource ) ;
555+ const input = EditorService . CACHE . get ( resource ) ! ;
548556 if ( input instanceof ResourceEditorInput ) {
549- input . setName ( label ) ;
550- input . setDescription ( description ) ;
557+ if ( label ) {
558+ input . setName ( label ) ;
559+ }
560+
561+ if ( description ) {
562+ input . setDescription ( description ) ;
563+ }
551564 } else if ( ! ( input instanceof DataUriEditorInput ) ) {
552- input . setPreferredEncoding ( encoding ) ;
565+ if ( encoding ) {
566+ input . setPreferredEncoding ( encoding ) ;
567+ }
553568 }
554569
555570 return input ;
@@ -582,9 +597,12 @@ export class EditorService extends Disposable implements EditorServiceImpl {
582597
583598 private toDiffLabel ( input : EditorInput ) : string | null {
584599 const res = input . getResource ( ) ;
600+ if ( ! res ) {
601+ return null ;
602+ }
585603
586604 // Do not try to extract any paths from simple untitled editors
587- if ( res && res . scheme === Schemas . untitled && ! this . untitledEditorService . hasAssociatedFilePath ( res ) ) {
605+ if ( res . scheme === Schemas . untitled && ! this . untitledEditorService . hasAssociatedFilePath ( res ) ) {
588606 return input . getName ( ) ;
589607 }
590608
0 commit comments