diff --git a/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetFunctionInsertHandler.java b/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetFunctionInsertHandler.java index 69b62b2f075..1409c43edb7 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetFunctionInsertHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/completion/handlers/JetFunctionInsertHandler.java @@ -104,6 +104,10 @@ public class JetFunctionInsertHandler implements InsertHandler { if (openingBracketIndex == -1) { // Insert ()/{} if it's not already exist if (braces) { + if (context.getCompletionChar() == ' ') { + context.setAddCompletionChar(false); + } + if (isInsertSpacesInOneLineFunctionEnabled(offsetElement.getProject())) { document.insertString(offset, " { }"); inBracketsShift = 1; diff --git a/idea/testData/completion/handlers/FunctionLiteralInsertOnSpace.kt b/idea/testData/completion/handlers/FunctionLiteralInsertOnSpace.kt new file mode 100644 index 00000000000..cbd9d8f7e88 --- /dev/null +++ b/idea/testData/completion/handlers/FunctionLiteralInsertOnSpace.kt @@ -0,0 +1,7 @@ +class Some +fun Some.filter(predicate : (T) -> jet.Boolean) = throw UnsupportedOperationException() + +fun main(args: Array) { + Some().fil +} + diff --git a/idea/testData/completion/handlers/FunctionLiteralInsertOnSpace.kt.after b/idea/testData/completion/handlers/FunctionLiteralInsertOnSpace.kt.after new file mode 100644 index 00000000000..cd457bc2117 --- /dev/null +++ b/idea/testData/completion/handlers/FunctionLiteralInsertOnSpace.kt.after @@ -0,0 +1,7 @@ +class Some +fun Some.filter(predicate : (T) -> jet.Boolean) = throw UnsupportedOperationException() + +fun main(args: Array) { + Some().filter { } +} + diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/CompletionHandlerTest.java b/idea/tests/org/jetbrains/jet/completion/handlers/CompletionHandlerTest.java index e1a092f032d..5174a927dbd 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/CompletionHandlerTest.java +++ b/idea/tests/org/jetbrains/jet/completion/handlers/CompletionHandlerTest.java @@ -38,7 +38,7 @@ import java.io.File; public class CompletionHandlerTest extends LightCompletionTestCase { public void testClassCompletionImport() { - doTest(CompletionType.BASIC, 2, "SortedSet", null); + doTest(CompletionType.BASIC, 2, "SortedSet", null, '\n'); } public void testDoNotInsertImportForAlreadyImported() { @@ -46,7 +46,7 @@ public class CompletionHandlerTest extends LightCompletionTestCase { } public void testNonStandardArray() { - doTest(CompletionType.BASIC, 2, "Array", "java.lang.reflect"); + doTest(CompletionType.BASIC, 2, "Array", "java.lang.reflect", '\n'); } public void testNoParamsFunction() { @@ -79,6 +79,10 @@ public class CompletionHandlerTest extends LightCompletionTestCase { doTest(); } + public void testFunctionLiteralInsertOnSpace() { + doTest(' '); + } + public void testFunctionLiteralInsertWhenNoSpacesForBraces() { CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); JetCodeStyleSettings jetSettings = settings.getCustomSettings(JetCodeStyleSettings.class); @@ -96,14 +100,18 @@ public class CompletionHandlerTest extends LightCompletionTestCase { } public void testHigherOrderFunctionWithArg() { - doTest(CompletionType.BASIC, 2, "filterNot", null); + doTest(CompletionType.BASIC, 2, "filterNot", null, '\n'); } public void doTest() { - doTest(CompletionType.BASIC, 2, null, null); + doTest('\n'); } - public void doTest(CompletionType type, int time, @Nullable String lookupString, @Nullable String tailText) { + public void doTest(char completionChar) { + doTest(CompletionType.BASIC, 2, null, null, completionChar); + } + + public void doTest(CompletionType type, int time, @Nullable String lookupString, @Nullable String tailText, char completionChar) { try { configureByFileNoComplete(getBeforeFileName()); setType(type); @@ -113,7 +121,7 @@ public class CompletionHandlerTest extends LightCompletionTestCase { LookupElement item = getExistentLookupElement(lookupString, tailText); if (item != null) { - selectItem(item, '\n'); + selectItem(item, completionChar); } } else {