List<PyFunction> (@NotNull PsiElement elementAt, @NotNull Predicate<PyFunction> extraCondition) { final StreamEx<PyFunction> definitions; final PyFunction immediateDefinition = findFunctionDefinitionUnderCaret(elementAt); if (immediateDefinition != null) { definitions = StreamEx.of(immediateDefinition); } else { definitions = StreamEx.of(getCallExpressions(elementAt)) .flatMap(call -> StreamEx.of(call.multiResolveCallee(getResolveContext(elementAt)))) .map(result -> result.getCallable()) .select(PyFunction.class); } final ProjectFileIndex index = ProjectFileIndex.getInstance(elementAt.getProject()); return definitions .filter(elem -> { VirtualFile dir = elem.getContainingFile().getOriginalFile().getVirtualFile(); return dir != null && !index.isInLibraryClasses(dir); }) .filter(extraCondition) .toList(); }