get the cononical URI when creating the notebookEditorInput

This commit is contained in:
Aaron Munger
2023-11-01 08:01:17 -07:00
committed by Aaron Munger
parent 04992395df
commit ca063373aa
6 changed files with 35 additions and 26 deletions
@@ -95,7 +95,7 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
@INotebookService private readonly _notebookService: INotebookService,
@IFileDialogService private readonly _fileDialogService: IFileDialogService
) {
const input = NotebookEditorInput.create(instantiationService, resource, 'interactive', {});
const input = NotebookEditorInput.create(instantiationService, resource, undefined, 'interactive', {});
super();
this._notebookEditorInput = input;
this._register(this._notebookEditorInput);
@@ -204,7 +204,7 @@ class NotebookEditorSerializer implements IEditorSerializer {
return undefined;
}
const input = NotebookEditorInput.create(instantiationService, resource, viewType, options);
const input = NotebookEditorInput.create(instantiationService, resource, undefined, viewType, options);
return input;
}
}
@@ -639,7 +639,7 @@ class SimpleNotebookWorkingCopyEditorHandler extends Disposable implements IWork
}
createEditor(workingCopy: IWorkingCopyIdentifier): EditorInput {
return NotebookEditorInput.create(this._instantiationService, workingCopy.resource, this._getViewType(workingCopy)!);
return NotebookEditorInput.create(this._instantiationService, workingCopy.resource, undefined, this._getViewType(workingCopy)!);
}
private async _installHandler(): Promise<void> {
@@ -42,6 +42,7 @@ import { DiffEditorInputFactoryFunction, EditorInputFactoryFunction, EditorInput
import { IExtensionService, isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { InstallRecommendedExtensionAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
export class NotebookProviderInfoStore extends Disposable {
@@ -62,7 +63,8 @@ export class NotebookProviderInfoStore extends Disposable {
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IFileService private readonly _fileService: IFileService,
@INotebookEditorModelResolverService private readonly _notebookEditorModelResolverService: INotebookEditorModelResolverService
@INotebookEditorModelResolverService private readonly _notebookEditorModelResolverService: INotebookEditorModelResolverService,
@IUriIdentityService private readonly uriIdentService: IUriIdentityService,
) {
super();
@@ -178,12 +180,18 @@ export class NotebookProviderInfoStore extends Disposable {
};
const notebookEditorInputFactory: EditorInputFactoryFunction = ({ resource, options }) => {
const data = CellUri.parse(resource);
let notebookUri: URI = resource;
let notebookUri: URI;
let cellOptions: IResourceEditorInput | undefined;
let preferredResource = resource;
if (data) {
notebookUri = data.notebook;
cellOptions = { resource, options };
// resource is a notebook cell
notebookUri = this.uriIdentService.asCanonicalUri(data.notebook);
preferredResource = data.notebook;
cellOptions = { resource: notebookUri, options };
} else {
notebookUri = this.uriIdentService.asCanonicalUri(resource);
}
if (!cellOptions) {
@@ -191,8 +199,10 @@ export class NotebookProviderInfoStore extends Disposable {
}
const notebookOptions = { ...options, cellOptions } as INotebookEditorOptions;
return { editor: NotebookEditorInput.create(this._instantiationService, notebookUri, notebookProviderInfo.id), options: notebookOptions };
const editor = NotebookEditorInput.create(this._instantiationService, notebookUri, preferredResource, notebookProviderInfo.id);
return { editor, options: notebookOptions };
};
const notebookUntitledEditorFactory: UntitledEditorInputFactoryFunction = async ({ resource, options }) => {
const ref = await this._notebookEditorModelResolverService.resolve({ untitledResource: resource }, notebookProviderInfo.id);
@@ -202,7 +212,7 @@ export class NotebookProviderInfoStore extends Disposable {
ref!.dispose();
});
return { editor: NotebookEditorInput.create(this._instantiationService, ref.object.resource, notebookProviderInfo.id), options };
return { editor: NotebookEditorInput.create(this._instantiationService, ref.object.resource, undefined, notebookProviderInfo.id), options };
};
const notebookDiffEditorInputFactory: DiffEditorInputFactoryFunction = ({ modified, original, label, description }) => {
return { editor: NotebookDiffEditorInput.create(this._instantiationService, modified.resource!, label, description, original.resource!, notebookProviderInfo.id) };
@@ -24,8 +24,8 @@ class NotebookDiffEditorModel extends EditorModel implements INotebookDiffEditor
export class NotebookDiffEditorInput extends DiffEditorInput {
static create(instantiationService: IInstantiationService, resource: URI, name: string | undefined, description: string | undefined, originalResource: URI, viewType: string) {
const original = NotebookEditorInput.create(instantiationService, originalResource, viewType);
const modified = NotebookEditorInput.create(instantiationService, resource, viewType);
const original = NotebookEditorInput.create(instantiationService, originalResource, undefined, viewType);
const modified = NotebookEditorInput.create(instantiationService, resource, undefined, viewType);
return instantiationService.createInstance(NotebookDiffEditorInput, name, description, original, modified, viewType);
}
@@ -41,8 +41,8 @@ export interface NotebookEditorInputOptions {
export class NotebookEditorInput extends AbstractResourceEditorInput {
static create(instantiationService: IInstantiationService, resource: URI, viewType: string, options: NotebookEditorInputOptions = {}) {
return instantiationService.createInstance(NotebookEditorInput, resource, viewType, options);
static create(instantiationService: IInstantiationService, resource: URI, preferredResource: URI | undefined, viewType: string, options: NotebookEditorInputOptions = {}) {
return instantiationService.createInstance(NotebookEditorInput, resource, preferredResource, viewType, options);
}
static readonly ID: string = 'workbench.input.notebook';
@@ -51,23 +51,27 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
private _sideLoadedListener: IDisposable;
private _defaultDirtyState: boolean = false;
static counter = 1;
private debugId = NotebookEditorInput.counter++;
constructor(
resource: URI,
preferredResource: URI | undefined,
public readonly viewType: string,
public readonly options: NotebookEditorInputOptions,
@INotebookService private readonly _notebookService: INotebookService,
@INotebookEditorModelResolverService private readonly _notebookModelResolverService: INotebookEditorModelResolverService,
@IFileDialogService private readonly _fileDialogService: IFileDialogService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@ILabelService labelService: ILabelService,
@IFileService fileService: IFileService,
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
@IExtensionService extensionService: IExtensionService,
@IEditorService editorService: IEditorService
) {
super(resource, undefined, labelService, fileService, filesConfigurationService);
super(resource, preferredResource, labelService, fileService, filesConfigurationService);
this._defaultDirtyState = !!options.startDirty;
console.log(`Creating notebookEditorInput ${this.debugId}`);
// Automatically resolve this input when the "wanted" model comes to life via
// some other way. This happens only once per input and resolve disposes
// this listener
@@ -96,6 +100,7 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
}
override dispose() {
console.log(`Disposing notebokEditorInput ${this.debugId}`);
this._sideLoadedListener.dispose();
this._editorModelReference?.dispose();
this._editorModelReference = null;
@@ -253,20 +258,12 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
// called when users rename a notebook document
override async rename(group: GroupIdentifier, target: URI): Promise<IMoveResult | undefined> {
if (this._editorModelReference) {
const contributedNotebookProviders = this._notebookService.getContributedNotebookTypes(target);
return { editor: { resource: target }, options: { override: this.viewType } };
if (contributedNotebookProviders.find(provider => provider.id === this._editorModelReference!.object.viewType)) {
return this._move(group, target);
}
}
return undefined;
}
private _move(_group: GroupIdentifier, newResource: URI): { editor: EditorInput } {
const editorInput = NotebookEditorInput.create(this._instantiationService, newResource, this.viewType);
return { editor: editorInput };
}
override async revert(_group: GroupIdentifier, options?: IRevertOptions): Promise<void> {
if (this._editorModelReference && this._editorModelReference.object.isDirty()) {
await this._editorModelReference.object.revert(options);
@@ -336,7 +333,7 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
override toUntyped(): IResourceEditorInput {
return {
resource: this.preferredResource,
resource: this.resource,
options: {
override: this.viewType
}
@@ -13,6 +13,7 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IFileService } from 'vs/platform/files/common/files';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { NotebookProviderInfoStore } from 'vs/workbench/contrib/notebook/browser/services/notebookServiceImpl';
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
@@ -43,7 +44,8 @@ suite('NotebookProviderInfoStore', function () {
new class extends mock<IFileService>() {
override hasProvider() { return true; }
},
new class extends mock<INotebookEditorModelResolverService>() { }
new class extends mock<INotebookEditorModelResolverService>() { },
new class extends mock<IUriIdentityService>() { }
);
disposables.add(store);