diff --git a/tools/intellij-plugin/run/projects/test-project/src/main/java/test/TestJavaPlugin.java b/tools/intellij-plugin/run/projects/test-project/src/main/java/test/TestJavaPlugin.java index 468afdad0..2af0e12f8 100644 --- a/tools/intellij-plugin/run/projects/test-project/src/main/java/test/TestJavaPlugin.java +++ b/tools/intellij-plugin/run/projects/test-project/src/main/java/test/TestJavaPlugin.java @@ -1,10 +1,30 @@ package test; +import net.mamoe.mirai.console.command.Command; +import net.mamoe.mirai.console.command.CommandOwner; +import net.mamoe.mirai.console.command.descriptor.CommandSignatureFromKFunction; +import net.mamoe.mirai.console.command.java.JSimpleCommand; +import net.mamoe.mirai.console.permission.Permission; +import net.mamoe.mirai.console.plugin.jvm.JavaPlugin; import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription; import org.jetbrains.annotations.NotNull; -public class TestJavaPlugin extends net.mamoe.mirai.console.plugin.jvm.JavaPlugin { +import java.util.List; + +public class TestJavaPlugin extends JavaPlugin { public TestJavaPlugin(@NotNull JvmPluginDescription description) { super(description); } } + +class TestCommand extends JSimpleCommand { + + public TestCommand(@NotNull CommandOwner owner, @NotNull String primaryName, @NotNull String[] secondaryNames, @NotNull Permission basePermission) { + super(owner, primaryName, secondaryNames, basePermission); + } + + @Handler + public void test(String s) { + + } +} \ No newline at end of file diff --git a/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt b/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt index ee006718c..6d1d2d0e6 100644 --- a/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt +++ b/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt @@ -13,6 +13,7 @@ import com.intellij.codeInsight.daemon.LineMarkerInfo import com.intellij.codeInsight.daemon.LineMarkerProvider import com.intellij.openapi.editor.markup.GutterIconRenderer import com.intellij.psi.PsiElement +import com.intellij.psi.PsiMethod import net.mamoe.mirai.console.intellij.Icons import net.mamoe.mirai.console.intellij.resolve.getElementForLineMark import net.mamoe.mirai.console.intellij.resolve.isSimpleCommandHandlerOrCompositeCommandSubCommand @@ -21,11 +22,24 @@ import org.jetbrains.kotlin.psi.KtNamedFunction class CommandDeclarationLineMarkerProvider : LineMarkerProvider { override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? { - if (element !is KtNamedFunction) return null - if (!element.isSimpleCommandHandlerOrCompositeCommandSubCommand()) return null - runIgnoringErrors { // not showing icons is better than throwing exception every time doing inspection - return Info(getElementForLineMark(element.funKeyword ?: element.identifyingElement ?: element)) + when (element) { + is KtNamedFunction -> { + if (!element.isSimpleCommandHandlerOrCompositeCommandSubCommand()) return null + + runIgnoringErrors { // not showing icons is better than throwing exception every time doing inspection + return Info(getElementForLineMark(element.funKeyword ?: element.identifyingElement ?: element)) + } + } + is PsiMethod -> { + if (!element.isSimpleCommandHandlerOrCompositeCommandSubCommand()) return null + + runIgnoringErrors { // not showing icons is better than throwing exception every time doing inspection + return Info(getElementForLineMark(element.identifyingElement ?: element)) + } + } + else -> return null } + } @Suppress("DEPRECATION") diff --git a/tools/intellij-plugin/src/resolve/resolveIdea.kt b/tools/intellij-plugin/src/resolve/resolveIdea.kt index b796980c2..eeb470978 100644 --- a/tools/intellij-plugin/src/resolve/resolveIdea.kt +++ b/tools/intellij-plugin/src/resolve/resolveIdea.kt @@ -12,6 +12,7 @@ package net.mamoe.mirai.console.intellij.resolve import com.intellij.psi.PsiClass import com.intellij.psi.PsiDeclarationStatement import com.intellij.psi.PsiElement +import com.intellij.psi.PsiModifierListOwner import com.intellij.psi.util.parentsWithSelf import net.mamoe.mirai.console.compiler.common.castOrNull import net.mamoe.mirai.console.compiler.common.resolve.* @@ -43,15 +44,22 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance * For CompositeCommand.SubCommand */ fun KtNamedFunction.isCompositeCommandSubCommand(): Boolean = this.hasAnnotation(COMPOSITE_COMMAND_SUB_COMMAND_FQ_NAME) +fun PsiModifierListOwner.isCompositeCommandSubCommand(): Boolean = this.hasAnnotation(COMPOSITE_COMMAND_SUB_COMMAND_FQ_NAME) + +internal fun PsiModifierListOwner.hasAnnotation(fqName: FqName): Boolean = this.hasAnnotation(fqName.asString()) /** * SimpleCommand.Handler */ fun KtNamedFunction.isSimpleCommandHandler(): Boolean = this.hasAnnotation(SIMPLE_COMMAND_HANDLER_COMMAND_FQ_NAME) +fun PsiModifierListOwner.isSimpleCommandHandler(): Boolean = this.hasAnnotation(SIMPLE_COMMAND_HANDLER_COMMAND_FQ_NAME) fun KtNamedFunction.isSimpleCommandHandlerOrCompositeCommandSubCommand(): Boolean = this.isSimpleCommandHandler() || this.isCompositeCommandSubCommand() +fun PsiModifierListOwner.isSimpleCommandHandlerOrCompositeCommandSubCommand(): Boolean = + this.isSimpleCommandHandler() || this.isCompositeCommandSubCommand() + val KtPureClassOrObject.allSuperTypes: Sequence get() = sequence {