示例#1
0
        protected static string GetJsonConfigurationForInspectProtocol(string target, string workingDir, string nodeExe, DebugLaunchActionContext debugLaunchContext)
        {
            var debuggerPort     = debugLaunchContext.LaunchConfiguration.GetValue(DebuggerPortKey, defaultValue: NodejsConstants.DefaultDebuggerPort);
            var runtimeArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue <string>(NodeArgsKey, defaultValue: null));

            // If we supply the port argument we also need to manually add --inspect-brk=port to the runtime arguments
            runtimeArguments = runtimeArguments.Append($"--inspect-brk={debuggerPort}");
            var scriptArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue <string>(ScriptArgsKey, defaultValue: null));

            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", target),
                new JProperty("args", scriptArguments),
                new JProperty("runtimeExecutable", nodeExe),
                new JProperty("runtimeArgs", runtimeArguments),
                new JProperty("port", debuggerPort),
                new JProperty("cwd", workingDir),
                new JProperty("console", "externalTerminal"),
                new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true));

            return(configuration.ToString());
        }
示例#2
0
        private void SetupDebugTargetInfoForWebkitV2Protocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            // todo: refactor the debugging and process starting so we can re-use

            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = Path.GetDirectoryName(target); // Current working directory

            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", target),
                new JProperty("runtimeExecutable", nodeExe),
                new JProperty("cwd", cwd),
                new JProperty("console", "externalTerminal"),
                new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true));

            var jsonContent = configuration.ToString();

            vsDebugTargetInfo.dlo         = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.clsidCustom = NodejsProjectLauncher.WebKitDebuggerV2Guid;
            vsDebugTargetInfo.bstrExe     = target;
            vsDebugTargetInfo.bstrOptions = jsonContent;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
示例#3
0
        private void SetupDebugTargetInfoForWebkitV2Protocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            // todo: refactor the debugging and process starting so we can re-use

            var setupConfiguration = new SetupConfiguration();
            var setupInstance      = setupConfiguration.GetInstanceForCurrentProcess();
            var visualStudioInstallationInstanceID = setupInstance.GetInstanceId();

            // The Node2Adapter depends on features only in Node v6+, so the old v5.4 version of node will not suffice for this scenario
            // This node.exe will be the one used by the node2 debug adapter, not the one used to host the user code.
            var pathToNodeExe = Path.Combine(setupInstance.GetInstallationPath(), "JavaScript\\Node.JS\\v6.4.0_x86\\Node.exe");

            // We check the registry to see if any parameters for the node.exe invocation have been specified (like "--inspect"), and append them if we find them.
            var nodeParams = NodejsProjectLauncher.CheckForRegistrySpecifiedNodeParams();

            if (!string.IsNullOrEmpty(nodeParams))
            {
                pathToNodeExe = pathToNodeExe + " " + nodeParams;
            }

            var pathToNode2DebugAdapterRuntime = Environment.ExpandEnvironmentVariables(@"""%ALLUSERSPROFILE%\" +
                                                                                        $@"Microsoft\VisualStudio\NodeAdapter\{visualStudioInstallationInstanceID}\extension\out\src\nodeDebug.js""");

            string trimmedPathToNode2DebugAdapter = pathToNode2DebugAdapterRuntime.Replace("\"", "");

            if (!File.Exists(trimmedPathToNode2DebugAdapter))
            {
                pathToNode2DebugAdapterRuntime = Environment.ExpandEnvironmentVariables(@"""%ALLUSERSPROFILE%\" +
                                                                                        $@"Microsoft\VisualStudio\NodeAdapter\{visualStudioInstallationInstanceID}\out\src\nodeDebug.js""");
            }

            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = Path.GetDirectoryName(target); // Current working directory

            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", target),
                new JProperty("runtimeExecutable", nodeExe),
                new JProperty("cwd", cwd),
                new JProperty("console", "externalTerminal"),
                new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true),
                new JProperty("$adapter", pathToNodeExe),
                new JProperty("$adapterArgs", pathToNode2DebugAdapterRuntime));

            var jsonContent = configuration.ToString();

            vsDebugTargetInfo.dlo         = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.clsidCustom = NodejsProjectLauncher.WebKitDebuggerV2Guid;
            vsDebugTargetInfo.bstrExe     = target;
            vsDebugTargetInfo.bstrOptions = jsonContent;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
        private void SetupDebugTargetInfoForInspectProtocol(ref VsDebugTargetInfo4 vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = vsDebugTargetInfo.bstrCurDir;

            var jsonContent = GetJsonConfigurationForInspectProtocol(target, cwd, nodeExe, debugLaunchContext);

            vsDebugTargetInfo.dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.guidLaunchDebugEngine = NodejsProjectLauncher.GetDebuggerGuid();
            vsDebugTargetInfo.bstrOptions           = jsonContent;
            vsDebugTargetInfo.LaunchFlags           = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
        void IVsDebugLaunchTargetProvider.SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            var nodeExe = CheckNodeInstalledAndWarn(debugLaunchContext);

            var nodeVersion = Nodejs.GetNodeVersion(nodeExe);

            if (nodeVersion >= new Version(8, 0) || NodejsProjectLauncher.CheckDebugProtocolOption())
            {
                this.SetupDebugTargetInfoForInspectProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);
            }
            else
            {
                this.SetupDebugTargetInfoForNodeProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString(), isProject: false);
            }
        }
示例#6
0
        public void SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            var nodeExe = debugLaunchContext.LaunchConfiguration.GetValue(NodeExeKey, defaultValue: Nodejs.GetPathToNodeExecutableFromEnvironment());

            var nodeVersion = Nodejs.GetNodeVersion(nodeExe);

            if (nodeVersion >= new Version(8, 0) || NodejsProjectLauncher.CheckDebugProtocolOption())
            {
                SetupDebugTargetInfoForWebkitV2Protocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);
            }
            else
            {
                this.SetupDebugTargetInfoForNodeProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString(), isProject: false);
            }
        }
示例#7
0
        protected static string GetJsonConfigurationForInspectProtocol(string target, string workingDir, string nodeExe, DebugLaunchActionContext debugLaunchContext)
        {
            var debuggerPort     = debugLaunchContext.LaunchConfiguration.GetValue(DebuggerPortKey, defaultValue: NodejsConstants.DefaultDebuggerPort);
            var runtimeArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue <string>(NodeArgsKey, defaultValue: null));

            // If we supply the port argument we also need to manually add --inspect-brk=port to the runtime arguments
            runtimeArguments = runtimeArguments.Append($"--inspect-brk={debuggerPort}");
            var scriptArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue <string>(ScriptArgsKey, defaultValue: null));

            var launchConfig = new NodePinezorroDebugLaunchConfig(target,
                                                                  scriptArguments,
                                                                  nodeExe,
                                                                  runtimeArguments,
                                                                  debuggerPort.ToString(),
                                                                  workingDir,
                                                                  NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption());


            return(JObject.FromObject(launchConfig).ToString());
        }
示例#8
0
        public void LaunchWebBrowserUriTests()
        {
            var testCases = new[] {
                new { Url = "/fob", Port = 0, Expected = "http://localhost:0/fob" },
                new { Url = "http://localhost:9999/fob", Port = 9999, Expected = "http://localhost:9999/fob" },
                new { Url = "http://localhost/fob", Port = 9999, Expected = "http://localhost:9999/fob" },
                new { Url = "fob", Port = 9999, Expected = "http://localhost:9999/fob" },
                new { Url = "/hello/world", Port = 367, Expected = "http://localhost:367/hello/world" },
            };

            foreach (var testCase in testCases)
            {
                Console.WriteLine("{0} {1} == {2}", testCase.Url, testCase.Port, testCase.Expected);

                Assert.AreEqual(
                    NodejsProjectLauncher.GetFullUrl(testCase.Url, testCase.Port),
                    testCase.Expected
                    );
            }
        }
示例#9
0
        public void SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            var nodeExe = debugLaunchContext.LaunchConfiguration.GetValue(NodeExeKey, defaultValue: Nodejs.GetPathToNodeExecutableFromEnvironment());

            if (string.IsNullOrEmpty(nodeExe))
            {
                var workspace = this.WorkspaceService.CurrentWorkspace;
                workspace.JTF.Run(async() =>
                {
                    await workspace.JTF.SwitchToMainThreadAsync();

                    VsShellUtilities.ShowMessageBox(this.ServiceProvider,
                                                    string.Format(Resources.NodejsNotInstalledAnyCode, LaunchConfigurationConstants.LaunchJsonFileName),
                                                    Resources.NodejsNotInstalledShort,
                                                    OLEMSGICON.OLEMSGICON_CRITICAL,
                                                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                });

                // This isn't pretty but the only way to not get an additional
                // dialog box, after the one we show.
                throw new TaskCanceledException();
            }

            var nodeVersion = Nodejs.GetNodeVersion(nodeExe);

            if (nodeVersion >= new Version(8, 0) || NodejsProjectLauncher.CheckDebugProtocolOption())
            {
                SetupDebugTargetInfoForWebkitV2Protocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);
            }
            else
            {
                this.SetupDebugTargetInfoForNodeProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString(), isProject: false);
            }
        }