Skip to content

Commit

Permalink
[23] Code assist changes for markdown Javadoc comments
Browse files Browse the repository at this point in the history
test [] markdown link completion
ensure markdown links can be completed..
+ if ']' is still missing
+ on the last line of a comment
+ without any reference prefix
  • Loading branch information
stephan-herrmann committed Aug 25, 2024
1 parent 4e4e4fd commit 94ed3cb
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,22 +601,27 @@ protected boolean parseMarkdownLinks(int previousPosition) throws InvalidInputEx
currentChar = readChar();
start = this.index;
} else {
int eofBkup = this.scanner.eofPosition;
this.scanner.eofPosition = this.index - 1;
this.scanner.resetTo(start, this.javadocEnd);
valid = parseReference(true);
this.scanner.eofPosition = eofBkup;
break loop;
}
break;
case '\r':
case '\n':
if ((this.kind & PARSER_KIND) == COMPLETION_PARSER) {
// TODO would like to trigger parseReference() with more tokens,
// but in "[some text][#theLink]" arbitrary chars are allowed which do not imply end of link identifier.
// To resolve this we would need to scan for detection of a second pair of brackets ...
break loop;
}
return false;
default:
break;
}
currentChar = readChar();
}
int eofBkup = this.scanner.eofPosition;
this.scanner.resetTo(start, Math.max(this.javadocEnd, this.index));
valid = parseReference(true);
this.scanner.eofPosition = eofBkup;
this.markdownHelper.resetLineStart();
return valid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,5 +765,50 @@ public void test037() {
verifyCompletionOnJavadocTag("lin".toCharArray(), allTags, false);

}

public void testTypeLink() {
// create assist node for unfinished markdown link
String source = """
package javadoc;
///
/// see [Te
///
public class Test {}
""";
verifyCompletionInJavadoc(source, "[Te");
assertCompletionNodeResult(source, """
<CompletionOnJavadocSingleTypeReference:Te
infos:formal reference
>"""
);
}
public void testTypeLink_lastLine() {
// create assist node for unfinished markdown link at end of comment
String source = """
package javadoc;
///
/// see [Te
public class Test {}
""";
verifyCompletionInJavadoc(source, "[Te");
assertCompletionNodeResult(source, """
<CompletionOnJavadocSingleTypeReference:Te
infos:formal reference
>"""
);
}
public void testTypeLink_lastLine_emptyReference() {
// create assist node for unfinished markdown link at end of comment
String source = """
package javadoc;
///
/// see [
public class Test {}
""";
verifyCompletionInJavadoc(source, "[");
assertCompletionNodeResult(source, """
<CompletionOnJavadocSingleTypeReference:
infos:formal reference
>"""
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,98 @@ public class X {}
removeClasspathEntry(this.completion23Project, jarTwoPath);
}
}

public void testMarkdownTypeLink1() throws CoreException {
createFolder("/Completion23/src/javadoc");
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("Completion23/src/javadoc/Test.java", """
package javadoc;
///
/// see [Te]
///
public class Test {}
""");
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
requestor.allowAllRequiredProposals();
String str = this.workingCopies[0].getSource();
String completeBehind = "[Te";
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
"TemplateRuntime[TYPE_REF]{java.lang.runtime.TemplateRuntime, java.lang.runtime, Ljava.lang.runtime.TemplateRuntime;, null, null, "+(DEFAULT_RELEVANCE + R_JAVA_LIBRARY)+"}\n" +
"Test[TYPE_REF]{Test, javadoc, Ljavadoc.Test;, null, null, "+(DEFAULT_RELEVANCE + R_UNQUALIFIED)+"}",
requestor.getResults());
}

public void testMarkdownMethodLink1() throws CoreException {
createFolder("/Completion23/src/javadoc");
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("Completion23/src/javadoc/Test.java", """
package javadoc;
///
/// see [#me] for details
public class Test {
void method() {}
}
""");
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
requestor.allowAllRequiredProposals();
String str = this.workingCopies[0].getSource();
String completeBehind = "[#me";
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
"method[METHOD_REF]{method(), Ljavadoc.Test;, ()V, method, null, "+(DEFAULT_RELEVANCE + R_NON_STATIC)+"}",
requestor.getResults());
}

public void testMarkdownMethodLink2_qualified() throws CoreException {
// type-prefixed
// missing ']' at end of line
createFolder("/Completion23/src/javadoc");
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("Completion23/src/javadoc/Test.java", """
package javadoc;
///
/// see [String#le
///
public class Test {
void method() {}
}
""");
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
requestor.allowAllRequiredProposals();
String str = this.workingCopies[0].getSource();
String completeBehind = "#le";
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
"length[METHOD_REF]{length(), Ljava.lang.String;, ()I, length, null, "+(DEFAULT_RELEVANCE + R_NON_STATIC)+"}",
requestor.getResults());
}

public void testMarkdownMethodLink2_qualified2() throws CoreException {
// type-prefixed
// missing ']' at end of line
// link is on the last comment line
createFolder("/Completion23/src/javadoc");
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy("Completion23/src/javadoc/Test.java", """
package javadoc;
///
/// see [String#le
public class Test {
void method() {}
}
""");
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
requestor.allowAllRequiredProposals();
String str = this.workingCopies[0].getSource();
String completeBehind = "#le";
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
"length[METHOD_REF]{length(), Ljava.lang.String;, ()I, length, null, "+(DEFAULT_RELEVANCE + R_NON_STATIC)+"}",
requestor.getResults());
}
}

0 comments on commit 94ed3cb

Please sign in to comment.