Preference of properties to functions made lower priority in completion
This commit is contained in:
@@ -233,9 +233,9 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
|||||||
|
|
||||||
val importableFqNameClassifier = ImportableFqNameClassifier(file)
|
val importableFqNameClassifier = ImportableFqNameClassifier(file)
|
||||||
|
|
||||||
sorter = sorter.weighBefore("stats", DeprecatedWeigher, PriorityWeigher, NotImportedWeigher(importableFqNameClassifier), KindWeigher)
|
sorter = sorter.weighBefore("stats", DeprecatedWeigher, PriorityWeigher, NotImportedWeigher(importableFqNameClassifier), KindWeigher, CallableWeigher)
|
||||||
|
|
||||||
sorter = sorter.weighAfter("stats", ImportedWeigher(importableFqNameClassifier), LocationWeigher(file, parameters.originalFile as JetFile))
|
sorter = sorter.weighAfter("stats", VariableOrFunctionWeigher, ImportedWeigher(importableFqNameClassifier), LocationWeigher(file, parameters.originalFile as JetFile))
|
||||||
|
|
||||||
sorter = sorter.weighBefore("middleMatching", PreferMatchingItemWeigher)
|
sorter = sorter.weighBefore("middleMatching", PreferMatchingItemWeigher)
|
||||||
|
|
||||||
|
|||||||
@@ -109,41 +109,51 @@ object SmartCompletionPriorityWeigher : LookupElementWeigher("kotlin.smartComple
|
|||||||
|
|
||||||
object KindWeigher : LookupElementWeigher("kotlin.kind") {
|
object KindWeigher : LookupElementWeigher("kotlin.kind") {
|
||||||
private enum class Weight {
|
private enum class Weight {
|
||||||
variable, // variable or property
|
enumMember,
|
||||||
function,
|
callable,
|
||||||
keyword,
|
keyword,
|
||||||
default,
|
default,
|
||||||
packages
|
packages
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class CompoundWeight(val weight: Weight, val callableWeight: CallableWeight? = null) : Comparable<CompoundWeight> {
|
override fun weigh(element: LookupElement): Weight {
|
||||||
override fun compareTo(other: CompoundWeight): Int {
|
|
||||||
if (callableWeight != null && other.callableWeight != null && callableWeight != other.callableWeight) {
|
|
||||||
return callableWeight.compareTo(other.callableWeight)
|
|
||||||
}
|
|
||||||
return weight.compareTo(other.weight)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun weigh(element: LookupElement): CompoundWeight {
|
|
||||||
val o = element.getObject()
|
val o = element.getObject()
|
||||||
|
|
||||||
return when (o) {
|
return when (o) {
|
||||||
is PackageLookupObject -> CompoundWeight(Weight.packages)
|
is PackageLookupObject -> Weight.packages
|
||||||
|
|
||||||
is DeclarationLookupObject -> {
|
is DeclarationLookupObject -> {
|
||||||
val descriptor = o.descriptor
|
val descriptor = o.descriptor
|
||||||
when (descriptor) {
|
when (descriptor) {
|
||||||
is VariableDescriptor -> CompoundWeight(Weight.variable, element.getUserData(CALLABLE_WEIGHT_KEY))
|
is VariableDescriptor, is FunctionDescriptor -> Weight.callable
|
||||||
is FunctionDescriptor -> CompoundWeight(Weight.function, element.getUserData(CALLABLE_WEIGHT_KEY))
|
is ClassDescriptor -> if (descriptor.kind == ClassKind.ENUM_ENTRY) Weight.enumMember else Weight.default
|
||||||
is ClassDescriptor -> if (descriptor.kind == ClassKind.ENUM_ENTRY) CompoundWeight(Weight.variable) else CompoundWeight(Weight.default)
|
else -> Weight.default
|
||||||
else -> CompoundWeight(Weight.default)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is KeywordLookupObject -> CompoundWeight(Weight.keyword)
|
is KeywordLookupObject -> Weight.keyword
|
||||||
|
|
||||||
else -> CompoundWeight(Weight.default)
|
else -> Weight.default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object CallableWeigher : LookupElementWeigher("kotlin.callableWeight") {
|
||||||
|
override fun weigh(element: LookupElement) = element.getUserData(CALLABLE_WEIGHT_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
|
object VariableOrFunctionWeigher : LookupElementWeigher("kotlin.variableOrFunction"){
|
||||||
|
private enum class Weight {
|
||||||
|
variable,
|
||||||
|
function
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun weigh(element: LookupElement): Weight? {
|
||||||
|
val descriptor = (element.`object` as? DeclarationLookupObject)?.descriptor ?: return null
|
||||||
|
return when (descriptor) {
|
||||||
|
is VariableDescriptor -> Weight.variable
|
||||||
|
is FunctionDescriptor -> Weight.function
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user