From 82779268ac6c07177e443479fc965183751aaf1c Mon Sep 17 00:00:00 2001 From: Christella Cidolit Date: Tue, 20 Aug 2019 10:26:27 -0700 Subject: [PATCH 1/3] Fixing the pacifica debug configuration overriding python's --- package.json | 8 +++----- src/constants.ts | 2 +- src/extension.ts | 2 +- src/simulatorDebugConfigurationProvider.ts | 6 ++++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 753239860..d29c25697 100644 --- a/package.json +++ b/package.json @@ -180,10 +180,8 @@ ], "debuggers": [ { - "type": "python", + "type": "pacifica", "label": "Pacifica Simulator Debugger", - "program": "./out/debugAdapter.js", - "runtime": "node", "configurationAttributes": { "launch": { "properties": { @@ -224,7 +222,7 @@ }, "initialConfigurations": [ { - "type": "python", + "type": "pacifica", "request": "launch", "name": "Pacifica Simulator Debugger", "program": "${file}", @@ -237,7 +235,7 @@ "label": "Pacifica Simulator Debugger : Launch", "description": "Pacifica Simulator Debugger - A configuration for debugging a python code file for the Pacifica simulator.", "body": { - "type": "python", + "type": "pacifica", "request": "launch", "name": "Pacifica Simulator Debugger", "program": "${file}", diff --git a/src/constants.ts b/src/constants.ts index d74e64ba4..8aac4b7e9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -17,7 +17,7 @@ const localize: nls.LocalizeFunc = nls.config({ })(); export const CONSTANTS = { - DEBUG_CONFIGURATION_NAME: "Pacifica Simulator Debugger", + DEBUG_CONFIGURATION_TYPE: "pacifica", DEPENDENCY_CHECKER: { PYTHON: "python", PYTHON3: "python3", diff --git a/src/extension.ts b/src/extension.ts index 1425348ab..7fce2573d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -675,7 +675,7 @@ export async function activate(context: vscode.ExtensionContext) { runDevice, selectSerialPort, vscode.debug.registerDebugConfigurationProvider( - "python", + "pacifica", simulatorDebugConfiguration ), debugSessionsStarted, diff --git a/src/simulatorDebugConfigurationProvider.ts b/src/simulatorDebugConfigurationProvider.ts index 15d87c117..475893311 100644 --- a/src/simulatorDebugConfigurationProvider.ts +++ b/src/simulatorDebugConfigurationProvider.ts @@ -22,8 +22,8 @@ export class SimulatorDebugConfigurationProvider config: vscode.DebugConfiguration, token?: vscode.CancellationToken ): vscode.ProviderResult { - // Check config name - if (config.name === CONSTANTS.DEBUG_CONFIGURATION_NAME) { + // Check config type + if (config.type === CONSTANTS.DEBUG_CONFIGURATION_TYPE) { const activeTextEditor = vscode.window.activeTextEditor; if (activeTextEditor) { const currentFilePath = activeTextEditor.document.fileName; @@ -50,6 +50,8 @@ export class SimulatorDebugConfigurationProvider } }); } + // Set the new configuration type so the python debugger can take over + config.type = "python"; // Set process_user_code path as program config.program = this.pathToScript; // Set user's code path and server's port as args From d9cb9f0c98936e3a8e2e4d6ff14c9c1044388ede Mon Sep 17 00:00:00 2001 From: Christella Cidolit Date: Tue, 20 Aug 2019 10:31:17 -0700 Subject: [PATCH 2/3] Debug configuration improvements (preventing output panel to open and simulator on regular python debug + creating a config if no launch.json) --- package.json | 24 ++++--- src/extension.ts | 79 +++++++++++----------- src/simulatorDebugConfigurationProvider.ts | 24 ++++++- 3 files changed, 75 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index d29c25697..7f9165427 100644 --- a/package.json +++ b/package.json @@ -182,6 +182,9 @@ { "type": "pacifica", "label": "Pacifica Simulator Debugger", + "languages": [ + "python" + ], "configurationAttributes": { "launch": { "properties": { @@ -193,12 +196,17 @@ "stopOnEntry": { "type": "boolean", "description": "Automatically stop after launch.", - "default": false - }, - "justMyCode": { - "type": "boolean", "default": true }, + "console": { + "enum": [ + "internalConsole", + "integratedTerminal", + "externalTerminal" + ], + "description": "Where to launch the debug target: internal console, integrated terminal, or external terminal.", + "default": "integratedTerminal" + }, "args": { "type": "array", "description": "Command line arguments passed to the program.", @@ -225,9 +233,7 @@ "type": "pacifica", "request": "launch", "name": "Pacifica Simulator Debugger", - "program": "${file}", - "stopOnEntry": false, - "justMyCode": true + "console": "integratedTerminal" } ], "configurationSnippets": [ @@ -238,9 +244,7 @@ "type": "pacifica", "request": "launch", "name": "Pacifica Simulator Debugger", - "program": "${file}", - "stopOnEntry": false, - "justMyCode": true + "console": "integratedTerminal" } } ] diff --git a/src/extension.ts b/src/extension.ts index 7fce2573d..a9a7fa43f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -63,11 +63,7 @@ export async function activate(context: vscode.ExtensionContext) { if (outChannel === undefined) { outChannel = vscode.window.createOutputChannel(CONSTANTS.NAME); - utils.logToOutputChannel( - outChannel, - CONSTANTS.INFO.WELCOME_OUTPUT_TAB, - true - ); + utils.logToOutputChannel(outChannel, CONSTANTS.INFO.WELCOME_OUTPUT_TAB); } vscode.workspace.onDidSaveTextDocument( @@ -297,7 +293,7 @@ export async function activate(context: vscode.ExtensionContext) { console.info(CONSTANTS.INFO.RUNNING_CODE); - utils.logToOutputChannel(outChannel, CONSTANTS.INFO.DEPLOY_SIMULATOR); + utils.logToOutputChannel(outChannel, CONSTANTS.INFO.DEPLOY_SIMULATOR, true); killProcessIfRunning(); @@ -450,7 +446,7 @@ export async function activate(context: vscode.ExtensionContext) { const deployCodeToDevice = async () => { console.info("Sending code to device"); - utils.logToOutputChannel(outChannel, CONSTANTS.INFO.DEPLOY_DEVICE); + utils.logToOutputChannel(outChannel, CONSTANTS.INFO.DEPLOY_DEVICE, true); await updateCurrentFileIfPython(vscode.window.activeTextEditor!.document); @@ -623,44 +619,49 @@ export async function activate(context: vscode.ExtensionContext) { // On Debug Session Start: Init comunication const debugSessionsStarted = vscode.debug.onDidStartDebugSession(() => { - // Reinitialize process - killProcessIfRunning(); - console.log("Debug Started"); - inDebugMode = true; - - try { - debuggerCommunicationHandler = new DebuggerCommunicationServer( - currentPanel, - utils.getServerPortConfig() - ); - openWebview(); - if (currentPanel) { - debuggerCommunicationHandler.setWebview(currentPanel); - currentPanel.webview.postMessage({ command: "activate-play" }); - } - } catch (err) { - if (err.message === SERVER_INFO.ERROR_CODE_INIT_SERVER) { - console.error( - `Error trying to init the server on port ${utils.getServerPortConfig()}` - ); - vscode.window.showErrorMessage( - CONSTANTS.ERROR.DEBUGGER_SERVER_INIT_FAILED( - utils.getServerPortConfig() - ) + if (simulatorDebugConfiguration.pacificaDebug) { + // Reinitialize process + killProcessIfRunning(); + console.log("Debug Started"); + inDebugMode = true; + + try { + debuggerCommunicationHandler = new DebuggerCommunicationServer( + currentPanel, + utils.getServerPortConfig() ); + openWebview(); + if (currentPanel) { + debuggerCommunicationHandler.setWebview(currentPanel); + currentPanel.webview.postMessage({ command: "activate-play" }); + } + } catch (err) { + if (err.message === SERVER_INFO.ERROR_CODE_INIT_SERVER) { + console.error( + `Error trying to init the server on port ${utils.getServerPortConfig()}` + ); + vscode.window.showErrorMessage( + CONSTANTS.ERROR.DEBUGGER_SERVER_INIT_FAILED( + utils.getServerPortConfig() + ) + ); + } } } }); // On Debug Session Stop: Stop communiation const debugSessionStopped = vscode.debug.onDidTerminateDebugSession(() => { - console.log("Debug Stopped"); - inDebugMode = false; - if (debuggerCommunicationHandler) { - debuggerCommunicationHandler.closeConnection(); - } - if (currentPanel) { - currentPanel.webview.postMessage({ command: "reset-state" }); + if (simulatorDebugConfiguration.pacificaDebug) { + console.log("Debug Stopped"); + inDebugMode = false; + simulatorDebugConfiguration.pacificaDebug = false; + if (debuggerCommunicationHandler) { + debuggerCommunicationHandler.closeConnection(); + } + if (currentPanel) { + currentPanel.webview.postMessage({ command: "reset-state" }); + } } }); @@ -675,7 +676,7 @@ export async function activate(context: vscode.ExtensionContext) { runDevice, selectSerialPort, vscode.debug.registerDebugConfigurationProvider( - "pacifica", + CONSTANTS.DEBUG_CONFIGURATION_TYPE, simulatorDebugConfiguration ), debugSessionsStarted, diff --git a/src/simulatorDebugConfigurationProvider.ts b/src/simulatorDebugConfigurationProvider.ts index 475893311..8e167539a 100644 --- a/src/simulatorDebugConfigurationProvider.ts +++ b/src/simulatorDebugConfigurationProvider.ts @@ -12,7 +12,11 @@ let shouldShowInvalidFileNamePopup: boolean = true; export class SimulatorDebugConfigurationProvider implements vscode.DebugConfigurationProvider { - constructor(private pathToScript: string) {} + public pacificaDebug: boolean; + + constructor(private pathToScript: string) { + this.pacificaDebug = false; + } /** * Modify the debug configuration just before a debug session is being launched. @@ -22,9 +26,23 @@ export class SimulatorDebugConfigurationProvider config: vscode.DebugConfiguration, token?: vscode.CancellationToken ): vscode.ProviderResult { + const activeTextEditor = vscode.window.activeTextEditor; + + // Create a configuration if no launch.json exists or if it's empty + if (!config.type && !config.request && !config.name) { + if ( + activeTextEditor && + activeTextEditor.document.languageId === "python" + ) { + config.type = "pacifica"; + config.request = "launch"; + config.name = "Pacifica Simulator Debugger"; + config.console = "integratedTerminal"; + } + } // Check config type if (config.type === CONSTANTS.DEBUG_CONFIGURATION_TYPE) { - const activeTextEditor = vscode.window.activeTextEditor; + this.pacificaDebug = true; if (activeTextEditor) { const currentFilePath = activeTextEditor.document.fileName; @@ -70,7 +88,7 @@ export class SimulatorDebugConfigurationProvider // Abort / show error message if can't find process_user_code.py if (!config.program) { return vscode.window - .showInformationMessage(CONSTANTS.ERROR.NO_PROGRAM_FOUND_DEBUG) + .showErrorMessage(CONSTANTS.ERROR.NO_PROGRAM_FOUND_DEBUG) .then(() => { return undefined; // Abort launch }); From d4b502377e632bb49548b5a4c1fbb9b4c0cd2314 Mon Sep 17 00:00:00 2001 From: Christella Cidolit Date: Tue, 20 Aug 2019 11:14:35 -0700 Subject: [PATCH 3/3] Fixing the restart debugging bug --- src/debuggerCommunicationServer.ts | 3 ++- src/extension.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/debuggerCommunicationServer.ts b/src/debuggerCommunicationServer.ts index 7cd2d45bc..23d429475 100644 --- a/src/debuggerCommunicationServer.ts +++ b/src/debuggerCommunicationServer.ts @@ -27,8 +27,9 @@ export class DebuggerCommunicationServer { } public closeConnection(): void { - this.serverHttp.close(); this.serverIo.close(); + this.serverHttp.close(); + console.info("Closing the server"); } public setWebview(webviewPanel: WebviewPanel | undefined) { diff --git a/src/extension.ts b/src/extension.ts index a9a7fa43f..221874268 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -626,6 +626,12 @@ export async function activate(context: vscode.ExtensionContext) { inDebugMode = true; try { + // Shut down existing server on debug restart + if (debuggerCommunicationHandler) { + debuggerCommunicationHandler.closeConnection(); + debuggerCommunicationHandler = undefined; + } + debuggerCommunicationHandler = new DebuggerCommunicationServer( currentPanel, utils.getServerPortConfig() @@ -658,6 +664,7 @@ export async function activate(context: vscode.ExtensionContext) { simulatorDebugConfiguration.pacificaDebug = false; if (debuggerCommunicationHandler) { debuggerCommunicationHandler.closeConnection(); + debuggerCommunicationHandler = undefined; } if (currentPanel) { currentPanel.webview.postMessage({ command: "reset-state" });