From e72271966306bf461223b82bb08d1e5dee850016 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 21 Nov 2023 16:59:40 -0500 Subject: [PATCH 1/4] Add debug python file for python debugger --- package.json | 28 +++++++++++++++++++++++++++- package.nls.json | 3 ++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 776be890..9977bef7 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,12 @@ "icon": "$(debug-alt)", "title": "%debugpy.command.debugInTerminal.title%" }, + { + "category": "Python Debugger", + "command": "debugpy.debugUsingLaunchConfig", + "icon": "$(debug-alt)", + "title": "%debugpy.command.debugUsingLaunchConfig.title%" + }, { "category": "Python Debugger", "command": "debugpy.clearCacheAndReload", @@ -70,13 +76,33 @@ "category": "Python Debugger", "command": "debugpy.debugInTerminal", "icon": "$(debug-alt)", - "title": "%debugpy.command.debugInTerminal.title%" + "title": "%debugpy.command.debugInTerminal.title%", + "when": "!virtualWorkspace && shellExecutionSupported && editorLangId == python" + }, + { + "category": "Python Debugger", + "command": "debugpy.debugUsingLaunchConfig", + "icon": "$(debug-alt)", + "title": "%debugpy.command.debugUsingLaunchConfig.title%", + "when": "!virtualWorkspace && shellExecutionSupported && editorLangId == python" }, { "category": "Python Debugger", "command": "debugpy.viewOutput", "title": "%debugpy.command.viewOutput.title%" } + ], + "editor/title/run": [ + { + "command": "debugpy.debugInTerminal", + "title": "%debugpy.command.debugInTerminal.title%", + "when": "resourceLangId == python && !isInDiffEditor && !virtualWorkspace && shellExecutionSupported" + }, + { + "command": "debugpy.debugUsingLaunchConfig", + "title": "%debugpy.command.debugUsingLaunchConfig.title%", + "when": "resourceLangId == python && !isInDiffEditor && !virtualWorkspace && shellExecutionSupported" + } ] }, "configuration": { diff --git a/package.nls.json b/package.nls.json index 0e861715..bb0904d6 100644 --- a/package.nls.json +++ b/package.nls.json @@ -1,5 +1,6 @@ { - "debugpy.command.debugInTerminal.title": "Debug Python File", + "debugpy.command.debugInTerminal.title": "Python Debugger: Debug Python File", + "debugpy.command.debugUsingLaunchConfig.title": "Python Debugger: Debug using launch.json", "debugpy.command.clearCacheAndReload.title": "Clear Cache and Reload Window", "debugpy.command.viewOutput.title": "Show Output", "debugpy.debugJustMyCode": "When debugging only step through user-written code. Disable this to allow stepping into library code." From f68e96fed6f7d5a538bd9c99df2f4f0bfc6d2296 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 21 Nov 2023 17:00:52 -0500 Subject: [PATCH 2/4] Add command that run config in launch json --- src/extension/common/constants.ts | 1 + src/extension/extensionInit.ts | 20 ++++++++++++++++++++ src/extension/telemetry/constants.ts | 1 + src/extension/telemetry/index.ts | 7 +++++++ src/test/unittest/extensionInit.unit.test.ts | 1 + 5 files changed, 30 insertions(+) diff --git a/src/extension/common/constants.ts b/src/extension/common/constants.ts index d5d621a4..dd6c219e 100644 --- a/src/extension/common/constants.ts +++ b/src/extension/common/constants.ts @@ -30,6 +30,7 @@ export function isUnitTestExecution(): boolean { export namespace Commands { export const Debug_In_Terminal = 'debugpy.debugInTerminal'; + export const Debug_Using_Launch_Config = 'debugpy.debugUsingLaunchConfig'; export const TriggerEnvironmentSelection = 'debugpy.triggerEnvSelection'; export const PickLocalProcess = 'debugpy.pickLocalProcess'; export const PickArguments = 'debugpy.pickArgs'; diff --git a/src/extension/extensionInit.ts b/src/extension/extensionInit.ts index 35dd76b0..477e7f1d 100644 --- a/src/extension/extensionInit.ts +++ b/src/extension/extensionInit.ts @@ -32,6 +32,7 @@ import { LaunchJsonUpdaterServiceHelper } from './debugger/configuration/launch. import { ignoreErrors } from './common/promiseUtils'; import { pickArgsInput } from './common/utils/localize'; import { DebugPortAttributesProvider } from './debugger/debugPort/portAttributesProvider'; +import { getConfigurationsByUri } from './debugger/configuration/launch.json/launchJsonReader'; export async function registerDebugger(context: IExtensionContext): Promise { const childProcessAttachService = new ChildProcessAttachService(); @@ -74,6 +75,25 @@ export async function registerDebugger(context: IExtensionContext): Promise { + sendTelemetryEvent(EventName.DEBUG_USING_LAUNCH_CONFIG_BUTTON); + const interpreter = await getInterpreterDetails(file); + + if (!interpreter.path) { + runPythonExtensionCommand(Commands.TriggerEnvironmentSelection, file).then(noop, noop); + return; + } + const configs = await getConfigurationsByUri(file); + if (configs.length > 0) { + executeCommand('workbench.action.debug.selectandstart'); + } else { + await executeCommand('debug.addConfiguration'); + executeCommand('workbench.action.debug.start'); + } + }), + ); + //PersistentStateFactory const persistantState = new PersistentStateFactory(context.globalState, context.workspaceState); persistantState.activate(); diff --git a/src/extension/telemetry/constants.ts b/src/extension/telemetry/constants.ts index 31f144d4..9f08a331 100644 --- a/src/extension/telemetry/constants.ts +++ b/src/extension/telemetry/constants.ts @@ -7,6 +7,7 @@ export enum EventName { DEBUG_SUCCESS_ACTIVATION = 'DEBUG.SUCCESS_ACTIVATION', DEBUG_IN_TERMINAL_BUTTON = 'DEBUG.IN_TERMINAL', + DEBUG_USING_LAUNCH_CONFIG_BUTTON = 'DEBUG.USING_LAUNCH_CONFIG', DEBUG_ADAPTER_USING_WHEELS_PATH = 'DEBUG_ADAPTER.USING_WHEELS_PATH', DEBUG_SESSION_ERROR = 'DEBUG_SESSION.ERROR', DEBUG_SESSION_START = 'DEBUG_SESSION.START', diff --git a/src/extension/telemetry/index.ts b/src/extension/telemetry/index.ts index f289b8d5..14913dd5 100644 --- a/src/extension/telemetry/index.ts +++ b/src/extension/telemetry/index.ts @@ -276,6 +276,13 @@ export interface IEventNamePropertyMapping { "debug_in_terminal_button" : { "owner": "paulacamargo25" } */ [EventName.DEBUG_IN_TERMINAL_BUTTON]: never | undefined; + /** + * Telemetry event sent when debug using launch.json button was used to debug. + */ + /* __GDPR__ + "debug_using_launch_config_button" : { "owner": "paulacamargo25" } + */ + [EventName.DEBUG_USING_LAUNCH_CONFIG_BUTTON]: never | undefined; /** * Telemetry event captured when debug adapter executable is created */ diff --git a/src/test/unittest/extensionInit.unit.test.ts b/src/test/unittest/extensionInit.unit.test.ts index e1b38388..f56d64d7 100644 --- a/src/test/unittest/extensionInit.unit.test.ts +++ b/src/test/unittest/extensionInit.unit.test.ts @@ -61,6 +61,7 @@ suite('Debugging - register Debugging', () => { registerDebugger(context.object); sinon.assert.calledWithExactly(registerCommandStub, Commands.Debug_In_Terminal, sinon.match.any); + sinon.assert.calledWithExactly(registerCommandStub, Commands.Debug_Using_Launch_Config, sinon.match.any); sinon.assert.calledWithExactly(registerCommandStub, Commands.PickLocalProcess, sinon.match.any); sinon.assert.calledWithExactly(registerCommandStub, Commands.PickArguments, sinon.match.any); sinon.assert.calledWithExactly( From a1ec36a031da8b30a301efdfccc4f37621664e9e Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 21 Nov 2023 17:01:20 -0500 Subject: [PATCH 3/4] Update function to get config from workspace too --- .../configuration/launch.json/launchJsonReader.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/extension/debugger/configuration/launch.json/launchJsonReader.ts b/src/extension/debugger/configuration/launch.json/launchJsonReader.ts index 8d61b504..386cbc7a 100644 --- a/src/extension/debugger/configuration/launch.json/launchJsonReader.ts +++ b/src/extension/debugger/configuration/launch.json/launchJsonReader.ts @@ -5,13 +5,17 @@ import * as path from 'path'; import * as fs from 'fs-extra'; import { parse } from 'jsonc-parser'; import { DebugConfiguration, Uri, WorkspaceFolder } from 'vscode'; -import { getWorkspaceFolder } from '../../../common/vscodeapi'; +import { getConfiguration, getWorkspaceFolder } from '../../../common/vscodeapi'; export async function getConfigurationsForWorkspace(workspace: WorkspaceFolder): Promise { const filename = path.join(workspace.uri.fsPath, '.vscode', 'launch.json'); - if (!(await fs.pathExists(filename))) { - return []; + // Check launch config in the workspace file + const codeWorkspaceConfig = getConfiguration('launch'); + if (!codeWorkspaceConfig.configurations || !Array.isArray(codeWorkspaceConfig.configurations)) { + return []; + } + return codeWorkspaceConfig.configurations; } const text = await fs.readFile(filename, 'utf-8'); From f4948e5ae1af82dda00a887065d675b19cf03008 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 21 Nov 2023 17:18:40 -0500 Subject: [PATCH 4/4] fix tests --- src/test/unittest/extensionInit.unit.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/unittest/extensionInit.unit.test.ts b/src/test/unittest/extensionInit.unit.test.ts index f56d64d7..25487683 100644 --- a/src/test/unittest/extensionInit.unit.test.ts +++ b/src/test/unittest/extensionInit.unit.test.ts @@ -71,7 +71,7 @@ suite('Debugging - register Debugging', () => { sinon.match.any, ); sinon.assert.calledWithExactly(registerCommandStub, Commands.ClearStorage, sinon.match.any); - expect(registerCommandStub.callCount).to.be.equal(5); + expect(registerCommandStub.callCount).to.be.equal(6); }); test('Activation will register the Debug adapter factories', async () => {