FIR Completion: Fix completion in function calls (foo.bar<caret>())
In such expressions, `KtCallExpression` wraps `KtSimpleNameExpression`, so `getQualifiedExpressionForSelector()` returns `null` Also, enable tests that are fixed by this
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
|
|
||||||
infix fun Int.func(s: String): Int{}
|
infix fun Int.func(s: String): Int{}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
|
|
||||||
|
class LocalClass
|
||||||
|
|
||||||
|
fun LocalClass.ext(action: () -> Unit) {}
|
||||||
|
fun LocalClass.extAnother(action: () -> Unit) {}
|
||||||
|
|
||||||
|
fun usage(l: LocalClass) {
|
||||||
|
l.ext<caret> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: ext
|
||||||
|
// EXIST: extAnother
|
||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
|
|
||||||
class Expr {}
|
class Expr {}
|
||||||
class Num : Expr() {
|
class Num : Expr() {
|
||||||
fun testing() {}
|
fun testing() {}
|
||||||
|
|||||||
+5
@@ -2297,6 +2297,11 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
|||||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionPropertyAndFunctionImplicitReceiver.kt");
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionPropertyAndFunctionImplicitReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionRecompletion.kt")
|
||||||
|
public void testExtensionRecompletion() throws Exception {
|
||||||
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionRecompletion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericExtensionPropertyAndFunctionExplicitReceiver.kt")
|
@TestMetadata("genericExtensionPropertyAndFunctionExplicitReceiver.kt")
|
||||||
public void testGenericExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
|
public void testGenericExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
|
||||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/genericExtensionPropertyAndFunctionExplicitReceiver.kt");
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/genericExtensionPropertyAndFunctionExplicitReceiver.kt");
|
||||||
|
|||||||
+5
@@ -2297,6 +2297,11 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionPropertyAndFunctionImplicitReceiver.kt");
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionPropertyAndFunctionImplicitReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionRecompletion.kt")
|
||||||
|
public void testExtensionRecompletion() throws Exception {
|
||||||
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionRecompletion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericExtensionPropertyAndFunctionExplicitReceiver.kt")
|
@TestMetadata("genericExtensionPropertyAndFunctionExplicitReceiver.kt")
|
||||||
public void testGenericExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
|
public void testGenericExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
|
||||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/genericExtensionPropertyAndFunctionExplicitReceiver.kt");
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/genericExtensionPropertyAndFunctionExplicitReceiver.kt");
|
||||||
|
|||||||
+3
-5
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.isExtension
|
|||||||
import org.jetbrains.kotlin.idea.references.mainReference
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
|
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||||
|
|
||||||
class KotlinFirCompletionContributor : CompletionContributor() {
|
class KotlinFirCompletionContributor : CompletionContributor() {
|
||||||
init {
|
init {
|
||||||
@@ -74,7 +74,7 @@ private object KotlinAvailableScopesCompletionProvider {
|
|||||||
val reference = (parameters.position.parent as? KtSimpleNameExpression)?.mainReference ?: return
|
val reference = (parameters.position.parent as? KtSimpleNameExpression)?.mainReference ?: return
|
||||||
val nameExpression = reference.expression.takeIf { it !is KtLabelReferenceExpression } ?: return
|
val nameExpression = reference.expression.takeIf { it !is KtLabelReferenceExpression } ?: return
|
||||||
|
|
||||||
val explicitReceiver = nameExpression.getQualifiedExpressionForSelector()?.receiverExpression
|
val explicitReceiver = nameExpression.getReceiverExpression()
|
||||||
|
|
||||||
with(getAnalysisSessionFor(originalFile).createContextDependentCopy()) {
|
with(getAnalysisSessionFor(originalFile).createContextDependentCopy()) {
|
||||||
val (implicitScopes, _) = originalFile.getScopeContextForPosition(nameExpression)
|
val (implicitScopes, _) = originalFile.getScopeContextForPosition(nameExpression)
|
||||||
@@ -128,9 +128,7 @@ private object KotlinAvailableScopesCompletionProvider {
|
|||||||
|
|
||||||
val extensionsWhichCanBeCalled = implicitScopes
|
val extensionsWhichCanBeCalled = implicitScopes
|
||||||
.getCallableSymbols()
|
.getCallableSymbols()
|
||||||
.filter {
|
.filter { it.isExtension && it.hasSuitableExtensionReceiver() }
|
||||||
it.isExtension && it.hasSuitableExtensionReceiver()
|
|
||||||
}
|
|
||||||
|
|
||||||
availableNonExtensions.forEach { result.addSymbolToCompletion(it) }
|
availableNonExtensions.forEach { result.addSymbolToCompletion(it) }
|
||||||
extensionsWhichCanBeCalled.forEach { result.addSymbolToCompletion(it) }
|
extensionsWhichCanBeCalled.forEach { result.addSymbolToCompletion(it) }
|
||||||
|
|||||||
+5
@@ -2297,6 +2297,11 @@ public class HighLevelJvmBasicCompletionTestGenerated extends AbstractHighLevelJ
|
|||||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionPropertyAndFunctionImplicitReceiver.kt");
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionPropertyAndFunctionImplicitReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionRecompletion.kt")
|
||||||
|
public void testExtensionRecompletion() throws Exception {
|
||||||
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionRecompletion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericExtensionPropertyAndFunctionExplicitReceiver.kt")
|
@TestMetadata("genericExtensionPropertyAndFunctionExplicitReceiver.kt")
|
||||||
public void testGenericExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
|
public void testGenericExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
|
||||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/genericExtensionPropertyAndFunctionExplicitReceiver.kt");
|
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/genericExtensionPropertyAndFunctionExplicitReceiver.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user