List<PsiNamedElement> (@NotNull PsiElement anchor) { final List<PsiNamedElement> results = new ArrayList<>(); for (ScopeOwner owner = ScopeUtil.getScopeOwner(anchor); owner != null; owner = ScopeUtil.getScopeOwner(owner)) { final Scope scope = ControlFlowCache.getScope(owner); results.addAll(scope.getNamedElements()); StreamEx .of(scope.getImportedNameDefiners()) .filter(definer -> !(definer instanceof PyImplicitImportNameDefiner)) .flatMap(definer -> StreamSupport.stream(definer.iterateNames().spliterator(), false)) .select(PsiNamedElement.class) .forEach(results::add); } return results; }