From fcfa4423ab31dc40955299646a384067ac6cfc25 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 02:01:43 -0700 Subject: [PATCH 1/8] Add ne config type --- package.json | 21 ++++++++++--- src/extension/common/utils/localize.ts | 14 +++++++++ .../debugConfigurationService.ts | 7 +++++ .../providers/fileLaunchWithArgs.ts | 31 +++++++++++++++++++ src/extension/debugger/types.ts | 1 + src/extension/types.ts | 2 +- 6 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/extension/debugger/configuration/providers/fileLaunchWithArgs.ts diff --git a/package.json b/package.json index 6f925d68..a439e0df 100644 --- a/package.json +++ b/package.json @@ -210,9 +210,21 @@ "items": { "type": "string" }, - "type": [ - "array", - "string" + "anyOf": [ + { + "default": "${command:pickArgs}", + "description": "Command line arguments passed to the program.", + "enum": [ + "${command:pickArgs}" + ] + }, + { + "description": "Command line arguments passed to the program.", + "type": [ + "array", + "string" + ] + } ] }, "autoReload": { @@ -415,7 +427,8 @@ ], "type": "debugpy", "variables": { - "pickProcess": "debugpy.pickLocalProcess" + "pickProcess": "debugpy.pickLocalProcess", + "pickArgs": "debugpy.pickArgs" }, "when": "!virtualWorkspace && shellExecutionSupported" } diff --git a/src/extension/common/utils/localize.ts b/src/extension/common/utils/localize.ts index 0a686823..2059f8dd 100644 --- a/src/extension/common/utils/localize.ts +++ b/src/extension/common/utils/localize.ts @@ -30,6 +30,15 @@ export namespace DebugConfigStrings { description: l10n.t('Debug the currently active Python file'), }; } + export namespace fileWithArgs { + export const snippet = { + name: l10n.t('Debugpy: Current File With Arguments'), + }; + export const selectConfiguration = { + label: l10n.t('Python File With Args'), + description: l10n.t('Debug the currently active Python file with a prompt for add arguments commands'), + }; + } export namespace module { export const snippet = { name: l10n.t('Debugpy: Module'), @@ -193,3 +202,8 @@ export namespace OutdatedDebugger { export namespace Logging { export const currentWorkingDirectory = l10n.t('cwd:'); } + +export namespace pickArgsInput { + export const title = l10n.t('Program Arguments'); + export const prompt = l10n.t('Enter the commands line arguments you want to pass to the program'); +} diff --git a/src/extension/debugger/configuration/debugConfigurationService.ts b/src/extension/debugger/configuration/debugConfigurationService.ts index 2c11a63b..4c069887 100644 --- a/src/extension/debugger/configuration/debugConfigurationService.ts +++ b/src/extension/debugger/configuration/debugConfigurationService.ts @@ -19,6 +19,7 @@ import { buildPidAttachConfiguration } from './providers/pidAttach'; import { buildPyramidLaunchConfiguration } from './providers/pyramidLaunch'; import { buildRemoteAttachConfiguration } from './providers/remoteAttach'; import { IDebugConfigurationResolver } from './types'; +import { buildFileLaunchWithArgsDebugConfiguration } from './providers/fileLaunchWithArgs'; @injectable() export class PythonDebugConfigurationService implements IDebugConfigurationService { @@ -116,6 +117,11 @@ export class PythonDebugConfigurationService implements IDebugConfigurationServi type: DebugConfigurationType.launchFile, description: DebugConfigStrings.file.selectConfiguration.description, }, + { + label: DebugConfigStrings.fileWithArgs.selectConfiguration.label, + type: DebugConfigurationType.launchFileWithArgs, + description: DebugConfigStrings.fileWithArgs.selectConfiguration.description, + }, { label: DebugConfigStrings.module.selectConfiguration.label, type: DebugConfigurationType.launchModule, @@ -162,6 +168,7 @@ export class PythonDebugConfigurationService implements IDebugConfigurationServi debugConfigurations.set(DebugConfigurationType.launchDjango, buildDjangoLaunchDebugConfiguration); debugConfigurations.set(DebugConfigurationType.launchFastAPI, buildFastAPILaunchDebugConfiguration); debugConfigurations.set(DebugConfigurationType.launchFile, buildFileLaunchDebugConfiguration); + debugConfigurations.set(DebugConfigurationType.launchFileWithArgs, buildFileLaunchWithArgsDebugConfiguration); debugConfigurations.set(DebugConfigurationType.launchFlask, buildFlaskLaunchDebugConfiguration); debugConfigurations.set(DebugConfigurationType.launchModule, buildModuleLaunchConfiguration); debugConfigurations.set(DebugConfigurationType.pidAttach, buildPidAttachConfiguration); diff --git a/src/extension/debugger/configuration/providers/fileLaunchWithArgs.ts b/src/extension/debugger/configuration/providers/fileLaunchWithArgs.ts new file mode 100644 index 00000000..2dfcfced --- /dev/null +++ b/src/extension/debugger/configuration/providers/fileLaunchWithArgs.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +import { DebugConfigStrings } from '../../../common/utils/localize'; +import { MultiStepInput } from '../../../common/multiStepInput'; +import { sendTelemetryEvent } from '../../../telemetry'; +import { EventName } from '../../../telemetry/constants'; +import { DebuggerTypeName } from '../../../constants'; +import { LaunchRequestArguments } from '../../../types'; +import { DebugConfigurationState, DebugConfigurationType } from '../../types'; + +export async function buildFileLaunchWithArgsDebugConfiguration( + _input: MultiStepInput, + state: DebugConfigurationState, +): Promise { + const config: Partial = { + name: DebugConfigStrings.fileWithArgs.snippet.name, + type: DebuggerTypeName, + request: 'launch', + program: '${file}', + console: 'integratedTerminal', + args: '${command:pickArgs}', + justMyCode: true, + }; + sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { + configurationType: DebugConfigurationType.launchFileWithArgs, + }); + Object.assign(state.config, config); +} diff --git a/src/extension/debugger/types.ts b/src/extension/debugger/types.ts index ecc381de..d342f758 100644 --- a/src/extension/debugger/types.ts +++ b/src/extension/debugger/types.ts @@ -30,6 +30,7 @@ export type DebugConfigurationState = { export enum DebugConfigurationType { launchFile = 'launchFile', + launchFileWithArgs = 'launchFileWithArgs', remoteAttach = 'remoteAttach', launchDjango = 'launchDjango', launchFastAPI = 'launchFastAPI', diff --git a/src/extension/types.ts b/src/extension/types.ts index a5aeef3f..0646e5ff 100644 --- a/src/extension/types.ts +++ b/src/extension/types.ts @@ -97,7 +97,7 @@ interface IKnownLaunchRequestArguments extends ICommonDebugArguments { python?: string; // Automatically stop target after launch. If not specified, target does not stop. stopOnEntry?: boolean; - args?: string[]; + args?: string[] | String; cwd?: string; debugOptions?: DebugOptions[]; env?: Record; From 39b7236fc84b8f1af60a8747262f0a489503ed78 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 02:02:14 -0700 Subject: [PATCH 2/8] Add command to show input --- src/extension/common/constants.ts | 1 + src/extension/extensionInit.ts | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/extension/common/constants.ts b/src/extension/common/constants.ts index be470b9b..977a80e0 100644 --- a/src/extension/common/constants.ts +++ b/src/extension/common/constants.ts @@ -32,6 +32,7 @@ export namespace Commands { export const Debug_In_Terminal = 'debugpy.debugInTerminal'; export const TriggerEnvironmentSelection = 'debugpy.triggerEnvSelection'; export const PickLocalProcess = 'debugpy.pickLocalProcess'; + export const PickArguments = 'debugpy.pickArgs'; export const ViewOutput = 'debugpy.viewOutput'; export const ClearStorage = 'debugpy.clearCacheAndReload'; export const Enable_SourceMap_Support = 'debugpy.enableSourceMapSupport'; diff --git a/src/extension/extensionInit.ts b/src/extension/extensionInit.ts index 93fef7a5..68b7cd4b 100644 --- a/src/extension/extensionInit.ts +++ b/src/extension/extensionInit.ts @@ -3,7 +3,7 @@ 'use strict'; -import { debug, DebugConfigurationProviderTriggerKind, languages, Uri } from 'vscode'; +import { debug, DebugConfigurationProviderTriggerKind, languages, Uri, window } from 'vscode'; import { executeCommand, getConfiguration, registerCommand, startDebugging } from './common/vscodeapi'; import { DebuggerTypeName } from './constants'; import { DynamicPythonDebugConfigurationService } from './debugger/configuration/dynamicdebugConfigurationService'; @@ -31,6 +31,7 @@ import { JsonLanguages, LaunchJsonCompletionProvider } from './debugger/configur import { InterpreterPathCommand } from './debugger/configuration/launch.json/interpreterPathCommand'; import { LaunchJsonUpdaterServiceHelper } from './debugger/configuration/launch.json/updaterServiceHelper'; import { ignoreErrors } from './common/promiseUtils'; +import { pickArgsInput } from './common/utils/localize'; export async function registerDebugger(context: IExtensionContext): Promise { const childProcessAttachService = new ChildProcessAttachService(); @@ -80,6 +81,11 @@ export async function registerDebugger(context: IExtensionContext): Promise attachPicker.showQuickPick())); + context.subscriptions.push( + registerCommand(Commands.PickArguments, () => { + return window.showInputBox({ title: pickArgsInput.title, prompt: pickArgsInput.prompt}); + }), + ); const debugAdapterDescriptorFactory = new DebugAdapterDescriptorFactory(persistantState); const debugSessionLoggingFactory = new DebugSessionLoggingFactory(); @@ -122,9 +128,9 @@ export async function registerDebugger(context: IExtensionContext): Promise - interpreterPathCommand._getSelectedInterpreterPath(args), - ), - ); + // context.subscriptions.push( + // registerCommand(Commands.GetSelectedInterpreterPath, (args) => + // interpreterPathCommand._getSelectedInterpreterPath(args), + // ), + // ); } From 25cf6971ece0be1d0d82f233e16f37ddf9f1c26d Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 02:03:37 -0700 Subject: [PATCH 3/8] Fix code affected by the changes --- src/extension/debugger/attachQuickPick/types.ts | 6 ------ .../debugger/configuration/providers/fastapiLaunch.ts | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/extension/debugger/attachQuickPick/types.ts b/src/extension/debugger/attachQuickPick/types.ts index c8ab8dbc..0e233e51 100644 --- a/src/extension/debugger/attachQuickPick/types.ts +++ b/src/extension/debugger/attachQuickPick/types.ts @@ -17,12 +17,6 @@ export interface IAttachProcessProvider { getAttachItems(): Promise; } -// eslint-disable-next-line @typescript-eslint/naming-convention -// export const IAttachProcessProviderFactory = Symbol('IAttachProcessProviderFactory'); -// export interface IAttachProcessProviderFactory { -// registerCommands(): void; -// } - export interface IAttachPicker { showQuickPick(): Promise; } diff --git a/src/extension/debugger/configuration/providers/fastapiLaunch.ts b/src/extension/debugger/configuration/providers/fastapiLaunch.ts index 69e37a71..d45930c3 100644 --- a/src/extension/debugger/configuration/providers/fastapiLaunch.ts +++ b/src/extension/debugger/configuration/providers/fastapiLaunch.ts @@ -30,7 +30,7 @@ export async function buildFastAPILaunchDebugConfiguration( justMyCode: true, }; - if (!application && config.args) { + if (!application) { const selectedPath = await input.showInputBox({ title: DebugConfigStrings.fastapi.enterAppPathOrNamePath.title, value: 'main.py', @@ -44,7 +44,7 @@ export async function buildFastAPILaunchDebugConfiguration( }); if (selectedPath) { manuallyEnteredAValue = true; - config.args[0] = `${path.basename(selectedPath, '.py').replace('/', '.')}:app`; + config.args = [`${path.basename(selectedPath, '.py').replace('/', '.')}:app`, '--reload']; } } From d2d03e7cc5420978fe9cde56112197d51b4e4278 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 02:05:53 -0700 Subject: [PATCH 4/8] run prettier --- src/extension/extensionInit.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/extension/extensionInit.ts b/src/extension/extensionInit.ts index 68b7cd4b..227a29c6 100644 --- a/src/extension/extensionInit.ts +++ b/src/extension/extensionInit.ts @@ -83,7 +83,7 @@ export async function registerDebugger(context: IExtensionContext): Promise attachPicker.showQuickPick())); context.subscriptions.push( registerCommand(Commands.PickArguments, () => { - return window.showInputBox({ title: pickArgsInput.title, prompt: pickArgsInput.prompt}); + return window.showInputBox({ title: pickArgsInput.title, prompt: pickArgsInput.prompt }); }), ); @@ -128,9 +128,9 @@ export async function registerDebugger(context: IExtensionContext): Promise - // interpreterPathCommand._getSelectedInterpreterPath(args), - // ), - // ); + context.subscriptions.push( + registerCommand(Commands.GetSelectedInterpreterPath, (args) => + interpreterPathCommand._getSelectedInterpreterPath(args), + ), + ); } From 39716a13a7c6c5bf581c1cc352889d6dd2ac726b Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 13:18:33 -0700 Subject: [PATCH 5/8] Add tests --- .../providers/fileLaunchWithArgs.unit.test | 34 +++++++++++++++++++ src/test/unittest/extensionInit.unit.test.ts | 3 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/test/unittest/configuration/providers/fileLaunchWithArgs.unit.test diff --git a/src/test/unittest/configuration/providers/fileLaunchWithArgs.unit.test b/src/test/unittest/configuration/providers/fileLaunchWithArgs.unit.test new file mode 100644 index 00000000..c3e4ad0b --- /dev/null +++ b/src/test/unittest/configuration/providers/fileLaunchWithArgs.unit.test @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +import { expect } from 'chai'; +import * as path from 'path'; +import { Uri } from 'vscode'; +import { MultiStepInput } from '../../../../extension/common/multiStepInput'; +import { DebugConfigStrings } from '../../../../extension/common/utils/localize'; +import { DebuggerTypeName } from '../../../../extension/constants'; +import { buildFileLaunchWithArgsDebugConfiguration } from '../../../../extension/debugger/configuration/providers/fileLaunchWithArgs'; +import { DebugConfigurationState } from '../../../../extension/debugger/types'; + +suite('Debugging - Configuration Provider File with Arguments', () => { + test('Launch JSON with default config', async () => { + const folder = { uri: Uri.parse(path.join('one', 'two')), name: '1', index: 0 }; + const state = { config: {}, folder }; + + await buildFileLaunchWithArgsDebugConfiguration(undefined as unknown as MultiStepInput, state); + + const config = { + name: DebugConfigStrings.fileWithArgs.snippet.name, + type: DebuggerTypeName, + request: 'launch', + program: '${file}', + console: 'integratedTerminal', + args: '${command:pickArgs}', + justMyCode: true, + }; + + expect(state.config).to.be.deep.equal(config); + }); +}); diff --git a/src/test/unittest/extensionInit.unit.test.ts b/src/test/unittest/extensionInit.unit.test.ts index fd647f05..7aa5b4eb 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', () => { sinon.assert.calledWithExactly(registerCommandStub, Commands.Debug_In_Terminal, sinon.match.any); sinon.assert.calledWithExactly(registerCommandStub, Commands.PickLocalProcess, sinon.match.any); + sinon.assert.calledWithExactly(registerCommandStub, Commands.PickArguments, sinon.match.any); sinon.assert.calledWithExactly( registerCommandStub, Commands.SelectDebugConfig, @@ -69,7 +70,7 @@ suite('Debugging - register Debugging', () => { ); sinon.assert.calledWithExactly(registerCommandStub, Commands.GetSelectedInterpreterPath, 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 () => { registerDebugger(context.object); From 250bb7242c144fd3dc1154e9090efe18f6b1b4cc Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 13:19:03 -0700 Subject: [PATCH 6/8] Update text --- src/extension/common/utils/localize.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/extension/common/utils/localize.ts b/src/extension/common/utils/localize.ts index 2059f8dd..96eeed20 100644 --- a/src/extension/common/utils/localize.ts +++ b/src/extension/common/utils/localize.ts @@ -32,11 +32,11 @@ export namespace DebugConfigStrings { } export namespace fileWithArgs { export const snippet = { - name: l10n.t('Debugpy: Current File With Arguments'), + name: l10n.t('Debugpy: Current File with Arguments'), }; export const selectConfiguration = { - label: l10n.t('Python File With Args'), - description: l10n.t('Debug the currently active Python file with a prompt for add arguments commands'), + label: l10n.t('Python File with Arguments'), + description: l10n.t('Debug the currently active Python file with arguments'), }; } export namespace module { @@ -204,6 +204,6 @@ export namespace Logging { } export namespace pickArgsInput { - export const title = l10n.t('Program Arguments'); - export const prompt = l10n.t('Enter the commands line arguments you want to pass to the program'); + export const title = l10n.t('Command Line Arguments'); + export const prompt = l10n.t('Enter the command line arguments you want to pass to the program'); } From 03625bf7c096d0f67727e977bbb2f2779adf737d Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 13:22:39 -0700 Subject: [PATCH 7/8] remove unnecessary description --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index a439e0df..e2354a2e 100644 --- a/package.json +++ b/package.json @@ -213,13 +213,11 @@ "anyOf": [ { "default": "${command:pickArgs}", - "description": "Command line arguments passed to the program.", "enum": [ "${command:pickArgs}" ] }, { - "description": "Command line arguments passed to the program.", "type": [ "array", "string" From e20f446f5010faea17c6238eaa0448117f904307 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 24 Jul 2023 13:27:00 -0700 Subject: [PATCH 8/8] Update name --- .../debugger/configuration/debugConfigurationService.ts | 4 ++-- .../debugger/configuration/providers/fileLaunchWithArgs.ts | 2 +- .../configuration/providers/fileLaunchWithArgs.unit.test | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/extension/debugger/configuration/debugConfigurationService.ts b/src/extension/debugger/configuration/debugConfigurationService.ts index 4c069887..5528d508 100644 --- a/src/extension/debugger/configuration/debugConfigurationService.ts +++ b/src/extension/debugger/configuration/debugConfigurationService.ts @@ -19,7 +19,7 @@ import { buildPidAttachConfiguration } from './providers/pidAttach'; import { buildPyramidLaunchConfiguration } from './providers/pyramidLaunch'; import { buildRemoteAttachConfiguration } from './providers/remoteAttach'; import { IDebugConfigurationResolver } from './types'; -import { buildFileLaunchWithArgsDebugConfiguration } from './providers/fileLaunchWithArgs'; +import { buildFileWithArgsLaunchDebugConfiguration } from './providers/fileLaunchWithArgs'; @injectable() export class PythonDebugConfigurationService implements IDebugConfigurationService { @@ -168,7 +168,7 @@ export class PythonDebugConfigurationService implements IDebugConfigurationServi debugConfigurations.set(DebugConfigurationType.launchDjango, buildDjangoLaunchDebugConfiguration); debugConfigurations.set(DebugConfigurationType.launchFastAPI, buildFastAPILaunchDebugConfiguration); debugConfigurations.set(DebugConfigurationType.launchFile, buildFileLaunchDebugConfiguration); - debugConfigurations.set(DebugConfigurationType.launchFileWithArgs, buildFileLaunchWithArgsDebugConfiguration); + debugConfigurations.set(DebugConfigurationType.launchFileWithArgs, buildFileWithArgsLaunchDebugConfiguration); debugConfigurations.set(DebugConfigurationType.launchFlask, buildFlaskLaunchDebugConfiguration); debugConfigurations.set(DebugConfigurationType.launchModule, buildModuleLaunchConfiguration); debugConfigurations.set(DebugConfigurationType.pidAttach, buildPidAttachConfiguration); diff --git a/src/extension/debugger/configuration/providers/fileLaunchWithArgs.ts b/src/extension/debugger/configuration/providers/fileLaunchWithArgs.ts index 2dfcfced..a09c8e9a 100644 --- a/src/extension/debugger/configuration/providers/fileLaunchWithArgs.ts +++ b/src/extension/debugger/configuration/providers/fileLaunchWithArgs.ts @@ -11,7 +11,7 @@ import { DebuggerTypeName } from '../../../constants'; import { LaunchRequestArguments } from '../../../types'; import { DebugConfigurationState, DebugConfigurationType } from '../../types'; -export async function buildFileLaunchWithArgsDebugConfiguration( +export async function buildFileWithArgsLaunchDebugConfiguration( _input: MultiStepInput, state: DebugConfigurationState, ): Promise { diff --git a/src/test/unittest/configuration/providers/fileLaunchWithArgs.unit.test b/src/test/unittest/configuration/providers/fileLaunchWithArgs.unit.test index c3e4ad0b..ff7ab6f9 100644 --- a/src/test/unittest/configuration/providers/fileLaunchWithArgs.unit.test +++ b/src/test/unittest/configuration/providers/fileLaunchWithArgs.unit.test @@ -9,7 +9,7 @@ import { Uri } from 'vscode'; import { MultiStepInput } from '../../../../extension/common/multiStepInput'; import { DebugConfigStrings } from '../../../../extension/common/utils/localize'; import { DebuggerTypeName } from '../../../../extension/constants'; -import { buildFileLaunchWithArgsDebugConfiguration } from '../../../../extension/debugger/configuration/providers/fileLaunchWithArgs'; +import { buildFileWithArgsLaunchDebugConfiguration } from '../../../../extension/debugger/configuration/providers/fileLaunchWithArgs'; import { DebugConfigurationState } from '../../../../extension/debugger/types'; suite('Debugging - Configuration Provider File with Arguments', () => { @@ -17,7 +17,7 @@ suite('Debugging - Configuration Provider File with Arguments', () => { const folder = { uri: Uri.parse(path.join('one', 'two')), name: '1', index: 0 }; const state = { config: {}, folder }; - await buildFileLaunchWithArgsDebugConfiguration(undefined as unknown as MultiStepInput, state); + await buildFileWithArgsLaunchDebugConfiguration(undefined as unknown as MultiStepInput, state); const config = { name: DebugConfigStrings.fileWithArgs.snippet.name,