com.intellij.codeInsight.completion.CompletionResultSet Java Examples

The following examples show how to use com.intellij.codeInsight.completion.CompletionResultSet. 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: StepCompletionProvider.java    From Intellij-Plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    resultSet.stopHere();
    final String prefix = getPrefix(parameters);

    resultSet = resultSet.withPrefixMatcher(new GaugePrefixMatcher(prefix));
    Module moduleForPsiElement = GaugeUtil.moduleForPsiElement(parameters.getPosition());
    if (moduleForPsiElement == null) {
        return;
    }
    for (Type item : getStepsInModule(moduleForPsiElement)) {
        LookupElementBuilder element = LookupElementBuilder.create(item.getText()).withTypeText(item.getType(), true);
        element = element.withInsertHandler((InsertionContext context1, LookupElement item1) -> {
            if (context1.getCompletionChar() == '\t') {
                context1.getDocument().insertString(context1.getEditor().getCaretModel().getOffset(), "\n");
                PsiDocumentManager.getInstance(context1.getProject()).commitDocument(context1.getDocument());
            }
            PsiElement stepElement = context1.getFile().findElementAt(context1.getStartOffset()).getParent();
            final TemplateBuilder templateBuilder = TemplateBuilderFactory.getInstance().createTemplateBuilder(stepElement);
            replaceStepParamElements(prefix, context1, stepElement, templateBuilder);
            templateBuilder.run(context1.getEditor(), false);
        });
        resultSet.addElement(element);
    }
}
 
Example #2
Source File: SQFVariableCompletionProvider.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
	PsiElement cursor = parameters.getOriginalPosition(); //cursor is on a word
	Project project = parameters.getOriginalFile().getProject();

	boolean originalPositionNull = cursor == null;
	if (originalPositionNull) {
		cursor = parameters.getPosition(); //cursor is after a word
	}
	if (forLocalVars) {
		if (cursor.getText().startsWith("_fnc")) {
			CompletionAdders.addFunctions(parameters, result);
		}
		CompletionAdders.addVariables(parameters, context, result, cursor, true);
	} else {
		if (cursor.getText().startsWith("BIS_")) {
			CompletionAdders.addBISFunctions(project, result);
		} else {
			CompletionAdders.addLiterals(cursor, result, false);
			CompletionAdders.addVariables(parameters, context, result, cursor, false);
			CompletionAdders.addCommands(project, result);
		}
	}
}
 
Example #3
Source File: LSContentAssistProcessor.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    Document document = parameters.getEditor().getDocument();
    Editor editor = parameters.getEditor();
    Project project = parameters.getOriginalFile().getProject();
    int offset = parameters.getOffset();
    initiateLanguageServers(project, document);
    CompletionParams param;
    try {
        param = LSPIJUtils.toCompletionParams(LSPIJUtils.toUri(document), offset, document);
        List<LookupElement> proposals = Collections.synchronizedList(new ArrayList<>());
        this.completionLanguageServersFuture
                .thenComposeAsync(languageServers -> CompletableFuture.allOf(languageServers.stream()
                        .map(languageServer -> languageServer.getTextDocumentService().completion(param)
                                .thenAcceptAsync(completion -> proposals
                                        .addAll(toProposals(project, editor, document, offset, completion, languageServer))))
                        .toArray(CompletableFuture[]::new)))
                .get();
        result.addAllElements(proposals);
    } catch (RuntimeException | InterruptedException | ExecutionException e) {
        LOGGER.warn(e.getLocalizedMessage(), e);
        result.addElement(createErrorProposal(offset, e));
    }
    super.fillCompletionVariants(parameters, result);
}
 
Example #4
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 #5
Source File: FluidUtil.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
public static void completeViewHelpers(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    for (FluidNamespace fluidNamespace : FluidUtil.getFluidNamespaces(parameters.getPosition())) {
        for (ViewHelperProvider viewHelperProvider : ViewHelperProvider.EP_NAME.getExtensions()) {
            viewHelperProvider
                .provideForNamespace(parameters.getPosition().getProject(), fluidNamespace.namespace)
                .forEach((name, vh) -> {
                    LookupElementBuilder elementBuilder;
                    if (parameters.getPosition().getParent() instanceof FluidViewHelperReference) {
                        elementBuilder = LookupElementBuilder.create(vh.name);
                    } else {
                        elementBuilder = LookupElementBuilder.create(fluidNamespace.prefix + ":" + vh.name);
                    }

                    result.addElement(
                        elementBuilder
                            .withPresentableText(fluidNamespace.prefix + ":" + vh.name)
                            .withIcon(vh.icon)
                            .withTypeText(vh.fqn)
                            .withInsertHandler(FluidViewHelperReferenceInsertHandler.INSTANCE)
                            .withPsiElement(parameters.getPosition())
                    );
                });
        }
    }
}
 
Example #6
Source File: FluidUtil.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
public static void completeViewHelperArguments(CompletionParameters parameters, CompletionResultSet result) {
    PsiElement psiElement = parameters.getPosition();

    FluidViewHelperExpr viewHelperExpr = (FluidViewHelperExpr) PsiTreeUtil.findFirstParent(psiElement, p -> p instanceof FluidViewHelperExpr);
    if (viewHelperExpr == null) {
        if (psiElement.getParent().getPrevSibling() instanceof FluidViewHelperExpr) {
            viewHelperExpr = (FluidViewHelperExpr) psiElement.getParent().getPrevSibling();
        } else if (psiElement.getParent() instanceof FluidInlineChain && psiElement.getParent().getFirstChild() instanceof FluidViewHelperExpr) {
            viewHelperExpr = (FluidViewHelperExpr) psiElement.getParent().getFirstChild();
        } else {
            return;
        }
    }

    Map<String, ViewHelper> allViewHelpersInContextByName = ViewHelperUtil.findAllViewHelpersInContextByName(psiElement.getProject(), psiElement);
    String viewHelperExprPresentableName = viewHelperExpr.getPresentableName();
    if (!allViewHelpersInContextByName.containsKey(viewHelperExprPresentableName)) {
        return;
    }

    allViewHelpersInContextByName.get(viewHelperExprPresentableName).arguments.forEach((name, argument) -> {
        result.addElement(FluidUtil.viewHelperArgumentLookupElement(psiElement, name, argument));
    });
}
 
Example #7
Source File: SoyCompletionContributor.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
@Override
public void fillCompletionVariants(
    @NotNull final CompletionParameters parameters,
    @NotNull final CompletionResultSet resultSet) {
  super.fillCompletionVariants(parameters, resultSet);

  // Discard _semantically_ invalid suggestions accepted by CamelHumpMatcher
  // (e.g. @state in @state/@param default initializer). We provide these ourselves.
  resultSet.runRemainingContributors(
      parameters,
      completionResult -> {
        if (completionResult.getLookupElement() != null) {
          if (completionResult.getLookupElement().getLookupString().startsWith("$")) {
            return;
          }
          resultSet.addElement(completionResult.getLookupElement());
        }
      });
}
 
Example #8
Source File: LattePhpNamespaceCompletionProvider.java    From intellij-latte with MIT License 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters params, ProcessingContext context, @NotNull CompletionResultSet result) {
	PsiElement curr = params.getPosition().getOriginalElement();
	if (PsiTreeUtil.getParentOfType(curr, LattePhpContent.class) == null) {
		return;
	}

	PhpIndex phpIndex = PhpIndex.getInstance(curr.getProject());
	String prefix = result.getPrefixMatcher().getPrefix();
	String namespace = "";
	if (prefix.contains("\\")) {
		int index = prefix.lastIndexOf("\\");
		namespace = prefix.substring(0, index) + "\\";
		prefix = prefix.substring(index + 1);
	}
	PhpCompletionUtil.addSubNamespaces(namespace, result.withPrefixMatcher(prefix), phpIndex, PhpNamespaceInsertHandler.getInstance());
}
 
Example #9
Source File: CSharpLinqCompletionContributor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
static void extend(CompletionContributor contributor)
{
	contributor.extend(CompletionType.BASIC, CSharpPatterns.expressionStart(), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@Nonnull CompletionParameters parameters, ProcessingContext context, @Nonnull CompletionResultSet result)
		{
			PsiElement position = parameters.getPosition();
			if(!CSharpModuleUtil.findLanguageVersion(position).isAtLeast(CSharpLanguageVersion._3_0))
			{
				return;
			}
			CSharpReferenceExpressionEx parent = (CSharpReferenceExpressionEx) position.getParent();
			if(parent.getQualifier() != null || parent.kind() != CSharpReferenceExpression.ResolveToKind.ANY_MEMBER)
			{
				return;
			}

			CSharpCompletionUtil.elementToLookup(result, CSharpSoftTokens.FROM_KEYWORD, null, null);
		}
	});
}
 
Example #10
Source File: PhpClassAndParameterCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, final @NotNull CompletionResultSet resultSet) {

        PsiElement psiElement = parameters.getOriginalPosition();
        if(psiElement == null || !Symfony2ProjectComponent.isEnabled(psiElement)) {
            return;
        }

        PhpClassCompletionProvider.addClassCompletion(parameters, resultSet, psiElement, false);

        for( Map.Entry<String, ContainerParameter> entry: ContainerCollectionResolver.getParameters(psiElement.getProject()).entrySet()) {
            resultSet.addElement(
                new ParameterLookupElement(entry.getValue(), ParameterPercentWrapInsertHandler.getInstance(), psiElement.getText())
            );
        }

    }
 
Example #11
Source File: DebuggerCompletionContributor.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
protected void addCompletions(
    CompletionParameters parameters, ProcessingContext context, CompletionResultSet result) {
  PsiFile file = parameters.getOriginalFile();
  SkylarkSourcePosition debugContext = getDebugContext(file);
  if (debugContext == null) {
    return;
  }
  String text = file.getText();
  List<Value> suggestions =
      SkylarkDebugCompletionSuggestions.create(debugContext).getCompletionValues(text);
  if (suggestions.isEmpty()) {
    return;
  }
  suggestions.forEach(
      value ->
          result.addElement(
              LookupElementBuilder.create(value.getLabel())
                  .withIcon(SkylarkDebugValue.getIcon(value))));
}
 
Example #12
Source File: ConfigCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void attachRootConfig(CompletionResultSet completionResultSet, PsiElement element) {

        Document document = getConfigTemplate(ProjectUtil.getProjectDir(element));
        if(document == null) {
            return;
        }

        try {

            // attach config aliases
            NodeList nodeList  = (NodeList) XPathFactory.newInstance().newXPath().compile("//config/*").evaluate(document, XPathConstants.NODESET);
            for (int i = 0; i < nodeList.getLength(); i++) {
                completionResultSet.addElement(LookupElementBuilder.create(getNodeName(nodeList.item(i))).withIcon(Symfony2Icons.CONFIG_VALUE));
            }

        } catch (XPathExpressionException ignored) {
        }

    }
 
Example #13
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 #14
Source File: PhpToolboxCompletionContributorParameter.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
public PhpToolboxCompletionContributorParameter(
    @NotNull CompletionParameters completionParameters,
    @NotNull ProcessingContext processingContext,
    @NotNull CompletionResultSet completionResultSet,
    @NotNull Collection<JsonRegistrar> registrars
) {
    this.completionParameters = completionParameters;
    this.processingContext = processingContext;
    this.completionResultSet = completionResultSet;
    this.registrars = registrars;
}
 
Example #15
Source File: CompletionAdders.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Adds all SQF BIS functions to the result
 */
public static void addBISFunctions(@NotNull Project project, @NotNull CompletionResultSet result) {
	for (String functionName : SQFStatic.LIST_BIS_FUNCTIONS) {
		SQFVariable fnc = PsiUtil.createElement(project, functionName, SQFFileType.INSTANCE, SQFVariable.class);
		if (fnc == null) {
			continue;
		}
		result.addElement(LookupElementBuilder.createWithSmartPointer(functionName, fnc)
				.withIcon(ArmaPluginIcons.ICON_SQF_FUNCTION)
				.appendTailText(" Bohemia Interactive Function", true)
		);
	}
}
 
Example #16
Source File: CSharpDocCompletionContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public CSharpDocCompletionContributor()
{
	extend(CompletionType.BASIC, StandardPatterns.psiElement(CSharpDocTokenType.XML_NAME), new CompletionProvider()
	{
		@RequiredReadAction
		@Override
		public void addCompletions(@Nonnull CompletionParameters parameters, ProcessingContext context, @Nonnull CompletionResultSet result)
		{
			PsiElement parent = parameters.getPosition().getParent();
			if(parent instanceof CSharpDocTagImpl)
			{
				Collection<CSharpDocTagInfo> tags = CSharpDocTagManager.getInstance().getTags();
				for(CSharpDocTagInfo tag : tags)
				{
					result.addElement(LookupElementBuilder.create(tag.getName()));
				}
			}
			else if(parent instanceof CSharpDocAttribute)
			{
				CSharpDocTagInfo tagInfo = ((CSharpDocAttribute) parent).getTagInfo();
				if(tagInfo == null)
				{
					return;
				}
				for(CSharpDocAttributeInfo attributeInfo : tagInfo.getAttributes())
				{
					result.addElement(LookupElementBuilder.create(attributeInfo.getName()));
				}
			}
		}
	});
}
 
Example #17
Source File: ElmModuleCompletionProvider.java    From elm-plugin with MIT License 5 votes vote down vote up
void addCompletions(Project project, String prefix, CompletionResultSet resultSet) {
    String matcherPrefix = resultSet.getPrefixMatcher().getPrefix();
    int dotIndex = matcherPrefix.lastIndexOf('.');
    CompletionResultSet newResultSet = dotIndex < 0
            ? resultSet
            : resultSet.withPrefixMatcher(matcherPrefix.substring(dotIndex + 1));

    ElmModuleIndex.getAllModuleNames(project).stream()
            .map(s -> getModulePart(s, prefix))
            .forEach(optionalString -> optionalString.ifPresent(s -> addStringToResult(s, newResultSet)));
}
 
Example #18
Source File: LocalRefValueCompletion.java    From intellij-swagger with MIT License 5 votes vote down vote up
LocalRefValueCompletion(
    final CompletionHelper completionHelper,
    final CompletionResultSet completionResultSet,
    final String refType) {
  super(completionHelper, completionResultSet);
  this.refType = refType;
}
 
Example #19
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 #20
Source File: CSharpCompletionContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result)
{
	CompletionResultSet resultSet = CSharpCompletionSorting.modifyResultSet(parameters, result);

	super.fillCompletionVariants(parameters, resultSet);

	CSharpNoVariantsDelegator.fillCompletionVariants(parameters, resultSet);
}
 
Example #21
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 #22
Source File: PhpToolboxCompletionContributorParameter.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
public PhpToolboxCompletionContributorParameter(
    @NotNull CompletionParameters completionParameters,
    @NotNull ProcessingContext processingContext,
    @NotNull CompletionResultSet completionResultSet,
    @NotNull Collection<JsonRegistrar> registrars
) {
    this.completionParameters = completionParameters;
    this.processingContext = processingContext;
    this.completionResultSet = completionResultSet;
    this.registrars = registrars;
}
 
Example #23
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 #24
Source File: PropertiesPropertyPlaceholdersSmartCompletion.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void buildResultSet(CompletionResultSet resultSet, VirtualFile virtualFile) {
    getProperties(virtualFile).forEach((key, value) -> {
        String keyStr = (String) key;
        if (!isIgnored(keyStr)) {
            LookupElementBuilder builder = LookupElementBuilder.create(keyStr + "}}")
                    .appendTailText(String.valueOf(value), true)
                    .withTypeText("[" + virtualFile.getPresentableName() + "]", true)
                    .withPresentableText(keyStr + " = ");
            resultSet.withPrefixMatcher(new PlainPrefixMatcher("")).addElement(builder);
        }
    });
}
 
Example #25
Source File: SwaggerValueFactory.java    From intellij-swagger with MIT License 5 votes vote down vote up
@Override
public Optional<ValueCompletion> from(
    SwaggerCompletionHelper swaggerCompletionHelper, CompletionResultSet completionResultSet) {
  if (swaggerCompletionHelper.hasPath("$.info.x-audience")) {
    return Optional.of(new AudienceValueCompletion(swaggerCompletionHelper, completionResultSet));
  } else {
    return Optional.empty();
  }
}
 
Example #26
Source File: XQueryCompletionContributor.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void extendForVariablesOnly() {
    extend(CompletionType.BASIC, referencePattern(XQueryTypes.NCNAME).withReferenceOfAnyOfTypes
                    (XQueryVariableReference.class),
            new CompletionProvider<CompletionParameters>() {
                @Override
                protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context,
                                              @NotNull CompletionResultSet result) {
                    VariableCollector variableCollector = new VariableCollector(parameters
                            .getPosition());
                    result.addAllElements(variableCollector.getProposedLookUpItems());
                }
            });
}
 
Example #27
Source File: CompletionAdders.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Adds all literals to completion set for all parent commands expression at the cursor.
 *
 * @see CommandDescriptor#getAllLiterals()
 */
public static void addLiterals(@NotNull PsiElement cursor, @NotNull CompletionResultSet result, boolean trimQuotes) {
	ASTNode ancestor = PsiUtil.getFirstAncestorOfType(cursor.getNode(), SQFTypes.EXPRESSION_STATEMENT, null);
	if (ancestor == null) {
		return;
	}

	PsiUtil.traverseDepthFirstSearch(ancestor, astNode -> {
		PsiElement nodeAsPsi = astNode.getPsi();
		if (nodeAsPsi == cursor) {
			return true;
		}
		if (!(nodeAsPsi instanceof SQFCommandExpression)) {
			return false;
		}
		SQFCommandExpression commandExpression = (SQFCommandExpression) nodeAsPsi;
		SQFExpressionOperator operator = commandExpression.getExprOperator();

		CommandDescriptor descriptor = SQFSyntaxHelper.getInstance().getDescriptor(operator.getText());
		if (descriptor == null) {
			return false;
		}
		for (String s : descriptor.getAllLiterals()) {
			result.addElement(
					PrioritizedLookupElement.withPriority(LookupElementBuilder.create(trimQuotes ? s.substring(1, s.length() - 1) : s)
							.bold()
							.withTailText(" (" + SQFStatic.getSQFBundle().getString("CompletionContributors.literal") + ")")
							, LITERAL_PRIORITY
					)
			);
		}

		return false;
	});
}
 
Example #28
Source File: LattePhpCompletionProvider.java    From intellij-latte with MIT License 5 votes vote down vote up
@Override
protected void addCompletions(
		@NotNull CompletionParameters parameters,
		ProcessingContext context,
		@NotNull CompletionResultSet result
) {
	PsiElement element = parameters.getPosition().getParent();
	if (
			element instanceof LattePhpStaticVariable
					|| element instanceof LattePhpConstant
					|| (element instanceof LattePhpMethod && ((LattePhpMethod) element).isStatic())) {
		attachPhpCompletions(parameters, context, result, (BaseLattePhpElement) element, true);

	} else if (element instanceof LattePhpProperty || (element instanceof LattePhpMethod && !((LattePhpMethod) element).isStatic())) {
		attachPhpCompletions(parameters, context, result, (BaseLattePhpElement) element, false);

	} else if (!(element instanceof LatteMacroModifier) && !(element instanceof LattePhpString)) {
		classCompletionProvider.addCompletions(parameters, context, result);
		namespaceCompletionProvider.addCompletions(parameters, context, result);

		if (LatteUtil.matchParentMacroName(element, "varType") || LatteUtil.matchParentMacroName(element, "var")) {
			attachVarTypes(result);
		}

		variableCompletionProvider.addCompletions(parameters, context, result);
		functionCompletionProvider.addCompletions(parameters, context, result);
	}
}
 
Example #29
Source File: BaseEnvCompletionProvider.java    From idea-php-dotenv-plugin with MIT License 5 votes vote down vote up
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 #30
Source File: ComponentRefValueCompletion.java    From intellij-swagger with MIT License 5 votes vote down vote up
ComponentRefValueCompletion(
    final CompletionHelper completionHelper,
    final CompletionResultSet completionResultSet,
    final String refType) {
  super(completionHelper, completionResultSet);
  this.refType = refType;
}