Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ images/**
docs/**
*.vsix
.appveyor.yml
.config/**
.devcontainer*/**
.editorconfig
.env
Expand All @@ -18,7 +19,9 @@ docs/**
.npmrc
.nvmrc
.nycrc
.ruff_cache/**
.travis.yml
.vscode-test.mjs
api/**
CODE_OF_CONDUCT.md
CODING_STANDARDS.md
Expand Down Expand Up @@ -83,6 +86,7 @@ obj/**
logs/**
out/**
precommit.hook
pythonFiles/.env
pythonFiles/**/*.pyc
pythonFiles/lib/**/*.dist-info/**
pythonFiles/lib/**/*.egg-info/**
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"theme": "light"
},
"engines": {
"vscode": "^1.100.0"
"vscode": "^1.98.0"
},
"l10n": "./l10n",
"extensionKind": [
Expand Down
2 changes: 1 addition & 1 deletion src/kernels/common/kernelSocketWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function KernelSocketWrapper<T extends ClassType<IWebSocketLike>>(SuperCl
this.msgChain = this.msgChain
.then(() => Promise.all(this.receiveHooks.map((p) => p(args[0]))))
.then(() => superHandler(event, ...args))
.catch((e) => logger.error(`Exception while handling messages: ${e}`));
.catch((e) => logger.error(`Exception while handling messages: `, e, e.stack));
// True value indicates there were handlers. We definitely have 'message' handlers.
return true;
} else {
Expand Down
64 changes: 61 additions & 3 deletions src/kernels/jupyter/jupyterUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type { ServerConnection } from '@jupyterlab/services';
import type { KernelMessage, ServerConnection } from '@jupyterlab/services';
import * as path from '../../platform/vscode-path/path';
import { ConfigurationTarget, Uri, window } from 'vscode';
import { IJupyterConnection } from '../types';
Expand Down Expand Up @@ -137,7 +137,64 @@ export function createJupyterConnectionInfo(
requestInit = { ...requestInit, agent: requestAgent };
}

const { ServerConnection } = require('@jupyterlab/services');
const { ServerConnection } = require('@jupyterlab/services') as typeof import('@jupyterlab/services');
const { deserialize, serialize } =
require('@jupyterlab/services/lib/kernel/serialize') as typeof import('@jupyterlab/services/lib/kernel/serialize');
// const { supportedKernelWebSocketProtocols } =
// require('@jupyterlab/services/lib/kernel/messages') as typeof import('@jupyterlab/services/lib/kernel/messages');

const serializer: import('@jupyterlab/services').ServerConnection.ISettings['serializer'] = {
deserialize: (data: ArrayBuffer, protocol?: string) => {
try {
logger.trace(`1.a UTILS. MESSAGE`, JSON.stringify(data));
} catch (error) {
try {
logger.trace(`1.b UTILS. MESSAGE`, data, error);
} catch (error2) {
logger.error(`1.c UTILS. MESSAGE`, error, error2);
}
}
logger.trace(
`Deserialize message type=${typeof data}, Buffer=${data instanceof Buffer}, ArrayBuffer=${
data instanceof ArrayBuffer
} with ${protocol}`
);
logger.trace(`Deserialize data=${data.toString()}`);
try {
if (typeof data === 'string') {
const result = deserialize(data, '');
logger.trace(`Deserialize message type=string with ${protocol}`);
return result;
}
logger.trace(`Deserialize message type=NOT string with ${protocol}`);
const result = deserialize(data, protocol);
logger.trace(`Deserialize message type=ArrayBuffer with ${protocol}`);
return result;
} catch (ex) {
logger.error(`Failed to deserialize message protocol = ${protocol}`, ex);
throw ex;
// if (protocol) {
// return deserialize(data, supportedKernelWebSocketProtocols.v1KernelWebsocketJupyterOrg);
// } else {
// return deserialize(data, '');
// }
}
},
serialize: (msg: KernelMessage.IMessage, protocol?: string) => {
logger.trace(`Serialize message ${typeof msg} && ${msg instanceof Buffer} with ${protocol}`);
try {
const data = serialize(msg, protocol);
logger.trace(`Serialized message ${typeof msg} && ${msg instanceof Buffer} with ${protocol}`);
return data;
} catch (ex) {
logger.error(
`Failed to serialize message ${typeof msg} && ${msg instanceof Buffer} with ${protocol}`,
ex
);
throw ex;
}
}
};
// This replaces the WebSocket constructor in jupyter lab services with our own implementation
// See _createSocket here:
// https://github.com/jupyterlab/jupyterlab/blob/cfc8ebda95e882b4ed2eefd54863bb8cdb0ab763/packages/services/src/kernel/default.ts
Expand All @@ -155,7 +212,8 @@ export function createJupyterConnectionInfo(
) as any),
fetch: serverUri.fetch || requestCreator.getFetchMethod(),
Request: requestCreator.getRequestCtor(undefined, allowUnauthorized, getAuthHeader),
Headers: requestCreator.getHeadersCtor()
Headers: requestCreator.getHeadersCtor(),
serializer
};

const connection: IJupyterConnection = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,73 @@ export class IPyWidgetMessageDispatcher implements IIPyWidgetMessageDispatcher {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const jupyterLabSerialize =
require('@jupyterlab/services/lib/kernel/serialize') as typeof import('@jupyterlab/services/lib/kernel/serialize'); // NOSONAR
this.deserialize = jupyterLabSerialize.deserialize;
this.deserialize = (data: ArrayBuffer, protocol?: string) => {
if (
data &&
typeof data === 'object' &&
(data as unknown as KernelMessage.IMessage<KernelMessage.MessageType>).header &&
(data as unknown as KernelMessage.IMessage<KernelMessage.MessageType>).channel
) {
logger.trace(
`1.0 WIDGET. Deserialize message not required, has header and channel properties ${protocol}`
);
}
try {
logger.trace(`1.a WIDGET. MESSAGE`, JSON.stringify(data));
} catch (error) {
try {
logger.trace(`1.b WIDGET. MESSAGE`, data, error);
} catch (error2) {
logger.error(`1.c WIDGET. MESSAGE`, error, error2);
}
}
logger.trace(
`1. WIDGET. Deserialize message type=${typeof data}, Buffer=${data instanceof Buffer}, ArrayBuffer=${
data instanceof ArrayBuffer
} with ${protocol}`
);
logger.trace(`1. WIDGET. Deserialize data=${data.toString()}`);
try {
if (typeof data === 'string') {
const result = jupyterLabSerialize.deserialize(data, '');
logger.trace(`1. WIDGET. Deserialize message type=string with ${protocol}`);
return result;
}
if (
data &&
typeof data === 'object' &&
(data as unknown as KernelMessage.IMessage<KernelMessage.MessageType>).header &&
(data as unknown as KernelMessage.IMessage<KernelMessage.MessageType>).channel
) {
logger.trace(
`1.x WIDGET. Deserialize message not required, has header and channel properties ${protocol}`
);
try {
logger.trace(
`1.y WIDGET. Deserialize message not required type=JSON object with ${protocol}`,
JSON.stringify(data)
);
} catch {
logger.trace(
`1.z WIDGET. Deserialize message not required type=JSON object with ${protocol}`,
data
);
}
return data as unknown as KernelMessage.IMessage<KernelMessage.MessageType>;
}
const result = jupyterLabSerialize.deserialize(data, protocol);
logger.trace(`1. WIDGET. Deserialize message type=ArrayBuffer with ${protocol}`);
return result;
} catch (ex) {
logger.error(`1. WIDGET. Failed to deserialize message protocol = ${protocol}`, ex);
throw ex;
// if (protocol) {
// return deserialize(data, supportedKernelWebSocketProtocols.v1KernelWebsocketJupyterOrg);
// } else {
// return deserialize(data, '');
// }
}
};
}
public dispose() {
this.disposed = true;
Expand Down