support @receiver KDoc tag; somewhat more precise tag name completion
This commit is contained in:
+16
-1
@@ -32,8 +32,13 @@ import org.jetbrains.kotlin.idea.util.CallType
|
||||
import org.jetbrains.kotlin.idea.util.substituteExtensionIfCallable
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
|
||||
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -134,9 +139,19 @@ object KDocTagCompletionProvider: CompletionProvider<CompletionParameters>() {
|
||||
if (prefix.length > 0 && !prefix.startsWith('@')) {
|
||||
return
|
||||
}
|
||||
val kdocOwner = parameters.position.getNonStrictParentOfType<KDoc>()?.getOwner()
|
||||
val resultWithPrefix = result.withPrefixMatcher(prefix)
|
||||
KDocKnownTag.values().forEach {
|
||||
resultWithPrefix.addElement(LookupElementBuilder.create("@" + it.name.toLowerCase()))
|
||||
if (kdocOwner == null || it.isApplicable(kdocOwner)) {
|
||||
resultWithPrefix.addElement(LookupElementBuilder.create("@" + it.name.toLowerCase()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun KDocKnownTag.isApplicable(declaration: KtDeclaration) = when(this) {
|
||||
KDocKnownTag.CONSTRUCTOR, KDocKnownTag.PROPERTY -> declaration is KtClassOrObject
|
||||
KDocKnownTag.RETURN -> declaration is KtNamedFunction
|
||||
KDocKnownTag.RECEIVER -> declaration is KtNamedFunction && declaration.receiverTypeReference != null
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,3 +7,4 @@ fun f(x: Int): Int {
|
||||
// EXIST: @param
|
||||
// EXIST: @return
|
||||
// EXIST: @suppress
|
||||
// ABSENT: @receiver
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* <caret>
|
||||
*/
|
||||
class C<T> {
|
||||
}
|
||||
|
||||
// EXIST: @param
|
||||
// EXIST: @suppress
|
||||
// EXIST: @constructor
|
||||
// EXIST: @property
|
||||
// ABSENT: @return
|
||||
// ABSENT: @receiver
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* <caret>
|
||||
*/
|
||||
fun Int.f(): Int {
|
||||
}
|
||||
|
||||
// EXIST: @param
|
||||
// EXIST: @return
|
||||
// EXIST: @suppress
|
||||
// EXIST: @receiver
|
||||
// ABSENT: @constructor
|
||||
// ABSENT: @property
|
||||
+12
@@ -77,6 +77,18 @@ public class KDocCompletionTestGenerated extends AbstractJvmBasicCompletionTest
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TagNameInClass.kt")
|
||||
public void testTagNameInClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/kdoc/TagNameInClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TagNameInExtensionFunction.kt")
|
||||
public void testTagNameInExtensionFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/kdoc/TagNameInExtensionFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TagNameMiddle.kt")
|
||||
public void testTagNameMiddle() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/kdoc/TagNameMiddle.kt");
|
||||
|
||||
Reference in New Issue
Block a user