Comparator<PsiElement> (@NotNull Comparator<? super PsiElement> comparator) { return (o1, o2) -> { int diff = comparator.compare(o1, o2); if (diff == 0) { return ReadAction.compute(() -> PsiUtilCore.compareElementsByPosition(o1, o2)); } return diff; }; }