Search in sources :

Example 6 with PerlSimpleCompletionProcessor

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

the class PerlLabelCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull final CompletionResultSet result) {
    final PsiElement element = parameters.getOriginalPosition();
    if (element == null) {
        return;
    }
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, element);
    if (LABEL_DECLARATION_PATTERN.accepts(element)) {
    // unresolved labels should be here
    } else if (LABEL_IN_GOTO_PATTERN.accepts(element)) {
        PerlPsiUtil.processGotoLabelDeclarations(element, perlLabelDeclaration -> {
            if (perlLabelDeclaration != null) {
                String labelName = perlLabelDeclaration.getName();
                if (StringUtil.isNotEmpty(labelName) && completionProcessor.matches(labelName)) {
                    return completionProcessor.process(LookupElementBuilder.create(perlLabelDeclaration, labelName));
                }
            }
            return completionProcessor.result();
        });
        logger.debug("Processed goto label declarations");
    } else if (LABEL_IN_NEXT_LAST_REDO_PATTERN.accepts(element)) {
        PerlPsiUtil.processNextRedoLastLabelDeclarations(element, perlLabelDeclaration -> {
            if (perlLabelDeclaration != null) {
                String labelName = perlLabelDeclaration.getName();
                if (StringUtil.isNotEmpty(labelName) && completionProcessor.matches(labelName)) {
                    return completionProcessor.process(LookupElementBuilder.create(perlLabelDeclaration, labelName));
                }
            }
            return completionProcessor.result();
        });
        logger.debug("Processed next redo label declarations");
    }
    completionProcessor.logStatus(getClass());
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) StringUtil(com.intellij.openapi.util.text.StringUtil) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) PsiElement(com.intellij.psi.PsiElement) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PerlPsiUtil(com.perl5.lang.perl.psi.utils.PerlPsiUtil) PerlElementPatterns(com.perl5.lang.perl.idea.PerlElementPatterns) NotNull(org.jetbrains.annotations.NotNull) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PerlSimpleCompletionProcessor

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

the class PerlPackageCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, element);
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    if (NAMESPACE_IN_DEFINITION_PATTERN.accepts(element)) {
        // package Foo
        PerlPackageCompletionUtil.fillWithNamespaceNameSuggestions(completionProcessor);
        logger.debug("Filled with NS suggestions");
    } else if (NAMESPACE_IN_VARIABLE_DECLARATION_PATTERN.accepts(element)) {
        // my Foo::Bar
        PerlPackageCompletionUtil.processAllNamespacesNames(completionProcessor);
        logger.debug("Processed all namespace names");
    } else if (NAMESPACE_IN_ANNOTATION_PATTERN.accepts(element)) {
        // #@returns / #@type
        completionProcessor.processSingle(LookupElementBuilder.create("ArrayRef").withInsertHandler(PerlInsertHandlers.ARRAY_ELEMENT_INSERT_HANDLER).withTailText("[]"));
        completionProcessor.processSingle(LookupElementBuilder.create("HashRef").withInsertHandler(PerlInsertHandlers.ARRAY_ELEMENT_INSERT_HANDLER).withTailText("[]"));
        PerlPackageCompletionUtil.processAllNamespacesNames(completionProcessor);
        logger.debug("Processed all namespace names");
    } else if (NAMESPACE_IN_USE_PATTERN.accepts(element)) {
        // use/no/require
        PerlPackageCompletionUtil.fillWithVersionNumbers(completionProcessor);
        logger.debug("Processed all version numbers");
        PerlPackageCompletionUtil.fillWithAllPackageFiles(completionProcessor);
        logger.debug("Processed all package files");
    } else {
        // fallback
        PerlPackageCompletionUtil.processAllNamespacesNames(completionProcessor);
        logger.debug("Processed all namespace names");
    }
    completionProcessor.logStatus(getClass());
}
Also used : PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PerlSimpleCompletionProcessor

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

the class PerlSubCallCompletionProvider method addCompletions.

@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    PsiElement position = parameters.getPosition();
    PsiElement method = position.getParent();
    assert method instanceof PsiPerlMethod;
    PerlCallValue perlValue = PerlCallValue.from(method);
    if (perlValue == null) {
        return;
    }
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, resultSet, position);
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    if (perlValue instanceof PerlCallStaticValue && !((PerlCallStaticValue) perlValue).hasExplicitNamespace()) {
        PerlSubCompletionUtil.processBuiltInSubsLookupElements(completionProcessor);
        logger.debug("Processed built-in subs");
    }
    PerlSubCompletionUtil.processSubsCompletionsForCallValue(completionProcessor, perlValue, perlValue instanceof PerlCallStaticValue);
    logger.debug("Processed subs for call value");
    completionProcessor.logStatus(getClass());
}
Also used : PerlCallStaticValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallStaticValue) PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlCallValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 9 with PerlSimpleCompletionProcessor

use of com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor 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 PerlSimpleCompletionProcessor

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

the class PerlUnicodeNamesCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result.caseInsensitive(), parameters.getPosition());
    Map<String, String> cache = myNamesCacheRef.get();
    if (cache == null) {
        LOG.debug("Cache been collected, re-init");
        cache = new HashMap<>();
        myCodePoint = 0;
        myNamesCacheRef = new SoftReference<>(cache);
    }
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    fillCached(completionProcessor, cache);
    logger.debug("Filled cached unicode names");
    lazyCache(completionProcessor, cache);
    logger.debug("Lazily populated cache of unicode names");
    if (LOG.isDebugEnabled()) {
        LOG.debug("Cached entries: ", cache.size(), "; data size, mb: ", (float) myDataSize / 1024 / 1024);
    }
    completionProcessor.logStatus(getClass());
}
Also used : PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor)

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