Skip to content

Commit

Permalink
Complete inline tags with blank (fixes #139)
Browse files Browse the repository at this point in the history
Complete those inline tags with an additional blank character as
completion suffix which take additional text from the user, e.g.
"{@code }" instead of "{@code}".

This reverts half of
https://bugs.eclipse.org/bugs/show_bug.cgi?id=121026, which meant to
only suppress superfluous blanks when adding the completion around
existing text, but wrongly removed blanks also from completion that does
not wrap around input.
  • Loading branch information
Bananeweizen authored and jarthana committed Dec 16, 2024
1 parent 9096700 commit 6f25056
Showing 1 changed file with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ private static boolean hasMemberTypesInEnclosingScope(SourceTypeBinding typeBind
private final static int SUPERTYPE = 1;
private final static int SUBTYPE = 2;

/**
* javadoc inline tags that shall be completed with a blank character at the end
*/
private final static List<String> JAVADOC_INLINE_TAGS_WITH_TEXT = List.of(
"code", //$NON-NLS-1$
"index", //$NON-NLS-1$
"link", //$NON-NLS-1$
"linkplain", //$NON-NLS-1$
"literal", //$NON-NLS-1$
"summary", //$NON-NLS-1$
"systemProperty", //$NON-NLS-1$
"value"); //$NON-NLS-1$

int expectedTypesPtr = -1;
TypeBinding[] expectedTypes = new TypeBinding[1];
int expectedTypesFilter;
Expand Down Expand Up @@ -8909,23 +8922,22 @@ private void findJavadocInlineTags(CompletionOnJavadocTag javadocTag) {
for (int i=0; i<length; i++) {
int relevance = computeBaseRelevance();
relevance += computeRelevanceForInterestingProposal();
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for keywors
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for keywords

this.noProposal = false;
if (!this.requestor.isIgnored(CompletionProposal.JAVADOC_INLINE_TAG)) {
char[] possibleTag = possibleTags[i];
InternalCompletionProposal proposal = createProposal(CompletionProposal.JAVADOC_INLINE_TAG, this.actualCompletionPosition);
proposal.setName(possibleTag);
int tagLength = possibleTag.length;
// boolean inlineTagStarted = javadocTag.completeInlineTagStarted();
char[] completion = new char[2+tagLength+1];
completion[0] = '{';
completion[1] = '@';
System.arraycopy(possibleTag, 0, completion, 2, tagLength);
// do not add space at end of inline tag (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=121026)
//completion[tagLength+2] = ' ';
completion[tagLength+2] = '}';
proposal.setCompletion(completion);
StringBuilder completion = new StringBuilder(possibleTag.length + 4);
completion.append("{@"); //$NON-NLS-1$
completion.append(possibleTag);
// additional blank for all tags that contain user provided text
if (JAVADOC_INLINE_TAGS_WITH_TEXT.contains(String.valueOf(possibleTag))) {
completion.append(' ');
}
completion.append('}');
proposal.setCompletion(completion.toString().toCharArray());
proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset);
proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset);
proposal.setRelevance(relevance);
Expand Down

0 comments on commit 6f25056

Please sign in to comment.