From 50c35ca30c6f79ce6f39258dcf68be0892a607db Mon Sep 17 00:00:00 2001 From: David Kutugata Date: Fri, 27 Aug 2021 16:36:35 -0700 Subject: [PATCH 1/4] put BP on first code line --- .../debugger/jupyter/kernelDebugAdapter.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/client/debugger/jupyter/kernelDebugAdapter.ts b/src/client/debugger/jupyter/kernelDebugAdapter.ts index 65a564c3333..db83b2c7078 100644 --- a/src/client/debugger/jupyter/kernelDebugAdapter.ts +++ b/src/client/debugger/jupyter/kernelDebugAdapter.ts @@ -496,8 +496,21 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID await this.dumpCell(cell.document.uri.toString()); if (this.configuration.__mode === KernelDebugMode.RunByLine) { + const textLines = cell.document.getText().split('\r\n'); + let firstLine = 0; + for (let i = 0; i < textLines.length; i++) { + if (textLines[i].trim().charAt(0) === '#') { + continue; + } + if (textLines[i].trim().length === 0) { + continue; + } + firstLine = i; + break; + } + const initialBreakpoint: DebugProtocol.SourceBreakpoint = { - line: 1 + line: firstLine + 1 }; const splitPath = cell.notebook.uri.path.split('/'); const name = splitPath[splitPath.length - 1]; @@ -510,7 +523,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID name: name, path: cell.document.uri.toString() }, - lines: [1], + lines: [firstLine + 1], breakpoints: [initialBreakpoint], sourceModified: false } From af58238227744fc9e7dc0edcb7d0f0402610d9e2 Mon Sep 17 00:00:00 2001 From: David Kutugata Date: Fri, 27 Aug 2021 16:52:25 -0700 Subject: [PATCH 2/4] better way --- .../debugger/jupyter/kernelDebugAdapter.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/client/debugger/jupyter/kernelDebugAdapter.ts b/src/client/debugger/jupyter/kernelDebugAdapter.ts index db83b2c7078..67fa852195b 100644 --- a/src/client/debugger/jupyter/kernelDebugAdapter.ts +++ b/src/client/debugger/jupyter/kernelDebugAdapter.ts @@ -32,6 +32,8 @@ import { Commands, Identifiers } from '../../datascience/constants'; import { IKernel } from '../../datascience/jupyter/kernels/types'; import { sendTelemetryEvent } from '../../telemetry'; import { DebuggingTelemetry } from '../constants'; +import { parseForComments } from '../../../datascience-ui/common'; +import { noop } from '../../common/utils/misc'; interface dumpCellResponse { sourcePath: string; // filename for the dumped source @@ -497,20 +499,20 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID if (this.configuration.__mode === KernelDebugMode.RunByLine) { const textLines = cell.document.getText().split('\r\n'); - let firstLine = 0; - for (let i = 0; i < textLines.length; i++) { - if (textLines[i].trim().charAt(0) === '#') { - continue; - } - if (textLines[i].trim().length === 0) { - continue; + const lineList: number[] = []; + parseForComments( + textLines, + () => noop(), + (s, i) => { + if (s.trim().length !== 0) { + lineList.push(i); + } } - firstLine = i; - break; - } + ); + lineList.sort(); const initialBreakpoint: DebugProtocol.SourceBreakpoint = { - line: firstLine + 1 + line: lineList[0] + 1 }; const splitPath = cell.notebook.uri.path.split('/'); const name = splitPath[splitPath.length - 1]; @@ -523,7 +525,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID name: name, path: cell.document.uri.toString() }, - lines: [firstLine + 1], + lines: [lineList[0] + 1], breakpoints: [initialBreakpoint], sourceModified: false } From a75b250915b3c11c038656c51b7b2bb7299eff9c Mon Sep 17 00:00:00 2001 From: David Kutugata Date: Fri, 27 Aug 2021 17:28:00 -0700 Subject: [PATCH 3/4] don't set a breakpoint if its all comments or empty lines --- .../debugger/jupyter/kernelDebugAdapter.ts | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/client/debugger/jupyter/kernelDebugAdapter.ts b/src/client/debugger/jupyter/kernelDebugAdapter.ts index 67fa852195b..90bfae28862 100644 --- a/src/client/debugger/jupyter/kernelDebugAdapter.ts +++ b/src/client/debugger/jupyter/kernelDebugAdapter.ts @@ -498,7 +498,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID await this.dumpCell(cell.document.uri.toString()); if (this.configuration.__mode === KernelDebugMode.RunByLine) { - const textLines = cell.document.getText().split('\r\n'); + const textLines = cell.document.getText().splitLines({ trim: false, removeEmptyEntries: false }); const lineList: number[] = []; parseForComments( textLines, @@ -511,31 +511,33 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID ); lineList.sort(); - const initialBreakpoint: DebugProtocol.SourceBreakpoint = { - line: lineList[0] + 1 - }; - const splitPath = cell.notebook.uri.path.split('/'); - const name = splitPath[splitPath.length - 1]; - const message: DebugProtocol.SetBreakpointsRequest = { - seq: seq + 1, - type: 'request', - command: 'setBreakpoints', - arguments: { - source: { - name: name, - path: cell.document.uri.toString() - }, - lines: [lineList[0] + 1], - breakpoints: [initialBreakpoint], - sourceModified: false - } - }; - this.sendRequestToJupyterSession(message); + if (lineList.length !== 0) { + const initialBreakpoint: DebugProtocol.SourceBreakpoint = { + line: lineList[0] + 1 + }; + const splitPath = cell.notebook.uri.path.split('/'); + const name = splitPath[splitPath.length - 1]; + const message: DebugProtocol.SetBreakpointsRequest = { + seq: seq + 1, + type: 'request', + command: 'setBreakpoints', + arguments: { + source: { + name: name, + path: cell.document.uri.toString() + }, + lines: [lineList[0] + 1], + breakpoints: [initialBreakpoint], + sourceModified: false + } + }; + this.sendRequestToJupyterSession(message); - // Open variable view - const settings = this.settings.getSettings(); - if (settings.showVariableViewWhenDebugging) { - await this.commandManager.executeCommand(Commands.OpenVariableView); + // Open variable view + const settings = this.settings.getSettings(); + if (settings.showVariableViewWhenDebugging) { + await this.commandManager.executeCommand(Commands.OpenVariableView); + } } } From 8a50f7603bd461bb38550b94d2f250f55280a17e Mon Sep 17 00:00:00 2001 From: David Date: Mon, 30 Aug 2021 10:26:05 -0700 Subject: [PATCH 4/4] PR comments --- src/client/debugger/jupyter/kernelDebugAdapter.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/client/debugger/jupyter/kernelDebugAdapter.ts b/src/client/debugger/jupyter/kernelDebugAdapter.ts index 90bfae28862..042899b4e5a 100644 --- a/src/client/debugger/jupyter/kernelDebugAdapter.ts +++ b/src/client/debugger/jupyter/kernelDebugAdapter.ts @@ -498,6 +498,8 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID await this.dumpCell(cell.document.uri.toString()); if (this.configuration.__mode === KernelDebugMode.RunByLine) { + // This will save the code lines of the cell in lineList (so ignore comments and emtpy lines) + // Its done to set the Run by Line breakpoint on the first code line const textLines = cell.document.getText().splitLines({ trim: false, removeEmptyEntries: false }); const lineList: number[] = []; parseForComments( @@ -511,19 +513,18 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID ); lineList.sort(); + // Don't send the SetBreakpointsRequest or open the variable view if there are no code lines if (lineList.length !== 0) { const initialBreakpoint: DebugProtocol.SourceBreakpoint = { line: lineList[0] + 1 }; - const splitPath = cell.notebook.uri.path.split('/'); - const name = splitPath[splitPath.length - 1]; const message: DebugProtocol.SetBreakpointsRequest = { seq: seq + 1, type: 'request', command: 'setBreakpoints', arguments: { source: { - name: name, + name: path.basename(cell.notebook.uri.path), path: cell.document.uri.toString() }, lines: [lineList[0] + 1], @@ -536,7 +537,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID // Open variable view const settings = this.settings.getSettings(); if (settings.showVariableViewWhenDebugging) { - await this.commandManager.executeCommand(Commands.OpenVariableView); + void this.commandManager.executeCommand(Commands.OpenVariableView); } } }