Redundant async inspection: run "optimize imports" after quick-fix
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections.collections
|
package org.jetbrains.kotlin.idea.inspections.collections
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.actions.OptimizeImportsProcessor
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
@@ -27,6 +28,7 @@ import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange
|
|||||||
class SimplifyCallChainFix(
|
class SimplifyCallChainFix(
|
||||||
private val conversion: AbstractCallChainChecker.Conversion,
|
private val conversion: AbstractCallChainChecker.Conversion,
|
||||||
private val removeReceiverOfFirstCall: Boolean = false,
|
private val removeReceiverOfFirstCall: Boolean = false,
|
||||||
|
private val runOptimizeImports: Boolean = false,
|
||||||
private val modifyArguments: KtPsiFactory.(KtCallExpression) -> Unit = {}
|
private val modifyArguments: KtPsiFactory.(KtCallExpression) -> Unit = {}
|
||||||
) : LocalQuickFix {
|
) : LocalQuickFix {
|
||||||
private val shortenedText = conversion.replacement.substringAfterLast(".")
|
private val shortenedText = conversion.replacement.substringAfterLast(".")
|
||||||
@@ -96,8 +98,13 @@ class SimplifyCallChainFix(
|
|||||||
argumentsText
|
argumentsText
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val project = qualifiedExpression.project
|
||||||
|
val file = qualifiedExpression.containingKtFile
|
||||||
val result = qualifiedExpression.replaced(newQualifiedExpression)
|
val result = qualifiedExpression.replaced(newQualifiedExpression)
|
||||||
ShortenReferences.DEFAULT.process(result)
|
ShortenReferences.DEFAULT.process(result)
|
||||||
|
if (runOptimizeImports) {
|
||||||
|
OptimizeImportsProcessor(project, file).run()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ class RedundantAsyncInspection : AbstractCallChainChecker() {
|
|||||||
"Redundant 'async' call may be reduced to '${conversion.replacement}'",
|
"Redundant 'async' call may be reduced to '${conversion.replacement}'",
|
||||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||||
isOnTheFly,
|
isOnTheFly,
|
||||||
SimplifyCallChainFix(conversion, removeReceiverOfFirstCall = true) { callExpression ->
|
SimplifyCallChainFix(conversion, removeReceiverOfFirstCall = true, runOptimizeImports = true) { callExpression ->
|
||||||
if (contextArgument != null) {
|
if (contextArgument != null) {
|
||||||
val call = callExpression.resolveToCall()
|
val call = callExpression.resolveToCall()
|
||||||
if (call != null) {
|
if (call != null) {
|
||||||
|
|||||||
Vendored
-2
@@ -1,8 +1,6 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
suspend fun test() {
|
suspend fun test() {
|
||||||
|
|||||||
Reference in New Issue
Block a user