SourcePosition (@NotNull DebuggerContextImpl context, @NotNull PsiElement psi, @NotNull PsiFile file) { if (psi instanceof PsiCompiledElement) { // it makes no sense to compute text range of compiled element return null; } final DebuggerSession session = context.getDebuggerSession(); if (session != null) { try { final XDebugSession debugSession = session.getXDebugSession(); if (debugSession != null) { final XSourcePosition position = debugSession.getCurrentPosition(); Editor editor = ((FileEditorManagerImpl)FileEditorManager.getInstance(file.getProject())).getSelectedTextEditor(true); //final Editor editor = fileEditor instanceof TextEditorImpl ? ((TextEditorImpl)fileEditor).getEditor() : null; if (editor != null && position != null && position.getFile().equals(file.getOriginalFile().getVirtualFile())) { PsiMethod method = PsiTreeUtil.getParentOfType(PositionUtil.getContextElement(context), PsiMethod.class, false); final Collection<TextRange> ranges = IdentifierHighlighterPass.getUsages(psi, method != null ? method : file, false); 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; }