Skip to content

Commit

Permalink
-add iopub message signal
Browse files Browse the repository at this point in the history
-remove debugger UI code
-remove logs
-normalize paths
  • Loading branch information
David committed Jun 18, 2021
1 parent 4626bbf commit e9bfc0d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/client/datascience/baseJupyterSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export abstract class BaseJupyterSession implements IJupyterSession {
}
return this.onStatusChangedEvent.event;
}
public get onIOPubMessageSignal(): Event<KernelMessage.IIOPubMessage> {
if (!this.ioPubEventEmitter) {
this.ioPubEventEmitter = new EventEmitter<KernelMessage.IIOPubMessage>();
}
return this.ioPubEventEmitter.event;
}

public get status(): ServerStatus {
return this.getServerStatus();
Expand Down
1 change: 1 addition & 0 deletions src/client/datascience/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export interface IDebuggingManager {}
export const IJupyterSession = Symbol('IJupyterSession');
export interface IJupyterSession extends IAsyncDisposable {
onSessionStatusChanged: Event<ServerStatus>;
onIOPubMessageSignal: Event<KernelMessage.IIOPubMessage>;
readonly status: ServerStatus;
readonly workingDirectory: string;
readonly kernelSocket: Observable<KernelSocketInformation | undefined>;
Expand Down
26 changes: 5 additions & 21 deletions src/client/debugger/jupyter/debuggingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class DebuggingManager implements IDebuggingManager, IExtensionSingleActi
for (const [doc, dbg] of this.notebookToDebugger.entries()) {
if (dbg && session === (await dbg.session)) {
this.notebookToDebugger.delete(doc);
this.updateDebuggerUI(doc, false);
break;
}
}
Expand Down Expand Up @@ -125,7 +124,6 @@ export class DebuggingManager implements IDebuggingManager, IExtensionSingleActi
}

private async toggleDebugging(doc: vscode.NotebookDocument) {
let showBreakpointMargin = false;
let dbg = this.notebookToDebugger.get(doc);
if (dbg) {
await dbg.stop();
Expand All @@ -136,17 +134,13 @@ export class DebuggingManager implements IDebuggingManager, IExtensionSingleActi
await this.kernelProvider.get(doc.uri); // ensure the kernel is running
try {
await dbg.session;
showBreakpointMargin = true;
} catch (err) {
vscode.window.showErrorMessage(`Can't start debugging (${err})`);
}
this.updateDebuggerUI(doc, showBreakpointMargin);
}
}

private async getDebuggerByUri(document: vscode.NotebookDocument): Promise<Debugger> {
let showBreakpointMargin = false;

for (const [doc, dbg] of this.notebookToDebugger.entries()) {
if (document.uri.toString() === doc.uri.toString()) {
return dbg;
Expand All @@ -156,23 +150,13 @@ export class DebuggingManager implements IDebuggingManager, IExtensionSingleActi
const dbg = new Debugger(document);
this.notebookToDebugger.set(document, dbg);
await this.kernelProvider.get(document.uri); // ensure the kernel is running
try {
await dbg.session;
showBreakpointMargin = true;
} catch (err) {
vscode.window.showErrorMessage(`Can't start debugging (${err})`);
}
this.updateDebuggerUI(document, showBreakpointMargin);
// try {
// await dbg.session;
// } catch (err) {
// vscode.window.showErrorMessage(`Can't start debugging (${err})`);
// }
return dbg;
}

private updateDebuggerUI(doc: vscode.NotebookDocument, showBreakpointsMargin: boolean) {
for (const cell of doc.getCells()) {
if (cell.kind === vscode.NotebookCellKind.Code) {
cell.metadata.breakpointMargin = showBreakpointsMargin;
}
}
}
}

class Debugger {
Expand Down
22 changes: 11 additions & 11 deletions src/client/debugger/jupyter/kernelDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ export class KernelDebugAdapter implements vscode.DebugAdapter {
private session: vscode.DebugSession,
private notebookDocument: vscode.NotebookDocument,
private readonly jupyterSession: IJupyterSession
) {}
) {
const iopubHandler = (msg: KernelMessage.IIOPubMessage) => {
if ((msg.content as any).event === 'stopped') {
this.sendMessage.fire(msg.content);
}
};
this.jupyterSession.onIOPubMessageSignal(iopubHandler);
}

async handleMessage(message: DebugProtocol.ProtocolMessage) {
// console.log('-> send', message);

// intercept 'setBreakpoints' request
if (message.type === 'request' && (message as DebugProtocol.Request).command === 'setBreakpoints') {
const args = (message as DebugProtocol.Request).arguments;
Expand Down Expand Up @@ -60,8 +65,6 @@ export class KernelDebugAdapter implements vscode.DebugAdapter {
if (control) {
control.onReply = (msg) => {
visitSources(msg.content, (source) => {
console.error('------------------ onReply ------------');
console.error(msg);
if (source && source.path) {
const cell = this.fileToCell.get(source.path);
if (cell) {
Expand All @@ -78,8 +81,6 @@ export class KernelDebugAdapter implements vscode.DebugAdapter {
};
control.onIOPub = (msg) => {
visitSources(msg.content as DebugProtocol.ProtocolMessage, (source) => {
console.error('------------------ onIOPub ------------');
console.error(msg);
if (source && source.path) {
const cell = this.fileToCell.get(source.path);
if (cell) {
Expand All @@ -96,8 +97,6 @@ export class KernelDebugAdapter implements vscode.DebugAdapter {
};
control.onStdin = (msg) => {
visitSources(msg.content as DebugProtocol.ProtocolMessage, (source) => {
console.error('------------------ onStdin ------------');
console.error(msg);
if (source && source.path) {
const cell = this.fileToCell.get(source.path);
if (cell) {
Expand Down Expand Up @@ -141,8 +140,9 @@ export class KernelDebugAdapter implements vscode.DebugAdapter {
if (cell) {
try {
const response = await this.session.customRequest('dumpCell', { code: cell.document.getText() });
this.fileToCell.set(response.sourcePath, cell);
this.cellToFile.set(cell.document.uri.toString(), response.sourcePath);
const norm = path.normalize(response.sourcePath);
this.fileToCell.set(norm, cell);
this.cellToFile.set(cell.document.uri.toString(), norm);
} catch (err) {
console.log(err);
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/datascience/mockJupyterSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class MockJupyterSession implements IJupyterSession {
}
return this.onStatusChangedEvent.event;
}
public get onIOPubMessageSignal(): Event<KernelMessage.IIOPubMessage> {
return new EventEmitter<KernelMessage.IIOPubMessage>().event;
}
public get status(): ServerStatus {
return this._status;
}
Expand Down

0 comments on commit e9bfc0d

Please sign in to comment.