Basic completion prefers right type in lambda value
This commit is contained in:
+6
-7
@@ -238,12 +238,6 @@ class SmartCompletion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun calcExpectedInfos(expression: JetExpression): Collection<ExpectedInfo> {
|
private fun calcExpectedInfos(expression: JetExpression): Collection<ExpectedInfo> {
|
||||||
if (forBasicCompletion) {
|
|
||||||
return ExpectedInfos(bindingContext, resolutionFacade, moduleDescriptor, useOuterCallsExpectedTypeCount = 0)
|
|
||||||
.calculate(expression)
|
|
||||||
.map { it.copy(tail = null) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// if our expression is initializer of implicitly typed variable - take type of variable from original file (+ the same for function)
|
// if our expression is initializer of implicitly typed variable - take type of variable from original file (+ the same for function)
|
||||||
val declaration = implicitlyTypedDeclarationFromInitializer(expression)
|
val declaration = implicitlyTypedDeclarationFromInitializer(expression)
|
||||||
if (declaration != null) {
|
if (declaration != null) {
|
||||||
@@ -262,7 +256,12 @@ class SmartCompletion(
|
|||||||
while (true) {
|
while (true) {
|
||||||
val infos = ExpectedInfos(bindingContext, resolutionFacade, moduleDescriptor, useOuterCallsExpectedTypeCount = count)
|
val infos = ExpectedInfos(bindingContext, resolutionFacade, moduleDescriptor, useOuterCallsExpectedTypeCount = count)
|
||||||
.calculate(expression)
|
.calculate(expression)
|
||||||
if (count == 2 /* use two outer calls maximum */ || infos.none { it.fuzzyType?.isAlmostEverything() ?: false }) return infos
|
if (count == 2 /* use two outer calls maximum */ || infos.none { it.fuzzyType?.isAlmostEverything() ?: false }) {
|
||||||
|
return if (forBasicCompletion)
|
||||||
|
infos.map { it.copy(tail = null) }
|
||||||
|
else
|
||||||
|
infos
|
||||||
|
}
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
//TODO: we could always give higher priority to results with outer call expected type used
|
//TODO: we could always give higher priority to results with outer call expected type used
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
fun <T, R> List<T>.map(transform: (T) -> R): List<R> {}
|
||||||
|
|
||||||
|
class X {
|
||||||
|
val x1: String
|
||||||
|
val x2: Any
|
||||||
|
val x3: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(list: List<X>): Collection<Int> {
|
||||||
|
return list.map { it.x<caret> }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ORDER: x3
|
||||||
|
// ORDER: x1
|
||||||
|
// ORDER: x2
|
||||||
+6
@@ -181,6 +181,12 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LambdaValue.kt")
|
||||||
|
public void testLambdaValue() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/expectedInfo/LambdaValue.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("MultiArgsItem.kt")
|
@TestMetadata("MultiArgsItem.kt")
|
||||||
public void testMultiArgsItem() throws Exception {
|
public void testMultiArgsItem() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/expectedInfo/MultiArgsItem.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/expectedInfo/MultiArgsItem.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user