diff --git a/src/interactive-window/debugger/jupyter/debuggingManager.ts b/src/interactive-window/debugger/jupyter/debuggingManager.ts index 85d79b363b1..be281123409 100644 --- a/src/interactive-window/debugger/jupyter/debuggingManager.ts +++ b/src/interactive-window/debugger/jupyter/debuggingManager.ts @@ -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. @@ -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)); diff --git a/src/interactive-window/debugger/jupyter/restartNotSupportedController.ts b/src/interactive-window/debugger/jupyter/restartNotSupportedController.ts new file mode 100644 index 00000000000..273e342aca5 --- /dev/null +++ b/src/interactive-window/debugger/jupyter/restartNotSupportedController.ts @@ -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); + } + + private trace(tag: string, msg: string) { + traceVerbose(`[Debug-IWRestart] ${tag}: ${msg}`); + } + + public async willSendResponse(response: DebugProtocol.Response): Promise { + if (response.command === 'initialize' && response.body) { + (response as DebugProtocol.InitializeResponse).body!.supportsRestartRequest = true; + } + } + + public async willSendRequest(request: DebugProtocol.Request): Promise { + 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; + } +} diff --git a/src/notebooks/debugger/controllers/restartController.ts b/src/notebooks/debugger/controllers/restartController.ts index 3ecea1639bf..4de1f8d026c 100644 --- a/src/notebooks/debugger/controllers/restartController.ts +++ b/src/notebooks/debugger/controllers/restartController.ts @@ -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'; /** @@ -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); } @@ -33,6 +30,12 @@ export class RestartController implements IDebuggingDelegate { traceError(`[Debug-Restart] ${tag}: ${msg}`); } + public async willSendResponse(response: DebugProtocol.Response): Promise { + if (response.command === 'initialize' && response.body) { + (response as DebugProtocol.InitializeResponse).body!.supportsRestartRequest = true; + } + } + public async willSendRequest(request: DebugProtocol.Request): Promise { 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. @@ -61,10 +64,4 @@ export class RestartController implements IDebuggingDelegate { return undefined; } - - public async willSendResponse(response: DebugProtocol.Response): Promise { - if (response.command === 'initialize' && response.body) { - (response as DebugProtocol.InitializeResponse).body!.supportsRestartRequest = true; - } - } } diff --git a/src/platform/common/utils/localize.ts b/src/platform/common/utils/localize.ts index f0b4cca297e..8c9c6b0821e 100644 --- a/src/platform/common/utils/localize.ts +++ b/src/platform/common/utils/localize.ts @@ -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 = () =>