More clear code

This commit is contained in:
Valentin Kipyatkov
2015-10-02 16:36:01 +03:00
parent 184d59a645
commit 2e02f02d9b
2 changed files with 5 additions and 8 deletions
@@ -287,7 +287,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
match.isMatch() match.isMatch()
} }
if (matched) { if (matched) {
lookupElement.putUserData(SmartCompletionInBasicWeigher.KEYWORD_VALUE_MATCHED_KEY, matched) lookupElement.putUserData(SmartCompletionInBasicWeigher.KEYWORD_VALUE_MATCHED_KEY, Unit)
lookupElement.putUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY, priority) lookupElement.putUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY, priority)
} }
collector.addElement(lookupElement) collector.addElement(lookupElement)
@@ -184,7 +184,7 @@ class SmartCompletionInBasicWeigher(
) : LookupElementWeigher("kotlin.smartInBasic", true, false) { ) : LookupElementWeigher("kotlin.smartInBasic", true, false) {
companion object { companion object {
val KEYWORD_VALUE_MATCHED_KEY = Key<Boolean>("SmartCompletionInBasicWeigher.KEYWORD_VALUE_MATCHED_KEY") val KEYWORD_VALUE_MATCHED_KEY = Key<Unit>("SmartCompletionInBasicWeigher.KEYWORD_VALUE_MATCHED_KEY")
} }
private val descriptorsToSkip = smartCompletion.descriptorsToSkip private val descriptorsToSkip = smartCompletion.descriptorsToSkip
@@ -201,14 +201,11 @@ class SmartCompletionInBasicWeigher(
private val DESCRIPTOR_TO_SKIP_WEIGHT = -1L // if descriptor is skipped from smart completion then it's probably irrelevant private val DESCRIPTOR_TO_SKIP_WEIGHT = -1L // if descriptor is skipped from smart completion then it's probably irrelevant
override fun weigh(element: LookupElement): Long { override fun weigh(element: LookupElement): Long {
val keywordValueMatched = element.getUserData(KEYWORD_VALUE_MATCHED_KEY) if (element.getUserData(KEYWORD_VALUE_MATCHED_KEY) != null) {
val smartCompletionPriority = element.getUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY) return fullMatchWeight(0)
if (keywordValueMatched != null) {
return if (keywordValueMatched) fullMatchWeight(0) else NO_MATCH_WEIGHT
} }
if (smartCompletionPriority != null) { // it's an "additional item" came from smart completion, don't match it against expected type if (element.getUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY) != null) { // it's an "additional item" came from smart completion, don't match it against expected type
return smartCompletionItemWeight(element.getUserData(NAME_SIMILARITY_KEY) ?: 0) return smartCompletionItemWeight(element.getUserData(NAME_SIMILARITY_KEY) ?: 0)
} }