KT-12328 Qualified function name inserted when typing before "if"

#KT-12328 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-05-20 20:30:45 +03:00
parent 2ec81f44bf
commit 1413a3fe63
4 changed files with 26 additions and 4 deletions
@@ -37,7 +37,8 @@ abstract class KotlinCallableInsertHandler(val callType: CallType<*>) : BaseDecl
}
private fun addImport(context : InsertionContext, item : LookupElement) {
PsiDocumentManager.getInstance(context.project).commitAllDocuments()
val psiDocumentManager = PsiDocumentManager.getInstance(context.project)
psiDocumentManager.commitAllDocuments()
val file = context.file
val o = item.`object`
@@ -50,10 +51,15 @@ abstract class KotlinCallableInsertHandler(val callType: CallType<*>) : BaseDecl
}
else if (callType == CallType.DEFAULT) {
val fqName = descriptor.importableFqName ?: return
context.document.replaceString(context.startOffset, context.tailOffset, fqName.render())
context.document.replaceString(context.startOffset, context.tailOffset, fqName.render() + " ") // insert space after for correct parsing
PsiDocumentManager.getInstance(context.project).commitAllDocuments()
ShortenReferences.DEFAULT.process(file, context.startOffset, context.tailOffset)
psiDocumentManager.commitAllDocuments()
ShortenReferences.DEFAULT.process(file, context.startOffset, context.tailOffset - 1)
psiDocumentManager.doPostponedOperationsAndUnblockDocument(context.document)
context.document.deleteString(context.tailOffset - 1, context.tailOffset) // delete space
}
}
}
@@ -0,0 +1,5 @@
fun f() {
val v = <caret>if (x) a else b
}
// ELEMENT: emptyList
@@ -0,0 +1,5 @@
fun f() {
val v = emptyList<<caret>>()if (x) a else b
}
// ELEMENT: emptyList
@@ -137,6 +137,12 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
doTest(fileName);
}
@TestMetadata("KT12328.kt")
public void testKT12328() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/KT12328.kt");
doTest(fileName);
}
@TestMetadata("NestedTypeArg.kt")
public void testNestedTypeArg() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/NestedTypeArg.kt");