Skip to content

Commit 895f824

Browse files
authored
Merge pull request microsoft#189345 from microsoft/aamunger/notebookErrorState
not dirty if auto-save soon without any save error state
2 parents 1fcc384 + f42cf9a commit 895f824

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/vs/workbench/contrib/notebook/common/notebookCommon.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ export interface INotebookEditorModel extends IEditorModel {
796796
readonly resource: URI;
797797
readonly viewType: string;
798798
readonly notebook: INotebookTextModel | undefined;
799+
readonly hasErrorState: boolean;
800+
readonly hasConflictState: boolean;
799801
isResolved(): this is IResolvedNotebookEditorModel;
800802
isDirty(): boolean;
801803
isModified(): boolean;

src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { VSBuffer } from 'vs/base/common/buffer';
2424
import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy';
2525
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
2626
import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance';
27-
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
27+
import { AutoSaveMode, IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
2828
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2929
import { localize } from 'vs/nls';
3030
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
@@ -156,6 +156,16 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
156156
return this._editorModelReference.object.isDirty();
157157
}
158158

159+
override isSaving(): boolean {
160+
const model = this._editorModelReference?.object;
161+
if (!model || !model.isDirty() || model.hasErrorState || model.hasConflictState) {
162+
return false; // require the model to be dirty and not in error or conflict state
163+
}
164+
165+
// if a short auto save is configured, treat this as being saved
166+
return this.filesConfigurationService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY;
167+
}
168+
159169
override async save(group: GroupIdentifier, options?: ISaveOptions): Promise<EditorInput | IUntypedEditorInput | undefined> {
160170
if (this._editorModelReference) {
161171

src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
108108
}
109109
}
110110

111+
get hasErrorState(): boolean {
112+
if (this._workingCopy && 'hasState' in this._workingCopy) {
113+
return this._workingCopy.hasState(StoredFileWorkingCopyState.ERROR);
114+
}
115+
116+
return false;
117+
}
118+
119+
get hasConflictState(): boolean {
120+
if (this._workingCopy && 'hasState' in this._workingCopy) {
121+
return this._workingCopy.hasState(StoredFileWorkingCopyState.CONFLICT);
122+
}
123+
124+
return false;
125+
}
126+
111127
revert(options?: IRevertOptions): Promise<void> {
112128
assertType(this.isResolved());
113129
return this._workingCopy!.revert(options);
@@ -133,7 +149,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
133149
this._workingCopyListeners.add(this._workingCopy.onDidChangeOrphaned(() => this._onDidChangeOrphaned.fire()));
134150
this._workingCopyListeners.add(this._workingCopy.onDidChangeReadonly(() => this._onDidChangeReadonly.fire()));
135151
}
136-
this._workingCopy.onDidChangeDirty(() => this._onDidChangeDirty.fire(), undefined, this._workingCopyListeners);
152+
this._workingCopyListeners.add(this._workingCopy.onDidChangeDirty(() => this._onDidChangeDirty.fire(), undefined, this._workingCopyListeners));
137153

138154
this._workingCopyListeners.add(this._workingCopy.onWillDispose(() => {
139155
this._workingCopyListeners.clear();

src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
135135
return this._dirty;
136136
}
137137

138+
get hasErrorState() {
139+
return false;
140+
}
141+
142+
get hasConflictState() {
143+
return false;
144+
}
145+
138146
isModified(): boolean {
139147
return this._dirty;
140148
}

0 commit comments

Comments
 (0)