Sorting overloads in completion

This commit is contained in:
Valentin Kipyatkov
2015-11-10 23:05:49 +03:00
parent ac8532ffce
commit 6a26e2fd82
6 changed files with 40 additions and 0 deletions
@@ -272,6 +272,8 @@ abstract class CompletionSession(
sorter = sorter.weighBefore("middleMatching", PreferMatchingItemWeigher)
sorter = sorter.weighAfter("kotlin.proximity", ByNameAlphabeticalWeigher, PreferLessParametersWeigher)
return sorter
}
@@ -281,4 +281,19 @@ class PreferContextElementsWeigher(private val context: DeclarationDescriptor) :
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: { String -> ... }
// ORDER: ::x
// ORDER: ::TODO
// ORDER: ::error
@@ -625,6 +625,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
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")
public void testPrivatesInSecondPressCompletion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
@@ -625,6 +625,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
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")
public void testPrivatesInSecondPressCompletion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");