Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add a launch.json option to capture output from stdoutput and stderr streams #138

Merged
merged 1 commit into from
Sep 11, 2017
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
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@
"type": "boolean",
"description": "%node.showAsyncStacks.description%",
"default": true
},
"outputCapture": {
"enum": [
"console",
"std"
],
"description": "%node.launch.outputCapture.description%",
"default": "console"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"node.launch.runtimeArgs.description": "Optional arguments passed to the runtime executable.",
"node.launch.env.description": "Environment variables passed to the program.",
"node.launch.envFile.description": "Absolute path to a file containing environment variable definitions.",
"node.launch.outputCapture.description": "Where to capture output messages: Console API, or stdout/stderr streams.",

"node.launch.config.name": "Launch",

Expand Down
12 changes: 9 additions & 3 deletions src/nodeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {
private _waitingForEntryPauseEvent = true;
private _finishedConfig = false;
private _handlingEarlyNodeMsgs = true;
private _captureFromStd: boolean = false;

private _supportsRunInTerminalRequest: boolean;
private _restartMode: boolean;
Expand Down Expand Up @@ -134,6 +135,8 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {
}
}

this._captureFromStd = args.outputCapture === 'std';

return this.resolveProgramPath(programPath, args.sourceMaps).then<void>(resolvedProgramPath => {
let program: string;
let cwd = args.cwd;
Expand Down Expand Up @@ -295,8 +298,7 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {

// Must attach a listener to stdout or process will hang on Windows
nodeProcess.stdout.on('data', (data: string) => {
// If only running, use stdout/stderr instead of debug protocol logs
if (noDebugMode) {
if (noDebugMode || this._captureFromStd) {
let msg = data.toString();
this._session.sendEvent(new OutputEvent(msg, 'stdout'));
}
Expand Down Expand Up @@ -335,7 +337,7 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {
msg = msg.replace(helpMsg, '');
}

if (this._handlingEarlyNodeMsgs || noDebugMode) {
if (this._handlingEarlyNodeMsgs || noDebugMode || this._captureFromStd) {
this._session.sendEvent(new OutputEvent(msg, 'stderr'));
}

Expand All @@ -349,6 +351,10 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {
// Once any console API message is received, we are done listening to initial stderr output
this._handlingEarlyNodeMsgs = false;

if (this._captureFromStd) {
return;
}

// Strip the --debug-brk deprecation message which is printed at startup
if (!params.args || params.args.length !== 1 || typeof params.args[0].value !== 'string' || !params.args[0].value.match(NodeDebugAdapter.DEBUG_BRK_DEP_MSG)) {
super.onConsoleAPICalled(params);
Expand Down
4 changes: 4 additions & 0 deletions src/nodeDebugInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as Core from 'vscode-chrome-debug-core';

type ConsoleType = "internalConsole" | "integratedTerminal" | "externalTerminal";

type OutputCaptureType = "console" | "std";

export interface ICommonRequestArgs extends Core.ICommonRequestArgs {
stopOnEntry?: boolean;
address?: string;
Expand Down Expand Up @@ -38,6 +40,8 @@ export interface ILaunchRequestArguments extends Core.ILaunchRequestArgs, ICommo
console?: ConsoleType;
/** Manually selected debugging port */
port?: number;
/** Source of the debug output */
outputCapture?: OutputCaptureType;

/** Logging options */
diagnosticLogging?: boolean;
Expand Down