diff --git a/idea/src/org/jetbrains/jet/plugin/completion/handlers/KotlinKeywordInsertHandler.kt b/idea/src/org/jetbrains/jet/plugin/completion/handlers/KotlinKeywordInsertHandler.kt index 21b519c63cc..89ffe593d0c 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/handlers/KotlinKeywordInsertHandler.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/handlers/KotlinKeywordInsertHandler.kt @@ -35,9 +35,13 @@ public object KotlinKeywordInsertHandler : InsertHandler { JetTokens.CONTINUE_KEYWORD.toString()) override fun handleInsert(context: InsertionContext, item: LookupElement) { - val keyword = item.getLookupString() + if (shouldInsertSpaceAfter(item.getLookupString(), context)) { + WithTailInsertHandler.spaceTail().postHandleInsert(context, item) + } + } - if (keyword in NO_SPACE_AFTER) return + private fun shouldInsertSpaceAfter(keyword: String, context: InsertionContext): Boolean { + if (keyword in NO_SPACE_AFTER) return false if (keyword == JetTokens.RETURN_KEYWORD.toString()) { val element = context.getFile().findElementAt(context.getStartOffset()) @@ -45,12 +49,11 @@ public object KotlinKeywordInsertHandler : InsertHandler { val jetFunction = PsiTreeUtil.getParentOfType(element, javaClass()) if (jetFunction != null && (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getTypeReference()))) { // No space for void function - return + return false } } } - // Add space after keyword - WithTailInsertHandler.spaceTail().postHandleInsert(context, item) + return true } }