From f2fb2b8cbe3a32338583c1f6ba269a9f11193289 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 31 May 2021 15:55:15 +0200 Subject: [PATCH] rename viewType to notebookType, https://github.com/microsoft/vscode/issues/122922 --- src/vs/vscode.d.ts | 32 +++++++++++-------- .../api/browser/mainThreadNotebookKernels.ts | 2 +- .../workbench/api/common/extHost.api.impl.ts | 4 +-- .../workbench/api/common/extHost.protocol.ts | 2 +- .../api/common/extHostNotebookDocument.ts | 5 +-- .../api/common/extHostNotebookKernels.ts | 5 +-- .../notebook/browser/extensionPoint.ts | 15 +++++++-- .../notebook/browser/notebookServiceImpl.ts | 2 +- .../api/extHostNotebookKernel2.test.ts | 2 +- 9 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 492dc878a34..9243c4acd2e 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -11371,11 +11371,14 @@ declare module 'vscode' { */ readonly uri: Uri; + /** @deprecated */ + // todo@API remove + readonly viewType: string; + /** * The type of notebook. */ - // todo@API should this be called `notebookType` or `notebookKind` - readonly viewType: string; + readonly notebookType: string; /** * The version number of this notebook (it will strictly increase after each @@ -11872,15 +11875,14 @@ declare module 'vscode' { * A notebook controller represents an entity that can execute notebook cells. This is often referred to as a kernel. * * There can be multiple controllers and the editor will let users choose which controller to use for a certain notebook. The - * {@link NotebookController.viewType `viewType`}-property defines for what kind of notebooks a controller is for and + * {@link NotebookController.notebookType `notebookType`}-property defines for what kind of notebooks a controller is for and * the {@link NotebookController.updateNotebookAffinity `updateNotebookAffinity`}-function allows controllers to set a preference - * for specific notebooks. + * for specific notebook documents. * * When a cell is being run the editor will invoke the {@link NotebookController.executeHandler `executeHandler`} and a controller * is expected to create and finalize a {@link NotebookCellExecution notebook cell execution}. However, controllers are also free * to create executions by themselves. */ - // todo@api adopt notebookType-rename in comment export interface NotebookController { /** @@ -11891,11 +11893,14 @@ declare module 'vscode' { */ readonly id: string; + // todo@api remove + /** @deprecated */ + readonly viewType: string; + /** - * The notebook view type this controller is for. + * The notebook type this controller is for. */ - // todo@api rename to notebookType - readonly viewType: string; + readonly notebookType: string; /** * An array of language identifiers that are supported by this @@ -12217,11 +12222,11 @@ declare module 'vscode' { * path when the document is to be saved. * * @see {@link openNotebookDocument} - * @param viewType The notebook view type that should be used. + * @param notebookType The notebook type that should be used. * @param content The initial contents of the notebook. * @returns A promise that resolves to a {@link NotebookDocument notebook}. */ - export function openNotebookDocument(viewType: string, content?: NotebookData): Thenable; + export function openNotebookDocument(notebookType: string, content?: NotebookData): Thenable; /** * An event that is emitted when a {@link NotebookDocument notebook} is opened. @@ -12255,17 +12260,16 @@ declare module 'vscode' { * Creates a new notebook controller. * * @param id Identifier of the controller. Must be unique per extension. - * @param viewType A notebook view type for which this controller is for. + * @param notebookType A notebook type for which this controller is for. * @param label The label of the controller. * @param handler The execute-handler of the controller. */ - //todo@API adopt viewType -> notebookType rename - export function createNotebookController(id: string, viewType: string, label: string, handler?: NotebookExecuteHandler): NotebookController; + export function createNotebookController(id: string, notebookType: string, label: string, handler?: NotebookExecuteHandler): NotebookController; /** * Register a {@link NotebookCellStatusBarItemProvider cell statusbar item provider} for the given notebook type. * - * @param notebookType The notebook view type to register for. + * @param notebookType The notebook type to register for. * @param provider A cell status bar provider. * @return A {@link Disposable} that unregisters this provider when being disposed. */ diff --git a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts index c5711a73300..98257c8f668 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts @@ -44,7 +44,7 @@ abstract class MainThreadKernel implements INotebookKernel { constructor(data: INotebookKernelDto2, private _modeService: IModeService) { this.id = data.id; - this.viewType = data.viewType; + this.viewType = data.notebookType; this.extension = data.extensionId; this.implementsInterrupt = data.supportsInterrupt ?? false; diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 9a7bce48e1a..53363031ecf 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1079,8 +1079,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I registerNotebookSerializer(viewType: string, serializer: vscode.NotebookSerializer, options?: vscode.NotebookDocumentContentOptions, registration?: vscode.NotebookRegistrationData) { return extHostNotebook.registerNotebookSerializer(extension, viewType, serializer, options, extension.enableProposedApi ? registration : undefined); }, - createNotebookController(id: string, viewType: string, label: string, handler?: vscode.NotebookExecuteHandler, rendererScripts?: vscode.NotebookRendererScript[]) { - return extHostNotebookKernels.createNotebookController(extension, id, viewType, label, handler, extension.enableProposedApi ? rendererScripts : undefined); + createNotebookController(id: string, notebookType: string, label: string, handler?: vscode.NotebookExecuteHandler, rendererScripts?: vscode.NotebookRendererScript[]) { + return extHostNotebookKernels.createNotebookController(extension, id, notebookType, label, handler, extension.enableProposedApi ? rendererScripts : undefined); }, registerNotebookCellStatusBarItemProvider: (notebookType: string, provider: vscode.NotebookCellStatusBarItemProvider) => { return extHostNotebook.registerNotebookCellStatusBarItemProvider(extension, notebookType, provider); diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 3d660b157cb..8a742dfa453 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -907,7 +907,7 @@ export interface MainThreadNotebookDocumentsShape extends IDisposable { export interface INotebookKernelDto2 { id: string; - viewType: string; + notebookType: string; extensionId: ExtensionIdentifier; extensionLocation: UriComponents; label: string; diff --git a/src/vs/workbench/api/common/extHostNotebookDocument.ts b/src/vs/workbench/api/common/extHostNotebookDocument.ts index 97bd11d61a1..e2d5059f06b 100644 --- a/src/vs/workbench/api/common/extHostNotebookDocument.ts +++ b/src/vs/workbench/api/common/extHostNotebookDocument.ts @@ -144,7 +144,7 @@ export class ExtHostNotebookDocument { private readonly _textDocumentsAndEditors: ExtHostDocumentsAndEditors, private readonly _textDocuments: ExtHostDocuments, private readonly _emitter: INotebookEventEmitter, - private readonly _viewType: string, + private readonly _notebookType: string, private _metadata: extHostTypes.NotebookDocumentMetadata, readonly uri: URI, ) { } @@ -159,7 +159,8 @@ export class ExtHostNotebookDocument { this._notebook = { get uri() { return that.uri; }, get version() { return that._versionId; }, - get viewType() { return that._viewType; }, + get viewType() { return that._notebookType; }, + get notebookType() { return that._notebookType; }, get isDirty() { return that._isDirty; }, get isUntitled() { return that.uri.scheme === Schemas.untitled; }, get isClosed() { return that._disposed; }, diff --git a/src/vs/workbench/api/common/extHostNotebookKernels.ts b/src/vs/workbench/api/common/extHostNotebookKernels.ts index a076d546cd0..8867d3fda92 100644 --- a/src/vs/workbench/api/common/extHostNotebookKernels.ts +++ b/src/vs/workbench/api/common/extHostNotebookKernels.ts @@ -72,7 +72,7 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape { const data: INotebookKernelDto2 = { id: `${extension.identifier.value}/${id}`, - viewType, + notebookType: viewType, extensionId: extension.identifier, extensionLocation: extension.extensionLocation, label: label || extension.identifier.value, @@ -111,7 +111,8 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape { const controller: vscode.NotebookController = { get id() { return id; }, - get viewType() { return data.viewType; }, + get viewType() { return data.notebookType; }, + get notebookType() { return data.notebookType; }, onDidChangeNotebookAssociation: onDidChangeSelection.event, get label() { return data.label; diff --git a/src/vs/workbench/contrib/notebook/browser/extensionPoint.ts b/src/vs/workbench/contrib/notebook/browser/extensionPoint.ts index 406d5a41951..4ed6c173c60 100644 --- a/src/vs/workbench/contrib/notebook/browser/extensionPoint.ts +++ b/src/vs/workbench/contrib/notebook/browser/extensionPoint.ts @@ -9,6 +9,8 @@ import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/exte import { NotebookEditorPriority, NotebookRendererEntrypoint } from 'vs/workbench/contrib/notebook/common/notebookCommon'; namespace NotebookEditorContribution { + export const type = 'type'; + /** @deprecated use type */ export const viewType = 'viewType'; export const displayName = 'displayName'; export const selector = 'selector'; @@ -16,6 +18,8 @@ namespace NotebookEditorContribution { } export interface INotebookEditorContribution { + readonly [NotebookEditorContribution.type]: string; + /** @deprecated use type */ readonly [NotebookEditorContribution.viewType]: string; readonly [NotebookEditorContribution.displayName]: string; readonly [NotebookEditorContribution.selector]?: readonly { filenamePattern?: string; excludeFileNamePattern?: string; }[]; @@ -23,6 +27,7 @@ export interface INotebookEditorContribution { } namespace NotebookRendererContribution { + /** @deprecated use type */ export const viewType = 'viewType'; export const id = 'id'; export const displayName = 'displayName'; @@ -35,6 +40,7 @@ namespace NotebookRendererContribution { export interface INotebookRendererContribution { readonly [NotebookRendererContribution.id]?: string; + /** @deprecated use type */ readonly [NotebookRendererContribution.viewType]?: string; readonly [NotebookRendererContribution.displayName]: string; readonly [NotebookRendererContribution.mimeTypes]?: readonly string[]; @@ -47,17 +53,22 @@ export interface INotebookRendererContribution { const notebookProviderContribution: IJSONSchema = { description: nls.localize('contributes.notebook.provider', 'Contributes notebook document provider.'), type: 'array', - defaultSnippets: [{ body: [{ viewType: '', displayName: '', 'selector': [{ 'filenamePattern': '' }] }] }], + defaultSnippets: [{ body: [{ type: '', displayName: '', 'selector': [{ 'filenamePattern': '' }] }] }], items: { type: 'object', required: [ - NotebookEditorContribution.viewType, + NotebookEditorContribution.type, NotebookEditorContribution.displayName, NotebookEditorContribution.selector, ], properties: { + [NotebookEditorContribution.type]: { + type: 'string', + description: nls.localize('contributes.notebook.provider.viewType', 'Unique identifier of the notebook.'), + }, [NotebookEditorContribution.viewType]: { type: 'string', + deprecationMessage: nls.localize('contributes.notebook.provider.viewType.deprecated', 'Rename `viewType` to `id`.'), description: nls.localize('contributes.notebook.provider.viewType', 'Unique identifier of the notebook.'), }, [NotebookEditorContribution.displayName]: { diff --git a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts index eae6726d746..baa92c9de3c 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts @@ -96,7 +96,7 @@ export class NotebookProviderInfoStore extends Disposable { for (const notebookContribution of extension.value) { this.add(new NotebookProviderInfo({ extension: extension.description.identifier, - id: notebookContribution.viewType, + id: notebookContribution.type || notebookContribution.viewType, displayName: notebookContribution.displayName, selectors: notebookContribution.selector || [], priority: this._convertPriority(notebookContribution.priority), diff --git a/src/vs/workbench/test/browser/api/extHostNotebookKernel2.test.ts b/src/vs/workbench/test/browser/api/extHostNotebookKernel2.test.ts index 742118b48d0..bdbc2d94fa7 100644 --- a/src/vs/workbench/test/browser/api/extHostNotebookKernel2.test.ts +++ b/src/vs/workbench/test/browser/api/extHostNotebookKernel2.test.ts @@ -138,7 +138,7 @@ suite('NotebookKernel', function () { assert.strictEqual(first.id, 'nullExtensionDescription/foo'); assert.strictEqual(ExtensionIdentifier.equals(first.extensionId, nullExtensionDescription.identifier), true); assert.strictEqual(first.label, 'Foo'); - assert.strictEqual(first.viewType, '*'); + assert.strictEqual(first.notebookType, '*'); kernel.dispose(); await rpcProtocol.sync(); -- GitLab