mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Make mirai-console compatible with IDEA 2021.1, fix #323
This commit is contained in:
parent
2d12d8bbce
commit
a40e5731e5
@ -20,8 +20,8 @@ object Versions {
|
|||||||
const val kotlinCompiler = "1.4.21"
|
const val kotlinCompiler = "1.4.21"
|
||||||
const val kotlinStdlib = "1.4.21"
|
const val kotlinStdlib = "1.4.21"
|
||||||
|
|
||||||
const val kotlinIntellijPlugin = "203-1.4.21-release-IJ5981.133" // keep to newest as kotlinCompiler
|
const val kotlinIntellijPlugin = "211-1.4.32-release-IJ6693.72" // keep to newest as kotlinCompiler
|
||||||
const val intellij = "2020.3" // don't update easily unless you want your disk space -= 500MB
|
const val intellij = "2021.1" // don't update easily unless you want your disk space -= 500MB
|
||||||
|
|
||||||
|
|
||||||
const val coroutines = "1.4.0"
|
const val coroutines = "1.4.0"
|
||||||
@ -40,7 +40,7 @@ object Versions {
|
|||||||
@Suppress("SpellCheckingInspection")
|
@Suppress("SpellCheckingInspection")
|
||||||
const val yamlkt = "0.7.5"
|
const val yamlkt = "0.7.5"
|
||||||
|
|
||||||
const val intellijGradlePlugin = "0.4.16"
|
const val intellijGradlePlugin = "0.7.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
const val `kotlin-compiler` = "org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}"
|
const val `kotlin-compiler` = "org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}"
|
||||||
|
@ -15,7 +15,6 @@ import com.intellij.openapi.module.Module
|
|||||||
import com.intellij.openapi.progress.ProgressIndicator
|
import com.intellij.openapi.progress.ProgressIndicator
|
||||||
import com.intellij.openapi.vfs.VfsUtil
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.testFramework.writeChild
|
|
||||||
import net.mamoe.mirai.console.intellij.assets.FT
|
import net.mamoe.mirai.console.intellij.assets.FT
|
||||||
import net.mamoe.mirai.console.intellij.creator.MiraiProjectModel
|
import net.mamoe.mirai.console.intellij.creator.MiraiProjectModel
|
||||||
import net.mamoe.mirai.console.intellij.creator.tasks.getTemplate
|
import net.mamoe.mirai.console.intellij.creator.tasks.getTemplate
|
||||||
@ -24,6 +23,7 @@ import net.mamoe.mirai.console.intellij.creator.tasks.runWriteActionAndWait
|
|||||||
import net.mamoe.mirai.console.intellij.creator.tasks.writeChild
|
import net.mamoe.mirai.console.intellij.creator.tasks.writeChild
|
||||||
import net.mamoe.mirai.console.intellij.creator.templateProperties
|
import net.mamoe.mirai.console.intellij.creator.templateProperties
|
||||||
import org.jetbrains.kotlin.idea.core.util.toPsiFile
|
import org.jetbrains.kotlin.idea.core.util.toPsiFile
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
sealed class ProjectCreator(
|
sealed class ProjectCreator(
|
||||||
val module: Module,
|
val module: Module,
|
||||||
@ -36,11 +36,11 @@ sealed class ProjectCreator(
|
|||||||
model.checkValuesNotNull()
|
model.checkValuesNotNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected val filesChanged = mutableListOf<VirtualFile>()
|
protected val filesChanged = mutableListOf<Path>()
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
protected fun addFileChanged(vf: VirtualFile) {
|
protected fun addFileChanged(path: Path) {
|
||||||
filesChanged.add(vf)
|
filesChanged.add(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getTemplate(name: String) = project.getTemplate(name, model.templateProperties)
|
protected fun getTemplate(name: String) = project.getTemplate(name, model.templateProperties)
|
||||||
@ -49,7 +49,7 @@ sealed class ProjectCreator(
|
|||||||
indicator.text2 = "Reformatting files"
|
indicator.text2 = "Reformatting files"
|
||||||
invokeAndWait {
|
invokeAndWait {
|
||||||
for (file in filesChanged) {
|
for (file in filesChanged) {
|
||||||
val psi = file.toPsiFile(project) ?: continue
|
val psi = file.toFile().toPsiFile(project) ?: continue
|
||||||
ReformatCodeProcessor(psi, false).run()
|
ReformatCodeProcessor(psi, false).run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,13 +69,14 @@ sealed class GradleProjectCreator(
|
|||||||
runWriteActionAndWait {
|
runWriteActionAndWait {
|
||||||
VfsUtil.createDirectoryIfMissing(root, "src/main/${model.languageType.sourceSetDirName}")
|
VfsUtil.createDirectoryIfMissing(root, "src/main/${model.languageType.sourceSetDirName}")
|
||||||
VfsUtil.createDirectoryIfMissing(root, "src/main/resources")
|
VfsUtil.createDirectoryIfMissing(root, "src/main/resources")
|
||||||
filesChanged += root.writeChild(model.languageType.pluginMainClassFile(this))
|
addFileChanged(root.writeChild(model.languageType.pluginMainClassFile(this)))
|
||||||
filesChanged += root.writeChild("src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin", model.mainClassQualifiedName)
|
addFileChanged(root.writeChild("src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin", model.mainClassQualifiedName))
|
||||||
filesChanged += root.writeChild("gradle.properties", getTemplate(FT.GradleProperties))
|
addFileChanged(root.writeChild("gradle.properties", getTemplate(FT.GradleProperties)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class GradleKotlinProjectCreator(
|
class GradleKotlinProjectCreator(
|
||||||
module: Module, root: VirtualFile, model: MiraiProjectModel,
|
module: Module, root: VirtualFile, model: MiraiProjectModel,
|
||||||
) : GradleProjectCreator(
|
) : GradleProjectCreator(
|
||||||
@ -84,8 +85,8 @@ class GradleKotlinProjectCreator(
|
|||||||
override fun createProject(module: Module, root: VirtualFile, model: MiraiProjectModel) {
|
override fun createProject(module: Module, root: VirtualFile, model: MiraiProjectModel) {
|
||||||
super.createProject(module, root, model)
|
super.createProject(module, root, model)
|
||||||
runWriteActionAndWait {
|
runWriteActionAndWait {
|
||||||
filesChanged += root.writeChild("build.gradle.kts", getTemplate(FT.BuildGradleKts))
|
addFileChanged(root.writeChild("build.gradle.kts", getTemplate(FT.BuildGradleKts)))
|
||||||
filesChanged += root.writeChild("settings.gradle.kts", getTemplate(FT.SettingsGradleKts))
|
addFileChanged(root.writeChild("settings.gradle.kts", getTemplate(FT.SettingsGradleKts)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,8 +99,8 @@ class GradleGroovyProjectCreator(
|
|||||||
override fun createProject(module: Module, root: VirtualFile, model: MiraiProjectModel) {
|
override fun createProject(module: Module, root: VirtualFile, model: MiraiProjectModel) {
|
||||||
super.createProject(module, root, model)
|
super.createProject(module, root, model)
|
||||||
runWriteActionAndWait {
|
runWriteActionAndWait {
|
||||||
filesChanged += root.writeChild("build.gradle", getTemplate(FT.BuildGradle))
|
addFileChanged(root.writeChild("build.gradle", getTemplate(FT.BuildGradle)))
|
||||||
filesChanged += root.writeChild("settings.gradle", getTemplate(FT.SettingsGradle))
|
addFileChanged(root.writeChild("settings.gradle", getTemplate(FT.SettingsGradle)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.openapi.vfs.LocalFileSystem
|
import com.intellij.openapi.vfs.LocalFileSystem
|
||||||
import com.intellij.openapi.vfs.VfsUtil
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.testFramework.writeChild
|
import com.intellij.util.io.writeChild
|
||||||
import net.mamoe.mirai.console.intellij.creator.steps.NamedFile
|
import net.mamoe.mirai.console.intellij.creator.steps.NamedFile
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
@ -81,7 +81,13 @@ fun Project.getTemplate(
|
|||||||
): String = getTemplate(templateName, properties.toMap())
|
): String = getTemplate(templateName, properties.toMap())
|
||||||
|
|
||||||
|
|
||||||
fun VirtualFile.writeChild(namedFile: NamedFile): VirtualFile = this.writeChild(namedFile.path, namedFile.content)
|
internal fun VirtualFile.writeChild(pluginMainClassFile: NamedFile): Path {
|
||||||
|
return writeChild(pluginMainClassFile.path, pluginMainClassFile.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun VirtualFile.writeChild(path: String, content: String): Path {
|
||||||
|
return toNioPath().writeChild(path, content)
|
||||||
|
}
|
||||||
|
|
||||||
@Language("RegExp")
|
@Language("RegExp")
|
||||||
const val CLASS_NAME_PATTERN = "[a-zA-Z]+[0-9a-zA-Z_]*" // self written
|
const val CLASS_NAME_PATTERN = "[a-zA-Z]+[0-9a-zA-Z_]*" // self written
|
||||||
|
@ -16,8 +16,8 @@ import com.intellij.openapi.project.rootManager
|
|||||||
import com.intellij.openapi.vfs.VfsUtil
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.testFramework.writeChild
|
|
||||||
import net.mamoe.mirai.console.intellij.creator.tasks.readChildText
|
import net.mamoe.mirai.console.intellij.creator.tasks.readChildText
|
||||||
|
import net.mamoe.mirai.console.intellij.creator.tasks.writeChild
|
||||||
import org.jetbrains.kotlin.idea.core.isAndroidModule
|
import org.jetbrains.kotlin.idea.core.isAndroidModule
|
||||||
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
||||||
|
Loading…
Reference in New Issue
Block a user