mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-05 08:06:56 +07:00
fix(JavaDoc): better autocomplete
GitOrigin-RevId: 64cc8794d732cd08566413b0070b371768e47d8f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a84875ed35
commit
f95cbb9677
@@ -604,6 +604,8 @@ public final class JavaDocCompletionContributor extends CompletionContributor im
|
||||
PsiElement element = context.getFile().findElementAt(signatureOffset - 1);
|
||||
final CodeStyleSettings styleSettings = CodeStyle.getSettings(context.getFile());
|
||||
PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
|
||||
final PsiMarkdownReferenceLink link = tag == null ? PsiTreeUtil.getParentOfType(element, PsiMarkdownReferenceLink.class) : null;
|
||||
|
||||
if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR && tag != null) {
|
||||
PsiDocTagValue valueElement = tag.getValueElement();
|
||||
int valueEnd = valueElement != null ? valueElement.getTextRange().getEndOffset() : -1;
|
||||
@@ -620,16 +622,19 @@ public final class JavaDocCompletionContributor extends CompletionContributor im
|
||||
String methodName = method.getName();
|
||||
int beforeParenth = signatureOffset + methodName.length();
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
String signature = "(" +
|
||||
StringUtil.join(parameters,
|
||||
p -> TypeConversionUtil.erasure(p.getType()).getCanonicalText(),
|
||||
"," + (styleSettings.getCommonSettings(JavaLanguage.INSTANCE).SPACE_AFTER_COMMA ? " " : "")) +
|
||||
")";
|
||||
|
||||
String signatureSeparator = "," + (styleSettings.getCommonSettings(JavaLanguage.INSTANCE).SPACE_AFTER_COMMA ? " " : "");
|
||||
String signatureContent = link == null
|
||||
? StringUtil.join(parameters,
|
||||
p -> TypeConversionUtil.erasure(p.getType()).getCanonicalText(),
|
||||
signatureSeparator)
|
||||
: StringUtil.join(parameters,
|
||||
p -> escapeBrackets(TypeConversionUtil.erasure(p.getType()).getCanonicalText()),
|
||||
signatureSeparator);
|
||||
String signature = "(" + signatureContent + ")";
|
||||
|
||||
String insertString = methodName + signature;
|
||||
if (!(tag instanceof PsiInlineDocTag)) {
|
||||
insertString += " ";
|
||||
}
|
||||
else {
|
||||
if (tag instanceof PsiInlineDocTag) {
|
||||
if (chars.charAt(signatureOffset) == '}') {
|
||||
afterSharp++;
|
||||
}
|
||||
@@ -637,6 +642,14 @@ public final class JavaDocCompletionContributor extends CompletionContributor im
|
||||
insertString += "} ";
|
||||
}
|
||||
}
|
||||
else if (link != null) {
|
||||
if(chars.charAt(signatureOffset) == ']') {
|
||||
afterSharp++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
insertString += " ";
|
||||
}
|
||||
|
||||
document.insertString(signatureOffset, insertString);
|
||||
RangeMarker paramListMarker = document.createRangeMarker(TextRange.from(beforeParenth, signature.length()));
|
||||
@@ -651,6 +664,11 @@ public final class JavaDocCompletionContributor extends CompletionContributor im
|
||||
}
|
||||
}
|
||||
|
||||
/** @return Escaped brackets to conform with the JEP-467 */
|
||||
private static String escapeBrackets(String input) {
|
||||
return input.replace("[", "\\[").replace("]", "\\]");
|
||||
}
|
||||
|
||||
private static void startParameterListTemplate(@NotNull InsertionContext context,
|
||||
Editor editor,
|
||||
Document document,
|
||||
|
||||
@@ -2353,7 +2353,7 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
|
||||
private static String markdownToHtml(String markdownInput) {
|
||||
return ourMarkdownConverter.convertMarkdownToHtml(markdownInput, null);
|
||||
return ourMarkdownConverter.convertMarkdownToHtml(markdownInput.stripIndent(), null);
|
||||
}
|
||||
|
||||
protected boolean isLeadingAsterisks(@Nullable PsiElement element) {
|
||||
|
||||
@@ -37,8 +37,8 @@ public class JavaDocMarkdownEnterHandler extends EnterHandlerDelegateAdapter {
|
||||
}
|
||||
Document document = editor.getDocument();
|
||||
|
||||
document.insertString(caretOffset.get(), "///");
|
||||
caretAdvance.set(3);
|
||||
document.insertString(caretOffset.get(), "/// ");
|
||||
caretAdvance.set(4);
|
||||
|
||||
return Result.DefaultForceIndent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user