mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-15 02:07:31 +01:00
AutoSave is triggering editor.formatOnSave even when files.autoSave is afterDelay (fix #206475) (#206789)
This commit is contained in:
@@ -80,7 +80,7 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
|
||||
if (workingCopyResult?.condition === condition) {
|
||||
if (
|
||||
workingCopyResult.workingCopy.isDirty() &&
|
||||
this.filesConfigurationService.getAutoSaveMode(workingCopyResult.workingCopy.resource).mode !== AutoSaveMode.OFF
|
||||
this.filesConfigurationService.getAutoSaveMode(workingCopyResult.workingCopy.resource, workingCopyResult.reason).mode !== AutoSaveMode.OFF
|
||||
) {
|
||||
this.discardAutoSave(workingCopyResult.workingCopy);
|
||||
|
||||
@@ -96,7 +96,7 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
|
||||
editorResult?.condition === condition &&
|
||||
!editorResult.editor.editor.isDisposed() &&
|
||||
editorResult.editor.editor.isDirty() &&
|
||||
this.filesConfigurationService.getAutoSaveMode(editorResult.editor.editor).mode !== AutoSaveMode.OFF
|
||||
this.filesConfigurationService.getAutoSaveMode(editorResult.editor.editor, editorResult.reason).mode !== AutoSaveMode.OFF
|
||||
) {
|
||||
this.waitingOnConditionAutoSaveEditors.delete(resource);
|
||||
|
||||
@@ -151,7 +151,7 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
|
||||
return; // no auto save for non-dirty, readonly or untitled editors
|
||||
}
|
||||
|
||||
const autoSaveMode = this.filesConfigurationService.getAutoSaveMode(editorIdentifier.editor);
|
||||
const autoSaveMode = this.filesConfigurationService.getAutoSaveMode(editorIdentifier.editor, reason);
|
||||
if (autoSaveMode.mode !== AutoSaveMode.OFF) {
|
||||
// Determine if we need to save all. In case of a window focus change we also save if
|
||||
// auto save mode is configured to be ON_FOCUS_CHANGE (editor focus change)
|
||||
@@ -198,7 +198,7 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
|
||||
continue; // we never auto save untitled working copies
|
||||
}
|
||||
|
||||
const autoSaveMode = this.filesConfigurationService.getAutoSaveMode(workingCopy.resource);
|
||||
const autoSaveMode = this.filesConfigurationService.getAutoSaveMode(workingCopy.resource, reason);
|
||||
if (autoSaveMode.mode !== AutoSaveMode.OFF) {
|
||||
workingCopy.save({ reason });
|
||||
} else if (autoSaveMode.reason === AutoSaveDisabledReason.ERRORS || autoSaveMode.reason === AutoSaveDisabledReason.DISABLED) {
|
||||
@@ -257,12 +257,13 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
|
||||
|
||||
// Save if dirty and unless prevented by other conditions such as error markers
|
||||
if (workingCopy.isDirty()) {
|
||||
const autoSaveMode = this.filesConfigurationService.getAutoSaveMode(workingCopy.resource);
|
||||
const reason = SaveReason.AUTO;
|
||||
const autoSaveMode = this.filesConfigurationService.getAutoSaveMode(workingCopy.resource, reason);
|
||||
if (autoSaveMode.mode !== AutoSaveMode.OFF) {
|
||||
this.logService.trace(`[editor auto save] running auto save`, workingCopy.resource.toString(), workingCopy.typeId);
|
||||
workingCopy.save({ reason: SaveReason.AUTO });
|
||||
workingCopy.save({ reason });
|
||||
} else if (autoSaveMode.reason === AutoSaveDisabledReason.ERRORS || autoSaveMode.reason === AutoSaveDisabledReason.DISABLED) {
|
||||
this.waitingOnConditionAutoSaveWorkingCopies.set(workingCopy.resource, { workingCopy, reason: SaveReason.AUTO, condition: autoSaveMode.reason });
|
||||
this.waitingOnConditionAutoSaveWorkingCopies.set(workingCopy.resource, { workingCopy, reason, condition: autoSaveMode.reason });
|
||||
}
|
||||
}
|
||||
}, autoSaveAfterDelay);
|
||||
|
||||
@@ -22,7 +22,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
|
||||
import { LRUCache, ResourceMap } from 'vs/base/common/map';
|
||||
import { IMarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||
import { EditorResourceAccessor, SideBySideEditor } from 'vs/workbench/common/editor';
|
||||
import { EditorResourceAccessor, SaveReason, SideBySideEditor } from 'vs/workbench/common/editor';
|
||||
import { IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
|
||||
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfiguration';
|
||||
import { IStringDictionary } from 'vs/base/common/collections';
|
||||
@@ -88,7 +88,7 @@ export interface IFilesConfigurationService {
|
||||
|
||||
hasShortAutoSaveDelay(resourceOrEditor: EditorInput | URI | undefined): boolean;
|
||||
|
||||
getAutoSaveMode(resourceOrEditor: EditorInput | URI | undefined): IAutoSaveMode;
|
||||
getAutoSaveMode(resourceOrEditor: EditorInput | URI | undefined, saveReason?: SaveReason): IAutoSaveMode;
|
||||
|
||||
toggleAutoSave(): Promise<void>;
|
||||
|
||||
@@ -384,7 +384,7 @@ export class FilesConfigurationService extends Disposable implements IFilesConfi
|
||||
return false;
|
||||
}
|
||||
|
||||
getAutoSaveMode(resourceOrEditor: EditorInput | URI | undefined): IAutoSaveMode {
|
||||
getAutoSaveMode(resourceOrEditor: EditorInput | URI | undefined, saveReason?: SaveReason): IAutoSaveMode {
|
||||
const resource = this.toResource(resourceOrEditor);
|
||||
if (resource && this.autoSaveDisabledOverrides.has(resource)) {
|
||||
return { mode: AutoSaveMode.OFF, reason: AutoSaveDisabledReason.DISABLED };
|
||||
@@ -395,6 +395,16 @@ export class FilesConfigurationService extends Disposable implements IFilesConfi
|
||||
return { mode: AutoSaveMode.OFF, reason: AutoSaveDisabledReason.SETTINGS };
|
||||
}
|
||||
|
||||
if (typeof saveReason === 'number') {
|
||||
if (
|
||||
(autoSaveConfiguration.autoSave === 'afterDelay' && saveReason !== SaveReason.AUTO) ||
|
||||
(autoSaveConfiguration.autoSave === 'onFocusChange' && saveReason !== SaveReason.FOCUS_CHANGE && saveReason !== SaveReason.WINDOW_CHANGE) ||
|
||||
(autoSaveConfiguration.autoSave === 'onWindowChange' && saveReason !== SaveReason.WINDOW_CHANGE)
|
||||
) {
|
||||
return { mode: AutoSaveMode.OFF, reason: AutoSaveDisabledReason.SETTINGS };
|
||||
}
|
||||
}
|
||||
|
||||
if (resource) {
|
||||
if (autoSaveConfiguration.autoSaveWorkspaceFilesOnly && autoSaveConfiguration.isOutOfWorkspace) {
|
||||
return { mode: AutoSaveMode.OFF, reason: AutoSaveDisabledReason.OUT_OF_WORKSPACE };
|
||||
|
||||
Reference in New Issue
Block a user