@@ -815,51 +815,81 @@ suite('Files - TextFileEditorModel', () => {
815815 participant . dispose ( ) ;
816816 } ) ;
817817
818- test ( 'Save Participant, calling save from within is unsupported but does not explode (sync save)' , async function ( ) {
818+ test ( 'Save Participant, calling save from within is unsupported but does not explode (sync save, no model change )' , async function ( ) {
819819 const model : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/index_async.txt' ) , 'utf8' , undefined ) ;
820820
821- await testSaveFromSaveParticipant ( model , false ) ;
821+ await testSaveFromSaveParticipant ( model , false , false , false ) ;
822822
823823 model . dispose ( ) ;
824824 } ) ;
825825
826- test ( 'Save Participant, calling save from within is unsupported but does not explode (async save)' , async function ( ) {
826+ test ( 'Save Participant, calling save from within is unsupported but does not explode (async save, no model change )' , async function ( ) {
827827 const model : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/index_async.txt' ) , 'utf8' , undefined ) ;
828828
829- await testSaveFromSaveParticipant ( model , true ) ;
829+ await testSaveFromSaveParticipant ( model , true , false , false ) ;
830830
831831 model . dispose ( ) ;
832832 } ) ;
833833
834- async function testSaveFromSaveParticipant ( model : TextFileEditorModel , async : boolean ) : Promise < void > {
834+ test ( 'Save Participant, calling save from within is unsupported but does not explode (sync save, model change)' , async function ( ) {
835+ const model : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/index_async.txt' ) , 'utf8' , undefined ) ;
835836
836- let breakLoop = false ;
837+ await testSaveFromSaveParticipant ( model , false , true , false ) ;
837838
838- const participant = accessor . textFileService . files . addSaveParticipant ( {
839- participate : async model => {
840- if ( breakLoop ) {
841- return ;
842- }
839+ model . dispose ( ) ;
840+ } ) ;
841+
842+ test ( 'Save Participant, calling save from within is unsupported but does not explode (async save, model change)' , async function ( ) {
843+ const model : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/index_async.txt' ) , 'utf8' , undefined ) ;
844+
845+ await testSaveFromSaveParticipant ( model , true , true , false ) ;
846+
847+ model . dispose ( ) ;
848+ } ) ;
849+
850+ test ( 'Save Participant, calling save from within is unsupported but does not explode (force)' , async function ( ) {
851+ const model : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/index_async.txt' ) , 'utf8' , undefined ) ;
852+
853+ await testSaveFromSaveParticipant ( model , false , false , true ) ;
843854
844- breakLoop = true ;
855+ model . dispose ( ) ;
856+ } ) ;
845857
858+ async function testSaveFromSaveParticipant ( model : TextFileEditorModel , async : boolean , modelChange : boolean , force : boolean ) : Promise < void > {
859+
860+ const disposable = accessor . textFileService . files . addSaveParticipant ( {
861+ participate : async ( ) => {
846862 if ( async ) {
847863 await timeout ( 10 ) ;
848864 }
849- const newSavePromise = model . save ( ) ;
850865
851- // assert that this is the same promise as the outer one
852- assert . strictEqual ( savePromise , newSavePromise ) ;
866+ if ( modelChange ) {
867+ model . updateTextEditorModel ( createTextBufferFactory ( 'bar' ) ) ;
868+
869+ const newSavePromise = model . save ( force ? { force } : undefined ) ;
870+
871+ // assert that this is not the same promise as the outer one
872+ assert . notStrictEqual ( savePromise , newSavePromise ) ;
873+
874+ await newSavePromise ;
875+ } else {
876+ const newSavePromise = model . save ( force ? { force } : undefined ) ;
877+
878+ // assert that this is the same promise as the outer one
879+ assert . strictEqual ( savePromise , newSavePromise ) ;
880+
881+ await savePromise ;
882+ }
853883 }
854884 } ) ;
855885
856886 await model . resolve ( ) ;
857887 model . updateTextEditorModel ( createTextBufferFactory ( 'foo' ) ) ;
858888
859- const savePromise = model . save ( ) ;
889+ const savePromise = model . save ( force ? { force } : undefined ) ;
860890 await savePromise ;
861891
862- participant . dispose ( ) ;
892+ disposable . dispose ( ) ;
863893 }
864894
865895 test ( 'backup and restore (simple)' , async function ( ) {
0 commit comments