Code completion: fixed comma key behavior for function with parameters + more tests
This commit is contained in:
+9
-5
@@ -163,14 +163,12 @@ public class JetFunctionInsertHandler(val caretPosition : CaretPosition, val lam
|
||||
}
|
||||
|
||||
openingBracketOffset = indexOfSkippingSpace(document, openingBracket, offset)
|
||||
assert (openingBracketOffset != -1) { "If there wasn't open bracket it should already have been inserted" }
|
||||
assert(openingBracketOffset != -1, "If there wasn't open bracket it should already have been inserted")
|
||||
|
||||
val closeBracketOffset = indexOfSkippingSpace(document, closingBracket, openingBracketOffset + 1)
|
||||
val editor = context.getEditor()
|
||||
|
||||
var forcePlaceCaretIntoParentheses = completionChar == '('
|
||||
|
||||
if (caretPosition == CaretPosition.IN_BRACKETS || forcePlaceCaretIntoParentheses || closeBracketOffset == -1) {
|
||||
if (shouldPlaceCaretInBrackets(completionChar) || closeBracketOffset == -1) {
|
||||
editor.getCaretModel().moveToOffset(openingBracketOffset + 1 + inBracketsShift)
|
||||
AutoPopupController.getInstance(context.getProject())?.autoPopupParameterInfo(editor, offsetElement)
|
||||
}
|
||||
@@ -178,13 +176,19 @@ public class JetFunctionInsertHandler(val caretPosition : CaretPosition, val lam
|
||||
editor.getCaretModel().moveToOffset(closeBracketOffset + 1)
|
||||
}
|
||||
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getDocument())
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitDocument(document)
|
||||
|
||||
if (lambdaInfo != null && lambdaInfo.explicitParameters) {
|
||||
insertLambdaTemplate(context, TextRange(openingBracketOffset, closeBracketOffset + 1), lambdaInfo.lambdaType)
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldPlaceCaretInBrackets(completionChar: Char): Boolean {
|
||||
if (completionChar == ',' || completionChar == '.') return false
|
||||
if (completionChar == '(') return true
|
||||
return caretPosition == CaretPosition.IN_BRACKETS
|
||||
}
|
||||
|
||||
class object {
|
||||
public val NO_PARAMETERS_HANDLER: JetFunctionInsertHandler = JetFunctionInsertHandler(CaretPosition.AFTER_BRACKETS, null)
|
||||
public val WITH_PARAMETERS_HANDLER: JetFunctionInsertHandler = JetFunctionInsertHandler(CaretPosition.IN_BRACKETS, null)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo() {}
|
||||
|
||||
fun bar() {
|
||||
x(<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// CHAR: ','
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo() {}
|
||||
|
||||
fun bar() {
|
||||
x(foo(), <caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// CHAR: ','
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(p: Int) {}
|
||||
|
||||
fun bar() {
|
||||
x(<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// CHAR: ','
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(p: Int) {}
|
||||
|
||||
fun bar() {
|
||||
x(foo(), <caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// CHAR: ','
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(): String = ""
|
||||
|
||||
fun bar() {
|
||||
<caret>
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// CHAR: .
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(): String = ""
|
||||
|
||||
fun bar() {
|
||||
foo().<caret>
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// CHAR: .
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(p: Int): String = ""
|
||||
|
||||
fun bar() {
|
||||
<caret>
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// CHAR: .
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(p: Int): String = ""
|
||||
|
||||
fun bar() {
|
||||
foo().<caret>
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
// CHAR: .
|
||||
+25
@@ -19,6 +19,7 @@ package org.jetbrains.jet.completion.handlers;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -71,6 +72,18 @@ public class CompletionCharFilterTestGenerated extends AbstractCompletionCharFil
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("CommaForFunction1.kt")
|
||||
public void testCommaForFunction1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/CommaForFunction1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("CommaForFunction2.kt")
|
||||
public void testCommaForFunction2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/CommaForFunction2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithLambdaArg1.kt")
|
||||
public void testConstructorWithLambdaArg1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/ConstructorWithLambdaArg1.kt");
|
||||
@@ -89,6 +102,18 @@ public class CompletionCharFilterTestGenerated extends AbstractCompletionCharFil
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DotAfterFun1.kt")
|
||||
public void testDotAfterFun1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/DotAfterFun1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DotAfterFun2.kt")
|
||||
public void testDotAfterFun2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/DotAfterFun2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FunctionWithLambdaArg1.kt")
|
||||
public void testFunctionWithLambdaArg1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/charFilter/FunctionWithLambdaArg1.kt");
|
||||
|
||||
Reference in New Issue
Block a user