From cd4303b63c041c18ce80a62a045a1de0e7b8cfd4 Mon Sep 17 00:00:00 2001 From: shan1024 Date: Fri, 30 Jun 2017 12:38:50 +0530 Subject: [PATCH] Update file separator --- .../idea/debugger/BallerinaDebugProcess.java | 47 +++++++++++-------- .../idea/debugger/BallerinaStackFrame.java | 4 +- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/ballerinalang/plugins/idea/debugger/BallerinaDebugProcess.java b/src/main/java/org/ballerinalang/plugins/idea/debugger/BallerinaDebugProcess.java index a1d32484..f43cbe16 100644 --- a/src/main/java/org/ballerinalang/plugins/idea/debugger/BallerinaDebugProcess.java +++ b/src/main/java/org/ballerinalang/plugins/idea/debugger/BallerinaDebugProcess.java @@ -27,7 +27,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; @@ -57,9 +56,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; @@ -205,15 +206,20 @@ private void debugHit(String response) { return; } - if (Response.DEBUG_HIT.name().equals(message.getCode())) { - XBreakpoint 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 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(); } } @@ -245,8 +251,15 @@ private XBreakpoint 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; } } @@ -335,13 +348,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(); diff --git a/src/main/java/org/ballerinalang/plugins/idea/debugger/BallerinaStackFrame.java b/src/main/java/org/ballerinalang/plugins/idea/debugger/BallerinaStackFrame.java index 8f6cb9ee..4bb044af 100644 --- a/src/main/java/org/ballerinalang/plugins/idea/debugger/BallerinaStackFrame.java +++ b/src/main/java/org/ballerinalang/plugins/idea/debugger/BallerinaStackFrame.java @@ -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 { @@ -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;