Search in sources :

Example 1 with PerlSimpleCompletionProcessor

use of com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor in project Perl5-IDEA by Camelcade.

the class PerlAnnotationCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, resultSet, parameters.getPosition());
    for (String annotation : TOKENS_MAP.keySet()) {
        if (completionProcessor.matches(annotation)) {
            if (!completionProcessor.process(LookupElementBuilder.create(TOKENS_MAP.get(annotation), annotation).withInsertHandler(PerlAnnotationInsertHandler.INSTANCE).withIcon(PerlIcons.ANNOTATION_GUTTER_ICON))) {
                break;
            }
        }
    }
    completionProcessor.logStatus(getClass());
}
Also used : PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor)

Example 2 with PerlSimpleCompletionProcessor

use of com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor in project Perl5-IDEA by Camelcade.

the class PerlPackageSubCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement method = parameters.getPosition().getParent();
    if (!(method instanceof PsiPerlMethod)) {
        LOG.warn("Expected PsiPerlMethod, got psiElement=[" + method.getClass() + "]; text=[" + method.getText() + "]");
        return;
    }
    String explicitNamespace = ((PsiPerlMethod) method).getExplicitNamespaceName();
    String currentPrefixMatcher = result.getPrefixMatcher().getPrefix();
    String newPrefixMathcer = explicitNamespace == null ? currentPrefixMatcher : PerlPackageUtil.join(explicitNamespace, currentPrefixMatcher);
    result = result.withPrefixMatcher(newPrefixMathcer);
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, parameters.getPosition());
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    if (!((PsiPerlMethod) method).isObjectMethod()) {
        PerlPackageCompletionUtil.processAllNamespacesNames(completionProcessor, false, false);
        logger.debug("Processed all namespace names");
    } else {
        if (!StringUtil.equals(PerlPackageUtil.SUPER_NAMESPACE_FULL, newPrefixMathcer)) {
            PerlPackageCompletionUtil.processPackageLookupElementWithAutocomplete(null, PerlPackageUtil.SUPER_NAMESPACE_FULL, null, completionProcessor);
            logger.debug("Processed all package lookups with autocomplete");
        }
    }
    completionProcessor.logStatus(getClass());
}
Also used : PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PerlSimpleCompletionProcessor

use of com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor in project Perl5-IDEA by Camelcade.

the class PerlStringContentCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull final CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    PsiElement parent = element.getParent();
    if (parent instanceof PsiLanguageInjectionHost && PerlInjectionUtil.hasInjections(parent)) {
        return;
    }
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, element);
    if (EXPORT_ASSIGNED_STRING_CONTENT.accepts(element)) {
        // exporter assignments
        PerlStringCompletionUtil.fillWithExportableEntities(completionProcessor);
        logger.debug("Filled with exportable entities");
    } else if (SIMPLE_HASH_INDEX.accepts(element)) {
        // hash indexes
        PsiPerlHashIndex indexElement = PsiTreeUtil.getParentOfType(element, PsiPerlHashIndex.class);
        if (indexElement != null && indexElement.getParent() instanceof PsiPerlGlobSlot) {
            PerlStringCompletionUtil.fillWithRefTypes(completionProcessor);
            logger.debug("Filled with ref types");
        } else {
            PerlStringCompletionUtil.fillWithHashIndexes(completionProcessor);
            logger.debug("Filled with hash indexes");
            PerlVariableCompletionUtil.processVariables(new PerlVariableCompletionProcessorImpl(completionProcessor, null, false, false, false), logger);
            PerlSubCompletionUtil.processContextSubsLookupElements(completionProcessor);
            logger.debug("Filled with context subs lookup elements");
            PerlPackageCompletionUtil.processAllNamespacesNames(completionProcessor, false, false);
            logger.debug("Filled with namespace names");
        }
    } else if (USE_PARAMETERS_PATTERN.accepts(element)) {
        // use or no parameters
        PerlStringCompletionUtil.fillWithUseParameters(completionProcessor);
        logger.debug("Filled with use parameters");
    } else if (parent != null && parent.getParent() instanceof PsiPerlAnnotationInject) {
        // #@Inject some
        PerlStringCompletionUtil.fillWithInjectableMarkers(completionProcessor);
        result.stopHere();
        logger.debug("Filled with injectable markers");
    } else if (STRING_CONTENT_IN_HEREDOC_OPENER_PATTERN.accepts(element)) {
        // HERE-DOC openers
        PerlStringCompletionUtil.fillWithInjectableMarkers(completionProcessor);
        logger.debug("Filled with injectable markers in opener");
        PerlStringCompletionUtil.fillWithHeredocOpeners(completionProcessor);
        logger.debug("Filled with heredoc openers");
    } else if (STRING_CONTENT_IN_LIST_OR_STRING_START.accepts(element)) {
        // begin of string or qw element
        PerlStringCompletionUtil.fillWithRefTypes(completionProcessor);
        logger.debug("Filled with ref types");
        PerlPackageCompletionUtil.processAllNamespacesNames(completionProcessor);
        logger.debug("Processed namespace names");
    }
    completionProcessor.logStatus(getClass());
}
Also used : PerlVariableCompletionProcessorImpl(com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) PsiPerlGlobSlot(com.perl5.lang.perl.psi.PsiPerlGlobSlot) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PsiPerlHashIndex(com.perl5.lang.perl.psi.PsiPerlHashIndex) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiPerlAnnotationInject(com.perl5.lang.perl.psi.PsiPerlAnnotationInject) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PerlSimpleCompletionProcessor

use of com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor in project Perl5-IDEA by Camelcade.

the class PodLinkCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    PsiElement linkPart = element.getParent();
    PodFormatterL linkElement = PsiTreeUtil.getParentOfType(element, PodFormatterL.class);
    if (linkElement == null) {
        return;
    }
    IElementType parentType = PsiUtilCore.getElementType(linkPart);
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, linkElement);
    if (parentType == LINK_TEXT && element.getPrevSibling() == null) {
        processFilesCompletions(completionProcessor);
    }
    if (parentType == LINK_NAME) {
        processFilesCompletions(completionProcessor);
    }
    if (parentType == LINK_SECTION) {
        addSectionsCompletions(linkElement.getTargetFile(), completionProcessor);
    }
    completionProcessor.logStatus(getClass());
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PodFormatterL(com.perl5.lang.pod.parser.psi.mixin.PodFormatterL) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 5 with PerlSimpleCompletionProcessor

use of com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor in project Perl5-IDEA by Camelcade.

the class PerlHandleCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement position = parameters.getPosition();
    if (!isApplicable(position)) {
        return;
    }
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, position);
    PerlPackageCompletionUtil.processAllNamespacesNames(completionProcessor, false, false);
    logger.debug("Processed namespace names");
    PerlSubCompletionUtil.processContextSubsLookupElements(completionProcessor);
    logger.debug("Processed context subs lookups");
    if (Experiments.getInstance().isFeatureEnabled("perl5.completion.var.without.sigil")) {
        PerlVariableCompletionProcessor variableCompletionProcessor = new PerlVariableCompletionProcessorImpl(completionProcessor, null, false, false, false);
        PerlVariableCompletionUtil.processVariables(variableCompletionProcessor, logger);
    }
    completionProcessor.logStatus(getClass());
}
Also used : PerlVariableCompletionProcessorImpl(com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl) PerlVariableCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessor) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PerlSimpleCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor)11 PsiElement (com.intellij.psi.PsiElement)9 PerlTimeLogger (com.perl5.lang.perl.util.PerlTimeLogger)8 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 IElementType (com.intellij.psi.tree.IElementType)2 ProcessingContext (com.intellij.util.ProcessingContext)2 PerlVariableCompletionProcessorImpl (com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl)2 PerlSubElement (com.perl5.lang.perl.psi.PerlSubElement)2 PsiPerlMethod (com.perl5.lang.perl.psi.PsiPerlMethod)2 PerlPsiUtil (com.perl5.lang.perl.psi.utils.PerlPsiUtil)2 NotNull (org.jetbrains.annotations.NotNull)2 CompletionProvider (com.intellij.codeInsight.completion.CompletionProvider)1 PsiFile (com.intellij.psi.PsiFile)1 PsiLanguageInjectionHost (com.intellij.psi.PsiLanguageInjectionHost)1 ResolveResult (com.intellij.psi.ResolveResult)1 PsiUtilCore (com.intellij.psi.util.PsiUtilCore)1 PerlElementPatterns (com.perl5.lang.perl.idea.PerlElementPatterns)1