use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.
the class SignatureHelpRequestor method getSignatureHelp.
public SignatureHelp getSignatureHelp(IProgressMonitor monitor) {
SignatureHelp signatureHelp = new SignatureHelp();
response.setProposals(proposals);
CompletionResponses.store(response);
List<SignatureInformation> infos = new ArrayList<>();
for (int i = 0; i < proposals.size(); i++) {
if (!monitor.isCanceled()) {
CompletionProposal proposal = proposals.get(i);
if (proposal.getKind() != CompletionProposal.METHOD_REF) {
typeProposals.add(proposal);
continue;
}
SignatureInformation signatureInformation = this.toSignatureInformation(proposal);
infoProposals.put(signatureInformation, proposal);
infos.add(signatureInformation);
} else {
return signatureHelp;
}
}
infos.sort((SignatureInformation a, SignatureInformation b) -> a.getParameters().size() - b.getParameters().size());
signatureHelp.getSignatures().addAll(infos);
return signatureHelp;
}
use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.
the class SignatureHelpHandlerTest method testSignatureHelp_singleMethod.
@Test
public void testSignatureHelp_singleMethod() throws JavaModelException {
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" /** This is a method */\n");
buf.append(" public int foo(String s) { }\n");
buf.append(" public int bar(String s) { this.foo() }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
SignatureHelp help = getSignatureHelp(cu, 4, 39);
assertNotNull(help);
assertEquals(1, help.getSignatures().size());
assertEquals("foo(String s) : int", help.getSignatures().get(help.getActiveSignature()).getLabel());
assertTrue(help.getSignatures().get(help.getActiveSignature()).getDocumentation().getLeft().length() > 0);
assertEquals((Integer) 0, help.getActiveParameter());
}
use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.
the class SignatureHelpHandlerTest method testSignatureHelp_invalid.
@Test
public void testSignatureHelp_invalid() throws JavaModelException {
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public int bar(String s) { if ( }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
SignatureHelp help = getSignatureHelp(cu, 2, 34);
assertNotNull(help);
assertEquals(0, help.getSignatures().size());
}
use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.
the class SignatureHelpHandlerTest method testSignatureHelp_parameters.
// See https://github.com/eclipse/eclipse.jdt.ls/pull/1015#issuecomment-487997215
@Test
public void testSignatureHelp_parameters() throws JavaModelException {
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public boolean bar() {\n");
buf.append(" foo(\"\",)\n");
buf.append(" return true;\n");
buf.append(" }\n");
buf.append(" public void foo(String s) {}\n");
buf.append(" public void foo(String s, boolean bar) {}\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
SignatureHelp help = getSignatureHelp(cu, 3, 12);
assertNotNull(help);
assertEquals(2, help.getSignatures().size());
assertEquals(help.getSignatures().get(help.getActiveSignature()).getLabel(), "foo(String s, boolean bar) : void");
}
use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.
the class SignatureHelpHandlerTest method testSignatureHelp_constructorParameters2.
@Test
public void testSignatureHelp_constructorParameters2() throws JavaModelException {
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void bar() {\n");
buf.append(" new RuntimeException(\"foo\")\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
SignatureHelp help = getSignatureHelp(cu, 3, 31);
assertNotNull(help);
assertEquals(4, help.getSignatures().size());
assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().matches("RuntimeException\\(String \\w+\\)"));
}
Aggregations