Top-level callables are added one by one
This commit is contained in:
@@ -79,23 +79,27 @@ public class ShadowedDeclarationsFilter(
|
|||||||
.flatMap { group -> filterEqualSignatureGroup(group) }
|
.flatMap { group -> filterEqualSignatureGroup(group) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun <TDescriptor : DeclarationDescriptor> filterNonImported(
|
public fun <TDescriptor : DeclarationDescriptor> createNonImportedDeclarationsFilter(
|
||||||
declarations: Collection<TDescriptor>,
|
|
||||||
importedDeclarations: Collection<DeclarationDescriptor>
|
importedDeclarations: Collection<DeclarationDescriptor>
|
||||||
): Collection<TDescriptor> {
|
): (Collection<TDescriptor>) -> Collection<TDescriptor> {
|
||||||
val importedDeclarationsSet = importedDeclarations.toSet()
|
val importedDeclarationsSet = importedDeclarations.toSet()
|
||||||
val nonImportedDeclarations = declarations.filter { it !in importedDeclarationsSet }
|
|
||||||
|
|
||||||
val importedDeclarationsBySignature = importedDeclarationsSet.groupBy { signature(it) }
|
val importedDeclarationsBySignature = importedDeclarationsSet.groupBy { signature(it) }
|
||||||
|
|
||||||
val notShadowed = HashSet<DeclarationDescriptor>()
|
return filter@ { declarations ->
|
||||||
// same signature non-imported declarations from different packages do not shadow each other
|
// optimization
|
||||||
for ((pair, group) in nonImportedDeclarations.groupBy { signature(it) to packageName(it) }) {
|
if (declarations.size == 1 && importedDeclarationsBySignature[signature(declarations.single())] == null) return@filter declarations
|
||||||
val imported = importedDeclarationsBySignature[pair.first]
|
|
||||||
val all = if (imported != null) group + imported else group
|
val nonImportedDeclarations = declarations.filter { it !in importedDeclarationsSet }
|
||||||
notShadowed.addAll(filterEqualSignatureGroup(all, descriptorsToImport = group))
|
|
||||||
|
val notShadowed = HashSet<DeclarationDescriptor>()
|
||||||
|
// same signature non-imported declarations from different packages do not shadow each other
|
||||||
|
for ((pair, group) in nonImportedDeclarations.groupBy { signature(it) to packageName(it) }) {
|
||||||
|
val imported = importedDeclarationsBySignature[pair.first]
|
||||||
|
val all = if (imported != null) group + imported else group
|
||||||
|
notShadowed.addAll(filterEqualSignatureGroup(all, descriptorsToImport = group))
|
||||||
|
}
|
||||||
|
declarations.filter { it in notShadowed }
|
||||||
}
|
}
|
||||||
return declarations.filter { it in notShadowed }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun signature(descriptor: DeclarationDescriptor): Any {
|
private fun signature(descriptor: DeclarationDescriptor): Any {
|
||||||
|
|||||||
+4
-1
@@ -242,7 +242,10 @@ class BasicCompletionSession(
|
|||||||
|
|
||||||
private fun completeNonImported(lookupElementFactory: LookupElementFactory) {
|
private fun completeNonImported(lookupElementFactory: LookupElementFactory) {
|
||||||
if (shouldCompleteTopLevelCallablesFromIndex()) {
|
if (shouldCompleteTopLevelCallablesFromIndex()) {
|
||||||
collector.addDescriptorElements(getTopLevelCallables(), lookupElementFactory, notImported = true)
|
processTopLevelCallables {
|
||||||
|
collector.addDescriptorElements(it, lookupElementFactory, notImported = true)
|
||||||
|
flushToResultSet()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val classKindFilter: ((ClassKind) -> Boolean)?
|
val classKindFilter: ((ClassKind) -> Boolean)?
|
||||||
|
|||||||
+14
-10
@@ -337,7 +337,9 @@ abstract class CompletionSession(
|
|||||||
|
|
||||||
if (shadowedDeclarationsFilter != null) {
|
if (shadowedDeclarationsFilter != null) {
|
||||||
variants = shadowedDeclarationsFilter.filter(variants)
|
variants = shadowedDeclarationsFilter.filter(variants)
|
||||||
notImportedExtensions = shadowedDeclarationsFilter.filterNonImported(notImportedExtensions, variants)
|
notImportedExtensions = shadowedDeclarationsFilter
|
||||||
|
.createNonImportedDeclarationsFilter<CallableDescriptor>(importedDeclarations = variants)
|
||||||
|
.invoke(notImportedExtensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configuration.filterOutJavaGettersAndSetters) {
|
if (configuration.filterOutJavaGettersAndSetters) {
|
||||||
@@ -394,10 +396,17 @@ abstract class CompletionSession(
|
|||||||
return callTypeAndReceiver.receiver == null
|
return callTypeAndReceiver.receiver == null
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getTopLevelCallables(): Collection<CallableDescriptor> {
|
protected fun processTopLevelCallables(processor: (CallableDescriptor) -> Unit) {
|
||||||
val result = LinkedHashSet<CallableDescriptor>()
|
val shadowedFilter = ShadowedDeclarationsFilter.create(bindingContext, resolutionFacade, nameExpression!!, callTypeAndReceiver)
|
||||||
indicesHelper(true).processTopLevelCallables({ prefixMatcher.prefixMatches(it) }) { result.add(it) }
|
?.createNonImportedDeclarationsFilter<CallableDescriptor>(referenceVariants!!.imported)
|
||||||
return result.filterShadowedNonImported()
|
indicesHelper(true).processTopLevelCallables({ prefixMatcher.prefixMatches(it) }) {
|
||||||
|
if (shadowedFilter != null) {
|
||||||
|
shadowedFilter(listOf(it)).singleOrNull()?.let(processor)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
processor(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun CallTypeAndReceiver<*, *>.shouldCompleteCallableExtensions(): Boolean {
|
protected fun CallTypeAndReceiver<*, *>.shouldCompleteCallableExtensions(): Boolean {
|
||||||
@@ -405,11 +414,6 @@ abstract class CompletionSession(
|
|||||||
&& this !is CallTypeAndReceiver.IMPORT_DIRECTIVE
|
&& this !is CallTypeAndReceiver.IMPORT_DIRECTIVE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Collection<CallableDescriptor>.filterShadowedNonImported(): Collection<CallableDescriptor> {
|
|
||||||
val filter = ShadowedDeclarationsFilter.create(bindingContext, resolutionFacade, nameExpression!!, callTypeAndReceiver)
|
|
||||||
return if (filter != null) filter.filterNonImported(this, referenceVariants!!.imported) else this
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun addClassesFromIndex(kindFilter: (ClassKind) -> Boolean) {
|
protected fun addClassesFromIndex(kindFilter: (ClassKind) -> Boolean) {
|
||||||
AllClassesCompletion(parameters, indicesHelper(true), prefixMatcher, resolutionFacade, kindFilter)
|
AllClassesCompletion(parameters, indicesHelper(true), prefixMatcher, resolutionFacade, kindFilter)
|
||||||
.collect(
|
.collect(
|
||||||
|
|||||||
+4
-2
@@ -120,8 +120,10 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldCompleteTopLevelCallablesFromIndex()) {
|
if (shouldCompleteTopLevelCallablesFromIndex()) {
|
||||||
getTopLevelCallables().forEach { collector.addElements(filter(it, lookupElementFactory), notImported = true) }
|
processTopLevelCallables {
|
||||||
flushToResultSet()
|
collector.addElements(filter(it, lookupElementFactory), notImported = true)
|
||||||
|
flushToResultSet()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position.getContainingFile() is KtCodeFragment) {
|
if (position.getContainingFile() is KtCodeFragment) {
|
||||||
|
|||||||
Reference in New Issue
Block a user