Need help with live-plugin?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

dkandalov
493 Stars 50 Forks 1.3K Commits 18 Opened issues

Description

IntelliJ plugin for writing IntelliJ plugins at runtime ⚡️

Services available

!
?

Need anything else?

Contributors list

Build Status

LivePlugin

This is a plugin for IntelliJ IDEs to create plugins at runtime using Groovy and Kotlin. To install search for "LivePlugin" in

IDE Preferences -> Plugins -> Marketplace
. See also plugin repository page.

demo

Why?

  • Minimal setup — you can edit and execute plugins in any project, i.e. less effort compared to creating a separate project for plugin development.
  • Fast feedback loop — plugins are executed in the same JVM instance as IDE, so there is no need to restart (this is similar to dynamic plugins except that it works in the same IDE instance).
  • Usable IDE API — LivePlugin adds a thin API layer on top of the IntelliJ to highlight some entry points and make common tasks easier.

Examples

Hello world:

groovy
import static liveplugin.PluginUtil.show
show("Hello world") // shows balloon message with "Hello world" text
Insert New Line Above Action: ```groovy import com.intellij.openapi.actionSystem.AnActionEvent import static liveplugin.PluginUtil.*

// Action to insert new line above the current line. // Based on this post http://martinfowler.com/bliki/InternalReprogrammability.html // Note that there is "Start New Line Before Current" action (ctrl+alt+enter) which does almost the same thing. registerAction("Insert New Line Above", "alt shift ENTER") { AnActionEvent event -> runDocumentWriteAction(event.project) { currentEditorIn(event.project).with { def offset = caretModel.offset def currentLine = caretModel.logicalPosition.line def lineStartOffset = document.getLineStartOffset(currentLine)

        document.insertString(lineStartOffset, "\n")
        caretModel.moveToOffset(offset + 1)
    }
}

} show("Loaded 'Insert New Line Above' action
Use 'Alt+Shift+Enter' to run it") ```

How to start writing plugins

Make sure "hello world" works fine: - In the

Plugins
tool window select "hello-world" plugin and click "Run" button to execute the plugin (
Run Plugin
action with
ctrl+shift+L
or
alt+C, alt+E
shortcut). It should display a message. - Make a small modification in
plugin.groovy
/
plugin.kts
and rerun the plugin. On the second run, previous version of the plugin will be unloaded before the code is evaluated again. - Modify
plugin.groovy
/
plugin.kts
file again so that it fails to compile/run. You should see an error message in the
Run
tool window which, hopefully, makes sense. - Note that plugins are just folders with
plugin.groovy
or
plugin.kts
scripts as entry points. This means that you can, for example, copy path to the plugin folder using
Copy Path
action (
ctrl/cmd+alt+C
shortcut).

Try bundled examples: - In the

Plugins
tool window click "Plus" button (
Add Plugin
action) and select Groovy or Kotlin examples. - It might be useful to install Groovy or Kotlin plugin if your IDE supports them.

Take a look at settings in the

Plugins
toowindow: -
Run Plugins on IDE Start
— to run all plugins on IDE start. -
Run Project Specific Plugins
— to run all plugins in
.live-plugins
project directory when the project is opened and unload them when the project is closed. -
Add LivePlugin and IDE Jars to Project
— useful for Groovy plugins to get auto-completion and code navigation in plugin code. (There is no doubt that adding jars unrelated to your project is a hack but there seems to be no major problems with it.) Note that Kotlin plugins should have auto-completion and code navigation without it.

Learn more about IntelliJ API: - Read (or at least skim) plugin development fundamentals and the following sections. - Clone IntelliJ source code or explore it on GitHub or Upsource. One strategy which I like is to search for text you can see in IDE UI and try to figure out how it's connected to the code which does actual work. - PluginUtil class and liveplugin package might have some good starting points to explore IntelliJ API.

Once your plugin has grown, you can move it to a proper plugin project still using live plugin for reloading and maybe then convert it to become a dynamic plugin.

If something doesn't work or doesn't make sense, please feel free to ask in

#live-plugin
channel on Jetbrains platform slack or report an issue (it's ok to report an issue even if it's just a question).

Practical use cases

  • prototyping of IntelliJ plugins
  • experimenting with IntelliJ API
  • project-specific workflow automation
  • integrating shell scripts with IDE

The main idea

LivePlugin basically runs Groovy or Kotlin code in JVM. Conceptually it's quite simple:

java
ClassLoader classLoader = createClassLoader(ideClassloader, ...);
GroovyScriptEngine scriptEngine = new GroovyScriptEngine(pluginFolderUrl, classLoader);
scriptEngine.run(mainScriptUrl, createGroovyBinding(binding));
This means that your code is executed in the same environment as IDE internal code. You can use any internal API and observe/change state of any object inside IDE. There are some limitations of course, like
final
fields and complex APIs not designed to be re-initialized.

To simplify usage of IntelliJ API for practical purposes some parts of IntelliJ API are wrapped in PluginUtil class. This is essentially a layer on top of the standard IntelliJ API. If you find yourself writing interesting IDE scripts, feel free to create pull request or send a gist to include your code into

PluginUtil
. This is experimental API and there is no intention to keep it minimal.
PluginUtil
is not required though and you can always use IntelliJ classes directly.

Also note that: - plugins are evaluated with new classloader on each run - plugins are stored in

$HOME/.$INTELLIJ_VERSION/config/live-plugins
(on Mac
$HOME/Library/Application Support/IntelliJIdea15/live-plugins
) Note that you can use
ctrl+shift+C
shortcut to copy file/folder path. - if available, Groovy library bundled with IDE is used

More examples

Similar plugins

The idea of running code inside IntelliJ is not original. There are/were similar plugins: - IDE Scripting Console (experimental feature, bundled with IntelliJ since 14.1) - Script Monkey - PMIP - Poor Mans IDE Plugin (no longer available) - Remote Groovy Console (most likely out-of-date) - Groovy Console Plugin (most likely out-of-date) - HotPlugin (most likely out-of-date)

Contributing

Please see CONTRIBUTING.md.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.