mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
ConfigurePluginMainServiceFix and PluginMainServiceNotConfiguredInspection: support multiline service files
This commit is contained in:
parent
75d9805db1
commit
0a0caeeb3a
@ -107,7 +107,9 @@ class PluginMainServiceNotConfiguredInspection : AbstractKotlinInspection() {
|
||||
}
|
||||
}
|
||||
return@runWithCancellationCheck services.any { serviceFile ->
|
||||
serviceFile.readAction { f -> f.inputStream.bufferedReader().use { it.readLine() }.trim() == fqName }
|
||||
serviceFile.readAction { f ->
|
||||
f.inputStream.bufferedReader().use { reader -> reader.lineSequence().any { it == fqName } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,11 @@ import com.intellij.codeInspection.LocalQuickFix
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.rootManager
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.testFramework.writeChild
|
||||
import net.mamoe.mirai.console.intellij.creator.tasks.readChildText
|
||||
import org.jetbrains.kotlin.idea.core.isAndroidModule
|
||||
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
||||
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
||||
@ -49,7 +51,19 @@ class ConfigurePluginMainServiceFix(
|
||||
}
|
||||
|
||||
project.executeWriteCommand(name) {
|
||||
sourceRoot.writeChild("META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin", elementFqName.toByteArray())
|
||||
val filepath = "META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin"
|
||||
|
||||
fun computeContent(): String {
|
||||
val origin = sourceRoot.readChildText(filepath) ?: ""
|
||||
return when {
|
||||
origin.isBlank() -> elementFqName
|
||||
origin.endsWith("\n") -> origin + elementFqName
|
||||
else -> "$origin\n$elementFqName"
|
||||
}
|
||||
}
|
||||
|
||||
sourceRoot.writeChild(filepath, computeContent())
|
||||
VfsUtil.markDirtyAndRefresh(true, false, false, sourceRoot.findChild(filepath))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user