public static SourcePosition findNearest(@NotNull DebuggerContextImpl context, @NotNull PsiFile file, Function<PsiElement, Collection<TextRange>> findUsages) {
    final DebuggerSession session = context.getDebuggerSession();
    if (session == null) return null;

    try {
      final XDebugSession debugSession = session.getXDebugSession();
      if (debugSession == null) return null;

      final XSourcePosition position = debugSession.getCurrentPosition();
      Editor editor = ((FileEditorManagerImpl)FileEditorManager.getInstance(file.getProject())).getSelectedTextEditor(true);
      if (editor == null || position == null || !position.getFile().equals(file.getOriginalFile().getVirtualFile())) return null;

      PsiMethod method = PsiTreeUtil.getParentOfType(PositionUtil.getContextElement(context), PsiMethod.class, false);
      PsiElement searchScope = method != null ? method : file;
      final Collection<TextRange> ranges = findUsages.apply(searchScope);
      final int breakPointLine = position.getLine();
      int bestLine = -1;
      int bestOffset = -1;
      int textOffset = method != null ? method.getTextOffset() : -1;
      for (TextRange range : ranges) {
        // skip comments
        if (range.getEndOffset() < textOffset) {
          continue;
        }
        final int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
        if (line > bestLine && line < breakPointLine) {
          bestLine = line;
          bestOffset = range.getStartOffset();
        }
        else if (line == breakPointLine) {
          bestOffset = range.getStartOffset();
          break;
        }
      }
      if (bestOffset > -1) {
        return SourcePosition.createFromOffset(file, bestOffset);
      }
    }
    catch (Exception ignore) {
    }
    return null;
  }
public static SourcePosition findNearest(@NotNull DebuggerContextImpl context, @NotNull PsiFile file, Function<PsiElement, Collection<TextRange>> findUsages)