Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnect form debugger if user deletes cell while debugging #7666

Merged
merged 3 commits into from
Sep 27, 2021
Merged
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
28 changes: 23 additions & 5 deletions src/client/debugger/jupyter/kernelDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
NotebookCellExecutionState,
NotebookCellExecutionStateChangeEvent,
NotebookCellKind,
NotebookCellsChangeEvent,
NotebookDocument,
notebooks,
Uri
notebooks
} from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { traceError, traceVerbose } from '../../common/logger';
Expand Down Expand Up @@ -51,7 +51,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
private delegate: IDebuggingDelegate | undefined;
onDidSendMessage: Event<DebugProtocolMessage> = this.sendMessage.event;
onDidEndSession: Event<DebugSession> = this.endSession.event;
public readonly debugCellUri: Uri | undefined;
public readonly debugCell: NotebookCell | undefined;
private disconected: boolean = false;

constructor(
Expand All @@ -66,7 +66,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
this.configuration = configuration;

if (configuration.__mode === KernelDebugMode.Cell || configuration.__mode === KernelDebugMode.RunByLine) {
this.debugCellUri = notebookDocument.cellAt(configuration.__cellIndex!)?.document.uri;
this.debugCell = notebookDocument.cellAt(configuration.__cellIndex!);
}

this.disposables.push(
Expand Down Expand Up @@ -122,6 +122,22 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
this.disposables
)
);

this.disposables.push(
notebooks.onDidChangeNotebookCells(
(e: NotebookCellsChangeEvent) => {
e.changes.forEach((change) => {
change.deletedItems.forEach((cell: NotebookCell) => {
if (cell === this.debugCell) {
this.disconnect();
}
});
});
},
this,
this.disposables
)
);
}

public setDebuggingDelegate(delegate: IDebuggingDelegate) {
Expand Down Expand Up @@ -212,7 +228,9 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
const cell = this.notebookDocument.cellAt(index);
if (cell) {
try {
const response = await this.session.customRequest('dumpCell', { code: cell.document.getText() });
const response = await this.session.customRequest('dumpCell', {
code: cell.document.getText().replace(/\r\n/g, '\n')
});
const norm = path.normalize((response as IDumpCellResponse).sourcePath);
this.fileToCell.set(norm, cell);
this.cellToFile.set(cell.document.uri.toString(), norm);
Expand Down