List<PsiElement> (@NotNull PsiElement element, @NotNull PsiFile file) { PsiElement selectionElement = getOriginalSelectionCoveringElement(element); TextRange textRange = getTextRangeForOperationElement(element); return StreamEx.of(PsiTreeUtil.collectElementsOfType(selectionElement, PyReferenceExpression.class)) .filter(it -> textRange.contains(it.getTextRange())) .filter(ref -> !ref.isQualified()) .flatMap(expr -> PyResolveUtil.resolveLocally(expr).stream()) .filter(it -> it != null && it.getContainingFile() == file) .toList(); }