Skip to content

Commit

Permalink
Use vscode-js-debug instead of deprecated node-debug2
Browse files Browse the repository at this point in the history
Fixes #555
  • Loading branch information
mickaelistria committed Oct 2, 2023
1 parent 33ab7ea commit dcc6209
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.File;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -170,21 +171,18 @@ public boolean condition() {
return launchManager.getDebugTargets().length > before.size();
}
}.waitForCondition(Display.getDefault(), 30000), "New Debug Target not created");
Set<IDebugTarget> after = new HashSet<>(Arrays.asList(launchManager.getDebugTargets()));
after.removeAll(before);
assertEquals(1, after.size(), "Extra DebugTarget not found");
IDebugTarget target = after.iterator().next();
assertTrue(new DisplayHelper() {
@Override
public boolean condition() {
try {
return target.getThreads().length > 0;
return debugTargetWithThreads(before) != null;
} catch (DebugException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(Display.getDefault(), 30000), "Debug Target shows no threads");
IDebugTarget target = debugTargetWithThreads(before);
assertTrue(new DisplayHelper() {
@Override
public boolean condition() {
Expand Down Expand Up @@ -221,4 +219,15 @@ protected boolean condition() {
}).findAny().get();
assertEquals("1605", nVariable.getValue().getValueString());
}

private IDebugTarget debugTargetWithThreads(Collection<IDebugTarget> toExclude) throws DebugException {
Set<IDebugTarget> current = new HashSet<>(Arrays.asList(launchManager.getDebugTargets()));
current.removeAll(toExclude);
for (IDebugTarget target : current) {
if (target.getThreads().length > 0) {
return target;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -56,27 +57,18 @@ public void testFindThreadsAndHitsBreakpoint() throws Exception {
Set<IDebugTarget> before = new HashSet<>(Arrays.asList(launchManager.getDebugTargets()));
DisplayHelper.sleep(1000);
new NodeRunDebugLaunchShortcut().launch(editor, ILaunchManager.DEBUG_MODE);
assertTrue(new DisplayHelper() {
@Override
public boolean condition() {
return launchManager.getDebugTargets().length > before.size();
}
}.waitForCondition(Display.getDefault(), 30000), "New Debug Target not created");
Set<IDebugTarget> after = new HashSet<>(Arrays.asList(launchManager.getDebugTargets()));
after.removeAll(before);
assertEquals(1, after.size(), "Extra DebugTarget not found");
IDebugTarget target = after.iterator().next();
assertTrue(new DisplayHelper() {
@Override
public boolean condition() {
try {
return target.getThreads().length > 0;
return debugTargetWithThreads(before) != null;
} catch (DebugException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(Display.getDefault(), 30000), "Debug Target shows no threads");
IDebugTarget target = debugTargetWithThreads(before);
assertTrue(new DisplayHelper() {
@Override
public boolean condition() {
Expand Down Expand Up @@ -113,4 +105,15 @@ protected boolean condition() {
}).findAny().get();
assertEquals("\"Eclipse User\"", nVariable.getValue().getValueString());
}

private IDebugTarget debugTargetWithThreads(Collection<IDebugTarget> toExclude) throws DebugException {
Set<IDebugTarget> current = new HashSet<>(Arrays.asList(launchManager.getDebugTargets()));
current.removeAll(toExclude);
for (IDebugTarget target : current) {
if (target.getThreads().length > 0) {
return target;
}
}
return null;
}
}
1 change: 1 addition & 0 deletions org.eclipse.wildwebdeveloper/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ target/
bin/
language-servers/
node_modules/
js-debug/
package-lock.json
1 change: 1 addition & 0 deletions org.eclipse.wildwebdeveloper/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bin.includes = META-INF/,\
snippets/,\
icons/,\
schema/,\
js-debug/,\
plugin.properties
# See https://github.com/redhat-developer/yaml-language-server/issues/253
bin.excludes = node_modules/yaml-language-server/out/server/node_modules/
1 change: 0 additions & 1 deletion org.eclipse.wildwebdeveloper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"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",
"node-debug2": "file:target/node-debug2-1.43.0.tgz",
"@vue/language-server" : "1.8.15",
"fsevents" : "2.3.3"
}
Expand Down
39 changes: 13 additions & 26 deletions org.eclipse.wildwebdeveloper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,42 +66,42 @@
</configuration>
</execution>
<execution>
<id>fetch-node-debug2</id>
<id>fetch-chrome-debug-adapter</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/node-debug2/1.43.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage</url>
<outputFileName>node-debug2.zip</outputFileName>
<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}/node-debug2</outputDirectory>
<outputDirectory>${project.build.directory}/chrome-debug-adapter</outputDirectory>
</configuration>
</execution>
<execution>
<id>fetch-chrome-debug-adapter</id>
<id>fetch-eslint-ls</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>
<url>https://dbaeumer.gallery.vsassets.io/_apis/public/gallery/publisher/dbaeumer/extension/vscode-eslint/2.4.2/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage</url>
<outputFileName>vscode-eslint-ls.zip</outputFileName>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/chrome-debug-adapter</outputDirectory>
<outputDirectory>${project.build.directory}/vscode-eslint-ls</outputDirectory>
</configuration>
</execution>
<execution>
<id>fetch-eslint-ls</id>
<id>fetch-js-debug</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://dbaeumer.gallery.vsassets.io/_apis/public/gallery/publisher/dbaeumer/extension/vscode-eslint/2.4.2/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage</url>
<outputFileName>vscode-eslint-ls.zip</outputFileName>
<url>https://github.com/microsoft/vscode-js-debug/releases/download/v1.83.0/js-debug-dap-v1.83.0.tar.gz</url>
<outputFileName>js-debug.tar.gz</outputFileName>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/vscode-eslint-ls</outputDirectory>
<outputDirectory>${project.basedir}</outputDirectory>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -148,19 +148,6 @@
</target>
</configuration>
</execution>
<execution>
<id>prepare-node-debug2</id>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete
file="${project.build.directory}/node-debug2/extension/.gitignore" />
</target>
</configuration>
</execution>
<execution>
<id>remove package-lock before install</id>
<phase>compile</phase>
Expand Down Expand Up @@ -197,7 +184,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>node-debug2/extension/</arg>
<arg>chrome-debug-adapter/extension/</arg>
<arg>vscode-eslint-ls/extension/server</arg>
</arguments>
Expand Down Expand Up @@ -235,6 +221,7 @@
<jgit.ignore>
node_modules
package-lock.json
js-debug
</jgit.ignore>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Type;
import java.net.ServerSocket;
import java.net.URL;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;

import org.eclipse.core.resources.IContainer;
Expand All @@ -48,9 +51,10 @@
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.debug.DSPPlugin;
import org.eclipse.lsp4e.debug.launcher.DSPLaunchDelegate;
import org.eclipse.swt.widgets.Display;
Expand Down Expand Up @@ -78,7 +82,7 @@ public class NodeRunDAPDebugDelegate extends DSPLaunchDelegate {
private static final String ENV = "env"; //$NON-NLS-1$
private static final String RUNTIME_EXECUTABLE = "runtimeExecutable"; //$NON-NLS-1$

public static final String NODE_DEBUG_CMD = "/node_modules/node-debug2/out/src/nodeDebug.js"; //$NON-NLS-1$
public static final String NODE_DEBUG_CMD = "/js-debug/src/dapDebugServer.js"; //$NON-NLS-1$
public static final String TYPESCRIPT_CONTENT_TYPE = "org.eclipse.wildwebdeveloper.ts"; //$NON-NLS-1$
public static final String JAVACRIPT_CONTENT_TYPE = "org.eclipse.wildwebdeveloper.js"; //$NON-NLS-1$

Expand All @@ -103,6 +107,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
// user settings
Map<String, Object> param = new HashMap<>();
param.put(LaunchConstants.PROGRAM, VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(configuration.getAttribute(LaunchConstants.PROGRAM, "no program path defined"))); //$NON-NLS-1$
param.put("type", "pwa-node");
String argsString = configuration.getAttribute(ARGUMENTS, "").trim(); //$NON-NLS-1$
if (!argsString.isEmpty()) {
Object[] args = Arrays.asList(argsString.split(" ")).stream() //$NON-NLS-1$
Expand Down Expand Up @@ -144,21 +149,40 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
}

try {
URL fileURL = FileLocator.toFileURL(
getClass().getResource(NODE_DEBUG_CMD));
URL fileURL = FileLocator.toFileURL(getClass().getResource(NODE_DEBUG_CMD));
File file = new File(fileURL.getPath());
List<String> debugCmdArgs = Collections.singletonList(file.getAbsolutePath());
int port = 0;
try (ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
serverSocket.close();
} catch (IOException ex) {
Activator.getDefault().getLog().log(Status.error(ex.getMessage(), ex));
}
File cwdFile = cwd == null || cwd.isBlank() ? new File(System.getProperty("user.dir")) : new File(cwd); //$NON-NLS-1$
Process vscodeJsDebugExec = DebugPlugin.exec(new String[] { runtimeExecutable.getAbsolutePath(), file.getAbsolutePath(), Integer.toString(port) }, cwdFile, new String[] { "DA_TEST_DISABLE_TELEMETRY=true"}, false);
IProcess vscodeJsDebugIProcess = DebugPlugin.newProcess(launch, vscodeJsDebugExec, "debug adapter");
AtomicBoolean started = new AtomicBoolean();
vscodeJsDebugIProcess.getStreamsProxy().getOutputStreamMonitor().addListener((text, mon) -> {
if (text.toLowerCase().contains("listening")) {
started.set(true);
}
});
Instant request = Instant.now();
while (!started.get() && Duration.between(request, Instant.now()).compareTo(Duration.ofSeconds(3)) < 3) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}

DSPLaunchDelegateLaunchBuilder builder = new DSPLaunchDelegateLaunchBuilder(configuration, mode, launch,
monitor);
builder.setLaunchDebugAdapter(NodeJSManager.getNodeJsLocation().getAbsolutePath(), debugCmdArgs);
builder.setAttachDebugAdapter("::1", port);
builder.setMonitorDebugAdapter(configuration.getAttribute(DSPPlugin.ATTR_DSP_MONITOR_DEBUG_ADAPTER, false));
builder.setDspParameters(param);
super.launch(builder);
} catch (IOException 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$
} catch (IOException ex) {
LanguageServerPlugin.logError(ex);
}
}

Expand Down

0 comments on commit dcc6209

Please sign in to comment.