From 18a0a95609760ae1086f0247603e67640e42574e Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 13 Nov 2020 18:24:33 +0800 Subject: [PATCH] Fix PluginMainServiceNotConfiguredInspection --- .../PluginMainServiceNotConfiguredInspection.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/intellij-plugin/src/diagnostics/PluginMainServiceNotConfiguredInspection.kt b/tools/intellij-plugin/src/diagnostics/PluginMainServiceNotConfiguredInspection.kt index 5f4568fd8..4d9fd7e9d 100644 --- a/tools/intellij-plugin/src/diagnostics/PluginMainServiceNotConfiguredInspection.kt +++ b/tools/intellij-plugin/src/diagnostics/PluginMainServiceNotConfiguredInspection.kt @@ -11,6 +11,7 @@ package net.mamoe.mirai.console.intellij.diagnostics import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder +import com.intellij.openapi.progress.impl.CancellationCheck.Companion.runWithCancellationCheck import com.intellij.psi.PsiElementVisitor import net.mamoe.mirai.console.compiler.common.resolve.AUTO_SERVICE import net.mamoe.mirai.console.intellij.diagnostics.fix.ConfigurePluginMainServiceFix @@ -64,14 +65,16 @@ class PluginMainServiceNotConfiguredInspection : AbstractKotlinInspection() { ktClass: KtClassOrObject, fqName: String, ): Boolean { - val sourceRoots = ktClass.module?.rootManager?.sourceRoots ?: return false - val services = sourceRoots.asSequence().flatMap { file -> - SERVICE_FILE_NAMES.asSequence().mapNotNull { serviceFileName -> - file.findFileByRelativePath("META-INF/services/$serviceFileName") + return runWithCancellationCheck { + val sourceRoots = ktClass.module?.rootManager?.sourceRoots ?: return@runWithCancellationCheck false + val services = sourceRoots.asSequence().flatMap { file -> + SERVICE_FILE_NAMES.asSequence().mapNotNull { serviceFileName -> + file.findFileByRelativePath("META-INF/services/$serviceFileName") + } + } + return@runWithCancellationCheck services.any { serviceFile -> + serviceFile.readAction { f -> f.inputStream.bufferedReader().use { it.readLine() }.trim() == fqName } } - } - return services.any { serviceFile -> - serviceFile.readAction { f -> f.inputStream.bufferedReader().use { it.readLine() }.trim() == fqName } } } } \ No newline at end of file