EA-70229 - IOOBE (KotlinFunctionInsertHandler): ImmutableText.findLeaf
#EA-70229 Fixed
This commit is contained in:
+1
-1
@@ -92,7 +92,7 @@ class KotlinFunctionInsertHandler(val caretPosition: CaretPosition, val lambdaIn
|
|||||||
val document = context.getDocument()
|
val document = context.getDocument()
|
||||||
val chars = document.getCharsSequence()
|
val chars = document.getCharsSequence()
|
||||||
|
|
||||||
val insertLambda = lambdaInfo != null && completionChar != '(' && !(completionChar == '\t' && chars.charAt(offset) == '(')
|
val insertLambda = lambdaInfo != null && completionChar != '(' && !(completionChar == '\t' && chars.isCharAt(offset, '('))
|
||||||
|
|
||||||
val openingBracket = if (insertLambda) '{' else '('
|
val openingBracket = if (insertLambda) '{' else '('
|
||||||
val closingBracket = if (insertLambda) '}' else ')'
|
val closingBracket = if (insertLambda) '}' else ')'
|
||||||
|
|||||||
+7
-10
@@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.completion.handlers
|
package org.jetbrains.kotlin.idea.completion.handlers
|
||||||
|
|
||||||
import com.intellij.codeInsight.completion.*
|
import com.intellij.codeInsight.AutoPopupController
|
||||||
|
import com.intellij.codeInsight.completion.InsertHandler
|
||||||
|
import com.intellij.codeInsight.completion.InsertionContext
|
||||||
|
import com.intellij.codeInsight.lookup.Lookup
|
||||||
import com.intellij.codeInsight.lookup.LookupElement
|
import com.intellij.codeInsight.lookup.LookupElement
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.codeInsight.AutoPopupController
|
|
||||||
import com.intellij.codeInsight.lookup.Lookup
|
|
||||||
import org.jetbrains.kotlin.idea.completion.smart.SmartCompletion
|
|
||||||
import org.jetbrains.kotlin.idea.completion.KEEP_OLD_ARGUMENT_LIST_ON_TAB_KEY
|
import org.jetbrains.kotlin.idea.completion.KEEP_OLD_ARGUMENT_LIST_ON_TAB_KEY
|
||||||
import com.intellij.openapi.util.TextRange
|
import org.jetbrains.kotlin.idea.completion.smart.SmartCompletion
|
||||||
|
|
||||||
class WithTailInsertHandler(val tailText: String,
|
class WithTailInsertHandler(val tailText: String,
|
||||||
val spaceBefore: Boolean,
|
val spaceBefore: Boolean,
|
||||||
@@ -55,16 +55,13 @@ class WithTailInsertHandler(val tailText: String,
|
|||||||
//TODO: analyze parenthesis balance to decide whether to replace or not
|
//TODO: analyze parenthesis balance to decide whether to replace or not
|
||||||
var insert = true
|
var insert = true
|
||||||
if (overwriteText) {
|
if (overwriteText) {
|
||||||
fun isCharAt(offset: Int, c: Char) = offset < document.getTextLength() && document.getCharsSequence().charAt(offset) == c
|
|
||||||
fun isTextAt(offset: Int, text: String) = offset + text.length() <= document.getTextLength() && document.getText(TextRange(offset, offset + text.length())) == text
|
|
||||||
|
|
||||||
var offset = document.charsSequence.skipSpacesAndLineBreaks(tailOffset)
|
var offset = document.charsSequence.skipSpacesAndLineBreaks(tailOffset)
|
||||||
if (isTextAt(offset, tailText)) {
|
if (document.isTextAt(offset, tailText)) {
|
||||||
insert = false
|
insert = false
|
||||||
offset += tailText.length()
|
offset += tailText.length()
|
||||||
tailOffset = offset
|
tailOffset = offset
|
||||||
|
|
||||||
if (spaceAfter && isCharAt(offset, ' ')) {
|
if (spaceAfter && document.charsSequence.isCharAt(offset, ' ')) {
|
||||||
document.deleteString(offset, offset + 1)
|
document.deleteString(offset, offset + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.completion.handlers
|
package org.jetbrains.kotlin.idea.completion.handlers
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.Document
|
||||||
|
import com.intellij.openapi.util.TextRange
|
||||||
|
|
||||||
fun CharSequence.indexOfSkippingSpace(c: Char, startIndex: Int): Int? {
|
fun CharSequence.indexOfSkippingSpace(c: Char, startIndex: Int): Int? {
|
||||||
for (i in startIndex..this.length() - 1) {
|
for (i in startIndex..this.length() - 1) {
|
||||||
val currentChar = this[i]
|
val currentChar = this[i]
|
||||||
@@ -31,3 +34,6 @@ fun CharSequence.skipSpaces(index: Int): Int
|
|||||||
fun CharSequence.skipSpacesAndLineBreaks(index: Int): Int
|
fun CharSequence.skipSpacesAndLineBreaks(index: Int): Int
|
||||||
= (index..length() - 1).firstOrNull { val c = this[it]; c != ' ' && c != '\t' && c != '\n' && c != '\r' } ?: this.length()
|
= (index..length() - 1).firstOrNull { val c = this[it]; c != ' ' && c != '\t' && c != '\n' && c != '\r' } ?: this.length()
|
||||||
|
|
||||||
|
fun CharSequence.isCharAt(offset: Int, c: Char) = offset < length() && charAt(offset) == c
|
||||||
|
|
||||||
|
fun Document.isTextAt(offset: Int, text: String) = offset + text.length() <= getTextLength() && getText(TextRange(offset, offset + text.length())) == text
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// ELEMENT: foo
|
||||||
|
// CHAR: '\t'
|
||||||
|
|
||||||
|
fun foo(handler: () -> Unit){}
|
||||||
|
|
||||||
|
val v = <caret>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// ELEMENT: foo
|
||||||
|
// CHAR: '\t'
|
||||||
|
|
||||||
|
fun foo(handler: () -> Unit){}
|
||||||
|
|
||||||
|
val v = foo { <caret> }
|
||||||
+6
@@ -47,6 +47,12 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("EA70229.kt")
|
||||||
|
public void testEA70229() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/EA70229.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ExtensionReceiverTypeArg.kt")
|
@TestMetadata("ExtensionReceiverTypeArg.kt")
|
||||||
public void testExtensionReceiverTypeArg() throws Exception {
|
public void testExtensionReceiverTypeArg() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/ExtensionReceiverTypeArg.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/ExtensionReceiverTypeArg.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user