From f36208718e7914cc00e2e09b0796512088d2306f Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 28 Oct 2014 21:25:34 +0300 Subject: [PATCH] Smart completion: fixed lookup string behaviour for "::xxx" items --- .../completion/KotlinCompletionCharFilter.kt | 47 ++++++++++++------- .../completion/smart/SmartCompletion.kt | 1 + 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/completion/KotlinCompletionCharFilter.kt b/idea/src/org/jetbrains/jet/plugin/completion/KotlinCompletionCharFilter.kt index 6f00262178e..191b741e36d 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/KotlinCompletionCharFilter.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/KotlinCompletionCharFilter.kt @@ -25,34 +25,45 @@ import com.intellij.openapi.util.Key public class KotlinCompletionCharFilter() : CharFilter() { class object { - public val ACCEPT_OPENING_BRACE: Key = Key("JetCompletionCharFilter.ACCEPT_OPENNING_BRACE") - public val ACCEPT_EQ: Key = Key("JetCompletionCharFilter.ACCEPT_EQ") + public val ACCEPT_OPENING_BRACE: Key = Key("KotlinCompletionCharFilter.ACCEPT_OPENNING_BRACE") + public val ACCEPT_EQ: Key = Key("KotlinCompletionCharFilter.ACCEPT_EQ") } public override fun acceptChar(c : Char, prefixLength : Int, lookup : Lookup) : Result? { if (lookup.getPsiFile() !is JetFile) return null + if (!lookup.isCompletion()) return null - if (c == '.' && prefixLength == 0 && !lookup.isSelectionTouched()) { - val caret = lookup.getEditor().getCaretModel().getOffset() - if (caret > 0 && (lookup.getEditor().getDocument().getCharsSequence().charAt(caret - 1)) == '.') { - return Result.HIDE_LOOKUP + if (Character.isJavaIdentifierPart(c) || c == ':' /* used in '::xxx'*/) return CharFilter.Result.ADD_TO_PREFIX + return when (c) { + '.' -> { + if (prefixLength == 0 && !lookup.isSelectionTouched()) { + val caret = lookup.getEditor().getCaretModel().getOffset() + if (caret > 0 && lookup.getEditor().getDocument().getCharsSequence()[caret - 1] == '.') { + return Result.HIDE_LOOKUP + } + } + Result.SELECT_ITEM_AND_FINISH_LOOKUP } - } - if (c == '{') { - val currentItem = lookup.getCurrentItem() - if (currentItem != null && currentItem.getUserData(ACCEPT_OPENING_BRACE) ?: false) { - return Result.SELECT_ITEM_AND_FINISH_LOOKUP + '(' -> { + val currentItem = lookup.getCurrentItem() + if (currentItem != null && currentItem.getUserData(ACCEPT_OPENING_BRACE) ?: false) + Result.SELECT_ITEM_AND_FINISH_LOOKUP + else + Result.HIDE_LOOKUP } - } - if (c == '=') { - val currentItem = lookup.getCurrentItem() - if (currentItem != null && currentItem.getUserData(ACCEPT_EQ) ?: false) { - return Result.SELECT_ITEM_AND_FINISH_LOOKUP + '=' -> { + val currentItem = lookup.getCurrentItem() + if (currentItem != null && currentItem.getUserData(ACCEPT_EQ) ?: false) + Result.SELECT_ITEM_AND_FINISH_LOOKUP + else + Result.HIDE_LOOKUP } - } - return null + ',', ' ' -> Result.SELECT_ITEM_AND_FINISH_LOOKUP + + else -> return CharFilter.Result.HIDE_LOOKUP + } } } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt index 877efc860f8..319a578114d 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/SmartCompletion.kt @@ -241,6 +241,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression, val text = "::" + (if (descriptor is ConstructorDescriptor) descriptor.getContainingDeclaration().getName() else descriptor.getName()) lookupElement = object: LookupElementDecorator(lookupElement) { override fun getLookupString() = text + override fun getAllLookupStrings() = setOf(text) override fun renderElement(presentation: LookupElementPresentation) { super.renderElement(presentation)