Completion: fixed ordering for packages + exclude for package items supported too
This commit is contained in:
@@ -90,12 +90,13 @@ private object KindWeigher : LookupElementWeigher("kotlin.kind") {
|
||||
val o = element.getObject()
|
||||
|
||||
return when (o) {
|
||||
is PackageLookupObject -> CompoundWeight(Weight.packages)
|
||||
|
||||
is DeclarationLookupObject -> {
|
||||
val descriptor = o.descriptor
|
||||
when (descriptor) {
|
||||
is VariableDescriptor -> CompoundWeight(Weight.variable, element.getUserData(CALLABLE_WEIGHT_KEY))
|
||||
is FunctionDescriptor -> CompoundWeight(Weight.function, element.getUserData(CALLABLE_WEIGHT_KEY))
|
||||
is PackageViewDescriptor -> CompoundWeight(Weight.packages)
|
||||
else -> CompoundWeight(Weight.default)
|
||||
}
|
||||
}
|
||||
@@ -144,9 +145,16 @@ private class DeclarationRemotenessWeigher(private val file: JetFile) : LookupEl
|
||||
}
|
||||
|
||||
val fqName = o.importableFqName
|
||||
// Invalid name can be met for companion object descriptor: Test.MyTest.A.<no name provided>.testOther
|
||||
if (fqName != null) {
|
||||
val importPath = ImportPath(fqName, false)
|
||||
|
||||
if (o is PackageLookupObject) {
|
||||
return when {
|
||||
importCache.isImportedWithPreciseImport(fqName) -> Weight.preciseImport
|
||||
else -> Weight.default
|
||||
}
|
||||
}
|
||||
|
||||
return when {
|
||||
JavaToKotlinClassMap.INSTANCE.mapPlatformClass(fqName).isNotEmpty() -> Weight.notToBeUsedInKotlin
|
||||
ImportInsertHelper.getInstance(file.getProject()).isImportedWithDefault(importPath, file) -> Weight.kotlinDefaultImport
|
||||
|
||||
+15
-14
@@ -42,6 +42,20 @@ import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import javax.swing.Icon
|
||||
|
||||
public data class PackageLookupObject(val fqName: FqName) : DeclarationLookupObject {
|
||||
override val psiElement: PsiElement? get() = null
|
||||
|
||||
override val descriptor: DeclarationDescriptor? get() = null
|
||||
|
||||
override val name: Name get() = fqName.shortName()
|
||||
|
||||
override val importableFqName: FqName get() = fqName
|
||||
|
||||
override val isDeprecated: Boolean get() = false
|
||||
|
||||
override fun getIcon(flags: Int) = PlatformIcons.PACKAGE_ICON
|
||||
}
|
||||
|
||||
public class LookupElementFactory(
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val receiverTypes: Collection<JetType>
|
||||
@@ -142,8 +156,7 @@ public class LookupElementFactory(
|
||||
}
|
||||
|
||||
public fun createLookupElementForPackage(name: FqName): LookupElement {
|
||||
val shortName = name.shortName()
|
||||
var element = LookupElementBuilder.create(PackageLookupObject(shortName), shortName.asString())
|
||||
var element = LookupElementBuilder.create(PackageLookupObject(name), name.shortName().asString())
|
||||
|
||||
element = element.withInsertHandler(BaseDeclarationInsertHandler())
|
||||
|
||||
@@ -154,18 +167,6 @@ public class LookupElementFactory(
|
||||
return element.withIconFromLookupObject()
|
||||
}
|
||||
|
||||
private data class PackageLookupObject(override val name: Name) : DeclarationLookupObject {
|
||||
override val psiElement: PsiElement? get() = null
|
||||
|
||||
override val descriptor: DeclarationDescriptor? get() = null
|
||||
|
||||
override val importableFqName: FqName? get() = null
|
||||
|
||||
override val isDeprecated: Boolean get() = false
|
||||
|
||||
override fun getIcon(flags: Int) = PlatformIcons.PACKAGE_ICON
|
||||
}
|
||||
|
||||
private fun createLookupElement(
|
||||
descriptor: DeclarationDescriptor,
|
||||
declaration: PsiElement?,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package my.koza
|
||||
|
||||
class K
|
||||
|
||||
fun kokoFun(){}
|
||||
@@ -0,0 +1,3 @@
|
||||
package kotlin
|
||||
|
||||
class K1
|
||||
@@ -0,0 +1,10 @@
|
||||
import my.koza
|
||||
|
||||
class A {
|
||||
val v = ko<caret>
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// ORDER: kokoFun
|
||||
// ORDER: koza
|
||||
// ORDER: kotlin
|
||||
+6
@@ -119,6 +119,12 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Packages.kt")
|
||||
public void testPackages() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/Packages.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ParametersBeforeKeywords.kt")
|
||||
public void testParametersBeforeKeywords() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/ParametersBeforeKeywords.kt");
|
||||
|
||||
Reference in New Issue
Block a user