diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LambdaSignatureTemplates.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LambdaSignatureTemplates.kt index 3ee15771412..fd1d181bdeb 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LambdaSignatureTemplates.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LambdaSignatureTemplates.kt @@ -27,7 +27,7 @@ import com.intellij.psi.PsiDocumentManager import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.builtins.extractParameterNameFromFunctionTypeArgument import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType -import org.jetbrains.kotlin.builtins.isFunctionType +import org.jetbrains.kotlin.builtins.isFunctionOrSuspendFunctionType import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.completion.handlers.isCharAt import org.jetbrains.kotlin.idea.core.ExpectedInfos @@ -122,7 +122,7 @@ object LambdaSignatureTemplates { val expectedInfos = ExpectedInfos(bindingContext, resolutionFacade, indicesHelper = null, useHeuristicSignatures = false).calculate(expression) val functionTypes = expectedInfos .mapNotNull { it.fuzzyType?.type } - .filter(KotlinType::isFunctionType) + .filter(KotlinType::isFunctionOrSuspendFunctionType) .toSet() return explicitParameterTypesRequired(functionTypes, lambdaType) } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt index d4fd6328deb..7d6d0c27e35 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.completion.smart import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.openapi.util.TextRange -import org.jetbrains.kotlin.builtins.isFunctionType +import org.jetbrains.kotlin.builtins.isFunctionOrSuspendFunctionType import org.jetbrains.kotlin.idea.completion.LambdaSignatureTemplates import org.jetbrains.kotlin.idea.completion.suppressAutoInsertion import org.jetbrains.kotlin.idea.core.ExpectedInfo @@ -36,7 +36,7 @@ object LambdaItems { } fun addToCollection(collection: MutableCollection, expectedInfos: Collection) { - val functionExpectedInfos = expectedInfos.filter { it.fuzzyType?.type?.isFunctionType == true } + val functionExpectedInfos = expectedInfos.filter { it.fuzzyType?.type?.isFunctionOrSuspendFunctionType == true } if (functionExpectedInfos.isEmpty()) return val functionTypes = functionExpectedInfos diff --git a/idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderSuspendFunctionWithArgs.kt b/idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderSuspendFunctionWithArgs.kt new file mode 100644 index 00000000000..53eb93df8a0 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderSuspendFunctionWithArgs.kt @@ -0,0 +1,9 @@ +fun foo(p : suspend (String, Char) -> Boolean){} +fun foo(p : suspend (String, Boolean) -> Boolean){} + +fun main(args: Array) { + fo +} + +// ELEMENT: foo +// TAIL_TEXT: " { String, Char -> ... } (p: suspend (String, Char) -> Boolean) ()" diff --git a/idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderSuspendFunctionWithArgs.kt.after b/idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderSuspendFunctionWithArgs.kt.after new file mode 100644 index 00000000000..37810b66cb2 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderSuspendFunctionWithArgs.kt.after @@ -0,0 +1,9 @@ +fun foo(p : suspend (String, Char) -> Boolean){} +fun foo(p : suspend (String, Boolean) -> Boolean){} + +fun main(args: Array) { + foo { s: String, c: Char -> } +} + +// ELEMENT: foo +// TAIL_TEXT: " { String, Char -> ... } (p: suspend (String, Char) -> Boolean) ()" diff --git a/idea/idea-completion/testData/smart/functionLiterals/SuspendExplicitParameterTypesRequired.kt b/idea/idea-completion/testData/smart/functionLiterals/SuspendExplicitParameterTypesRequired.kt new file mode 100644 index 00000000000..99fe0e895e5 --- /dev/null +++ b/idea/idea-completion/testData/smart/functionLiterals/SuspendExplicitParameterTypesRequired.kt @@ -0,0 +1,11 @@ +fun foo(p: suspend (String, Int) -> Unit){} +fun foo(p: suspend (Char, xx: Any) -> Unit){} + +fun bar() { + foo() +} + +// ABSENT: "{ s, i -> ... }" +// ABSENT: "{ c, xx -> ... }" +// EXIST: "{ String, Int -> ... }" +// EXIST: "{ Char, xx -> ... }" diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java index a20cb5f3ebc..88590fbddbf 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java @@ -959,6 +959,11 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT public void testOutsideCallParenthesisAndVararg2() throws Exception { runTest("idea/idea-completion/testData/smart/functionLiterals/OutsideCallParenthesisAndVararg2.kt"); } + + @TestMetadata("SuspendExplicitParameterTypesRequired.kt") + public void testSuspendExplicitParameterTypesRequired() throws Exception { + runTest("idea/idea-completion/testData/smart/functionLiterals/SuspendExplicitParameterTypesRequired.kt"); + } } @TestMetadata("idea/idea-completion/testData/smart/generics") diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java index 7a13809732d..b29b0c2c708 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java @@ -462,6 +462,11 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderFunctionWithArgs3.kt"); } + @TestMetadata("HigherOrderSuspendFunctionWithArgs.kt") + public void testHigherOrderSuspendFunctionWithArgs() throws Exception { + runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderSuspendFunctionWithArgs.kt"); + } + @TestMetadata("InsertFunctionWithSingleParameterWithBrace.kt") public void testInsertFunctionWithSingleParameterWithBrace() throws Exception { runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/InsertFunctionWithSingleParameterWithBrace.kt"); diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/PerformanceBasicCompletionHandlerTestGenerated.java b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/PerformanceBasicCompletionHandlerTestGenerated.java index 1e0c7ab0deb..0422e9c61b8 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/PerformanceBasicCompletionHandlerTestGenerated.java +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/PerformanceBasicCompletionHandlerTestGenerated.java @@ -462,6 +462,11 @@ public class PerformanceBasicCompletionHandlerTestGenerated extends AbstractPerf runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderFunctionWithArgs3.kt"); } + @TestMetadata("HigherOrderSuspendFunctionWithArgs.kt") + public void testHigherOrderSuspendFunctionWithArgs() throws Exception { + runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/HigherOrderSuspendFunctionWithArgs.kt"); + } + @TestMetadata("InsertFunctionWithSingleParameterWithBrace.kt") public void testInsertFunctionWithSingleParameterWithBrace() throws Exception { runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/InsertFunctionWithSingleParameterWithBrace.kt");