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

Run by Line: disconnect at last line #6974

Merged
merged 13 commits into from
Aug 9, 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
1 change: 1 addition & 0 deletions news/2 Fixes/6858.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Run by line now stops after running the last line.
26 changes: 22 additions & 4 deletions src/client/debugger/jupyter/kernelDebugAdapter.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,10 @@ import {
NotebookCell,
Event,
EventEmitter,
DebugProtocolMessage
DebugProtocolMessage,
notebooks,
NotebookCellExecutionStateChangeEvent,
NotebookCellExecutionState
} from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { randomBytes } from 'crypto';
@@ -21,6 +24,7 @@ import { ICommandManager } from '../../common/application/types';
import { traceError } from '../../common/logger';
import { IFileSystem } from '../../common/platform/types';
import { IKernelDebugAdapter } from '../types';
import { IDisposable } from '../../common/types';

const debugRequest = (message: DebugProtocol.Request, jupyterSessionId: string): KernelMessage.IDebugRequestMsg => {
return {
@@ -91,13 +95,14 @@ interface debugInfoResponseBreakpoint {
// For info on the custom requests implemented by jupyter see:
// https://jupyter-client.readthedocs.io/en/stable/messaging.html#debug-request
// https://jupyter-client.readthedocs.io/en/stable/messaging.html#additions-to-the-dap
export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter {
export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, IDisposable {
private readonly fileToCell = new Map<string, NotebookCell>();
private readonly cellToFile = new Map<string, string>();
private readonly sendMessage = new EventEmitter<DebugProtocolMessage>();
private isRunByLine = false;
private runByLineThreadId: number = 1;
private runByLineSeq: number = 0;
private readonly disposables: IDisposable[] = [];

onDidSendMessage: Event<DebugProtocolMessage> = this.sendMessage.event;

@@ -116,14 +121,26 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const content = msg.content as any;
if (content.event === 'stopped') {
this.runByLineThreadId = content.body.threadId;
this.runByLineSeq = content.seq;
if (this.isRunByLine) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code work if i have a cell as follows:

def do_something():
    print("Hello")


do_something()

Now, when I'm at the last line, will I be able to step in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or what if i add a breakpoint at line print("Hello")
& then hit continue, surely it shouldn't stop the run by line, but should step into that code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't remember how it used to work, I'll check

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like run by line in the webview doesn't work on stable. I'll go for it anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new approach covers that scenario

this.runByLineThreadId = content.body.threadId;
this.runByLineSeq = content.seq;
}
this.sendMessage.fire(msg.content);
}
};
this.jupyterSession.onIOPubMessage(iopubHandler);

void this.dumpCellsThatRanBeforeDebuggingBegan();
notebooks.onDidChangeNotebookCellExecutionState(
(cellStateChange: NotebookCellExecutionStateChangeEvent) => {
// If a cell has moved to idle, stop the run by line session
if (cellStateChange.state === NotebookCellExecutionState.Idle) {
this.runByLineStop();
}
},
this,
this.disposables
);
}

async handleMessage(message: DebugProtocol.ProtocolMessage) {
@@ -195,6 +212,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter {
}

dispose() {
this.disposables.forEach((d) => d.dispose());
// clean temp files
this.cellToFile.forEach((tempPath) => {
const norm = path.normalize(tempPath);