kotlinintellij-plugin

Extension dose not implement interface GotoDeclarationHandler


I am trying to develop an idea plugin using the intellij-platform-plugin-template

I want to implement the navigation from JavaScript function parameters to Java method definitions

When I tried to run the plug-in after coding, I got an error

com.intellij.diagnostic.PluginException: 
Extension com.github.xuzheng0912.liems.handler.LuiAjaxArgumentGotoJavaMethodHandler does not implement interface com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler 
(adapter=SimpleConstructorInjectionAdapter(implementation=com.github.xuzheng0912.liems.handler.LuiAjaxArgumentGotoJavaMethodHandler, plugin=PluginDescriptor(name=LiEMS, id=com.github.xuzheng0912.liems, descriptorPath=plugin.xml, path=D:\dev\repository\LiEMS\build\idea-sandbox\IC-2024.2.4\plugins\LiEMS, version=0.0.1, package=null, isBundled=false)))

language: kotlin
JDK: 17

I need use PSI, so I add the JavaScript and Java PSI dependency

libs.version.toml addition

[versions]
# PSI
javaPsi = "242.23726.103"
javaScriptPsi = "241.19416.19"

[libraries]
javaScriptPsi = { group = "com.jetbrains.intellij.javascript", name = "javascript", version.ref = "javaScriptPsi" }
javaScriptPsiImpl = { group = "com.jetbrains.intellij.javascript", name = "javascript-psi-impl", version.ref = "javaScriptPsi" }
javaPsi = { group = "com.jetbrains.intellij.java", name = "java-psi", version.ref = "javaPsi" }
javaPsiImpl = { group = "com.jetbrains.intellij.java", name = "java-psi-impl", version.ref = "javaPsi" }

build.gradle.kts dependencies block addition

implementation(libs.javaPsi)
implementation(libs.javaPsiImpl)
implementation(libs.javaScriptPsi)
implementation(libs.javaScriptPsiImpl)

then I implement the interface GotoDeclarationHandler

package com.github.xuzheng0912.liems.handler

import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler
import com.intellij.lang.javascript.psi.JSCallExpression
import com.intellij.lang.javascript.psi.JSFile
import com.intellij.lang.javascript.psi.JSReferenceExpression
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiElement
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.annotations.Nls
import java.io.File

class LuiAjaxArgumentGotoJavaMethodHandler : GotoDeclarationHandler {
    override fun getGotoDeclarationTargets(
        sourceElement: PsiElement?,
        offset: Int,
        editor: Editor?
    ): Array<out PsiElement?>? { 
        //code
    }
}

also register the extension in plugin.xml

<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
    <id>com.github.xuzheng0912.liems</id>
    <name>LiEMS</name>
    <vendor>xuzheng0912</vendor>

    <depends>com.intellij.modules.platform</depends>

    <resource-bundle>messages.MyBundle</resource-bundle>

    <extensions defaultExtensionNs="com.intellij">
        <gotoDeclarationHandler
                implementation="com.github.xuzheng0912.liems.handler.LuiAjaxArgumentGotoJavaMethodHandler"/>
    </extensions>
</idea-plugin>

finally, the project build successfully

But But when I tried to trigger the function of my plugin, I got an error

2024-11-12 11:35:13,391 [   4227]   WARN - #c.i.o.a.Application - issue detected: ide.script.launcher.used
2024-11-12 11:35:32,552 [  23388] SEVERE - #c.i.o.e.i.ExtensionPointImpl - Extension com.github.xuzheng0912.liems.handler.LuiAjaxArgumentGotoJavaMethodHandler does not implement interface com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler (adapter=SimpleConstructorInjectionAdapter(implementation=com.github.xuzheng0912.liems.handler.LuiAjaxArgumentGotoJavaMethodHandler, plugin=PluginDescriptor(name=LiEMS, id=com.github.xuzheng0912.liems, descriptorPath=plugin.xml, path=D:\dev\repository\LiEMS\build\idea-sandbox\IC-2024.2.4\plugins\LiEMS, version=0.0.1, package=null, isBundled=false)))
com.intellij.diagnostic.PluginException: Extension com.github.xuzheng0912.liems.handler.LuiAjaxArgumentGotoJavaMethodHandler does not implement interface com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler (adapter=SimpleConstructorInjectionAdapter(implementation=com.github.xuzheng0912.liems.handler.LuiAjaxArgumentGotoJavaMethodHandler, plugin=PluginDescriptor(name=LiEMS, id=com.github.xuzheng0912.liems, descriptorPath=plugin.xml, path=D:\dev\repository\LiEMS\build\idea-sandbox\IC-2024.2.4\plugins\LiEMS, version=0.0.1, package=null, isBundled=false)))
    at com.intellij.serviceContainer.ComponentManagerImpl.createError(ComponentManagerImpl.kt:980)
    at com.intellij.openapi.extensions.impl.ExtensionPointImpl.checkExtensionType(ExtensionPointImpl.kt:209)
    at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapter(ExtensionPointImpl.kt:427)
    at com.intellij.openapi.extensions.impl.ExtensionPointImpl.createExtensionInstances(ExtensionPointImpl.kt:376)
    at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensionList(ExtensionPointImpl.kt:222)
    at com.intellij.openapi.extensions.ExtensionPointName.getExtensionList(ExtensionPointName.kt:54)
    at com.intellij.codeInsight.navigation.actions.GotoDeclarationAction.update(GotoDeclarationAction.java:263)
    at com.intellij.openapi.actionSystem.ex.ActionUtil$performDumbAwareUpdate$runnable$1.invoke(ActionUtil.kt:202)
    at com.intellij.openapi.actionSystem.ex.ActionUtil$performDumbAwareUpdate$runnable$1.invoke(ActionUtil.kt:196)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.kt:220)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$updateAction$success$1$1$1.invoke(ActionUpdater.kt:561)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$updateAction$success$1$1$1.invoke(ActionUpdater.kt:560)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$callAction$2$1.invoke(ActionUpdater.kt:155)
    at com.intellij.openapi.application.rw.InternalReadAction.insideReadAction(InternalReadAction.kt:104)
    at com.intellij.openapi.application.rw.InternalReadAction.access$insideReadAction(InternalReadAction.kt:15)
    at com.intellij.openapi.application.rw.InternalReadAction$tryReadCancellable$2.invoke(InternalReadAction.kt:94)
    at com.intellij.openapi.application.rw.InternalReadAction$tryReadCancellable$2.invoke(InternalReadAction.kt:93)
    at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal$lambda$2$lambda$1$lambda$0(cancellableReadAction.kt:31)
    at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.tryRunReadAction(AnyThreadWriteThreadingSupport.kt:291)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:965)
    at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal$lambda$2$lambda$1(cancellableReadAction.kt:29)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtilService.runActionAndCancelBeforeWrite(ProgressIndicatorUtilService.java:66)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:155)
    at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal(cancellableReadAction.kt:27)
    at com.intellij.openapi.application.rw.InternalReadAction.tryReadCancellable(InternalReadAction.kt:93)
    at com.intellij.openapi.application.rw.InternalReadAction.tryReadAction(InternalReadAction.kt:77)
    at com.intellij.openapi.application.rw.InternalReadAction.readLoop(InternalReadAction.kt:64)
    at com.intellij.openapi.application.rw.InternalReadAction.access$readLoop(InternalReadAction.kt:15)
    at com.intellij.openapi.application.rw.InternalReadAction$runReadAction$3.invokeSuspend(InternalReadAction.kt:35)
    at com.intellij.openapi.application.rw.InternalReadAction$runReadAction$3.invoke(InternalReadAction.kt)
    at com.intellij.openapi.application.rw.InternalReadAction$runReadAction$3.invoke(InternalReadAction.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:62)
    at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:261)
    at com.intellij.openapi.application.rw.InternalReadAction.runReadAction(InternalReadAction.kt:34)
    at com.intellij.openapi.application.rw.PlatformReadWriteActionSupport.executeReadAction(PlatformReadWriteActionSupport.kt:38)
    at com.intellij.openapi.application.ReadWriteActionSupport.executeReadAction$default(ReadWriteActionSupport.kt:15)
    at com.intellij.openapi.application.CoroutinesKt.constrainedReadActionUndispatched(coroutines.kt:82)
    at com.intellij.openapi.application.CoroutinesKt.readActionUndispatched(coroutines.kt:69)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$callAction$$inlined$useWithScope$1.invokeSuspend(trace.kt:163)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$callAction$$inlined$useWithScope$1.invoke(trace.kt)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$callAction$$inlined$useWithScope$1.invoke(trace.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:62)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:163)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.callAction(ActionUpdater.kt:939)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.access$callAction(ActionUpdater.kt:85)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$updateAction$success$1$1.invokeSuspend(ActionUpdater.kt:560)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$updateAction$success$1$1.invoke(ActionUpdater.kt)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$updateAction$success$1$1.invoke(ActionUpdater.kt)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$updateAction$$inlined$retryOnAwaitSharedData$1.invokeSuspend(ActionUpdater.kt:939)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$updateAction$$inlined$retryOnAwaitSharedData$1.invoke(ActionUpdater.kt)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$updateAction$$inlined$retryOnAwaitSharedData$1.invoke(ActionUpdater.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:62)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:163)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.updateAction(ActionUpdater.kt:979)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.presentation(ActionUpdater.kt:530)
    at com.intellij.openapi.actionSystem.impl.Utils$runUpdateSessionForInputEvent$2$result$1$1$1.invoke(Utils.kt:1032)
    at com.intellij.openapi.actionSystem.impl.Utils$runUpdateSessionForInputEvent$2$result$1$1$1.invoke(Utils.kt:1032)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doUpdateActionsInner(IdeKeyEventDispatcher.kt:812)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.access$doUpdateActionsInner(IdeKeyEventDispatcher.kt:1)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$processAction$1$chosen$1.invokeSuspend(IdeKeyEventDispatcher.kt:545)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$processAction$1$chosen$1.invoke(IdeKeyEventDispatcher.kt)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$processAction$1$chosen$1.invoke(IdeKeyEventDispatcher.kt)
    at com.intellij.openapi.actionSystem.impl.Utils$runUpdateSessionForInputEvent$2$result$1$1.invokeSuspend(Utils.kt:1032)
    at com.intellij.openapi.actionSystem.impl.Utils$runUpdateSessionForInputEvent$2$result$1$1.invoke(Utils.kt)
    at com.intellij.openapi.actionSystem.impl.Utils$runUpdateSessionForInputEvent$2$result$1$1.invoke(Utils.kt)
    at com.intellij.openapi.actionSystem.impl.Utils$runUpdateSessionForInputEvent$2$result$1.invokeSuspend(Utils.kt:1301)
    at com.intellij.openapi.actionSystem.impl.Utils$runUpdateSessionForInputEvent$2$result$1.invoke(Utils.kt)
    at com.intellij.openapi.actionSystem.impl.Utils$runUpdateSessionForInputEvent$2$result$1.invoke(Utils.kt)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater$runUpdateSession$2.invokeSuspend(ActionUpdater.kt:229)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:608)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:873)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:763)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:750)
2024-11-12 11:35:32,566 [  23402] SEVERE - #c.i.o.e.i.ExtensionPointImpl - IntelliJ IDEA 2024.2.4  Build #IC-242.23726.103
2024-11-12 11:35:32,566 [  23402] SEVERE - #c.i.o.e.i.ExtensionPointImpl - JDK: 21.0.4; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o.
2024-11-12 11:35:32,566 [  23402] SEVERE - #c.i.o.e.i.ExtensionPointImpl - OS: Windows 11
2024-11-12 11:35:32,566 [  23402] SEVERE - #c.i.o.e.i.ExtensionPointImpl - Plugin to blame: LiEMS version: 0.0.1
2024-11-12 11:35:32,566 [  23402] SEVERE - #c.i.o.e.i.ExtensionPointImpl - Last Action: 
2024-11-12 11:35:37,854 [  28690]   WARN - #c.i.u.x.Binding - No accessors for org.jetbrains.kotlin.cli.common.arguments.InternalArgument. This means that state class cannot be serialized properly. Please see https://jb.gg/ij-psoc

I made sure I implemented the interface and registered the implementation class

I also executed the gradle clean and build commands


Solution

  • I found the problem and fixed it
    Firstly, IC dose not support web-related features like JavaScript, so we need to adjust gradle.properties

    IC means Idea Community
    IU means Idea Ultimate

    platformType = IU
    

    References to PSI dependencies are also not configured in the build.gradle.kts
    configured that also in gradle.properties

    platformBundledPlugins = com.intellij.java, JavaScript
    

    this property means we need to use Java and JavaScript PSI

    platformBundledPlugins = JavaScript only works when platformType = IU

    we can remove the PSI dependency configuration in build.gradle.kts
    Before the end, we need to add language <depends></depends> to plugin.xml

    <depends>com.intellij.modules.platform</depends>
    <depends>com.intellij.modules.lang</depends>
    <depends>com.intellij.modules.javascript</depends>
    <depends>com.intellij.java</depends>
    

    if miss this, PSI like JSCallExpression will raise ClassNotFindException in runtime

    Finally, you can build, run and debug the plugin!