Search in sources :

Example 1 with ParameterInformation

use of org.eclipse.lsp4j.ParameterInformation in project eclipse.jdt.ls by eclipse.

the class SignatureHelpRequestor method toSignatureInformation.

public SignatureInformation toSignatureInformation(CompletionProposal methodProposal) {
    SignatureInformation $ = new SignatureInformation();
    StringBuilder desription = descriptionProvider.createMethodProposalDescription(methodProposal);
    $.setLabel(desription.toString());
    $.setDocumentation(this.computeJavaDoc(methodProposal));
    char[] signature = SignatureUtil.fix83600(methodProposal.getSignature());
    char[][] parameterNames = methodProposal.findParameterNames(null);
    char[][] parameterTypes = Signature.getParameterTypes(signature);
    for (int i = 0; i < parameterTypes.length; i++) {
        parameterTypes[i] = Signature.getSimpleName(Signature.toCharArray(SignatureUtil.getLowerBound(parameterTypes[i])));
    }
    if (Flags.isVarargs(methodProposal.getFlags())) {
        int index = parameterTypes.length - 1;
        parameterTypes[index] = convertToVararg(parameterTypes[index]);
    }
    List<ParameterInformation> parameterInfos = new LinkedList<>();
    for (int i = 0; i < parameterTypes.length; i++) {
        StringBuilder builder = new StringBuilder();
        builder.append(parameterTypes[i]);
        builder.append(' ');
        builder.append(parameterNames[i]);
        parameterInfos.add(new ParameterInformation(builder.toString(), null));
    }
    $.setParameters(parameterInfos);
    return $;
}
Also used : SignatureInformation(org.eclipse.lsp4j.SignatureInformation) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) LinkedList(java.util.LinkedList)

Example 2 with ParameterInformation

use of org.eclipse.lsp4j.ParameterInformation in project ballerina by ballerina-lang.

the class SignatureHelpUtil method getSignatureInformation.

/**
 * Get the signature information for the given Ballerina function.
 *
 * @param bInvokableSymbol BLang Invokable symbol
 * @param signatureContext Signature operation context
 * @return {@link SignatureInformation}     Signature information for the function
 */
private static SignatureInformation getSignatureInformation(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
    List<ParameterInformation> parameterInformationList = new ArrayList<>();
    SignatureInformation signatureInformation = new SignatureInformation();
    SignatureInfoModel signatureInfoModel = getSignatureInfoModel(bInvokableSymbol, signatureContext);
    String functionName = bInvokableSymbol.getName().getValue();
    // Join the function parameters to generate the function's signature
    String paramsJoined = signatureInfoModel.getParameterInfoModels().stream().map(parameterInfoModel -> {
        // For each of the parameters, create a parameter info instance
        ParameterInformation parameterInformation = new ParameterInformation(parameterInfoModel.paramValue, parameterInfoModel.description);
        parameterInformationList.add(parameterInformation);
        return parameterInfoModel.toString();
    }).collect(Collectors.joining(", "));
    signatureInformation.setLabel(functionName + "(" + paramsJoined + ")");
    signatureInformation.setParameters(parameterInformationList);
    signatureInformation.setDocumentation(signatureInfoModel.signatureDescription);
    return signatureInformation;
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) Stack(java.util.Stack) ArrayList(java.util.ArrayList) DocTag(org.ballerinalang.model.elements.DocTag) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) Map(java.util.Map) Position(org.eclipse.lsp4j.Position) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) Collectors(java.util.stream.Collectors) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Objects(java.util.Objects) List(java.util.List) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) UtilSymbolKeys(org.ballerinalang.langserver.common.UtilSymbolKeys) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) ArrayList(java.util.ArrayList) ParameterInformation(org.eclipse.lsp4j.ParameterInformation)

Example 3 with ParameterInformation

use of org.eclipse.lsp4j.ParameterInformation in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method signatureHelp.

/**
     * Displays a function's parameters, including which one is currently
     * active. Called automatically by VSCode any time that the user types "(",
     * so be sure to check that a function call is actually happening at the
     * current position.
     */
@Override
public CompletableFuture<SignatureHelp> signatureHelp(TextDocumentPositionParams position) {
    String textDocumentUri = position.getTextDocument().getUri();
    if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
        //we couldn't find a node at the specified location
        return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
    }
    IASNode offsetNode = null;
    IMXMLTagData offsetTag = getOffsetMXMLTag(position);
    if (offsetTag != null) {
        IMXMLTagAttributeData attributeData = getMXMLTagAttributeWithValueAtOffset(offsetTag, currentOffset);
        if (attributeData != null) {
            //some attributes can have ActionScript completion, such as
            //events and properties with data binding
            IClassDefinition tagDefinition = (IClassDefinition) currentProject.resolveXMLNameToDefinition(offsetTag.getXMLName(), offsetTag.getMXMLDialect());
            IDefinition attributeDefinition = currentProject.resolveSpecifier(tagDefinition, attributeData.getShortName());
            if (attributeDefinition instanceof IEventDefinition) {
                IMXMLInstanceNode mxmlNode = (IMXMLInstanceNode) getOffsetNode(position);
                IMXMLEventSpecifierNode eventNode = mxmlNode.getEventSpecifierNode(attributeData.getShortName());
                for (IASNode asNode : eventNode.getASNodes()) {
                    IASNode containingNode = getContainingNodeIncludingStart(asNode, currentOffset);
                    if (containingNode != null) {
                        offsetNode = containingNode;
                    }
                }
                if (offsetNode == null) {
                    offsetNode = eventNode;
                }
            }
        }
    }
    if (offsetNode == null) {
        offsetNode = getOffsetNode(position);
    }
    if (offsetNode == null) {
        //we couldn't find a node at the specified location
        return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
    }
    IFunctionCallNode functionCallNode = getAncestorFunctionCallNode(offsetNode);
    IFunctionDefinition functionDefinition = null;
    if (functionCallNode != null) {
        IExpressionNode nameNode = functionCallNode.getNameNode();
        IDefinition definition = nameNode.resolve(currentUnit.getProject());
        if (definition instanceof IFunctionDefinition) {
            functionDefinition = (IFunctionDefinition) definition;
        } else if (definition instanceof IClassDefinition) {
            IClassDefinition classDefinition = (IClassDefinition) definition;
            functionDefinition = classDefinition.getConstructor();
        } else if (nameNode instanceof IIdentifierNode) {
            //special case for super()
            IIdentifierNode identifierNode = (IIdentifierNode) nameNode;
            if (identifierNode.getName().equals(IASKeywordConstants.SUPER)) {
                ITypeDefinition typeDefinition = nameNode.resolveType(currentProject);
                if (typeDefinition instanceof IClassDefinition) {
                    IClassDefinition classDefinition = (IClassDefinition) typeDefinition;
                    functionDefinition = classDefinitionToConstructor(classDefinition);
                }
            }
        }
    }
    if (functionDefinition != null) {
        SignatureHelp result = new SignatureHelp();
        List<SignatureInformation> signatures = new ArrayList<>();
        SignatureInformation signatureInfo = new SignatureInformation();
        signatureInfo.setLabel(getSignatureLabel(functionDefinition));
        List<ParameterInformation> parameters = new ArrayList<>();
        for (IParameterDefinition param : functionDefinition.getParameters()) {
            ParameterInformation paramInfo = new ParameterInformation();
            paramInfo.setLabel(param.getBaseName());
            parameters.add(paramInfo);
        }
        signatureInfo.setParameters(parameters);
        signatures.add(signatureInfo);
        result.setSignatures(signatures);
        result.setActiveSignature(0);
        int index = getFunctionCallNodeArgumentIndex(functionCallNode, offsetNode);
        IParameterDefinition[] params = functionDefinition.getParameters();
        int paramCount = params.length;
        if (paramCount > 0 && index >= paramCount) {
            if (index >= paramCount) {
                IParameterDefinition lastParam = params[paramCount - 1];
                if (lastParam.isRest()) {
                    //functions with rest parameters may accept any
                    //number of arguments, so continue to make the rest
                    //parameter active
                    index = paramCount - 1;
                } else {
                    //if there's no rest parameter, and we're beyond the
                    //final parameter, none should be active
                    index = -1;
                }
            }
        }
        if (index != -1) {
            result.setActiveParameter(index);
        }
        return CompletableFuture.completedFuture(result);
    }
    return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
}
Also used : IMXMLEventSpecifierNode(org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode) IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IMXMLInstanceNode(org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode) ITypeDefinition(org.apache.flex.compiler.definitions.ITypeDefinition) ArrayList(java.util.ArrayList) IIdentifierNode(org.apache.flex.compiler.tree.as.IIdentifierNode) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData) IFunctionCallNode(org.apache.flex.compiler.tree.as.IFunctionCallNode) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) IASNode(org.apache.flex.compiler.tree.as.IASNode) IParameterDefinition(org.apache.flex.compiler.definitions.IParameterDefinition) IEventDefinition(org.apache.flex.compiler.definitions.IEventDefinition) IExpressionNode(org.apache.flex.compiler.tree.as.IExpressionNode) IMXMLTagAttributeData(org.apache.flex.compiler.mxml.IMXMLTagAttributeData)

Example 4 with ParameterInformation

use of org.eclipse.lsp4j.ParameterInformation in project xtext-core by eclipse.

the class SignatureHelpServiceImpl method getSignatureHelp.

private SignatureHelp getSignatureHelp(final OperationCall call, final String operationName, final int offset) {
    final List<Integer> separatorIndices = CollectionLiterals.<Integer>newArrayList();
    BidiIterable<INode> _children = NodeModelUtils.getNode(call).getChildren();
    for (final INode node : _children) {
        {
            final String text = node.getText();
            if ((Objects.equal(SignatureHelpServiceImpl.OPENING_CHAR, text) && (node.getOffset() >= offset))) {
                return ISignatureHelpService.EMPTY;
            } else {
                if ((Objects.equal(SignatureHelpServiceImpl.CLOSING_CHAR, text) && (node.getOffset() < offset))) {
                    return ISignatureHelpService.EMPTY;
                } else {
                    boolean _equals = Objects.equal(SignatureHelpServiceImpl.SEPARATOR_CHAR, text);
                    if (_equals) {
                        separatorIndices.add(Integer.valueOf(node.getOffset()));
                    }
                }
            }
        }
    }
    final int paramCount = call.getParams().size();
    final int separatorCount = separatorIndices.size();
    if ((((separatorCount + 1) == paramCount) || (separatorCount == paramCount))) {
        final List<INode> paramNodes = NodeModelUtils.findNodesForFeature(call, this._testLanguagePackage.getOperation_Params());
        for (int i = 0; (i < separatorCount); i++) {
            {
                final INode paramNode = paramNodes.get(i);
                int _offset = paramNode.getOffset();
                int _length = paramNode.getLength();
                int _plus = (_offset + _length);
                Integer _get = separatorIndices.get(i);
                boolean _greaterThan = (_plus > (_get).intValue());
                if (_greaterThan) {
                    return ISignatureHelpService.EMPTY;
                }
            }
        }
    } else {
        return ISignatureHelpService.EMPTY;
    }
    int _xifexpression = (int) 0;
    if ((paramCount == 0)) {
        _xifexpression = 0;
    } else {
        int _xifexpression_1 = (int) 0;
        boolean _contains = separatorIndices.contains(Integer.valueOf(offset));
        if (_contains) {
            int _indexOf = separatorIndices.indexOf(Integer.valueOf(offset));
            _xifexpression_1 = (_indexOf + 2);
        } else {
            int _binarySearch = Arrays.binarySearch(((int[]) Conversions.unwrapArray(separatorIndices, int.class)), offset);
            _xifexpression_1 = (-_binarySearch);
        }
        _xifexpression = _xifexpression_1;
    }
    final int currentParameter = _xifexpression;
    final Function1<Operation, Boolean> _function = (Operation it) -> {
        int _size = it.getParams().size();
        return Boolean.valueOf((currentParameter <= _size));
    };
    final Iterable<Operation> visibleOperations = IterableExtensions.<Operation>filter(this.getVisibleOperationsWithName(call, operationName), _function);
    int _xifexpression_2 = (int) 0;
    boolean _contains_1 = separatorIndices.contains(Integer.valueOf(offset));
    if (_contains_1) {
        _xifexpression_2 = 2;
    } else {
        _xifexpression_2 = 1;
    }
    final int paramOffset = _xifexpression_2;
    Integer _xifexpression_3 = null;
    if ((paramCount == 0)) {
        Integer _xblockexpression = null;
        {
            final Function1<Operation, Integer> _function_1 = (Operation it) -> {
                return Integer.valueOf(it.getParams().size());
            };
            final Iterable<Integer> paramSize = IterableExtensions.<Operation, Integer>map(visibleOperations, _function_1);
            Integer _xifexpression_4 = null;
            if (((!IterableExtensions.<Integer>exists(paramSize, ((Function1<Integer, Boolean>) (Integer it) -> {
                return Boolean.valueOf(((it).intValue() == 0));
            }))) && IterableExtensions.<Operation>exists(visibleOperations, ((Function1<Operation, Boolean>) (Operation it) -> {
                boolean _isEmpty = it.getParams().isEmpty();
                return Boolean.valueOf((!_isEmpty));
            })))) {
                _xifexpression_4 = Integer.valueOf(0);
            } else {
                _xifexpression_4 = null;
            }
            _xblockexpression = _xifexpression_4;
        }
        _xifexpression_3 = _xblockexpression;
    } else {
        _xifexpression_3 = Integer.valueOf((currentParameter - paramOffset));
    }
    final Integer activeParamIndex = _xifexpression_3;
    SignatureHelp _signatureHelp = new SignatureHelp();
    final Procedure1<SignatureHelp> _function_1 = (SignatureHelp it) -> {
        it.setActiveParameter(activeParamIndex);
        it.setActiveSignature(Integer.valueOf(0));
        final Function1<Operation, SignatureInformation> _function_2 = (Operation operation) -> {
            SignatureInformation _signatureInformation = new SignatureInformation();
            final Procedure1<SignatureInformation> _function_3 = (SignatureInformation it_1) -> {
                it_1.setLabel(this.getLabel(operation));
                final Function1<Parameter, ParameterInformation> _function_4 = (Parameter param) -> {
                    ParameterInformation _parameterInformation = new ParameterInformation();
                    final Procedure1<ParameterInformation> _function_5 = (ParameterInformation it_2) -> {
                        StringConcatenation _builder = new StringConcatenation();
                        String _name = param.getName();
                        _builder.append(_name);
                        _builder.append(": ");
                        String _label = this.getLabel(param.getType());
                        _builder.append(_label);
                        it_2.setLabel(_builder.toString());
                    };
                    return ObjectExtensions.<ParameterInformation>operator_doubleArrow(_parameterInformation, _function_5);
                };
                it_1.setParameters(ListExtensions.<Parameter, ParameterInformation>map(operation.getParams(), _function_4));
            };
            return ObjectExtensions.<SignatureInformation>operator_doubleArrow(_signatureInformation, _function_3);
        };
        it.setSignatures(IterableExtensions.<SignatureInformation>sortWith(IterableExtensions.<SignatureInformation>toList(IterableExtensions.<Operation, SignatureInformation>map(visibleOperations, _function_2)), SignatureHelpServiceImpl.SIGNATURE_INFO_ORDERING));
    };
    return ObjectExtensions.<SignatureHelp>operator_doubleArrow(_signatureHelp, _function_1);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) BidiIterable(org.eclipse.xtext.nodemodel.BidiIterable) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Operation(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Parameter(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter)

Aggregations

ParameterInformation (org.eclipse.lsp4j.ParameterInformation)4 SignatureInformation (org.eclipse.lsp4j.SignatureInformation)4 SignatureHelp (org.eclipse.lsp4j.SignatureHelp)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Stack (java.util.Stack)1 Collectors (java.util.stream.Collectors)1 IClassDefinition (org.apache.flex.compiler.definitions.IClassDefinition)1 IDefinition (org.apache.flex.compiler.definitions.IDefinition)1 IEventDefinition (org.apache.flex.compiler.definitions.IEventDefinition)1 IFunctionDefinition (org.apache.flex.compiler.definitions.IFunctionDefinition)1 IParameterDefinition (org.apache.flex.compiler.definitions.IParameterDefinition)1 ITypeDefinition (org.apache.flex.compiler.definitions.ITypeDefinition)1 IMXMLTagAttributeData (org.apache.flex.compiler.mxml.IMXMLTagAttributeData)1 IMXMLTagData (org.apache.flex.compiler.mxml.IMXMLTagData)1