diff --git a/settings.gradle.kts b/settings.gradle.kts index aaf891a63..27b9b3fc2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,6 +20,7 @@ fun includeProject(projectPath: String, path: String? = null) { includeProject(":mirai-console", "backend/mirai-console") includeProject(":mirai-console.codegen", "backend/codegen") includeProject(":mirai-console-pure", "frontend/mirai-console-pure") +includeProject(":mirai-console-compiler-common", "tools/compiler-common") includeProject(":mirai-console-intellij", "tools/intellij-plugin") includeProject(":mirai-console-gradle", "tools/gradle-plugin") diff --git a/tools/compiler-common/README.md b/tools/compiler-common/README.md new file mode 100644 index 000000000..a3e4973fb --- /dev/null +++ b/tools/compiler-common/README.md @@ -0,0 +1,5 @@ +# mirai-console-compiler-common + +Mirai Console 编译器后端通用模块. + +## \ No newline at end of file diff --git a/tools/compiler-common/build.gradle.kts b/tools/compiler-common/build.gradle.kts new file mode 100644 index 000000000..fb6a5e172 --- /dev/null +++ b/tools/compiler-common/build.gradle.kts @@ -0,0 +1,75 @@ +@file:Suppress("UnusedImport") + +plugins { + kotlin("jvm") + id("java") + `maven-publish` + id("com.jfrog.bintray") +} + +repositories { + maven("http://maven.aliyun.com/nexus/content/groups/public/") +} + +version = Versions.console +description = "Mirai Console compiler common" + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +tasks.withType(JavaCompile::class.java) { + options.encoding = "UTF8" +} + +kotlin { + sourceSets.all { + target.compilations.all { + kotlinOptions { + jvmTarget = "1.8" + freeCompilerArgs = freeCompilerArgs + "-Xjvm-default=all" + //useIR = true + } + } + languageSettings.apply { + progressiveMode = true + + useExperimentalAnnotation("kotlin.Experimental") + useExperimentalAnnotation("kotlin.RequiresOptIn") + + useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiInternalAPI") + useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiExperimentalAPI") + useExperimentalAnnotation("net.mamoe.mirai.console.ConsoleFrontEndImplementation") + useExperimentalAnnotation("net.mamoe.mirai.console.util.ConsoleExperimentalApi") + useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") + useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference") + useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") + useExperimentalAnnotation("kotlinx.serialization.ExperimentalSerializationApi") + useExperimentalAnnotation("net.mamoe.mirai.console.util.ConsoleInternalApi") + } + } +} + +dependencies { + api("org.jetbrains:annotations:19.0.0") + api(kotlinx("coroutines-jdk8", Versions.coroutines)) + + compileOnly("org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}") + compileOnly("org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}") + compileOnly(files("libs/ide-common.jar")) + + testApi(kotlin("test")) + testApi(kotlin("test-junit5")) + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.2.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0") +} + +tasks { + "test"(Test::class) { + useJUnitPlatform() + } +} + +// setupPublishing("mirai-console-intellij") \ No newline at end of file diff --git a/tools/compiler-common/src/main/java/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrors.java b/tools/compiler-common/src/main/java/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrors.java new file mode 100644 index 000000000..2b65a3bd8 --- /dev/null +++ b/tools/compiler-common/src/main/java/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrors.java @@ -0,0 +1,31 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.compiler.common.diagnostics; + +import com.intellij.psi.PsiElement; +import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1; +import org.jetbrains.kotlin.diagnostics.Errors; + +import static org.jetbrains.kotlin.diagnostics.Severity.ERROR; + +public interface MiraiConsoleErrors { + DiagnosticFactory1 ILLEGAL_PLUGIN_ID = DiagnosticFactory1.create(ERROR); + DiagnosticFactory1 ILLEGAL_PLUGIN_NAME = DiagnosticFactory1.create(ERROR); + + @Deprecated + Object _init = new Object() { + { + Errors.Initializer.initializeFactoryNamesAndDefaultErrorMessages( + MiraiConsoleErrors.class, + MiraiConsoleErrorsRendering.INSTANCE + ); + } + }; +} diff --git a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrorsRendering.kt b/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrorsRendering.kt new file mode 100644 index 000000000..8eb25bc37 --- /dev/null +++ b/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrorsRendering.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.compiler.common.diagnostics + +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PLUGIN_ID +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PLUGIN_NAME +import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages +import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap +import org.jetbrains.kotlin.diagnostics.rendering.Renderers + +object MiraiConsoleErrorsRendering : DefaultErrorMessages.Extension { + private val MAP = DiagnosticFactoryToRendererMap("MiraiConsole").apply { + put( + ILLEGAL_PLUGIN_ID, + "Illegal plugin id: '{0}'", + Renderers.STRING + ) + put( + ILLEGAL_PLUGIN_NAME, + "Illegal plugin name: '{0}'", + Renderers.STRING + ) + } + + override fun getMap() = MAP +} diff --git a/tools/gradle-plugin/README.md b/tools/gradle-plugin/README.md new file mode 100644 index 000000000..78e0e7f29 --- /dev/null +++ b/tools/gradle-plugin/README.md @@ -0,0 +1,2 @@ +# mirai-console-gradle + diff --git a/tools/intellij-plugin/README.md b/tools/intellij-plugin/README.md new file mode 100644 index 000000000..da5b520e0 --- /dev/null +++ b/tools/intellij-plugin/README.md @@ -0,0 +1,7 @@ +# mirai-console-intellij + +IntelliJ 平台的 Mirai Console 开发插件 + +## 功能 + +### 诊断 \ No newline at end of file diff --git a/tools/intellij-plugin/build.gradle.kts b/tools/intellij-plugin/build.gradle.kts index ace7adb38..3520633be 100644 --- a/tools/intellij-plugin/build.gradle.kts +++ b/tools/intellij-plugin/build.gradle.kts @@ -87,6 +87,8 @@ dependencies { api("org.jetbrains:annotations:19.0.0") api(kotlinx("coroutines-jdk8", Versions.coroutines)) + api(project(":mirai-console-compiler-common")) + compileOnly("org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}") compileOnly("org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}") compileOnly(files("libs/ide-common.jar"))