Skip to content

Commit 6c17234

Browse files
authored
Change how debug options are captured in launch.json (microsoft#1395)
Fixes microsoft#1326
1 parent 41ec24a commit 6c17234

13 files changed

Lines changed: 260 additions & 126 deletions

File tree

package.json

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -934,22 +934,6 @@
934934
"description": "Absolute path to the working directory of the program being debugged. Default is the root directory of the file (leave empty).",
935935
"default": "${workspaceFolder}"
936936
},
937-
"debugOptions": {
938-
"type": "array",
939-
"description": "Advanced options, view read me for further details.",
940-
"items": {
941-
"type": "string",
942-
"enum": [
943-
"RedirectOutput",
944-
"DebugStdLib",
945-
"Django",
946-
"Jinja",
947-
"Sudo",
948-
"Pyramid"
949-
]
950-
},
951-
"default": []
952-
},
953937
"env": {
954938
"type": "object",
955939
"description": "Environment variables defined as a key value pair. Property ends up being the Environment Variable and the value of the property ends up being the value of the Env Variable.",
@@ -974,25 +958,48 @@
974958
"type": "boolean",
975959
"description": "Enable logging of debugger events to a log file.",
976960
"default": false
961+
},
962+
"redirectOutput": {
963+
"type": "boolean",
964+
"description": "Redirect output.",
965+
"default": true
966+
},
967+
"debugStdLib": {
968+
"type": "boolean",
969+
"description": "Debug standard library code.",
970+
"default": false
971+
},
972+
"django": {
973+
"type": "boolean",
974+
"description": "Django debugging.",
975+
"default": false
976+
},
977+
"jinja": {
978+
"enum": [
979+
true,
980+
false,
981+
null
982+
],
983+
"description": "Jinja template debugging (e.g. Flask).",
984+
"default": null
985+
},
986+
"sudo": {
987+
"type": "boolean",
988+
"description": "Running debug program under elevated permissions (on Unix).",
989+
"default": false
990+
},
991+
"pyramid": {
992+
"type": "boolean",
993+
"description": "Whether debugging Pyramid applications",
994+
"default": false
977995
}
978996
}
979997
},
980998
"attach": {
981999
"required": [
982-
"port",
983-
"remoteRoot"
1000+
"port"
9841001
],
9851002
"properties": {
986-
"localRoot": {
987-
"type": "string",
988-
"description": "Local source root that corrresponds to the 'remoteRoot'.",
989-
"default": "${workspaceFolder}"
990-
},
991-
"remoteRoot": {
992-
"type": "string",
993-
"description": "The source root of the remote host.",
994-
"default": ""
995-
},
9961003
"port": {
9971004
"type": "number",
9981005
"description": "Debug port to attach",
@@ -1003,23 +1010,9 @@
10031010
"description": "IP Address of the of remote server (default is localhost or use 127.0.0.1).",
10041011
"default": "localhost"
10051012
},
1006-
"debugOptions": {
1007-
"type": "array",
1008-
"description": "Advanced options, view read me for further details.",
1009-
"items": {
1010-
"type": "string",
1011-
"enum": [
1012-
"RedirectOutput",
1013-
"DebugStdLib",
1014-
"Django",
1015-
"Jinja"
1016-
]
1017-
},
1018-
"default": []
1019-
},
10201013
"pathMappings": {
10211014
"type": "array",
1022-
"label": "Additional path mappings.",
1015+
"label": "Path mappings.",
10231016
"items": {
10241017
"type": "object",
10251018
"label": "Path mapping",
@@ -1031,7 +1024,7 @@
10311024
"localRoot": {
10321025
"type": "string",
10331026
"label": "Local source root.",
1034-
"default": ""
1027+
"default": "${workspaceFolder}"
10351028
},
10361029
"remoteRoot": {
10371030
"type": "string",
@@ -1046,6 +1039,30 @@
10461039
"type": "boolean",
10471040
"description": "Enable logging of debugger events to a log file.",
10481041
"default": false
1042+
},
1043+
"redirectOutput": {
1044+
"type": "boolean",
1045+
"description": "Redirect output.",
1046+
"default": true
1047+
},
1048+
"debugStdLib": {
1049+
"type": "boolean",
1050+
"description": "Debug standard library code.",
1051+
"default": false
1052+
},
1053+
"django": {
1054+
"type": "boolean",
1055+
"description": "Django debugging.",
1056+
"default": false
1057+
},
1058+
"jinja": {
1059+
"enum": [
1060+
true,
1061+
false,
1062+
null
1063+
],
1064+
"description": "Jinja template debugging (e.g. Flask).",
1065+
"default": null
10491066
}
10501067
}
10511068
}

pythonFiles/PythonTools/visualstudio_py_launcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Python Tools for Visual Studio
22
# Copyright(c) Microsoft Corporation
33
# All rights reserved.
4-
#
4+
#
55
# Licensed under the Apache License, Version 2.0 (the License); you may not use
66
# this file except in compliance with the License. You may obtain a copy of the
77
# License at http://www.apache.org/licenses/LICENSE-2.0
8-
#
8+
#
99
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
1010
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
1111
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
1212
# MERCHANTABLITY OR NON-INFRINGEMENT.
13-
#
13+
#
1414
# See the Apache Version 2.0 License for specific language governing
1515
# permissions and limitations under the License.
1616

src/client/debugger/Common/Contracts.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,23 @@ export interface ExceptionHandling {
5151

5252
export type DebuggerType = 'python' | 'pythonExperimental';
5353

54-
export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
54+
export interface AdditionalLaunchDebugOptions {
55+
redirectOutput?: boolean;
56+
django?: boolean;
57+
jinja?: boolean;
58+
debugStdLib?: boolean;
59+
sudo?: boolean;
60+
pyramid?: boolean;
61+
}
62+
63+
export interface AdditionalAttachDebugOptions {
64+
redirectOutput?: boolean;
65+
django?: boolean;
66+
jinja?: boolean;
67+
debugStdLib?: boolean;
68+
}
69+
70+
export interface BaseLaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
5571
type?: DebuggerType;
5672
/** An absolute path to the program to debug. */
5773
module?: string;
@@ -60,31 +76,42 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
6076
/** Automatically stop target after launch. If not specified, target does not stop. */
6177
stopOnEntry?: boolean;
6278
args: string[];
63-
applicationType?: string;
6479
cwd?: string;
6580
debugOptions?: DebugOptions[];
6681
env?: Object;
6782
envFile: string;
68-
exceptionHandling?: ExceptionHandling;
6983
console?: 'none' | 'integratedTerminal' | 'externalTerminal';
7084
port?: number;
7185
host?: string;
7286
logToFile?: boolean;
7387
}
7488

75-
export interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
89+
export interface LaunchRequestArgumentsV1 extends BaseLaunchRequestArguments {
90+
exceptionHandling?: ExceptionHandling;
91+
}
92+
93+
export interface LaunchRequestArguments extends BaseLaunchRequestArguments, AdditionalLaunchDebugOptions {
94+
}
95+
96+
export interface BaseAttachRequestArguments extends DebugProtocol.AttachRequestArguments {
7697
type?: DebuggerType;
7798
/** An absolute path to local directory with source. */
78-
localRoot: string;
79-
remoteRoot: string;
8099
port?: number;
81100
host?: string;
82-
secret?: string;
83101
logToFile?: boolean;
84-
pathMappings?: { localRoot: string; remoteRoot: string }[];
85102
debugOptions?: DebugOptions[];
86103
}
104+
export interface AttachRequestArgumentsV1 extends BaseAttachRequestArguments {
105+
secret?: string;
106+
localRoot: string;
107+
remoteRoot: string;
108+
}
87109

110+
export interface AttachRequestArguments extends BaseAttachRequestArguments, AdditionalAttachDebugOptions {
111+
localRoot?: string;
112+
remoteRoot?: string;
113+
pathMappings?: { localRoot: string; remoteRoot: string }[];
114+
}
88115
export interface IDebugServer {
89116
port: number;
90117
host?: string;

src/client/debugger/DebugClients/RemoteDebugClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { DebugSession } from 'vscode-debugadapter';
2-
import { AttachRequestArguments, IPythonProcess } from '../Common/Contracts';
2+
import { AttachRequestArgumentsV1, BaseAttachRequestArguments, IPythonProcess } from '../Common/Contracts';
33
import { BaseDebugServer } from '../DebugServers/BaseDebugServer';
44
import { RemoteDebugServer } from '../DebugServers/RemoteDebugServer';
55
import { RemoteDebugServerV2 } from '../DebugServers/RemoteDebugServerv2';
66
import { DebugClient, DebugType } from './DebugClient';
77

8-
export class RemoteDebugClient extends DebugClient<AttachRequestArguments> {
8+
export class RemoteDebugClient<T extends BaseAttachRequestArguments> extends DebugClient<T> {
99
private pythonProcess?: IPythonProcess;
1010
private debugServer?: BaseDebugServer;
1111
// tslint:disable-next-line:no-any
12-
constructor(args: AttachRequestArguments, debugSession: DebugSession) {
12+
constructor(args: T, debugSession: DebugSession) {
1313
super(args, debugSession);
1414
}
1515

@@ -19,7 +19,7 @@ export class RemoteDebugClient extends DebugClient<AttachRequestArguments> {
1919
this.debugServer = new RemoteDebugServerV2(this.debugSession, undefined as any, this.args);
2020
} else {
2121
this.pythonProcess = pythonProcess!;
22-
this.debugServer = new RemoteDebugServer(this.debugSession, this.pythonProcess!, this.args);
22+
this.debugServer = new RemoteDebugServer(this.debugSession, this.pythonProcess!, this.args as {} as AttachRequestArgumentsV1);
2323
}
2424
return this.debugServer!;
2525
}

src/client/debugger/DebugClients/localDebugClientV2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class LocalDebugClientV2 extends LocalDebugClient {
2222
return ['-m', this.args.module, ...programArgs];
2323
}
2424
if (this.args.program && this.args.program.length > 0) {
25-
return ['--file', this.args.program, ...programArgs];
25+
return [this.args.program, ...programArgs];
2626
}
2727
return programArgs;
2828
}

src/client/debugger/DebugServers/RemoteDebugServer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// tslint:disable:quotemark ordered-imports no-any no-empty curly member-ordering one-line max-func-body-length no-var-self prefer-const cyclomatic-complexity prefer-template
1+
// tslint:disable:quotemark ordered-imports no-any no-empty curly member-ordering one-line max-func-body-length no-var-self prefer-const cyclomatic-complexity prefer-template no-this-assignment
22
"use strict";
33

44
import { DebugSession, OutputEvent } from "vscode-debugadapter";
5-
import { IPythonProcess, IDebugServer, AttachRequestArguments } from "../Common/Contracts";
5+
import { IPythonProcess, IDebugServer, AttachRequestArgumentsV1 } from "../Common/Contracts";
66
import * as net from "net";
77
import { BaseDebugServer } from "./BaseDebugServer";
88
import { SocketStream } from "../../common/net/socket/SocketStream";
@@ -15,8 +15,8 @@ const AttachCommandBytes: Buffer = new Buffer("ATCH", "ascii");
1515

1616
export class RemoteDebugServer extends BaseDebugServer {
1717
private socket?: net.Socket;
18-
private args: AttachRequestArguments;
19-
constructor(debugSession: DebugSession, pythonProcess: IPythonProcess, args: AttachRequestArguments) {
18+
private args: AttachRequestArgumentsV1;
19+
constructor(debugSession: DebugSession, pythonProcess: IPythonProcess, args: AttachRequestArgumentsV1) {
2020
super(debugSession, pythonProcess);
2121
this.args = args;
2222
}
@@ -29,7 +29,7 @@ export class RemoteDebugServer extends BaseDebugServer {
2929
catch (ex) { }
3030
this.socket = undefined;
3131
}
32-
private stream: SocketStream;
32+
private stream!: SocketStream;
3333
public Start(): Promise<IDebugServer> {
3434
return new Promise<IDebugServer>((resolve, reject) => {
3535
let that = this;

src/client/debugger/Main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { DebugProtocol } from "vscode-debugprotocol";
1414
import { DEBUGGER } from '../../client/telemetry/constants';
1515
import { DebuggerTelemetry } from '../../client/telemetry/types';
1616
import { isNotInstalledError } from '../common/helpers';
17-
import { enum_EXCEPTION_STATE, IPythonBreakpoint, IPythonException, PythonBreakpointConditionKind, PythonBreakpointPassCountKind, PythonEvaluationResultReprKind } from "./Common/Contracts";
17+
import { enum_EXCEPTION_STATE, IPythonBreakpoint, IPythonException, PythonBreakpointConditionKind, PythonBreakpointPassCountKind, PythonEvaluationResultReprKind, LaunchRequestArgumentsV1, AttachRequestArgumentsV1 } from "./Common/Contracts";
1818
import { IDebugServer, IPythonEvaluationResult, IPythonModule, IPythonStackFrame, IPythonThread } from "./Common/Contracts";
19-
import { AttachRequestArguments, DebugOptions, LaunchRequestArguments, PythonEvaluationResultFlags, TelemetryEvent } from "./Common/Contracts";
19+
import { DebugOptions, LaunchRequestArguments, PythonEvaluationResultFlags, TelemetryEvent } from "./Common/Contracts";
2020
import { getPythonExecutable, validatePath } from './Common/Utils';
2121
import { DebugClient } from "./DebugClients/DebugClient";
2222
import { CreateAttachDebugClient, CreateLaunchDebugClient } from "./DebugClients/DebugFactory";
@@ -203,8 +203,8 @@ export class PythonDebugger extends LoggingDebugSession {
203203
this.sendEvent(new OutputEvent(output, outputChannel));
204204
}
205205
private entryResponse?: DebugProtocol.LaunchResponse;
206-
private launchArgs!: LaunchRequestArguments;
207-
private attachArgs!: AttachRequestArguments;
206+
private launchArgs!: LaunchRequestArgumentsV1;
207+
private attachArgs!: AttachRequestArgumentsV1;
208208
private canStartDebugger(): Promise<boolean> {
209209
return Promise.resolve(true);
210210
}
@@ -280,7 +280,7 @@ export class PythonDebugger extends LoggingDebugSession {
280280
this.sendErrorResponse(response, 200, errorMsg);
281281
});
282282
}
283-
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments) {
283+
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArgumentsV1) {
284284
if (args.logToFile === true) {
285285
logger.setup(LogLevel.Verbose, true);
286286
}

0 commit comments

Comments
 (0)