Completion: more correct code for lambda template insertion
This commit is contained in:
+7
-2
@@ -114,7 +114,13 @@ class KotlinFunctionInsertHandler(val caretPosition: CaretPosition, val lambdaIn
|
||||
}
|
||||
|
||||
var openingBracketOffset = chars.indexOfSkippingSpace(openingBracket, offset)
|
||||
var closeBracketOffset = openingBracketOffset?.let { chars.indexOfSkippingSpace(closingBracket, it + 1) }
|
||||
var inBracketsShift = 0
|
||||
|
||||
if (insertLambda && lambdaInfo!!.explicitParameters && closeBracketOffset == null) {
|
||||
openingBracketOffset = null
|
||||
}
|
||||
|
||||
if (openingBracketOffset == null) {
|
||||
if (insertLambda) {
|
||||
if (completionChar == ' ' || completionChar == '{') {
|
||||
@@ -135,10 +141,9 @@ class KotlinFunctionInsertHandler(val caretPosition: CaretPosition, val lambdaIn
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitDocument(document)
|
||||
|
||||
openingBracketOffset = chars.indexOfSkippingSpace(openingBracket, offset)!!
|
||||
closeBracketOffset = chars.indexOfSkippingSpace(closingBracket, openingBracketOffset + 1)!!
|
||||
}
|
||||
|
||||
val closeBracketOffset = chars.indexOfSkippingSpace(closingBracket, openingBracketOffset + 1)
|
||||
|
||||
val editor = context.getEditor()
|
||||
if (shouldPlaceCaretInBrackets(completionChar) || closeBracketOffset == null) {
|
||||
editor.getCaretModel().moveToOffset(openingBracketOffset + 1 + inBracketsShift)
|
||||
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(p : (String, Char) -> Boolean){}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fo<caret>{ }
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// TAIL_TEXT: " { String, Char -> ... } (<root>)"
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(p : (String, Char) -> Boolean){}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
foo{ s, c -> <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// TAIL_TEXT: " { String, Char -> ... } (<root>)"
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(p : (String, Char) -> Boolean){}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fo<caret>{ x }
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// TAIL_TEXT: " { String, Char -> ... } (<root>)"
|
||||
idea/idea-completion/testData/handlers/basic/highOrderFunctions/WithArgsNonEmptyLambdaAfter.kt.after
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(p : (String, Char) -> Boolean){}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
foo { s, c -> <caret> }{ x }
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// TAIL_TEXT: " { String, Char -> ... } (<root>)"
|
||||
+12
@@ -225,6 +225,18 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/ReplaceByLambdaTemplateNoClosingParenth.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("WithArgsEmptyLambdaAfter.kt")
|
||||
public void testWithArgsEmptyLambdaAfter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/WithArgsEmptyLambdaAfter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("WithArgsNonEmptyLambdaAfter.kt")
|
||||
public void testWithArgsNonEmptyLambdaAfter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/WithArgsNonEmptyLambdaAfter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/idea-completion/testData/handlers/basic/stringTemplate")
|
||||
|
||||
Reference in New Issue
Block a user