fix notebookinput matches function to work with replacement (#8585)

This commit is contained in:
Anthony Dresser
2019-12-05 16:53:36 -08:00
committed by GitHub
parent 3de95af25c
commit 4787d7ba5c
6 changed files with 27 additions and 52 deletions

View File

@@ -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<NotebookContentChange>();
@@ -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<boolean> {
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);

View File

@@ -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<boolean> {
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<boolean> {
let options: ISaveOptions = { force: false };
return this._model.save(options);
save(groupId: number, options?: ITextFileSaveOptions): Promise<boolean> {
return this.textInput.save(groupId, options);
}
saveAs(group: number, options?: ITextFileSaveOptions): Promise<boolean> {
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 = <NotebookInput>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;
}
}

View File

@@ -869,7 +869,7 @@ suite('Notebook Editor Model', function (): void {
let textFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(self, defaultUri.toString()), 'utf8', undefined);
(<TextFileEditorModelManager>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) {

View File

@@ -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<T> = { [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<boolean> {
return this.text.save(groupId, options);
}
saveAs(group: number, options?: ITextFileSaveOptions): Promise<boolean> {
return this.text.saveAs(group, options);
}
public isResolved(): boolean {
return this.text.isResolved();
}

View File

@@ -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<boolean> {
return this.text.save(groupId, options);
}
saveAs(group: number, options?: ITextFileSaveOptions): Promise<boolean> {
return this.text.saveAs(group, options);
}
// Called to get the tooltip of the tab
public getTitle(): string {
return this.getName(true);

View File

@@ -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<T> = { [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<boolean> {
return this.text.save(groupId, options);
}
saveAs(group: number, options?: ITextFileSaveOptions): Promise<boolean> {
return this.text.saveAs(group, options);
}
isUntitled(): boolean {
// Subclasses need to explicitly opt-in to being untitled.
return true;