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

Add "Debug Cell" #7059

Merged
merged 7 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
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
22 changes: 17 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
"key": "ctrl+r",
"mac": "cmd+r",
"when": "jupyter.dataViewerActive"
},
{
"command": "jupyter.runAndDebugCell",
"key": "ctrl+alt+shift+enter",
"mac": "ctrl+shift+enter"
}
],
"commands": [
Expand All @@ -289,6 +294,12 @@
"category": "Jupyter",
"enablement": "notebookKernelCount > 0 && !jupyter.notebookeditor.debuggingInProgress && !jupyter.notebookeditor.runByLineInProgress && config.jupyter.experimental.debugging"
},
{
"command": "jupyter.runAndDebugCell",
"title": "Debug Cell",
"icon": "$(debug-alt-small)",
"category": "Jupyter"
},
{
"command": "jupyter.runByLineContinue",
"title": "Continue",
Expand Down Expand Up @@ -937,11 +948,6 @@
"command": "jupyter.notebookeditor.export",
"group": "Jupyter",
"when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted"
},
{
"command": "jupyter.debugNotebook",
"group": "navigation@3",
"when": "notebookType == 'jupyter-notebook' && isWorkspaceTrusted && config.jupyter.experimental.debugging"
}
],
"notebook/cell/title": [
Expand All @@ -961,6 +967,12 @@
"group": "inline/cell@0"
}
],
"notebook/cell/execute": [
{
"command": "jupyter.runAndDebugCell",
"when": "notebookType == jupyter-notebook && notebookCellType == code && isWorkspaceTrusted && !jupyter.notebookeditor.runByLineInProgress && config.jupyter.experimental.debugging"
}
],
"interactive/toolbar": [
{
"command": "jupyter.interactive.clearAllCells",
Expand Down
1 change: 1 addition & 0 deletions src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
[DSCommands.NotebookEditorKeybindUndo]: [];
[DSCommands.DebugNotebook]: [];
[DSCommands.RunByLine]: [NotebookCell];
[DSCommands.RunAndDebugCell]: [NotebookCell];
[DSCommands.RunByLineContinue]: [NotebookCell];
[DSCommands.RunByLineStop]: [NotebookCell];
}
1 change: 1 addition & 0 deletions src/client/datascience/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export namespace Commands {
export const InteractiveExportAs = 'jupyter.interactive.exportas';
export const DebugNotebook = 'jupyter.debugNotebook';
export const RunByLine = 'jupyter.runByLine';
export const RunAndDebugCell = 'jupyter.runAndDebugCell';
export const RunByLineContinue = 'jupyter.runByLineContinue';
export const RunByLineStop = 'jupyter.runByLineStop';
}
Expand Down
83 changes: 65 additions & 18 deletions src/client/debugger/jupyter/debuggingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import * as path from 'path';
import { IKernelProvider } from '../../datascience/jupyter/kernels/types';
import { IDisposable } from '../../common/types';
import { KernelDebugAdapter } from './kernelDebugAdapter';
import { IKernelDebugAdapterConfig, KernelDebugAdapter, KernelDebugMode } from './kernelDebugAdapter';
import { IDebuggingCellMap, INotebookProvider } from '../../datascience/types';
import { IExtensionSingleActivationService } from '../../activation/types';
import { ServerStatus } from '../../../datascience-ui/interactive-common/mainState';
Expand Down Expand Up @@ -111,7 +111,7 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb
this.updateToolbar(false);
this.updateCellToolbar(false);
for (const [doc, dbg] of this.notebookToDebugger.entries()) {
if (dbg && session === (await dbg.session)) {
if (dbg && session.id === (await dbg.session).id) {
this.debuggingCellMap.getCellsAndClearQueue(doc);
this.notebookToDebugger.delete(doc);
break;
Expand Down Expand Up @@ -189,7 +189,7 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb
if (editor) {
this.updateToolbar(true);
this.updateCellToolbar(true);
void this.startDebugging(editor.document, cell, { debugUI: { simple: true } });
void this.startDebuggingCell(editor.document, KernelDebugMode.RunByLine, cell);
} else {
void this.appShell.showErrorMessage(DataScience.noNotebookToDebug());
}
Expand All @@ -207,7 +207,28 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb
this.commandManager.registerCommand(DSCommands.RunByLineStop, (cell: NotebookCell) => {
const adapter = this.notebookToDebugAdapter.get(cell.notebook);
if (adapter) {
adapter.runByLineStop();
adapter.disconnect();
} else {
void this.appShell.showErrorMessage(DataScience.noNotebookToDebug());
}
}),

this.commandManager.registerCommand(DSCommands.RunAndDebugCell, (cell: NotebookCell | undefined) => {
const editor = this.vscNotebook.activeNotebookEditor;
if (!cell) {
const range = editor?.selections[0];
if (range) {
cell = editor?.document.cellAt(range.start);
}
}

if (!cell) {
return;
}

if (editor) {
this.updateToolbar(true);
void this.startDebuggingCell(editor.document, KernelDebugMode.Cell, cell);
} else {
void this.appShell.showErrorMessage(DataScience.noNotebookToDebug());
}
Expand All @@ -234,22 +255,48 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb
this.runByLineInProgress.set(runningByLine).ignoreErrors();
}

private async startDebugging(doc: NotebookDocument, cell?: NotebookCell, options?: DebugSessionOptions) {
private async startDebuggingCell(
doc: NotebookDocument,
mode: KernelDebugMode.Cell | KernelDebugMode.RunByLine,
cell: NotebookCell
) {
const config: IKernelDebugAdapterConfig = {
type: pythonKernelDebugAdapter,
name: path.basename(doc.uri.toString()),
request: 'attach',
internalConsoleOptions: 'neverOpen',
justMyCode: true,
// add the doc uri to the config
__document: doc.uri.toString(),
Copy link
Member Author

Choose a reason for hiding this comment

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

@DavidKutu is this used anywhere? I couldn't actually find a usage

Choose a reason for hiding this comment

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

Yeah, I guess I removed it. We send the NotebookDocument as a parameter anyway. I'll remove it on my next PR.

// add a property to the config to know if the session is runByLine
__mode: mode,
__cellIndex: cell.index
};
const opts = mode === KernelDebugMode.RunByLine ? { debugUI: { simple: true } } : undefined;
return this.startDebuggingConfig(doc, config, opts);
}

private async startDebugging(doc: NotebookDocument) {
const config: IKernelDebugAdapterConfig = {
type: pythonKernelDebugAdapter,
name: path.basename(doc.uri.toString()),
request: 'attach',
internalConsoleOptions: 'neverOpen',
justMyCode: false,
// add the doc uri to the config
__document: doc.uri.toString(),
__mode: KernelDebugMode.Everything
};
return this.startDebuggingConfig(doc, config);
}

private async startDebuggingConfig(
doc: NotebookDocument,
config: IKernelDebugAdapterConfig,
options?: DebugSessionOptions
) {
let dbg = this.notebookToDebugger.get(doc);
if (!dbg) {
const config: DebugConfiguration = {
type: pythonKernelDebugAdapter,
name: path.basename(doc.uri.toString()),
request: 'attach',
internalConsoleOptions: 'neverOpen',
justMyCode: cell ? true : false,
// add the doc uri to the config
__document: doc.uri.toString(),
// add a property to the config to know if the session is runByLine
__runByLine: cell ? true : false,
// if the debugger was called from a cell, add it
__cellIndex: cell ? cell.index : undefined
};
dbg = new Debugger(doc, config, options);
this.notebookToDebugger.set(doc, dbg);

Expand Down
Loading