@@ -24,6 +24,9 @@ import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
24
24
import { ResourceMap , ResourceSet } from 'vs/base/common/map' ;
25
25
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService' ;
26
26
import { URI } from 'vs/base/common/uri' ;
27
+ import { Registry } from 'vs/platform/registry/common/platform' ;
28
+ import { Extensions , IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry' ;
29
+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
27
30
28
31
class BulkEdit {
29
32
@@ -145,6 +148,7 @@ export class BulkEditService implements IBulkEditService {
145
148
@ILifecycleService private readonly _lifecycleService : ILifecycleService ,
146
149
@IDialogService private readonly _dialogService : IDialogService ,
147
150
@IWorkingCopyService private readonly _workingCopyService : IWorkingCopyService ,
151
+ @IConfigurationService private readonly _configService : IConfigurationService ,
148
152
) { }
149
153
150
154
setPreviewHandler ( handler : IBulkEditPreviewHandler ) : IDisposable {
@@ -218,18 +222,13 @@ export class BulkEditService implements IBulkEditService {
218
222
219
223
let listener : IDisposable | undefined ;
220
224
try {
221
- listener = this . _lifecycleService . onBeforeShutdown ( e => e . veto ( this . shouldVeto ( label , e . reason ) , 'veto.blukEditService' ) ) ;
222
- const resources = new ResourceSet ( await bulkEdit . perform ( ) ) ;
223
-
224
- if ( options ?. saveWhenDone ) {
225
- // with `saveWhenDone` enabled loop over all dirty working copies and trigger save
226
- // for those that were involved in this bulk edit operation.
227
- const saves = this . _workingCopyService . dirtyWorkingCopies . map ( async copy => {
228
- if ( resources . has ( copy . resource ) ) {
229
- await copy . save ( ) ;
230
- }
231
- } ) ;
232
- await Promise . allSettled ( saves ) ;
225
+ listener = this . _lifecycleService . onBeforeShutdown ( e => e . veto ( this . _shouldVeto ( label , e . reason ) , 'veto.blukEditService' ) ) ;
226
+ const resources = await bulkEdit . perform ( ) ;
227
+
228
+ // when enabled (option AND setting) loop over all dirty working copies and trigger save
229
+ // for those that were involved in this bulk edit operation.
230
+ if ( options ?. respectAutoSaveConfig && this . _configService . getValue ( autoSaveSetting ) === true && resources . length > 1 ) {
231
+ await this . _saveAll ( resources ) ;
233
232
}
234
233
235
234
return { ariaSummary : bulkEdit . ariaMessage ( ) } ;
@@ -244,7 +243,23 @@ export class BulkEditService implements IBulkEditService {
244
243
}
245
244
}
246
245
247
- private async shouldVeto ( label : string | undefined , reason : ShutdownReason ) : Promise < boolean > {
246
+ private async _saveAll ( resources : readonly URI [ ] ) {
247
+ const set = new ResourceSet ( resources ) ;
248
+ const saves = this . _workingCopyService . dirtyWorkingCopies . map ( async ( copy ) => {
249
+ if ( set . has ( copy . resource ) ) {
250
+ await copy . save ( ) ;
251
+ }
252
+ } ) ;
253
+
254
+ const result = await Promise . allSettled ( saves ) ;
255
+ for ( const item of result ) {
256
+ if ( item . status === 'rejected' ) {
257
+ this . _logService . warn ( item . reason ) ;
258
+ }
259
+ }
260
+ }
261
+
262
+ private async _shouldVeto ( label : string | undefined , reason : ShutdownReason ) : Promise < boolean > {
248
263
label = label || localize ( 'fileOperation' , "File operation" ) ;
249
264
const reasonLabel = reason === ShutdownReason . CLOSE ? localize ( 'closeTheWindow' , "Close Window" ) : reason === ShutdownReason . LOAD ? localize ( 'changeWorkspace' , "Change Workspace" ) :
250
265
reason === ShutdownReason . RELOAD ? localize ( 'reloadTheWindow' , "Reload Window" ) : localize ( 'quit' , "Quit" ) ;
@@ -258,3 +273,16 @@ export class BulkEditService implements IBulkEditService {
258
273
}
259
274
260
275
registerSingleton ( IBulkEditService , BulkEditService , true ) ;
276
+
277
+ const autoSaveSetting = 'files.refactoring.autoSave' ;
278
+
279
+ Registry . as < IConfigurationRegistry > ( Extensions . Configuration ) . registerConfiguration ( {
280
+ id : 'files' ,
281
+ properties : {
282
+ [ autoSaveSetting ] : {
283
+ description : localize ( 'refactoring.autoSave' , "Controls if files that were part of a refactoring are saved automatically" ) ,
284
+ default : true ,
285
+ type : 'boolean'
286
+ }
287
+ }
288
+ } ) ;
0 commit comments