use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PerlPackageCompletionUtil method processAllNamespacesNames.
public static boolean processAllNamespacesNames(@NotNull PerlCompletionProcessor completionProcessor, boolean appendNamespaceSeparator, boolean addPackageTag) {
PsiElement element = completionProcessor.getLeafElement();
final Project project = element.getProject();
Processor<PerlNamespaceDefinitionElement> namespaceProcessor = namespace -> processNamespaceLookupElement(namespace, completionProcessor, appendNamespaceSeparator);
PerlBuiltInNamespacesService.getInstance(project).processNamespaces(namespaceProcessor);
if (addPackageTag && !PerlPackageCompletionUtil.processPackageLookupElement(null, __PACKAGE__, PACKAGE_GUTTER_ICON, completionProcessor, false)) {
return false;
}
return processFirstNamespaceForEachName(completionProcessor, project, element.getResolveScope(), namespaceProcessor);
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PerlStringCompletionUtil method fillWithHashIndexes.
public static void fillWithHashIndexes(@NotNull PerlCompletionProcessor completionProcessor) {
Set<String> hashIndexesCache = PerlStringCompletionCache.getInstance(completionProcessor.getProject()).getHashIndexesCache();
for (String text : hashIndexesCache) {
if (completionProcessor.matches(text) && !completionProcessor.process(LookupElementBuilder.create(text))) {
return;
}
}
PsiElement element = completionProcessor.getLeafElement();
PsiFile file = completionProcessor.getContainingFile();
file.accept(new PerlCompletionRecursiveVisitor(completionProcessor) {
@Override
public void visitStringContentElement(@NotNull PerlStringContentElementImpl o) {
if (o != element && SIMPLE_HASH_INDEX.accepts(o)) {
processStringElement(o);
}
super.visitStringContentElement(o);
}
@Override
public void visitCommaSequenceExpr(@NotNull PsiPerlCommaSequenceExpr o) {
if (o.getParent() instanceof PsiPerlAnonHash) {
PsiElement sequenceElement = o.getFirstChild();
boolean isKey = true;
while (sequenceElement != null) {
ProgressManager.checkCanceled();
IElementType elementType = sequenceElement.getNode().getElementType();
if (isKey && sequenceElement instanceof PerlString) {
for (PerlStringContentElement stringElement : PerlPsiUtil.collectStringElements(sequenceElement)) {
processStringElement(stringElement);
}
} else if (elementType == COMMA || elementType == FAT_COMMA) {
isKey = !isKey;
}
sequenceElement = PerlPsiUtil.getNextSignificantSibling(sequenceElement);
}
}
super.visitCommaSequenceExpr(o);
}
protected void processStringElement(PerlStringContentElement stringContentElement) {
String text = stringContentElement.getText();
if (StringUtil.isNotEmpty(text) && hashIndexesCache.add(text) && completionProcessor.matches(text) && isIdentifier(text)) {
completionProcessor.process(LookupElementBuilder.create(stringContentElement, text));
}
}
});
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PerlStringCompletionUtil method fillWithInjectableMarkers.
public static void fillWithInjectableMarkers(@NotNull PerlCompletionProcessor completionProcessor) {
// injectable markers
PerlInjectionMarkersService injectionService = PerlInjectionMarkersService.getInstance(completionProcessor.getProject());
for (String marker : injectionService.getSupportedMarkers()) {
if (!completionProcessor.matches(marker)) {
continue;
}
Language language = injectionService.getLanguageByMarker(marker);
if (language == null) {
continue;
}
LookupElementBuilder newItem = LookupElementBuilder.create(marker).withTypeText("inject with " + language.getDisplayName(), true);
if (language.getAssociatedFileType() != null) {
newItem = newItem.withIcon(language.getAssociatedFileType().getIcon());
}
if (!completionProcessor.process(newItem)) {
return;
}
}
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PerlStringCompletionUtil method fillWithUseParameters.
public static void fillWithUseParameters(@NotNull PerlCompletionProcessor completionProcessor) {
PsiElement baseElement = completionProcessor.getLeafElement();
PerlUseStatementElement useStatement = PsiTreeUtil.getParentOfType(baseElement, PerlUseStatementElement.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()) {
String lookupString = option.getKey();
if (!typedStringsSet.contains(lookupString) && completionProcessor.matches(lookupString) && !completionProcessor.process(LookupElementBuilder.create(lookupString).withTypeText(option.getValue(), true).withIcon(PerlIcons.PERL_OPTION))) {
return;
}
}
options = ((PerlPackageOptionsProvider) packageProcessor).getOptionsBundles();
for (Map.Entry<String, String> option : options.entrySet()) {
String lookupString = option.getKey();
if (!typedStringsSet.contains(lookupString) && completionProcessor.matches(lookupString) && !completionProcessor.process(LookupElementBuilder.create(lookupString).withTypeText(option.getValue(), true).withIcon(PerlIcons.PERL_OPTIONS))) {
return;
}
}
}
if (packageProcessor instanceof PerlPackageParentsProvider && ((PerlPackageParentsProvider) packageProcessor).hasPackageFilesOptions() && !PerlPackageUtil.processPackageFilesForPsiElement(baseElement, (packageName, file) -> typedStringsSet.contains(packageName) || PerlPackageCompletionUtil.processPackageLookupElement(file, packageName, null, completionProcessor, false))) {
return;
}
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) && completionProcessor.matches(subName) && !completionProcessor.process(LookupElementBuilder.create(subName).withIcon(PerlIcons.SUB_GUTTER_ICON).withTypeText("default", true))) {
return;
}
}
for (String subName : exportOk) {
if (!typedStringsSet.contains(subName) && completionProcessor.matches(subName) && !completionProcessor.process(LookupElementBuilder.create(subName).withIcon(PerlIcons.SUB_GUTTER_ICON).withTypeText("optional", true))) {
return;
}
}
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PodLinkCompletionProvider method addSectionsCompletions.
protected static void addSectionsCompletions(@Nullable PsiFile targetFile, @NotNull PerlCompletionProcessor completionProcessor) {
if (targetFile == null) {
return;
}
Set<String> distinctString = new HashSet<>();
targetFile.accept(new PodStubsAwareRecursiveVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
if (completionProcessor.result()) {
super.visitElement(element);
}
}
@Override
public void visitTargetableSection(PodTitledSection o) {
String title = cleanItemText(o.getTitleText());
if (completionProcessor.matches(title) && distinctString.add(title)) {
completionProcessor.process(LookupElementBuilder.create(o, escapeTitle(title)).withLookupString(title).withPresentableText(title).withIcon(PerlIcons.POD_FILE).withTypeText(UsageViewUtil.getType(o)));
}
super.visitTargetableSection(o);
}
@Override
public void visitItemSection(@NotNull PsiItemSection o) {
if (((PodSectionItem) o).isTargetable()) {
super.visitItemSection(o);
} else {
visitElement(o);
}
}
@Contract("null->null")
@Nullable
private String cleanItemText(@Nullable String itemText) {
if (itemText == null) {
return null;
}
String trimmed = StringUtil.trimLeading(itemText.trim(), '*');
if (NumberUtils.isNumber(trimmed)) {
return null;
}
return trimItemText(trimmed);
}
@Override
public void visitPodFormatIndex(@NotNull PsiPodFormatIndex o) {
assert o instanceof PodFormatterX;
if (!((PodFormatterX) o).isMeaningful()) {
return;
}
String indexTitle = ((PodFormatterX) o).getTitleText();
if (StringUtil.isEmpty(indexTitle) || !distinctString.add(indexTitle)) {
return;
}
String escapedIndexTitle = escapeTitle(indexTitle);
if (!completionProcessor.matches(indexTitle) && !completionProcessor.matches(escapedIndexTitle)) {
return;
}
PsiElement indexTarget = ((PodFormatterX) o).getIndexTarget();
String targetPresentableText;
if (indexTarget instanceof PodFile) {
targetPresentableText = cleanItemText(((PodFile) indexTarget).getPodLinkText());
} else if (indexTarget instanceof PodCompositeElement) {
targetPresentableText = cleanItemText(((PodCompositeElement) indexTarget).getPresentableText());
} else {
LOG.warn("Unhandled index target: " + indexTarget);
return;
}
String tailText = null;
if (targetPresentableText != null) {
tailText = "(" + targetPresentableText + ")";
}
completionProcessor.process(LookupElementBuilder.create(o, escapedIndexTitle).withLookupString(indexTitle).withPresentableText(indexTitle).withTailText(tailText).withTypeText(UsageViewUtil.getType(o)).withIcon(PerlIcons.POD_FILE));
}
});
}
Aggregations