com.intellij.lang.parameterInfo.CreateParameterInfoContext Java Examples

The following examples show how to use com.intellij.lang.parameterInfo.CreateParameterInfoContext. 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: XQueryParameterInfoHandlerTest.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
private void doTest(String text, int highlightedParameterIndex, int shownItems) {
    myFixture.configureByText("a.xq", text);
    final XQueryParameterInfoHandler parameterInfoHandler = new XQueryParameterInfoHandler();
    final CreateParameterInfoContext createContext = new FakeCreateParameterInfoContext(myFixture.getEditor(), myFixture.getFile());
    final XQueryArgumentList list = parameterInfoHandler.findElementForParameterInfo(createContext);

    if (highlightedParameterIndex >= 0) {
        assertNotNull(list);
        parameterInfoHandler.showParameterInfo(list, createContext);
        Object[] itemsToShow = createContext.getItemsToShow();
        assertNotNull(itemsToShow);
        assertEquals(shownItems, itemsToShow.length);
    }
    FakeUpdateParameterInfoContext updateContext = new FakeUpdateParameterInfoContext(myFixture.getEditor(), myFixture.getFile());
    final XQueryArgumentList element = parameterInfoHandler.findElementForUpdatingParameterInfo(updateContext);
    if (element == null) {
        assertEquals(-1, highlightedParameterIndex);
    } else {
        assertNotNull(element);
        parameterInfoHandler.updateParameterInfo(element, updateContext);
        assertEquals(highlightedParameterIndex, updateContext.getCurrentParameter());
    }
}
 
Example #2
Source File: ArgumentHintTest.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
private Object[] getItemsToShow() {
    CreateParameterInfoContext createCtx = new MockCreateParameterInfoContext(myFixture.getEditor(), myFixture.getFile());
    CypherInvocation psiElement = parameterInfoHandler.findElementForParameterInfo(createCtx);
    assertNotNull(psiElement);
    parameterInfoHandler.showParameterInfo(psiElement, createCtx);
    return createCtx.getItemsToShow();
}
 
Example #3
Source File: CSharpParameterInfoHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
public PsiElement findElementForParameterInfo(CreateParameterInfoContext context)
{
	final PsiElement at = context.getFile().findElementAt(context.getEditor().getCaretModel().getOffset());
	return resolveCallArgumentListOwner(at);
}
 
Example #4
Source File: CSharpParameterInfoHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public void showParameterInfo(@Nonnull PsiElement element, CreateParameterInfoContext context)
{
	ItemToShow[] itemsToShow = resolveToCallables(element, context);

	if(itemsToShow.length > 0)
	{
		context.setItemsToShow(itemsToShow);
		context.showHint(element, element.getTextRange().getStartOffset(), this);
	}
}
 
Example #5
Source File: CSharpParameterInfoHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
private static ItemToShow[] resolveToCallables(PsiElement element, CreateParameterInfoContext context)
{
	List<ItemToShow> list = new SmartList<>();
	if(element instanceof CSharpCallArgumentListOwner)
	{
		ResolveResult[] resolveResults = ((CSharpCallArgumentListOwner) element).multiResolve(true);

		for(ResolveResult resolveResult : resolveResults)
		{
			CSharpSimpleLikeMethod likeMethod = resolveSimpleMethod(resolveResult, element);
			if(likeMethod != null)
			{
				ItemToShow item = new ItemToShow(likeMethod, element);
				list.add(item);
				if(resolveResult.isValidResult() && context.getHighlightedElement() == null)
				{
					context.setHighlightedElement(item.valid());
				}
			}
		}
	}

	ContainerUtil.sort(list, (o1, o2) ->
	{
		if(o1.isValid())
		{
			return -1;
		}
		if(o2.isValid())
		{
			return 1;
		}
		return o1.myLikeMethod.getParameterInfos().length - o2.myLikeMethod.getParameterInfos().length;
	});
	return ContainerUtil.toArray(list, ItemToShow.ARRAY_FACTORY);
}
 
Example #6
Source File: CSharpGenericParameterInfoHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public PsiElement findElementForParameterInfo(CreateParameterInfoContext context)
{
	final PsiElement at = context.getFile().findElementAt(context.getEditor().getCaretModel().getOffset());
	return PsiTreeUtil.getParentOfType(at, CSharpReferenceExpression.class);
}
 
Example #7
Source File: CSharpGenericParameterInfoHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void showParameterInfo(@Nonnull PsiElement place, CreateParameterInfoContext context)
{
	DotNetGenericParameterListOwner genericParameterOwner = findGenericParameterOwner(context);
	if(genericParameterOwner == null)
	{
		return;
	}
	context.setItemsToShow(new Object[]{genericParameterOwner});
	context.showHint(place, place.getTextRange().getStartOffset(), this);
}
 
Example #8
Source File: XQueryParameterInfoHandler.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
public void showParameterInfo(@NotNull XQueryArgumentList args, CreateParameterInfoContext context) {
    XQueryFunctionCall functionCall = PsiTreeUtil.getParentOfType(args, XQueryFunctionCall.class);
    if (functionCall != null) {
        addItemsToShow(context, functionCall);
        context.showHint(args, args.getTextRange().getStartOffset(), this);
    }
}
 
Example #9
Source File: XQueryParameterInfoHandler.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void addItemsToShow(CreateParameterInfoContext context, XQueryFunctionCall functionCall) {
    ResolveResult[] resolveResults = getFunctionWithAllArities(functionCall);
    List<XQueryFunctionDecl> functionDeclarations = extractFunctionDeclarations(resolveResults);
    if (functionDeclarations.size() > 0) {
        Collections.sort(functionDeclarations, getParameterListSizeComparator());
        context.setItemsToShow(ArrayUtil.toObjectArray(functionDeclarations));
    } else {
        XQueryFile file = (XQueryFile) functionCall.getContainingFile();
        String name = functionCall.getFunctionName().getLocalNameText();
        String prefix = functionCall.getFunctionName().getPrefixText();
        String namespace = file.mapFunctionPrefixToNamespace(prefix);
        context.setItemsToShow(ArrayUtil.toObjectArray(getFunctionsSignatures(file, name, namespace)));
    }
}
 
Example #10
Source File: ORParameterInfoHandlerWithTabActionSupport.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public PsiFunctionCallParams findElementForParameterInfo(@NotNull CreateParameterInfoContext context) {
    return findFunctionParams(context.getFile(), context.getOffset());
}
 
Example #11
Source File: ORParameterInfoHandlerWithTabActionSupport.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@Override
public void showParameterInfo(@NotNull PsiFunctionCallParams paramsOwner, @NotNull CreateParameterInfoContext context) {
    PsiLowerSymbol functionName = PsiTreeUtil.getPrevSiblingOfType(paramsOwner, PsiLowerSymbol.class);
    if (functionName != null) {
        PsiReference reference = functionName.getReference();
        PsiElement resolvedElement = reference == null ? null : reference.resolve();
        if (resolvedElement instanceof PsiNamedElement) {
            PsiElement resolvedParent = resolvedElement.getParent();

            if (resolvedParent instanceof PsiLet) {
                // If it's an alias, resolve to the alias
                String alias = ((PsiLet) resolvedParent).getAlias();
                if (alias != null) {
                    Project project = resolvedElement.getProject();
                    PsiFinder psiFinder = PsiFinder.getInstance(project);
                    PsiVal valFromAlias = psiFinder.findValFromQn(alias);
                    if (valFromAlias == null) {
                        PsiLet letFromAlias = psiFinder.findLetFromQn(alias);
                        if (letFromAlias != null) {
                            resolvedParent = letFromAlias;
                        }
                    } else {
                        resolvedParent = valFromAlias;
                    }
                }
            }

            if (resolvedParent instanceof PsiSignatureElement) {
                PsiSignature signature = ((PsiSignatureElement) resolvedParent).getPsiSignature();
                if (signature != null) {
                    context.setItemsToShow(new Object[]{signature.asHMSignature()});
                    context.showHint(paramsOwner, paramsOwner.getTextOffset(), this);
                } else if (resolvedParent instanceof PsiLet) {
                    PsiLet resolvedLet = (PsiLet) resolvedParent;
                    if (resolvedLet.isFunction()) {
                        // We don't have the real signature, we just display the function arguments
                        PsiFunction function = resolvedLet.getFunction();
                        if (function != null) {
                            Collection<PsiParameter> parameters = function.getParameters();
                            ORSignature hmSignature = new ORSignature(parameters);
                            context.setItemsToShow(new Object[]{hmSignature});
                            context.showHint(paramsOwner, paramsOwner.getTextOffset(), this);
                        }
                    }
                }
            }
        }
    }
}
 
Example #12
Source File: XQueryParameterInfoHandler.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public XQueryArgumentList findElementForParameterInfo(CreateParameterInfoContext context) {
    return getArgumentList(context);
}