Skip to content

Commit ca5a46d

Browse files
author
Paul van Brenk
committed
Remove support for old Webkit debugger which nobody used
And cleaned up some code
1 parent 2297b17 commit ca5a46d

File tree

4 files changed

+13
-148
lines changed

4 files changed

+13
-148
lines changed

Nodejs/Product/Nodejs/Project/NodejsProjectLauncher.cs

Lines changed: 7 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ internal class NodejsProjectLauncher : IProjectLauncher
3232
private readonly NodejsProjectNode _project;
3333
private int? _testServerPort;
3434

35-
private static readonly Guid WebkitDebuggerGuid = Guid.Parse("4cc6df14-0ab5-4a91-8bb4-eb0bf233d0fe");
36-
private static readonly Guid WebkitPortSupplierGuid = Guid.Parse("4103f338-2255-40c0-acf5-7380e2bea13d");
3735
internal static readonly Guid WebKitDebuggerV2Guid = Guid.Parse("30d423cc-6d0b-4713-b92d-6b2a374c3d89");
3836

3937
public NodejsProjectLauncher(NodejsProjectNode project)
@@ -64,26 +62,20 @@ public int LaunchFile(string file, bool debug)
6462
}
6563

6664
var nodeVersion = Nodejs.GetNodeVersion(nodePath);
67-
var chromeProtocolRequired = nodeVersion >= new Version(8, 0) || CheckDebugProtocolOption();
6865
var startBrowser = ShouldStartBrowser();
6966

7067
// The call to Version.ToString() is safe, since changes to the ToString method are very unlikely, as the current output is widely documented.
71-
if (debug && !chromeProtocolRequired)
68+
if (debug)
7269
{
73-
StartWithDebugger(file);
74-
TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString());
75-
}
76-
else if (debug && chromeProtocolRequired)
77-
{
78-
if (CheckUseNewChromeDebugProtocolOption())
70+
if (nodeVersion >= new Version(8, 0))
7971
{
8072
StartWithChromeV2Debugger(file, nodePath, startBrowser);
8173
TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString());
8274
}
8375
else
8476
{
85-
StartAndAttachDebugger(file, nodePath, startBrowser);
86-
TelemetryHelper.LogDebuggingStarted("Chrome", nodeVersion.ToString());
77+
StartWithDebugger(file);
78+
TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString());
8779
}
8880
}
8981
else
@@ -97,144 +89,13 @@ public int LaunchFile(string file, bool debug)
9789

9890
// todo: move usersettings to separate class, so we can use this from other places.
9991

100-
internal static bool CheckUseNewChromeDebugProtocolOption()
101-
{
102-
var optionString = NodejsDialogPage.LoadString(name: "WebKitVersion", cat: "Debugging");
103-
104-
return !StringComparer.OrdinalIgnoreCase.Equals(optionString, "V1");
105-
}
106-
107-
internal static bool CheckDebugProtocolOption()
108-
{
109-
var optionString = NodejsDialogPage.LoadString(name: "DebugProtocol", cat: "Debugging");
110-
111-
return StringComparer.OrdinalIgnoreCase.Equals(optionString, "chrome");
112-
}
113-
11492
internal static bool CheckEnableDiagnosticLoggingOption()
11593
{
11694
var optionString = NodejsDialogPage.LoadString(name: "DiagnosticLogging", cat: "Debugging");
11795

11896
return StringComparer.OrdinalIgnoreCase.Equals(optionString, "true");
11997
}
12098

121-
internal static string CheckForRegistrySpecifiedNodeParams()
122-
{
123-
var paramString = NodejsDialogPage.LoadString(name: "NodeCmdParams", cat: "Debugging");
124-
125-
return paramString;
126-
}
127-
128-
private void StartAndAttachDebugger(string file, string nodePath, bool startBrowser)
129-
{
130-
// start the node process
131-
var workingDir = _project.GetWorkingDirectory();
132-
var url = GetFullUrl();
133-
var env = GetEnvironmentVariablesString(url);
134-
var interpreterOptions = _project.GetProjectProperty(NodeProjectProperty.NodeExeArguments);
135-
var debugOptions = this.GetDebugOptions();
136-
var script = GetFullArguments(file, includeNodeArgs: false);
137-
138-
var process = NodeDebugger.StartNodeProcessWithInspect(exe: nodePath, script: script, dir: workingDir, env: env, interpreterOptions: interpreterOptions, debugOptions: debugOptions);
139-
process.Start();
140-
141-
// setup debug info and attach
142-
var debugUri = $"http://127.0.0.1:{process.DebuggerPort}";
143-
144-
var dbgInfo = new VsDebugTargetInfo4();
145-
dbgInfo.dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning;
146-
dbgInfo.LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
147-
148-
dbgInfo.guidLaunchDebugEngine = WebkitDebuggerGuid;
149-
dbgInfo.dwDebugEngineCount = 1;
150-
151-
var enginesPtr = MarshalDebugEngines(new[] { WebkitDebuggerGuid });
152-
dbgInfo.pDebugEngines = enginesPtr;
153-
dbgInfo.guidPortSupplier = WebkitPortSupplierGuid;
154-
dbgInfo.bstrPortName = debugUri;
155-
dbgInfo.fSendToOutputWindow = 0;
156-
157-
// we connect through a URI, so no need to set the process,
158-
// we need to set the process id to '1' so the debugger is able to attach
159-
dbgInfo.bstrExe = $"\01";
160-
161-
AttachDebugger(dbgInfo);
162-
163-
if (startBrowser)
164-
{
165-
Uri uri = null;
166-
if (!String.IsNullOrWhiteSpace(url))
167-
{
168-
uri = new Uri(url);
169-
}
170-
171-
if (uri != null)
172-
{
173-
OnPortOpenedHandler.CreateHandler(
174-
uri.Port,
175-
shortCircuitPredicate: () => process.HasExited,
176-
action: () =>
177-
{
178-
VsShellUtilities.OpenBrowser(url, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
179-
}
180-
);
181-
}
182-
}
183-
}
184-
185-
private NodeDebugOptions GetDebugOptions()
186-
{
187-
var debugOptions = NodeDebugOptions.None;
188-
189-
if (NodejsPackage.Instance.GeneralOptionsPage.WaitOnAbnormalExit)
190-
{
191-
debugOptions |= NodeDebugOptions.WaitOnAbnormalExit;
192-
}
193-
194-
if (NodejsPackage.Instance.GeneralOptionsPage.WaitOnNormalExit)
195-
{
196-
debugOptions |= NodeDebugOptions.WaitOnNormalExit;
197-
}
198-
199-
return debugOptions;
200-
}
201-
202-
private void AttachDebugger(VsDebugTargetInfo4 dbgInfo)
203-
{
204-
var serviceProvider = _project.Site;
205-
206-
var debugger = serviceProvider.GetService(typeof(SVsShellDebugger)) as IVsDebugger4;
207-
208-
if (debugger == null)
209-
{
210-
throw new InvalidOperationException("Failed to get the debugger service.");
211-
}
212-
213-
var launchResults = new VsDebugTargetProcessInfo[1];
214-
debugger.LaunchDebugTargets4(1, new[] { dbgInfo }, launchResults);
215-
}
216-
217-
private static IntPtr MarshalDebugEngines(Guid[] debugEngines)
218-
{
219-
if (debugEngines.Length == 0)
220-
{
221-
return IntPtr.Zero;
222-
}
223-
224-
var guidSize = Marshal.SizeOf(typeof(Guid));
225-
var size = debugEngines.Length * guidSize;
226-
var bytes = new byte[size];
227-
for (var i = 0; i < debugEngines.Length; ++i)
228-
{
229-
debugEngines[i].ToByteArray().CopyTo(bytes, i * guidSize);
230-
}
231-
232-
var pDebugEngines = Marshal.AllocCoTaskMem(size);
233-
Marshal.Copy(bytes, 0, pDebugEngines, size);
234-
235-
return pDebugEngines;
236-
}
237-
23899
private void StartNodeProcess(string file, string nodePath, bool startBrowser)
239100
{
240101
//TODO: looks like this duplicates a bunch of code in NodeDebugger
@@ -385,6 +246,8 @@ private void StartWithChromeV2Debugger(string file, string nodePath, bool startB
385246
}
386247

387248
var runtimeArguments = ConvertArguments(this._project.GetProjectProperty(NodeProjectProperty.NodeExeArguments));
249+
// If we supply the port argument we also need to manually add --inspect-brk=port to the runtime arguments
250+
runtimeArguments = runtimeArguments.Append($"--inspect-brk=${debuggerPort}");
388251
var scriptArguments = ConvertArguments(this._project.GetProjectProperty(NodeProjectProperty.ScriptArguments));
389252

390253
var cwd = _project.GetWorkingDirectory(); // Current working directory
@@ -395,7 +258,7 @@ private void StartWithChromeV2Debugger(string file, string nodePath, bool startB
395258
new JProperty("program", file),
396259
new JProperty("args", scriptArguments),
397260
new JProperty("runtimeExecutable", nodePath),
398-
new JProperty("runtimeArgs", runtimeArguments.Concat(new[] { $"--inspect-brk=${debuggerPort}" }).ToArray()), // If we supply the port argument we also need to manually add --inspect-brk=port to the runtime arguments
261+
new JProperty("runtimeArgs", runtimeArguments),
399262
new JProperty("port", debuggerPort),
400263
new JProperty("cwd", cwd),
401264
new JProperty("console", "externalTerminal"),

Nodejs/Product/Nodejs/Workspace/JsFileDebugLaunchTargetProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void IVsDebugLaunchTargetProvider.SetupDebugTargetInfo(ref VsDebugTargetInfo vsD
3131
var nodeExe = CheckNodeInstalledAndWarn(debugLaunchContext);
3232

3333
var nodeVersion = Nodejs.GetNodeVersion(nodeExe);
34-
if (nodeVersion >= new Version(8, 0) || NodejsProjectLauncher.CheckDebugProtocolOption())
34+
if (nodeVersion >= new Version(8, 0))
3535
{
3636
this.SetupDebugTargetInfoForInspectProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
3737
TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);

Nodejs/Product/Nodejs/Workspace/LaunchDebugTargetProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ protected string CheckNodeInstalledAndWarn(DebugLaunchActionContext debugLaunchC
6161

6262
protected static string GetJsonConfigurationForInspectProtocol(string target, string workingDir, string nodeExe, DebugLaunchActionContext debugLaunchContext)
6363
{
64+
var debuggerPort = debugLaunchContext.LaunchConfiguration.GetValue(DebuggerPortKey, defaultValue: NodejsConstants.DefaultDebuggerPort);
6465
var runtimeArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue<string>(NodeArgsKey, defaultValue: null));
66+
// If we supply the port argument we also need to manually add --inspect-brk=port to the runtime arguments
67+
runtimeArguments = runtimeArguments.Append($"--inspect-brk=${debuggerPort}");
6568
var scriptArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue<string>(ScriptArgsKey, defaultValue: null));
66-
var port = debugLaunchContext.LaunchConfiguration.GetValue(DebuggerPortKey, defaultValue: NodejsConstants.DefaultDebuggerPort);
6769

6870
var configuration = new JObject(
6971
new JProperty("name", "Debug Node.js program from Visual Studio"),
@@ -73,7 +75,7 @@ protected static string GetJsonConfigurationForInspectProtocol(string target, st
7375
new JProperty("args", scriptArguments),
7476
new JProperty("runtimeExecutable", nodeExe),
7577
new JProperty("runtimeArgs", runtimeArguments),
76-
new JProperty("port", port),
78+
new JProperty("port", debuggerPort),
7779
new JProperty("cwd", workingDir),
7880
new JProperty("console", "externalTerminal"),
7981
new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),

Nodejs/Product/Nodejs/Workspace/NodeJsDebugLaunchTargetProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void IVsDebugLaunchTargetProvider2.SetupDebugTargetInfo(ref VsDebugTargetInfo4 v
3636
var nodeExe = CheckNodeInstalledAndWarn(debugLaunchContext);
3737

3838
var nodeVersion = Nodejs.GetNodeVersion(nodeExe);
39-
if (nodeVersion >= new Version(8, 0) || NodejsProjectLauncher.CheckDebugProtocolOption())
39+
if (nodeVersion >= new Version(8, 0))
4040
{
4141
SetupDebugTargetInfoForInspectProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
4242
TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);

0 commit comments

Comments
 (0)