use of com.perl5.lang.perl.extensions.packageprocessor.PerlPackageParentsProvider in project Perl5-IDEA by Camelcade.
the class PerlStringCompletionUtil method fillWithUseParameters.
public static void fillWithUseParameters(@NotNull final PsiElement stringContentElement, @NotNull final CompletionResultSet resultSet) {
@SuppressWarnings("unchecked") PsiPerlUseStatement useStatement = PsiTreeUtil.getParentOfType(stringContentElement, PsiPerlUseStatement.class, true, PsiPerlStatement.class);
if (useStatement == null) {
return;
}
List<String> typedParameters = useStatement.getImportParameters();
Set<String> typedStringsSet = typedParameters == null ? Collections.emptySet() : new THashSet<>(typedParameters);
PerlPackageProcessor packageProcessor = useStatement.getPackageProcessor();
// fixme we should allow lookup elements customization by package processor
if (packageProcessor instanceof PerlPackageOptionsProvider) {
Map<String, String> options = ((PerlPackageOptionsProvider) packageProcessor).getOptions();
for (Map.Entry<String, String> option : options.entrySet()) {
if (!typedStringsSet.contains(option.getKey())) {
resultSet.addElement(LookupElementBuilder.create(option.getKey()).withTypeText(option.getValue(), true).withIcon(PerlIcons.PERL_OPTION));
}
}
options = ((PerlPackageOptionsProvider) packageProcessor).getOptionsBundles();
for (Map.Entry<String, String> option : options.entrySet()) {
if (!typedStringsSet.contains(option.getKey())) {
resultSet.addElement(LookupElementBuilder.create(option.getKey()).withTypeText(option.getValue(), true).withIcon(PerlIcons.PERL_OPTIONS));
}
}
}
if (packageProcessor instanceof PerlPackageParentsProvider && ((PerlPackageParentsProvider) packageProcessor).hasPackageFilesOptions()) {
PerlPackageUtil.processPackageFilesForPsiElement(stringContentElement, s -> {
if (!typedStringsSet.contains(s)) {
resultSet.addElement(PerlPackageCompletionUtil.getPackageLookupElement(s, null));
}
return true;
});
}
Set<String> export = new HashSet<>();
Set<String> exportOk = new HashSet<>();
packageProcessor.addExports(useStatement, export, exportOk);
exportOk.removeAll(export);
for (String subName : export) {
if (!typedStringsSet.contains(subName)) {
resultSet.addElement(LookupElementBuilder.create(subName).withIcon(PerlIcons.SUB_GUTTER_ICON).withTypeText("default", true));
}
}
for (String subName : exportOk) {
if (!typedStringsSet.contains(subName)) {
resultSet.addElement(LookupElementBuilder.create(subName).withIcon(PerlIcons.SUB_GUTTER_ICON).withTypeText("optional", true));
}
}
}
Aggregations