Add modules: mirai-console-intellij and mirai-console-gradle

This commit is contained in:
Him188 2020-09-13 15:27:42 +08:00
parent 18bf3bd563
commit bf5a43b6b4
10 changed files with 375 additions and 0 deletions

View File

@ -0,0 +1,67 @@
@file:Suppress("UnusedImport")
plugins {
kotlin("jvm")
id("java")
`maven-publish`
id("com.jfrog.bintray")
}
version = Versions.console
description = "Gradle plugin for Mirai Console"
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))
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-gradle")

View File

@ -0,0 +1,107 @@
@file:Suppress("UnusedImport")
plugins {
kotlin("jvm")
id("java")
`maven-publish`
id("com.jfrog.bintray")
id("org.jetbrains.intellij") version "0.4.16"
}
repositories {
maven("http://maven.aliyun.com/nexus/content/groups/public/")
}
version = Versions.console
description = "IntelliJ plugin for Mirai Console"
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType(JavaCompile::class.java) {
options.encoding = "UTF8"
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version = "2020.2.1"
isDownloadSources = true
updateSinceUntilBuild = false
setPlugins(
"org.jetbrains.kotlin:1.4.10-release-IJ2020.2.1-1@staging"
)
}
tasks.getByName("publishPlugin", org.jetbrains.intellij.tasks.PublishTask::class) {
val pluginKey = project.findProperty("jetbrains.hub.key")?.toString()
if (pluginKey != null) {
logger.info("Found jetbrains.hub.key")
setToken(pluginKey)
} else {
logger.info("jetbrains.hub.key not found")
}
}
tasks.withType<org.jetbrains.intellij.tasks.PatchPluginXmlTask> {
sinceBuild("193.*")
untilBuild("205.*")
changeNotes("""
Fix cancellation on analyzing augments
""".trimIndent())
}
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")

Binary file not shown.

View File

@ -0,0 +1,94 @@
package net.mamoe.mirai.console.intellij
import com.intellij.codeHighlighting.Pass
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProvider
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.editor.markup.GutterIconRenderer
import com.intellij.openapi.progress.ProgressManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiJavaCodeReferenceCodeFragment
import com.intellij.psi.PsiJavaFile
import com.intellij.psi.PsiReferenceExpression
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
import org.jetbrains.kotlin.idea.core.util.getLineNumber
import org.jetbrains.kotlin.psi.KtForExpression
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
class MiraiConsoleLineMarkerProvider : LineMarkerProvider {
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
return null
}
override fun collectSlowLineMarkers(
elements: MutableList<out PsiElement>,
result: MutableCollection<in LineMarkerInfo<*>>,
) {
val markedLineNumbers = HashSet<Int>()
for (element in elements) {
ProgressManager.checkCanceled()
if (element !is PsiReferenceExpression) continue
val containingFile = element.containingFile
if (containingFile !is PsiJavaFile || containingFile is PsiJavaCodeReferenceCodeFragment) {
continue
}
val lineNumber = element.getLineNumber()
if (lineNumber in markedLineNumbers) continue
if (!element.hasBridgeCalls()) continue
markedLineNumbers += lineNumber
result += if (element is KtForExpression) {
CommandDeclarationLineMarkerInfo(
getElementForLineMark(element.loopRange!!),
// KotlinBundle.message("highlighter.message.suspending.iteration")
)
} else {
CommandDeclarationLineMarkerInfo(
getElementForLineMark(element),
//KotlinBundle.message("highlighter.message.suspend.function.call")
)
}
}
}
@Suppress("DEPRECATION")
class CommandDeclarationLineMarkerInfo(
callElement: PsiElement,
) : LineMarkerInfo<PsiElement>(
callElement,
callElement.textRange,
Icons.CommandDeclaration,
Pass.LINE_MARKERS,
{
"Mirai Console Command"
},
null,
GutterIconRenderer.Alignment.RIGHT
) {
override fun createGutterRenderer(): GutterIconRenderer? {
return object : LineMarkerInfo.LineMarkerGutterIconRenderer<PsiElement>(this) {
override fun getClickAction(): AnAction? = null
}
}
}
}
fun PsiReferenceExpression.hasBridgeCalls(): Boolean {
val resolved = this.resolve() as? KtLightMethod ?: return false
TODO()
}
internal fun getElementForLineMark(callElement: PsiElement): PsiElement =
when (callElement) {
is KtSimpleNameExpression -> callElement.getReferencedNameElement()
else ->
// a fallback,
//but who knows what to reference in KtArrayAccessExpression ?
generateSequence(callElement, { it.firstChild }).last()
}

View File

@ -0,0 +1,16 @@
package net.mamoe.mirai.console.intellij
import org.jetbrains.kotlin.container.StorageComponentContainer
import org.jetbrains.kotlin.container.useInstance
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
class IDEContainerContributor : StorageComponentContainerContributor {
override fun registerModuleComponents(
container: StorageComponentContainer,
platform: org.jetbrains.kotlin.platform.TargetPlatform,
moduleDescriptor: ModuleDescriptor,
) {
container.useInstance(MiraiConsoleDeclarationChecker())
}
}

View File

@ -0,0 +1,17 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.console.intellij
import com.intellij.openapi.util.IconLoader
import javax.swing.Icon
object Icons {
val CommandDeclaration: Icon = IconLoader.getIcon("/icons/commandDeclaration.svg")
}

View File

@ -0,0 +1,25 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.console.intellij
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
class MiraiConsoleDeclarationChecker : DeclarationChecker {
override fun check(
declaration: KtDeclaration,
descriptor: DeclarationDescriptor,
context: DeclarationCheckerContext,
) {
}
}

View File

@ -0,0 +1,28 @@
<idea-plugin>
<id>net.mamoe.mirai-console-dev</id>
<name>Mirai Console Dev</name>
<vendor
email="support@mamoe.net"
url="https://github.com/mamoe/">
Mamoe Technologies
</vendor>
<depends>com.intellij.modules.platform</depends>
<depends>org.jetbrains.kotlin</depends>
<extensions defaultExtensionNs="com.intellij">
<codeInsight.lineMarkerProvider language="JAVA"
implementationClass="net.mamoe.kjbb.ide.BlockingBridgeLineMarkerProvider"/>
</extensions>
<extensions defaultExtensionNs="org.jetbrains.kotlin">
<storageComponentContainerContributor
implementation="net.mamoe.mirai.console.intellij.IDEContainerContributor"/>
<!-- <quickFixContributor implementation="org.jetbrains.kotlinx.serialization.idea.quickfixes.SerializationQuickFixContributor"/> -->
</extensions>
<idea-version since-build="193.*" until-build="203.*"/>
</idea-plugin>

View File

@ -0,0 +1,19 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<path fill="#9AA7B0" fill-opacity=".8" fill-rule="evenodd"
d="
M7.06393077,7.93322956
L4.76000023,10.0664986
L6.03195752,11.2442368
L9.59577548,7.94440533
L9.58370576,7.93322956
L9.59577548,7.92205378
L11.89970602,5.79996049
L10.62774873,4.62222227
L7.06393077,7.93322956
Z M2,3
L14,3
L14,13
L2,13
L2,3 Z"/>
<!-- center 6.329853125 -->
</svg>

After

Width:  |  Height:  |  Size: 491 B

View File

@ -20,6 +20,8 @@ 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-intellij", "intellij-plugin")
includeProject(":mirai-console-gradle", "gradle-plugin")
@Suppress("ConstantConditionIf")
if (!disableOldFrontEnds) {