Java Code Examples for org.eclipse.lsp4j.SignatureHelp#getSignatures()

The following examples show how to use org.eclipse.lsp4j.SignatureHelp#getSignatures() . 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: SignatureHelpHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isSameParameters(IMethod m, SignatureHelp help, SignatureHelpRequestor collector, IJavaProject javaProject) throws JavaModelException {
	if (m == null || help == null || javaProject == null) {
		return false;
	}
	List<SignatureInformation> infos = help.getSignatures();
	for (int i = 0; i < infos.size(); i++) {
		CompletionProposal proposal = collector.getInfoProposals().get(infos.get(i));
		IMethod method = JDTUtils.resolveMethod(proposal, javaProject);
		if (isSameParameters(method, m)) {
			return true;
		}
	}
	return false;
}