Skip to content

Commit 3626de2

Browse files
authored
Changes to how debug options are passed into the experimental version of PTVSD (debugger) (microsoft#1195)
* 🔨 change how debug options are passed to new PTVSD * 📝 news entry * Fixes microsoft#1168
1 parent bbf346e commit 3626de2

11 files changed

Lines changed: 47 additions & 48 deletions

File tree

news/3 Code Health/1168.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changes to how debug options are passed into the experimental version of PTVSD (debugger).

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,10 @@
901901
"items": {
902902
"type": "string",
903903
"enum": [
904+
"RedirectOutput",
905+
"DebugStdLib",
906+
"DjangoDebugging",
907+
"FlaskDebugging",
904908
"Sudo",
905909
"Pyramid"
906910
]

src/client/debugger/Common/Contracts.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ export enum DebugFlags {
2929
IgnoreCommandBursts = 1
3030
}
3131

32-
export class DebugOptions {
33-
public static get WaitOnAbnormalExit(): string { return 'WaitOnAbnormalExit'; }
34-
public static get WaitOnNormalExit(): string { return 'WaitOnNormalExit'; }
35-
public static get RedirectOutput(): string { return 'RedirectOutput'; }
36-
public static get DjangoDebugging(): string { return 'DjangoDebugging'; }
37-
public static get DebugStdLib(): string { return 'DebugStdLib'; }
38-
public static get BreakOnSystemExitZero(): string { return 'BreakOnSystemExitZero'; }
32+
export enum DebugOptions {
33+
WaitOnAbnormalExit = 'WaitOnAbnormalExit',
34+
WaitOnNormalExit = 'WaitOnNormalExit',
35+
RedirectOutput = 'RedirectOutput',
36+
DjangoDebugging = 'DjangoDebugging',
37+
FlaskDebugging = 'FlaskDebugging',
38+
DebugStdLib = 'DebugStdLib',
39+
BreakOnSystemExitZero = 'BreakOnSystemExitZero',
40+
Sudo = 'Sudo',
41+
Pyramid = 'Pyramid',
42+
FixFilePathCase = 'FixFilePathCase'
3943
}
4044

4145
export interface ExceptionHandling {
@@ -57,7 +61,7 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
5761
args: string[];
5862
applicationType?: string;
5963
cwd?: string;
60-
debugOptions?: string[];
64+
debugOptions?: DebugOptions[];
6165
env?: Object;
6266
envFile: string;
6367
exceptionHandling?: ExceptionHandling;

src/client/debugger/DebugClients/LocalDebugClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PathUtils } from '../../common/platform/pathUtils';
88
import { CurrentProcess } from '../../common/process/currentProcess';
99
import { EnvironmentVariablesService } from '../../common/variables/environment';
1010
import { IServiceContainer } from '../../ioc/types';
11-
import { IDebugServer, IPythonProcess, LaunchRequestArguments } from '../Common/Contracts';
11+
import { DebugOptions, IDebugServer, IPythonProcess, LaunchRequestArguments } from '../Common/Contracts';
1212
import { IS_WINDOWS } from '../Common/Utils';
1313
import { BaseDebugServer } from '../DebugServers/BaseDebugServer';
1414
import { LocalDebugServer } from '../DebugServers/LocalDebugServer';
@@ -163,7 +163,7 @@ export class LocalDebugClient extends DebugClient<LaunchRequestArguments> {
163163
}
164164
// tslint:disable-next-line:member-ordering
165165
protected buildLauncherArguments(): string[] {
166-
const vsDebugOptions = ['RedirectOutput'];
166+
const vsDebugOptions = [DebugOptions.RedirectOutput];
167167
if (Array.isArray(this.args.debugOptions)) {
168168
this.args.debugOptions.filter(opt => VALID_DEBUG_OPTIONS.indexOf(opt) >= 0)
169169
.forEach(item => vsDebugOptions.push(item));

src/client/debugger/configProviders/baseProvider.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import { PythonLanguage } from '../../common/constants';
1111
import { IFileSystem, IPlatformService } from '../../common/platform/types';
1212
import { IConfigurationService } from '../../common/types';
1313
import { IServiceContainer } from '../../ioc/types';
14-
import { DebuggerType, LaunchRequestArguments } from '../Common/Contracts';
14+
import { DebuggerType, DebugOptions, LaunchRequestArguments } from '../Common/Contracts';
1515

1616
// tslint:disable:no-invalid-template-strings
1717

1818
export type PythonDebugConfiguration = DebugConfiguration & LaunchRequestArguments;
19-
export type PTVSDDebugConfiguration = PythonDebugConfiguration & { redirectOutput: boolean; fixFilePathCase: boolean };
2019

2120
@injectable()
2221
export abstract class BaseConfigurationProvider implements DebugConfigurationProvider {
@@ -62,10 +61,10 @@ export abstract class BaseConfigurationProvider implements DebugConfigurationPro
6261
debugConfiguration.debugOptions = [];
6362
}
6463
// Always redirect output.
65-
if (debugConfiguration.debugOptions.indexOf('RedirectOutput') === -1) {
66-
debugConfiguration.debugOptions.push('RedirectOutput');
64+
if (debugConfiguration.debugOptions.indexOf(DebugOptions.RedirectOutput) === -1) {
65+
debugConfiguration.debugOptions.push(DebugOptions.RedirectOutput);
6766
}
68-
if (debugConfiguration.debugOptions.indexOf('Pyramid') >= 0) {
67+
if (debugConfiguration.debugOptions.indexOf(DebugOptions.Pyramid) >= 0) {
6968
const platformService = this.serviceContainer.get<IPlatformService>(IPlatformService);
7069
const fs = this.serviceContainer.get<IFileSystem>(IFileSystem);
7170
const pserve = platformService.isWindows ? 'pserve.exe' : 'pserve';

src/client/debugger/configProviders/pythonV2Provider.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { inject, injectable } from 'inversify';
77
import { Uri } from 'vscode';
88
import { IPlatformService } from '../../common/platform/types';
99
import { IServiceContainer } from '../../ioc/types';
10-
import { BaseConfigurationProvider, PTVSDDebugConfiguration, PythonDebugConfiguration } from './baseProvider';
10+
import { DebugOptions } from '../Common/Contracts';
11+
import { BaseConfigurationProvider, PythonDebugConfiguration } from './baseProvider';
1112

1213
@injectable()
1314
export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvider {
@@ -20,8 +21,9 @@ export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvide
2021
debugConfiguration.stopOnEntry = false;
2122

2223
// Add PTVSD specific flags.
23-
const ptvsdDebugConfigurationFlags = debugConfiguration as PTVSDDebugConfiguration;
24-
ptvsdDebugConfigurationFlags.redirectOutput = Array.isArray(debugConfiguration.debugOptions) && debugConfiguration.debugOptions.indexOf('RedirectOutput') >= 0;
25-
ptvsdDebugConfigurationFlags.fixFilePathCase = this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows;
24+
if (this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows) {
25+
debugConfiguration.debugOptions = Array.isArray(debugConfiguration.debugOptions) ? debugConfiguration.debugOptions : [];
26+
debugConfiguration.debugOptions.push(DebugOptions.FixFilePathCase);
27+
}
2628
}
2729
}

src/client/unittests/common/debugLauncher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Uri } from 'vscode';
44
import { IDebugService, IWorkspaceService } from '../../common/application/types';
55
import { EXTENSION_ROOT_DIR } from '../../common/constants';
66
import { IConfigurationService } from '../../common/types';
7+
import { DebugOptions } from '../../debugger/Common/Contracts';
78
import { IServiceContainer } from '../../ioc/types';
89
import { ITestDebugLauncher, LaunchOptions, TestProvider } from './types';
910

@@ -40,7 +41,7 @@ export class DebugLauncher implements ITestDebugLauncher {
4041
cwd,
4142
args: debugArgs,
4243
console: 'none',
43-
debugOptions: ['RedirectOutput']
44+
debugOptions: [DebugOptions.RedirectOutput]
4445
}).then(() => void (0));
4546
}
4647
private fixArgs(args: string[], testProvider: TestProvider, useExperimentalDebugger: boolean): string[] {

src/test/debugger/configProvider/provider.test.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { PythonLanguage } from '../../../client/common/constants';
1414
import { IFileSystem, IPlatformService } from '../../../client/common/platform/types';
1515
import { IConfigurationService, IPythonSettings } from '../../../client/common/types';
1616
import { PythonDebugConfigurationProvider, PythonV2DebugConfigurationProvider } from '../../../client/debugger';
17+
import { DebugOptions } from '../../../client/debugger/Common/Contracts';
1718
import { IServiceContainer } from '../../../client/ioc/types';
1819

1920
[
@@ -260,24 +261,8 @@ import { IServiceContainer } from '../../../client/ioc/types';
260261

261262
expect(debugConfig).to.have.property('stopOnEntry', false);
262263
expect(debugConfig).to.have.property('debugOptions');
263-
expect((debugConfig as any).debugOptions).to.be.deep.equal(['RedirectOutput']);
264-
});
265-
test('Test redirection of output', async () => {
266-
if (provider.debugType === 'python') {
267-
return;
268-
}
269-
const pythonPath = `PythonPath_${new Date().toString()}`;
270-
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
271-
const pythonFile = 'xyz.py';
272-
setupIoc(pythonPath);
273-
setupActiveEditor(pythonFile, PythonLanguage.language);
274-
275-
const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { debugOptions: ['RedirectOutput'] } as any);
276-
277-
expect(debugConfig).to.have.property('redirectOutput');
278-
expect((debugConfig as any).redirectOutput).to.be.equal(true, 'invalid value');
264+
expect((debugConfig as any).debugOptions).to.be.deep.equal([DebugOptions.RedirectOutput]);
279265
});
280-
281266
async function testFixFilePathCase(isWindows: boolean, isMac: boolean, isLinux: boolean) {
282267
const pythonPath = `PythonPath_${new Date().toString()}`;
283268
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
@@ -286,9 +271,11 @@ import { IServiceContainer } from '../../../client/ioc/types';
286271
setupActiveEditor(pythonFile, PythonLanguage.language);
287272

288273
const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, {} as DebugConfiguration);
289-
290-
expect(debugConfig).to.have.property('fixFilePathCase');
291-
expect((debugConfig as any).fixFilePathCase).to.be.equal(isWindows, 'invalid value (true only for windows)');
274+
if (isWindows) {
275+
expect(debugConfig).to.have.property('debugOptions').contains(DebugOptions.FixFilePathCase);
276+
} else {
277+
expect(debugConfig).to.have.property('debugOptions').not.contains(DebugOptions.FixFilePathCase);
278+
}
292279
}
293280
test('Test fixFilePathCase for Windows', async () => {
294281
if (provider.debugType === 'python') {
@@ -318,7 +305,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
318305
setupIoc(pythonPath, isWindows, isMac, isLinux);
319306
setupActiveEditor(pythonFile, PythonLanguage.language);
320307

321-
const options = addPyramidDebugOption ? { debugOptions: ['Pyramid'] } : {};
308+
const options = addPyramidDebugOption ? { debugOptions: [DebugOptions.Pyramid] } : {};
322309
fileSystem.setup(fs => fs.fileExistsSync(TypeMoq.It.isValue(pythonPath))).returns(() => pythonPathExists);
323310

324311
const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, options as any as DebugConfiguration);

src/test/debugger/misc.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { noop } from '../../client/common/core.utils';
1414
import { IS_WINDOWS } from '../../client/common/platform/constants';
1515
import { FileSystem } from '../../client/common/platform/fileSystem';
1616
import { PlatformService } from '../../client/common/platform/platformService';
17-
import { LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
17+
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
1818
import { sleep } from '../common';
1919
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
2020
import { DEBUGGER_TIMEOUT } from './common/constants';
@@ -78,7 +78,7 @@ let testCounter = 0;
7878
program: path.join(debugFilesPath, pythonFile),
7979
cwd: debugFilesPath,
8080
stopOnEntry,
81-
debugOptions: ['RedirectOutput'],
81+
debugOptions: [DebugOptions.RedirectOutput],
8282
pythonPath: 'python',
8383
args: [],
8484
env,

src/test/debugger/portAndHost.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as net from 'net';
88
import * as path from 'path';
99
import { DebugClient } from 'vscode-debugadapter-testsupport';
1010
import { noop } from '../../client/common/core.utils';
11-
import { LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
11+
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
1212
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
1313
import { DEBUGGER_TIMEOUT } from './common/constants';
1414

@@ -49,7 +49,7 @@ const EXPERIMENTAL_DEBUG_ADAPTER = path.join(__dirname, '..', '..', 'client', 'd
4949
program: path.join(debugFilesPath, pythonFile),
5050
cwd: debugFilesPath,
5151
stopOnEntry,
52-
debugOptions: ['RedirectOutput'],
52+
debugOptions: [DebugOptions.RedirectOutput],
5353
pythonPath: 'python',
5454
args: [],
5555
envFile: '',

0 commit comments

Comments
 (0)