Completion: do not force dsl members to the top if some type is expected

This commit is contained in:
Pavel V. Talanov
2018-02-20 16:26:52 +01:00
parent 1796d40118
commit 92070d132e
3 changed files with 57 additions and 1 deletions
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import java.util.*
@@ -269,7 +270,11 @@ abstract class CompletionSession(
sorter = sorter.weighAfter("kotlin.proximity", ByNameAlphabeticalWeigher, PreferLessParametersWeigher)
sorter = sorter.weighBefore("prefix", PreferDslMembers)
if (expectedInfos.all { it.fuzzyType?.type?.isUnit() == true }) {
sorter = sorter.weighBefore("prefix", PreferDslMembers)
} else {
sorter = sorter.weighAfter("kotlin.preferContextElements", PreferDslMembers)
}
return sorter
}
@@ -0,0 +1,45 @@
// RUNTIME
package test
import bar.r
import bar.foo3
fun main() {
val foo5 = 3
r {
val j: String = foo<caret>
}
}
@DslMarker
annotation class Dsl
@Dsl
class R
fun r(body: R.() -> Unit) {
}
fun foo1(i: Int): String ""
fun foo3() {
}
@Dsl
fun R.foobar2(): String = ""
@Dsl
fun R.foobar4() {
}
// ORDER: foobar2
// ORDER: foo1
// ORDER: foo5
// ORDER: foobar4
// ORDER: foo3
@@ -61,6 +61,12 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
doTest(fileName);
}
@TestMetadata("DslCallWithExpectedType.kt")
public void testDslCallWithExpectedType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/DslCallWithExpectedType.kt");
doTest(fileName);
}
@TestMetadata("DslCalls.kt")
public void testDslCalls() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/DslCalls.kt");