From 25499ff969e4a711c435737b957356e42a300421 Mon Sep 17 00:00:00 2001 From: rebornix Date: Thu, 13 Aug 2020 16:57:47 -0700 Subject: [PATCH] fix #101871. --- src/vs/workbench/api/browser/mainThreadNotebook.ts | 11 +++++++++-- src/vs/workbench/api/common/extHostNotebook.ts | 2 +- .../notebook/browser/notebookPureOutputRenderer.ts | 2 +- .../contrib/notebook/browser/notebookServiceImpl.ts | 11 ++++++++--- .../notebook/browser/view/renderers/codeCell.ts | 3 ++- .../contrib/notebook/common/notebookCommon.ts | 1 + .../contrib/notebook/common/notebookService.ts | 3 +++ 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadNotebook.ts b/src/vs/workbench/api/browser/mainThreadNotebook.ts index d9a61aa4f42..7fdf21501ff 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebook.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebook.ts @@ -415,7 +415,13 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo } async $registerNotebookRenderer(extension: NotebookExtensionDescription, type: string, selectors: INotebookMimeTypeSelector, preloads: UriComponents[]): Promise { - const renderer = new MainThreadNotebookRenderer(this._proxy, type, extension.id, URI.revive(extension.location), selectors, preloads.map(uri => URI.revive(uri))); + const staticContribution = this._notebookService.getContributedNotebookOutputRenderers(type); + + if (!staticContribution) { + throw new Error(`Notebook renderer for '${type}' is not statically registered.`); + } + + const renderer = new MainThreadNotebookRenderer(this._proxy, type, staticContribution.displayName, extension.id, URI.revive(extension.location), selectors, preloads.map(uri => URI.revive(uri))); this._notebookRenderers.set(type, renderer); this._notebookService.registerNotebookRenderer(type, renderer); } @@ -674,10 +680,11 @@ export class MainThreadNotebookRenderer implements INotebookRendererInfo { constructor( private readonly _proxy: ExtHostNotebookShape, readonly id: string, + public displayName: string, readonly extensionId: ExtensionIdentifier, readonly extensionLocation: URI, readonly selectors: INotebookMimeTypeSelector, - readonly preloads: URI[] + readonly preloads: URI[], ) { } diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 6452d5a3985..037b0c71e63 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -964,7 +964,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN filter: vscode.NotebookOutputSelector, renderer: vscode.NotebookOutputRenderer ): vscode.Disposable { - if (this._notebookKernels.has(type)) { + if (this._notebookOutputRenderers.has(type)) { throw new Error(`Notebook renderer for '${type}' already registered`); } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookPureOutputRenderer.ts b/src/vs/workbench/contrib/notebook/browser/notebookPureOutputRenderer.ts index c1f42f14d6c..af6c59fc4ed 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookPureOutputRenderer.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookPureOutputRenderer.ts @@ -19,7 +19,7 @@ export class PureNotebookOutputRenderer implements INotebookRendererInfo { public readonly preloads: URI[]; - constructor(public readonly id: string, extension: IExtensionDescription, entrypoint: string) { + constructor(public readonly id: string, public readonly displayName: string, extension: IExtensionDescription, entrypoint: string) { this.extensionId = extension.identifier; this.extensionLocation = extension.extensionLocation; this.preloads = [joinPath(extension.extensionLocation, entrypoint)]; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts index b5c95859442..a45e3a397c0 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts @@ -298,7 +298,7 @@ export class NotebookService extends Disposable implements INotebookService, ICu })); if (notebookContribution.entrypoint) { - this._notebookRenderers.set(notebookContribution.viewType, new PureNotebookOutputRenderer(notebookContribution.viewType, extension.description, notebookContribution.entrypoint)); + this._notebookRenderers.set(notebookContribution.viewType, new PureNotebookOutputRenderer(notebookContribution.viewType, notebookContribution.displayName, extension.description, notebookContribution.entrypoint)); } } } @@ -547,6 +547,11 @@ export class NotebookService extends Disposable implements INotebookService, ICu registerNotebookRenderer(id: string, renderer: INotebookRendererInfo) { this._notebookRenderers.set(id, renderer); + const staticInfo = this.notebookRenderersInfoStore.get(id); + + if (staticInfo) { + + } } unregisterNotebookRenderer(id: string) { @@ -995,8 +1000,8 @@ export class NotebookService extends Disposable implements INotebookService, ICu return this.notebookProviderInfoStore.get(viewType); } - getContributedNotebookOutputRenderers(mimeType: string): readonly NotebookOutputRendererInfo[] { - return this.notebookRenderersInfoStore.getContributedRenderer(mimeType); + getContributedNotebookOutputRenderers(viewType: string): NotebookOutputRendererInfo | undefined { + return this.notebookRenderersInfoStore.get(viewType); } getNotebookProviderResourceRoots(): URI[] { diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts index c541cb9b136..ef7e8c202a1 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts @@ -558,7 +558,8 @@ export class CodeCell extends Disposable { const renderInfo = this.notebookService.getRendererInfo(renderId); if (renderInfo) { - return `${renderId} (${renderInfo.extensionId.value})`; + const displayName = renderInfo.displayName !== '' ? renderInfo.displayName : renderInfo.id; + return `${displayName} (${renderInfo.extensionId.value})`; } return nls.localize('builtinRenderInfo', "built-in"); diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index 46c9f3f0ec5..319c8fd9130 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -113,6 +113,7 @@ export interface INotebookMimeTypeSelector { export interface INotebookRendererInfo { id: string; + displayName: string; extensionId: ExtensionIdentifier; extensionLocation: URI, preloads: URI[], diff --git a/src/vs/workbench/contrib/notebook/common/notebookService.ts b/src/vs/workbench/contrib/notebook/common/notebookService.ts index 9c6d199d7ed..87fad7fb364 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookService.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookService.ts @@ -16,6 +16,7 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no import { CancellationToken } from 'vs/base/common/cancellation'; import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel'; import { IDisposable } from 'vs/base/common/lifecycle'; +import { NotebookOutputRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookOutputRenderer'; export const INotebookService = createDecorator('notebookService'); @@ -61,7 +62,9 @@ export interface INotebookService { registerNotebookKernelProvider(provider: INotebookKernelProvider): IDisposable; getContributedNotebookKernels(viewType: string, resource: URI): readonly INotebookKernelInfo[]; getContributedNotebookKernels2(viewType: string, resource: URI, token: CancellationToken): Promise; + getContributedNotebookOutputRenderers(id: string): NotebookOutputRendererInfo | undefined; getRendererInfo(id: string): INotebookRendererInfo | undefined; + resolveNotebook(viewType: string, uri: URI, forceReload: boolean, editorId?: string, backupId?: string): Promise; getNotebookTextModel(uri: URI): NotebookTextModel | undefined; executeNotebook(viewType: string, uri: URI): Promise; -- GitLab