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
This also restore ability to debug running Node processes (eg start with
--inspect).

Requires usage of latest LSP4E support for DAP.

Fixes #555
  • Loading branch information
mickaelistria committed Oct 8, 2023
1 parent 92ece9f commit b6e8837
Show file tree
Hide file tree
Showing 15 changed files with 619 additions and 545 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 @@ -76,9 +77,17 @@ public void setUpLaunch() throws DebugException {

private void removeAllLaunches() throws DebugException {
for (ILaunch launch : this.launchManager.getLaunches()) {
launch.terminate();
try {
launch.terminate();
} catch (DebugException e) {
e.printStackTrace();
}
for (IDebugTarget debugTarget : launch.getDebugTargets()) {
debugTarget.terminate();
try {
debugTarget.terminate();
} catch (DebugException e) {
e.printStackTrace();
}
launch.removeDebugTarget(debugTarget);
}
for (IProcess process : launch.getProcesses()) {
Expand Down Expand Up @@ -170,21 +179,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 +227,82 @@ 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;
}

@Test
public void testFindThreadsAndHitsBreakpointTypeScript() throws Exception {
IProject project = Utils.provisionTestProject("HelloWorldTS");
IFile tsFile = project.getFile("index.ts");
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), tsFile);
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
TextSelection selection = new TextSelection(doc, doc.getLineOffset(2) + 1, 0);
IToggleBreakpointsTarget toggleBreakpointsTarget = DebugUITools.getToggleBreakpointsTargetManager()
.getToggleBreakpointsTarget(editor, selection);
toggleBreakpointsTarget.toggleLineBreakpoints(editor, selection);
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() {
try {
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() {
try {
return Arrays.stream(target.getThreads()).anyMatch(ISuspendResume::isSuspended);
} catch (DebugException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(Display.getDefault(), 3000), "No thread is suspended");
IThread suspendedThread = Arrays.stream(target.getThreads()).filter(ISuspendResume::isSuspended).findFirst()
.get();
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
try {
return suspendedThread.getStackFrames().length > 0
&& suspendedThread.getStackFrames()[0].getVariables().length > 0;
} catch (Exception ex) {
// ignore
return false;
}
}
}.waitForCondition(Display.getDefault(), 3000), "Suspended Thread doesn't show variables");
IVariable closureVar = null;
for (IVariable variable : suspendedThread.getStackFrames()[0].getVariables()) {
if ("Closure".equals(variable.getName())) {
closureVar = variable;
}
}
IVariable userVariable = null;
for (IVariable variable : closureVar.getValue().getVariables()) {
if ("user".equals(variable.getName())) {
userVariable = variable;
}
}
assertEquals("'Eclipse User'", userVariable.getValue().getValueString());
}

}

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
let user:string = "Eclipse User";
console.log("Hello world,, " + user + '!');
new Promise(resolve => setTimeout(resolve, 1000)).then(() =>
console.log("Hello world,, " + user + '!')
);
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2017",
"module": "commonjs",
"lib": ["es6", "dom"],
"allowJs": true,
"sourceMap": true,
"outDir": ".build/",
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
"skipLibCheck": true
}
}
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
2 changes: 1 addition & 1 deletion org.eclipse.wildwebdeveloper/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.resources;bundle-version="3.12.0",
org.eclipse.debug.core;bundle-version="3.11.0",
org.eclipse.debug.ui;bundle-version="3.11.0",
org.eclipse.lsp4e.debug;bundle-version="0.9.0",
org.eclipse.lsp4e.debug;bundle-version="0.15.5",
com.google.gson;bundle-version="2.8.2",
org.eclipse.core.expressions;bundle-version="3.6.0",
org.eclipse.tm4e.languageconfiguration,
Expand Down
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
Loading

0 comments on commit b6e8837

Please sign in to comment.