org.eclipse.lsp4j.SignatureInformation Java Examples
The following examples show how to use
org.eclipse.lsp4j.SignatureInformation.
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: SignatureHelpRequestor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
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); 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; }
Example #2
Source File: SignatureHelpHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testSignatureHelp_javadocOriginal() throws JavaModelException { IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("import java.util.LinkedList;\n"); buf.append("import org.sample.MyList;\n"); buf.append("public class E {\n\n"); buf.append(" void test() {\n"); buf.append(" MyList<String> l = new LinkedList<>();\n"); buf.append(" l.add(\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); int[] loc = findCompletionLocation(cu, "l.add("); SignatureHelp help = getSignatureHelp(cu, loc[0], loc[1]); assertNotNull(help); assertEquals(2, help.getSignatures().size()); SignatureInformation signature = help.getSignatures().get(help.getActiveSignature()); assertTrue(signature.getLabel().equals("add(String e) : boolean")); String documentation = signature.getDocumentation().getLeft(); assertEquals(" Test ", documentation); }
Example #3
Source File: EditorEventManager.java From lsp4intellij with Apache License 2.0 | 5 votes |
private String extractLabel(SignatureInformation signatureInformation, Either<String, Tuple.Two<Integer, Integer>> label) { if (label.isLeft()) { return label.getLeft(); } else if (label.isRight()) { return signatureInformation.getLabel().substring(label.getRight().getFirst(), label.getRight().getSecond()); } else { return ""; } }
Example #4
Source File: GroovyServicesSignatureHelpTests.java From groovy-language-server with Apache License 2.0 | 5 votes |
@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 #5
Source File: GroovyServicesSignatureHelpTests.java From groovy-language-server with Apache License 2.0 | 5 votes |
@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 #6
Source File: GroovyServicesSignatureHelpTests.java From groovy-language-server with Apache License 2.0 | 5 votes |
@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 #7
Source File: StringLSP4J.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** @return string for given element */ public String toString(SignatureInformation sigInfo) { if (sigInfo == null) { return ""; } String str = Strings.join(", ", sigInfo.getLabel(), Strings.toString(this::toString, sigInfo.getParameters()), toString7(sigInfo.getDocumentation())); return "(" + str + ")"; }
Example #8
Source File: SignatureHelpRequestor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
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 #9
Source File: SignatureHelpHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
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; }
Example #10
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String _toExpectation(final SignatureHelp it) { String _xblockexpression = null; { int _size = it.getSignatures().size(); boolean _tripleEquals = (_size == 0); if (_tripleEquals) { StringConcatenation _builder = new StringConcatenation(); _builder.append("Signature index is expected to be null when no signatures are available. Was: "); Integer _activeSignature = it.getActiveSignature(); _builder.append(_activeSignature); _builder.append("."); Assert.assertNull(_builder.toString(), it.getActiveSignature()); return "<empty>"; } Assert.assertNotNull("Active signature index must not be null when signatures are available.", it.getActiveSignature()); String _xifexpression = null; Integer _activeParameter = it.getActiveParameter(); boolean _tripleEquals_1 = (_activeParameter == null); if (_tripleEquals_1) { _xifexpression = "<empty>"; } else { _xifexpression = it.getSignatures().get((it.getActiveSignature()).intValue()).getParameters().get( (it.getActiveParameter()).intValue()).getLabel().getLeft(); } final String param = _xifexpression; StringConcatenation _builder_1 = new StringConcatenation(); final Function1<SignatureInformation, String> _function = (SignatureInformation it_1) -> { return it_1.getLabel(); }; String _join = IterableExtensions.join(ListExtensions.<SignatureInformation, String>map(it.getSignatures(), _function), " | "); _builder_1.append(_join); _builder_1.append(" | "); _builder_1.append(param); _xblockexpression = _builder_1.toString(); } return _xblockexpression; }
Example #11
Source File: SignatureHelpProvider.java From groovy-language-server with Apache License 2.0 | 4 votes |
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 #12
Source File: SignatureHelpRequestor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public Map<SignatureInformation, CompletionProposal> getInfoProposals() { return infoProposals; }
Example #13
Source File: SignatureHelp.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public SignatureHelp() { ArrayList<SignatureInformation> _arrayList = new ArrayList<SignatureInformation>(); this.signatures = _arrayList; }
Example #14
Source File: SignatureHelp.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public SignatureHelp(@NonNull final List<SignatureInformation> signatures, final Integer activeSignature, final Integer activeParameter) { this.signatures = Preconditions.<List<SignatureInformation>>checkNotNull(signatures, "signatures"); this.activeSignature = activeSignature; this.activeParameter = activeParameter; }
Example #15
Source File: SignatureHelp.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * One or more signatures. */ @Pure @NonNull public List<SignatureInformation> getSignatures() { return this.signatures; }
Example #16
Source File: SignatureHelp.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * One or more signatures. */ public void setSignatures(@NonNull final List<SignatureInformation> signatures) { this.signatures = Preconditions.checkNotNull(signatures, "signatures"); }