Completion: do not force dsl members to the top if some type is expected
This commit is contained in:
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -269,7 +270,11 @@ abstract class CompletionSession(
|
|||||||
|
|
||||||
sorter = sorter.weighAfter("kotlin.proximity", ByNameAlphabeticalWeigher, PreferLessParametersWeigher)
|
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
|
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
|
||||||
+6
@@ -61,6 +61,12 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("DslCalls.kt")
|
||||||
public void testDslCalls() throws Exception {
|
public void testDslCalls() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/DslCalls.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/DslCalls.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user