Java Code Examples for com.intellij.codeInsight.completion.CompletionResultSet

The following examples show how to use com.intellij.codeInsight.completion.CompletionResultSet. 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
@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 2
@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 Project: yiistorm   Source File: YiiAppCompletionProvider.java    License: 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 Project: idea-php-typo3-plugin   Source File: FluidUtil.java    License: 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 5
Source Project: idea-php-typo3-plugin   Source File: FluidUtil.java    License: 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 6
Source Project: bamboo-soy   Source File: SoyCompletionContributor.java    License: 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 7
@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 8
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 9
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 10
Source Project: intellij   Source File: DebuggerCompletionContributor.java    License: 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 11
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 12
Source Project: consulo-csharp   Source File: CSharpCompletionUtil.java    License: 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 13
Source Project: Intellij-Plugin   Source File: StepCompletionProvider.java    License: 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 14
Source Project: elm-plugin   Source File: ElmModuleCompletionProvider.java    License: 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 15
Source Project: litho   Source File: OnEventCompletionProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void addCompletions(
    CompletionParameters parameters, ProcessingContext context, CompletionResultSet result) {
  final Optional<PsiClass> maybeCls =
      CompletionUtils.findFirstParent(parameters.getPosition(), LithoPluginUtils::isLithoSpec);
  if (!maybeCls.isPresent()) return;

  final PsiClass lithoSpecCls = maybeCls.get();
  final PsiClass clickEventCls =
      getOrCreateClass(LithoClassNames.CLICK_EVENT_CLASS_NAME, lithoSpecCls.getProject());
  final PsiMethod onEventMethod =
      OnEventGenerateUtils.createOnEventMethod(
          lithoSpecCls, clickEventCls, Collections.emptyList());
  result.addElement(
      PrioritizedLookupElement.withPriority(
          createMethodLookup(
              onEventMethod,
              clickEventCls,
              OnEventGenerateUtils.createOnEventLookupString(clickEventCls),
              () -> {
                final Map<String, String> data = new HashMap<>();
                data.put(EventLogger.KEY_TARGET, EventLogger.VALUE_COMPLETION_TARGET_METHOD);
                data.put(EventLogger.KEY_CLASS, "OnEvent");
                LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_COMPLETION, data);
                LithoPluginUtils.getFirstLayoutSpec(parameters.getOriginalFile())
                    .ifPresent(ComponentGenerateUtils::updateLayoutComponent);
              }),
          Integer.MAX_VALUE));
}
 
Example 16
Source Project: litho   Source File: LayoutSpecMethodAnnotationsProvider.java    License: 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 17
@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 18
private void addBuiltInVariables(CompletionResultSet result, Project project) {
    if (BashProjectSettings.storedSettings(project).isAutocompleteBuiltinVars()) {
        Collection<LookupElement> shellBuiltIns = CompletionProviderUtils.createItems(LanguageBuiltins.bashShellVars, BashIcons.BASH_VAR_ICON, true, CompletionGrouping.BuiltInVar.ordinal());
        result.addAllElements(shellBuiltIns);

        Collection<LookupElement> bashBuiltIns = CompletionProviderUtils.createItems(LanguageBuiltins.bourneShellVars, BashIcons.BOURNE_VAR_ICON, true, CompletionGrouping.BuiltInVar.ordinal());
        result.addAllElements(bashBuiltIns);
    }
}
 
Example 19
@Override
public void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {

    PsiElement psiElement = completionParameters.getPosition().getParent();

    Collection<PhpDocParamTag> docTags = PhpDocUtil.getDocTagsForScope(psiElement);
    if(docTags == null || docTags.size() == 0) {
        return;
    }

    PhpToolboxCompletionContributorParameter parameter = null;

    for(PhpDocParamTag phpDocParamTag: docTags) {
        String providerName = extractProviderName(phpDocParamTag.getText());
        if(providerName == null) {
            continue;
        }

        List<PhpToolboxProviderInterface> filter = getProvidersByName(
            psiElement,
            providerName
        );

        if(filter.size() == 0) {
            continue;
        }

        if(parameter == null) {
            parameter = new PhpToolboxCompletionContributorParameter(completionParameters, context, resultSet, new HashSet<>());
        }

        for (PhpToolboxProviderInterface provider : filter) {
            resultSet.addAllElements(provider.getLookupElements(parameter));
        }
    }
}
 
Example 20
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 21
protected void setupCompletions(@NotNull Project project, @NotNull CompletionResultSet result) {
  CompletionService completionService = CompletionService.getInstance(project);
  List<Formatter> formatters = completionService.getFormatters();
  Collection<Pair<String, String>> branchInfos = getBranchInfo(completionService);
  log.debug("Setup completions for: ", branchInfos);
  branchInfos.forEach(branchInfo -> {
    String branchName = branchInfo.getFirst();
    formatters.forEach(formatter -> addCompletion(result, formatter, branchName, branchInfo.getSecond()));
  });
}
 
Example 22
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
	try {
		doAddCompletions(parameters, context, result);
	} catch (Exception ignore) {

	}
}
 
Example 23
Source Project: yiistorm   Source File: PhpElementsUtil.java    License: MIT License 5 votes vote down vote up
static public void addClassPublicMethodCompletion(CompletionResultSet completionResultSet, PhpClass phpClass) {
    for (Method method : phpClass.getMethods()) {
        if (method.getAccess().isPublic() && !method.getName().startsWith("__")) {
            completionResultSet.addElement(new PhpLookupElement(method));
        }
    }
}
 
Example 24
Source Project: consulo-csharp   Source File: CSharpCompletionSorting.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
private static LookupElementWeigher recursiveSorter(CompletionParameters completionParameters, CompletionResultSet result)
{
	PsiElement position = completionParameters.getPosition();


	Set<PsiElement> elements = new THashSet<>();

	PsiElement argumentListOwner = PsiTreeUtil.getContextOfType(position, CSharpCallArgumentListOwner.class, DotNetVariable.class);
	if(argumentListOwner instanceof CSharpMethodCallExpressionImpl)
	{
		ContainerUtil.addIfNotNull(elements, ((CSharpMethodCallExpressionImpl) argumentListOwner).resolveToCallable());
	}
	else if(argumentListOwner instanceof DotNetVariable)
	{
		elements.add(argumentListOwner);
	}

	List<CSharpForeachStatementImpl> foreachStatements = SyntaxTraverser.psiApi().parents(position).filter(CSharpForeachStatementImpl.class).addAllTo(new ArrayList<>());
	for(CSharpForeachStatementImpl foreachStatement : foreachStatements)
	{
		DotNetExpression iterableExpression = foreachStatement.getIterableExpression();
		if(iterableExpression instanceof CSharpReferenceExpression)
		{
			ContainerUtil.addIfNotNull(elements, ((CSharpReferenceExpression) iterableExpression).resolve());
		}
	}

	if(!elements.isEmpty())
	{
		return new CSharpRecursiveGuardWeigher(elements);
	}
	return null;
}
 
Example 25
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement psiElement = parameters.getPosition();

    if (psiElement instanceof LeafPsiElement) {
        // Don't complete after tag (at end of line)
        // key: !my_tag <caret>\n
        if (YamlHelper.isElementAfterYamlTag(psiElement)) {
            return;
        }

        // Don't complete after End Of Line:
        // key: foo\n
        // <caret>
        if (YamlHelper.isElementAfterEol(psiElement)) {
            return;
        }

        String prefix = psiElement.getText();

        if (prefix.contains(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED)) {
            prefix = prefix.substring(0, prefix.indexOf(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED));
        }

        result = result.withPrefixMatcher(prefix);
    }

    for (Map.Entry<String, String> entry : YAML_KEYWORDS.entrySet()) {
        String yamlKeyword = entry.getKey();
        String yamlType = entry.getValue();

        LookupElementBuilder lookupElement = LookupElementBuilder.create(yamlKeyword)
                .withTypeText(yamlType);

        result.addElement(lookupElement);
    }
}
 
Example 26
Source Project: idea-php-dotenv-plugin   Source File: BaseEnvCompletionProvider.java    License: 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 27
Source Project: intellij-latte   Source File: LattePhpCompletionProvider.java    License: 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 28
Source Project: arma-intellij-plugin   Source File: CompletionAdders.java    License: 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 29
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 30
Source Project: intellij-swagger   Source File: SwaggerValueFactory.java    License: 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();
  }
}