mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
prioritize javadoc existing param description completion (IDEA-153083)
This commit is contained in:
+16
-17
@@ -69,6 +69,20 @@ public class JavaDocCompletionContributor extends CompletionContributor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.JavaDocCompletionContributor");
|
||||
private static final @NonNls String VALUE_TAG = "value";
|
||||
private static final @NonNls String LINK_TAG = "link";
|
||||
private static final InsertHandler<LookupElement> PARAM_DESCRIPTION_INSERT_HANDLER = (context, item) -> {
|
||||
if (context.getCompletionChar() != Lookup.REPLACE_SELECT_CHAR) return;
|
||||
|
||||
context.commitDocument();
|
||||
PsiDocTag docTag = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiDocTag.class, false);
|
||||
if (docTag != null) {
|
||||
Document document = context.getDocument();
|
||||
int tagEnd = DocTagSelectioner.getDocTagRange(docTag, document.getCharsSequence(), 0).getEndOffset();
|
||||
int tail = context.getTailOffset();
|
||||
if (tail < tagEnd) {
|
||||
document.deleteString(tail, tagEnd);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public JavaDocCompletionContributor() {
|
||||
extend(CompletionType.BASIC, PsiJavaPatterns.psiElement(JavaDocTokenType.DOC_TAG_NAME), new TagChooser());
|
||||
@@ -265,23 +279,8 @@ public class JavaDocCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
});
|
||||
for (String description : descriptions) {
|
||||
result.addElement(LookupElementBuilder.create(description).withInsertHandler(new InsertHandler<LookupElement>() {
|
||||
@Override
|
||||
public void handleInsert(InsertionContext context, LookupElement item) {
|
||||
if (context.getCompletionChar() != Lookup.REPLACE_SELECT_CHAR) return;
|
||||
|
||||
context.commitDocument();
|
||||
PsiDocTag docTag = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiDocTag.class, false);
|
||||
if (docTag != null) {
|
||||
Document document = context.getDocument();
|
||||
int tagEnd = DocTagSelectioner.getDocTagRange(docTag, document.getCharsSequence(), 0).getEndOffset();
|
||||
int tail = context.getTailOffset();
|
||||
if (tail < tagEnd) {
|
||||
document.deleteString(tail, tagEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
result.addElement(PrioritizedLookupElement.withPriority(
|
||||
LookupElementBuilder.create(description).withInsertHandler(PARAM_DESCRIPTION_INSERT_HANDLER), 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-2
@@ -265,8 +265,7 @@ class Foo {
|
||||
}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'some', 'some integer param'
|
||||
myFixture.lookup.currentItem = myFixture.lookupElements[1]
|
||||
myFixture.assertPreferredCompletionItems 0, 'some integer param', 'some'
|
||||
myFixture.type('\t')
|
||||
myFixture.checkResult '''
|
||||
class Foo {
|
||||
@@ -284,6 +283,25 @@ class Foo {
|
||||
'''
|
||||
}
|
||||
|
||||
public void "test suggest same param descriptions with no text after param name"() {
|
||||
myFixture.configureByText "a.java", '''
|
||||
class Foo {
|
||||
/**
|
||||
* @param intParam <caret>
|
||||
* @throws Foo
|
||||
*/
|
||||
void foo2(int intParam, Object param2) { }
|
||||
|
||||
/**
|
||||
* @param intParam some integer param
|
||||
*/
|
||||
void foo(int intParam, Object param2) { }
|
||||
}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'some integer param'
|
||||
}
|
||||
|
||||
public void "test see super class"() {
|
||||
myFixture.addClass("package foo; public interface Foo {}")
|
||||
myFixture.addClass("package bar; public class Bar {} ")
|
||||
|
||||
Reference in New Issue
Block a user