@NotNull public static LookupElement createLabelLookupElement(@NotNull GoLabelDefinition l, @NotNull String lookupString) { return PrioritizedLookupElement.withPriority(LookupElementBuilder.createWithSmartPointer(lookupString, l).withIcon(GoIcons.LABEL), LABEL_PRIORITY); }
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement psiElement = completionParameters.getOriginalPosition(); if (!Symfony2ProjectComponent.isEnabled(psiElement)) { return; } MethodReference methodReference = PhpElementsUtil.findMethodReferenceOnClassConstant(psiElement); if (methodReference == null) { return; } if(!( PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Doctrine\\Common\\Persistence\\ObjectManager", "getRepository") || PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Doctrine\\Common\\Persistence\\ManagerRegistry", "getRepository") )) { return; } Collection<DoctrineModel> modelClasses = EntityHelper.getModelClasses(psiElement.getProject()); for (DoctrineModel doctrineModel : modelClasses) { PhpClass phpClass = doctrineModel.getPhpClass(); if(phpClass.isAbstract() || phpClass.isInterface()) { continue; } LookupElement elementBuilder = new Foo(phpClass); // does this have an effect really? completionResultSet.addElement( PrioritizedLookupElement.withExplicitProximity(PrioritizedLookupElement.withPriority(elementBuilder, 1000), 1000) ); } }
static Collection<LookupElement> createFromPsiItems(Collection<? extends PsiNamedElement> elements, @Nullable Icon icon, @Nullable Integer groupId) { return elements.stream().map(psi -> { LookupElementBuilder element = LookupElementBuilder.create(psi).withCaseSensitivity(true); if (icon != null) { element = element.withIcon(icon); } if (groupId != null) { return PrioritizedLookupElement.withGrouping(element, groupId); } return element; }).collect(Collectors.toList()); }
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement psiElement = completionParameters.getOriginalPosition(); if (!Symfony2ProjectComponent.isEnabled(psiElement)) { return; } MethodReference methodReference = PhpElementsUtil.findMethodReferenceOnClassConstant(psiElement); if(methodReference == null) { return; } if(!( PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Symfony\\Component\\Form\\FormBuilderInterface", "add") || PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Symfony\\Component\\Form\\FormBuilderInterface", "create") || PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Symfony\\Component\\Form\\FormFactoryInterface", "createNamedBuilder") || PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Symfony\\Component\\Form\\FormFactoryInterface", "createNamed") )) { return; } for (PhpClass phpClass : PhpIndex.getInstance(psiElement.getProject()).getAllSubclasses("\\Symfony\\Component\\Form\\FormTypeInterface")) { if(phpClass.isAbstract() || phpClass.isInterface()) { continue; } LookupElement elementBuilder = new FormClassConstantsLookupElement(phpClass); // does this have an effect really? completionResultSet.addElement( PrioritizedLookupElement.withExplicitProximity(PrioritizedLookupElement.withPriority(elementBuilder, 1000), 1000) ); } }
static Collection<LookupElement> createPathItems(List<String> osPathes) { return osPathes.stream() .map(path -> //fix the windows file and directory pathes to be cygwin compatible SystemInfoRt.isWindows ? OSUtil.toBashCompatible(path) : path ) .map(path -> { int groupId = path.startsWith("/") ? CompletionGrouping.AbsoluteFilePath.ordinal() : CompletionGrouping.RelativeFilePath.ordinal(); return PrioritizedLookupElement.withGrouping(createPathLookupElement(path, !path.endsWith("/")), groupId); }).collect(Collectors.toList()); }
@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); }
static Collection<LookupElement> createItems(Collection<String> lookupStrings, final Icon icon, boolean trimLookupString, Integer groupId) { return lookupStrings .stream() .map(item -> { LookupElementBuilder elementBuilder = LookupElementBuilder.create(item).withCaseSensitivity(true); if (icon != null) { elementBuilder = elementBuilder.withIcon(icon); } if (trimLookupString) { elementBuilder = elementBuilder.withLookupString(item.replace("_", "")); } if (groupId != null) { return PrioritizedLookupElement.withGrouping(elementBuilder, groupId); } return elementBuilder; }) .collect(Collectors.toList()); }
@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); }
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); }
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)); }
@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 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 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 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); }