diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestDebug.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestDebug.java index e652bdbdbb..56b5830f6d 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestDebug.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestDebug.java @@ -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; @@ -170,21 +171,18 @@ public boolean condition() { return launchManager.getDebugTargets().length > before.size(); } }.waitForCondition(Display.getDefault(), 30000), "New Debug Target not created"); - Set 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() { @@ -221,4 +219,15 @@ protected boolean condition() { }).findAny().get(); assertEquals("1605", nVariable.getValue().getValueString()); } + + private IDebugTarget debugTargetWithThreads(Collection toExclude) throws DebugException { + Set current = new HashSet<>(Arrays.asList(launchManager.getDebugTargets())); + current.removeAll(toExclude); + for (IDebugTarget target : current) { + if (target.getThreads().length > 0) { + return target; + } + } + return null; + } } diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestDebugTS.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestDebugTS.java index 9908357fc0..2a5537de61 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestDebugTS.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestDebugTS.java @@ -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; @@ -56,27 +57,18 @@ public void testFindThreadsAndHitsBreakpoint() throws Exception { Set 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 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() { @@ -113,4 +105,15 @@ protected boolean condition() { }).findAny().get(); assertEquals("\"Eclipse User\"", nVariable.getValue().getValueString()); } + + private IDebugTarget debugTargetWithThreads(Collection toExclude) throws DebugException { + Set current = new HashSet<>(Arrays.asList(launchManager.getDebugTargets())); + current.removeAll(toExclude); + for (IDebugTarget target : current) { + if (target.getThreads().length > 0) { + return target; + } + } + return null; + } } diff --git a/org.eclipse.wildwebdeveloper/.gitignore b/org.eclipse.wildwebdeveloper/.gitignore index 61dda4e492..bf4242c708 100644 --- a/org.eclipse.wildwebdeveloper/.gitignore +++ b/org.eclipse.wildwebdeveloper/.gitignore @@ -2,4 +2,5 @@ target/ bin/ language-servers/ node_modules/ +js-debug/ package-lock.json \ No newline at end of file diff --git a/org.eclipse.wildwebdeveloper/build.properties b/org.eclipse.wildwebdeveloper/build.properties index 4746789f00..1f9421c7bd 100644 --- a/org.eclipse.wildwebdeveloper/build.properties +++ b/org.eclipse.wildwebdeveloper/build.properties @@ -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/ diff --git a/org.eclipse.wildwebdeveloper/package.json b/org.eclipse.wildwebdeveloper/package.json index b94c24a3e7..e544e9d4f9 100644 --- a/org.eclipse.wildwebdeveloper/package.json +++ b/org.eclipse.wildwebdeveloper/package.json @@ -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" } diff --git a/org.eclipse.wildwebdeveloper/pom.xml b/org.eclipse.wildwebdeveloper/pom.xml index 2bcd265ff0..ecda7d2559 100644 --- a/org.eclipse.wildwebdeveloper/pom.xml +++ b/org.eclipse.wildwebdeveloper/pom.xml @@ -66,42 +66,42 @@ - fetch-node-debug2 + fetch-chrome-debug-adapter generate-resources wget - https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/node-debug2/1.43.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage - node-debug2.zip + https://msjsdiag.gallery.vsassets.io/_apis/public/gallery/publisher/msjsdiag/extension/debugger-for-chrome/4.13.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage + chromeDebugAdapter.zip true - ${project.build.directory}/node-debug2 + ${project.build.directory}/chrome-debug-adapter - fetch-chrome-debug-adapter + fetch-eslint-ls generate-resources wget - https://msjsdiag.gallery.vsassets.io/_apis/public/gallery/publisher/msjsdiag/extension/debugger-for-chrome/4.13.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage - chromeDebugAdapter.zip + https://dbaeumer.gallery.vsassets.io/_apis/public/gallery/publisher/dbaeumer/extension/vscode-eslint/2.4.2/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage + vscode-eslint-ls.zip true - ${project.build.directory}/chrome-debug-adapter + ${project.build.directory}/vscode-eslint-ls - fetch-eslint-ls + fetch-js-debug generate-resources wget - https://dbaeumer.gallery.vsassets.io/_apis/public/gallery/publisher/dbaeumer/extension/vscode-eslint/2.4.2/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage - vscode-eslint-ls.zip + https://github.com/microsoft/vscode-js-debug/releases/download/v1.83.0/js-debug-dap-v1.83.0.tar.gz + js-debug.tar.gz true - ${project.build.directory}/vscode-eslint-ls + ${project.basedir} @@ -148,19 +148,6 @@ - - prepare-node-debug2 - process-resources - - run - - - - - - - remove package-lock before install compile @@ -197,7 +184,6 @@ vscode/VSCode-linux-x64/resources/app/extensions/html-language-features/server vscode/VSCode-linux-x64/resources/app/extensions/css-language-features/server vscode/VSCode-linux-x64/resources/app/extensions/json-language-features/server - node-debug2/extension/ chrome-debug-adapter/extension/ vscode-eslint-ls/extension/server @@ -235,6 +221,7 @@ node_modules package-lock.json + js-debug diff --git a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/node/NodeRunDAPDebugDelegate.java b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/node/NodeRunDAPDebugDelegate.java index 6359b66359..2db33d9b0e 100644 --- a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/node/NodeRunDAPDebugDelegate.java +++ b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/node/NodeRunDAPDebugDelegate.java @@ -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; @@ -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; @@ -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$ @@ -103,6 +107,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun // user settings Map 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$ @@ -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 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); } }