Search in sources :

Example 6 with PerlCompletionProcessor

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));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PerlFileImpl(com.perl5.lang.perl.psi.impl.PerlFileImpl) PsiFile(com.intellij.psi.PsiFile)

Example 7 with PerlCompletionProcessor

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();
}
Also used : PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger)

Example 8 with PerlCompletionProcessor

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);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) PerlInjectionMarkersService(com.perl5.lang.perl.idea.intellilang.PerlInjectionMarkersService) PsiFile(com.intellij.psi.PsiFile)

Example 9 with PerlCompletionProcessor

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());
}
Also used : PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PerlCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 10 with PerlCompletionProcessor

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();
    });
}
Also used : PodFormatterL(com.perl5.lang.pod.parser.psi.mixin.PodFormatterL)

Aggregations

PsiElement (com.intellij.psi.PsiElement)5 PsiFile (com.intellij.psi.PsiFile)4 PerlTimeLogger (com.perl5.lang.perl.util.PerlTimeLogger)3 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PerlCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor)2 PerlInjectionMarkersService (com.perl5.lang.perl.idea.intellilang.PerlInjectionMarkersService)2 PerlFileImpl (com.perl5.lang.perl.psi.impl.PerlFileImpl)2 Nullable (org.jetbrains.annotations.Nullable)2 AutoPopupController (com.intellij.codeInsight.AutoPopupController)1 InsertHandler (com.intellij.codeInsight.completion.InsertHandler)1 Lookup (com.intellij.codeInsight.lookup.Lookup)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 Language (com.intellij.lang.Language)1 Logger (com.intellij.openapi.diagnostic.Logger)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 IElementType (com.intellij.psi.tree.IElementType)1 ObjectUtils (com.intellij.util.ObjectUtils)1