Search in sources :

Example 46 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class GradleArgumentsCompletionProvider method getVariants.

protected List<LookupElement> getVariants(@NotNull final DataNode<ProjectData> projectDataNode, @NotNull final String modulePath) {
    final DataNode<ModuleData> moduleDataNode = findModuleDataNode(projectDataNode, modulePath);
    if (moduleDataNode == null) {
        return Collections.emptyList();
    }
    final ModuleData moduleData = moduleDataNode.getData();
    final boolean isRoot = projectDataNode.getData().getLinkedExternalProjectPath().equals(moduleData.getLinkedExternalProjectPath());
    final Collection<DataNode<TaskData>> tasks = ExternalSystemApiUtil.getChildren(moduleDataNode, ProjectKeys.TASK);
    List<LookupElement> elements = ContainerUtil.newArrayListWithCapacity(tasks.size());
    for (DataNode<TaskData> taskDataNode : tasks) {
        final TaskData taskData = taskDataNode.getData();
        elements.add(LookupElementBuilder.create(taskData.getName()).withIcon(ExternalSystemIcons.Task));
        if (!taskData.isInherited()) {
            elements.add(LookupElementBuilder.create((isRoot ? ':' : moduleData.getId() + ':') + taskData.getName()).withIcon(ExternalSystemIcons.Task));
        }
    }
    return elements;
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) LookupElement(com.intellij.codeInsight.lookup.LookupElement) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData)

Example 47 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class CompletionResultSet method addAllElements.

public void addAllElements(@NotNull final Iterable<? extends LookupElement> elements) {
    int seldomCounter = 0;
    for (LookupElement element : elements) {
        seldomCounter++;
        addElement(element);
        if (seldomCounter % 1000 == 0) {
            ProgressManager.checkCanceled();
        }
    }
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 48 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class LegacyCompletionContributor method completeReference.

public static boolean completeReference(final CompletionParameters parameters, final CompletionResultSet result) {
    final CompletionData completionData = getCompletionData(parameters);
    if (completionData == null) {
        return false;
    }
    final Ref<Boolean> hasVariants = Ref.create(false);
    processReferences(parameters, result, (reference, resultSet) -> {
        final Set<LookupElement> lookupSet = new LinkedHashSet<>();
        completionData.completeReference(reference, lookupSet, parameters.getPosition(), parameters.getOriginalFile());
        for (final LookupElement item : lookupSet) {
            if (resultSet.getPrefixMatcher().prefixMatches(item)) {
                if (!item.isValid()) {
                    LOG.error(completionData + " has returned an invalid lookup element " + item + " of " + item.getClass() + " in " + parameters.getOriginalFile() + " of " + parameters.getOriginalFile().getClass() + "; reference=" + reference + " of " + reference.getClass());
                }
                hasVariants.set(true);
                resultSet.addElement(item);
            }
        }
    });
    return hasVariants.get().booleanValue();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 49 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class WordCompletionContributor method addValuesFromOtherStringLiterals.

private static void addValuesFromOtherStringLiterals(CompletionResultSet result, CompletionParameters parameters, final Set<String> realExcludes, PsiElement position) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(position.getLanguage());
    if (definition == null) {
        return;
    }
    final ElementPattern<PsiElement> pattern = psiElement().withElementType(definition.getStringLiteralElements());
    final PsiElement localString = PsiTreeUtil.findFirstParent(position, false, element -> pattern.accepts(element));
    if (localString == null) {
        return;
    }
    ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(localString);
    if (manipulator == null) {
        return;
    }
    int offset = manipulator.getRangeInElement(localString).getStartOffset();
    PsiFile file = position.getContainingFile();
    final CompletionResultSet fullStringResult = result.withPrefixMatcher(file.getText().substring(offset + localString.getTextRange().getStartOffset(), parameters.getOffset()));
    file.accept(new PsiRecursiveElementWalkingVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element == localString) {
                return;
            }
            if (pattern.accepts(element)) {
                element.accept(new PsiRecursiveElementWalkingVisitor() {

                    @Override
                    public void visitElement(PsiElement each) {
                        String valueText = ElementManipulators.getValueText(each);
                        if (StringUtil.isNotEmpty(valueText) && !realExcludes.contains(valueText)) {
                            final LookupElement item = LookupElementBuilder.create(valueText);
                            fullStringResult.addElement(item);
                        }
                    }
                });
                return;
            }
            super.visitElement(element);
        }
    });
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 50 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class LiftShorterItemsClassifier method addElement.

@Override
public void addElement(@NotNull LookupElement added, @NotNull ProcessingContext context) {
    myCount++;
    for (String string : CompletionUtil.iterateLookupStrings(added)) {
        if (string.length() == 0)
            continue;
        myElements.putValue(string, added);
        mySortedStrings.add(string);
        final NavigableSet<String> after = mySortedStrings.tailSet(string, false);
        for (String s : after) {
            if (!s.startsWith(string)) {
                break;
            }
            for (LookupElement longer : myElements.get(s)) {
                updateLongerItem(added, longer);
            }
        }
    }
    super.addElement(added, context);
    calculateToLift(added);
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)183 PsiElement (com.intellij.psi.PsiElement)33 NotNull (org.jetbrains.annotations.NotNull)32 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)20 Nullable (org.jetbrains.annotations.Nullable)17 ArrayList (java.util.ArrayList)14 Project (com.intellij.openapi.project.Project)12 LookupElementPresentation (com.intellij.codeInsight.lookup.LookupElementPresentation)10 Document (com.intellij.openapi.editor.Document)10 PsiFile (com.intellij.psi.PsiFile)10 Editor (com.intellij.openapi.editor.Editor)9 THashSet (gnu.trove.THashSet)8 LinkedHashSet (java.util.LinkedHashSet)8 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)7 XmlTag (com.intellij.psi.xml.XmlTag)7 Consumer (com.intellij.util.Consumer)7 HashSet (java.util.HashSet)7 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)6 PsiTypeLookupItem (com.intellij.codeInsight.lookup.PsiTypeLookupItem)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6