@@ -815,51 +815,81 @@ suite('Files - TextFileEditorModel', () => {
815
815
participant . dispose ( ) ;
816
816
} ) ;
817
817
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 ( ) {
819
819
const model : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/index_async.txt' ) , 'utf8' , undefined ) ;
820
820
821
- await testSaveFromSaveParticipant ( model , false ) ;
821
+ await testSaveFromSaveParticipant ( model , false , false , false ) ;
822
822
823
823
model . dispose ( ) ;
824
824
} ) ;
825
825
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 ( ) {
827
827
const model : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/index_async.txt' ) , 'utf8' , undefined ) ;
828
828
829
- await testSaveFromSaveParticipant ( model , true ) ;
829
+ await testSaveFromSaveParticipant ( model , true , false , false ) ;
830
830
831
831
model . dispose ( ) ;
832
832
} ) ;
833
833
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 ) ;
835
836
836
- let breakLoop = false ;
837
+ await testSaveFromSaveParticipant ( model , false , true , false ) ;
837
838
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 ) ;
843
854
844
- breakLoop = true ;
855
+ model . dispose ( ) ;
856
+ } ) ;
845
857
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 ( ) => {
846
862
if ( async ) {
847
863
await timeout ( 10 ) ;
848
864
}
849
- const newSavePromise = model . save ( ) ;
850
865
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
+ }
853
883
}
854
884
} ) ;
855
885
856
886
await model . resolve ( ) ;
857
887
model . updateTextEditorModel ( createTextBufferFactory ( 'foo' ) ) ;
858
888
859
- const savePromise = model . save ( ) ;
889
+ const savePromise = model . save ( force ? { force } : undefined ) ;
860
890
await savePromise ;
861
891
862
- participant . dispose ( ) ;
892
+ disposable . dispose ( ) ;
863
893
}
864
894
865
895
test ( 'backup and restore (simple)' , async function ( ) {
0 commit comments