Skip to content

Commit

Permalink
Change how debug options are captured in launch.json (#1395)
Browse files Browse the repository at this point in the history
Fixes #1326
  • Loading branch information
DonJayamanne authored Apr 18, 2018
1 parent 41ec24a commit 6c17234
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 126 deletions.
105 changes: 61 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -934,22 +934,6 @@
"description": "Absolute path to the working directory of the program being debugged. Default is the root directory of the file (leave empty).",
"default": "${workspaceFolder}"
},
"debugOptions": {
"type": "array",
"description": "Advanced options, view read me for further details.",
"items": {
"type": "string",
"enum": [
"RedirectOutput",
"DebugStdLib",
"Django",
"Jinja",
"Sudo",
"Pyramid"
]
},
"default": []
},
"env": {
"type": "object",
"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.",
Expand All @@ -974,25 +958,48 @@
"type": "boolean",
"description": "Enable logging of debugger events to a log file.",
"default": false
},
"redirectOutput": {
"type": "boolean",
"description": "Redirect output.",
"default": true
},
"debugStdLib": {
"type": "boolean",
"description": "Debug standard library code.",
"default": false
},
"django": {
"type": "boolean",
"description": "Django debugging.",
"default": false
},
"jinja": {
"enum": [
true,
false,
null
],
"description": "Jinja template debugging (e.g. Flask).",
"default": null
},
"sudo": {
"type": "boolean",
"description": "Running debug program under elevated permissions (on Unix).",
"default": false
},
"pyramid": {
"type": "boolean",
"description": "Whether debugging Pyramid applications",
"default": false
}
}
},
"attach": {
"required": [
"port",
"remoteRoot"
"port"
],
"properties": {
"localRoot": {
"type": "string",
"description": "Local source root that corrresponds to the 'remoteRoot'.",
"default": "${workspaceFolder}"
},
"remoteRoot": {
"type": "string",
"description": "The source root of the remote host.",
"default": ""
},
"port": {
"type": "number",
"description": "Debug port to attach",
Expand All @@ -1003,23 +1010,9 @@
"description": "IP Address of the of remote server (default is localhost or use 127.0.0.1).",
"default": "localhost"
},
"debugOptions": {
"type": "array",
"description": "Advanced options, view read me for further details.",
"items": {
"type": "string",
"enum": [
"RedirectOutput",
"DebugStdLib",
"Django",
"Jinja"
]
},
"default": []
},
"pathMappings": {
"type": "array",
"label": "Additional path mappings.",
"label": "Path mappings.",
"items": {
"type": "object",
"label": "Path mapping",
Expand All @@ -1031,7 +1024,7 @@
"localRoot": {
"type": "string",
"label": "Local source root.",
"default": ""
"default": "${workspaceFolder}"
},
"remoteRoot": {
"type": "string",
Expand All @@ -1046,6 +1039,30 @@
"type": "boolean",
"description": "Enable logging of debugger events to a log file.",
"default": false
},
"redirectOutput": {
"type": "boolean",
"description": "Redirect output.",
"default": true
},
"debugStdLib": {
"type": "boolean",
"description": "Debug standard library code.",
"default": false
},
"django": {
"type": "boolean",
"description": "Django debugging.",
"default": false
},
"jinja": {
"enum": [
true,
false,
null
],
"description": "Jinja template debugging (e.g. Flask).",
"default": null
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pythonFiles/PythonTools/visualstudio_py_launcher.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Python Tools for Visual Studio
# Copyright(c) Microsoft Corporation
# All rights reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the License); you may not use
# this file except in compliance with the License. You may obtain a copy of the
# License at http://www.apache.org/licenses/LICENSE-2.0
#
#
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
# MERCHANTABLITY OR NON-INFRINGEMENT.
#
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.

Expand Down
43 changes: 35 additions & 8 deletions src/client/debugger/Common/Contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,23 @@ export interface ExceptionHandling {

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

export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
export interface AdditionalLaunchDebugOptions {
redirectOutput?: boolean;
django?: boolean;
jinja?: boolean;
debugStdLib?: boolean;
sudo?: boolean;
pyramid?: boolean;
}

export interface AdditionalAttachDebugOptions {
redirectOutput?: boolean;
django?: boolean;
jinja?: boolean;
debugStdLib?: boolean;
}

export interface BaseLaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
type?: DebuggerType;
/** An absolute path to the program to debug. */
module?: string;
Expand All @@ -60,31 +76,42 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
/** Automatically stop target after launch. If not specified, target does not stop. */
stopOnEntry?: boolean;
args: string[];
applicationType?: string;
cwd?: string;
debugOptions?: DebugOptions[];
env?: Object;
envFile: string;
exceptionHandling?: ExceptionHandling;
console?: 'none' | 'integratedTerminal' | 'externalTerminal';
port?: number;
host?: string;
logToFile?: boolean;
}

export interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
export interface LaunchRequestArgumentsV1 extends BaseLaunchRequestArguments {
exceptionHandling?: ExceptionHandling;
}

export interface LaunchRequestArguments extends BaseLaunchRequestArguments, AdditionalLaunchDebugOptions {
}

export interface BaseAttachRequestArguments extends DebugProtocol.AttachRequestArguments {
type?: DebuggerType;
/** An absolute path to local directory with source. */
localRoot: string;
remoteRoot: string;
port?: number;
host?: string;
secret?: string;
logToFile?: boolean;
pathMappings?: { localRoot: string; remoteRoot: string }[];
debugOptions?: DebugOptions[];
}
export interface AttachRequestArgumentsV1 extends BaseAttachRequestArguments {
secret?: string;
localRoot: string;
remoteRoot: string;
}

export interface AttachRequestArguments extends BaseAttachRequestArguments, AdditionalAttachDebugOptions {
localRoot?: string;
remoteRoot?: string;
pathMappings?: { localRoot: string; remoteRoot: string }[];
}
export interface IDebugServer {
port: number;
host?: string;
Expand Down
8 changes: 4 additions & 4 deletions src/client/debugger/DebugClients/RemoteDebugClient.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { DebugSession } from 'vscode-debugadapter';
import { AttachRequestArguments, IPythonProcess } from '../Common/Contracts';
import { AttachRequestArgumentsV1, BaseAttachRequestArguments, IPythonProcess } from '../Common/Contracts';
import { BaseDebugServer } from '../DebugServers/BaseDebugServer';
import { RemoteDebugServer } from '../DebugServers/RemoteDebugServer';
import { RemoteDebugServerV2 } from '../DebugServers/RemoteDebugServerv2';
import { DebugClient, DebugType } from './DebugClient';

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

Expand All @@ -19,7 +19,7 @@ export class RemoteDebugClient extends DebugClient<AttachRequestArguments> {
this.debugServer = new RemoteDebugServerV2(this.debugSession, undefined as any, this.args);
} else {
this.pythonProcess = pythonProcess!;
this.debugServer = new RemoteDebugServer(this.debugSession, this.pythonProcess!, this.args);
this.debugServer = new RemoteDebugServer(this.debugSession, this.pythonProcess!, this.args as {} as AttachRequestArgumentsV1);
}
return this.debugServer!;
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/debugger/DebugClients/localDebugClientV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class LocalDebugClientV2 extends LocalDebugClient {
return ['-m', this.args.module, ...programArgs];
}
if (this.args.program && this.args.program.length > 0) {
return ['--file', this.args.program, ...programArgs];
return [this.args.program, ...programArgs];
}
return programArgs;
}
Expand Down
10 changes: 5 additions & 5 deletions src/client/debugger/DebugServers/RemoteDebugServer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// 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
// 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
"use strict";

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

export class RemoteDebugServer extends BaseDebugServer {
private socket?: net.Socket;
private args: AttachRequestArguments;
constructor(debugSession: DebugSession, pythonProcess: IPythonProcess, args: AttachRequestArguments) {
private args: AttachRequestArgumentsV1;
constructor(debugSession: DebugSession, pythonProcess: IPythonProcess, args: AttachRequestArgumentsV1) {
super(debugSession, pythonProcess);
this.args = args;
}
Expand All @@ -29,7 +29,7 @@ export class RemoteDebugServer extends BaseDebugServer {
catch (ex) { }
this.socket = undefined;
}
private stream: SocketStream;
private stream!: SocketStream;
public Start(): Promise<IDebugServer> {
return new Promise<IDebugServer>((resolve, reject) => {
let that = this;
Expand Down
10 changes: 5 additions & 5 deletions src/client/debugger/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { DebugProtocol } from "vscode-debugprotocol";
import { DEBUGGER } from '../../client/telemetry/constants';
import { DebuggerTelemetry } from '../../client/telemetry/types';
import { isNotInstalledError } from '../common/helpers';
import { enum_EXCEPTION_STATE, IPythonBreakpoint, IPythonException, PythonBreakpointConditionKind, PythonBreakpointPassCountKind, PythonEvaluationResultReprKind } from "./Common/Contracts";
import { enum_EXCEPTION_STATE, IPythonBreakpoint, IPythonException, PythonBreakpointConditionKind, PythonBreakpointPassCountKind, PythonEvaluationResultReprKind, LaunchRequestArgumentsV1, AttachRequestArgumentsV1 } from "./Common/Contracts";
import { IDebugServer, IPythonEvaluationResult, IPythonModule, IPythonStackFrame, IPythonThread } from "./Common/Contracts";
import { AttachRequestArguments, DebugOptions, LaunchRequestArguments, PythonEvaluationResultFlags, TelemetryEvent } from "./Common/Contracts";
import { DebugOptions, LaunchRequestArguments, PythonEvaluationResultFlags, TelemetryEvent } from "./Common/Contracts";
import { getPythonExecutable, validatePath } from './Common/Utils';
import { DebugClient } from "./DebugClients/DebugClient";
import { CreateAttachDebugClient, CreateLaunchDebugClient } from "./DebugClients/DebugFactory";
Expand Down Expand Up @@ -203,8 +203,8 @@ export class PythonDebugger extends LoggingDebugSession {
this.sendEvent(new OutputEvent(output, outputChannel));
}
private entryResponse?: DebugProtocol.LaunchResponse;
private launchArgs!: LaunchRequestArguments;
private attachArgs!: AttachRequestArguments;
private launchArgs!: LaunchRequestArgumentsV1;
private attachArgs!: AttachRequestArgumentsV1;
private canStartDebugger(): Promise<boolean> {
return Promise.resolve(true);
}
Expand Down Expand Up @@ -280,7 +280,7 @@ export class PythonDebugger extends LoggingDebugSession {
this.sendErrorResponse(response, 200, errorMsg);
});
}
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments) {
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArgumentsV1) {
if (args.logToFile === true) {
logger.setup(LogLevel.Verbose, true);
}
Expand Down
Loading

0 comments on commit 6c17234

Please sign in to comment.