Search in sources :

Example 1 with PerlTimeLogger

use of com.perl5.lang.perl.util.PerlTimeLogger 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 2 with PerlTimeLogger

use of com.perl5.lang.perl.util.PerlTimeLogger 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 3 with PerlTimeLogger

use of com.perl5.lang.perl.util.PerlTimeLogger in project Perl5-IDEA by Camelcade.

the class PerlVariableCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    if (!Experiments.getInstance().isFeatureEnabled("perl5.completion.var.without.sigil")) {
        return;
    }
    PsiElement subName = parameters.getPosition();
    PsiElement method = subName.getParent();
    String namespaceName = null;
    if (!(method instanceof PsiPerlMethod) || ((PsiPerlMethod) method).isObjectMethod()) {
        return;
    }
    namespaceName = ((PsiPerlMethod) method).getExplicitNamespaceName();
    if (StringUtil.isNotEmpty(namespaceName)) {
        resultSet = resultSet.withPrefixMatcher(PerlPackageUtil.join(namespaceName, resultSet.getPrefixMatcher().getPrefix()));
    }
    PerlVariableCompletionProcessor variableCompletionProcessor = new PerlVariableCompletionProcessorImpl(parameters, resultSet, subName, namespaceName, false, false, false);
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    PerlVariableCompletionUtil.processVariables(variableCompletionProcessor, logger);
    variableCompletionProcessor.logStatus(getClass());
}
Also used : PerlVariableCompletionProcessorImpl(com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl) PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlVariableCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessor) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PerlTimeLogger

use of com.perl5.lang.perl.util.PerlTimeLogger in project Perl5-IDEA by Camelcade.

the class PerlVariableNameCompletionProvider method addCompletions.

@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    PsiElement variableNameElement = parameters.getPosition();
    String namespaceName = null;
    if (variableNameElement instanceof PerlVariableNameElement) {
        resultSet = resultSet.withPrefixMatcher(getVariableNamePrefix(variableNameElement, parameters.getOffset()));
        PsiElement variable = variableNameElement.getParent();
        if (variable instanceof PerlVariable) {
            namespaceName = ((PerlVariable) variable).getExplicitNamespaceName();
        }
    }
    boolean isDeclaration = VARIABLE_NAME_IN_DECLARATION_PATTERN.accepts(variableNameElement);
    boolean hasBraces = VARIABLE_OPEN_BRACES.contains(PsiUtilCore.getElementType(variableNameElement.getPrevSibling()));
    boolean isCapped = StringUtil.startsWithChar(resultSet.getPrefixMatcher().getPrefix(), '^');
    PerlVariableCompletionProcessorImpl variableCompletionProcessor = new PerlVariableCompletionProcessorImpl(parameters, resultSet, variableNameElement, namespaceName, hasBraces, isDeclaration, false);
    PerlTimeLogger timeLogger = new PerlTimeLogger(LOG);
    // declaration helper
    if (isDeclaration) {
        PerlVariableCompletionUtil.fillWithUnresolvedVars(variableCompletionProcessor);
        timeLogger.debug("Filled with unresolved variables");
    } else if (!variableCompletionProcessor.isFullQualified()) {
        if (!isCapped) {
            PerlVariableCompletionUtil.fillWithLexicalVariables(variableCompletionProcessor);
            timeLogger.debug("Filled with lexical variables");
        }
        PerlVariableCompletionUtil.fillWithBuiltInVariables(variableCompletionProcessor);
        timeLogger.debug("Filled with built in variables");
    }
    // built ins
    if (VARIABLE_NAME_IN_LOCAL_DECLARATION_PATTERN.accepts(variableNameElement)) {
        PerlVariableCompletionUtil.fillWithBuiltInVariables(variableCompletionProcessor);
        timeLogger.debug("Filled with built in variables");
    }
    // imports
    if (!isCapped && !isDeclaration && !variableCompletionProcessor.isFullQualified()) {
        PerlVariableCompletionUtil.fillWithImportedVariables(variableCompletionProcessor);
        timeLogger.debug("Filled with imported variables");
    }
    // fqn names
    if (!isCapped && !isDeclaration) {
        PerlPackageCompletionUtil.processAllNamespacesNames(variableCompletionProcessor, true, false);
        timeLogger.debug("Filled with namespace names");
        PerlVariableCompletionUtil.processFullQualifiedVariables(variableCompletionProcessor);
        timeLogger.debug("Filled with full qualified variables");
    }
    variableCompletionProcessor.logStatus(getClass());
}
Also used : PerlVariableNameElement(com.perl5.lang.perl.psi.PerlVariableNameElement) PerlVariableCompletionProcessorImpl(com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlVariable(com.perl5.lang.perl.psi.PerlVariable) PsiElement(com.intellij.psi.PsiElement)

Example 5 with PerlTimeLogger

use of com.perl5.lang.perl.util.PerlTimeLogger in project Perl5-IDEA by Camelcade.

the class PerlReparseableElementType method parseContents.

@Override
public ASTNode parseContents(@NotNull ASTNode chameleon) {
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    PsiElement parentElement = chameleon.getTreeParent().getPsi();
    Project project = parentElement.getProject();
    CharSequence newChars = chameleon.getChars();
    PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, createLexer(chameleon), getLanguage(), newChars);
    ASTNode result = PerlParserImpl.INSTANCE.parse(this, builder).getFirstChildNode();
    logger.trace("Parsed: ", PerlTimeLogger.kb(newChars.length()), " kb of ", this);
    return result;
}
Also used : Project(com.intellij.openapi.project.Project) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PerlTimeLogger (com.perl5.lang.perl.util.PerlTimeLogger)17 PsiElement (com.intellij.psi.PsiElement)10 PerlSimpleCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor)8 PerlVariableCompletionProcessorImpl (com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl)4 PsiPerlMethod (com.perl5.lang.perl.psi.PsiPerlMethod)3 NotNull (org.jetbrains.annotations.NotNull)3 PerlVariableCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessor)2 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 PsiLanguageInjectionHost (com.intellij.psi.PsiLanguageInjectionHost)1 ProcessingContext (com.intellij.util.ProcessingContext)1 PerlElementPatterns (com.perl5.lang.perl.idea.PerlElementPatterns)1 PerlCallStaticValue (com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallStaticValue)1 PerlCallValue (com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue)1 PerlCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlCompletionProcessor)1 PerlFormattingBlock (com.perl5.lang.perl.idea.formatter.blocks.PerlFormattingBlock)1