Sorting overloads in completion
This commit is contained in:
@@ -272,6 +272,8 @@ abstract class CompletionSession(
|
|||||||
|
|
||||||
sorter = sorter.weighBefore("middleMatching", PreferMatchingItemWeigher)
|
sorter = sorter.weighBefore("middleMatching", PreferMatchingItemWeigher)
|
||||||
|
|
||||||
|
sorter = sorter.weighAfter("kotlin.proximity", ByNameAlphabeticalWeigher, PreferLessParametersWeigher)
|
||||||
|
|
||||||
return sorter
|
return sorter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,4 +281,19 @@ class PreferContextElementsWeigher(private val context: DeclarationDescriptor) :
|
|||||||
|
|
||||||
return original in contextElements
|
return original in contextElements
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object ByNameAlphabeticalWeigher : LookupElementWeigher("kotlin.byNameAlphabetical") {
|
||||||
|
override fun weigh(element: LookupElement): String? {
|
||||||
|
val lookupObject = element.`object` as? DeclarationLookupObject ?: return null
|
||||||
|
return lookupObject.name?.asString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object PreferLessParametersWeigher : LookupElementWeigher("kotlin.preferLessParameters") {
|
||||||
|
override fun weigh(element: LookupElement): Int? {
|
||||||
|
val lookupObject = element.`object` as? DeclarationLookupObject ?: return null
|
||||||
|
val function = lookupObject.descriptor as? FunctionDescriptor ?: return null
|
||||||
|
return function.valueParameters.size
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun foo(iterable: Iterable<String>) {
|
||||||
|
iterable.singl<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// WITH_ORDER
|
||||||
|
// EXIST: { itemText: "single", tailText: "() for Iterable<T> in kotlin" }
|
||||||
|
// EXIST: { itemText: "single", tailText: " {...} (predicate: (String) -> Boolean) for Iterable<T> in kotlin" }
|
||||||
|
// EXIST: { itemText: "singleOrNull", tailText: "() for Iterable<T> in kotlin" }
|
||||||
|
// EXIST: { itemText: "singleOrNull", tailText: " {...} (predicate: (String) -> Boolean) for Iterable<T> in kotlin" }
|
||||||
|
// NOTHING_ELSE
|
||||||
@@ -12,4 +12,5 @@ fun bar(p: (String) -> Boolean) {
|
|||||||
// ORDER: {...}
|
// ORDER: {...}
|
||||||
// ORDER: { String -> ... }
|
// ORDER: { String -> ... }
|
||||||
// ORDER: ::x
|
// ORDER: ::x
|
||||||
|
// ORDER: ::TODO
|
||||||
// ORDER: ::error
|
// ORDER: ::error
|
||||||
|
|||||||
+6
@@ -625,6 +625,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PreferLessParameters.kt")
|
||||||
|
public void testPreferLessParameters() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PreferLessParameters.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("PrivatesInSecondPressCompletion.kt")
|
@TestMetadata("PrivatesInSecondPressCompletion.kt")
|
||||||
public void testPrivatesInSecondPressCompletion() throws Exception {
|
public void testPrivatesInSecondPressCompletion() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
|
||||||
|
|||||||
+6
@@ -625,6 +625,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PreferLessParameters.kt")
|
||||||
|
public void testPreferLessParameters() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PreferLessParameters.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("PrivatesInSecondPressCompletion.kt")
|
@TestMetadata("PrivatesInSecondPressCompletion.kt")
|
||||||
public void testPrivatesInSecondPressCompletion() throws Exception {
|
public void testPrivatesInSecondPressCompletion() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user