Code completion: fixed comma key behavior for function with parameters + more tests

This commit is contained in:
Valentin Kipyatkov
2014-11-14 12:59:46 +03:00
parent 57692b1a37
commit 3ecae800af
10 changed files with 98 additions and 5 deletions
@@ -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)