Skip to content

Commit

Permalink
Use vscode-js-debug for Chrome
Browse files Browse the repository at this point in the history
and get rid of former debugger
  • Loading branch information
mickaelistria committed Oct 10, 2023
1 parent b6e8837 commit 17be0cb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 220 deletions.
1 change: 0 additions & 1 deletion org.eclipse.wildwebdeveloper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"vscode-css-languageserver": "file:target/vscode-css-languageserver-1.0.0.tgz",
"vscode-html-languageserver": "file:target/vscode-html-languageserver-1.0.0.tgz",
"vscode-json-languageserver": "file:target/vscode-json-languageserver-1.3.4.tgz",
"debugger-for-chrome": "file:target/debugger-for-chrome-4.13.0.tgz",
"eslint-server": "file:target/eslint-server-2.4.1.tgz",
"@vue/language-server" : "1.8.15",
"fsevents" : "2.3.3"
Expand Down
27 changes: 0 additions & 27 deletions org.eclipse.wildwebdeveloper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,6 @@
<outputDirectory>${project.build.directory}/vscode</outputDirectory>
</configuration>
</execution>
<execution>
<id>fetch-chrome-debug-adapter</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://msjsdiag.gallery.vsassets.io/_apis/public/gallery/publisher/msjsdiag/extension/debugger-for-chrome/4.13.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage</url>
<outputFileName>chromeDebugAdapter.zip</outputFileName>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/chrome-debug-adapter</outputDirectory>
</configuration>
</execution>
<execution>
<id>fetch-eslint-ls</id>
<phase>generate-resources</phase>
Expand Down Expand Up @@ -135,19 +122,6 @@
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>prepare-chrome-debug-adapter</id>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete
file="${project.build.directory}/chrome-debug-adapter/extension/.gitignore" />
</target>
</configuration>
</execution>
<execution>
<id>remove package-lock before install</id>
<phase>compile</phase>
Expand Down Expand Up @@ -184,7 +158,6 @@
<arg>vscode/VSCode-linux-x64/resources/app/extensions/html-language-features/server</arg>
<arg>vscode/VSCode-linux-x64/resources/app/extensions/css-language-features/server</arg>
<arg>vscode/VSCode-linux-x64/resources/app/extensions/json-language-features/server</arg>
<arg>chrome-debug-adapter/extension/</arg>
<arg>vscode-eslint-ls/extension/server</arg>
</arguments>
<workingDirectory>${project.build.directory}</workingDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,30 @@
*******************************************************************************/
package org.eclipse.wildwebdeveloper.debug.chrome;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.wildwebdeveloper.debug.AbstractHTMLDebugDelegate;
import org.eclipse.wildwebdeveloper.debug.LaunchConstants;

public class ChromeAttachDebugDelegate extends AbstractHTMLDebugDelegate {
public class ChromeAttachDebugDelegate extends ChromeRunDAPDebugDelegate {

static final String ID = "org.eclipse.wildwebdeveloper.launchConfiguration.chromeAttachDebug"; //$NON-NLS-1$

static final String ADDRESS = "address"; //$NON-NLS-1$

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
// user settings
Map<String, Object> param = new HashMap<>();
param.put(ADDRESS, configuration.getAttribute(ADDRESS, "no address defined")); //$NON-NLS-1$
param.put(LaunchConstants.PORT, configuration.getAttribute(LaunchConstants.PORT, 9229));
String url = configuration.getAttribute(ChromeRunDAPDebugDelegate.URL, "https://www.google.ca/");
param.put(ChromeRunDAPDebugDelegate.URL, url);
param.put("runtimeExecutable", ChromeRunDAPDebugDelegate.findChromeLocation(configuration));

super.launchWithParameters(configuration, mode, launch, monitor, param, ChromeRunDAPDebugDelegate.findDebugAdapter());

protected boolean configureAdditionalParameters(ILaunchConfiguration configuration, Map<String, Object> param) throws CoreException {
if (super.configureAdditionalParameters(configuration, param)) {
param.remove("file");
param.put("request", "attach");
String url = configuration.getAttribute(ChromeRunDAPDebugDelegate.URL, "https://github.com/eclipse/wildwebdeveloper/"); //$NON-NLS-1$
param.put(ChromeRunDAPDebugDelegate.URL, url);
param.put(ADDRESS, configuration.getAttribute(ADDRESS, "no address defined")); //$NON-NLS-1$
param.put(LaunchConstants.PORT, configuration.getAttribute(LaunchConstants.PORT, 9229));
return true;
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.ui.internal.browser.IBrowserDescriptor;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.debug.Messages;
import org.eclipse.wildwebdeveloper.debug.node.VSCodeJSDebugDelegate;

public class ChromeExecutableTab extends AbstractLaunchConfigurationTab {

Expand Down Expand Up @@ -100,7 +101,7 @@ public void createControl(Composite parent) {

@Override
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
configuration.removeAttribute(ChromeRunDAPDebugDelegate.RUNTIME_EXECUTABLE);
configuration.removeAttribute(VSCodeJSDebugDelegate.RUNTIME_EXECUTABLE);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,128 +14,40 @@
package org.eclipse.wildwebdeveloper.debug.chrome;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.internal.browser.BrowserManager;
import org.eclipse.ui.internal.browser.IBrowserDescriptor;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.debug.AbstractHTMLDebugDelegate;
import org.eclipse.wildwebdeveloper.debug.LaunchConstants;
import org.eclipse.wildwebdeveloper.debug.node.VSCodeJSDebugDelegate;

import com.google.gson.JsonObject;

public class ChromeRunDAPDebugDelegate extends AbstractHTMLDebugDelegate {
public class ChromeRunDAPDebugDelegate extends VSCodeJSDebugDelegate {

static final String ID = "org.eclipse.wildwebdeveloper.launchConfiguration.chromeRunDebug"; //$NON-NLS-1$

static final String VERBOSE = "verbose";
private static final String TRACE = "trace";
public static final String RUNTIME_EXECUTABLE = "runtimeExecutable";
public static final String URL = "url";
private static final String SOURCE_MAPS = "sourceMaps";
public static final String TYPE = "type";
public static final String CHROME = "chrome";
public static final String REQUEST = "request";
public static final String LAUNCH = "launch";

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
// user settings
Map<String, Object> param = new HashMap<>();

// Chrome executable arguments
String argsString = configuration.getAttribute(AbstractHTMLDebugDelegate.ARGUMENTS, "").trim(); //$NON-NLS-1$
if (!argsString.isEmpty()) {
Object[] args = Arrays.asList(argsString.split(" ")).stream() //$NON-NLS-1$
.filter(s -> !s.trim().isEmpty()) //
.map(s -> {
try {
return VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(s);
} catch (CoreException e) {
IStatus errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(errorStatus);
return s;
}
}) //
.toArray();
if (args.length > 0) {
param.put(AbstractHTMLDebugDelegate.ARGUMENTS, args);
}
}

// Debug environment variables
Map<String, String> env = configuration.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES,
Collections.emptyMap());
if (!env.isEmpty()) {
JsonObject envJson = new JsonObject();
for (Entry<String, String> envVar : env.entrySet()) {
envJson.addProperty(envVar.getKey(), VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(envVar.getValue()));
}
param.put(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, envJson);
}

// File or URL to debug
String url = configuration.getAttribute(URL, "");
if (!url.equals("")) {
param.put(URL, url);
} else {
param.put("file", VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(configuration.getAttribute(LaunchConstants.PROGRAM, "no program path defined"))); //$NON-NLS-1$
}

// Chrome working directory
String cwd = configuration.getAttribute(DebugPlugin.ATTR_WORKING_DIRECTORY, "").trim(); //$NON-NLS-1$
if (!cwd.isEmpty()) {
param.put(DebugPlugin.ATTR_WORKING_DIRECTORY, VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(cwd));
}

param.put(SOURCE_MAPS, true);

//Tell the debugger that we want to start a chrome debug session
param.put(TYPE, CHROME);
param.put(REQUEST, LAUNCH);

if (configuration.getAttribute(VERBOSE, false)) {
param.put(TRACE, VERBOSE);
}

super.launchWithParameters(configuration, mode, launch, monitor, param, findDebugAdapter());
public ChromeRunDAPDebugDelegate() {
super("pwa-chrome");
}

static File findDebugAdapter() {
URL fileURL;
try {
fileURL = FileLocator.toFileURL(
ChromeRunDAPDebugDelegate.class.getResource("/node_modules/debugger-for-chrome/out/src/chromeDebug.js"));
return new File(fileURL.toURI());
} catch (IOException | URISyntaxException e) {
IStatus errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(errorStatus);
Display.getDefault().asyncExec(() -> ErrorDialog.openError(Display.getDefault().getActiveShell(), "Debug error", e.getMessage(), errorStatus)); //$NON-NLS-1$

@Override
protected boolean configureAdditionalParameters(ILaunchConfiguration config, Map<String, Object> param) throws CoreException {
if (super.configureAdditionalParameters(config, param)) {
String program = (String)param.remove(LaunchConstants.PROGRAM);
param.put("file", program);
return true;
}
return null;
return false;
}

static String findChromeLocation(ILaunchConfiguration configuration) {
@Override
public File computeRuntimeExecutable(ILaunchConfiguration configuration) {
String res = ""; //$NON-NLS-1$
try {
res = configuration.getAttribute(RUNTIME_EXECUTABLE, res);
Expand All @@ -145,8 +57,8 @@ static String findChromeLocation(ILaunchConfiguration configuration) {
}
File executable = new File(res);
if (executable.isAbsolute() && executable.canExecute()) {
return res;
return executable;
}
return BrowserManager.getInstance().getWebBrowsers().stream().filter(ChromeExecutableTab::isChrome).findAny().map(IBrowserDescriptor::getLocation).orElse(null);
return BrowserManager.getInstance().getWebBrowsers().stream().filter(ChromeExecutableTab::isChrome).findAny().map(IBrowserDescriptor::getLocation).map(File::new).orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.lsp4e.debug.launcher.DSPOverrideSettingsTab;
import org.eclipse.wildwebdeveloper.debug.AbstractRunHTMLDebugTab;

public class ChromeRunDebugTabGroup extends AbstractLaunchConfigurationTabGroup {

@Override
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
setTabs(new ILaunchConfigurationTab[] {
new RunChromeDebugTab(),
new AbstractRunHTMLDebugTab() {},
new EnvironmentTab(),
new DSPOverrideSettingsTab(),
new CommonTab()
Expand Down

This file was deleted.

Loading

0 comments on commit 17be0cb

Please sign in to comment.