dkandalov / live-plugin

IntelliJ plugin for writing IntelliJ plugins at runtime ⚡️
https://plugins.jetbrains.com/plugin/7282
Apache License 2.0
858 stars 67 forks source link

git4idea classes are not available in Kotlin #106

Closed coodix closed 2 years ago

coodix commented 4 years ago

Trying to import Git plugin classes in Kotlin plugin

import git4idea.GitUtil
import git4idea.GitContentRevision
import git4idea.GitRevisionNumber
import git4idea.changes.GitChangeUtils
import git4idea.history.GitHistoryUtils

but getting error:

Couldn't load plugin: "branch-differ". Error compiling script. /Users/iisakov/Library/Application Support/PhpStorm2019.2/live-plugins/branch-differ/plugin.kts:13:8: error: unresolved reference: git4idea
import git4idea.GitUtil
       ^

When run as Groovy plugin import is not failing.

  1. Tried to add with no luck // depends-on-plugin Git4Idea

    • same error appears (unresolved reference: git4idea)
  2. Tried to add with no luck

    // add-to-classpath /Applications/PhpStorm.app/Contents/plugins/git4idea/lib/git4idea.jar
    • but getting error:
      Couldn't load plugin: "branch-differ". Error while loading plugin class. java.lang.VerifyError: class Plugin overrides final method liveplugin.pluginrunner.kotlin.KotlinScriptTemplate.getProject()Lcom/intellij/openapi/project/Project;
      at java.base/java.lang.ClassLoader.defineClass1(Native Method)
      at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
      at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
      at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
      at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
      at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
      at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:702)
      at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:812)
      at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:800)
      at liveplugin.pluginrunner.kotlin.KotlinPluginRunner.runPlugin(KotlinPluginRunner.kt:99)
      at liveplugin.pluginrunner.RunPluginActionKt$runPlugins$$inlined$map$lambda$1.invoke(RunPluginAction.kt:94)
      at liveplugin.pluginrunner.RunPluginActionKt$runPlugins$$inlined$map$lambda$1.invoke(RunPluginAction.kt)
      at liveplugin.IdeUtilKt$sam$java_lang_Runnable$0.run(IdeUtil.kt)
      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      at java.base/java.lang.Thread.run(Thread.java:834)
coodix commented 4 years ago

@dkandalov any ideas how to eliminate this?

coodix commented 4 years ago

@dkandalov hey, could you please have a look at this issue? It would be great if you could point the way where to dig.

dkandalov commented 4 years ago

Hi. Sorry for the slow reply. I was able to reproduce the issue and started looking into it yesterday but didn't get too far.

There are two sides to it:

coodix commented 4 years ago

It would be great to make it at least successfully compiling. I've looked at KotlinPluginRunner and tried to apply same approach as was done in https://github.com/dkandalov/live-plugin/pull/104/files

"unresolved reference" errors disappear and git4idea's classes become available but it doesn't seem normal way to hardcode paths for needed plugins.

dkandalov commented 3 years ago

👋 This should be fixed in plugin version 0.7.0. (Apologies it took a while to fix but, unfortunately, dealing with Kotlin scripting API and compilation is not easy or pleasant.)