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);
}
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();
}
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);
}
}
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();
}
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)));
}
}
}
Aggregations