void (@NotNull Collection<? extends VFileCreateEvent> createEvents, @NotNull NewVirtualFileSystem fs, boolean isCaseSensitive) { for (VFileCreateEvent createEvent : createEvents) { ChildInfo[] children = createEvent.getChildren(); if (children == null || !createEvent.isDirectory()) continue; // todo avoid expensive findFile VirtualFile createdDir = createEvent.getFile(); if (createdDir instanceof VirtualDirectoryImpl) { Queue<Pair<VirtualDirectoryImpl, ChildInfo[]>> queue = new ArrayDeque<>(); queue.add(new Pair<>((VirtualDirectoryImpl)createdDir, children)); while (!queue.isEmpty()) { Pair<VirtualDirectoryImpl, ChildInfo[]> queued = queue.remove(); VirtualDirectoryImpl directory = queued.first; List<ChildInfo> scannedChildren = Arrays.asList(queued.second); int directoryId = directory.getId(); List<ChildInfo> added = new ArrayList<>(scannedChildren.size()); for (ChildInfo childInfo : scannedChildren) { CharSequence childName = childInfo.getName(); Pair<@NotNull FileAttributes, String> childData = getChildData(fs, directory, childName.toString(), childInfo.getFileAttributes(), childInfo.getSymlinkTarget()); if (childData != null) { added.add(makeChildRecord(directory, directoryId, childName, childData, fs, childInfo.getChildren())); } } added.sort(ChildInfo.BY_ID); vfsPeer.update(directory, directoryId, oldChildren -> oldChildren.merge(vfsPeer, added, isCaseSensitive)); setChildrenCached(directoryId); // set "all children loaded" because the first "fileCreated" listener (looking at you, local history) // will call getChildren() anyway, beyond a shadow of a doubt directory.createAndAddChildren(added, true, (childCreated, childInfo) -> { // enqueue recursive children if (childCreated instanceof VirtualDirectoryImpl && childInfo.getChildren() != null) { queue.add(new Pair<>((VirtualDirectoryImpl)childCreated, childInfo.getChildren())); } }); } } } }