private XBreakpoint<BallerinaBreakpointProperties> findBreakPoint(@NotNull BreakPoint breakPoint) { String fileName = breakPoint.getFileName(); String packagePath = breakPoint.getPackagePath(); String relativeFilePathInProject; // If the package is ".", full path of the file will be sent as the filename. if (".".equals(packagePath)) { // Then we need to get the actual filename from the path. int index = fileName.lastIndexOf(File.separator); if (index <= -1) { return null; } relativeFilePathInProject = fileName.substring(index); } else { // If the absolute path is not sent, we need to construct the relative file path in the project. relativeFilePathInProject = packagePath.replaceAll("\\.", File.separator) + File.separator + fileName; } int lineNumber = breakPoint.getLineNumber(); for (XBreakpoint<BallerinaBreakpointProperties> breakpoint : breakpoints) { XSourcePosition breakpointPosition = breakpoint.getSourcePosition(); if (breakpointPosition == null) { continue; } VirtualFile fileInBreakpoint = breakpointPosition.getFile(); int line = breakpointPosition.getLine() + 1; if (fileInBreakpoint.getPath().endsWith(relativeFilePathInProject) && line == lineNumber) { return breakpoint; } } return null; }
@Nullable private static PsiElement findTargetElement(@NotNull Project project, @NotNull XSourcePosition position, @NotNull Editor editor, @NotNull String name) { PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null || !file.getVirtualFile().equals(position.getFile())) return null; ASTNode leafElement = file.getNode().findLeafElementAt(position.getOffset()); if (leafElement == null) return null; GoTopLevelDeclaration topLevel = PsiTreeUtil.getTopmostParentOfType(leafElement.getPsi(), GoTopLevelDeclaration.class); SyntaxTraverser<PsiElement> traverser = SyntaxTraverser.psiTraverser(topLevel) .filter(e -> e instanceof GoNamedElement && Comparing.equal(name, ((GoNamedElement)e).getName())); Iterator<PsiElement> iterator = traverser.iterator(); return iterator.hasNext() ? iterator.next() : null; }
@NotNull public VirtualFile getFile() { return mySourcePosition.getFile(); }
public int getLine() { return mySourcePosition.getLine(); }
/** * Called when the user clicks a pending breakpoint. We find the local IDE representation and * navigate to its line of code. */ public void navigateTo(@NotNull Breakpoint serverBreakpoint) { final XBreakpoint xIdeBreakpoint = ideBreakpoints.get(serverBreakpoint.getId()); if (xIdeBreakpoint != null && xIdeBreakpoint.getSourcePosition() != null && process.getXDebugSession() != null) { xIdeBreakpoint .getSourcePosition() .createNavigatable(process.getXDebugSession().getProject()) .navigate(true); } }
@Nullable private static Language getFileTypeLanguage( XLineBreakpoint<CloudLineBreakpointProperties> breakpoint) { if (breakpoint.getSourcePosition() != null) { FileType fileType = breakpoint.getSourcePosition().getFile().getFileType(); if (fileType instanceof LanguageFileType) { return ((LanguageFileType) fileType).getLanguage(); } } return null; }
@Override public void registerBreakpoint(@NotNull XLineBreakpoint<DlvBreakpointProperties> breakpoint) { XSourcePosition breakpointPosition = breakpoint.getSourcePosition(); if (breakpointPosition == null) return; VirtualFile file = breakpointPosition.getFile(); int line = breakpointPosition.getLine(); send(new DlvRequest.CreateBreakpoint(file.getPath(), line + 1)) .done(b -> { breakpoint.putUserData(ID, b.id); breakpoints.put(b.id, breakpoint); getSession().updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_verified_breakpoint, null); }) .rejected(t -> { String message = t == null ? null : t.getMessage(); getSession().updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, message); }); }
@Nullable public static PerlLineBreakPointDescriptor createFromSourcePosition(XSourcePosition position, PerlDebugThread debugThread) { VirtualFile virtualFile = position.getFile(); String virtualFilePath = virtualFile.getCanonicalPath(); if (virtualFilePath == null) { return null; } String filePath = debugThread.getDebugProfileState().mapPathToRemote(virtualFilePath); if (filePath == null) { return null; } PerlLineBreakPointDescriptor descriptor = new PerlLineBreakPointDescriptor(); descriptor.path = filePath; descriptor.line = position.getLine(); return descriptor; } }
component.append(function + "():" + (sourcePosition.getLine() + 1), SimpleTextAttributes.REGULAR_ATTRIBUTES); component.append(" (" + sourcePosition.getFile().getName() + ")", SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES); } else { sourcePosition.getFile().getName() + ":" + (sourcePosition.getLine() + 1), SimpleTextAttributes.REGULAR_ATTRIBUTES); } else {