KT-1968 Double closing parentheses entered when completing unit function

#KT-1968 Fixed
This commit is contained in:
Nikolay Krasko
2012-12-26 18:02:25 +04:00
parent 9b9e338131
commit 93b7e9add9
4 changed files with 29 additions and 3 deletions
@@ -96,7 +96,9 @@ public class JetFunctionInsertHandler implements InsertHandler<LookupElement> {
String documentText = document.getText();
boolean braces = bracketType == BracketType.BRACES && context.getCompletionChar() != '(';
char completionChar = context.getCompletionChar();
boolean braces = bracketType == BracketType.BRACES && completionChar != '(';
char openingBracket = braces ? '{' : '(';
char closingBracket = braces ? '}' : ')';
@@ -106,7 +108,7 @@ public class JetFunctionInsertHandler implements InsertHandler<LookupElement> {
if (openingBracketIndex == -1) {
// Insert ()/{} if it's not already exist
if (braces) {
if (context.getCompletionChar() == ' ') {
if (completionChar == ' ') {
context.setAddCompletionChar(false);
}
@@ -133,7 +135,11 @@ public class JetFunctionInsertHandler implements InsertHandler<LookupElement> {
int closeBracketIndex = indexOfSkippingSpace(documentText, closingBracket, openingBracketIndex + 1);
Editor editor = context.getEditor();
if (caretPosition == CaretPosition.IN_BRACKETS || closeBracketIndex == -1) {
// Satisfy TypedHandler.handleRParen() algorithm for preventing doubling ')' char if user typed "()" manually.
boolean forcePlaceCaretIntoParentheses = completionChar == '(';
if (caretPosition == CaretPosition.IN_BRACKETS || forcePlaceCaretIntoParentheses || closeBracketIndex == -1) {
editor.getCaretModel().moveToOffset(openingBracketIndex + 1 + inBracketsShift);
AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, offsetElement);
}
@@ -0,0 +1,7 @@
// KT-1968 Double closing parentheses entered when completing unit function
package some
fun test() = 12
fun test1()
val a = <caret>
@@ -0,0 +1,7 @@
// KT-1968 Double closing parentheses entered when completing unit function
package some
fun test() = 12
fun test1()
val a = test()<caret>
@@ -92,6 +92,12 @@ public class CompletionHandlerTest extends LightCompletionTestCase {
doTest(CompletionType.BASIC, 2, null, null, ' ');
}
public void testInsertFunctionWithBothParentheses() {
configureByFile(getBeforeFileName());
type("test()");
checkResultByFile(getAfterFileName());
}
public void testInsertImportOnTab() {
doTest(CompletionType.BASIC, 2, "ArrayList", null, '\t');
}