Skip to content

Commit 9e03b4c

Browse files
author
Paul van Brenk
committed
Finish up options to use when starting the Node process
1 parent 9e71319 commit 9e03b4c

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

Nodejs/Product/Nodejs/Debugger/DebugEngine/AD7Engine.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ public sealed class AD7Engine : IDebugEngine2, IDebugEngineLaunch2, IDebugProgra
8585
/// </summary>
8686
public const string WaitOnNormalExitSetting = "WAIT_ON_NORMAL_EXIT";
8787

88-
/// <summary>
89-
/// Specifies if the output should be redirected to the visual studio output window.
90-
/// </summary>
91-
public const string RedirectOutputSetting = "REDIRECT_OUTPUT";
92-
9388
/// <summary>
9489
/// Specifies options which should be passed to the Node runtime before the script. If
9590
/// the interpreter options should include a semicolon then it should be escaped as a double
@@ -517,11 +512,6 @@ int IDebugEngineLaunch2.LaunchSuspended(string pszServer, IDebugPort2 port, stri
517512
debugOptions |= NodeDebugOptions.WaitOnNormalExit;
518513
}
519514
break;
520-
case RedirectOutputSetting:
521-
if (Boolean.TryParse(setting[1], out value) && value) {
522-
debugOptions |= NodeDebugOptions.RedirectOutput;
523-
}
524-
break;
525515
case DirMappingSetting:
526516
string[] dirs = setting[1].Split('|');
527517
if (dirs.Length == 2) {

Nodejs/Product/Nodejs/Debugger/NodeDebugOptions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,5 @@ internal enum NodeDebugOptions {
2929
/// Passing this flag to the debugger will cause it to wait for input on a normal (zero) exit code.
3030
/// </summary>
3131
WaitOnNormalExit = 0x02,
32-
/// <summary>
33-
/// Passing this flag will cause output to standard out to be redirected via the debugger
34-
/// so it can be outputted in the Visual Studio debug output window.
35-
/// </summary>
36-
RedirectOutput = 0x04,
37-
38-
/// <summary>
39-
/// Set if you do not want to create a window
40-
/// </summary>
41-
CreateNoWindow = 0x40
4232
}
4333
}

Nodejs/Product/Nodejs/Debugger/NodeDebugger.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ private static NodeProcess StartNodeProcess(string exe, string dir, string env,
151151
debuggerPort: debuggerPortOrDefault);
152152
}
153153

154-
155-
156154
#region Public Process API
157155

158156
public int Id => _id != null ? _id.Value : _process.Id;
@@ -244,7 +242,7 @@ public async Task BreakAllAsync() {
244242
// We need to get the backtrace before we break, so we request the backtrace
245243
// and follow up with firing the appropriate event for the break
246244
tokenSource = new CancellationTokenSource(_timeout);
247-
bool running = await PerformBacktraceAsync(tokenSource.Token).ConfigureAwait(false);
245+
var running = await PerformBacktraceAsync(tokenSource.Token).ConfigureAwait(false);
248246
Debug.Assert(!running);
249247

250248
// Fallback to firing step complete event

Nodejs/Product/Nodejs/Logging/LiveLogger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
//
1515
//*********************************************************//
1616

17-
using Microsoft.NodejsTools.Options;
18-
using Microsoft.VisualStudioTools.Project;
1917
using System;
2018
using System.Diagnostics;
2119
using System.Globalization;
20+
using Microsoft.NodejsTools.Options;
21+
using Microsoft.VisualStudioTools.Project;
2222

2323
namespace Microsoft.NodejsTools.Logging {
2424

Nodejs/Product/Nodejs/Project/NodejsProjectLauncher.cs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,20 @@ private int Start(string file, bool debug) {
9494
private void StartAndAttachDebugger(string file, string nodePath) {
9595

9696
// start the node process
97-
string workingDir = _project.GetWorkingDirectory();
98-
string env = "";
97+
var workingDir = _project.GetWorkingDirectory();
98+
var env = "";
9999
var interpreterOptions = _project.GetProjectProperty(NodeProjectProperty.NodeExeArguments);
100+
var debugOptions = this.GetDebugOptions();
100101

101-
var process = NodeDebugger.StartNodeProcessWithInspect(exe: nodePath, script: file, dir: workingDir, env: env, interpreterOptions: interpreterOptions, debugOptions: NodeDebugOptions.None);
102+
var process = NodeDebugger.StartNodeProcessWithInspect(exe: nodePath, script: file, dir: workingDir, env: env, interpreterOptions: interpreterOptions, debugOptions: debugOptions);
102103
process.Start();
103104

104105
// setup debug info and attach
105106
var debugUri = $"http://127.0.0.1:{process.DebuggerPort}";
106107

107108
var dbgInfo = new VsDebugTargetInfo4();
108109
dbgInfo.dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning;
109-
dbgInfo.LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop;
110+
dbgInfo.LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
110111

111112
dbgInfo.guidLaunchDebugEngine = WebkitDebuggerGuid;
112113
dbgInfo.dwDebugEngineCount = 1;
@@ -115,6 +116,7 @@ private void StartAndAttachDebugger(string file, string nodePath) {
115116
dbgInfo.pDebugEngines = enginesPtr;
116117
dbgInfo.guidPortSupplier = WebkitPortSupplierGuid;
117118
dbgInfo.bstrPortName = debugUri;
119+
dbgInfo.fSendToOutputWindow = 0;
118120

119121
// we connect through a URI, so no need to set the process,
120122
// we need to set the process id to '1' so the debugger is able to attach
@@ -123,6 +125,22 @@ private void StartAndAttachDebugger(string file, string nodePath) {
123125
AttachDebugger(dbgInfo);
124126
}
125127

128+
private NodeDebugOptions GetDebugOptions() {
129+
130+
var debugOptions = NodeDebugOptions.None;
131+
132+
if (NodejsPackage.Instance.GeneralOptionsPage.WaitOnAbnormalExit) {
133+
debugOptions |= NodeDebugOptions.WaitOnAbnormalExit;
134+
}
135+
136+
if (NodejsPackage.Instance.GeneralOptionsPage.WaitOnNormalExit) {
137+
debugOptions |= NodeDebugOptions.WaitOnNormalExit;
138+
}
139+
140+
141+
return debugOptions;
142+
}
143+
126144
private void AttachDebugger(VsDebugTargetInfo4 dbgInfo) {
127145
var serviceProvider = _project.Site;
128146

@@ -155,7 +173,7 @@ private static IntPtr MarshalDebugEngines(Guid[] debugEngines) {
155173
}
156174

157175
private void StartNodeProcess(string file, string nodePath, bool startBrowser) {
158-
//TODO: looks like this duplicates a ton of code in NodeDebugger
176+
//TODO: looks like this duplicates a bunch of code in NodeDebugger
159177
var psi = new ProcessStartInfo() {
160178
UseShellExecute = false,
161179

@@ -228,7 +246,7 @@ private string GetFullUrl() {
228246
}
229247
}
230248

231-
internal static string GetFullUrl(string host, int port) {
249+
private static string GetFullUrl(string host, int port) {
232250
UriBuilder builder;
233251
Uri uri;
234252
if (Uri.TryCreate(host, UriKind.Absolute, out uri)) {
@@ -332,10 +350,19 @@ private bool SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile) {
332350
}
333351

334352
dbgInfo.fSendStdoutToOutputWindow = 0;
353+
dbgInfo.bstrEnv = GetEnvironmentVariablesString(url);
335354

355+
356+
// Set the Node debugger
357+
dbgInfo.clsidCustom = AD7Engine.DebugEngineGuid;
358+
dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
359+
return true;
360+
}
361+
362+
private string GetEnvironmentVariablesString(string url) {
336363
var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
337364
if (!String.IsNullOrWhiteSpace(url)) {
338-
Uri webUrl = new Uri(url);
365+
var webUrl = new Uri(url);
339366
env["PORT"] = webUrl.Port.ToString();
340367
}
341368

@@ -347,7 +374,7 @@ private bool SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile) {
347374
// add any inherited env vars
348375
var variables = Environment.GetEnvironmentVariables();
349376
foreach (var key in variables.Keys) {
350-
string strKey = (string)key;
377+
var strKey = (string)key;
351378
if (!env.ContainsKey(strKey)) {
352379
env.Add(strKey, (string)variables[key]);
353380
}
@@ -356,18 +383,15 @@ private bool SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile) {
356383
//Environment variables should be passed as a
357384
//null-terminated block of null-terminated strings.
358385
//Each string is in the following form:name=value\0
359-
StringBuilder buf = new StringBuilder();
386+
var buf = new StringBuilder();
360387
foreach (var entry in env) {
361388
buf.AppendFormat("{0}={1}\0", entry.Key, entry.Value);
362389
}
363390
buf.Append("\0");
364-
dbgInfo.bstrEnv = buf.ToString();
391+
return buf.ToString();
365392
}
366393

367-
// Set the Node debugger
368-
dbgInfo.clsidCustom = AD7Engine.DebugEngineGuid;
369-
dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
370-
return true;
394+
return null;
371395
}
372396

373397
private bool ShouldStartBrowser() {

0 commit comments

Comments
 (0)