Smart completion: fixed lookup string behaviour for "::xxx" items

This commit is contained in:
Valentin Kipyatkov
2014-10-28 21:25:34 +03:00
parent dfc8c9be16
commit f36208718e
2 changed files with 30 additions and 18 deletions
@@ -25,34 +25,45 @@ import com.intellij.openapi.util.Key
public class KotlinCompletionCharFilter() : CharFilter() {
class object {
public val ACCEPT_OPENING_BRACE: Key<Boolean> = Key<Boolean>("JetCompletionCharFilter.ACCEPT_OPENNING_BRACE")
public val ACCEPT_EQ: Key<Boolean> = Key<Boolean>("JetCompletionCharFilter.ACCEPT_EQ")
public val ACCEPT_OPENING_BRACE: Key<Boolean> = Key<Boolean>("KotlinCompletionCharFilter.ACCEPT_OPENNING_BRACE")
public val ACCEPT_EQ: Key<Boolean> = Key<Boolean>("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
}
}
}
@@ -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>(lookupElement) {
override fun getLookupString() = text
override fun getAllLookupStrings() = setOf(text)
override fun renderElement(presentation: LookupElementPresentation) {
super.renderElement(presentation)