(
protected session: DebugSession,
protected notebookDocument: NotebookDocument,
protected readonly jupyterSession: IKernelSession,
private readonly kernel: IKernel | undefined,
private readonly platformService: IPlatformService,
private readonly debugService: IDebugService
)
| 64 | public readonly debugCell: NotebookCell | undefined; |
| 65 | private disconnected: boolean = false; |
| 66 | constructor( |
| 67 | protected session: DebugSession, |
| 68 | protected notebookDocument: NotebookDocument, |
| 69 | protected readonly jupyterSession: IKernelSession, |
| 70 | private readonly kernel: IKernel | undefined, |
| 71 | private readonly platformService: IPlatformService, |
| 72 | private readonly debugService: IDebugService |
| 73 | ) { |
| 74 | logger.ci(`Creating kernel debug adapter for debugging notebooks`); |
| 75 | const configuration = this.session.configuration; |
| 76 | assertIsDebugConfig(configuration); |
| 77 | this.configuration = configuration; |
| 78 | this.debugCell = notebookDocument.cellAt(configuration.__cellIndex!); |
| 79 | |
| 80 | this.addDebuggingDelegates([new ResetKernelController(this)]); |
| 81 | |
| 82 | this.jupyterSession.kernel?.iopubMessage.connect(this.onIOPubMessage, this); |
| 83 | this.disposables.push( |
| 84 | new Disposable(() => this.jupyterSession.kernel?.iopubMessage.disconnect(this.onIOPubMessage, this)) |
| 85 | ); |
| 86 | |
| 87 | if (this.kernel) { |
| 88 | this.kernel.addHook('willRestart', () => this.disconnect(), this, this.disposables); |
| 89 | this.kernel.addHook('interruptCompleted', () => this.disconnect(), this, this.disposables); |
| 90 | this.disposables.push( |
| 91 | this.kernel.onDisposed(() => { |
| 92 | if (!this.disconnected) { |
| 93 | debug.stopDebugging(this.session).then(noop, noop); |
| 94 | this.disconnect().catch(noop); |
| 95 | sendTelemetryEvent(DebuggingTelemetry.endedSession, undefined, { reason: 'onKernelDisposed' }); |
| 96 | } |
| 97 | }) |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | this.disposables.push( |
| 102 | notebookCellExecutions.onDidChangeNotebookCellExecutionState( |
| 103 | (cellStateChange: NotebookCellExecutionStateChangeEvent) => { |
| 104 | // If a cell has moved to idle, stop the debug session |
| 105 | if ( |
| 106 | this.configuration.__cellIndex === cellStateChange.cell.index && |
| 107 | cellStateChange.state === NotebookCellExecutionState.Idle && |
| 108 | !this.disconnected |
| 109 | ) { |
| 110 | sendTelemetryEvent(DebuggingTelemetry.endedSession, undefined, { reason: 'normally' }); |
| 111 | this.disconnect().catch(noop); |
| 112 | } |
| 113 | }, |
| 114 | this, |
| 115 | this.disposables |
| 116 | ) |
| 117 | ); |
| 118 | |
| 119 | this.disposables.push( |
| 120 | workspace.onDidChangeNotebookDocument( |
| 121 | (e) => { |
| 122 | e.contentChanges.forEach((change) => { |
| 123 | change.removedCells.forEach((cell: NotebookCell) => { |
nothing calls this directly
no test coverage detected