Smart completion: fixed lookup string behaviour for "::xxx" items
This commit is contained in:
@@ -25,34 +25,45 @@ import com.intellij.openapi.util.Key
|
|||||||
|
|
||||||
public class KotlinCompletionCharFilter() : CharFilter() {
|
public class KotlinCompletionCharFilter() : CharFilter() {
|
||||||
class object {
|
class object {
|
||||||
public val ACCEPT_OPENING_BRACE: Key<Boolean> = Key<Boolean>("JetCompletionCharFilter.ACCEPT_OPENNING_BRACE")
|
public val ACCEPT_OPENING_BRACE: Key<Boolean> = Key<Boolean>("KotlinCompletionCharFilter.ACCEPT_OPENNING_BRACE")
|
||||||
public val ACCEPT_EQ: Key<Boolean> = Key<Boolean>("JetCompletionCharFilter.ACCEPT_EQ")
|
public val ACCEPT_EQ: Key<Boolean> = Key<Boolean>("KotlinCompletionCharFilter.ACCEPT_EQ")
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun acceptChar(c : Char, prefixLength : Int, lookup : Lookup) : Result? {
|
public override fun acceptChar(c : Char, prefixLength : Int, lookup : Lookup) : Result? {
|
||||||
if (lookup.getPsiFile() !is JetFile) return null
|
if (lookup.getPsiFile() !is JetFile) return null
|
||||||
|
if (!lookup.isCompletion()) return null
|
||||||
|
|
||||||
if (c == '.' && prefixLength == 0 && !lookup.isSelectionTouched()) {
|
if (Character.isJavaIdentifierPart(c) || c == ':' /* used in '::xxx'*/) return CharFilter.Result.ADD_TO_PREFIX
|
||||||
val caret = lookup.getEditor().getCaretModel().getOffset()
|
return when (c) {
|
||||||
if (caret > 0 && (lookup.getEditor().getDocument().getCharsSequence().charAt(caret - 1)) == '.') {
|
'.' -> {
|
||||||
return Result.HIDE_LOOKUP
|
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()
|
val currentItem = lookup.getCurrentItem()
|
||||||
if (currentItem != null && currentItem.getUserData(ACCEPT_OPENING_BRACE) ?: false) {
|
if (currentItem != null && currentItem.getUserData(ACCEPT_OPENING_BRACE) ?: false)
|
||||||
return Result.SELECT_ITEM_AND_FINISH_LOOKUP
|
Result.SELECT_ITEM_AND_FINISH_LOOKUP
|
||||||
|
else
|
||||||
|
Result.HIDE_LOOKUP
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (c == '=') {
|
'=' -> {
|
||||||
val currentItem = lookup.getCurrentItem()
|
val currentItem = lookup.getCurrentItem()
|
||||||
if (currentItem != null && currentItem.getUserData(ACCEPT_EQ) ?: false) {
|
if (currentItem != null && currentItem.getUserData(ACCEPT_EQ) ?: false)
|
||||||
return Result.SELECT_ITEM_AND_FINISH_LOOKUP
|
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())
|
val text = "::" + (if (descriptor is ConstructorDescriptor) descriptor.getContainingDeclaration().getName() else descriptor.getName())
|
||||||
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
|
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
|
||||||
override fun getLookupString() = text
|
override fun getLookupString() = text
|
||||||
|
override fun getAllLookupStrings() = setOf(text)
|
||||||
|
|
||||||
override fun renderElement(presentation: LookupElementPresentation) {
|
override fun renderElement(presentation: LookupElementPresentation) {
|
||||||
super.renderElement(presentation)
|
super.renderElement(presentation)
|
||||||
|
|||||||
Reference in New Issue
Block a user