Fix support for builtin renderers (#128453)

* Support builtin renderers, lazy access renderers

* Oops
This commit is contained in:
Don Jayamanne 2021-07-20 16:53:45 -07:00 committed by GitHub
parent 649145c24c
commit 3c09e4e765
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 12 deletions

View file

@ -96,7 +96,7 @@ export class NotebookCodeRendererContribution extends Disposable {
}
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookCodeRendererContribution, LifecyclePhase.Eventually);
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookCodeRendererContribution, LifecyclePhase.Restored);
// --- utils ---

View file

@ -16,28 +16,34 @@ export class OutputRenderer {
private readonly _richMimeTypeRenderers = new Map<string, IOutputTransformContribution>();
constructor(
notebookEditor: ICommonNotebookEditor,
instantiationService: IInstantiationService
private readonly notebookEditor: ICommonNotebookEditor,
private readonly instantiationService: IInstantiationService
) {
for (const desc of OutputRendererRegistry.getOutputTransformContributions()) {
try {
const contribution = instantiationService.createInstance(desc.ctor, notebookEditor);
contribution.getMimetypes().forEach(mimetype => { this._richMimeTypeRenderers.set(mimetype, contribution); });
} catch (err) {
onUnexpectedError(err);
}
}
}
dispose(): void {
dispose(this._richMimeTypeRenderers.values());
this._richMimeTypeRenderers.clear();
}
getContribution(preferredMimeType: string): IOutputTransformContribution | undefined {
this._initialize();
return this._richMimeTypeRenderers.get(preferredMimeType);
}
private _initialize() {
if (this._richMimeTypeRenderers.size) {
return;
}
for (const desc of OutputRendererRegistry.getOutputTransformContributions()) {
try {
const contribution = this.instantiationService.createInstance(desc.ctor, this.notebookEditor);
contribution.getMimetypes().forEach(mimetype => { this._richMimeTypeRenderers.set(mimetype, contribution); });
} catch (err) {
onUnexpectedError(err);
}
}
}
private _renderMessage(container: HTMLElement, message: string): IRenderOutput {
const contentNode = document.createElement('p');
contentNode.innerText = message;
@ -46,6 +52,7 @@ export class OutputRenderer {
}
render(viewModel: ICellOutputViewModel, container: HTMLElement, preferredMimeType: string | undefined, notebookUri: URI): IRenderOutput {
this._initialize();
if (!viewModel.model.outputs.length) {
return this._renderMessage(container, localize('empty', "Cell has no output"));
}