Skip to content
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
1 change: 1 addition & 0 deletions news/1 Enhancements/1189.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Django Template debugging in experimental debugger.
1 change: 1 addition & 0 deletions news/1 Enhancements/1190.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Flask Template debugging in experimental debugger.
1 change: 1 addition & 0 deletions news/3 Code Health/1198.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change `DjangoDebugging` to `Django` in `debugOptions` of launch.json.
58 changes: 53 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
],
"debugOptions": [
"RedirectOutput",
"DjangoDebugging"
"Django"
]
}
},
Expand Down Expand Up @@ -515,7 +515,7 @@
"RedirectOutput",
"DebugStdLib",
"BreakOnSystemExitZero",
"DjangoDebugging",
"Django",
"Sudo",
"IgnoreDjangoTemplateWarnings",
"Pyramid"
Expand Down Expand Up @@ -663,7 +663,7 @@
],
"debugOptions": [
"RedirectOutput",
"DjangoDebugging"
"Django"
]
},
{
Expand Down Expand Up @@ -781,6 +781,32 @@
"runserver",
"--noreload",
"--nothreading"
],
"debugOptions": [
"RedirectOutput",
"Django"
]
}
},
{
"label": "Python Experimental: Flask",
"description": "%python.snippet.launch.flask.description%",
"body": {
"name": "Flask",
"type": "pythonExperimental",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "^\"\\${workspaceFolder}/app.py\""
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"debugOptions": [
"RedirectOutput",
"Flask"
]
}
},
Expand Down Expand Up @@ -903,8 +929,8 @@
"enum": [
"RedirectOutput",
"DebugStdLib",
"DjangoDebugging",
"FlaskDebugging",
"Django",
"Flask",
"Sudo",
"Pyramid"
]
Expand Down Expand Up @@ -957,6 +983,28 @@
"runserver",
"--noreload",
"--nothreading"
],
"debugOptions": [
"RedirectOutput",
"Django"
]
},
{
"label": "Python Experimental: Flask",
"type": "pythonExperimental",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "${workspaceFolder}/app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"debugOptions": [
"RedirectOutput",
"Flask"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/client/debugger/Common/Contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export enum DebugOptions {
WaitOnAbnormalExit = 'WaitOnAbnormalExit',
WaitOnNormalExit = 'WaitOnNormalExit',
RedirectOutput = 'RedirectOutput',
DjangoDebugging = 'DjangoDebugging',
FlaskDebugging = 'FlaskDebugging',
Django = 'Django',
Flask = 'Flask',
DebugStdLib = 'DebugStdLib',
BreakOnSystemExitZero = 'BreakOnSystemExitZero',
Sudo = 'Sudo',
Expand Down
11 changes: 8 additions & 3 deletions src/client/debugger/DebugClients/LocalDebugClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const VALID_DEBUG_OPTIONS = [
'RedirectOutput',
'DebugStdLib',
'BreakOnSystemExitZero',
'DjangoDebugging'];
'DjangoDebugging',
'Django'];

enum DebugServerStatus {
Unknown = 1,
Expand Down Expand Up @@ -163,12 +164,16 @@ export class LocalDebugClient extends DebugClient<LaunchRequestArguments> {
}
// tslint:disable-next-line:member-ordering
protected buildLauncherArguments(): string[] {
const vsDebugOptions = [DebugOptions.RedirectOutput];
const vsDebugOptions: string[] = [DebugOptions.RedirectOutput];
if (Array.isArray(this.args.debugOptions)) {
this.args.debugOptions.filter(opt => VALID_DEBUG_OPTIONS.indexOf(opt) >= 0)
.forEach(item => vsDebugOptions.push(item));
}

const djangoIndex = vsDebugOptions.indexOf(DebugOptions.Django);
// PTVSD expects the string `DjangoDebugging`
if (djangoIndex >= 0) {
vsDebugOptions[djangoIndex] = 'DjangoDebugging';
}
const programArgs = Array.isArray(this.args.args) && this.args.args.length > 0 ? this.args.args : [];
if (typeof this.args.module === 'string' && this.args.module.length > 0) {
return [vsDebugOptions.join(','), '-m', this.args.module].concat(programArgs);
Expand Down
2 changes: 1 addition & 1 deletion src/client/debugger/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class PythonDebugger extends LoggingDebugSession {
let isDjangoFile = false;
if (this.launchArgs &&
Array.isArray(this.launchArgs.debugOptions) &&
this.launchArgs.debugOptions.indexOf(DebugOptions.DjangoDebugging) >= 0) {
this.launchArgs.debugOptions.indexOf(DebugOptions.Django) >= 0) {
isDjangoFile = filePath.toUpperCase().endsWith(".HTML");
}

Expand Down
6 changes: 5 additions & 1 deletion src/client/debugger/configProviders/pythonV2Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvide
super.provideDefaults(workspaceFolder, debugConfiguration);

debugConfiguration.stopOnEntry = false;
debugConfiguration.debugOptions = Array.isArray(debugConfiguration.debugOptions) ? debugConfiguration.debugOptions : [];

// Add PTVSD specific flags.
if (this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows) {
debugConfiguration.debugOptions = Array.isArray(debugConfiguration.debugOptions) ? debugConfiguration.debugOptions : [];
debugConfiguration.debugOptions.push(DebugOptions.FixFilePathCase);
}
if (debugConfiguration.module && debugConfiguration.module.toUpperCase() === 'FLASK'
&& debugConfiguration.debugOptions.indexOf(DebugOptions.Flask) === -1) {
debugConfiguration.debugOptions.push(DebugOptions.Flask);
}
}
}
16 changes: 16 additions & 0 deletions src/test/debugger/configProvider/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,21 @@ import { IServiceContainer } from '../../../client/ioc/types';
test('Program is set to executable name for Pyramid when python exec does not exist (Mac)', async () => {
await testPyramidConfiguration(false, false, true, true, false, true);
});
test('Auto detect flask debugging', async () => {
if (provider.debugType === 'python') {
return;
}
const pythonPath = `PythonPath_${new Date().toString()}`;
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PythonLanguage.language);

const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { module: 'flask' } as any as DebugConfiguration);

expect(debugConfig).to.have.property('debugOptions');
expect((debugConfig as any).debugOptions).contains(DebugOptions.RedirectOutput);
expect((debugConfig as any).debugOptions).contains(DebugOptions.Flask);
});
});
});