use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PerlPackageCompletionUtil method fillWithNamespaceNameSuggestions.
public static void fillWithNamespaceNameSuggestions(@NotNull PerlCompletionProcessor completionProcessor) {
PsiFile originalFile = completionProcessor.getOriginalFile();
VirtualFile virtualFile = originalFile.getViewProvider().getVirtualFile();
if (virtualFile.getFileType() != PerlFileTypePackage.INSTANCE) {
return;
}
completionProcessor.processSingle(LookupElementBuilder.create(virtualFile, virtualFile.getNameWithoutExtension()));
if (!(originalFile instanceof PerlFileImpl)) {
return;
}
String packageName = ((PerlFileImpl) originalFile).getFilePackageName();
if (packageName != null) {
completionProcessor.processSingle(LookupElementBuilder.create(originalFile, packageName));
}
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PerlPackageCompletionUtil method processFirstNamespaceForEachName.
/**
* Iterates all namespaces in {@code project} and {@code searchScope}, and processes the first element with each name with
* {@code namespaceProcessor}
*/
public static boolean processFirstNamespaceForEachName(@NotNull PerlCompletionProcessor completionProcessor, @NotNull Project project, @NotNull GlobalSearchScope searchScope, @NotNull Processor<PerlNamespaceDefinitionElement> namespaceProcessor) {
PerlTimeLogger logger = PerlTimeLogger.create(LOG);
Collection<String> names = PerlPackageUtil.getKnownNamespaceNames(searchScope);
logger.debug("Collected all namespaces names: ", names.size());
for (String packageName : names) {
if (!completionProcessor.matches(packageName)) {
continue;
}
PerlPackageUtil.processNamespaces(packageName, project, searchScope, namespace -> {
String name = namespace.getNamespaceName();
if (StringUtil.isNotEmpty(name)) {
char firstChar = name.charAt(0);
if (firstChar == '_' || Character.isLetterOrDigit(firstChar)) {
namespaceProcessor.process(namespace);
completionProcessor.register(namespace.getNamespaceName());
return false;
}
}
return false;
});
if (!completionProcessor.result()) {
LOG.debug("Processor is full");
return false;
}
}
logger.debug("Collected namespaces from indexes");
return completionProcessor.result();
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PerlStringCompletionUtil method fillWithHeredocOpeners.
public static void fillWithHeredocOpeners(@NotNull PerlCompletionProcessor completionProcessor) {
Project project = completionProcessor.getProject();
Set<String> heredocOpenersCache = PerlStringCompletionCache.getInstance(project).getHeredocOpenersCache();
// cached values
for (String marker : heredocOpenersCache) {
if (completionProcessor.matches(marker) && !completionProcessor.process(LookupElementBuilder.create(marker))) {
return;
}
}
PerlInjectionMarkersService injectionService = PerlInjectionMarkersService.getInstance(project);
// collect new values
PsiFile file = completionProcessor.getContainingFile();
file.accept(new PerlCompletionRecursiveVisitor(completionProcessor) {
@Override
public void visitHeredocOpener(@NotNull PsiPerlHeredocOpener o) {
String openerName = o.getName();
if (StringUtil.isNotEmpty(openerName) && heredocOpenersCache.add(openerName) && injectionService.getLanguageByMarker(openerName) == null && !completionProcessor.process(LookupElementBuilder.create(o, openerName))) {
return;
}
super.visitHeredocOpener(o);
}
});
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PerlSubNameElementCompletionProvider method addCompletions.
@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet) {
PsiElement element = parameters.getPosition();
if (!(element.getParent() instanceof PerlSubElement)) {
return;
}
PerlCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, resultSet, element);
PerlTimeLogger logger = PerlTimeLogger.create(LOG);
PerlSubElement subDefinitionBase = (PerlSubElement) element.getParent();
PerlSubCompletionUtil.processUnresolvedSubsLookups(subDefinitionBase, completionProcessor);
logger.debug("Processed unresolved subs");
PerlSubCompletionUtil.processWithNotOverriddenSubs(subDefinitionBase, completionProcessor);
logger.debug("Processed not overriden subs");
completionProcessor.logStatus(getClass());
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor in project Perl5-IDEA by Camelcade.
the class PodLinkCompletionProvider method processFilesCompletions.
protected boolean processFilesCompletions(@NotNull PerlCompletionProcessor completionProcessor) {
PodFormatterL linkElement = (PodFormatterL) completionProcessor.getLeafElement();
final Set<String> foundPods = new HashSet<>();
PerlPackageUtil.processIncFilesForPsiElement(linkElement, (file, classRoot) -> {
String className = PodFileUtil.getPackageNameFromVirtualFile(file, classRoot);
if (StringUtil.isNotEmpty(className)) {
boolean isBuiltIn = false;
if (StringUtil.startsWith(className, "pod::")) {
isBuiltIn = true;
className = className.substring(5);
}
if (completionProcessor.matches(className) && foundPods.add(className)) {
if (!completionProcessor.process(LookupElementBuilder.create(file, className).withIcon(PerlIcons.POD_FILE).withBoldness(isBuiltIn))) {
return false;
}
}
}
return completionProcessor.result();
}, PodFileType.INSTANCE);
return PerlPackageUtil.processPackageFilesForPsiElement(linkElement, (packageName, file) -> {
if (StringUtil.isNotEmpty(packageName) && completionProcessor.matches(packageName) && foundPods.add(packageName)) {
return PerlPackageCompletionUtil.processPackageLookupElement(file, packageName, null, completionProcessor, false);
}
return completionProcessor.result();
});
}
Aggregations