Fixed completion of explicitly imported non-top level packages broken by optimization before
This commit is contained in:
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
@@ -47,6 +48,7 @@ public class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, pr
|
|||||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
if (!kindFilter.acceptsKinds(DescriptorKindFilter.PACKAGES_MASK)) return listOf()
|
if (!kindFilter.acceptsKinds(DescriptorKindFilter.PACKAGES_MASK)) return listOf()
|
||||||
|
if (fqName.isRoot() && kindFilter.excludes.contains(DescriptorKindExclude.TopLevelPackages)) return listOf()
|
||||||
|
|
||||||
val subFqNames = moduleDescriptor.getSubPackagesOf(fqName, nameFilter)
|
val subFqNames = moduleDescriptor.getSubPackagesOf(fqName, nameFilter)
|
||||||
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
||||||
|
|||||||
@@ -229,4 +229,17 @@ public trait DescriptorKindExclude {
|
|||||||
|
|
||||||
override val fullyExcludedDescriptorKinds: Int get() = 0
|
override val fullyExcludedDescriptorKinds: Int get() = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object TopLevelPackages : DescriptorKindExclude {
|
||||||
|
override fun excludes(descriptor: DeclarationDescriptor): Boolean {
|
||||||
|
val fqName = when (descriptor) {
|
||||||
|
is PackageFragmentDescriptor -> descriptor.fqName
|
||||||
|
is PackageViewDescriptor -> descriptor.fqName
|
||||||
|
else -> return false
|
||||||
|
}
|
||||||
|
return fqName.parent().isRoot()
|
||||||
|
}
|
||||||
|
|
||||||
|
override val fullyExcludedDescriptorKinds: Int get() = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-5
@@ -75,10 +75,13 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
|
|
||||||
private val completionKind = calcCompletionKind()
|
private val completionKind = calcCompletionKind()
|
||||||
|
|
||||||
override val descriptorKindFilter = if (isNoQualifierContext())
|
override val descriptorKindFilter = if (isNoQualifierContext()) {
|
||||||
completionKind.descriptorKindFilter?.withoutKinds(DescriptorKindFilter.PACKAGES_MASK)
|
// it's an optimization because obtaining top-level packages from scope is very slow, we obtains them in other way
|
||||||
else
|
completionKind.descriptorKindFilter?.exclude(DescriptorKindExclude.TopLevelPackages)
|
||||||
|
}
|
||||||
|
else {
|
||||||
completionKind.descriptorKindFilter
|
completionKind.descriptorKindFilter
|
||||||
|
}
|
||||||
|
|
||||||
private val parameterNameAndTypeCompletion = if (shouldCompleteParameterNameAndType())
|
private val parameterNameAndTypeCompletion = if (shouldCompleteParameterNameAndType())
|
||||||
ParameterNameAndTypeCompletion(collector, lookupElementFactory, prefixMatcher, resolutionFacade)
|
ParameterNameAndTypeCompletion(collector, lookupElementFactory, prefixMatcher, resolutionFacade)
|
||||||
@@ -202,8 +205,8 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getting root packages from scope is very slow so we do this in alternative way
|
// getting root packages from scope is very slow so we do this in alternative way
|
||||||
if (isNoQualifierContext() && (completionKind.descriptorKindFilter?.kindMask ?: 0).and(DescriptorKindFilter.PACKAGES_MASK) != 0) {
|
if (isNoQualifierContext() && (descriptorKindFilter?.kindMask ?: 0).and(DescriptorKindFilter.PACKAGES_MASK) != 0) {
|
||||||
//TODO: move this code somewhere else
|
//TODO: move this code somewhere else?
|
||||||
val packageNames = PackageIndexUtil.getSubPackageFqNames(FqName.ROOT, originalSearchScope, project, prefixMatcher.asNameFilter())
|
val packageNames = PackageIndexUtil.getSubPackageFqNames(FqName.ROOT, originalSearchScope, project, prefixMatcher.asNameFilter())
|
||||||
.toMutableSet()
|
.toMutableSet()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import java.util
|
||||||
|
|
||||||
|
class A {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: { lookupString: "kotlin", itemText: "kotlin", tailText: null, typeText: null }
|
||||||
|
// EXIST_JAVA_ONLY: { lookupString: "util", itemText: "util", tailText: " (java.util)", typeText: null }
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
class A {
|
|
||||||
kot<caret>
|
|
||||||
}
|
|
||||||
|
|
||||||
// EXIST: "kotlin"
|
|
||||||
+6
-6
@@ -733,6 +733,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PackageCompletionInClassBody.kt")
|
||||||
|
public void testPackageCompletionInClassBody() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PackageCompletionInClassBody.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("PrivatesInSecondPressCompletion.kt")
|
@TestMetadata("PrivatesInSecondPressCompletion.kt")
|
||||||
public void testPrivatesInSecondPressCompletion() throws Exception {
|
public void testPrivatesInSecondPressCompletion() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
|
||||||
@@ -865,12 +871,6 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("TopLevelPackageInClassBody.kt")
|
|
||||||
public void testTopLevelPackageInClassBody() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/TopLevelPackageInClassBody.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("TypeParameterFromOuterClass.kt")
|
@TestMetadata("TypeParameterFromOuterClass.kt")
|
||||||
public void testTypeParameterFromOuterClass() throws Exception {
|
public void testTypeParameterFromOuterClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/TypeParameterFromOuterClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/TypeParameterFromOuterClass.kt");
|
||||||
|
|||||||
+6
-6
@@ -733,6 +733,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PackageCompletionInClassBody.kt")
|
||||||
|
public void testPackageCompletionInClassBody() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PackageCompletionInClassBody.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("PrivatesInSecondPressCompletion.kt")
|
@TestMetadata("PrivatesInSecondPressCompletion.kt")
|
||||||
public void testPrivatesInSecondPressCompletion() throws Exception {
|
public void testPrivatesInSecondPressCompletion() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/PrivatesInSecondPressCompletion.kt");
|
||||||
@@ -865,12 +871,6 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("TopLevelPackageInClassBody.kt")
|
|
||||||
public void testTopLevelPackageInClassBody() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/TopLevelPackageInClassBody.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("TypeParameterFromOuterClass.kt")
|
@TestMetadata("TypeParameterFromOuterClass.kt")
|
||||||
public void testTypeParameterFromOuterClass() throws Exception {
|
public void testTypeParameterFromOuterClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/TypeParameterFromOuterClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/TypeParameterFromOuterClass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user