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

Breakpoints in Scala sources in VSCode #5910

Merged
merged 1 commit into from
Jun 2, 2023
Merged
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
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