PyFile (@NotNull Project project, @NotNull VirtualFile virtualFile) { VirtualFile targetFile = Arrays.stream(FileEditorManager.getInstance(project).getAllEditors(virtualFile)) .map(editor -> editor.getFile()) .filter(file -> file instanceof BackedVirtualFile) .findFirst() .orElse(virtualFile); return (PyFile)ContainerUtil.find( Objects.requireNonNull(PsiManager.getInstance(project).findFile(targetFile)) .getViewProvider() .getAllFiles(), file -> file instanceof PyFile); }