提交 e0871329 编写于 作者: D Daniel Imms 提交者: GitHub

Merge pull request #16896 from Microsoft/tyriar/16509/afterDelay

Disable text file backups when files.autoSave is afterDelay
...@@ -464,6 +464,8 @@ export const AutoSaveConfiguration = { ...@@ -464,6 +464,8 @@ export const AutoSaveConfiguration = {
ON_WINDOW_CHANGE: 'onWindowChange' ON_WINDOW_CHANGE: 'onWindowChange'
}; };
export const CONTENT_CHANGE_EVENT_BUFFER_DELAY = 1000;
export interface IFilesConfiguration { export interface IFilesConfiguration {
files: { files: {
associations: { [filepattern: string]: string }; associations: { [filepattern: string]: string };
......
...@@ -11,7 +11,7 @@ import { StringEditorModel } from 'vs/workbench/common/editor/stringEditorModel' ...@@ -11,7 +11,7 @@ import { StringEditorModel } from 'vs/workbench/common/editor/stringEditorModel'
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry'; import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
import { EndOfLinePreference } from 'vs/editor/common/editorCommon'; import { EndOfLinePreference } from 'vs/editor/common/editorCommon';
import { IFilesConfiguration } from 'vs/platform/files/common/files'; import { IFilesConfiguration, CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService'; import { IModelService } from 'vs/editor/common/services/modelService';
...@@ -23,7 +23,7 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile ...@@ -23,7 +23,7 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
export class UntitledEditorModel extends StringEditorModel implements IEncodingSupport { export class UntitledEditorModel extends StringEditorModel implements IEncodingSupport {
public static DEFAULT_CONTENT_CHANGE_BUFFER_DELAY = 1000; public static DEFAULT_CONTENT_CHANGE_BUFFER_DELAY = CONTENT_CHANGE_EVENT_BUFFER_DELAY;
private textModelChangeListener: IDisposable; private textModelChangeListener: IDisposable;
private configurationChangeListener: IDisposable; private configurationChangeListener: IDisposable;
......
...@@ -13,18 +13,24 @@ import { ITextFileService, TextFileModelChangeEvent, StateChange } from 'vs/work ...@@ -13,18 +13,24 @@ import { ITextFileService, TextFileModelChangeEvent, StateChange } from 'vs/work
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IFilesConfiguration, AutoSaveConfiguration, CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
const AUTO_SAVE_AFTER_DELAY_DISABLED_TIME = CONTENT_CHANGE_EVENT_BUFFER_DELAY + 500;
export class BackupModelTracker implements IWorkbenchContribution { export class BackupModelTracker implements IWorkbenchContribution {
public _serviceBrand: any; public _serviceBrand: any;
private configuredAutoSaveAfterDelay: boolean;
private toDispose: IDisposable[]; private toDispose: IDisposable[];
constructor( constructor(
@IBackupFileService private backupFileService: IBackupFileService, @IBackupFileService private backupFileService: IBackupFileService,
@ITextFileService private textFileService: ITextFileService, @ITextFileService private textFileService: ITextFileService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService, @IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IEnvironmentService private environmentService: IEnvironmentService @IEnvironmentService private environmentService: IEnvironmentService,
@IConfigurationService private configurationService: IConfigurationService
) { ) {
this.toDispose = []; this.toDispose = [];
...@@ -44,14 +50,32 @@ export class BackupModelTracker implements IWorkbenchContribution { ...@@ -44,14 +50,32 @@ export class BackupModelTracker implements IWorkbenchContribution {
// Listen for untitled model changes // Listen for untitled model changes
this.toDispose.push(this.untitledEditorService.onDidChangeContent((e) => this.onUntitledModelChanged(e))); this.toDispose.push(this.untitledEditorService.onDidChangeContent((e) => this.onUntitledModelChanged(e)));
this.toDispose.push(this.untitledEditorService.onDidDisposeModel((e) => this.discardBackup(e))); this.toDispose.push(this.untitledEditorService.onDidDisposeModel((e) => this.discardBackup(e)));
// Listen to config changes
this.toDispose.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationChange(e.config)));
}
private onConfigurationChange(configuration: IFilesConfiguration): void {
if (!configuration || !configuration.files) {
this.configuredAutoSaveAfterDelay = false;
return;
}
this.configuredAutoSaveAfterDelay =
(configuration.files.autoSave === AutoSaveConfiguration.AFTER_DELAY &&
configuration.files.autoSaveDelay <= AUTO_SAVE_AFTER_DELAY_DISABLED_TIME);
} }
private onTextFileModelChanged(event: TextFileModelChangeEvent): void { private onTextFileModelChanged(event: TextFileModelChangeEvent): void {
if (event.kind === StateChange.REVERTED) { if (event.kind === StateChange.REVERTED) {
// This must proceed even if auto save after delay is configured in order to clean up
// any backups made before the config change
this.discardBackup(event.resource); this.discardBackup(event.resource);
} else if (event.kind === StateChange.CONTENT_CHANGE) { } else if (event.kind === StateChange.CONTENT_CHANGE) {
const model = this.textFileService.models.get(event.resource); // Do not backup when auto save after delay is configured
this.backupFileService.backupResource(model.getResource(), model.getValue(), model.getVersionId()).done(null, errors.onUnexpectedError); if (!this.configuredAutoSaveAfterDelay) {
const model = this.textFileService.models.get(event.resource);
this.backupFileService.backupResource(model.getResource(), model.getValue(), model.getVersionId()).done(null, errors.onUnexpectedError);
}
} }
} }
......
...@@ -23,7 +23,7 @@ import { ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorMo ...@@ -23,7 +23,7 @@ import { ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorMo
import { EncodingMode, EditorModel } from 'vs/workbench/common/editor'; import { EncodingMode, EditorModel } from 'vs/workbench/common/editor';
import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'; import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel';
import { IBackupFileService, BACKUP_FILE_RESOLVE_OPTIONS } from 'vs/workbench/services/backup/common/backup'; import { IBackupFileService, BACKUP_FILE_RESOLVE_OPTIONS } from 'vs/workbench/services/backup/common/backup';
import { IFileService, IFileStat, IFileOperationResult, FileOperationResult, IContent } from 'vs/platform/files/common/files'; import { IFileService, IFileStat, IFileOperationResult, FileOperationResult, IContent, CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IMessageService, Severity } from 'vs/platform/message/common/message'; import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
...@@ -38,7 +38,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil ...@@ -38,7 +38,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
public static ID = 'workbench.editors.files.textFileEditorModel'; public static ID = 'workbench.editors.files.textFileEditorModel';
public static DEFAULT_CONTENT_CHANGE_BUFFER_DELAY = 1000; public static DEFAULT_CONTENT_CHANGE_BUFFER_DELAY = CONTENT_CHANGE_EVENT_BUFFER_DELAY;
private static saveErrorHandler: ISaveErrorHandler; private static saveErrorHandler: ISaveErrorHandler;
private static saveParticipant: ISaveParticipant; private static saveParticipant: ISaveParticipant;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册