Search in sources :

Example 1 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoKeywordCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    super.fillCompletionVariants(parameters, result);
    PsiElement position = parameters.getPosition();
    if (insideGoOrDeferStatements().accepts(position) || anonymousFunction().accepts(position)) {
        InsertHandler<LookupElement> insertHandler = GoKeywordCompletionProvider.createTemplateBasedInsertHandler("go_lang_anonymous_func");
        result.addElement(GoKeywordCompletionProvider.createKeywordLookupElement("func", CONTEXT_KEYWORD_PRIORITY, insertHandler));
    }
    if (referenceExpression().accepts(position)) {
        InsertHandler<LookupElement> insertHandler = GoKeywordCompletionProvider.createTemplateBasedInsertHandler("go_lang_anonymous_struct");
        result.addElement(GoKeywordCompletionProvider.createKeywordLookupElement("struct", CONTEXT_KEYWORD_PRIORITY, insertHandler));
    }
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Example 2 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class Variants method executeOnAliasedName.

/*
     * Protected Instance Methods
     */
/**
     * Decides whether {@code match} matches the criteria being searched for.  All other {@link #execute} methods
     * eventually end here.
     *
     * @param match
     * @param aliasedName
     * @param state
     * @return {@code true} to keep processing; {@code false} to stop processing.
     */
@Override
protected boolean executeOnAliasedName(@NotNull PsiNamedElement match, @NotNull final String aliasedName, @NotNull ResolveState state) {
    if (lookupElementList == null) {
        lookupElementList = new ArrayList<LookupElement>();
    }
    lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedName, match));
    String unaliasedName = UnaliasedName.unaliasedName(match);
    if (unaliasedName != null) {
        Project project = match.getProject();
        Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project);
        List<String> unaliasedNestedNames = ContainerUtil.findAll(indexedNameCollection, new org.elixir_lang.Module.IsNestedUnder(unaliasedName));
        if (unaliasedNestedNames.size() > 0) {
            GlobalSearchScope scope = GlobalSearchScope.allScope(project);
            for (String unaliasedNestedName : unaliasedNestedNames) {
                Collection<NamedElement> unaliasedNestedNamedElementCollection = StubIndex.getElements(AllName.KEY, unaliasedNestedName, project, scope, NamedElement.class);
                if (unaliasedNestedNamedElementCollection.size() > 0) {
                    List<String> unaliasedNestedNamePartList = split(unaliasedNestedName);
                    List<String> unaliasedNamePartList = split(unaliasedName);
                    List<String> aliasedNamePartList = split(aliasedName);
                    List<String> aliasedNestedNamePartList = new ArrayList<String>();
                    aliasedNestedNamePartList.addAll(aliasedNamePartList);
                    for (int i = unaliasedNamePartList.size(); i < unaliasedNestedNamePartList.size(); i++) {
                        aliasedNestedNamePartList.add(unaliasedNestedNamePartList.get(i));
                    }
                    String aliasedNestedName = concat(aliasedNestedNamePartList);
                    for (NamedElement unaliasedNestedNamedElement : unaliasedNestedNamedElementCollection) {
                        lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedNestedName, unaliasedNestedNamedElement));
                    }
                }
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(org.elixir_lang.psi.scope.Module) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 3 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class Variants method addToLookupElementByPsiElement.

/*
     * Private Instance Methods
     */
private void addToLookupElementByPsiElement(@NotNull Call call) {
    if (call instanceof Named) {
        Named named = (Named) call;
        PsiElement nameIdentifier = named.getNameIdentifier();
        if (nameIdentifier != null) {
            if (lookupElementByPsiElement == null || !lookupElementByPsiElement.containsKey(nameIdentifier)) {
                if (lookupElementByPsiElement == null) {
                    lookupElementByPsiElement = new THashMap<PsiElement, LookupElement>();
                }
                String name = nameIdentifier.getText();
                lookupElementByPsiElement.put(nameIdentifier, LookupElementBuilder.createWithSmartPointer(name, nameIdentifier).withRenderer(new org.elixir_lang.code_insight.lookup.element_renderer.CallDefinitionClause(name)));
            }
        }
    }
}
Also used : Named(org.elixir_lang.psi.call.Named) CallDefinitionClause(org.elixir_lang.psi.scope.CallDefinitionClause) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Example 4 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class CallDefinitionClauseTest method testIssue457ShorterName.

/*
     * Tests
     */
public void testIssue457ShorterName() {
    String name = "fo";
    LookupElement lookupElement = lookupElement(name);
    LookupElementPresentation lookupElementPresentation = new LookupElementPresentation();
    lookupElement.renderElement(lookupElementPresentation);
    assertEquals(name, lookupElementPresentation.getItemText());
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 5 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class CallDefinitionClauseTest method testIssue457LongerNameIssue503.

public void testIssue457LongerNameIssue503() {
    String name = "fooo";
    LookupElement lookupElement = lookupElement(name);
    LookupElementPresentation lookupElementPresentation = new LookupElementPresentation();
    lookupElement.renderElement(lookupElementPresentation);
    assertEquals(name, lookupElementPresentation.getItemText());
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)182 PsiElement (com.intellij.psi.PsiElement)32 NotNull (org.jetbrains.annotations.NotNull)32 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)19 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 PsiTypeLookupItem (com.intellij.codeInsight.lookup.PsiTypeLookupItem)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 com.intellij.psi (com.intellij.psi)6