@NotNull public static LookupElement createLabelLookupElement(@NotNull GoLabelDefinition l, @NotNull String lookupString) { return PrioritizedLookupElement.withPriority(LookupElementBuilder.createWithSmartPointer(lookupString, l).withIcon(GoIcons.LABEL), LABEL_PRIORITY); }
@NotNull public static LookupElement createVariableLikeLookupElement(@NotNull GoNamedElement v, @NotNull String lookupString, @Nullable InsertHandler<LookupElement> insertHandler, double priority) { return PrioritizedLookupElement.withPriority(LookupElementBuilder.createWithSmartPointer(lookupString, v) .withRenderer(Lazy.VARIABLE_RENDERER) .withInsertHandler(insertHandler), priority); }
@NotNull private static LookupElement packageLookup(@NotNull String packageName, int priority) { LookupElement element = withPriority(LookupElementBuilder.create(packageName), priority); return AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(element); }
@NotNull public static LookupElement createFunctionOrMethodLookupElement(@NotNull GoNamedSignatureOwner f, @NotNull String lookupString, @Nullable InsertHandler<LookupElement> h, double priority) { return PrioritizedLookupElement.withPriority(LookupElementBuilder .createWithSmartPointer(lookupString, f) .withRenderer(Lazy.FUNCTION_RENDERER) .withInsertHandler(h != null ? h : Lazy.VARIABLE_OR_FUNCTION_INSERT_HANDLER), priority); }
private static void addLookupElement(@NotNull String lookupString, int initialPriority, @NotNull Set<String> allTestFunctionNames, @NotNull CompletionResultSet result) { int priority = initialPriority; if (allTestFunctionNames.contains(lookupString)) { priority -= 5; lookupString = UniqueNameGenerator.generateUniqueName(lookupString, allTestFunctionNames); } result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(lookupString) .withInsertHandler(GenerateTestInsertHandler.INSTANCE), priority)); }
public static LookupElement createKeywordLookupElement(@NotNull String keyword, int priority, @Nullable InsertHandler<LookupElement> insertHandler) { LookupElementBuilder builder = LookupElementBuilder.create(keyword).withBoldness(true).withInsertHandler(insertHandler); return PrioritizedLookupElement.withPriority(builder, priority); }
@NotNull public static LookupElement createPackageLookupElement(@NotNull String importPath, @Nullable String contextImportPath, @Nullable PsiDirectory directory, boolean forType) { LookupElementBuilder builder = directory != null ? LookupElementBuilder.create(directory, importPath) : LookupElementBuilder.create(importPath); return PrioritizedLookupElement.withPriority(builder.withLookupString(importPath.substring(Math.max(0, importPath.lastIndexOf('/')))) .withIcon(GoIcons.PACKAGE) .withInsertHandler(forType ? Lazy.PACKAGE_INSERT_HANDLER : null), calculatePackagePriority(importPath, contextImportPath)); }
@NotNull public static LookupElement createTypeLookupElement(@NotNull GoTypeSpec t, @NotNull String lookupString, @Nullable InsertHandler<LookupElement> handler, @Nullable String importPath, double priority) { LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(lookupString, t) .withInsertHandler(handler).withIcon(GoIcons.TYPE); if (importPath != null) builder = builder.withTailText(" " + importPath, true); return PrioritizedLookupElement.withPriority(builder, priority); }
@NotNull public static LookupElement createVariableLookupElement(@NotNull PsiElement element, @Nullable String type) { LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(element.getText(), element) .withIcon(BallerinaIcons.VARIABLE); if (type == null || type.isEmpty()) { builder = builder.withTypeText("Variable"); } else { builder = builder.withTypeText(type); } return PrioritizedLookupElement.withPriority(builder, VARIABLE_PRIORITY); }
@NotNull public static LookupElement createNamespaceLookupElement(@NotNull PsiElement element) { LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(element.getText(), element) .withTypeText("Namespace").withIcon(BallerinaIcons.NAMESPACE); return PrioritizedLookupElement.withPriority(builder, VARIABLE_PRIORITY); }
@NotNull public static LookupElement createWorkerLookupElement(@NotNull PsiElement workerName) { LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(workerName.getText(), workerName) .withTypeText("Worker").withIcon(BallerinaIcons.WORKER); return PrioritizedLookupElement.withPriority(builder, VARIABLE_PRIORITY); }
@NotNull public static LookupElement createServiceLookupElement(@NotNull PsiElement element) { LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(element.getText(), element) .withTypeText("Service").withIcon(BallerinaIcons.SERVICE); return PrioritizedLookupElement.withPriority(builder, VARIABLE_PRIORITY); }
@NotNull public static LookupElement createParameterLookupElement(@NotNull PsiElement element, @Nullable String type, @Nullable String defaultValue) { // Todo - Add support to render default value LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(element.getText(), element) .withIcon(BallerinaIcons.PARAMETER); if (type == null || type.isEmpty()) { builder = builder.withTypeText("Parameter"); } else { builder = builder.withTypeText(type); } if (defaultValue != null && !defaultValue.isEmpty()) { builder = builder.withTailText(" ( = " + defaultValue + " )"); } return PrioritizedLookupElement.withPriority(builder, VARIABLE_PRIORITY); }
public static LookupElement createPackageLookup(@NotNull PsiElement identifier, @Nullable InsertHandler<LookupElement> insertHandler) { LookupElementBuilder builder = LookupElementBuilder.create(identifier.getText()).withTypeText("Package") .withIcon(BallerinaIcons.PACKAGE).withInsertHandler(insertHandler); return PrioritizedLookupElement.withPriority(builder, PACKAGE_PRIORITY); }
public static LookupElement createUnImportedPackageLookup(@Nullable String organization, @NotNull String packageName, @NotNull PsiElement element, @Nullable InsertHandler<LookupElement> insertHandler) { if (organization != null) { element.putUserData(ORGANIZATION_NAME, organization); } LookupElementBuilder builder = LookupElementBuilder.create(element, packageName).withTypeText("Package") .withIcon(BallerinaIcons.PACKAGE).withInsertHandler(insertHandler); if (organization != null) { builder = builder.withTailText("(" + organization + "/" + packageName + ")", true); } else { builder = builder.withTailText("(" + packageName + ")", true); } return PrioritizedLookupElement.withPriority(builder, PACKAGE_PRIORITY); }
@NotNull public static LookupElement createAnnotationLookupElement(@NotNull PsiElement identifier) { BallerinaUserDefineTypeName userDefineTypeName = PsiTreeUtil.getNextSiblingOfType(identifier, BallerinaUserDefineTypeName.class); LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(identifier.getText(), identifier) .withTypeText("Annotation").withIcon(BallerinaIcons.ANNOTATION) .withInsertHandler(userDefineTypeName != null ? BracesInsertHandler.INSTANCE : AddSpaceInsertHandler.INSTANCE); return PrioritizedLookupElement.withPriority(builder, ANNOTATION_PRIORITY); } }
@NotNull public static LookupElement createTypeLookupElement(@NotNull BallerinaTopLevelDefinition definition, @Nullable InsertHandler<LookupElement> insertHandler) { LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(definition.getIdentifier() .getText(), definition).withInsertHandler(insertHandler).withTypeText("Type") .withIcon(definition.getIcon(Iconable.ICON_FLAG_VISIBILITY)).bold(); return PrioritizedLookupElement.withPriority(builder, TYPE_PRIORITY); }
@NotNull public static LookupElement createFieldLookupElement(@NotNull PsiElement fieldName, @NotNull PsiElement ownerName, @NotNull String type, @Nullable String defaultValue, @Nullable InsertHandler<LookupElement> insertHandler, boolean isPublic, boolean isPrivate) { LookupElementBuilder lookupElementBuilder = LookupElementBuilder.createWithSmartPointer(fieldName.getText(), fieldName).withInsertHandler(insertHandler).withTypeText(type).bold(); if (defaultValue == null || defaultValue.isEmpty()) { lookupElementBuilder = lookupElementBuilder.withTailText(" -> " + ownerName.getText(), true); } else { String tailText = "(= " + defaultValue + ") -> " + ownerName.getText(); lookupElementBuilder = lookupElementBuilder.withTailText(tailText, true); } if (isPublic) { lookupElementBuilder = lookupElementBuilder.withIcon(BallerinaIcons.PUBLIC_FIELD); } else { lookupElementBuilder = lookupElementBuilder.withIcon(BallerinaIcons.PRIVATE_FIELD); } return PrioritizedLookupElement.withPriority(lookupElementBuilder, VARIABLE_PRIORITY); }
@NotNull public static LookupElement createFunctionLookupElement(@NotNull BallerinaObjectFunctionDefinition definition, @NotNull PsiElement owner, @Nullable InsertHandler<LookupElement> insertHandler) { BallerinaCallableUnitSignature objectCallableUnitSignature = definition.getCallableUnitSignature(); // We check and confirm that the objectCallableUnitSignature != null before calling the method. BallerinaAnyIdentifierName anyIdentifierName = objectCallableUnitSignature.getAnyIdentifierName(); PsiElement identifier = anyIdentifierName.getIdentifier(); LookupElementBuilder builder = LookupElementBuilder.createWithSmartPointer(identifier.getText(), identifier) .withIcon(BallerinaIcons.FUNCTION).bold().withInsertHandler(insertHandler); // Add parameters. BallerinaReturnParameter returnParameter = objectCallableUnitSignature.getReturnParameter(); if (returnParameter != null) { BallerinaReturnType returnType = returnParameter.getReturnType(); if (returnType != null) { builder = builder.withTypeText(BallerinaPsiImplUtil.formatBallerinaFunctionReturnType(returnType)); } } else { builder = builder.withTypeText("nil"); identifier.putUserData(HAS_A_RETURN_VALUE, "nil"); } // Add return type. BallerinaFormalParameterList formalParameterList = objectCallableUnitSignature.getFormalParameterList(); builder = builder.withTailText(BallerinaPsiImplUtil.formatBallerinaFunctionParameters(formalParameterList) + " -> " + owner.getText()); if (formalParameterList != null) { identifier.putUserData(REQUIRE_PARAMETERS, "YES"); } return PrioritizedLookupElement.withPriority(builder, FUNCTION_PRIORITY); }
return PrioritizedLookupElement.withPriority(builder, FUNCTION_PRIORITY);