use of org.eclipse.lsp4j.SignatureInformation 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 $;
}
use of org.eclipse.lsp4j.SignatureInformation in project ballerina by ballerina-lang.
the class SignatureHelpUtil method getFunctionSignatureHelp.
/**
* Get the functionSignatureHelp instance.
*
* @param context Signature help context
* @return {@link SignatureHelp} Signature help for the completion
*/
public static SignatureHelp getFunctionSignatureHelp(TextDocumentServiceContext context) {
// Get the functions List
List<SymbolInfo> functions = context.get(SignatureKeys.FILTERED_FUNCTIONS);
List<SignatureInformation> signatureInformationList = functions.stream().map(symbolInfo -> getSignatureInformation((BInvokableSymbol) symbolInfo.getScopeEntry().symbol, context)).filter(Objects::nonNull).collect(Collectors.toList());
SignatureHelp signatureHelp = new SignatureHelp();
signatureHelp.setSignatures(signatureInformationList);
signatureHelp.setActiveParameter(context.get(SignatureKeys.PARAMETER_COUNT));
signatureHelp.setActiveSignature(0);
return signatureHelp;
}
use of org.eclipse.lsp4j.SignatureInformation 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;
}
use of org.eclipse.lsp4j.SignatureInformation 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));
}
use of org.eclipse.lsp4j.SignatureInformation 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);
}
Aggregations