Implemented own version of LookupElementProximityWeigher (the standard one checks getObject() instanceof PsiElement)
#KT-8842 Fixed
This commit is contained in:
@@ -16,10 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.completion
|
package org.jetbrains.kotlin.idea.completion
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.completion.CompletionLocation
|
||||||
|
import com.intellij.codeInsight.completion.CompletionWeigher
|
||||||
import com.intellij.codeInsight.lookup.LookupElement
|
import com.intellij.codeInsight.lookup.LookupElement
|
||||||
import com.intellij.codeInsight.lookup.LookupElementWeigher
|
import com.intellij.codeInsight.lookup.LookupElementWeigher
|
||||||
import com.intellij.codeInsight.lookup.WeighingContext
|
import com.intellij.codeInsight.lookup.WeighingContext
|
||||||
import com.intellij.openapi.module.ModuleUtilCore
|
import com.intellij.openapi.module.ModuleUtilCore
|
||||||
|
import com.intellij.psi.util.proximity.PsiProximityComparator
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
@@ -102,6 +105,14 @@ class LocationWeigher(private val file: JetFile, private val originalFile: JetFi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// analog of LookupElementProximityWeigher which does not work for us
|
||||||
|
object KotlinLookupElementProximityWeigher : CompletionWeigher() {
|
||||||
|
override fun weigh(element: LookupElement, location: CompletionLocation): Comparable<Nothing>? {
|
||||||
|
val psiElement = (element.`object` as? DeclarationLookupObject)?.psiElement ?: return null
|
||||||
|
return PsiProximityComparator.getProximity({ psiElement }, location.completionParameters.position, location.processingContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
object SmartCompletionPriorityWeigher : LookupElementWeigher("kotlin.smartCompletionPriority") {
|
object SmartCompletionPriorityWeigher : LookupElementWeigher("kotlin.smartCompletionPriority") {
|
||||||
override fun weigh(element: LookupElement, context: WeighingContext)
|
override fun weigh(element: LookupElement, context: WeighingContext)
|
||||||
= element.getUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY) ?: SmartCompletionItemPriority.DEFAULT
|
= element.getUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY) ?: SmartCompletionItemPriority.DEFAULT
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package dependency
|
||||||
|
|
||||||
|
public class Data
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import dependency.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun foo(): Dat<caret>
|
||||||
|
|
||||||
|
// ORDER: Date
|
||||||
|
// ORDER: Data
|
||||||
+6
@@ -131,6 +131,12 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PreferFromJdk.kt")
|
||||||
|
public void testPreferFromJdk() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/PreferFromJdk.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("PropertiesBeforeKeywords.kt")
|
@TestMetadata("PropertiesBeforeKeywords.kt")
|
||||||
public void testPropertiesBeforeKeywords() throws Exception {
|
public void testPropertiesBeforeKeywords() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/PropertiesBeforeKeywords.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/PropertiesBeforeKeywords.kt");
|
||||||
|
|||||||
@@ -331,6 +331,8 @@
|
|||||||
<statistician key="completion" implementationClass="org.jetbrains.kotlin.idea.completion.KotlinCompletionStatistician"/>
|
<statistician key="completion" implementationClass="org.jetbrains.kotlin.idea.completion.KotlinCompletionStatistician"/>
|
||||||
<statistician key="proximity" implementationClass="org.jetbrains.kotlin.idea.completion.KotlinProximityStatistician"/>
|
<statistician key="proximity" implementationClass="org.jetbrains.kotlin.idea.completion.KotlinProximityStatistician"/>
|
||||||
|
|
||||||
|
<weigher key="completion" implementationClass="org.jetbrains.kotlin.idea.completion.KotlinLookupElementProximityWeigher" id="kotlin.proximity" order="after proximity"/>
|
||||||
|
|
||||||
<psi.referenceContributor language="jet" implementation="org.jetbrains.kotlin.idea.references.JetReferenceContributor"/>
|
<psi.referenceContributor language="jet" implementation="org.jetbrains.kotlin.idea.references.JetReferenceContributor"/>
|
||||||
|
|
||||||
<renamePsiElementProcessor id="KotlinClass"
|
<renamePsiElementProcessor id="KotlinClass"
|
||||||
|
|||||||
Reference in New Issue
Block a user