use of org.eclipse.jdt.ls.core.internal.contentassist.SignatureHelpRequestor in project eclipse.jdt.ls by eclipse.
the class SignatureHelpHandler method signatureHelp.
public SignatureHelp signatureHelp(TextDocumentPositionParams position, IProgressMonitor monitor) {
SignatureHelp help = new SignatureHelp();
if (!preferenceManager.getPreferences(null).isSignatureHelpEnabled()) {
return help;
}
try {
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(position.getTextDocument().getUri());
final int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), position.getPosition().getLine(), position.getPosition().getCharacter());
int[] contextInfomation = getContextInfomation(unit.getBuffer(), offset);
if (contextInfomation[0] == -1) {
return help;
}
SignatureHelpRequestor collector = new SignatureHelpRequestor(unit, contextInfomation[0] + 1);
if (offset > -1 && !monitor.isCanceled()) {
unit.codeComplete(contextInfomation[0] + 1, collector, monitor);
help = collector.getSignatureHelp(monitor);
if (help != null) {
int currentParameter = contextInfomation[1];
List<SignatureInformation> infos = help.getSignatures();
for (int i = 0; i < infos.size(); i++) {
if (infos.get(i).getParameters().size() >= currentParameter + 1) {
help.setActiveSignature(i);
help.setActiveParameter(currentParameter);
break;
}
}
}
}
} catch (CoreException ex) {
JavaLanguageServerPlugin.logException("Find signatureHelp failure ", ex);
}
return help;
}
use of org.eclipse.jdt.ls.core.internal.contentassist.SignatureHelpRequestor in project eclipse.jdt.ls by eclipse.
the class SignatureHelpHandler method signatureHelp.
public SignatureHelp signatureHelp(SignatureHelpParams position, IProgressMonitor monitor) {
SignatureHelp help = new SignatureHelp();
if (!preferenceManager.getPreferences(null).isSignatureHelpEnabled()) {
return help;
}
try {
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(position.getTextDocument().getUri());
final int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), position.getPosition().getLine(), position.getPosition().getCharacter());
int[] contextInfomation = getContextInfomation(unit.getBuffer(), offset);
ASTNode node = getNode(unit, contextInfomation, monitor);
if (node == null) {
return help;
}
IMethod method = getMethod(node);
String name = method != null ? method.getElementName() : getMethodName(node, unit, contextInfomation);
SignatureHelpRequestor collector = new SignatureHelpRequestor(unit, name, contextInfomation[0] + 1);
if (offset > -1 && !monitor.isCanceled()) {
unit.codeComplete(contextInfomation[0] + 1, collector, monitor);
help = collector.getSignatureHelp(monitor);
if (help.getSignatures().isEmpty()) {
int pos = offset;
if (method != null) {
int start;
if (node instanceof MethodInvocation) {
start = ((MethodInvocation) node).getName().getStartPosition();
} else if (node instanceof ClassInstanceCreation) {
start = ((ClassInstanceCreation) node).getType().getStartPosition();
} else {
start = node.getStartPosition();
}
pos = start + method.getElementName().length();
}
unit.codeComplete(pos, collector, monitor);
help = collector.getSignatureHelp(monitor);
addConstructorProposals(help, node, method, collector, pos);
}
if (!monitor.isCanceled() && help != null) {
SignatureHelp help2 = null;
SignatureHelpRequestor collector2 = null;
if (contextInfomation[0] + 1 != offset) {
collector2 = new SignatureHelpRequestor(unit, offset, name, true);
unit.codeComplete(offset, collector2, monitor);
help2 = collector2.getSignatureHelp(monitor);
}
int currentParameter = contextInfomation[1];
int size = currentParameter + 1;
List<SignatureInformation> infos = help.getSignatures();
int activeParameter = currentParameter < 0 ? 0 : currentParameter;
if (node != null) {
IJavaProject javaProject = unit.getJavaProject();
if (help2 != null) {
if (method != null) {
for (int i = 0; i < infos.size(); i++) {
if (infos.get(i).getParameters().size() >= size) {
CompletionProposal proposal = collector.getInfoProposals().get(infos.get(i));
IMethod m = JDTUtils.resolveMethod(proposal, javaProject, monitor);
if (!monitor.isCanceled() && JDTUtils.isSameParameters(m, method)) {
help.setActiveSignature(i);
help.setActiveParameter(activeParameter);
return help;
}
}
}
}
if (!monitor.isCanceled() && help.getActiveSignature() == null) {
for (int i = 0; i < infos.size(); i++) {
if (infos.get(i).getParameters().size() >= size) {
CompletionProposal proposal = collector.getInfoProposals().get(infos.get(i));
IMethod m = JDTUtils.resolveMethod(proposal, javaProject, monitor);
if (!monitor.isCanceled() && isSameParameters(m, help2, collector2, javaProject, monitor)) {
help.setActiveSignature(i);
help.setActiveParameter(activeParameter);
return help;
}
for (CompletionProposal typeProposal : collector2.getTypeProposals()) {
if (isSameParameters(m, method, typeProposal)) {
help.setActiveSignature(i);
help.setActiveParameter(activeParameter);
return help;
}
}
}
}
}
}
if (!monitor.isCanceled() && help.getActiveSignature() == null) {
if (method != null) {
for (int i = 0; i < infos.size(); i++) {
if (infos.get(i).getParameters().size() >= size) {
CompletionProposal proposal = collector.getInfoProposals().get(infos.get(i));
IMethod m = JDTUtils.resolveMethod(proposal, javaProject, monitor);
if (!monitor.isCanceled() && JDTUtils.isSameParameters(method, m)) {
help.setActiveSignature(i);
help.setActiveParameter(activeParameter);
return help;
}
}
}
}
}
if (!monitor.isCanceled() && help.getActiveSignature() == null) {
for (int i = 0; i < infos.size(); i++) {
CompletionProposal proposal = collector.getInfoProposals().get(infos.get(i));
if (Flags.isVarargs(proposal.getFlags())) {
help.setActiveSignature(i);
char[][] infoTypes = Signature.getParameterTypes(SignatureUtil.fix83600(proposal.getSignature()));
if (infoTypes.length <= activeParameter) {
help.setActiveParameter(infoTypes.length - 1);
} else {
help.setActiveParameter(activeParameter);
}
return help;
}
}
}
if (!monitor.isCanceled() && help.getActiveSignature() == null && node instanceof Block) {
String methodName = getMethodName(node, unit, contextInfomation);
for (int i = 0; i < infos.size(); i++) {
if (infos.get(i).getParameters().size() >= activeParameter) {
CompletionProposal proposal = collector.getInfoProposals().get(infos.get(i));
IMethod m = JDTUtils.resolveMethod(proposal, javaProject, monitor);
if (!monitor.isCanceled() && m != null && m.getElementName().equals(methodName)) {
help.setActiveSignature(i);
help.setActiveParameter(activeParameter);
return help;
}
}
}
}
if (method != null && !monitor.isCanceled() && help.getActiveSignature() == null) {
for (int i = 0; i < infos.size(); i++) {
if (infos.get(i).getParameters().size() >= size) {
CompletionProposal proposal = collector.getInfoProposals().get(infos.get(i));
IMethod m = JDTUtils.resolveMethod(proposal, javaProject, monitor);
if (!monitor.isCanceled() && isSameParameters(m, method, null)) {
help.setActiveSignature(i);
help.setActiveParameter(activeParameter);
return help;
}
}
}
}
}
}
}
} catch (CoreException ex) {
JavaLanguageServerPlugin.logException("Find signatureHelp failure ", ex);
}
return help;
}
Aggregations