Search in sources :

Example 6 with PerlVariableCompletionProcessor

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

the class PerlVariableCompletionUtil method fillWithLexicalVariables.

public static void fillWithLexicalVariables(@NotNull PerlVariableCompletionProcessor variableCompletionProcessor) {
    PsiElement perlVariable = variableCompletionProcessor.getLeafParentElement();
    Processor<PerlVariableDeclarationElement> lookupProcessor = createLexicalLookupProcessor(new PerlDelegatingVariableCompletionProcessor(variableCompletionProcessor) {

        @Override
        public boolean isLexical() {
            return true;
        }
    });
    PsiScopeProcessor processor = (element, __) -> {
        if (!(element instanceof PerlVariableDeclarationElement)) {
            return true;
        }
        PerlVariableDeclarationElement variable = (PerlVariableDeclarationElement) element;
        PsiElement declarationStatement = PsiTreeUtil.getParentOfType(variable, PerlStatement.class);
        if (PsiTreeUtil.isAncestor(declarationStatement, perlVariable, false)) {
            return true;
        }
        if (StringUtil.isNotEmpty(variable.getName())) {
            boolean processResult = lookupProcessor.process(variable);
            if (processResult && variable.isGlobalDeclaration()) {
                variableCompletionProcessor.register(variable.getCanonicalNameWithSigil());
            }
            return processResult;
        }
        return true;
    };
    PerlResolveUtil.treeWalkUp(variableCompletionProcessor.getLeafElement(), processor);
}
Also used : PerlBundle(com.perl5.PerlBundle) GLOB_GUTTER_ICON(com.perl5.PerlIcons.GLOB_GUTTER_ICON) PerlDelegatingVariableCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlDelegatingVariableCompletionProcessor) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) PerlInsertHandlers(com.perl5.lang.perl.idea.completion.PerlInsertHandlers) PerlLexicalScope(com.perl5.lang.perl.psi.properties.PerlLexicalScope) PerlVariableCompletionProcessorImpl(com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor) PerlSharedSettings(com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings) PsiElement(com.intellij.psi.PsiElement) PerlVersion(com.perl5.lang.perl.internals.PerlVersion) Project(com.intellij.openapi.project.Project) com.perl5.lang.perl.psi(com.perl5.lang.perl.psi) PerlIconProvider(com.perl5.lang.perl.idea.ui.PerlIconProvider) PerlBuiltInVariablesService(com.perl5.lang.perl.psi.references.PerlBuiltInVariablesService) CompletionUtil(com.intellij.codeInsight.completion.CompletionUtil) com.perl5.lang.perl.util(com.perl5.lang.perl.util) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) PerlVariableType(com.perl5.lang.perl.psi.utils.PerlVariableType) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) StringUtil(com.intellij.openapi.util.text.StringUtil) Predicate(java.util.function.Predicate) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) PerlBuiltInVariable(com.perl5.lang.perl.psi.impl.PerlBuiltInVariable) PerlCompletionWeighter(com.perl5.lang.perl.idea.PerlCompletionWeighter) Processor(com.intellij.util.Processor) PerlResolveUtil(com.perl5.lang.perl.psi.utils.PerlResolveUtil) NotNull(org.jetbrains.annotations.NotNull) PerlVariableCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessor) PerlNamespaceEntityProcessor(com.perl5.lang.perl.util.processors.PerlNamespaceEntityProcessor) javax.swing(javax.swing) PerlDelegatingVariableCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlDelegatingVariableCompletionProcessor) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PerlVariableCompletionProcessor

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

PsiElement (com.intellij.psi.PsiElement)6 PerlVariableCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessor)6 PerlVariableCompletionProcessorImpl (com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl)6 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)5 PerlBuiltInVariable (com.perl5.lang.perl.psi.impl.PerlBuiltInVariable)5 CompletionUtil (com.intellij.codeInsight.completion.CompletionUtil)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 Project (com.intellij.openapi.project.Project)4 StringUtil (com.intellij.openapi.util.text.StringUtil)4 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)4 Processor (com.intellij.util.Processor)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 PerlBundle (com.perl5.PerlBundle)4 GLOB_GUTTER_ICON (com.perl5.PerlIcons.GLOB_GUTTER_ICON)4 PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)4 PerlCompletionWeighter (com.perl5.lang.perl.idea.PerlCompletionWeighter)4 PerlInsertHandlers (com.perl5.lang.perl.idea.completion.PerlInsertHandlers)4 PerlDelegatingVariableCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlDelegatingVariableCompletionProcessor)4