Search in sources :

Example 21 with LookupElementBuilder

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

the class AngularJSTagDescriptorsProvider method addLookupItem.

private static void addLookupItem(Language language, List<LookupElement> elements, JSImplicitElement directive) {
    LookupElementBuilder element = LookupElementBuilder.create(directive).withIcon(AngularJSIcons.Angular2);
    if (language.isKindOf(XMLLanguage.INSTANCE)) {
        element = element.withInsertHandler(XmlTagInsertHandler.INSTANCE);
    }
    elements.add(element);
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder)

Example 22 with LookupElementBuilder

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

the class AngularMessageFormatCompletion method messageFormatSelectionKeywords.

private static void messageFormatSelectionKeywords(AngularJSMessageFormatParser.ExtensionType type, CompletionResultSet result) {
    final CompletionResultSet set = result.withRelevanceSorter(CompletionSorter.emptySorter().weigh(MESSAGE_FORMAT_KEYWORD_WEIGHER));
    if (AngularJSMessageFormatParser.ExtensionType.plural.equals(type)) {
        final List<AngularJSPluralCategories> values = new ArrayList<>(Arrays.asList(AngularJSPluralCategories.values()));
        Collections.sort(values, PLURAL_CATEGORIES_COMPARATOR);
        for (AngularJSPluralCategories category : values) {
            LookupElementBuilder element = LookupElementBuilder.create(category).withInsertHandler(MESSAGE_FORMAT_KEYWORD_INSERT_HANDLER);
            if (AngularJSPluralCategories.other.equals(category)) {
                element = element.withTypeText("Default selection keyword", true);
            } else {
                element = element.withTypeText("Plural category", true);
            }
            set.addElement(element);
        }
        for (int i = 0; i < 4; i++) {
            final LookupElementBuilder element = LookupElementBuilder.create("=" + i).withInsertHandler(MESSAGE_FORMAT_KEYWORD_INSERT_HANDLER);
            set.addElement(element);
        }
    } else {
        set.addElement(LookupElementBuilder.create("other").setTypeText("Default selection keyword", true).withInsertHandler(MESSAGE_FORMAT_KEYWORD_INSERT_HANDLER));
    }
    set.stopHere();
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder)

Example 23 with LookupElementBuilder

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

the class AngularJavaScriptCompletionContributor method addCompletionVariants.

static void addCompletionVariants(@NotNull CompletionResultSet result, Collection<String> keys, @Nullable final String comment) {
    for (String key : keys) {
        if (StringUtil.isEmptyOrSpaces(key)) {
            continue;
        }
        LookupElementBuilder builder = LookupElementBuilder.create(key);
        if (comment != null) {
            builder = builder.withTailText(comment, true);
        }
        final LookupElement item = JSCompletionUtil.withJSLookupPriority(builder, JSLookupPriority.LOCAL_SCOPE_MAX_PRIORITY);
        result.addElement(item);
    }
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 24 with LookupElementBuilder

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

the class AngularMessageFormatCompletion method messageFormatExtensions.

private static void messageFormatExtensions(CompletionResultSet result) {
    for (AngularJSMessageFormatParser.ExtensionType type : AngularJSMessageFormatParser.ExtensionType.values()) {
        final LookupElementBuilder elementBuilder = LookupElementBuilder.create(type.name()).setTypeText("Message format extension", true);
        result.consume(elementBuilder);
    }
    result.stopHere();
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) AngularJSMessageFormatParser(org.angularjs.lang.parser.AngularJSMessageFormatParser)

Example 25 with LookupElementBuilder

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

the class CucumberCompletionContributor method addStepDefinitions.

private static void addStepDefinitions(CompletionResultSet result, PsiFile file) {
    result = result.withPrefixMatcher(new CucumberPrefixMatcher(result.getPrefixMatcher().getPrefix()));
    final List<AbstractStepDefinition> definitions = CucumberStepsIndex.getInstance(file.getProject()).getAllStepDefinitions(file);
    for (AbstractStepDefinition definition : definitions) {
        String text = definition.getCucumberRegex();
        if (text != null) {
            // trim regexp line start/end markers
            text = StringUtil.trimStart(text, "^");
            text = StringUtil.trimEnd(text, "$");
            text = StringUtil.replace(text, "\\\"", "\"");
            for (Map.Entry<String, String> group : GROUP_TYPE_MAP.entrySet()) {
                text = StringUtil.replace(text, group.getKey(), group.getValue());
            }
            for (Map.Entry<String, String> group : INTERPOLATION_PARAMETERS_MAP.entrySet()) {
                text = text.replaceAll(group.getKey(), group.getValue());
            }
            final List<TextRange> ranges = new ArrayList<>();
            Matcher m = QUESTION_MARK_PATTERN.matcher(text);
            if (m.find()) {
                text = m.replaceAll("$1");
            }
            m = POSSIBLE_GROUP_PATTERN.matcher(text);
            while (m.find()) {
                text = m.replaceAll("$1");
            }
            m = PARAMETERS_PATTERN.matcher(text);
            while (m.find()) {
                ranges.add(new TextRange(m.start(), m.end()));
            }
            final PsiElement element = definition.getElement();
            final LookupElementBuilder lookup = element != null ? LookupElementBuilder.create(element, text).bold() : LookupElementBuilder.create(text);
            result.addElement(lookup.withInsertHandler(new StepInsertHandler(ranges)));
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) TextRange(com.intellij.openapi.util.TextRange) AbstractStepDefinition(org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiElement(com.intellij.psi.PsiElement)

Aggregations

LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)53 LookupElement (com.intellij.codeInsight.lookup.LookupElement)19 NotNull (org.jetbrains.annotations.NotNull)16 PsiElement (com.intellij.psi.PsiElement)12 Nullable (org.jetbrains.annotations.Nullable)9 PsiFile (com.intellij.psi.PsiFile)6 Document (com.intellij.openapi.editor.Document)5 ArrayList (java.util.ArrayList)4 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)3 Editor (com.intellij.openapi.editor.Editor)3 TextRange (com.intellij.openapi.util.TextRange)3 PsiPresentableMetaData (com.intellij.psi.meta.PsiPresentableMetaData)3 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlExtension (com.intellij.xml.XmlExtension)3 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 ParenthesesInsertHandler (com.intellij.codeInsight.completion.util.ParenthesesInsertHandler)2 AutoCompletionPolicy (com.intellij.codeInsight.lookup.AutoCompletionPolicy)2 AllIcons (com.intellij.icons.AllIcons)2 FileType (com.intellij.openapi.fileTypes.FileType)2