mirror of
https://github.com/Microsoft/vscode
synced 2024-10-12 06:17:18 +00:00
Fix support for builtin renderers (#128453)
* Support builtin renderers, lazy access renderers * Oops
This commit is contained in:
parent
649145c24c
commit
3c09e4e765
|
@ -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 ---
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue