Search in sources :

Example 1 with PlainPrefixMatcher

use of com.intellij.codeInsight.completion.PlainPrefixMatcher in project intellij-community by JetBrains.

the class ChangeListCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull final CompletionResultSet result) {
    final PsiFile file = parameters.getOriginalFile();
    final Document document = PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file);
    if (document == null)
        return;
    ComboBox comboBox = document.getUserData(COMBO_BOX_KEY);
    if (comboBox == null)
        return;
    final CompletionResultSet resultSet = result.withPrefixMatcher(new PlainPrefixMatcher(document.getText()));
    for (int i = 0; i < comboBox.getItemCount(); i++) {
        resultSet.addElement(LookupElementBuilder.create(comboBox.getItemAt(i)));
    }
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document)

Example 2 with PlainPrefixMatcher

use of com.intellij.codeInsight.completion.PlainPrefixMatcher in project intellij-community by JetBrains.

the class ListTemplatesHandler method showTemplatesLookup.

public static void showTemplatesLookup(final Project project, final Editor editor, Map<TemplateImpl, String> template2Argument) {
    final LookupImpl lookup = (LookupImpl) LookupManager.getInstance(project).createLookup(editor, LookupElement.EMPTY_ARRAY, "", new LookupArranger.DefaultArranger());
    for (TemplateImpl template : template2Argument.keySet()) {
        String prefix = computePrefix(template, template2Argument.get(template));
        lookup.addItem(createTemplateElement(template), new PlainPrefixMatcher(prefix));
    }
    showLookup(lookup, template2Argument);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher)

Example 3 with PlainPrefixMatcher

use of com.intellij.codeInsight.completion.PlainPrefixMatcher in project Perl5-IDEA by Camelcade.

the class PerlVariableNameCompletionProvider method addCompletions.

public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    PsiElement variableNameElement = parameters.getPosition();
    boolean isDeclaration = VARIABLE_NAME_IN_DECLARATION_PATTERN.accepts(variableNameElement);
    boolean isFullQualified = PerlPackageUtil.isFullQualifiedName(variableNameElement.getText());
    PsiElement originalPosition = parameters.getOriginalPosition();
    if (originalPosition instanceof PerlVariableNameElement) {
        resultSet = resultSet.withPrefixMatcher(new PlainPrefixMatcher(originalPosition.getText()));
    }
    // declaration helper
    if (isDeclaration) {
        PerlVariableCompletionUtil.fillWithUnresolvedVars((PerlVariableNameElement) variableNameElement, resultSet);
    } else if (!isFullQualified) {
        PerlVariableCompletionUtil.fillWithLExicalVariables(variableNameElement, resultSet);
    }
    // built ins
    if (VARIABLE_NAME_IN_LOCAL_DECLARATION_PATTERN.accepts(variableNameElement)) {
        PerlVariableCompletionUtil.fillWithBuiltInVariables(variableNameElement, resultSet);
    }
    // imports
    if (!isDeclaration && !isFullQualified) {
        fillWithImportedVariables(variableNameElement, resultSet);
    }
    // fqn names
    if (!isDeclaration) {
        fillWithFullQualifiedVariables(variableNameElement, resultSet);
    }
}
Also used : PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PlainPrefixMatcher

use of com.intellij.codeInsight.completion.PlainPrefixMatcher in project Perl5-IDEA by Camelcade.

the class PerlPackageSubCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement method = parameters.getPosition().getParent();
    assert method instanceof PsiPerlMethod : "Expected PsiPerlMethod, got " + method.getClass();
    String explicitNamespace = ((PsiPerlMethod) method).getExplicitPackageName();
    String currentPrefixMatcher = result.getPrefixMatcher().getPrefix();
    String newPrefixMathcer = (explicitNamespace == null ? currentPrefixMatcher : (explicitNamespace + PerlPackageUtil.PACKAGE_SEPARATOR) + currentPrefixMatcher);
    result = result.withPrefixMatcher(new PlainPrefixMatcher(newPrefixMathcer));
    if (!((PsiPerlMethod) method).isObjectMethod()) {
        PerlPackageCompletionUtil.fillWithAllPackageNamesWithAutocompletion(parameters.getPosition(), result);
    } else {
        if (!StringUtil.equals(PerlPackageUtil.SUPER_PACKAGE_FULL, newPrefixMathcer)) {
            LookupElementBuilder newElement = PerlPackageCompletionUtil.getPackageLookupElementWithAutocomplete(method.getProject(), PerlPackageUtil.SUPER_PACKAGE_FULL, null);
            newElement.putUserData(PerlCompletionWeighter.WEIGHT, -1);
            result.addElement(newElement);
        }
    }
}
Also used : PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiElement(com.intellij.psi.PsiElement)

Example 5 with PlainPrefixMatcher

use of com.intellij.codeInsight.completion.PlainPrefixMatcher in project Intellij-Plugin by getgauge.

the class StaticArgCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    String prefix = getPrefix(parameters);
    resultSet = resultSet.withPrefixMatcher(new PlainPrefixMatcher(prefix));
    PsiFile specFile = parameters.getOriginalFile();
    SpecDetail specDetail = PsiTreeUtil.getChildOfType(specFile, SpecDetail.class);
    List<SpecStep> stepsInFile = new ArrayList<>();
    addContextSteps(specDetail, stepsInFile);
    addStepsInScenarios(specFile, stepsInFile);
    Set<String> staticArgs = getArgsFromSteps(stepsInFile);
    for (String arg : staticArgs) {
        if (arg != null) {
            LookupElementBuilder item = LookupElementBuilder.create(arg);
            resultSet.addElement(item);
        }
    }
}
Also used : SpecDetail(com.thoughtworks.gauge.language.psi.SpecDetail) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) SpecStep(com.thoughtworks.gauge.language.psi.SpecStep) ArrayList(java.util.ArrayList) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiFile(com.intellij.psi.PsiFile)

Aggregations

PlainPrefixMatcher (com.intellij.codeInsight.completion.PlainPrefixMatcher)9 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)4 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 SpecDetail (com.thoughtworks.gauge.language.psi.SpecDetail)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 Document (com.intellij.openapi.editor.Document)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 MultiMap (com.intellij.util.containers.MultiMap)1 PsiPerlMethod (com.perl5.lang.perl.psi.PsiPerlMethod)1 ConceptDynamicArg (com.thoughtworks.gauge.language.psi.ConceptDynamicArg)1 ConceptStaticArg (com.thoughtworks.gauge.language.psi.ConceptStaticArg)1 SpecStep (com.thoughtworks.gauge.language.psi.SpecStep)1 SpecTable (com.thoughtworks.gauge.language.psi.SpecTable)1 ArrayList (java.util.ArrayList)1