Fixed KT-5077 Code completion inserts FQ names inside lambda
#KT-5077 Fixed
This commit is contained in:
@@ -61,19 +61,24 @@ public object ShortenReferences {
|
||||
if (rangeMarker.isValid()) {
|
||||
val range = TextRange(rangeMarker.getStartOffset(), rangeMarker.getEndOffset())
|
||||
|
||||
var elementRange = element.getTextRange()!!
|
||||
|
||||
// for qualified call expression take only the part without parenthesis
|
||||
val calleeExpression = ((element as? JetDotQualifiedExpression)
|
||||
?.getSelectorExpression() as? JetCallExpression)
|
||||
?.getCalleeExpression()
|
||||
if (calleeExpression != null) {
|
||||
elementRange = TextRange(elementRange.getStartOffset(), calleeExpression.getTextRange()!!.getEndOffset())
|
||||
}
|
||||
|
||||
val elementRange = element.getTextRange()!!
|
||||
when {
|
||||
range.contains(elementRange) -> FilterResult.PROCESS
|
||||
range.intersects(elementRange) -> FilterResult.GO_INSIDE
|
||||
|
||||
range.intersects(elementRange) -> {
|
||||
// for qualified call expression allow to shorten only the part without parenthesis
|
||||
val calleeExpression = ((element as? JetDotQualifiedExpression)
|
||||
?.getSelectorExpression() as? JetCallExpression)
|
||||
?.getCalleeExpression()
|
||||
if (calleeExpression != null) {
|
||||
val rangeWithoutParenthesis = TextRange(elementRange.getStartOffset(), calleeExpression.getTextRange()!!.getEndOffset())
|
||||
if (range.contains(rangeWithoutParenthesis)) FilterResult.PROCESS else FilterResult.GO_INSIDE
|
||||
}
|
||||
else {
|
||||
FilterResult.GO_INSIDE
|
||||
}
|
||||
}
|
||||
|
||||
else -> FilterResult.SKIP
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(list: List<String>) {
|
||||
list.map { Stri<caret> }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(list: List<String>) {
|
||||
list.map { String<caret> }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(list: List<String>) {
|
||||
list.contains(<selection>java.util.TimeZone</selection>)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import java.util.TimeZone
|
||||
|
||||
fun foo(list: List<String>) {
|
||||
list.contains(TimeZone)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(list: List<String>) {
|
||||
list.map { <selection>java.util.TimeZone</selection> }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import java.util.TimeZone
|
||||
|
||||
fun foo(list: List<String>) {
|
||||
list.map { TimeZone }
|
||||
}
|
||||
@@ -30,6 +30,8 @@ public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){
|
||||
|
||||
fun testClassCompletionInImport() = doTest(1, "TimeZone", " (java.util)", '\t')
|
||||
|
||||
fun testClassCompletionInLambda() = doTest(1, "String", " (kotlin)", '\n')
|
||||
|
||||
fun testDoNotInsertImportForAlreadyImported() = doTest()
|
||||
|
||||
fun testDoNotInsertDefaultJsImports() = doTest()
|
||||
|
||||
@@ -179,6 +179,16 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/shortenRefs/type"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassNameInsideArguments.kt")
|
||||
public void testClassNameInsideArguments() throws Exception {
|
||||
doTest("idea/testData/shortenRefs/type/ClassNameInsideArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassNameInsideLambda.kt")
|
||||
public void testClassNameInsideLambda() throws Exception {
|
||||
doTest("idea/testData/shortenRefs/type/ClassNameInsideLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassSameNameAsPackage.kt")
|
||||
public void testClassSameNameAsPackage() throws Exception {
|
||||
doTest("idea/testData/shortenRefs/type/ClassSameNameAsPackage.kt");
|
||||
|
||||
Reference in New Issue
Block a user