KT-1968 Double closing parentheses entered when completing unit function
#KT-1968 Fixed
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user