Skip to content

Update debug python button #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
1 change: 1 addition & 0 deletions src/extension/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DebugConfiguration[]> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you need to look up launch configs for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the proposal, we check if there is any configuration already created. If not, we show the user the prompt to create the launch.json

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');
Expand Down
20 changes: 20 additions & 0 deletions src/extension/extensionInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const childProcessAttachService = new ChildProcessAttachService();
Expand Down Expand Up @@ -74,6 +75,25 @@ export async function registerDebugger(context: IExtensionContext): Promise<void
}),
);

context.subscriptions.push(
registerCommand(Commands.Debug_Using_Launch_Config, async (file?: Uri) => {
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();
Expand Down
1 change: 1 addition & 0 deletions src/extension/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions src/extension/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion src/test/unittest/extensionInit.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -70,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 () => {
Expand Down