Java Code Examples for com.intellij.codeInsight.lookup.LookupElementBuilder#withTailText()

The following examples show how to use com.intellij.codeInsight.lookup.LookupElementBuilder#withTailText() . These examples are extracted from open source projects. 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
private static void addEnumSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer,
                                       String deprecated, String enums, String defaultValue, boolean xmlMode) {
    String[] parts = enums.split(",");
    for (String part : parts) {
        String lookup = val + part;
        LookupElementBuilder builder = LookupElementBuilder.create(lookup);
        builder = addInsertHandler(editor, suffix, builder, xmlMode);

        // only show the option in the UI
        builder = builder.withPresentableText(part);
        builder = builder.withBoldness(true);
        if ("true".equals(deprecated)) {
            // mark as deprecated
            builder = builder.withStrikeoutness(true);
        }
        boolean isDefaultValue = defaultValue != null && part.equals(defaultValue);
        if (isDefaultValue) {
            builder = builder.withTailText(" (default value)");
            // add default value first in the list
            answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
        } else {
            answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
        }
    }
}
 
Example 2
Source Project: idea-php-toolbox   File: JsonParseUtil.java    License: MIT License 6 votes vote down vote up
@NotNull
public static LookupElementBuilder getDecoratedLookupElementBuilder(@NotNull LookupElementBuilder lookupElement, @Nullable JsonRawLookupElement jsonLookup) {
    if(jsonLookup == null) {
        return lookupElement;
    }

    if(jsonLookup.getTailText() != null) {
        lookupElement = lookupElement.withTailText(jsonLookup.getTailText(), true);
    }

    if(jsonLookup.getTypeText() != null) {
        lookupElement = lookupElement.withTypeText(jsonLookup.getTypeText(), true);
    }

    String iconString = jsonLookup.getIcon();
    if(iconString != null) {
        Icon icon = getLookupIconOnString(iconString);
        if(icon != null) {
            lookupElement = lookupElement.withIcon(icon);
        }
    }

    return lookupElement;
}
 
Example 3
private LookupElementBuilder createBuilderForMacro(LatteTagSettings tag, boolean isEndTag) {
	String name = (isEndTag ? "/" : "") + tag.getMacroName();
	LookupElementBuilder builder = LookupElementBuilder.create(name);
	builder = builder.withInsertHandler(MacroInsertHandler.getInstance());
	if (!isEndTag) {
		String appendText = tag.getType() == LatteTagSettings.Type.PAIR ? (" … {/" + tag.getMacroName() + "}") : "";
		String arguments = tag.getArgumentsInfo();
		if (arguments.length() > 0) {
			builder = builder.withTailText(" " + arguments + "}" + appendText);
		} else {
			builder = builder.withTailText("}" + appendText);
		}
	} else {
		builder = builder.withTailText("}");
	}

	if (tag.isDeprecated()) {
		builder = builder.withStrikeoutness(true);
	}
	builder = builder.withPresentableText("{" + name);
	return builder.withIcon(LatteIcons.MACRO);
}
 
Example 4
Source Project: idea-php-toolbox   File: JsonParseUtil.java    License: MIT License 6 votes vote down vote up
@NotNull
public static LookupElementBuilder getDecoratedLookupElementBuilder(@NotNull LookupElementBuilder lookupElement, @Nullable JsonRawLookupElement jsonLookup) {
    if(jsonLookup == null) {
        return lookupElement;
    }

    if(jsonLookup.getTailText() != null) {
        lookupElement = lookupElement.withTailText(jsonLookup.getTailText(), true);
    }

    if(jsonLookup.getTypeText() != null) {
        lookupElement = lookupElement.withTypeText(jsonLookup.getTypeText(), true);
    }

    String iconString = jsonLookup.getIcon();
    if(iconString != null) {
        Icon icon = getLookupIconOnString(iconString);
        if(icon != null) {
            lookupElement = lookupElement.withIcon(icon);
        }
    }

    return lookupElement;
}
 
Example 5
@RequiredReadAction
private static <E extends DotNetGenericParameterListOwner & DotNetQualifiedElement> LookupElementBuilder buildTypeLikeElement(@Nonnull E element, @Nonnull DotNetGenericExtractor extractor)
{
	String genericText = CSharpElementPresentationUtil.formatGenericParameters(element, extractor);

	String name = CSharpNamedElement.getEscapedName(element);

	LookupElementBuilder builder = LookupElementBuilder.create(element, name + (extractor == DotNetGenericExtractor.EMPTY ? "" : genericText));

	builder = builder.withPresentableText(name); // always show only name

	builder = builder.withIcon(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY));

	builder = builder.withTypeText(element.getPresentableParentQName());

	builder = builder.withTailText(genericText, true);

	if(extractor == DotNetGenericExtractor.EMPTY)
	{
		builder = withGenericInsertHandler(element, builder);
	}
	return builder;
}
 
Example 6
private LookupElementBuilder getNodeAttributeLookupElement(Node node, Map<String, String> nodeVars, boolean isShortcut) {

        String nodeName = getNodeName(node);
        LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(nodeName).withIcon(Symfony2Icons.CONFIG_VALUE);

        String textContent = node.getTextContent();
        if(StringUtils.isNotBlank(textContent)) {
            lookupElementBuilder = lookupElementBuilder.withTailText("(" + textContent + ")", true);
        }

        if(nodeVars.containsKey(nodeName)) {
            lookupElementBuilder = lookupElementBuilder.withTypeText(StringUtil.shortenTextWithEllipsis(nodeVars.get(nodeName), 100, 0), true);
        }

        if(isShortcut) {
            lookupElementBuilder = lookupElementBuilder.withIcon(Symfony2Icons.CONFIG_VALUE_SHORTCUT);
        }

        return lookupElementBuilder;
    }
 
Example 7
public LookupElementBuilder createLookupBuilder(@Nonnull final T item) {
  LookupElementBuilder builder = LookupElementBuilder.create(item, getLookupString(item))
    .withIcon(getIcon(item));

  final InsertHandler<LookupElement> handler = createInsertHandler(item);
  if (handler != null) {
    builder = builder.withInsertHandler(handler);
  }

  final String tailText = getTailText(item);
  if (tailText != null) {
    builder = builder.withTailText(tailText, true);
  }

  final String typeText = getTypeText(item);
  if (typeText != null) {
    builder = builder.withTypeText(typeText);
  }
  return builder;
}
 
Example 8
@Nonnull
@Override
public LookupElementBuilder createLookupBuilder(@Nonnull T item) {
  LookupElementBuilder builder = LookupElementBuilder.create(item, getLookupString(item))
          .withIcon(getIcon(item));

  InsertHandler<LookupElement> handler = createInsertHandler(item);
  if (handler != null) {
    builder = builder.withInsertHandler(handler);
  }

  String tailText = getTailText(item);
  if (tailText != null) {
    builder = builder.withTailText(tailText, true);
  }

  String typeText = getTypeText(item);
  if (typeText != null) {
    builder = builder.withTypeText(typeText);
  }
  return builder;
}
 
Example 9
protected void fillCompletionResultSet(@NotNull CompletionResultSet completionResultSet, @NotNull Project project) {
    for(Map.Entry<String, String> entry : EnvironmentVariablesApi.getAllKeyValues(project).entrySet()) {
        LookupElementBuilder lockup = LookupElementBuilder.create(entry.getKey())
                .withLookupString(entry.getKey().toLowerCase());

        if(StringUtils.isNotEmpty(entry.getValue())) {
            lockup = lockup.withTailText(" = " + entry.getValue(), true);
        }

        completionResultSet.addElement(PrioritizedLookupElement.withPriority(lockup, 100));
    }
}
 
Example 10
private static void addBooleanSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer,
                                          String deprecated, String defaultValue, boolean xmlMode) {
    // for boolean types then give a choice between true|false
    String lookup = val + "true";
    LookupElementBuilder builder = LookupElementBuilder.create(lookup);
    builder = addInsertHandler(editor, suffix, builder, xmlMode);
    // only show the option in the UI
    builder = builder.withPresentableText("true");
    if ("true".equals(deprecated)) {
        // mark as deprecated
        builder = builder.withStrikeoutness(true);
    }
    boolean isDefaultValue = defaultValue != null && "true".equals(defaultValue);
    if (isDefaultValue) {
        builder = builder.withTailText(" (default value)");
        // add default value first in the list
        answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
    } else {
        answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
    }

    lookup = val + "false";
    builder = LookupElementBuilder.create(lookup);
    builder = addInsertHandler(editor, suffix, builder, xmlMode);
    // only show the option in the UI
    builder = builder.withPresentableText("false");
    if ("true".equals(deprecated)) {
        // mark as deprecated
        builder = builder.withStrikeoutness(true);
    }
    isDefaultValue = defaultValue != null && "false".equals(defaultValue);
    if (isDefaultValue) {
        builder = builder.withTailText(" (default value)");
        // add default value first in the list
        answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
    } else {
        answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
    }
}
 
Example 11
private static void addDefaultValueSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer,
                                               String deprecated, String defaultValue, boolean xmlMode) {
    String lookup = val + defaultValue;
    LookupElementBuilder builder = LookupElementBuilder.create(lookup);
    builder = addInsertHandler(editor, suffix, builder, xmlMode);
    // only show the option in the UI
    builder = builder.withPresentableText(defaultValue);
    if ("true".equals(deprecated)) {
        // mark as deprecated
        builder = builder.withStrikeoutness(true);
    }
    builder = builder.withTailText(" (default value)");
    // there is only one value in the list and its the default value, so never auto complete it but show as suggestion
    answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE));
}
 
Example 12
private void completeObjectValueField() {
    CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
        @Override
        protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {

            final PsiElement completionElement = parameters.getPosition();
            final GraphQLTypeScopeProvider typeScopeProvider = PsiTreeUtil.getParentOfType(completionElement, GraphQLObjectValueImpl.class);
            if (typeScopeProvider != null) {
                GraphQLType typeScope = typeScopeProvider.getTypeScope();
                if (typeScope != null) {
                    // unwrap lists, non-null etc:
                    typeScope = GraphQLUtil.getUnmodifiedType(typeScope);
                    if (typeScope instanceof GraphQLInputFieldsContainer) {
                        final List<GraphQLInputObjectField> fieldDefinitions = ((GraphQLInputFieldsContainer) typeScope).getFieldDefinitions();
                        final GraphQLObjectValue objectValue = PsiTreeUtil.getParentOfType(completionElement, GraphQLObjectValue.class);
                        if (objectValue != null) {
                            // get the existing object field names to filter them out
                            final Set<String> existingFieldNames = objectValue.getObjectFieldList().stream().map(PsiNamedElement::getName).collect(Collectors.toSet());
                            for (GraphQLInputObjectField fieldDefinition : fieldDefinitions) {
                                if (!existingFieldNames.contains(fieldDefinition.getName())) {
                                    LookupElementBuilder element = LookupElementBuilder.create(fieldDefinition.getName()).withTypeText(SchemaIDLUtil.typeString(fieldDefinition.getType()));
                                    if (fieldDefinition.getDescription() != null) {
                                        final String fieldDocumentation = GraphQLDocumentationMarkdownRenderer.getDescriptionAsPlainText(fieldDefinition.getDescription(), true);
                                        element = element.withTailText(" - " + fieldDocumentation, true);
                                    }
                                    result.addElement(element.withInsertHandler(AddColonSpaceInsertHandler.INSTANCE_WITH_AUTO_POPUP));
                                }
                            }
                        }
                    }
                }
            }

        }
    };
    extend(CompletionType.BASIC, psiElement(GraphQLElementTypes.NAME).withSuperParent(2, GraphQLObjectField.class), provider);
}
 
Example 13
private LookupElementBuilder createBuilderWithHelp(LatteFunctionSettings settings) {
	LookupElementBuilder builder = LookupElementBuilder.create(settings.getFunctionName());
	builder = builder.withIcon(PhpIcons.FUNCTION_ICON);
	builder = builder.withInsertHandler(MacroCustomFunctionInsertHandler.getInstance());
	if (settings.getFunctionHelp().trim().length() > 0) {
		builder = builder.withTailText(settings.getFunctionHelp());
	}
	return builder.withTypeText(settings.getFunctionReturnType());
}
 
Example 14
private LookupElementBuilder createBuilderWithHelp(LatteFilterSettings modifier) {
	LookupElementBuilder builder = LookupElementBuilder.create(modifier.getModifierName());
	if (modifier.getModifierDescription().trim().length() > 0) {
		builder = builder.withTypeText(modifier.getModifierDescription());
	}
	if (modifier.getModifierHelp().trim().length() > 0) {
		builder = builder.withTailText(modifier.getModifierHelp());
	}
	builder = builder.withInsertHandler(FilterInsertHandler.getInstance());
	return builder.withIcon(LatteIcons.MODIFIER);
}
 
Example 15
@Nullable
public static LookupElementBuilder create(@NotNull HaxeModel model, @Nullable String alias) {
  PsiElement basePsi = model.getBasePsi();
  HaxeNamedComponent namedComponent = getNamedComponent(basePsi);

  if (namedComponent == null) return null;

  String name = StringUtil.defaultIfEmpty(alias, model.getName());
  String presentableText = null;
  String tailText = getParentPath(model);
  Icon icon = null;

  ItemPresentation presentation = namedComponent.getPresentation();
  if (presentation != null) {
    icon = presentation.getIcon(false);
    presentableText = presentation.getPresentableText();
  }

  LookupElementBuilder lookupElement = LookupElementBuilder.create(basePsi, name);

  if (presentableText != null) {
    if (alias != null && presentableText.startsWith(model.getName())) {
      presentableText = presentableText.replace(model.getName(), alias);
    }
    lookupElement = lookupElement.withPresentableText(presentableText);
  }

  if (icon != null) lookupElement = lookupElement.withIcon(icon);

  if (tailText != null) {
    if (alias != null) {
      tailText = HaxeBundle.message("haxe.lookup.alias", tailText + "." + model.getName());
    }
    tailText = " " + tailText;
    lookupElement = lookupElement.withTailText(tailText, true);
  }

  return lookupElement;
}
 
Example 16
private void buildLookupElements(CompletionResultSet completionResultSet, QueryBuilderScopeContext collect) {
    for(Map.Entry<String, QueryBuilderPropertyAlias> entry: collect.getPropertyAliasMap().entrySet()) {
        DoctrineModelField field = entry.getValue().getField();
        LookupElementBuilder lookup = LookupElementBuilder.create(entry.getKey());
        lookup = lookup.withIcon(Symfony2Icons.DOCTRINE);
        if(field != null) {
            lookup = lookup.withTypeText(field.getTypeName(), true);

            if(field.getRelationType() != null) {
                lookup = lookup.withTailText("(" + field.getRelationType() + ")", true);
                lookup = lookup.withTypeText(field.getRelation(), true);
                lookup = lookup.withIcon(PhpIcons.CLASS_ICON);
            } else {
                // relation tail text wins
                String column = field.getColumn();
                if(column != null) {
                    lookup = lookup.withTailText("(" + column + ")", true);
                }
            }

        }

        // highlight fields which are possible in select statement
        if(collect.getSelects().contains(entry.getValue().getAlias())) {
            lookup = lookup.withBoldness(true);
        }

        completionResultSet.addElement(lookup);

    }
}
 
Example 17
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {

    Collection<LookupElement> elements = new ArrayList<>();

    Map<String, CommandArg> targets = getCommandConfigurationMap(phpClass, addMethod);

    for(CommandArg key: targets.values()) {
        LookupElementBuilder lookup = LookupElementBuilder.create(key.getName()).withIcon(Symfony2Icons.SYMFONY);

        String description = key.getDescription();
        if(description != null) {

            if(description.length() > 25) {
                description = StringUtils.abbreviate(description, 25);
            }

            lookup = lookup.withTypeText(description, true);
        }

        if(key.getDefaultValue() != null) {
            lookup = lookup.withTailText("(" + key.getDefaultValue() + ")", true);
        }

        elements.add(lookup);
    }

    return elements;
}
 
Example 18
Source Project: consulo   File: FileInfoManager.java    License: Apache License 2.0 5 votes vote down vote up
public LookupElementBuilder _getLookupItem(@Nonnull final PsiFile file, String name, Icon icon) {
  LookupElementBuilder builder = LookupElementBuilder.create(file, name).withIcon(icon);

  final String info = _getInfo(file);
  if (info != null) {
    return builder.withTailText(String.format(" (%s)", info), true);
  }

  return builder;
}
 
Example 19
@Nonnull
@RequiredReadAction
private static LookupElementBuilder buildLookupItem(UnityFunctionManager.FunctionInfo functionInfo, CSharpTypeDeclaration scope)
{
	StringBuilder builder = new StringBuilder();

	builder.append("void ");
	builder.append(functionInfo.getName());
	builder.append("(");

	boolean first = true;
	for(Map.Entry<String, String> entry : functionInfo.getParameters().entrySet())
	{
		if(first)
		{
			first = false;
		}
		else
		{
			builder.append(", ");
		}

		DotNetTypeRef typeRef = UnityFunctionManager.createTypeRef(scope, entry.getValue());
		builder.append(CSharpTypeRefPresentationUtil.buildShortText(typeRef, scope));
		builder.append(" ");
		builder.append(entry.getKey());
	}
	builder.append(")");

	String presentationText = builder.toString();
	builder.append("{\n");
	builder.append("}");

	LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(builder.toString());
	lookupElementBuilder = lookupElementBuilder.withPresentableText(presentationText);
	lookupElementBuilder = lookupElementBuilder.withLookupString(functionInfo.getName());
	lookupElementBuilder = lookupElementBuilder.withTailText("{...}", true);

	IconDescriptor iconDescriptor = new IconDescriptor(new IconDescriptor(AllIcons.Nodes.Method).toIcon());
	iconDescriptor.setRightIcon(Unity3dIcons.EventMethod);

	lookupElementBuilder = lookupElementBuilder.withIcon(iconDescriptor.toIcon());

	lookupElementBuilder = lookupElementBuilder.withInsertHandler(new InsertHandler<LookupElement>()
	{
		@Override
		@RequiredUIAccess
		public void handleInsert(InsertionContext context, LookupElement item)
		{
			CaretModel caretModel = context.getEditor().getCaretModel();

			PsiElement elementAt = context.getFile().findElementAt(caretModel.getOffset() - 1);
			if(elementAt == null)
			{
				return;
			}

			DotNetVirtualImplementOwner virtualImplementOwner = PsiTreeUtil.getParentOfType(elementAt, DotNetVirtualImplementOwner.class);
			if(virtualImplementOwner == null)
			{
				return;
			}

			if(virtualImplementOwner instanceof CSharpMethodDeclaration)
			{
				PsiElement codeBlock = ((CSharpMethodDeclaration) virtualImplementOwner).getCodeBlock().getElement();
				if(codeBlock instanceof CSharpBlockStatementImpl)
				{
					DotNetStatement[] statements = ((CSharpBlockStatementImpl) codeBlock).getStatements();
					if(statements.length > 0)
					{
						caretModel.moveToOffset(statements[0].getTextOffset() + statements[0].getTextLength());
					}
					else
					{
						caretModel.moveToOffset(((CSharpBlockStatementImpl) codeBlock).getLeftBrace().getTextOffset() + 1);
					}
				}
			}

			context.commitDocument();

			CodeStyleManager.getInstance(context.getProject()).reformat(virtualImplementOwner);
		}
	});
	return lookupElementBuilder;
}
 
Example 20
@Nonnull
@RequiredReadAction
private static LookupElement buildForMethodReference(final CSharpMethodDeclaration methodDeclaration, CSharpTypeDeclaration contextType, final CSharpReferenceExpressionEx expression)
{
	LookupElementBuilder builder = LookupElementBuilder.create(methodDeclaration.getName());
	builder = builder.withIcon((Image) AllIcons.Nodes.MethodReference);

	final DotNetTypeRef[] parameterTypes = methodDeclaration.getParameterTypeRefs();

	String genericText = DotNetElementPresentationUtil.formatGenericParameters(methodDeclaration);

	String parameterText = genericText + "(" + StringUtil.join(parameterTypes, new Function<DotNetTypeRef, String>()
	{
		@Override
		@RequiredReadAction
		public String fun(DotNetTypeRef parameter)
		{
			return CSharpTypeRefPresentationUtil.buildShortText(parameter, methodDeclaration);
		}
	}, ", ") + ")";

	if(CSharpMethodImplUtil.isExtensionWrapper(methodDeclaration))
	{
		builder = builder.withItemTextUnderlined(true);
	}
	builder = builder.withTypeText(CSharpTypeRefPresentationUtil.buildShortText(methodDeclaration.getReturnTypeRef(), methodDeclaration), true);
	builder = builder.withTailText(parameterText, true);
	if(DotNetAttributeUtil.hasAttribute(methodDeclaration, DotNetTypes.System.ObsoleteAttribute))
	{
		builder = builder.withStrikeoutness(true);
	}
	builder = builder.withInsertHandler(new InsertHandler<LookupElement>()
	{
		@Override
		@RequiredWriteAction
		public void handleInsert(InsertionContext context, LookupElement item)
		{
			char completionChar = context.getCompletionChar();
			switch(completionChar)
			{
				case ',':
					if(expression != null && expression.getParent() instanceof CSharpCallArgument)
					{
						context.setAddCompletionChar(false);
						TailType.COMMA.processTail(context.getEditor(), context.getTailOffset());
					}
					break;
			}
		}
	});

	if(contextType != null && contextType.isEquivalentTo(methodDeclaration.getParent()))
	{
		builder = builder.bold();
	}

	CSharpCompletionSorting.force(builder, CSharpCompletionSorting.KindSorter.Type.member);
	return builder;
}