Java Code Examples for com.intellij.codeInsight.completion.CompletionResultSet#addElement()

The following examples show how to use com.intellij.codeInsight.completion.CompletionResultSet#addElement() . 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: JSGraphQLEndpointCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
private boolean completeAnnotations(@NotNull CompletionResultSet result, boolean autoImport, PsiFile file, PsiElement completionElement) {
	final JSGraphQLEndpointFieldDefinition field = PsiTreeUtil.getNextSiblingOfType(completionElement, JSGraphQLEndpointFieldDefinition.class);
	final JSGraphQLEndpointProperty property = PsiTreeUtil.getNextSiblingOfType(completionElement, JSGraphQLEndpointProperty.class);
	final JSGraphQLEndpointAnnotation nextAnnotation = PsiTreeUtil.getNextSiblingOfType(completionElement, JSGraphQLEndpointAnnotation.class);
	final boolean afterAtAnnotation = completionElement.getNode().getElementType() == JSGraphQLEndpointTokenTypes.AT_ANNOTATION;
	final boolean isTopLevelCompletion = completionElement.getParent() instanceof JSGraphQLEndpointFile;
	if (afterAtAnnotation || isTopLevelCompletion || field != null || nextAnnotation != null || property != null) {
		final JSGraphQLConfigurationProvider configurationProvider = JSGraphQLConfigurationProvider.getService(file.getProject());
		for (JSGraphQLSchemaEndpointAnnotation endpointAnnotation : configurationProvider.getEndpointAnnotations(file)) {
			String completion = endpointAnnotation.name;
			if (!afterAtAnnotation) {
				completion = "@" + completion;
			}
			LookupElementBuilder element = LookupElementBuilder.create(completion).withIcon(JSGraphQLIcons.Schema.Attribute);
			if(endpointAnnotation.arguments != null && endpointAnnotation.arguments.size() > 0) {
				element = element.withInsertHandler(ParenthesesInsertHandler.WITH_PARAMETERS);
			}
			result.addElement(element);
		}
		return true;
	}
	return false;
}
 
Example 2
Source File: JsxNameCompletionProvider.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
public static void addCompletions(@NotNull PsiElement element, @NotNull CompletionResultSet resultSet) {
    LOG.debug("JSX name expression completion");

    RmlFile originalFile = (RmlFile) element.getContainingFile();
    Project project = originalFile.getProject();
    GlobalSearchScope scope = allScope(project);

    Collection<PsiModule> modules = PsiFinder.getInstance(project).findComponents(scope);
    LOG.debug(" -> Modules found", modules);
    for (PsiModule module : modules) {
        String moduleName = module.getModuleName();
        FileBase containingFile = module instanceof FileBase ? (FileBase) module : (FileBase) module.getContainingFile();
        resultSet.addElement(LookupElementBuilder.
                create(moduleName).
                withIcon(getProvidersIcon(module, 0)).
                withTypeText(module instanceof PsiInnerModule ? containingFile.getModuleName() : containingFile.shortLocation(project)).
                withInsertHandler((context, item) -> insertTagNameHandler(project, context, moduleName)));
    }
}
 
Example 3
Source File: YiiAppCompletionProvider.java    From yiistorm with MIT License 6 votes vote down vote up
protected void addCompletions(@NotNull com.intellij.codeInsight.completion.CompletionParameters completionParameters,
                              ProcessingContext processingContext,
                              @NotNull CompletionResultSet completionResultSet) {

    PsiFile currentFile = completionParameters.getPosition().getContainingFile();
    Project project = currentFile.getProject();
    ConfigParser config = YiiStormProjectComponent.getInstance(project).getYiiConfig();
    if (config != null) {
        HashMap<String, String> classMap = config.getComponentsClassMap();
        if (classMap != null && classMap.size() > 0) {
            for (String componentName : classMap.keySet()) {
                completionResultSet.addElement(new ConfigComponentLookupElement(componentName, project));
            }
        }
    }

}
 
Example 4
Source File: MuleElementCompletionProvider.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
    final Project project = completionParameters.getOriginalFile().getProject();
    final MuleElementDefinitionService instance = MuleElementDefinitionService.getInstance(project);
    final List<MuleModuleDefinition> definitions = instance.getDefinitions();
    for (MuleModuleDefinition definition : definitions) {
        final List<MuleElementDefinition> elementDefinitions = definition.getElementDefinitions();
        for (MuleElementDefinition elementDefinition : elementDefinitions) {
            final LookupElementBuilder lookupElement =
                    LookupElementBuilder.create(elementDefinition.getName())
                            .withCaseSensitivity(false)
                            .withLookupString(definition.getName() + ":" + elementDefinition.getName())
                            .withTypeText("\t" + StringUtil.capitalizeWords(elementDefinition.getType().name().toLowerCase(), "_", true, false), true)
                            .withPresentableText(definition.getName() + ":" + elementDefinition.getName())
                            .withInsertHandler(new MuleElementInsertHandler(elementDefinition.getName(), definition.getName(), definition.getNamespace(), definition.getLocationLookup()));
            completionResultSet.addElement(lookupElement);
        }
    }
    completionResultSet.stopHere();
}
 
Example 5
Source File: RamlCompletionContributor.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet)
{
    final int offset = completionParameters.getOffset() - 1;
    final PsiFile originalFile = completionParameters.getOriginalFile();
    if (RamlUtils.isRamlFile(originalFile))
    {
        final String text = originalFile.getText();
        System.out.println("text = " + text);
        System.out.println("offset = " + offset);
        final Suggestions suggestions = new RamlSuggester().suggestions(text, offset);
        final List<Suggestion> suggestionList = suggestions.getSuggestions();
        for (Suggestion suggestion : suggestionList)
        {
            final LookupElementBuilder map = LookupElementBuilder.create(suggestion.getValue())
                                                                 .withPresentableText(suggestion.getLabel())
                                                                 .withLookupString(suggestion.getLabel())
                                                                 .withLookupString(suggestion.getValue());
            completionResultSet.addElement(map);
        }
    }
}
 
Example 6
Source File: CSharpCompletionUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
public static void elementToLookup(@Nonnull CompletionResultSet resultSet,
		@Nonnull IElementType elementType,
		@Nullable NotNullPairFunction<LookupElementBuilder, IElementType, LookupElement> decorator,
		@Nullable Condition<IElementType> condition)
{
	if(condition != null && !condition.value(elementType))
	{
		return;
	}

	String keyword = ourCache.get(elementType);
	LookupElementBuilder builder = LookupElementBuilder.create(elementType, keyword);
	builder = builder.bold();
	LookupElement item = builder;
	if(decorator != null)
	{
		item = decorator.fun(builder, elementType);
	}

	item.putUserData(KEYWORD_ELEMENT_TYPE, elementType);
	resultSet.addElement(item);
}
 
Example 7
Source File: TableUtil.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public static void completeAvailableTableNames(@NotNull Project project, @NotNull CompletionResultSet completionResultSet) {
    for (String name : TableUtil.getAvailableTableNames(project)) {
        completionResultSet.addElement(new LookupElement() {
            @NotNull
            @Override
            public String getLookupString() {

                return name;
            }
        });
    }
}
 
Example 8
Source File: PhpArrayCallbackGotoCompletion.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Override
public void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    PsiElement position = completionParameters.getPosition();

    PhpClass phpClass = findClassCallback(position);
    if(phpClass == null) {
        return;
    }

    for (Method method : phpClass.getMethods()) {
        String name = method.getName();

        // __construct
        if(name.startsWith("__")) {
            continue;
        }

        LookupElementBuilder lookupElement = LookupElementBuilder.create(name).withIcon(method.getIcon());

        PhpClass containingClass = method.getContainingClass();
        if(containingClass != null) {
            lookupElement = lookupElement.withTypeText(containingClass.getPresentableFQN(), true);
        }

        resultSet.addElement(lookupElement);
    }
}
 
Example 9
Source File: KubernetesYamlCompletionContributor.java    From intellij-kubernetes with Apache License 2.0 5 votes vote down vote up
/**
 * Adds suggestions for possible items to insert under the value of a given {@link YAMLKeyValue}.
 *
 * @param modelProvider the store for model info.
 * @param resultSet the result set to append suggestions to.
 * @param resourceKey the identifier of the resource in question.
 * @param keyValue the {@link YAMLKeyValue} to obtain suggestions for.
 */
private static void addValueSuggestionsForKey(@NotNull final ModelProvider modelProvider, final @NotNull CompletionResultSet resultSet, @NotNull final ResourceTypeKey resourceKey,
        @NotNull final YAMLKeyValue keyValue) {
    final Property keyProperty = KubernetesYamlPsiUtil.propertyForKey(modelProvider, resourceKey, keyValue);
    final Model keyModel = KubernetesYamlPsiUtil.modelForKey(modelProvider, resourceKey, keyValue);
    if (keyProperty != null && keyProperty.getType() == FieldType.BOOLEAN) {
        resultSet.addElement(LookupElementBuilder.create("true").withBoldness(true));
        resultSet.addElement(LookupElementBuilder.create("false").withBoldness(true));
    }
    if (keyModel != null) {
        for (final Entry<String, Property> property : keyModel.getProperties().entrySet()) {
            resultSet.addElement(createKeyLookupElement(property.getKey(), property.getValue()));
        }
    }
}
 
Example 10
Source File: CurrentBranchCompletionProvider.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
private void addCompletion(CompletionResultSet result, Formatter formatter, String branchName, String repoName) {
  Formatted formatted = formatter.format(branchName);
  if (formatted.getDisplayable()) {
    result.addElement(LookupElementBuilder.create(formatted.getText())
        .withTypeText(repoName, true)
        .withIcon(formatter.getIconHandle().getIcon()));
  } else {
    log.debug("Skipped completion: ", formatted);
  }
}
 
Example 11
Source File: ConceptStaticArgCompletionProvider.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void addCompletions(CompletionParameters parameters, ProcessingContext processingContext, CompletionResultSet resultSet) {
    String prefix = getPrefix(parameters);
    resultSet = resultSet.withPrefixMatcher(new PlainPrefixMatcher(prefix));
    Collection<ConceptStaticArg> staticArgs = PsiTreeUtil.collectElementsOfType(parameters.getOriginalFile(), ConceptStaticArg.class);
    for (ConceptStaticArg arg : staticArgs) {
        if (arg != null) {
            String text = arg.getText().replaceFirst("\"", "");
            String textWithoutQuotes = text.substring(0, text.length() - 1);
            if (!textWithoutQuotes.equals(""))
                resultSet.addElement(LookupElementBuilder.create(textWithoutQuotes));
        }
    }
}
 
Example 12
Source File: PrototypeProvider.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    Collection<String> keys = StubIndex.getInstance().getAllKeys(FusionPrototypeDeclarationIndex.KEY, parameters.getPosition().getProject());
    Project project = parameters.getPosition().getProject();

    for (String key : keys) {
        Collection<FusionPrototypeSignature> prototypes = StubIndex.getElements(FusionPrototypeDeclarationIndex.KEY, key, project, GlobalSearchScope.projectScope(project), FusionPrototypeSignature.class );
        for (FusionPrototypeSignature signature : prototypes) {
            if (signature.getType() != null) {
                result.addElement(LookupElementBuilder.create(signature.getType().getText()).withIcon(FusionIcons.PROTOTYPE));
            }
        }
    }
}
 
Example 13
Source File: ConfigCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void getConfigPathLookupElements(CompletionResultSet completionResultSet, Node configNode, boolean isShortcut) {

        // get config on node attributes
        NamedNodeMap attributes = configNode.getAttributes();
        if(attributes.getLength() > 0) {
            Map<String, String> nodeDocVars = getNodeCommentVars(configNode);
            for (int i = 0; i < attributes.getLength(); i++) {
                completionResultSet.addElement(getNodeAttributeLookupElement(attributes.item(i), nodeDocVars, isShortcut));
            }
        }


        // check for additional child node
        if(configNode instanceof Element) {

            NodeList nodeList1 = ((Element) configNode).getElementsByTagName("*");
            for (int i = 0; i < nodeList1.getLength(); i++) {
                LookupElementBuilder nodeTagLookupElement = getNodeTagLookupElement(nodeList1.item(i), isShortcut);
                if(nodeTagLookupElement != null) {
                    completionResultSet.addElement(nodeTagLookupElement);
                }
            }

        }


    }
 
Example 14
Source File: ConceptDynamicArgCompletionProvider.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    String prefix = getPrefix(parameters);
    resultSet = resultSet.withPrefixMatcher(new PlainPrefixMatcher(prefix));
    Collection<ConceptDynamicArg> args = PsiTreeUtil.collectElementsOfType(parameters.getOriginalFile(), ConceptDynamicArg.class);
    for (ConceptDynamicArg arg : args) {
        LookupElementBuilder item = LookupElementBuilder.create(arg.getText().replaceAll("<|>", ""));
        resultSet.addElement(item);
    }
}
 
Example 15
Source File: CompletionAdders.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Adds all SQF commands to the completion result
 */
public static void addCommands(@NotNull Project project, @NotNull CompletionResultSet result) {
	for (String command : SQFStatic.COMMANDS_SET) {
		SQFCommand cmd = PsiUtil.createElement(project, command, SQFFileType.INSTANCE, SQFCommand.class);
		if (cmd == null) {
			continue;
		}
		result.addElement(LookupElementBuilder.createWithSmartPointer(command, cmd)
				.withIcon(ArmaPluginIcons.ICON_SQF_COMMAND)
				.appendTailText(" (Command)", true)
		);
	}
}
 
Example 16
Source File: JSGraphQLEndpointCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
private boolean completeOverrideFields(JSGraphQLEndpointFieldDefinitionSet fieldDefinitionSet, PsiElement completionElement, CompletionResultSet result) {
	if(PsiTreeUtil.getParentOfType(completionElement, JSGraphQLEndpointAnnotation.class) != null) {
		return false;
	}
	final JSGraphQLEndpointObjectTypeDefinition typeDefinition = PsiTreeUtil.getParentOfType(fieldDefinitionSet, JSGraphQLEndpointObjectTypeDefinition.class);
	if (typeDefinition != null) {
		if (typeDefinition.getImplementsInterfaces() != null) {
			final Set<String> implementsNames = typeDefinition.getImplementsInterfaces().getNamedTypeList().stream().map(t -> t.getIdentifier().getText()).collect(Collectors.toSet());
			final Collection<JSGraphQLEndpointInterfaceTypeDefinition> interfaceTypeDefinitions = JSGraphQLEndpointPsiUtil.getKnownDefinitions(
					fieldDefinitionSet.getContainingFile(),
					JSGraphQLEndpointInterfaceTypeDefinition.class,
					false,
					null
			);
			final Set<String> currentFieldNames = fieldDefinitionSet.getFieldDefinitionList().stream().map(f -> f.getProperty().getText()).collect(Collectors.toSet());
			for (JSGraphQLEndpointInterfaceTypeDefinition interfaceTypeDefinition : interfaceTypeDefinitions) {
				if (interfaceTypeDefinition.getNamedTypeDef() != null) {
					if (implementsNames.contains(interfaceTypeDefinition.getNamedTypeDef().getText())) {
						if (interfaceTypeDefinition.getFieldDefinitionSet() != null) {
							for (JSGraphQLEndpointFieldDefinition field : interfaceTypeDefinition.getFieldDefinitionSet().getFieldDefinitionList()) {
								if (!currentFieldNames.contains(field.getProperty().getText())) {
									LookupElementBuilder element = LookupElementBuilder.create(field.getText().trim());
									element = element.withTypeText(" " + interfaceTypeDefinition.getNamedTypeDef().getText(), true);
									result.addElement(element);
								}
							}
						}
					}
				}
			}
			return true;
		}
	}
	return false;
}
 
Example 17
Source File: JSGraphQLEndpointCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
private boolean completeKeywordsAndDefinitionAnnotations(@NotNull CompletionResultSet result, boolean autoImport, PsiElement completionElement, PsiElement leafBeforeCompletion, PsiElement parent) {
	if (parent instanceof JSGraphQLEndpointFile || isTopLevelError(parent)) {

		if (isKeyword(leafBeforeCompletion)) {
			// no keyword suggestions right after another keyword
			return true;
		}

		// implements after TYPE NamedType
		if(completeImplementsKeyword(result, completionElement)) {
			return true;
		}

		for (String keyword : TOP_LEVEL_KEYWORDS) {
			LookupElementBuilder element = LookupElementBuilder.create(keyword).withBoldness(true);
			if(keyword.equals(JSGraphQLEndpointTokenTypes.IMPORT.toString())) {
				element = element.withInsertHandler(JSGraphQLEndpointImportInsertHandler.INSTANCE_WITH_AUTO_POPUP);
			} else {
				element = element.withInsertHandler(AddSpaceInsertHandler.INSTANCE_WITH_AUTO_POPUP);
			}
			result.addElement(element);
		}

		completeAnnotations(result, autoImport, completionElement.getContainingFile(), completionElement);

		return true;

	}
	if(parent instanceof JSGraphQLEndpointAnnotation && parent.getParent() instanceof JSGraphQLEndpointNamedTypeDefinition) {
		// completing inside a definition/top level annotation
		return completeAnnotations(result, autoImport, completionElement.getContainingFile(), completionElement);
	}
	return false;
}
 
Example 18
Source File: BuckTargetCompletionContributor.java    From buck with Apache License 2.0 4 votes vote down vote up
private void addResultForFile(CompletionResultSet result, VirtualFile file, String name) {
  result.addElement(LookupElementBuilder.create(name).withIcon(file.getFileType().getIcon()));
}
 
Example 19
Source File: JSGraphQLEndpointDocCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
public JSGraphQLEndpointDocCompletionContributor() {

		CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
			@SuppressWarnings("unchecked")
			@Override
			protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {

				final PsiFile file = parameters.getOriginalFile();

				if (!(file instanceof JSGraphQLEndpointDocFile)) {
					return;
				}

				final PsiElement completionElement = Optional.ofNullable(parameters.getOriginalPosition()).orElse(parameters.getPosition());
				if (completionElement != null) {
					final PsiComment comment = PsiTreeUtil.getContextOfType(completionElement, PsiComment.class);
					if (comment != null && JSGraphQLEndpointDocPsiUtil.isDocumentationComment(comment)) {

						if (completionElement.getNode().getElementType() == JSGraphQLEndpointDocTokenTypes.DOCVALUE) {
							final JSGraphQLEndpointFieldDefinition fieldDefinition = PsiTreeUtil.getNextSiblingOfType(comment, JSGraphQLEndpointFieldDefinition.class);
							if (fieldDefinition != null && fieldDefinition.getArgumentsDefinition() != null) {
								final List<String> otherDocTagValues = JSGraphQLEndpointDocPsiUtil.getOtherDocTagValues(comment);
								for (JSGraphQLEndpointInputValueDefinition arg : PsiTreeUtil.findChildrenOfType(fieldDefinition.getArgumentsDefinition(), JSGraphQLEndpointInputValueDefinition.class)) {
									final String argName = arg.getInputValueDefinitionIdentifier().getText();
									if (!otherDocTagValues.contains(argName)) {
										result.addElement(LookupElementBuilder.create(argName).withInsertHandler(AddSpaceInsertHandler.INSTANCE));
									}
								}
							}
							return;
						}

						final JSGraphQLEndpointDocTag tagBefore = PsiTreeUtil.getPrevSiblingOfType(completionElement, JSGraphQLEndpointDocTag.class);
						final JSGraphQLEndpointDocTag tagParent = PsiTreeUtil.getParentOfType(completionElement, JSGraphQLEndpointDocTag.class);
						if (tagBefore == null || tagParent != null) {
							String completion = "param";
							final boolean includeAt = completionElement.getNode().getElementType() != JSGraphQLEndpointDocTokenTypes.DOCNAME;
							if (includeAt) {
								completion = "@" + completion;
							}
							result.addElement(LookupElementBuilder.create(completion).withInsertHandler(AddSpaceInsertHandler.INSTANCE_WITH_AUTO_POPUP));
						}
					}
				}
			}
		};

		extend(CompletionType.BASIC, PlatformPatterns.psiElement(), provider);

	}
 
Example 20
Source File: BuckTargetCompletionContributor.java    From buck with Apache License 2.0 4 votes vote down vote up
private void addResultForTarget(CompletionResultSet result, String name) {
  result.addElement(LookupElementBuilder.create(name).withIcon(BuckIcons.FILE_TYPE));
}