KT-12080 Move parameter names higher up in code completion

#KT-12080 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-04-29 21:37:55 +03:00
parent 15dcd3d9f9
commit dd16eb14e5
8 changed files with 50 additions and 3 deletions
@@ -74,7 +74,6 @@ enum class ItemPriority {
DEFAULT,
IMPLEMENT,
OVERRIDE,
NAMED_PARAMETER,
STATIC_MEMBER_FROM_IMPORTS,
STATIC_MEMBER
}
@@ -66,7 +66,7 @@ object NamedArgumentCompletion {
.withTailText(" $typeText")
.withIcon(KotlinIcons.PARAMETER)
.withInsertHandler(NamedArgumentInsertHandler(name))
.assignPriority(ItemPriority.NAMED_PARAMETER)
lookupElement.putUserData(SmartCompletionInBasicWeigher.NAMED_ARGUMENT_KEY, Unit)
collector.addElement(lookupElement)
}
}
@@ -194,6 +194,7 @@ class SmartCompletionInBasicWeigher(
companion object {
val KEYWORD_VALUE_MATCHED_KEY = Key<Unit>("SmartCompletionInBasicWeigher.KEYWORD_VALUE_MATCHED_KEY")
val NAMED_ARGUMENT_KEY = Key<Unit>("SmartCompletionInBasicWeigher.NAMED_ARGUMENT_KEY")
}
private val descriptorsToSkip = smartCompletion.descriptorsToSkip
@@ -205,6 +206,8 @@ class SmartCompletionInBasicWeigher(
private fun smartCompletionItemWeight(nameSimilarity: Int) = (1L shl 32) + nameSimilarity
private val NAMED_ARGUMENT_WEIGHT = 1L
private val NO_MATCH_WEIGHT = 0L
private val DESCRIPTOR_TO_SKIP_WEIGHT = -1L // if descriptor is skipped from smart completion then it's probably irrelevant
@@ -214,6 +217,10 @@ class SmartCompletionInBasicWeigher(
return fullMatchWeight(0)
}
if (element.getUserData(NAMED_ARGUMENT_KEY) != null) {
return NAMED_ARGUMENT_WEIGHT
}
if (element.getUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY) != null) { // it's an "additional item" came from smart completion, don't match it against expected type
return smartCompletionItemWeight(element.getUserData(NAME_SIMILARITY_KEY) ?: 0)
}
@@ -1,6 +1,6 @@
package temp.test
class Options(val listNew: Boolean, val listMatch: Boolean) {
class Options(val listNew: Int, val listMatch: Boolean) {
}
fun listImportedFun() = 12
@@ -5,6 +5,8 @@ import temp.test.*
val listThisFileVal = 12
fun listThisFileFun() = 1
fun listFunNotMatchingType() = ""
class ListThisFileClass {}
fun test(listParam: Int) {
@@ -20,3 +22,4 @@ fun test(listParam: Int) {
// ORDER: listImportedFun
// ORDER: listMatch
// ORDER: listNew
// ORDER: listFunNotMatchingType
@@ -0,0 +1,11 @@
fun f(b: Boolean, tra: Int){}
fun test(tri: Boolean, trb: Int) {
f(tr<caret>)
}
// ORDER: true
// ORDER: tri
// ORDER: tra
// ORDER: trb
// ORDER: try
@@ -0,0 +1,15 @@
class X {
companion object {
fun instance(): X = X()
}
}
fun f(insp: X){}
fun test(insa: Any) {
f(ins<caret>)
}
// ORDER: instance
// ORDER: insp
// ORDER: insa
@@ -131,6 +131,18 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
doTest(fileName);
}
@TestMetadata("NamedParameters2.kt")
public void testNamedParameters2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/NamedParameters2.kt");
doTest(fileName);
}
@TestMetadata("NamedParameters3.kt")
public void testNamedParameters3() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/NamedParameters3.kt");
doTest(fileName);
}
@TestMetadata("Packages.kt")
public void testPackages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/Packages.kt");