List<CompletionItem> (@NotNull PsiDirectory directory) { List<CompletionItem> variants = new ArrayList<>(); VirtualFile vDir = directory.getVirtualFile(); for (CreateDirectoryCompletionContributor contributor : EP.getExtensionList()) { for (CreateDirectoryCompletionContributor.Variant variant : contributor.getVariants(directory)) { String relativePath = FileUtil.toSystemIndependentName(variant.path); if (FileUtil.isAbsolutePlatformIndependent(relativePath)) { // only suggest sub-folders if (!FileUtil.isAncestor(vDir.getPath(), relativePath, true)) continue; // convert absolute paths to the relative paths relativePath = FileUtil.getRelativePath(vDir.getPath(), relativePath, '/'); if (relativePath == null) continue; } // only suggested non-existent folders if (vDir.findFileByRelativePath(relativePath) != null) continue; ModuleSourceRootEditHandler<?> handler = variant.rootType != null ? ModuleSourceRootEditHandler.getEditHandler(variant.rootType) : null; Icon icon = handler == null ? null : handler.getRootIcon(); if (icon == null) icon = AllIcons.Nodes.Folder; CompletionItem completionItem = new CompletionItem(contributor, relativePath, icon, variant.rootType); if (!variants.contains(completionItem)) { variants.add(completionItem); } } } variants.sort((o1, o2) -> { int result = StringUtil.naturalCompare(o1.contributor.getDescription(), o2.contributor.getDescription()); if (result != 0) return result; return StringUtil.naturalCompare(o1.relativePath, o2.relativePath); }); return variants; }