mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
fix notebookinput matches function to work with replacement (#8585)
This commit is contained in:
@@ -37,6 +37,7 @@ import { find } from 'vs/base/common/arrays';
|
|||||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||||
import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput';
|
import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput';
|
||||||
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
||||||
|
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
||||||
|
|
||||||
class MainThreadNotebookEditor extends Disposable {
|
class MainThreadNotebookEditor extends Disposable {
|
||||||
private _contentChangedEmitter = new Emitter<NotebookContentChange>();
|
private _contentChangedEmitter = new Emitter<NotebookContentChange>();
|
||||||
@@ -44,7 +45,7 @@ class MainThreadNotebookEditor extends Disposable {
|
|||||||
private _providerId: string = '';
|
private _providerId: string = '';
|
||||||
private _providers: string[] = [];
|
private _providers: string[] = [];
|
||||||
|
|
||||||
constructor(public readonly editor: INotebookEditor) {
|
constructor(public readonly editor: INotebookEditor, private readonly textFileService: ITextFileService) {
|
||||||
super();
|
super();
|
||||||
editor.modelReady.then(model => {
|
editor.modelReady.then(model => {
|
||||||
this._providerId = model.providerId;
|
this._providerId = model.providerId;
|
||||||
@@ -94,7 +95,7 @@ class MainThreadNotebookEditor extends Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public save(): Thenable<boolean> {
|
public save(): Thenable<boolean> {
|
||||||
return this.editor.notebookParams.input.save();
|
return this.textFileService.save(this.uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public matches(input: NotebookInput): boolean {
|
public matches(input: NotebookInput): boolean {
|
||||||
@@ -333,7 +334,8 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
|
|||||||
@IEditorGroupsService private _editorGroupService: IEditorGroupsService,
|
@IEditorGroupsService private _editorGroupService: IEditorGroupsService,
|
||||||
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
|
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
|
||||||
@INotebookService private readonly _notebookService: INotebookService,
|
@INotebookService private readonly _notebookService: INotebookService,
|
||||||
@IFileService private readonly _fileService: IFileService
|
@IFileService private readonly _fileService: IFileService,
|
||||||
|
@ITextFileService private readonly _textFileService: ITextFileService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
if (extHostContext) {
|
if (extHostContext) {
|
||||||
@@ -515,7 +517,7 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
|
|||||||
|
|
||||||
// added editors
|
// added editors
|
||||||
for (const editor of delta.addedEditors) {
|
for (const editor of delta.addedEditors) {
|
||||||
const mainThreadEditor = new MainThreadNotebookEditor(editor);
|
const mainThreadEditor = new MainThreadNotebookEditor(editor, this._textFileService);
|
||||||
|
|
||||||
this._notebookEditors.set(editor.id, mainThreadEditor);
|
this._notebookEditors.set(editor.id, mainThreadEditor);
|
||||||
addedEditors.push(mainThreadEditor);
|
addedEditors.push(mainThreadEditor);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* 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 { Emitter, Event } from 'vs/base/common/event';
|
||||||
import { URI } from 'vs/base/common/uri';
|
import { URI } from 'vs/base/common/uri';
|
||||||
import * as resources from 'vs/base/common/resources';
|
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 { INotebookModel, IContentManager, NotebookContentChange } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces';
|
||||||
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
|
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
|
||||||
import { Schemas } from 'vs/base/common/network';
|
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 { LocalContentManager } from 'sql/workbench/services/notebook/common/localContentManager';
|
||||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||||
@@ -43,7 +43,6 @@ export class NotebookEditorModel extends EditorModel {
|
|||||||
constructor(public readonly notebookUri: URI,
|
constructor(public readonly notebookUri: URI,
|
||||||
private textEditorModel: TextFileEditorModel | UntitledTextEditorModel | ResourceEditorModel,
|
private textEditorModel: TextFileEditorModel | UntitledTextEditorModel | ResourceEditorModel,
|
||||||
@INotebookService private notebookService: INotebookService,
|
@INotebookService private notebookService: INotebookService,
|
||||||
@ITextFileService private textFileService: ITextFileService,
|
|
||||||
@ITextResourcePropertiesService private textResourcePropertiesService: ITextResourcePropertiesService
|
@ITextResourcePropertiesService private textResourcePropertiesService: ITextResourcePropertiesService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
@@ -106,20 +105,6 @@ export class NotebookEditorModel extends EditorModel {
|
|||||||
this._onDidChangeDirty.fire();
|
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 {
|
public updateModel(contentChange?: NotebookContentChange, type?: NotebookChangeType): void {
|
||||||
this._lastEditFullReplacement = false;
|
this._lastEditFullReplacement = false;
|
||||||
if (contentChange && contentChange.changeType === NotebookChangeType.Saved) {
|
if (contentChange && contentChange.changeType === NotebookChangeType.Saved) {
|
||||||
@@ -282,9 +267,12 @@ export abstract class NotebookInput extends EditorInput {
|
|||||||
return this._standardKernels;
|
return this._standardKernels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public save(): Promise<boolean> {
|
save(groupId: number, options?: ITextFileSaveOptions): Promise<boolean> {
|
||||||
let options: ISaveOptions = { force: false };
|
return this.textInput.save(groupId, options);
|
||||||
return this._model.save(options);
|
}
|
||||||
|
|
||||||
|
saveAs(group: number, options?: ITextFileSaveOptions): Promise<boolean> {
|
||||||
|
return this.textInput.saveAs(group, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public set standardKernels(value: IStandardKernelWithProvider[]) {
|
public set standardKernels(value: IStandardKernelWithProvider[]) {
|
||||||
@@ -452,17 +440,11 @@ export abstract class NotebookInput extends EditorInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public matches(otherInput: any): boolean {
|
public matches(otherInput: any): boolean {
|
||||||
if (super.matches(otherInput) === true) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (otherInput instanceof NotebookInput) {
|
if (otherInput instanceof NotebookInput) {
|
||||||
const otherNotebookEditorInput = <NotebookInput>otherInput;
|
return this.textInput.matches(otherInput.textInput);
|
||||||
|
} else {
|
||||||
// Compare by resource
|
return this.textInput.matches(otherInput);
|
||||||
return otherNotebookEditorInput.notebookUri.toString() === this.notebookUri.toString();
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -869,7 +869,7 @@ suite('Notebook Editor Model', function (): void {
|
|||||||
let textFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(self, defaultUri.toString()), 'utf8', undefined);
|
let textFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(self, defaultUri.toString()), 'utf8', undefined);
|
||||||
(<TextFileEditorModelManager>accessor.textFileService.models).add(textFileEditorModel.resource, textFileEditorModel);
|
(<TextFileEditorModelManager>accessor.textFileService.models).add(textFileEditorModel.resource, textFileEditorModel);
|
||||||
await textFileEditorModel.load();
|
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) {
|
function setupTextEditorModelWithEmptyOutputs(notebookEditorModel: NotebookEditorModel, newCell: ICellModel) {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { EncodingMode } from 'vs/workbench/common/editor';
|
|||||||
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
|
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
|
||||||
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
|
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
|
||||||
import { IFileService } from 'vs/platform/files/common/files';
|
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] };
|
type PublicPart<T> = { [K in keyof T]: T[K] };
|
||||||
|
|
||||||
@@ -82,14 +81,6 @@ export class FileQueryEditorInput extends QueryEditorInput implements PublicPart
|
|||||||
this.text.setForceOpenAsBinary();
|
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 {
|
public isResolved(): boolean {
|
||||||
return this.text.isResolved();
|
return this.text.isResolved();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { IQueryModelService } from 'sql/platform/query/common/queryModel';
|
|||||||
|
|
||||||
import { ISelectionData, ExecutionPlanOptions } from 'azdata';
|
import { ISelectionData, ExecutionPlanOptions } from 'azdata';
|
||||||
import { startsWith } from 'vs/base/common/strings';
|
import { startsWith } from 'vs/base/common/strings';
|
||||||
|
import { ITextFileSaveOptions } from 'vs/workbench/services/textfile/common/textfiles';
|
||||||
|
|
||||||
const MAX_SIZE = 13;
|
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
|
// Called to get the tooltip of the tab
|
||||||
public getTitle(): string {
|
public getTitle(): string {
|
||||||
return this.getName(true);
|
return this.getName(true);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverServ
|
|||||||
import { IFileService } from 'vs/platform/files/common/files';
|
import { IFileService } from 'vs/platform/files/common/files';
|
||||||
import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput';
|
import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput';
|
||||||
import { UntitledTextEditorModel } from 'vs/workbench/common/editor/untitledTextEditorModel';
|
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] };
|
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);
|
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 {
|
isUntitled(): boolean {
|
||||||
// Subclasses need to explicitly opt-in to being untitled.
|
// Subclasses need to explicitly opt-in to being untitled.
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user