Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #461 from Shan1024/update-debugger
Browse files Browse the repository at this point in the history
Change the file separator in the debugger request message
  • Loading branch information
sameerajayasoma authored Jul 4, 2017
2 parents 0e2d6b5 + 23f6e22 commit f237ff6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
Expand Down Expand Up @@ -58,8 +57,11 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;

import javax.swing.event.HyperlinkListener;

Expand Down Expand Up @@ -204,15 +206,21 @@ private void debugHit(String response) {
LOGGER.debug(e);
return;
}
if (Response.DEBUG_HIT.name().equals(message.getCode())) {
XBreakpoint<BallerinaBreakpointProperties> breakpoint = findBreakPoint(message.getLocation());
BallerinaSuspendContext context = new BallerinaSuspendContext(BallerinaDebugProcess.this, message);
XDebugSession session = getSession();
if (breakpoint == null) {
session.positionReached(context);
} else {
session.breakpointReached(breakpoint, null, context);
}

String code = message.getCode();
if (Response.DEBUG_HIT.name().equals(code)) {
ApplicationManager.getApplication().runReadAction(() -> {
XBreakpoint<BallerinaBreakpointProperties> breakpoint = findBreakPoint(message.getLocation());
BallerinaSuspendContext context = new BallerinaSuspendContext(BallerinaDebugProcess.this, message);
XDebugSession session = getSession();
if (breakpoint == null) {
session.positionReached(context);
} else {
session.breakpointReached(breakpoint, null, context);
}
});
} else if (Response.EXIT.name().equals(code) || Response.COMPLETE.name().equals(code)) {
getSession().stop();
}
}

Expand Down Expand Up @@ -244,8 +252,15 @@ private XBreakpoint<BallerinaBreakpointProperties> findBreakPoint(@NotNull Break
VirtualFile file = breakpointPosition.getFile();
int line = breakpointPosition.getLine() + 1;

// Todo - get relative package path
if (file.getName().equals(fileName) && line == lineNumber) {
Project project = getSession().getProject();
String filePath = file.getName();
String packageName = BallerinaUtil.suggestPackageNameForFile(project, file);
if (!packageName.isEmpty()) {
filePath = packageName.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
filePath += (Matcher.quoteReplacement(File.separator) + file.getName());
}

if (filePath.equals(fileName) && line == lineNumber) {
return breakpoint;
}
}
Expand Down Expand Up @@ -334,13 +349,9 @@ void sendBreakpoints() {
PackageDeclarationNode.class);
if (packageDeclarationNode != null) {
name = BallerinaUtil.suggestPackageNameForFile(project, file);
// We need to escape the file separator in the Windows. Otherwise the debug hits wont be
// identified by the debug server.
if (SystemInfo.isWindows) {
name = name.replaceAll("\\.", "\\\\\\\\") + "\\\\";
} else {
name = name.replaceAll("\\.", "/") + "/";
}
// We don't need to use '\' instead of '/' here since the debug server will convert it to
// proper separator character.
name = name.replaceAll("\\.", "/") + "/";
}
name += file.getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

public class BallerinaStackFrame extends XStackFrame {

Expand Down Expand Up @@ -73,7 +75,7 @@ private VirtualFile findFile() {
VirtualFile[] contentRoots = ProjectRootManager.getInstance(project).getContentRoots();
VirtualFile file = null;
for (VirtualFile contentRoot : contentRoots) {
String absolutePath = contentRoot.getPath() + "/" + relativePath;
String absolutePath = contentRoot.getPath() + Matcher.quoteReplacement(File.separator) + relativePath;
file = LocalFileSystem.getInstance().findFileByPath(absolutePath);
if (file != null) {
break;
Expand Down

0 comments on commit f237ff6

Please sign in to comment.