@@ -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