Skip to content

Commit

Permalink
#5910: Breakpoints in Scala sources in VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
jtulach authored Jun 2, 2023
2 parents d6c8b6f + 6034731 commit d89a420
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.netbeans.modules.java.lsp.server.debugging.breakpoints;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
Expand All @@ -27,6 +28,8 @@
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.lsp4j.debug.BreakpointEventArguments;
import org.eclipse.lsp4j.debug.Source;
Expand All @@ -37,6 +40,9 @@
import org.netbeans.api.debugger.jpda.LineBreakpoint;
import org.netbeans.modules.debugger.jpda.truffle.breakpoints.TruffleLineBreakpoint;
import org.netbeans.modules.java.lsp.server.debugging.DebugAdapterContext;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.URLMapper;
import org.openide.util.Exceptions;

/**
*
Expand Down Expand Up @@ -102,8 +108,32 @@ public CompletableFuture<NbBreakpoint> install() {
Breakpoint breakpoint;
String sourceURLLower = sourceURL.toLowerCase();
boolean isJava = sourceURLLower.endsWith(".java"); // NOI18N
boolean isScala = sourceURLLower.endsWith(".scala"); // NOI18N
boolean isGroovy = sourceURLLower.endsWith(".groovy"); // NOI18N
if (isJava || isGroovy) {
if (isScala) {
final Pattern PACKAGE = Pattern.compile("package *([\\p{Alnum}+\\.$]+) *");
try {
LineBreakpoint b = LineBreakpoint.create(sourceURL, line);

FileObject fo = URLMapper.findFileObject(new URL(sourceURL));
for (String code : fo.asLines()) {
Matcher match = PACKAGE.matcher(code);
if (match.matches()) {
String pkg = match.group(1);
int slash = sourceURL.lastIndexOf("/");
int dot = sourceURL.indexOf('.', slash + 1);
if (dot >= 0) {
String filter = pkg + "." + sourceURL.substring(slash + 1, dot) + "*";
b.setPreferredClassName(filter);
}
break;
}
}
breakpoint = b;
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
} else if (isJava || isGroovy) {
LineBreakpoint b = LineBreakpoint.create(sourceURL, line);
if (condition != null && !condition.isEmpty()) {
b.setCondition(condition);
Expand Down

0 comments on commit d89a420

Please sign in to comment.