Skip to content

Commit 3178224

Browse files
committed
use error state from working copy
1 parent 3b42192 commit 3178224

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ export interface INotebookEditorModel extends IEditorModel {
797797
readonly viewType: string;
798798
readonly notebook: INotebookTextModel | undefined;
799799
readonly hasErrorState: boolean;
800+
readonly hasConflictState: boolean;
800801
isResolved(): this is IResolvedNotebookEditorModel;
801802
isDirty(): boolean;
802803
isModified(): boolean;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
157157
}
158158

159159
override isSaving(): boolean {
160-
if (!this._editorModelReference || !this._editorModelReference.object.isDirty() || this._editorModelReference.object.hasErrorState) {
161-
return false; // require the model to be dirty and not in error state
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 of conflict state
162163
}
163164

164165
// if a short auto save is configured, treat this as being saved

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
4646
private _workingCopy?: IStoredFileWorkingCopy<NotebookFileWorkingCopyModel> | IUntitledFileWorkingCopy<NotebookFileWorkingCopyModel>;
4747
private readonly _workingCopyListeners = this._register(new DisposableStore());
4848
private readonly scratchPad: boolean;
49-
private _hasErrorState: boolean = false;
5049

5150
constructor(
5251
readonly resource: URI,
@@ -110,7 +109,19 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
110109
}
111110

112111
get hasErrorState(): boolean {
113-
return this._hasErrorState;
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;
114125
}
115126

116127
revert(options?: IRevertOptions): Promise<void> {
@@ -123,13 +134,6 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
123134
return this._workingCopy!.save(options);
124135
}
125136

126-
private onDidChangeDirtyHandler() {
127-
if (!this._workingCopy?.isDirty()) {
128-
this._hasErrorState = false;
129-
}
130-
this._onDidChangeDirty.fire();
131-
}
132-
133137
async load(options?: INotebookLoadOptions): Promise<IResolvedNotebookEditorModel> {
134138
if (!this._workingCopy || !this._workingCopy.model) {
135139
if (this.resource.scheme === Schemas.untitled) {
@@ -144,9 +148,8 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
144148
this._workingCopyListeners.add(this._workingCopy.onDidSave(e => this._onDidSave.fire(e)));
145149
this._workingCopyListeners.add(this._workingCopy.onDidChangeOrphaned(() => this._onDidChangeOrphaned.fire()));
146150
this._workingCopyListeners.add(this._workingCopy.onDidChangeReadonly(() => this._onDidChangeReadonly.fire()));
147-
this._workingCopyListeners.add(this._workingCopy.onDidSaveError(() => { this._hasErrorState = true; }));
148151
}
149-
this._workingCopyListeners.add(this._workingCopy.onDidChangeDirty(this.onDidChangeDirtyHandler.bind(this), undefined, this._workingCopyListeners));
152+
this._workingCopyListeners.add(this._workingCopy.onDidChangeDirty(() => this._onDidChangeDirty.fire(), undefined, this._workingCopyListeners));
150153

151154
this._workingCopyListeners.add(this._workingCopy.onWillDispose(() => {
152155
this._workingCopyListeners.clear();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
139139
return false;
140140
}
141141

142+
get hasConflictState() {
143+
return false;
144+
}
145+
142146
isModified(): boolean {
143147
return this._dirty;
144148
}

0 commit comments

Comments
 (0)