FIR IDE: do not add internal packages to completion
This commit is contained in:
committed by
TeamCityServer
parent
48b69b4f3f
commit
365bc5712b
+3
-29
@@ -5,41 +5,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.core
|
||||
|
||||
import com.intellij.codeInsight.JavaProjectCodeInsightSettings
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.isExcludedFromAutoImport
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
|
||||
private val exclusions =
|
||||
listOf(
|
||||
"kotlin.jvm.internal",
|
||||
"kotlin.coroutines.experimental.intrinsics",
|
||||
"kotlin.coroutines.intrinsics",
|
||||
"kotlin.coroutines.experimental.jvm.internal",
|
||||
"kotlin.coroutines.jvm.internal",
|
||||
"kotlin.reflect.jvm.internal"
|
||||
)
|
||||
|
||||
private fun shouldBeHiddenAsInternalImplementationDetail(fqName: String, locationFqName: String) =
|
||||
exclusions.any { fqName.startsWith(it) } && (locationFqName.isBlank() || !fqName.startsWith(locationFqName))
|
||||
|
||||
/**
|
||||
* We do not want to show nothing from "kotlin.coroutines.experimental" when release coroutines are available,
|
||||
* since in 1.3 this package is obsolete.
|
||||
*
|
||||
* However, we still want to show this package when release coroutines are not available.
|
||||
*/
|
||||
private fun usesOutdatedCoroutinesPackage(fqName: String, inFile: KtFile): Boolean =
|
||||
fqName.startsWith("kotlin.coroutines.experimental.") &&
|
||||
inFile.languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)
|
||||
|
||||
fun DeclarationDescriptor.isExcludedFromAutoImport(project: Project, inFile: KtFile?): Boolean {
|
||||
val fqName = importableFqName?.asString() ?: return false
|
||||
return JavaProjectCodeInsightSettings.getSettings(project).isExcluded(fqName) ||
|
||||
(inFile != null && usesOutdatedCoroutinesPackage(fqName, inFile)) ||
|
||||
shouldBeHiddenAsInternalImplementationDetail(fqName, inFile?.packageFqName?.asString() ?: "")
|
||||
val fqName = importableFqName ?: return false
|
||||
return fqName.isExcludedFromAutoImport(project, inFile, inFile?.languageVersionSettings)
|
||||
}
|
||||
|
||||
+5
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.idea.completion.context.FirNameReferenceRawPositionC
|
||||
import org.jetbrains.kotlin.idea.completion.context.FirRawPositionCompletionContext
|
||||
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.idea.isExcludedFromAutoImport
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -30,6 +32,9 @@ internal class FirPackageCompletionContributor(
|
||||
} ?: return
|
||||
rootSymbol.getPackageScope()
|
||||
.getPackageSymbols(scopeNameFilter)
|
||||
.filterNot { packageName ->
|
||||
packageName.fqName.isExcludedFromAutoImport(project, originalKtFile, originalKtFile.languageVersionSettings)
|
||||
}
|
||||
.forEach { packageSymbol ->
|
||||
result.addElement(lookupElementFactory.createPackageLookupElement(packageSymbol.fqName))
|
||||
}
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea
|
||||
|
||||
import com.intellij.codeInsight.JavaProjectCodeInsightSettings
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
|
||||
private val exclusions =
|
||||
listOf(
|
||||
"kotlin.jvm.internal",
|
||||
"kotlin.coroutines.experimental.intrinsics",
|
||||
"kotlin.coroutines.intrinsics",
|
||||
"kotlin.coroutines.experimental.jvm.internal",
|
||||
"kotlin.coroutines.jvm.internal",
|
||||
"kotlin.reflect.jvm.internal"
|
||||
)
|
||||
|
||||
private fun shouldBeHiddenAsInternalImplementationDetail(fqName: String, locationFqName: String) =
|
||||
exclusions.any { fqName.startsWith(it) } && (locationFqName.isBlank() || !fqName.startsWith(locationFqName))
|
||||
|
||||
/**
|
||||
* We do not want to show nothing from "kotlin.coroutines.experimental" when release coroutines are available,
|
||||
* since in 1.3 this package is obsolete.
|
||||
*
|
||||
* However, we still want to show this package when release coroutines are not available.
|
||||
*/
|
||||
private fun usesOutdatedCoroutinesPackage(fqName: String, languageVersionSettings: LanguageVersionSettings): Boolean =
|
||||
fqName.startsWith("kotlin.coroutines.experimental.") &&
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)
|
||||
|
||||
fun FqName.isExcludedFromAutoImport(project: Project, inFile: KtFile?, languageVersionSettings: LanguageVersionSettings?): Boolean {
|
||||
val fqName = this.asString()
|
||||
return JavaProjectCodeInsightSettings.getSettings(project).isExcluded(fqName) ||
|
||||
(languageVersionSettings != null && usesOutdatedCoroutinesPackage(fqName, languageVersionSettings)) ||
|
||||
shouldBeHiddenAsInternalImplementationDetail(fqName, inFile?.packageFqName?.asString() ?: "")
|
||||
}
|
||||
Reference in New Issue
Block a user