Ordering of parameter name suggestions by type relevance
This commit is contained in:
@@ -89,7 +89,7 @@ private object KindWeigher : LookupElementWeigher("kotlin.kind") {
|
||||
val o = element.getObject()
|
||||
|
||||
return when (o) {
|
||||
is DeclarationDescriptorLookupObjectImpl -> {
|
||||
is DeclarationDescriptorLookupObject -> {
|
||||
val descriptor = o.descriptor
|
||||
when (descriptor) {
|
||||
is VariableDescriptor -> CompoundWeight(Weight.variable, element.getUserData(CALLABLE_WEIGHT_KEY))
|
||||
@@ -136,7 +136,7 @@ private class JetDeclarationRemotenessWeigher(private val file: JetFile) : Looku
|
||||
|
||||
override fun weigh(element: LookupElement): Weight {
|
||||
val o = element.getObject()
|
||||
if (o is DeclarationDescriptorLookupObjectImpl) {
|
||||
if (o is DeclarationDescriptorLookupObject) {
|
||||
val elementFile = o.psiElement?.getContainingFile()
|
||||
if (elementFile is JetFile && elementFile.getOriginalFile() == file) {
|
||||
return Weight.thisFile
|
||||
|
||||
+1
-2
@@ -129,10 +129,9 @@ class ParameterNameAndTypeCompletion(
|
||||
val nameAndType: NameAndType,
|
||||
factory: LookupElementFactory
|
||||
) : LookupElementDecorator<LookupElement>(nameAndType.createTypeLookupElement(factory)) {
|
||||
override fun getObject() = nameAndType
|
||||
|
||||
override fun equals(other: Any?)
|
||||
= other is MyLookupElement && nameAndType.parameterName == other.getObject().parameterName && getDelegate() == other.getDelegate()
|
||||
= other is MyLookupElement && nameAndType.parameterName == other.nameAndType.parameterName && getDelegate() == other.getDelegate()
|
||||
override fun hashCode() = nameAndType.parameterName.hashCode()
|
||||
|
||||
override fun getLookupString() = nameAndType.parameterName
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class MyClassA
|
||||
deprecated class MyClassB
|
||||
class MyClassC
|
||||
|
||||
fun foo(myCla<caret>)
|
||||
|
||||
// ORDER: myClassA
|
||||
// ORDER: myClassC
|
||||
// ORDER: myClassB
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package ppp
|
||||
|
||||
class MyClassA
|
||||
class MyClassB
|
||||
class MyClassC
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import ppp.MyClassB
|
||||
|
||||
fun foo(myCla<caret>)
|
||||
|
||||
// ORDER: myClassB
|
||||
// ORDER: myClassA
|
||||
// ORDER: myClassC
|
||||
+8
-9
@@ -17,16 +17,15 @@
|
||||
package org.jetbrains.kotlin.idea.completion.test.weighers
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import org.jetbrains.kotlin.idea.completion.test.COMPLETION_TEST_DATA_BASE_PATH
|
||||
import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.JetLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.JetTestUtils
|
||||
import org.jetbrains.kotlin.test.util.configureWithExtraFile
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
public abstract class AbstractCompletionWeigherTest(val completionType: CompletionType, val relativeTestDataPath: String) : JetLightCodeInsightFixtureTestCase() {
|
||||
public abstract class AbstractCompletionWeigherTest(val completionType: CompletionType) : JetLightCodeInsightFixtureTestCase() {
|
||||
fun doTest(path: String) {
|
||||
myFixture.configureWithExtraFile(path, ".Data", ".Data1", ".Data2", ".Data3")
|
||||
|
||||
@@ -39,13 +38,13 @@ public abstract class AbstractCompletionWeigherTest(val completionType: Completi
|
||||
myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
|
||||
}
|
||||
|
||||
protected override fun getTestDataPath() : String? {
|
||||
return File(COMPLETION_TEST_DATA_BASE_PATH, relativeTestDataPath).getPath() + File.separator
|
||||
}
|
||||
override fun getTestDataPath() = JetTestUtils.getHomeDirectory()
|
||||
}
|
||||
|
||||
public abstract class AbstractBasicCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.BASIC, "/weighers/basic")
|
||||
public abstract class AbstractBasicCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.BASIC) {
|
||||
override fun getProjectDescriptor() = JetLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
|
||||
public abstract class AbstractSmartCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.SMART, "/weighers/smart") {
|
||||
public abstract class AbstractSmartCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.SMART) {
|
||||
override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
}
|
||||
|
||||
+21
@@ -130,4 +130,25 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/ReturnBoolean.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/idea-completion/testData/weighers/basic/parameterNameAndType")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ParameterNameAndType extends AbstractBasicCompletionWeigherTest {
|
||||
public void testAllFilesPresentInParameterNameAndType() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/weighers/basic/parameterNameAndType"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("Deprecated.kt")
|
||||
public void testDeprecated() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/parameterNameAndType/Deprecated.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ImportedFirst.kt")
|
||||
public void testImportedFirst() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/parameterNameAndType/ImportedFirst.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user