Skip to content

Commit

Permalink
Show error message when trying to restart an IW debug session (#11739)
Browse files Browse the repository at this point in the history
Fix #7670
  • Loading branch information
roblourens authored Oct 21, 2022
1 parent 008f00c commit 5c5f1a2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/interactive-window/debugger/jupyter/debuggingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { buildSourceMap } from '../helper';
import { DebugCellController } from './debugCellController';
import { IWDebugger } from './debugger';
import { KernelDebugAdapter } from './kernelDebugAdapter';
import { RestartNotSupportedController } from './restartNotSupportedController';

/**
* The DebuggingManager maintains the mapping between notebook documents and debug sessions.
Expand Down Expand Up @@ -176,7 +177,7 @@ export class InteractiveWindowDebuggingManager

const cell = notebook.cellAt(config.__cellIndex);
const controller = new DebugCellController(adapter, cell, kernel!);
adapter.setDebuggingDelegates([controller]);
adapter.setDebuggingDelegates([controller, new RestartNotSupportedController(cell, this.serviceContainer)]);
controller.ready
.then(() => dbgr.resolve())
.catch((ex) => console.error('Failed waiting for controller to be ready', ex));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { NotebookCell } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { IDebuggingDelegate } from '../../../notebooks/debugger/debuggingTypes';
import { IApplicationShell } from '../../../platform/common/application/types';
import { DataScience } from '../../../platform/common/utils/localize';
import { noop } from '../../../platform/common/utils/misc';
import { IServiceContainer } from '../../../platform/ioc/types';
import { traceVerbose } from '../../../platform/logging';

/**
* Implements the "restart" request.
*/
export class RestartNotSupportedController implements IDebuggingDelegate {
private readonly applicationShell: IApplicationShell;

constructor(public readonly debugCell: NotebookCell, serviceContainer: IServiceContainer) {
this.applicationShell = serviceContainer.get<IApplicationShell>(IApplicationShell);
}

private trace(tag: string, msg: string) {
traceVerbose(`[Debug-IWRestart] ${tag}: ${msg}`);
}

public async willSendResponse(response: DebugProtocol.Response): Promise<void> {
if (response.command === 'initialize' && response.body) {
(response as DebugProtocol.InitializeResponse).body!.supportsRestartRequest = true;
}
}

public async willSendRequest(request: DebugProtocol.Request): Promise<undefined | DebugProtocol.Response> {
if (request.command === 'restart') {
this.trace('restart', 'Showing warning for unsupported restart request');
this.applicationShell.showWarningMessage(DataScience.restartNotSupported()).then(noop, noop);
return {
command: request.command,
request_seq: request.seq,
seq: request.seq,
success: true,
type: 'response'
};
}

return undefined;
}
}
15 changes: 6 additions & 9 deletions src/notebooks/debugger/controllers/restartController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { NotebookCell } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { IServiceContainer } from '../../../platform/ioc/types';
import { traceError, traceVerbose } from '../../../platform/logging';
import { sendTelemetryEvent } from '../../../telemetry';
import { DebuggingTelemetry } from '../constants';
import { IDebuggingDelegate, IKernelDebugAdapter, INotebookDebuggingManager, KernelDebugMode } from '../debuggingTypes';

/**
Expand All @@ -21,7 +19,6 @@ export class RestartController implements IDebuggingDelegate {
public readonly debugCell: NotebookCell,
private readonly serviceContainer: IServiceContainer
) {
sendTelemetryEvent(DebuggingTelemetry.successfullyStartedRunByLine);
this.debuggingManager = this.serviceContainer.get<INotebookDebuggingManager>(INotebookDebuggingManager);
}

Expand All @@ -33,6 +30,12 @@ export class RestartController implements IDebuggingDelegate {
traceError(`[Debug-Restart] ${tag}: ${msg}`);
}

public async willSendResponse(response: DebugProtocol.Response): Promise<void> {
if (response.command === 'initialize' && response.body) {
(response as DebugProtocol.InitializeResponse).body!.supportsRestartRequest = true;
}
}

public async willSendRequest(request: DebugProtocol.Request): Promise<undefined | DebugProtocol.Response> {
if (request.command === 'restart') {
// We have to implement restart manually because the previous launch config includes the cell index, but the cell index may have changed.
Expand Down Expand Up @@ -61,10 +64,4 @@ export class RestartController implements IDebuggingDelegate {

return undefined;
}

public async willSendResponse(response: DebugProtocol.Response): Promise<void> {
if (response.command === 'initialize' && response.body) {
(response as DebugProtocol.InitializeResponse).body!.supportsRestartRequest = true;
}
}
}
2 changes: 2 additions & 0 deletions src/platform/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ export namespace DataScience {
export const noNotebookToDebug = () =>
localize('DataScience.noNotebookToDebug', 'No active notebook document to debug.');
export const cantStartDebugging = () => localize('DataScience.cantStartDebugging', "Can't start debugging.");
export const restartNotSupported = () =>
localize('DataScience.restartNotSupported', 'Restarting is not supported in the interactive window.');
export const importingIpynb = () => localize('DataScience.importingIpynb', 'Importing notebook file');
export const exportingToFormat = () => localize('DataScience.exportingToFormat', 'Exporting to {0}');
export const kernelCategoryForJupyterSession = () =>
Expand Down

0 comments on commit 5c5f1a2

Please sign in to comment.