MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / initializeWidgetComms

Function initializeWidgetComms

src/test/datascience/widgets/commUtils.ts:12–37  ·  view source on GitHub ↗
(disposables: IDisposable[])

Source from the content-addressed store, hash-verified

10import colors from 'colors';
11
12export function initializeWidgetComms(disposables: IDisposable[]): Utils {
13 const messageChannel = notebooks.createRendererMessaging('deepnote-ipywidget-renderer');
14 if (!messageChannel) {
15 throw new Error('No Widget renderer comms channel');
16 }
17 const deferred = createDeferred<NotebookEditor>();
18 // eslint-disable-next-line @typescript-eslint/no-use-before-define
19 const utils = new Utils(messageChannel, deferred.promise);
20 disposables.push(utils);
21 logger.ci(`Adding comm message handler`);
22 const disposable = messageChannel.onDidReceiveMessage(async ({ editor, message }) => {
23 if (message && message.command === 'log') {
24 const messageToLog = message.category === 'error' ? colors.red(message.message) : message.message;
25 const category = message.category ? ` (${message.category})` : '';
26 logger.info(`${colors.yellow('Widget renderer')}${category}: ${messageToLog}`);
27 }
28 if (message && message.command === 'INIT') {
29 deferred.resolve(editor);
30 // Redirect all of console.log, console.warn & console.error messages from
31 // renderer to the extension host.
32 messageChannel.postMessage({ command: 'hijackLogging' }, editor).then(noop, noop);
33 }
34 });
35 disposables.push(disposable);
36 return utils;
37}
38
39export class Utils {
40 private readonly disposables: IDisposable[] = [];

Calls 7

createDeferredFunction · 0.90
pushMethod · 0.65
ciMethod · 0.65
infoMethod · 0.65
resolveMethod · 0.65
postMessageMethod · 0.65
onDidReceiveMessageMethod · 0.45

Tested by

no test coverage detected