KT-20706: Fix auto-popup completion after digit in KDoc
#KT-20706 Fixed
This commit is contained in:
+6
-4
@@ -133,11 +133,13 @@ object KDocTagCompletionProvider : CompletionProvider<CompletionParameters>() {
|
||||
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet) {
|
||||
// findIdentifierPrefix() requires identifier part characters to be a superset of identifier start characters
|
||||
val prefix = CompletionUtil.findIdentifierPrefix(
|
||||
parameters.position.containingFile,
|
||||
parameters.offset,
|
||||
StandardPatterns.character().javaIdentifierPart() or singleCharPattern('@'),
|
||||
StandardPatterns.character().javaIdentifierStart() or singleCharPattern('@'))
|
||||
parameters.position.containingFile,
|
||||
parameters.offset,
|
||||
StandardPatterns.character().javaIdentifierPart() or singleCharPattern('@'),
|
||||
StandardPatterns.character().javaIdentifierStart() or singleCharPattern('@')
|
||||
)
|
||||
|
||||
if (parameters.isAutoPopup && prefix.isEmpty()) return
|
||||
if (prefix.isNotEmpty() && !prefix.startsWith('@')) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
/**
|
||||
* @<caret>
|
||||
*/
|
||||
fun some() {}
|
||||
|
||||
// INVOCATION_COUNT: 0
|
||||
// EXIST: @return
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
/**
|
||||
* 0<caret>
|
||||
*/
|
||||
fun some() {}
|
||||
|
||||
// INVOCATION_COUNT: 0
|
||||
// NOTHING_ELSE
|
||||
@@ -8,3 +8,4 @@ fun f(x: Int): Int {
|
||||
// EXIST: @return
|
||||
// EXIST: @suppress
|
||||
// ABSENT: @receiver
|
||||
// INVOCATION_COUNT: 1
|
||||
@@ -10,3 +10,4 @@ class C<T> {
|
||||
// EXIST: @property
|
||||
// ABSENT: @return
|
||||
// ABSENT: @receiver
|
||||
// INVOCATION_COUNT: 1
|
||||
@@ -10,3 +10,4 @@ fun Int.f(): Int {
|
||||
// EXIST: @receiver
|
||||
// ABSENT: @constructor
|
||||
// ABSENT: @property
|
||||
// INVOCATION_COUNT: 1
|
||||
|
||||
@@ -4,3 +4,4 @@ fun f(x: Int): Int {
|
||||
|
||||
// EXIST: @param
|
||||
// EXIST: @return
|
||||
// INVOCATION_COUNT: 1
|
||||
+10
@@ -34,6 +34,11 @@ public class KDocCompletionTestGenerated extends AbstractJvmBasicCompletionTest
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/kdoc"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("AutoPopupAfterAtInKDoc.kt")
|
||||
public void testAutoPopupAfterAtInKDoc() throws Exception {
|
||||
runTest("idea/idea-completion/testData/kdoc/AutoPopupAfterAtInKDoc.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ExtensionsFQLink.kt")
|
||||
public void testExtensionsFQLink() throws Exception {
|
||||
runTest("idea/idea-completion/testData/kdoc/ExtensionsFQLink.kt");
|
||||
@@ -79,6 +84,11 @@ public class KDocCompletionTestGenerated extends AbstractJvmBasicCompletionTest
|
||||
runTest("idea/idea-completion/testData/kdoc/MemberLink.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NoAutoPopupAfterDigitInKDoc.kt")
|
||||
public void testNoAutoPopupAfterDigitInKDoc() throws Exception {
|
||||
runTest("idea/idea-completion/testData/kdoc/NoAutoPopupAfterDigitInKDoc.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NoCompletionAfterFunName.kt")
|
||||
public void testNoCompletionAfterFunName() throws Exception {
|
||||
runTest("idea/idea-completion/testData/kdoc/NoCompletionAfterFunName.kt");
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.KtNodeTypes;
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
|
||||
@@ -127,6 +128,7 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
||||
|
||||
case '@':
|
||||
autoPopupLabelLookup(project, editor);
|
||||
autoPopupKDocTag(project, editor);
|
||||
return Result.CONTINUE;
|
||||
|
||||
case ':':
|
||||
@@ -179,6 +181,16 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
||||
});
|
||||
}
|
||||
|
||||
private static void autoPopupKDocTag(Project project, final Editor editor) {
|
||||
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, (PsiFile file) -> {
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
PsiElement lastElement = file.findElementAt(offset - 1);
|
||||
if (lastElement == null) return false;
|
||||
|
||||
return lastElement.getNode().getElementType() == KDocTokens.TEXT;
|
||||
});
|
||||
}
|
||||
|
||||
private static void autoPopupLabelLookup(Project project, final Editor editor) {
|
||||
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, new Condition<PsiFile>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user