@@ -24,13 +24,12 @@ import { RunOnceScheduler, timeout } from 'vs/base/common/async';
24
24
import { ITextBufferFactory } from 'vs/editor/common/model' ;
25
25
import { hash } from 'vs/base/common/hash' ;
26
26
import { INotificationService } from 'vs/platform/notification/common/notification' ;
27
- import { toDisposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
28
27
import { ILogService } from 'vs/platform/log/common/log' ;
29
28
import { isEqual , isEqualOrParent , extname , basename , joinPath } from 'vs/base/common/resources' ;
30
29
import { onUnexpectedError } from 'vs/base/common/errors' ;
31
30
import { Schemas } from 'vs/base/common/network' ;
32
31
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService' ;
33
- import { IFilesConfigurationService , IAutoSaveConfiguration } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService' ;
32
+ import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService' ;
34
33
35
34
export interface IBackupMetaData {
36
35
mtime : number ;
@@ -92,10 +91,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
92
91
93
92
private lastResolvedFileStat : IFileStatWithMetadata | undefined ;
94
93
95
- private autoSaveAfterMillies : number | undefined ;
96
- private autoSaveAfterMilliesEnabled : boolean | undefined ;
97
- private readonly autoSaveDisposable = this . _register ( new MutableDisposable ( ) ) ;
98
-
99
94
private readonly saveSequentializer = new SaveSequentializer ( ) ;
100
95
private lastSaveAttemptTime = 0 ;
101
96
@@ -128,8 +123,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
128
123
) {
129
124
super ( modelService , modeService ) ;
130
125
131
- this . updateAutoSaveConfiguration ( filesConfigurationService . getAutoSaveConfiguration ( ) ) ;
132
-
133
126
// Make known to working copy service
134
127
this . _register ( this . workingCopyService . registerWorkingCopy ( this ) ) ;
135
128
@@ -138,7 +131,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
138
131
139
132
private registerListeners ( ) : void {
140
133
this . _register ( this . fileService . onFileChanges ( e => this . onFileChanges ( e ) ) ) ;
141
- this . _register ( this . filesConfigurationService . onAutoSaveConfigurationChange ( config => this . updateAutoSaveConfiguration ( config ) ) ) ;
142
134
this . _register ( this . filesConfigurationService . onFilesAssociationChange ( e => this . onFilesAssociationChange ( ) ) ) ;
143
135
this . _register ( this . onDidStateChange ( e => this . onStateChange ( e ) ) ) ;
144
136
}
@@ -206,13 +198,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
206
198
}
207
199
}
208
200
209
- private updateAutoSaveConfiguration ( config : IAutoSaveConfiguration ) : void {
210
- const autoSaveAfterMilliesEnabled = ( typeof config . autoSaveDelay === 'number' ) && config . autoSaveDelay > 0 ;
211
-
212
- this . autoSaveAfterMilliesEnabled = autoSaveAfterMilliesEnabled ;
213
- this . autoSaveAfterMillies = autoSaveAfterMilliesEnabled ? config . autoSaveDelay : undefined ;
214
- }
215
-
216
201
private onFilesAssociationChange ( ) : void {
217
202
if ( ! this . isResolved ( ) ) {
218
203
return ;
@@ -258,9 +243,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
258
243
return false ;
259
244
}
260
245
261
- // Cancel any running auto-save
262
- this . autoSaveDisposable . clear ( ) ;
263
-
264
246
// Unset flags
265
247
const wasDirty = this . dirty ;
266
248
const undo = this . setDirty ( false ) ;
@@ -474,13 +456,8 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
474
456
this . createTextEditorModel ( value , resource , this . preferredMode ) ;
475
457
476
458
// We restored a backup so we have to set the model as being dirty
477
- // We also want to trigger auto save if it is enabled to simulate the exact same behaviour
478
- // you would get if manually making the model dirty (fixes https://github.com/Microsoft/vscode/issues/16977)
479
459
if ( fromBackup ) {
480
460
this . doMakeDirty ( ) ;
481
- if ( this . autoSaveAfterMilliesEnabled ) {
482
- this . doAutoSave ( this . versionId ) ;
483
- }
484
461
}
485
462
486
463
// Ensure we are not tracking a stale state
@@ -536,9 +513,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
536
513
537
514
// The contents changed as a matter of Undo and the version reached matches the saved one
538
515
// In this case we clear the dirty flag and emit a SAVED event to indicate this state.
539
- // Note: we currently only do this check when auto-save is turned off because there you see
540
- // a dirty indicator that you want to get rid of when undoing to the saved version.
541
- if ( ! this . autoSaveAfterMilliesEnabled && this . isResolved ( ) && this . textEditorModel . getAlternativeVersionId ( ) === this . bufferSavedVersionId ) {
516
+ if ( this . isResolved ( ) && this . textEditorModel . getAlternativeVersionId ( ) === this . bufferSavedVersionId ) {
542
517
this . logService . trace ( 'onModelContentChanged() - model content changed back to last saved version' , this . resource ) ;
543
518
544
519
// Clear flags
@@ -559,15 +534,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
559
534
// Mark as dirty
560
535
this . doMakeDirty ( ) ;
561
536
562
- // Start auto save process unless we are in conflict resolution mode and unless it is disabled
563
- if ( this . autoSaveAfterMilliesEnabled ) {
564
- if ( ! this . inConflictMode ) {
565
- this . doAutoSave ( this . versionId ) ;
566
- } else {
567
- this . logService . trace ( 'makeDirty() - prevented save because we are in conflict resolution mode' , this . resource ) ;
568
- }
569
- }
570
-
571
537
// Handle content change events
572
538
this . contentChangeEventScheduler . schedule ( ) ;
573
539
}
@@ -593,37 +559,13 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
593
559
}
594
560
}
595
561
596
- private doAutoSave ( versionId : number ) : void {
597
- this . logService . trace ( `doAutoSave() - enter for versionId ${ versionId } ` , this . resource ) ;
598
-
599
- // Cancel any currently running auto saves to make this the one that succeeds
600
- this . autoSaveDisposable . clear ( ) ;
601
-
602
- // Create new save timer and store it for disposal as needed
603
- const handle = setTimeout ( ( ) => {
604
-
605
- // Clear the timeout now that we are running
606
- this . autoSaveDisposable . clear ( ) ;
607
-
608
- // Only trigger save if the version id has not changed meanwhile
609
- if ( versionId === this . versionId ) {
610
- this . doSave ( versionId , { reason : SaveReason . AUTO } ) ; // Very important here to not return the promise because if the timeout promise is canceled it will bubble up the error otherwise - do not change
611
- }
612
- } , this . autoSaveAfterMillies ) ;
613
-
614
- this . autoSaveDisposable . value = toDisposable ( ( ) => clearTimeout ( handle ) ) ;
615
- }
616
-
617
562
async save ( options : ITextFileSaveOptions = Object . create ( null ) ) : Promise < boolean > {
618
563
if ( ! this . isResolved ( ) ) {
619
564
return false ;
620
565
}
621
566
622
567
this . logService . trace ( 'save() - enter' , this . resource ) ;
623
568
624
- // Cancel any currently running auto saves to make this the one that succeeds
625
- this . autoSaveDisposable . clear ( ) ;
626
-
627
569
await this . doSave ( this . versionId , options ) ;
628
570
629
571
return true ;
@@ -676,8 +618,8 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
676
618
}
677
619
678
620
// Push all edit operations to the undo stack so that the user has a chance to
679
- // Ctrl+Z back to the saved version. We only do this when auto-save is turned off
680
- if ( ! this . autoSaveAfterMilliesEnabled && this . isResolved ( ) ) {
621
+ // Ctrl+Z back to the saved version.
622
+ if ( this . isResolved ( ) ) {
681
623
this . textEditorModel . pushStackElement ( ) ;
682
624
}
683
625
0 commit comments