Iterable<FoundItemDescriptor<PsiFileSystemItem>> (@NotNull MinusculeMatcher qualifierMatcher, JBIterable<? extends FoundItemDescriptor<PsiFileSystemItem>> iterable, @NotNull String completePattern) { List<FoundItemDescriptor<PsiFileSystemItem>> matching = new ArrayList<>(); for (FoundItemDescriptor<PsiFileSystemItem> descriptor : iterable) { PsiFileSystemItem item = descriptor.getItem(); ProgressManager.checkCanceled(); String qualifier = Objects.requireNonNull(getParentPath(item)); FList<TextRange> fragments = qualifierMatcher.matchingFragments(qualifier); if (fragments != null) { int gapPenalty = fragments.isEmpty() ? 0 : qualifier.length() - fragments.get(fragments.size() - 1).getEndOffset(); int exactMatchScore = isExactMatch(item, completePattern) ? EXACT_MATCH_DEGREE : 0; int qualifierDegree = qualifierMatcher.matchingDegree(qualifier, false, fragments) - gapPenalty + exactMatchScore; matching.add(new FoundItemDescriptor<>(item, qualifierDegree)); } else if (isExactMatch(item, completePattern)) { matching.add(new FoundItemDescriptor<>(item, EXACT_MATCH_DEGREE)); } } if (matching.size() > 1) { Comparator<FoundItemDescriptor<PsiFileSystemItem>> comparator = Comparator.comparing((FoundItemDescriptor<PsiFileSystemItem> res) -> res.getWeight()).reversed(); matching.sort(comparator); } return matching; }