From 4787d7ba5c9ffda9e79ddcbafcdd0886eaa9d2f6 Mon Sep 17 00:00:00 2001 From: Anthony Dresser Date: Thu, 5 Dec 2019 16:53:36 -0800 Subject: [PATCH] fix notebookinput matches function to work with replacement (#8585) --- .../mainThreadNotebookDocumentsAndEditors.ts | 10 +++-- .../notebook/browser/models/notebookInput.ts | 40 +++++-------------- .../test/browser/notebookEditorModel.test.ts | 2 +- .../query/common/fileQueryEditorInput.ts | 9 ----- .../contrib/query/common/queryEditorInput.ts | 9 +++++ .../query/common/untitledQueryEditorInput.ts | 9 ----- 6 files changed, 27 insertions(+), 52 deletions(-) diff --git a/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts b/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts index f6dd0ca4e4..d996bb3b0f 100644 --- a/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts @@ -37,6 +37,7 @@ import { find } from 'vs/base/common/arrays'; import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService'; import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput'; import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput'; +import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; class MainThreadNotebookEditor extends Disposable { private _contentChangedEmitter = new Emitter(); @@ -44,7 +45,7 @@ class MainThreadNotebookEditor extends Disposable { private _providerId: string = ''; private _providers: string[] = []; - constructor(public readonly editor: INotebookEditor) { + constructor(public readonly editor: INotebookEditor, private readonly textFileService: ITextFileService) { super(); editor.modelReady.then(model => { this._providerId = model.providerId; @@ -94,7 +95,7 @@ class MainThreadNotebookEditor extends Disposable { } public save(): Thenable { - return this.editor.notebookParams.input.save(); + return this.textFileService.save(this.uri); } public matches(input: NotebookInput): boolean { @@ -333,7 +334,8 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements @IEditorGroupsService private _editorGroupService: IEditorGroupsService, @ICapabilitiesService private _capabilitiesService: ICapabilitiesService, @INotebookService private readonly _notebookService: INotebookService, - @IFileService private readonly _fileService: IFileService + @IFileService private readonly _fileService: IFileService, + @ITextFileService private readonly _textFileService: ITextFileService ) { super(); if (extHostContext) { @@ -515,7 +517,7 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements // added editors for (const editor of delta.addedEditors) { - const mainThreadEditor = new MainThreadNotebookEditor(editor); + const mainThreadEditor = new MainThreadNotebookEditor(editor, this._textFileService); this._notebookEditors.set(editor.id, mainThreadEditor); addedEditors.push(mainThreadEditor); diff --git a/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts b/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts index d9567a1a63..a6703784ce 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/notebookInput.ts @@ -3,7 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { EditorInput, EditorModel, ISaveOptions } from 'vs/workbench/common/editor'; +import { EditorInput, EditorModel } from 'vs/workbench/common/editor'; import { Emitter, Event } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; import * as resources from 'vs/base/common/resources'; @@ -16,7 +16,7 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { INotebookModel, IContentManager, NotebookContentChange } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; import { Schemas } from 'vs/base/common/network'; -import { ITextFileService, StateChange } from 'vs/workbench/services/textfile/common/textfiles'; +import { StateChange, ITextFileSaveOptions } from 'vs/workbench/services/textfile/common/textfiles'; import { LocalContentManager } from 'sql/workbench/services/notebook/common/localContentManager'; import { IConnectionProfile } from 'sql/platform/connection/common/interfaces'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; @@ -43,7 +43,6 @@ export class NotebookEditorModel extends EditorModel { constructor(public readonly notebookUri: URI, private textEditorModel: TextFileEditorModel | UntitledTextEditorModel | ResourceEditorModel, @INotebookService private notebookService: INotebookService, - @ITextFileService private textFileService: ITextFileService, @ITextResourcePropertiesService private textResourcePropertiesService: ITextResourcePropertiesService ) { super(); @@ -106,20 +105,6 @@ export class NotebookEditorModel extends EditorModel { this._onDidChangeDirty.fire(); } - /** - * UntitledEditor uses TextFileService to save data from UntitledEditorInput - * Titled editor uses TextFileEditorModel to save existing notebook - */ - save(options: ISaveOptions): Promise { - if (this.textEditorModel instanceof TextFileEditorModel) { - this.textEditorModel.save(options); - return Promise.resolve(true); - } - else { - return this.textFileService.save(this.notebookUri, options); - } - } - public updateModel(contentChange?: NotebookContentChange, type?: NotebookChangeType): void { this._lastEditFullReplacement = false; if (contentChange && contentChange.changeType === NotebookChangeType.Saved) { @@ -282,9 +267,12 @@ export abstract class NotebookInput extends EditorInput { return this._standardKernels; } - public save(): Promise { - let options: ISaveOptions = { force: false }; - return this._model.save(options); + save(groupId: number, options?: ITextFileSaveOptions): Promise { + return this.textInput.save(groupId, options); + } + + saveAs(group: number, options?: ITextFileSaveOptions): Promise { + return this.textInput.saveAs(group, options); } public set standardKernels(value: IStandardKernelWithProvider[]) { @@ -452,17 +440,11 @@ export abstract class NotebookInput extends EditorInput { } public matches(otherInput: any): boolean { - if (super.matches(otherInput) === true) { - return true; - } - if (otherInput instanceof NotebookInput) { - const otherNotebookEditorInput = otherInput; - - // Compare by resource - return otherNotebookEditorInput.notebookUri.toString() === this.notebookUri.toString(); + return this.textInput.matches(otherInput.textInput); + } else { + return this.textInput.matches(otherInput); } - return false; } } diff --git a/src/sql/workbench/contrib/notebook/test/browser/notebookEditorModel.test.ts b/src/sql/workbench/contrib/notebook/test/browser/notebookEditorModel.test.ts index 598b52fe07..a325bd0a70 100644 --- a/src/sql/workbench/contrib/notebook/test/browser/notebookEditorModel.test.ts +++ b/src/sql/workbench/contrib/notebook/test/browser/notebookEditorModel.test.ts @@ -869,7 +869,7 @@ suite('Notebook Editor Model', function (): void { let textFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(self, defaultUri.toString()), 'utf8', undefined); (accessor.textFileService.models).add(textFileEditorModel.resource, textFileEditorModel); await textFileEditorModel.load(); - return new NotebookEditorModel(defaultUri, textFileEditorModel, mockNotebookService.object, accessor.textFileService, testResourcePropertiesService); + return new NotebookEditorModel(defaultUri, textFileEditorModel, mockNotebookService.object, testResourcePropertiesService); } function setupTextEditorModelWithEmptyOutputs(notebookEditorModel: NotebookEditorModel, newCell: ICellModel) { diff --git a/src/sql/workbench/contrib/query/common/fileQueryEditorInput.ts b/src/sql/workbench/contrib/query/common/fileQueryEditorInput.ts index fa13c88cfe..67457a6d05 100644 --- a/src/sql/workbench/contrib/query/common/fileQueryEditorInput.ts +++ b/src/sql/workbench/contrib/query/common/fileQueryEditorInput.ts @@ -14,7 +14,6 @@ import { EncodingMode } from 'vs/workbench/common/editor'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel'; import { IFileService } from 'vs/platform/files/common/files'; -import { ITextFileSaveOptions } from 'vs/workbench/services/textfile/common/textfiles'; type PublicPart = { [K in keyof T]: T[K] }; @@ -82,14 +81,6 @@ export class FileQueryEditorInput extends QueryEditorInput implements PublicPart this.text.setForceOpenAsBinary(); } - save(groupId: number, options?: ITextFileSaveOptions): Promise { - return this.text.save(groupId, options); - } - - saveAs(group: number, options?: ITextFileSaveOptions): Promise { - return this.text.saveAs(group, options); - } - public isResolved(): boolean { return this.text.isResolved(); } diff --git a/src/sql/workbench/contrib/query/common/queryEditorInput.ts b/src/sql/workbench/contrib/query/common/queryEditorInput.ts index ff1876180b..fe79446acc 100644 --- a/src/sql/workbench/contrib/query/common/queryEditorInput.ts +++ b/src/sql/workbench/contrib/query/common/queryEditorInput.ts @@ -17,6 +17,7 @@ import { IQueryModelService } from 'sql/platform/query/common/queryModel'; import { ISelectionData, ExecutionPlanOptions } from 'azdata'; import { startsWith } from 'vs/base/common/strings'; +import { ITextFileSaveOptions } from 'vs/workbench/services/textfile/common/textfiles'; const MAX_SIZE = 13; @@ -219,6 +220,14 @@ export abstract class QueryEditorInput extends EditorInput implements IConnectab } } + save(groupId: number, options?: ITextFileSaveOptions): Promise { + return this.text.save(groupId, options); + } + + saveAs(group: number, options?: ITextFileSaveOptions): Promise { + return this.text.saveAs(group, options); + } + // Called to get the tooltip of the tab public getTitle(): string { return this.getName(true); diff --git a/src/sql/workbench/contrib/query/common/untitledQueryEditorInput.ts b/src/sql/workbench/contrib/query/common/untitledQueryEditorInput.ts index 7ff7ab8fd5..8b50cb78e3 100644 --- a/src/sql/workbench/contrib/query/common/untitledQueryEditorInput.ts +++ b/src/sql/workbench/contrib/query/common/untitledQueryEditorInput.ts @@ -14,7 +14,6 @@ import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverServ import { IFileService } from 'vs/platform/files/common/files'; import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput'; import { UntitledTextEditorModel } from 'vs/workbench/common/editor/untitledTextEditorModel'; -import { ITextFileSaveOptions } from 'vs/workbench/services/textfile/common/textfiles'; type PublicPart = { [K in keyof T]: T[K] }; @@ -73,14 +72,6 @@ export class UntitledQueryEditorInput extends QueryEditorInput implements IEncod this.text.setEncoding(encoding, mode); } - save(groupId: number, options?: ITextFileSaveOptions): Promise { - return this.text.save(groupId, options); - } - - saveAs(group: number, options?: ITextFileSaveOptions): Promise { - return this.text.saveAs(group, options); - } - isUntitled(): boolean { // Subclasses need to explicitly opt-in to being untitled. return true;