use of com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl in project Perl5-IDEA by Camelcade.
the class PerlVariableCompletionUtil method fillWithUnresolvedVars.
public static void fillWithUnresolvedVars(@NotNull PerlVariableCompletionProcessorImpl completionProcessor) {
PsiElement variableNameElement = completionProcessor.getLeafElement();
final PerlLexicalScope lexicalScope = PsiTreeUtil.getParentOfType(variableNameElement, PerlLexicalScope.class);
PsiElement perlVariable = variableNameElement.getParent();
final Set<String> collectedNames = new THashSet<>();
if (lexicalScope != null && perlVariable instanceof PerlVariable) {
final int minOffset = variableNameElement.getTextOffset();
final PerlVariableType actualType = ((PerlVariable) perlVariable).getActualType();
lexicalScope.accept(new PerlCompletionRecursiveVisitor(completionProcessor) {
@Override
public void visitPerlVariable(@NotNull PerlVariable perlVariable) {
if (perlVariable.isValid() && !(perlVariable.getParent() instanceof PerlVariableDeclarationElement) && perlVariable.getTextOffset() > minOffset && actualType == perlVariable.getActualType()) {
String variableName = perlVariable.getName();
if (completionProcessor.matches(variableName) && collectedNames.add(variableName) && perlVariable.getLexicalDeclaration() == null) {
completionProcessor.process(LookupElementBuilder.create(variableName));
}
}
super.visitPerlVariable(perlVariable);
}
});
}
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl 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());
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl 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());
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl 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());
}
use of com.perl5.lang.perl.idea.completion.providers.processors.PerlVariableCompletionProcessorImpl 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());
}
Aggregations