mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 15:06:56 +07:00
[kotlin] Find expect declarations in depends on module dependencies
* #FL-26673 GitOrigin-RevId: f4f3656ffcfbc8252ad844c1eda11bacf8f525ac
This commit is contained in:
committed by
intellij-monorepo-bot
parent
18ba51016c
commit
d5e69b141c
@@ -49,7 +49,7 @@ object ExpectActualUtils {
|
||||
null
|
||||
} ?: unwrappedElement
|
||||
|
||||
fun collectTopLevelExpectDeclarations(project: Project, modules: Set<KaModule>): List<KtNamedDeclaration> {
|
||||
fun collectTopLevelExpectDeclarations(project: Project, modules: List<KaModule>): List<KtNamedDeclaration> {
|
||||
val searchScope = GlobalSearchScope.union(modules.map { module -> module.contentScope })
|
||||
|
||||
val indexes = listOf(
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.ui.RowIcon
|
||||
import org.jetbrains.kotlin.analysis.api.projectStructure.KaModule
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.isSuspend
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
@@ -25,7 +24,6 @@ import org.jetbrains.kotlin.idea.search.ExpectActualUtils
|
||||
import org.jetbrains.kotlin.idea.search.ExpectActualUtils.actualsForExpected
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
@@ -63,18 +61,15 @@ internal class ActualDeclarationCompletion(
|
||||
fun complete(position: PsiElement) {
|
||||
val module = position.module ?: return
|
||||
val kaModule = position.moduleInfo.toKaModule()
|
||||
if (kaModule.targetPlatform.isCommon()) {
|
||||
return
|
||||
}
|
||||
val dependsOnModules = kaModule.transitiveDependsOnDependencies
|
||||
if (dependsOnModules.isEmpty()) return
|
||||
|
||||
val packageQualifiedName = position.packageDirective?.qualifiedName ?: return
|
||||
|
||||
val commonModules = kaModule.findCommonDependencyModules()
|
||||
|
||||
// TODO: Allow completion not only for top level actual declarations
|
||||
// `expect`/`actual` interfaces, objects, annotations, enums and typealiases are in Beta
|
||||
// https://youtrack.jetbrains.com/issue/KT-61573
|
||||
val notImplementedExpectDeclarations = ExpectActualUtils.collectTopLevelExpectDeclarations(project, commonModules)
|
||||
val notImplementedExpectDeclarations = ExpectActualUtils.collectTopLevelExpectDeclarations(project, dependsOnModules)
|
||||
.filter { expectDeclaration -> canImplementActualForExpect(expectDeclaration, module, packageQualifiedName) }
|
||||
val actualDeclarationLookupElements = notImplementedExpectDeclarations
|
||||
.mapNotNull { expectDeclaration -> expectDeclaration.createLookupElement(position, module) }
|
||||
@@ -82,12 +77,6 @@ internal class ActualDeclarationCompletion(
|
||||
actualDeclarationLookupElements.forEach { lookupElement -> collector.addElement(lookupElement) }
|
||||
}
|
||||
|
||||
private fun KaModule.findCommonDependencyModules(): Set<KaModule> {
|
||||
return directRegularDependencies
|
||||
.filter { dependencyModule -> dependencyModule.targetPlatform.isCommon() }
|
||||
.toSet()
|
||||
}
|
||||
|
||||
private fun canImplementActualForExpect(
|
||||
expectDeclaration: KtNamedDeclaration,
|
||||
targetModule: Module,
|
||||
|
||||
Reference in New Issue
Block a user