Fixed parameter name&type auto-popup completion to insert "dynamic" on typing ": "
This commit is contained in:
+8
-2
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import com.intellij.codeInsight.completion.*
|
||||
import com.intellij.codeInsight.completion.CompletionParameters
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.patterns.PatternCondition
|
||||
import com.intellij.patterns.StandardPatterns
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
@@ -160,7 +162,11 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
}
|
||||
|
||||
if (completionKind == CompletionKind.PARAMETER_NAME || completionKind == CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME) {
|
||||
collector.suppressItemSelectionByCharsOnTyping = true
|
||||
collector.addLookupElementPostProcessor { lookupElement ->
|
||||
lookupElement.putUserData(KotlinCompletionCharFilter.SUPPRESS_ITEM_SELECTION_BY_CHARS_ON_TYPING, Unit)
|
||||
lookupElement.putUserData(KotlinCompletionCharFilter.HIDE_LOOKUP_ON_COLON, Unit)
|
||||
lookupElement
|
||||
}
|
||||
}
|
||||
|
||||
if (completionKind != CompletionKind.NAMED_ARGUMENTS_ONLY) {
|
||||
|
||||
+7
-3
@@ -32,9 +32,10 @@ import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
|
||||
|
||||
public class KotlinCompletionCharFilter() : CharFilter() {
|
||||
companion object {
|
||||
public val ACCEPT_OPENING_BRACE: Key<Unit> = Key("KotlinCompletionCharFilter.ACCEPT_OPENNING_BRACE")
|
||||
public val ACCEPT_OPENING_BRACE: Key<Unit> = Key("KotlinCompletionCharFilter.ACCEPT_OPENING_BRACE")
|
||||
|
||||
public val SUPPRESS_ITEM_SELECTION_BY_CHARS_ON_TYPING: Key<Unit> = Key("KotlinCompletionCharFilter.SUPPRESS_ITEM_SELECTION_BY_CHARS_ON_TYPING")
|
||||
public val HIDE_LOOKUP_ON_COLON: Key<Unit> = Key("KotlinCompletionCharFilter.HIDE_LOOKUP_ON_COLON")
|
||||
|
||||
public val JUST_TYPING_PREFIX: Key<String> = Key("KotlinCompletionCharFilter.JUST_TYPING_PREFIX")
|
||||
}
|
||||
@@ -59,8 +60,11 @@ public class KotlinCompletionCharFilter() : CharFilter() {
|
||||
return Result.HIDE_LOOKUP
|
||||
}
|
||||
|
||||
if (c == ':' /* used in '::xxx'*/) {
|
||||
return CharFilter.Result.ADD_TO_PREFIX
|
||||
if (c == ':') {
|
||||
return when {
|
||||
currentItem?.getUserData(HIDE_LOOKUP_ON_COLON) != null -> Result.HIDE_LOOKUP
|
||||
else -> CharFilter.Result.ADD_TO_PREFIX /* used in '::xxx'*/
|
||||
}
|
||||
}
|
||||
|
||||
if (!lookup.isSelectionTouched()) {
|
||||
|
||||
+9
-4
@@ -54,6 +54,8 @@ class LookupElementsCollector(
|
||||
.withPrefixMatcher(defaultPrefixMatcher)
|
||||
.addKotlinSorting(completionParameters)
|
||||
|
||||
private val postProcessors = ArrayList<(LookupElement) -> LookupElement>()
|
||||
|
||||
public fun flushToResultSet() {
|
||||
if (!elements.isEmpty()) {
|
||||
for ((prefixMatcher, elements) in elements) {
|
||||
@@ -71,7 +73,9 @@ class LookupElementsCollector(
|
||||
public var isResultEmpty: Boolean = true
|
||||
private set
|
||||
|
||||
public var suppressItemSelectionByCharsOnTyping: Boolean = false
|
||||
public fun addLookupElementPostProcessor(processor: (LookupElement) -> LookupElement) {
|
||||
postProcessors.add(processor)
|
||||
}
|
||||
|
||||
public fun addDescriptorElements(descriptors: Iterable<DeclarationDescriptor>,
|
||||
suppressAutoInsertion: Boolean, // auto-insertion suppression is used for elements that require adding an import
|
||||
@@ -178,11 +182,12 @@ class LookupElementsCollector(
|
||||
}
|
||||
}
|
||||
|
||||
if (suppressItemSelectionByCharsOnTyping) {
|
||||
decorated.putUserData(KotlinCompletionCharFilter.SUPPRESS_ITEM_SELECTION_BY_CHARS_ON_TYPING, Unit)
|
||||
var result: LookupElement = decorated
|
||||
for (postProcessor in postProcessors) {
|
||||
result = postProcessor(result)
|
||||
}
|
||||
|
||||
elements.getOrPut(prefixMatcher) { ArrayList() }.add(decorated)
|
||||
elements.getOrPut(prefixMatcher) { ArrayList() }.add(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user