KT-13810 Kotlin code completion missing last character
#KT-13810 Fixed
This commit is contained in:
+4
-1
@@ -59,7 +59,10 @@ abstract class KotlinCallableInsertHandler(val callType: CallType<*>) : BaseDecl
|
||||
|
||||
psiDocumentManager.doPostponedOperationsAndUnblockDocument(context.document)
|
||||
|
||||
context.document.deleteString(context.tailOffset - 1, context.tailOffset) // delete space
|
||||
// delete space
|
||||
if (context.document.isTextAt(context.tailOffset - 1, " ")) { // sometimes space can be lost because of reformatting
|
||||
context.document.deleteString(context.tailOffset - 1, context.tailOffset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// CODE_STYLE_SETTING: ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true
|
||||
package test
|
||||
|
||||
interface Foo {
|
||||
companion object {
|
||||
val EMPTY = object : Foo {}
|
||||
}
|
||||
}
|
||||
|
||||
fun test(foo: Foo, bar: String) {}
|
||||
|
||||
fun test2() {
|
||||
test(<caret>, "")
|
||||
}
|
||||
|
||||
// ELEMENT: EMPTY
|
||||
@@ -0,0 +1,16 @@
|
||||
// CODE_STYLE_SETTING: ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true
|
||||
package test
|
||||
|
||||
interface Foo {
|
||||
companion object {
|
||||
val EMPTY = object : Foo {}
|
||||
}
|
||||
}
|
||||
|
||||
fun test(foo: Foo, bar: String) {}
|
||||
|
||||
fun test2() {
|
||||
test(Foo.EMPTY<caret>, "")
|
||||
}
|
||||
|
||||
// ELEMENT: EMPTY
|
||||
+11
-4
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.completion.test.handlers
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils
|
||||
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
@@ -57,15 +58,21 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType:
|
||||
|
||||
val completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType
|
||||
|
||||
val codeStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
||||
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
||||
val commonStyleSettings = CodeStyleSettingsManager.getSettings(project).getCommonSettings(KotlinLanguage.INSTANCE)
|
||||
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
||||
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
||||
val settingName = line.substring(0, index).trim()
|
||||
val settingValue = line.substring(index + 1).trim()
|
||||
val field = codeStyleSettings.javaClass.getDeclaredField(settingName)
|
||||
val (field, settings) = try {
|
||||
kotlinStyleSettings.javaClass.getDeclaredField(settingName) to kotlinStyleSettings
|
||||
}
|
||||
catch (e: NoSuchFieldException) {
|
||||
commonStyleSettings.javaClass.getDeclaredField(settingName) to commonStyleSettings
|
||||
}
|
||||
when (field.type.name) {
|
||||
"boolean" -> field.setBoolean(codeStyleSettings, settingValue.toBoolean())
|
||||
"int" -> field.setInt(codeStyleSettings, settingValue.toInt())
|
||||
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
||||
"int" -> field.setInt(settings, settingValue.toInt())
|
||||
else -> error("Unsupported setting type: ${field.type}")
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -125,6 +125,12 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("KT14130.kt")
|
||||
public void testKT14130() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/KT14130.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NestedTypeArg.kt")
|
||||
public void testNestedTypeArg() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/NestedTypeArg.kt");
|
||||
|
||||
Reference in New Issue
Block a user