Search in sources :

Example 81 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project Intellij-Plugin by getgauge.

the class StepCompletionProvider method addCompletions.

@Override
public void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    resultSet.stopHere();
    final String prefix = getPrefix(parameters);
    resultSet = resultSet.withPrefixMatcher(new GaugePrefixMatcher(prefix));
    Module moduleForPsiElement = GaugeUtil.moduleForPsiElement(parameters.getPosition());
    if (moduleForPsiElement == null) {
        return;
    }
    for (Type item : getStepsInModule(moduleForPsiElement)) {
        LookupElementBuilder element = LookupElementBuilder.create(item.getText()).withTypeText(item.getType(), true);
        element = element.withInsertHandler((InsertionContext context1, LookupElement item1) -> {
            if (context1.getCompletionChar() == '\t') {
                context1.getDocument().insertString(context1.getEditor().getCaretModel().getOffset(), "\n");
                PsiDocumentManager.getInstance(context1.getProject()).commitDocument(context1.getDocument());
            }
            PsiElement stepElement = context1.getFile().findElementAt(context1.getStartOffset()).getParent();
            final TemplateBuilder templateBuilder = TemplateBuilderFactory.getInstance().createTemplateBuilder(stepElement);
            replaceStepParamElements(prefix, context1, stepElement, templateBuilder);
            templateBuilder.run(context1.getEditor(), false);
        });
        resultSet.addElement(element);
    }
}
Also used : TemplateBuilder(com.intellij.codeInsight.template.TemplateBuilder) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) Module(com.intellij.openapi.module.Module) InsertionContext(com.intellij.codeInsight.completion.InsertionContext) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Example 82 with LookupElement

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

the class LanguageListCompletionContributor method doFillVariants.

private static void doFillVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    for (CodeFenceLanguageProvider provider : LanguageGuesser.INSTANCE.getCodeFenceLanguageProviders()) {
        final List<LookupElement> lookups = provider.getCompletionVariantsForInfoString(parameters);
        for (LookupElement lookupElement : lookups) {
            result.addElement(LookupElementDecorator.withInsertHandler(lookupElement, (context, item) -> {
                new MyInsertHandler(parameters).handleInsert(context, item);
                lookupElement.handleInsert(context);
            }));
        }
    }
    for (Map.Entry<String, Language> entry : LanguageGuesser.INSTANCE.getLangToLanguageMap().entrySet()) {
        final Language language = entry.getValue();
        final LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(entry.getKey()).withIcon(new DeferredIconImpl<>(null, language, true, language1 -> {
            final LanguageFileType fileType = language1.getAssociatedFileType();
            return fileType != null ? fileType.getIcon() : null;
        })).withTypeText(language.getDisplayName(), true).withInsertHandler(new MyInsertHandler(parameters));
        result.addElement(lookupElementBuilder);
    }
}
Also used : Language(com.intellij.lang.Language) MarkdownElementTypes(org.intellij.plugins.markdown.lang.MarkdownElementTypes) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) MarkdownTokenTypes(org.intellij.plugins.markdown.lang.MarkdownTokenTypes) MarkdownFile(org.intellij.plugins.markdown.lang.psi.impl.MarkdownFile) TextRange(com.intellij.openapi.util.TextRange) DeferredIconImpl(com.intellij.ui.DeferredIconImpl) com.intellij.codeInsight.completion(com.intellij.codeInsight.completion) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) LookupElementDecorator(com.intellij.codeInsight.lookup.LookupElementDecorator) NotNull(org.jetbrains.annotations.NotNull) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Map(java.util.Map)

Example 83 with LookupElement

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

the class GoReferenceCompletionProvider method addElement.

private static void addElement(@NotNull PsiElement o, @NotNull ResolveState state, boolean forTypes, boolean vendoringEnabled, @NotNull Set<String> processedNames, @NotNull CompletionResultSet set) {
    LookupElement lookup = createLookupElement(o, state, forTypes, vendoringEnabled);
    if (lookup != null) {
        String lookupString = lookup.getLookupString();
        if (!processedNames.contains(lookupString)) {
            set.addElement(lookup);
            processedNames.add(lookupString);
        }
    }
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 84 with LookupElement

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

the class GoKeywordCompletionProvider method createKeywordLookupElement.

@NotNull
private LookupElement createKeywordLookupElement(@NotNull String keyword) {
    InsertHandler<LookupElement> insertHandler = ObjectUtils.chooseNotNull(myInsertHandler, createTemplateBasedInsertHandler("go_lang_" + keyword));
    LookupElement result = createKeywordLookupElement(keyword, myPriority, insertHandler);
    return myCompletionPolicy != null ? myCompletionPolicy.applyPolicy(result) : result;
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with LookupElement

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

the class GoCompletionTest method testPointerSpecType.

public void testPointerSpecType() {
    myFixture.configureByText("foo.go", "package main; type a struct{};" + "func main() {q1, q2:=&a{};q<caret>}");
    myFixture.completeBasic();
    LookupElement first = ArrayUtil.getFirstElement(myFixture.getLookupElements());
    assertNotNull(first);
    LookupElementPresentation presentation = new LookupElementPresentation();
    first.renderElement(presentation);
    assertEquals("*main.a", presentation.getTypeText());
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) 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