Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return untyped editor input from saveAs #148614

Merged
merged 1 commit into from May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/vs/workbench/contrib/notebook/common/notebookCommon.ts
Expand Up @@ -25,8 +25,7 @@ import { IEditorModel } from 'vs/platform/editor/common/editor';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { ThemeColor } from 'vs/platform/theme/common/themeService';
import { UndoRedoGroup } from 'vs/platform/undoRedo/common/undoRedo';
import { IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { IRevertOptions, ISaveOptions, IUntypedEditorInput } from 'vs/workbench/common/editor';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { IWorkingCopyBackupMeta, IWorkingCopySaveEvent } from 'vs/workbench/services/workingCopy/common/workingCopy';
Expand Down Expand Up @@ -780,7 +779,7 @@ export interface INotebookEditorModel extends IEditorModel {
hasAssociatedFilePath(): boolean;
load(options?: INotebookLoadOptions): Promise<IResolvedNotebookEditorModel>;
save(options?: ISaveOptions): Promise<boolean>;
saveAs(target: URI): Promise<EditorInput | undefined>;
saveAs(target: URI): Promise<IUntypedEditorInput | undefined>;
revert(options?: IRevertOptions): Promise<void>;
}

Expand Down
Expand Up @@ -124,7 +124,7 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
return this._editorModelReference.object.isDirty();
}

override async save(group: GroupIdentifier, options?: ISaveOptions): Promise<EditorInput | undefined> {
override async save(group: GroupIdentifier, options?: ISaveOptions): Promise<EditorInput | IUntypedEditorInput | undefined> {
if (this._editorModelReference) {

if (this.hasCapability(EditorInputCapabilities.Untitled)) {
Expand All @@ -139,7 +139,7 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
return undefined;
}

override async saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<EditorInput | undefined> {
override async saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<IUntypedEditorInput | undefined> {
if (!this._editorModelReference) {
return undefined;
}
Expand Down
15 changes: 5 additions & 10 deletions src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts
Expand Up @@ -4,8 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import { IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { IRevertOptions, ISaveOptions, IUntypedEditorInput } from 'vs/workbench/common/editor';
import { EditorModel } from 'vs/workbench/common/editor/editorModel';
import { Emitter, Event } from 'vs/base/common/event';
import { ICellDto2, INotebookEditorModel, INotebookLoadOptions, IResolvedNotebookEditorModel, NotebookCellsChangeType, NotebookData, NotebookDocumentBackupData } from 'vs/workbench/contrib/notebook/common/notebookCommon';
Expand All @@ -28,8 +27,6 @@ import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/commo
import { StoredFileWorkingCopyState, IStoredFileWorkingCopy, IStoredFileWorkingCopyModel, IStoredFileWorkingCopyModelContentChangedEvent, IStoredFileWorkingCopyModelFactory, IStoredFileWorkingCopySaveEvent } from 'vs/workbench/services/workingCopy/common/storedFileWorkingCopy';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { CancellationError } from 'vs/base/common/errors';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { filter } from 'vs/base/common/objects';
import { IFileWorkingCopyManager } from 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager';
import { IUntitledFileWorkingCopy, IUntitledFileWorkingCopyModel, IUntitledFileWorkingCopyModelContentChangedEvent, IUntitledFileWorkingCopyModelFactory } from 'vs/workbench/services/workingCopy/common/untitledFileWorkingCopy';
Expand Down Expand Up @@ -59,7 +56,6 @@ export class ComplexNotebookEditorModel extends EditorModel implements INotebook
readonly resource: URI,
readonly viewType: string,
private readonly _contentProvider: INotebookContentProvider,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@INotebookService private readonly _notebookService: INotebookService,
@IWorkingCopyService private readonly _workingCopyService: IWorkingCopyService,
@IWorkingCopyBackupService private readonly _workingCopyBackupService: IWorkingCopyBackupService,
Expand Down Expand Up @@ -393,7 +389,7 @@ export class ComplexNotebookEditorModel extends EditorModel implements INotebook
});
}

async saveAs(targetResource: URI): Promise<EditorInput | undefined> {
async saveAs(targetResource: URI): Promise<IUntypedEditorInput | undefined> {

if (!this.isResolved()) {
return undefined;
Expand All @@ -419,7 +415,7 @@ export class ComplexNotebookEditorModel extends EditorModel implements INotebook
}
this.setDirty(false);
this._onDidSave.fire({});
return this._instantiationService.createInstance(NotebookEditorInput, targetResource, this.viewType, {});
return { resource: targetResource };
}

private async _resolveStats(resource: URI) {
Expand Down Expand Up @@ -462,7 +458,6 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
private readonly _hasAssociatedFilePath: boolean,
readonly viewType: string,
private readonly _workingCopyManager: IFileWorkingCopyManager<NotebookFileWorkingCopyModel, NotebookFileWorkingCopyModel>,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IFileService private readonly _fileService: IFileService
) {
super();
Expand Down Expand Up @@ -547,14 +542,14 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
return this;
}

async saveAs(target: URI): Promise<EditorInput | undefined> {
async saveAs(target: URI): Promise<IUntypedEditorInput | undefined> {
const newWorkingCopy = await this._workingCopyManager.saveAs(this.resource, target);
if (!newWorkingCopy) {
return undefined;
}
// this is a little hacky because we leave the new working copy alone. BUT
// the newly created editor input will pick it up and claim ownership of it.
return this._instantiationService.createInstance(NotebookEditorInput, newWorkingCopy.resource, this.viewType, {});
return { resource: newWorkingCopy.resource };
}

private static _isStoredFileWorkingCopy(candidate?: IStoredFileWorkingCopy<NotebookFileWorkingCopyModel> | IUntitledFileWorkingCopy<NotebookFileWorkingCopyModel>): candidate is IStoredFileWorkingCopy<NotebookFileWorkingCopyModel> {
Expand Down
Expand Up @@ -10,7 +10,6 @@ import { isEqual } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { mock } from 'vs/base/test/common/mock';
import { IFileService } from 'vs/platform/files/common/files';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { ILabelService } from 'vs/platform/label/common/label';
import { NullLogService } from 'vs/platform/log/common/log';
import { INotificationService } from 'vs/platform/notification/common/notification';
Expand Down Expand Up @@ -187,7 +186,6 @@ suite('NotebookFileWorkingCopyModel', function () {

suite('ComplexNotebookEditorModel', function () {

const instaService = new InstantiationService();
const notebokService = new class extends mock<INotebookService>() { };
const backupService = new class extends mock<IWorkingCopyBackupService>() { };
const notificationService = new class extends mock<INotificationService>() { };
Expand All @@ -214,8 +212,8 @@ suite('ComplexNotebookEditorModel', function () {
}
};

new ComplexNotebookEditorModel(r1, 'fff', notebookDataProvider, instaService, notebokService, workingCopyService, backupService, fileService, notificationService, new NullLogService(), untitledTextEditorService, labelService);
new ComplexNotebookEditorModel(r2, 'fff', notebookDataProvider, instaService, notebokService, workingCopyService, backupService, fileService, notificationService, new NullLogService(), untitledTextEditorService, labelService);
new ComplexNotebookEditorModel(r1, 'fff', notebookDataProvider, notebokService, workingCopyService, backupService, fileService, notificationService, new NullLogService(), untitledTextEditorService, labelService);
new ComplexNotebookEditorModel(r2, 'fff', notebookDataProvider, notebokService, workingCopyService, backupService, fileService, notificationService, new NullLogService(), untitledTextEditorService, labelService);

assert.strictEqual(copies.length, 2);
assert.strictEqual(!isEqual(copies[0].resource, copies[1].resource), true);
Expand Down