KT-8743 Propose class names for extension receiver in completion after 'fun' if a capital letter was entered
#KT-8743 Fixed
This commit is contained in:
+18
-9
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
|
|
||||||
public class KotlinCompletionContributor : CompletionContributor() {
|
public class KotlinCompletionContributor : CompletionContributor() {
|
||||||
@@ -275,21 +276,29 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
|||||||
if (invocationCount == 0 && prefixMatcher.getPrefix().isEmpty() && AFTER_INTEGER_LITERAL_AND_DOT.accepts(position)) return true
|
if (invocationCount == 0 && prefixMatcher.getPrefix().isEmpty() && AFTER_INTEGER_LITERAL_AND_DOT.accepts(position)) return true
|
||||||
|
|
||||||
// no auto-popup on typing after "val", "var" and "fun" because it's likely the name of the declaration which is being typed by user
|
// no auto-popup on typing after "val", "var" and "fun" because it's likely the name of the declaration which is being typed by user
|
||||||
if (invocationCount == 0 && isInExtensionReceiver(position)) return true
|
if (invocationCount == 0) {
|
||||||
|
val callable = isInExtensionReceiverOf(position)
|
||||||
|
if (callable != null) {
|
||||||
|
return when (callable) {
|
||||||
|
is JetNamedFunction -> prefixMatcher.prefix.let { it.isEmpty() || it[0].isLowerCase() /* function name usually starts with lower case letter */ }
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isInExtensionReceiver(position: PsiElement): Boolean {
|
private fun isInExtensionReceiverOf(position: PsiElement): JetCallableDeclaration? {
|
||||||
val nameRef = position.getParent() as? JetNameReferenceExpression ?: return false
|
val nameRef = position.getParent() as? JetNameReferenceExpression ?: return null
|
||||||
val userType = nameRef.getParent() as? JetUserType ?: return false
|
val userType = nameRef.getParent() as? JetUserType ?: return null
|
||||||
val typeRef = userType.getParent() as? JetTypeReference ?: return false
|
val typeRef = userType.getParent() as? JetTypeReference ?: return null
|
||||||
if (userType != typeRef.getTypeElement()) return false
|
if (userType != typeRef.getTypeElement()) return null
|
||||||
val parent = typeRef.getParent()
|
val parent = typeRef.getParent()
|
||||||
return when (parent) {
|
return when (parent) {
|
||||||
is JetNamedFunction -> typeRef == parent.getReceiverTypeReference()
|
is JetNamedFunction -> parent.check { typeRef == it.receiverTypeReference }
|
||||||
is JetProperty -> typeRef == parent.getReceiverTypeReference()
|
is JetProperty -> parent.check { typeRef == it.receiverTypeReference }
|
||||||
else -> false
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class Xyz
|
||||||
|
|
||||||
|
fun X<caret>
|
||||||
|
|
||||||
|
// INVOCATION_COUNT: 0
|
||||||
|
// EXIST: Xyz
|
||||||
+6
@@ -67,6 +67,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AutopopupInFunExtensionReceiver.kt")
|
||||||
|
public void testAutopopupInFunExtensionReceiver() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/AutopopupInFunExtensionReceiver.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("BasicAny.kt")
|
@TestMetadata("BasicAny.kt")
|
||||||
public void testBasicAny() throws Exception {
|
public void testBasicAny() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/BasicAny.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/BasicAny.kt");
|
||||||
|
|||||||
+6
@@ -67,6 +67,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AutopopupInFunExtensionReceiver.kt")
|
||||||
|
public void testAutopopupInFunExtensionReceiver() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/AutopopupInFunExtensionReceiver.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("BasicAny.kt")
|
@TestMetadata("BasicAny.kt")
|
||||||
public void testBasicAny() throws Exception {
|
public void testBasicAny() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/BasicAny.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/BasicAny.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user