Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Chrome DevTools Protocol for NodeJS Debugging #4220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ide/javascript2.debug.ui/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<friend-packages>
<friend>org.netbeans.modules.debugger.jpda.jsui</friend>
<friend>org.netbeans.modules.debugger.jpda.truffle</friend>
<friend>org.netbeans.modules.javascript.cdtdebug.ui</friend>
<friend>org.netbeans.modules.javascript.v8debug</friend>
<friend>org.netbeans.modules.javascript.v8debug.ui</friend>
<friend>org.netbeans.modules.web.javascript.debugger</friend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public class JSUtils {
private static final Logger LOG = Logger.getLogger(JSUtils.class.getName());

public static final String JS_MIME_TYPE = "text/javascript"; // NOI18N
public static final String TS_MIME_TYPE = "application/x-typescript"; // NOI18N

public static Line getCurrentLine() {
FileObject fo = EditorContextDispatcher.getDefault().getCurrentFile();
if (fo == null) {
return null;
}
if (!JS_MIME_TYPE.equalsIgnoreCase(fo.getMIMEType())) {
if (!JS_MIME_TYPE.equalsIgnoreCase(fo.getMIMEType()) && !TS_MIME_TYPE.equalsIgnoreCase(fo.getMIMEType())) {
return null;
}
return EditorContextDispatcher.getDefault().getCurrentLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@

import javax.swing.JComponent;
import org.netbeans.modules.javascript2.debug.ui.JSUtils;
import org.netbeans.modules.javascript2.debug.ui.breakpoints.JSLineBreakpointCustomizerPanel;
import org.netbeans.spi.debugger.ui.BreakpointType;
import org.netbeans.spi.debugger.ui.Controller;
import org.netbeans.spi.debugger.ui.EditorContextDispatcher;
import org.openide.filesystems.FileObject;
import org.openide.util.NbBundle;


@NbBundle.Messages({"JavaScriptBreakpointTypeCategory=JavaScript",
"LineBreakpointTypeName=Line"})
@NbBundle.Messages({
"JavaScriptBreakpointTypeCategory=JavaScript",
"LineBreakpointTypeName=Line"
})
@BreakpointType.Registration(displayName="#LineBreakpointTypeName")
public class JSLineBreakpointType extends BreakpointType {

private JSLineBreakpointCustomizerPanel cust;

/* (non-Javadoc)
* @see org.netbeans.spi.debugger.ui.BreakpointType#getCategoryDisplayName()
*/
Expand All @@ -59,7 +60,7 @@ public Controller getController() {
getCustomizer();
return cust.getController();
}

/* (non-Javadoc)
* @see org.netbeans.spi.debugger.ui.BreakpointType#getTypeDisplayName()
*/
Expand All @@ -78,7 +79,7 @@ public boolean isDefault() {
return false;
}
String mimeType = mostRecentFile.getMIMEType();
return JSUtils.JS_MIME_TYPE.equals(mimeType);
return JSUtils.JS_MIME_TYPE.equals(mimeType) || JSUtils.TS_MIME_TYPE.equals(mimeType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,23 @@
*
* @author Martin
*/
@ActionsProvider.Registration(actions={"toggleBreakpoint"},
activateForMIMETypes={JSUtils.JS_MIME_TYPE})
@ActionsProvider.Registration(
actions = {"toggleBreakpoint"},
activateForMIMETypes = {JSUtils.JS_MIME_TYPE, JSUtils.TS_MIME_TYPE}
)
public class ToggleBreakpointActionProvider extends ActionsProviderSupport
implements PropertyChangeListener {

public ToggleBreakpointActionProvider() {
setEnabled(ActionsManager.ACTION_TOGGLE_BREAKPOINT, false);
EditorContextDispatcher.getDefault().addPropertyChangeListener(
JSUtils.JS_MIME_TYPE,
WeakListeners.propertyChange(this, EditorContextDispatcher.getDefault()));
EditorContextDispatcher.getDefault().addPropertyChangeListener(
JSUtils.TS_MIME_TYPE,
WeakListeners.propertyChange(this, EditorContextDispatcher.getDefault()));
}

@Override
public void doAction(Object action) {
Line line = JSUtils.getCurrentLine();
Expand All @@ -61,7 +66,7 @@ public void doAction(Object action) {
for (Breakpoint breakpoint : d.getBreakpoints()) {
if (breakpoint instanceof JSLineBreakpoint &&
JSUtils.getLine((JSLineBreakpoint) breakpoint).equals(line)) {

d.removeBreakpoint(breakpoint);
add = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
public abstract class ViewModelSupport {

protected static final Object[] EMPTY_CHILDREN = new Object[]{};
private CopyOnWriteArrayList<ModelListener> myListeners;

private final CopyOnWriteArrayList<ModelListener> myListeners;

protected ViewModelSupport() {
myListeners = new CopyOnWriteArrayList<ModelListener>();
myListeners = new CopyOnWriteArrayList<>();
}

public final void addModelListener(ModelListener l) {
Expand Down Expand Up @@ -72,8 +72,7 @@ protected final void fireChangeEvents(Collection<ModelEvent> events) {
fireChangeEvent( event );
}
}



public static String toHTML(String text) {
return toHTML(text, false, false, null);
}
Expand All @@ -84,28 +83,39 @@ public static String toHTML(String text, boolean bold, boolean italics,
if (text.length() > 6 && text.substring(0, 6).equalsIgnoreCase("<html>")) {
return text; // Already HTML
}
StringBuffer sb = new StringBuffer ();
sb.append ("<html>");
if (bold) sb.append ("<b>");
if (italics) sb.append ("<i>");
if (color == null) {
color = UIManager.getColor("Table.foreground");
if (color == null) {
color = new JTable().getForeground();
StringBuilder sb = new StringBuilder();
sb.append("<html>");
if (bold) {
sb.append("<b>");
}
if (italics) {
sb.append("<i>");
}
Color fontColor = color;
if (fontColor == null) {
fontColor = UIManager.getColor("Table.foreground");
if (fontColor == null) {
fontColor = new JTable().getForeground();
}
}
sb.append ("<font color=");
sb.append (Integer.toHexString ((color.getRGB () & 0xffffff)));
sb.append (">");
text = text.replace ("&", "&amp;");
text = text.replace ("<", "&lt;");
text = text.replace (">", "&gt;");
sb.append (text);
sb.append ("</font>");
if (italics) sb.append ("</i>");
if (bold) sb.append ("</b>");
sb.append ("</html>");
sb.append("<font color=\"");
sb.append(String.format(
"#%02x%02x%02x",
fontColor.getRed(),
fontColor.getGreen(),
fontColor.getBlue()
));
sb.append("\">");
sb.append(text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;"));
sb.append("</font>");
if (italics) {
sb.append("</i>");
}
if (bold) {
sb.append("</b>");
}
sb.append("</html>");
return sb.toString ();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.netbeans.modules.javascript2.debug.ui.models.breakpoints;

import java.awt.Color;
import java.awt.datatransfer.Transferable;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Expand All @@ -30,6 +31,7 @@
import org.netbeans.modules.javascript2.debug.breakpoints.JSBreakpointStatus;
import org.netbeans.modules.javascript2.debug.breakpoints.JSBreakpointsInfoManager;
import org.netbeans.modules.javascript2.debug.breakpoints.JSLineBreakpoint;
import org.netbeans.modules.javascript2.debug.ui.models.ViewModelSupport;
import org.netbeans.spi.debugger.DebuggerServiceRegistration;
import org.netbeans.spi.viewmodel.ExtendedNodeModel;
import org.netbeans.spi.viewmodel.ModelEvent;
Expand Down Expand Up @@ -90,7 +92,13 @@ public String getDisplayName(Object node) throws UnknownTypeException {
JSLineBreakpoint breakpoint = (JSLineBreakpoint) node;
String fileName = JSUtils.getFileName(breakpoint);
int lineNumber = breakpoint.getLineNumber();
return Bundle.LBL_LineBreakpoint_on(fileName + ":" + lineNumber);
if(breakpoint.isActive()) {
return ViewModelSupport.toHTML(
Bundle.LBL_LineBreakpoint_on(fileName + ":" + lineNumber),
true, false, null);
} else {
return Bundle.LBL_LineBreakpoint_on(fileName + ":" + lineNumber);
}
}
throw new UnknownTypeException(node);
}
Expand All @@ -112,7 +120,7 @@ public String getIconBaseWithExtension(Object node) throws UnknownTypeException
iconBase = DEACTIVATED_DISABLED_LINE_BREAKPOINT;
}
} else {
if (b == JSBreakpointStatus.getActive()) {
if (b.isActive()) {
iconBase = CURRENT_LINE_BREAKPOINT;
} else {
if (active) {
Expand Down
2 changes: 2 additions & 0 deletions ide/javascript2.debug/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
<friend>org.netbeans.modules.debugger.jpda.js</friend>
<friend>org.netbeans.modules.debugger.jpda.truffle</friend>
<friend>org.netbeans.modules.java.lsp.server</friend>
<friend>org.netbeans.modules.javascript.cdtdebug</friend>
<friend>org.netbeans.modules.javascript.cdtdebug.ui</friend>
<friend>org.netbeans.modules.javascript.v8debug</friend>
<friend>org.netbeans.modules.javascript.v8debug.ui</friend>
<friend>org.netbeans.modules.javascript2.debug.ui</friend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ public static final void resetValidity(JSLineBreakpoint lb) {
*/
public static void setActive(JSLineBreakpoint lb) {
synchronized (JSBreakpointStatus.class) {
JSLineBreakpoint oldBreakpoint = activeBPRef.get();
if(oldBreakpoint != null) {
oldBreakpoint.setActive(false);
}
activeBPRef = new WeakReference<>(lb);
if(lb != null) {
lb.setActive(true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.net.URL;
import java.util.Objects;
import org.netbeans.api.debugger.Breakpoint;
import org.netbeans.api.debugger.DebuggerManager;
import org.netbeans.modules.javascript2.debug.EditorLineHandler;
Expand Down Expand Up @@ -56,9 +57,11 @@ public class JSLineBreakpoint extends Breakpoint {
*/
public static final String PROP_FILE = "fileChanged"; // NOI18N
public static final String PROP_CONDITION = "condition";

public static final String PROP_ACTIVE = "active";

private EditorLineHandler line;
private boolean isEnabled = true;
private boolean active = false;
private volatile String condition;
private final FileRemoveListener myListener = new FileRemoveListener();
private FileChangeListener myWeakListener;
Expand Down Expand Up @@ -166,7 +169,20 @@ public void enable() {
public boolean isEnabled() {
return isEnabled;
}


final void setActive(boolean active) {
boolean oldActive = this.active;
if(Objects.equals(oldActive, active)) {
return;
}
this.active = active;
firePropertyChange(PROP_ACTIVE, oldActive, this.active);
}

public boolean isActive() {
return active;
}

@Override
protected void dispose() {
super.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import org.openide.filesystems.FileObject;

/**
Expand Down Expand Up @@ -48,7 +49,12 @@ public URL getSourceFile(String name, int hash, String content) {
}

public URL getSourceFile(String name, int hash, SourceContent content) {
String path = Integer.toHexString(hash) + '/' + name;
return getSourceFile(name, Integer.toHexString(hash), content);
}

public URL getSourceFile(String name, String hash, SourceContent content) {
Objects.requireNonNull(hash, "hash was null");
String path = hash + '/' + name;
FileObject fo = fs.findResource(path);
if (fo == null) {
fo = fs.createFile(path, content);
Expand Down
2 changes: 2 additions & 0 deletions ide/web.common/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@
<friend>org.netbeans.modules.javaee.project</friend>
<friend>org.netbeans.modules.javascript.bower</friend>
<friend>org.netbeans.modules.javascript.cdnjs</friend>
<friend>org.netbeans.modules.javascript.cdtdebug</friend>
<friend>org.netbeans.modules.javascript.cdtdebug.ui</friend>
<friend>org.netbeans.modules.javascript.grunt</friend>
<friend>org.netbeans.modules.javascript.gulp</friend>
<friend>org.netbeans.modules.javascript.jstestdriver</friend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static FileObject getSourceFile(String sourcePath, FileObject parentFolder) {
}

public FileObject getFile() {
if (file == null) {
if (file == null && parentFolder != null && mapping != null) {
int sourceIndex = mapping.getSourceIndex();
String sourcePath = sourceMap.getSourcePath(sourceIndex);
file = getSourceFile(sourcePath, parentFolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -100,7 +101,7 @@ private DirectMapping getMapping(FileObject source, String sourceMapFileName, So
if (sourceMapFileName == null && sm == null) {
String lastLine = null;
try {
List<String> lines = source.asLines();
List<String> lines = source == null ? Collections.emptyList() : source.asLines();
if (!lines.isEmpty()) {
lastLine = lines.get(lines.size() - 1);
}
Expand Down
1 change: 1 addition & 0 deletions java/debugger.jpda.trufflenode/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Manifest-Version: 1.0
AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.netbeans.modules.debugger.jpda.trufflenode/1
OpenIDE-Module-Layer: org/netbeans/modules/debugger/jpda/truffle/node/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/jpda/truffle/node/Bundle.properties
OpenIDE-Module-Specification-Version: 1.21
OpenIDE-Module-Recommends: org.netbeans.modules.debugger.jpda.truffle
Expand Down
9 changes: 0 additions & 9 deletions java/debugger.jpda.trufflenode/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@
<specification-version>1.52</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.extexecution</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>2</release-version>
<specification-version>1.48</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.java.j2seplatform</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ OpenIDE-Module-Name=GraalVM Node.js Debugging Support
OpenIDE-Module-Display-Category=Web
OpenIDE-Module-Short-Description=Supports Node.js Debugging on GraalVM
OpenIDE-Module-Long-Description=Supports debugging of Node.js based on top of GraalVM.
NodeJsDebuggerName=GraalVM via JPDA
Loading
Loading