Skip to content

Commit

Permalink
[WIP] fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Feb 28, 2023
1 parent f547693 commit c5df43e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
Expand All @@ -47,7 +46,6 @@
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.handlers.SignatureHelpUtils;
import org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess;
import org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
Expand Down Expand Up @@ -160,7 +158,6 @@ public SignatureInformation toSignatureInformation(CompletionProposal methodProp
String documentation = null;
if (isDescriptionEnabled) {
documentation = this.computeJavaDoc(methodProposal);
// $.setDocumentation(new MarkupContent(MarkupKind.MARKDOWN, documentation));
}

char[] signature = SignatureUtil.fix83600(methodProposal.getSignature());
Expand All @@ -184,7 +181,7 @@ public SignatureInformation toSignatureInformation(CompletionProposal methodProp
builder.append(parameterNames[i]);
ParameterInformation parameterInformation = new ParameterInformation(builder.toString());
if (documentation != null) {
Pattern p = Pattern.compile("\\* \\*\\*" + new String(parameterNames[i]) + "\\*\\*([^\n\r]+)");
Pattern p = Pattern.compile("\\* \\*\\*" + new String(parameterNames[i]) + "\\*\\*[\\s]+([^\n\r]+)");
Matcher m = p.matcher(documentation);
if (m.find()) {
String paramDocs = m.group(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public interface MyList<E> extends List<E> {

/**
* Test
*
* @param e test
*/
boolean add(E e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.MarkupKind;
import org.eclipse.lsp4j.ParameterInformation;
import org.eclipse.lsp4j.SignatureHelp;
import org.eclipse.lsp4j.SignatureHelpParams;
import org.eclipse.lsp4j.SignatureInformation;
Expand Down Expand Up @@ -94,17 +96,20 @@ public void testSignatureHelp_singleMethod() throws JavaModelException {
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" /** This is a method */\n");
buf.append(" /** This is a method\n");
buf.append(" * @param s documentation */\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);
SignatureHelp help = getSignatureHelp(cu, 5, 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);
SignatureInformation activeSignature = help.getSignatures().get(help.getActiveSignature());
assertEquals("foo(String s) : int", activeSignature.getLabel());
assertNull(activeSignature.getDocumentation());
assertEquals("documentation", activeSignature.getParameters().get(0).getDocumentation().getRight().getValue());
assertEquals((Integer) 0, help.getActiveParameter());
}

Expand Down Expand Up @@ -354,8 +359,10 @@ public void testSignatureHelp_javadocOriginal() throws JavaModelException {
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);
assertNull(signature.getDocumentation());
ParameterInformation paramInfo = signature.getParameters().get(0);
assertEquals(MarkupKind.MARKDOWN, paramInfo.getDocumentation().getRight().getKind());
assertEquals("test", paramInfo.getDocumentation().getRight().getValue());
}

@Test
Expand Down Expand Up @@ -1097,15 +1104,19 @@ public void testSignatureHelpDescriptionDisabled() throws Exception {
buf.append("public class E {\n");
buf.append(" /**\n");
buf.append(" * This is an API.\n");
buf.append(" * @param s documentation\n");
buf.append(" */\n");
buf.append(" public void foo(String s) {\n");
buf.append(" foo(null)\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
SignatureHelp help = getSignatureHelp(cu, 6, 7);
SignatureHelp help = getSignatureHelp(cu, 7, 7);
assertNotNull(help);
assertNull(help.getSignatures().get(help.getActiveSignature()).getDocumentation());
SignatureInformation activeSignature = help.getSignatures().get(help.getActiveSignature());
assertNull(activeSignature.getDocumentation());
ParameterInformation paramInfo = activeSignature.getParameters().get(0);
assertNull(paramInfo.getDocumentation());
}

@Test
Expand All @@ -1117,16 +1128,21 @@ public void testSignatureHelpDescriptionEnabled() throws Exception {
buf.append("public class E {\n");
buf.append(" /**\n");
buf.append(" * This is an API.\n");
buf.append(" * @param s docs for s\n");
buf.append(" */\n");
buf.append(" public void foo(String s) {\n");
buf.append(" foo(null)\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
SignatureHelp help = getSignatureHelp(cu, 6, 7);
SignatureHelp help = getSignatureHelp(cu, 7, 7);
assertNotNull(help);
Either<String, MarkupContent> documentation = help.getSignatures().get(help.getActiveSignature()).getDocumentation();
assertEquals("This is an API.", documentation.getLeft().trim());
SignatureInformation active = help.getSignatures().get(help.getActiveSignature());
Either<String, MarkupContent> documentation = active.getDocumentation();
assertNull(documentation);
ParameterInformation parameterInformation = active.getParameters().get(0);
assertEquals(MarkupKind.MARKDOWN, parameterInformation.getDocumentation().getRight().getKind());
assertEquals("docs for s", parameterInformation.getDocumentation().getRight().getValue());
}

@Test
Expand All @@ -1137,20 +1153,25 @@ public void testSignatureHelp_erasureType() throws Exception {
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" new V<String>();\n");
buf.append(" new V<String>(null);\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("class V<T> {\n");
buf.append(" /** hi */\n");
buf.append(" public V() {}\n");
buf.append(" private V(String a) {}\n");
buf.append(" /** hi\n");
buf.append(" * @param a documentation */\n");
buf.append(" public V(String a) {}\n");
buf.append(" private V(String a, String b) {}\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
SignatureHelp help = getSignatureHelp(cu, 3, 16);
assertNotNull(help);
assertEquals(1, help.getSignatures().size());
Either<String, MarkupContent> documentation = help.getSignatures().get(help.getActiveSignature()).getDocumentation();
assertEquals("hi", documentation.getLeft().trim());
SignatureInformation active = help.getSignatures().get(help.getActiveSignature());
Either<String, MarkupContent> documentation = active.getDocumentation();
assertNull(documentation);
ParameterInformation parameterInformation = active.getParameters().get(0);
assertEquals(MarkupKind.MARKDOWN, parameterInformation.getDocumentation().getRight().getKind());
assertEquals("documentation", parameterInformation.getDocumentation().getRight().getValue());
}

@Test
Expand Down

0 comments on commit c5df43e

Please sign in to comment.