diff --git a/news/1 Enhancements/1189.md b/news/1 Enhancements/1189.md new file mode 100644 index 000000000000..6d306e55189c --- /dev/null +++ b/news/1 Enhancements/1189.md @@ -0,0 +1 @@ +Add support for Django Template debugging in experimental debugger. diff --git a/news/1 Enhancements/1190.md b/news/1 Enhancements/1190.md new file mode 100644 index 000000000000..a1b144662fa5 --- /dev/null +++ b/news/1 Enhancements/1190.md @@ -0,0 +1 @@ +Add support for Flask Template debugging in experimental debugger. diff --git a/news/3 Code Health/1198.md b/news/3 Code Health/1198.md new file mode 100644 index 000000000000..b14083165f25 --- /dev/null +++ b/news/3 Code Health/1198.md @@ -0,0 +1 @@ +Change `DjangoDebugging` to `Django` in `debugOptions` of launch.json. diff --git a/package.json b/package.json index 62ca582bcf96..c59ad5dfcea9 100644 --- a/package.json +++ b/package.json @@ -363,7 +363,7 @@ ], "debugOptions": [ "RedirectOutput", - "DjangoDebugging" + "Django" ] } }, @@ -515,7 +515,7 @@ "RedirectOutput", "DebugStdLib", "BreakOnSystemExitZero", - "DjangoDebugging", + "Django", "Sudo", "IgnoreDjangoTemplateWarnings", "Pyramid" @@ -663,7 +663,7 @@ ], "debugOptions": [ "RedirectOutput", - "DjangoDebugging" + "Django" ] }, { @@ -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" ] } }, @@ -903,8 +929,8 @@ "enum": [ "RedirectOutput", "DebugStdLib", - "DjangoDebugging", - "FlaskDebugging", + "Django", + "Flask", "Sudo", "Pyramid" ] @@ -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" ] }, { diff --git a/src/client/debugger/Common/Contracts.ts b/src/client/debugger/Common/Contracts.ts index 0d82722dc6ca..4aa5540c9784 100644 --- a/src/client/debugger/Common/Contracts.ts +++ b/src/client/debugger/Common/Contracts.ts @@ -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', diff --git a/src/client/debugger/DebugClients/LocalDebugClient.ts b/src/client/debugger/DebugClients/LocalDebugClient.ts index fd366af2412f..5697c3978a59 100644 --- a/src/client/debugger/DebugClients/LocalDebugClient.ts +++ b/src/client/debugger/DebugClients/LocalDebugClient.ts @@ -21,7 +21,8 @@ const VALID_DEBUG_OPTIONS = [ 'RedirectOutput', 'DebugStdLib', 'BreakOnSystemExitZero', - 'DjangoDebugging']; + 'DjangoDebugging', + 'Django']; enum DebugServerStatus { Unknown = 1, @@ -163,12 +164,16 @@ export class LocalDebugClient extends DebugClient { } // 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); diff --git a/src/client/debugger/Main.ts b/src/client/debugger/Main.ts index 69f46e3f0326..190330501a52 100644 --- a/src/client/debugger/Main.ts +++ b/src/client/debugger/Main.ts @@ -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"); } diff --git a/src/client/debugger/configProviders/pythonV2Provider.ts b/src/client/debugger/configProviders/pythonV2Provider.ts index f9d124d95e0e..36d91ba73a01 100644 --- a/src/client/debugger/configProviders/pythonV2Provider.ts +++ b/src/client/debugger/configProviders/pythonV2Provider.ts @@ -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).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); + } } } diff --git a/src/test/debugger/configProvider/provider.test.ts b/src/test/debugger/configProvider/provider.test.ts index ebe4a0ffbdfe..628eba9676da 100644 --- a/src/test/debugger/configProvider/provider.test.ts +++ b/src/test/debugger/configProvider/provider.test.ts @@ -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); + }); }); });