diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifyCallChainFix.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifyCallChainFix.kt index 68360dc8ca7..1d59afb5d46 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifyCallChainFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifyCallChainFix.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.idea.inspections.collections +import com.intellij.codeInsight.actions.OptimizeImportsProcessor import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor import com.intellij.openapi.project.Project @@ -27,6 +28,7 @@ import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange class SimplifyCallChainFix( private val conversion: AbstractCallChainChecker.Conversion, private val removeReceiverOfFirstCall: Boolean = false, + private val runOptimizeImports: Boolean = false, private val modifyArguments: KtPsiFactory.(KtCallExpression) -> Unit = {} ) : LocalQuickFix { private val shortenedText = conversion.replacement.substringAfterLast(".") @@ -96,8 +98,13 @@ class SimplifyCallChainFix( argumentsText ) + val project = qualifiedExpression.project + val file = qualifiedExpression.containingKtFile val result = qualifiedExpression.replaced(newQualifiedExpression) ShortenReferences.DEFAULT.process(result) + if (runOptimizeImports) { + OptimizeImportsProcessor(project, file).run() + } } override fun applyFix(project: Project, descriptor: ProblemDescriptor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/coroutines/RedundantAsyncInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/coroutines/RedundantAsyncInspection.kt index a28e024b086..a68230e6bd4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/coroutines/RedundantAsyncInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/coroutines/RedundantAsyncInspection.kt @@ -73,7 +73,7 @@ class RedundantAsyncInspection : AbstractCallChainChecker() { "Redundant 'async' call may be reduced to '${conversion.replacement}'", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly, - SimplifyCallChainFix(conversion, removeReceiverOfFirstCall = true) { callExpression -> + SimplifyCallChainFix(conversion, removeReceiverOfFirstCall = true, runOptimizeImports = true) { callExpression -> if (contextArgument != null) { val call = callExpression.resolveToCall() if (call != null) { diff --git a/idea/testData/inspectionsLocal/coroutines/redundantAsync/globalScopeNoContextNoPackage.kt.after b/idea/testData/inspectionsLocal/coroutines/redundantAsync/globalScopeNoContextNoPackage.kt.after index 9a19a7afd78..4bc5feacf83 100644 --- a/idea/testData/inspectionsLocal/coroutines/redundantAsync/globalScopeNoContextNoPackage.kt.after +++ b/idea/testData/inspectionsLocal/coroutines/redundantAsync/globalScopeNoContextNoPackage.kt.after @@ -1,8 +1,6 @@ // WITH_RUNTIME import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.async import kotlinx.coroutines.withContext suspend fun test() {