Completion: don't propose the same name for arguments of lambda (KT-9792)
#KT-9792 Fixed
This commit is contained in:
committed by
Nikolay Krasko
parent
c442d69db6
commit
3a77b63c85
+10
-2
@@ -154,6 +154,7 @@ object LambdaSignatureTemplates {
|
|||||||
template.addTextSegment("{ ")
|
template.addTextSegment("{ ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val noNameParameterCount = mutableMapOf<KotlinType, Int>()
|
||||||
for ((i, parameterType) in parameterTypes.withIndex()) {
|
for ((i, parameterType) in parameterTypes.withIndex()) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
template.addTextSegment(", ")
|
template.addTextSegment(", ")
|
||||||
@@ -168,7 +169,10 @@ object LambdaSignatureTemplates {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val nameSuggestions = nameSuggestions(parameterType)
|
val count = (noNameParameterCount[parameterType] ?: 0) + 1
|
||||||
|
noNameParameterCount[parameterType] = count
|
||||||
|
val suffix = if (count == 1) null else "$count"
|
||||||
|
val nameSuggestions = nameSuggestions(parameterType, suffix)
|
||||||
object : Expression() {
|
object : Expression() {
|
||||||
override fun calculateResult(context: ExpressionContext?) = TextResult(nameSuggestions[0])
|
override fun calculateResult(context: ExpressionContext?) = TextResult(nameSuggestions[0])
|
||||||
override fun calculateQuickResult(context: ExpressionContext?): Result? = null
|
override fun calculateQuickResult(context: ExpressionContext?): Result? = null
|
||||||
@@ -193,7 +197,11 @@ object LambdaSignatureTemplates {
|
|||||||
return template
|
return template
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun nameSuggestions(parameterType: KotlinType) = KotlinNameSuggester.suggestNamesByType(parameterType, { true }, "p")
|
private fun nameSuggestions(parameterType: KotlinType, suffix: String? = null): List<String> {
|
||||||
|
val suggestions = KotlinNameSuggester.suggestNamesByType(parameterType, { true }, "p")
|
||||||
|
return if (suffix != null) suggestions.map { "$it$suffix" } else suggestions
|
||||||
|
}
|
||||||
|
|
||||||
private fun nameSuggestion(parameterType: KotlinType) = nameSuggestions(parameterType)[0]
|
private fun nameSuggestion(parameterType: KotlinType) = nameSuggestions(parameterType)[0]
|
||||||
|
|
||||||
private fun functionParameterTypes(functionType: KotlinType): List<KotlinType> {
|
private fun functionParameterTypes(functionType: KotlinType): List<KotlinType> {
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
fun foo(f: (Int, Int, Int) -> Unit) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
foo<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: foo
|
||||||
|
// TAIL_TEXT: " { Int, Int, Int -> ... } (f: (Int, Int, Int) -> Unit) (<root>)"
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
fun foo(f: (Int, Int, Int) -> Unit) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
foo { i, i2, i3 -> <caret> }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: foo
|
||||||
|
// TAIL_TEXT: " { Int, Int, Int -> ... } (f: (Int, Int, Int) -> Unit) (<root>)"
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
fun bar(f: (Int, String, Int, String) -> Unit) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
bar<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: bar
|
||||||
|
// TAIL_TEXT: " { Int, String, Int, String -> ... } (f: (Int, String, Int, String) -> Unit) (<root>)"
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
fun bar(f: (Int, String, Int, String) -> Unit) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
bar { i, s, i2, s2 -> <caret> }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: bar
|
||||||
|
// TAIL_TEXT: " { Int, String, Int, String -> ... } (f: (Int, String, Int, String) -> Unit) (<root>)"
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
fun baz(f: (a: Int, b: String, Int, String, Int, String) -> Unit) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
baz<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: baz
|
||||||
|
// TAIL_TEXT: " { a, b, Int, String, Int, String -> ... } (f: (Int, String, Int, String, Int, String) -> Unit) (<root>)"
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
fun baz(f: (a: Int, b: String, Int, String, Int, String) -> Unit) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
baz { a, b, i, s, i2, s2 -> <caret> }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: baz
|
||||||
|
// TAIL_TEXT: " { a, b, Int, String, Int, String -> ... } (f: (Int, String, Int, String, Int, String) -> Unit) (<root>)"
|
||||||
+15
@@ -410,6 +410,21 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
|
|||||||
runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/ReplaceByLambdaTemplateNoClosingParenth.kt");
|
runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/ReplaceByLambdaTemplateNoClosingParenth.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("SameTypeParameters.kt")
|
||||||
|
public void testSameTypeParameters() throws Exception {
|
||||||
|
runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/SameTypeParameters.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("SameTypeParameters2.kt")
|
||||||
|
public void testSameTypeParameters2() throws Exception {
|
||||||
|
runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/SameTypeParameters2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("SameTypeParameters3.kt")
|
||||||
|
public void testSameTypeParameters3() throws Exception {
|
||||||
|
runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/SameTypeParameters3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("WithArgsEmptyLambdaAfter.kt")
|
@TestMetadata("WithArgsEmptyLambdaAfter.kt")
|
||||||
public void testWithArgsEmptyLambdaAfter() throws Exception {
|
public void testWithArgsEmptyLambdaAfter() throws Exception {
|
||||||
runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/WithArgsEmptyLambdaAfter.kt");
|
runTest("idea/idea-completion/testData/handlers/basic/highOrderFunctions/WithArgsEmptyLambdaAfter.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user