Java Code Examples for com.intellij.codeInsight.completion.PrioritizedLookupElement#withPriority()

The following examples show how to use com.intellij.codeInsight.completion.PrioritizedLookupElement#withPriority() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayoutSpecMethodAnnotationsProvider.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void addCompletions(
    CompletionParameters parameters, ProcessingContext context, CompletionResultSet result) {
  PsiElement position = parameters.getPosition();
  if (!CompletionUtils.findFirstParent(position, LithoPluginUtils::isLayoutSpec).isPresent())
    return;

  final Project project = position.getProject();
  for (String annotationFQN : ANNOTATION_QUALIFIED_NAMES) {
    LookupElement lookup =
        PrioritizedLookupElement.withPriority(
            createLookup(annotationFQN, project), Integer.MAX_VALUE);
    result.addElement(lookup);
  }
}
 
Example 2
Source File: Suggestion.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
public LookupElement newLookupElement(final int priority) {
    return PrioritizedLookupElement
            .withPriority(LookupElementBuilder
                    .create(this, getKey())
                    .withRenderer(new LookupElementRenderer<LookupElement>() {

                        @Override
                        public void renderElement(final LookupElement element,
                                final LookupElementPresentation presentation) {
                            final Suggestion suggestion = Suggestion.class.cast(element.getObject());
                            presentation.setItemText(suggestion.getKey());
                            if (Type.Family.equals(suggestion.getType())) {
                                presentation.setIcon(AllIcons.Nodes.ModuleGroup);
                                presentation.appendTailText("  Family", true);
                            } else if (Type.Component.equals(suggestion.getType())) {
                                presentation.setIcon(Icons.TACOKIT.getIcon());
                                presentation.appendTailText("  Component", true);
                            } else if (Type.Configuration.equals(suggestion.getType())) {
                                presentation.setIcon(AllIcons.Hierarchy.Class);
                                presentation.appendTailText("  Configuration", true);
                            } else if (Type.Action.equals(suggestion.getType())) {
                                presentation.setIcon(findSubmit());
                                presentation.appendTailText("  Action", true);
                            }
                        }
                    }), priority);
}
 
Example 3
Source File: RequiredPropLookupElement.java    From litho with Apache License 2.0 4 votes vote down vote up
static RequiredPropLookupElement create(LookupElement delegate, boolean shouldPrioritize) {
  if (shouldPrioritize) {
    delegate = PrioritizedLookupElement.withPriority(delegate, Integer.MAX_VALUE);
  }
  return new RequiredPropLookupElement(delegate);
}
 
Example 4
Source File: CamelSmartCompletionEndpointOptions.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
private static List<LookupElement> addSmartCompletionContextPathEnumSuggestions(final String val,
                                                                                final ComponentModel component,
                                                                                final Map<String, String> existing) {
    final List<LookupElement> answer = new ArrayList<>();

    double priority = 100.0d;

    // lets help the suggestion list if we are editing the context-path and only have 1 enum type option
    // and the option has not been in use yet, then we can populate the list with the enum values.

    final long enums = component
            .getEndpointOptions()
            .stream()
            .filter(o -> "path".equals(o.getKind()) && !o
                    .getEnums()
                    .isEmpty())
            .count();
    if (enums == 1) {
        for (final EndpointOptionModel option : component.getEndpointOptions()) {

            // only add support for enum in the context-path smart completion
            if ("path".equals(option.getKind()) && !option
                    .getEnums()
                    .isEmpty()) {
                final String name = option.getName();
                // only add if not already used
                final String old = existing != null ? existing.get(name) : "";
                if (existing == null || old == null || old.isEmpty()) {

                    // add all enum as choices
                    for (final String choice : option
                            .getEnums()
                            .split(",")) {

                        final String key = choice;
                        final String lookup = val + key;

                        LookupElementBuilder builder = LookupElementBuilder.create(lookup);
                        // only show the option in the UI
                        builder = builder.withPresentableText(choice);
                        // lets use the option name as the type so its visible
                        builder = builder.withTypeText(name, true);
                        builder = builder.withIcon(AllIcons.Nodes.Enum);

                        if ("true".equals(option.getDeprecated())) {
                            // mark as deprecated
                            builder = builder.withStrikeoutness(true);
                        }

                        // its an enum so always auto complete the choices
                        LookupElement element = builder.withAutoCompletionPolicy(AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE);

                        // they should be in the exact order
                        element = PrioritizedLookupElement.withPriority(element, priority);

                        priority -= 1.0d;

                        answer.add(element);
                    }
                }
            }
        }
    }

    return answer;
}
 
Example 5
Source File: XQueryCompletionContributor.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
public static LookupElement prioritized(LookupElement lookupElement, int priority) {
    return PrioritizedLookupElement.withPriority(lookupElement, priority);
}
 
Example 6
Source File: TemplateExpressionLookupElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
public TemplateExpressionLookupElement(final TemplateState state, LookupElement element, int index) {
  super(PrioritizedLookupElement.withPriority(element, Integer.MAX_VALUE - 10 - index));
  myState = state;
}