notebooks: remove old renderer api

This commit is contained in:
Connor Peet 2021-07-15 11:08:54 -07:00
parent d0c212ce1e
commit 8a0f4763b1
No known key found for this signature in database
GPG key ID: CF8FD2EA0DBC61BD

View file

@ -158,48 +158,6 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re
};
};
const runRenderScript = async (url: string, rendererId: string): Promise<ScriptModule> => {
const text = await loadScriptSource(url);
// TODO: Support both the new module based renderers and the old style global renderers
const isModule = !text.includes('acquireNotebookRendererApi');
if (isModule) {
return __import(url);
} else {
return createBackCompatModule(rendererId, url, text);
}
};
const createBackCompatModule = (rendererId: string, scriptUrl: string, scriptText: string): ScriptModule => ({
activate: (): RendererApi => {
const onDidCreateOutput = createEmitter<IOutputItem>();
const onWillDestroyOutput = createEmitter<undefined | IDestroyCellInfo>();
const globals = {
scriptUrl,
acquireNotebookRendererApi: <T>(): GlobalNotebookRendererApi<T> => ({
onDidCreateOutput: onDidCreateOutput.event,
onWillDestroyOutput: onWillDestroyOutput.event,
setState: newState => vscode.setState({ ...vscode.getState(), [rendererId]: newState }),
getState: () => {
const state = vscode.getState();
return typeof state === 'object' && state ? state[rendererId] as T : undefined;
},
}),
};
invokeSourceWithGlobals(scriptText, globals);
return {
renderOutputItem(outputItem) {
onDidCreateOutput.fire({ ...outputItem, outputId: outputItem.id });
},
disposeOutputItem(id) {
onWillDestroyOutput.fire(id ? { outputId: id } : undefined);
}
};
}
});
const dimensionUpdater = new class {
private readonly pending = new Map<string, webviewMessages.DimensionUpdate>();
@ -477,20 +435,8 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re
bytes(): Uint8Array;
}
interface IDestroyCellInfo {
outputId: string;
}
const onDidReceiveKernelMessage = createEmitter<unknown>();
/** @deprecated */
interface GlobalNotebookRendererApi<T> {
setState: (newState: T) => void;
getState(): T | undefined;
readonly onWillDestroyOutput: Event<undefined | IDestroyCellInfo>;
readonly onDidCreateOutput: Event<IOutputItem>;
}
const kernelPreloadGlobals = {
acquireVsCodeApi,
onDidReceiveKernelMessage: onDidReceiveKernelMessage.event,
@ -766,7 +712,7 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re
/** Inner function cached in the _loadPromise(). */
private async _load(): Promise<RendererApi | undefined> {
const module = await runRenderScript(this.data.entrypoint, this.data.id);
const module = await __import(this.data.entrypoint);
if (!module) {
return;
}