VirtualFile (@NotNull VirtualFile resource) { String rootPath = ScratchFileService.getInstance().getRootPath(this); VirtualFile root = LocalFileSystem.getInstance().findFileByPath(rootPath); if (root == null) { return null; } VirtualFile parent = resource; VirtualFile file = resource; while (parent != null && !root.equals(parent)) { file = parent; parent = file.getParent(); } return parent != null && file.isDirectory() ? file : null; }