org.eclipse.lsp4j.ParameterInformation Java Examples

The following examples show how to use org.eclipse.lsp4j.ParameterInformation. 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: GroovyServicesSignatureHelpTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testSignatureHelpOnMethod() throws Exception {
	Path filePath = srcRoot.resolve("Completion.groovy");
	String uri = filePath.toUri().toString();
	StringBuilder contents = new StringBuilder();
	contents.append("class SignatureHelp {\n");
	contents.append("  public SignatureHelp() {\n");
	contents.append("    method(\n");
	contents.append("  }\n");
	contents.append("  public void method(int param0) {}\n");
	contents.append("}");
	TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString());
	services.didOpen(new DidOpenTextDocumentParams(textDocumentItem));
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	Position position = new Position(2, 11);
	SignatureHelp signatureHelp = services.signatureHelp(new TextDocumentPositionParams(textDocument, position))
			.get();
	List<SignatureInformation> signatures = signatureHelp.getSignatures();
	Assertions.assertEquals(1, signatures.size());
	SignatureInformation signature = signatures.get(0);
	Assertions.assertEquals("public void method(int param0)", signature.getLabel());
	List<ParameterInformation> params = signature.getParameters();
	Assertions.assertEquals(1, params.size());
	ParameterInformation param0 = params.get(0);
	Assertions.assertEquals("int param0", param0.getLabel().get());
	Assertions.assertEquals((int) 0, (int) signatureHelp.getActiveSignature());
	Assertions.assertEquals((int) 0, (int) signatureHelp.getActiveParameter());
}
 
Example #2
Source File: GroovyServicesSignatureHelpTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testSignatureHelpOnMethodWithMultipleParameters() throws Exception {
	Path filePath = srcRoot.resolve("Completion.groovy");
	String uri = filePath.toUri().toString();
	StringBuilder contents = new StringBuilder();
	contents.append("class SignatureHelp {\n");
	contents.append("  public SignatureHelp() {\n");
	contents.append("    method(\n");
	contents.append("  }\n");
	contents.append("  public void method(int param0, String param1) {}\n");
	contents.append("}");
	TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString());
	services.didOpen(new DidOpenTextDocumentParams(textDocumentItem));
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	Position position = new Position(2, 11);
	SignatureHelp signatureHelp = services.signatureHelp(new TextDocumentPositionParams(textDocument, position))
			.get();
	List<SignatureInformation> signatures = signatureHelp.getSignatures();
	Assertions.assertEquals(1, signatures.size());
	SignatureInformation signature = signatures.get(0);
	Assertions.assertEquals("public void method(int param0, String param1)", signature.getLabel());
	List<ParameterInformation> params = signature.getParameters();
	Assertions.assertEquals(2, params.size());
	ParameterInformation param0 = params.get(0);
	Assertions.assertEquals("int param0", param0.getLabel().get());
	ParameterInformation param1 = params.get(1);
	Assertions.assertEquals("String param1", param1.getLabel().get());
	Assertions.assertEquals((int) 0, (int) signatureHelp.getActiveSignature());
	Assertions.assertEquals((int) 0, (int) signatureHelp.getActiveParameter());
}
 
Example #3
Source File: GroovyServicesSignatureHelpTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testSignatureHelpOnMethodWithActiveParameter() throws Exception {
	Path filePath = srcRoot.resolve("Completion.groovy");
	String uri = filePath.toUri().toString();
	StringBuilder contents = new StringBuilder();
	contents.append("class SignatureHelp {\n");
	contents.append("  public SignatureHelp() {\n");
	contents.append("    method(123,\n");
	contents.append("  }\n");
	contents.append("  public void method(int param0, String param1) {}\n");
	contents.append("}");
	TextDocumentItem textDocumentItem = new TextDocumentItem(uri, LANGUAGE_GROOVY, 1, contents.toString());
	services.didOpen(new DidOpenTextDocumentParams(textDocumentItem));
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
	Position position = new Position(2, 15);
	SignatureHelp signatureHelp = services.signatureHelp(new TextDocumentPositionParams(textDocument, position))
			.get();
	List<SignatureInformation> signatures = signatureHelp.getSignatures();
	Assertions.assertEquals(1, signatures.size());
	SignatureInformation signature = signatures.get(0);
	Assertions.assertEquals("public void method(int param0, String param1)", signature.getLabel());
	List<ParameterInformation> params = signature.getParameters();
	Assertions.assertEquals(2, params.size());
	ParameterInformation param0 = params.get(0);
	Assertions.assertEquals("int param0", param0.getLabel().get());
	ParameterInformation param1 = params.get(1);
	Assertions.assertEquals("String param1", param1.getLabel().get());
	Assertions.assertEquals((int) 0, (int) signatureHelp.getActiveSignature());
	Assertions.assertEquals((int) 1, (int) signatureHelp.getActiveParameter());
}
 
Example #4
Source File: StringLSP4J.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return string for given element */
public String toString(ParameterInformation parmInfo) {
	if (parmInfo == null) {
		return "";
	}
	String str = Strings.join(", ",
			toString8(parmInfo.getLabel()),
			toString7(parmInfo.getDocumentation()));

	return "(" + str + ")";
}
 
Example #5
Source File: SignatureHelpRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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()));
	}

	$.setParameters(parameterInfos);

	return $;
}
 
Example #6
Source File: SignatureHelpProvider.java    From groovy-language-server with Apache License 2.0 4 votes vote down vote up
public CompletableFuture<SignatureHelp> provideSignatureHelp(TextDocumentIdentifier textDocument,
		Position position) {
	if (ast == null) {
		//this shouldn't happen, but let's avoid an exception if something
		//goes terribly wrong.
		return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
	}
	URI uri = URI.create(textDocument.getUri());
	ASTNode offsetNode = ast.getNodeAtLineAndColumn(uri, position.getLine(), position.getCharacter());
	if (offsetNode == null) {
		return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
	}
	int activeParamIndex = -1;
	MethodCall methodCall = null;
	ASTNode parentNode = ast.getParent(offsetNode);

	if (offsetNode instanceof ArgumentListExpression) {
		methodCall = (MethodCall) parentNode;

		ArgumentListExpression argsList = (ArgumentListExpression) offsetNode;
		List<Expression> expressions = argsList.getExpressions();
		activeParamIndex = getActiveParameter(position, expressions);
	}

	if (methodCall == null) {
		return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
	}

	List<MethodNode> methods = GroovyASTUtils.getMethodOverloadsFromCallExpression(methodCall, ast);
	if (methods.isEmpty()) {
		return CompletableFuture.completedFuture(new SignatureHelp(Collections.emptyList(), -1, -1));
	}

	List<SignatureInformation> sigInfos = new ArrayList<>();
	for (MethodNode method : methods) {
		List<ParameterInformation> parameters = new ArrayList<>();
		Parameter[] methodParams = method.getParameters();
		for (int i = 0; i < methodParams.length; i++) {
			Parameter methodParam = methodParams[i];

			ParameterInformation paramInfo = new ParameterInformation();
			paramInfo.setLabel(GroovyNodeToStringUtils.variableToString(methodParam, ast));
			parameters.add(paramInfo);
		}
		SignatureInformation sigInfo = new SignatureInformation();
		sigInfo.setLabel(GroovyNodeToStringUtils.methodToString(method, ast));
		sigInfo.setParameters(parameters);
		sigInfos.add(sigInfo);
	}

	MethodNode bestMethod = GroovyASTUtils.getMethodFromCallExpression(methodCall, ast, activeParamIndex);
	int activeSignature = methods.indexOf(bestMethod);

	return CompletableFuture.completedFuture(new SignatureHelp(sigInfos, activeSignature, activeParamIndex));
}
 
Example #7
Source File: SignatureInformation.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public SignatureInformation(@NonNull final String label, final String documentation, final List<ParameterInformation> parameters) {
  this(label);
  this.setDocumentation(documentation);
  this.parameters = parameters;
}
 
Example #8
Source File: SignatureInformation.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public SignatureInformation(@NonNull final String label, final MarkupContent documentation, final List<ParameterInformation> parameters) {
  this(label);
  this.setDocumentation(documentation);
  this.parameters = parameters;
}
 
Example #9
Source File: SignatureInformation.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The parameters of this signature.
 */
@Pure
public List<ParameterInformation> getParameters() {
  return this.parameters;
}
 
Example #10
Source File: SignatureInformation.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The parameters of this signature.
 */
public void setParameters(final List<ParameterInformation> parameters) {
  this.parameters = parameters;
}