• Stars
    star
    839
  • Rank 54,338 (Top 2 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 13 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

IntelliJ plugin for writing IntelliJ plugins at runtime ⚡️

Build Status

LivePlugin

Plugin for IntelliJ-based IDEs to create plugins at runtime using Kotlin and Groovy. To install search for "LivePlugin" in IDE Preferences -> Plugins -> Marketplace or use the "Install" button on the Plugin Marketplace website.

demo

Why?

  • Minimal setup — no need to set up a separate project for plugin development
  • Fast feedback loop — plugins are (re)loaded in the same JVM instance as IDE without restart
  • Usable IDE API — LivePlugin has a small API with entry points for common IDE APIs

Examples

Hello world (Groovy):

import static liveplugin.PluginUtil.show
show("Hello world") // Shows balloon notification popup with "Hello world" text

Insert New Line Above action (Kotlin):

import com.intellij.openapi.actionSystem.AnActionEvent
import liveplugin.*

// Action to insert a new line above the current line.
// Based on this post https://martinfowler.com/bliki/InternalReprogrammability.html
// Note that there is also built-in "Start New Line Before Current" action (ctrl+alt+enter).
registerAction(id = "Insert New Line Above", keyStroke = "ctrl alt shift ENTER") { event ->
    val project = event.project ?: return@registerAction
    val editor = event.editor ?: return@registerAction
    executeCommand(editor.document, project) { document ->
        val caretModel = editor.caretModel
        val lineStartOffset = document.getLineStartOffset(caretModel.logicalPosition.line)
        document.insertString(lineStartOffset, "\n")
        caretModel.moveToOffset(caretModel.offset + 1)
    }
}
show("Loaded 'Insert New Line Above' action<br/>Use 'ctrl+alt+shift+Enter' to run it")

Getting started

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, the 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.
  • Note that plugins are just folders with plugin.groovy or plugin.kts scripts as entry points. This means that you can, for example, copy the path to the plugin folder using the Copy Path action (ctrl/cmd+alt+C shortcut).

Try bundled examples:

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

Take a look at settings in the Plugins toowindow:

  • Run Plugins on IDE Start — run all plugins on IDE start.
  • Run Project Specific Plugins — 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. (Adding jars unrelated to your project is a bit of 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:

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).

How does LivePlugin work?

Overall, the idea is just to load and run plugin Groovy or Kotlin classes in the IDE JVM at runtime. More specifically the steps are:

  • if there is an instance of pluginDisposable from previous execution, then dispose it (on EDT)
  • create a new classloader with dependencies on other plugins and jars (on a background thread)
  • compile code if necessary and load classes in the classloader (on a background thread)
  • run the plugin code (on EDT)

This means that plugin code can use any internal IDE API and observe/change IDE state. There are some limitations of course, such as final fields and IDE APIs which are not designed to be re-initialized.

Most IntelliJ-based IDEs come with a bundled Groovy jar which is used for loading and running live plugins (otherwise, the groovy-all jar will be downloaded). LivePlugin uses its own version of Kotlin stdlib and compiler because the version bundled with IDEs changes quite often and seems to be harder to rely on.

Some practical use cases

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

More examples

Similar plugins

The idea of running code inside IntelliJ is not original. There are/were similar plugins:

Contributing

Please see CONTRIBUTING.md.

More Repositories

1

kotlin-99

Ninety-Nine Problems in Kotlin
Kotlin
650
star
2

tab-shifter

Plugin for IntelliJ IDEA to move and split editor tabs
Kotlin
169
star
3

pomodoro-tm

Pomodoro timer for IntelliJ 🍅⏲
Kotlin
136
star
4

code-history-mining

IntelliJ plugin for analysis and visualisation of project code history
Groovy
121
star
5

limited-wip

IntelliJ plugin to limit your work-in-progress
Kotlin
109
star
6

scratch

Scratch is IntelliJ IDEs plugin to quickly open temporary text editor
Kotlin
83
star
7

friday-mario

IntelliJ plugin to have fun 🎮🔊
Kotlin
76
star
8

activity-tracker

Plugin for IntelliJ IDEs to track and record user activity
Kotlin
67
star
9

kotlin-native-snake

Slides and source code for the "Live Coding Kotlin/Native Snake" talk
Kotlin
52
star
10

kotlin-puzzlers

Kotlin
36
star
11

ijkl-shortcuts-plugin

IJKL navigation shortcuts plugin for JetBrains IDEs 🙌 ⌨️
Kotlin
27
star
12

slides-presenter

Plugin to show slides and code examples directly from IntelliJ IDEs
Kotlin
21
star
13

rosettacode-kotlin

Repository with source code from http://rosettacode.org/wiki/Category:Kotlin
Kotlin
21
star
14

quick-fix

Plugin for JetBrains IDEs to apply "quick fix" from the most relevant intention or inspection 💡
Kotlin
19
star
15

coroutines-explained

Slides and code for the "Coroutines explained" talk at ACCU, SoCraTes UK and CodeMesh 2018
Kotlin
18
star
16

tictactoe4k

Source code and slides for the tictactoe4k talk
Kotlin
12
star
17

gilded-rose

This is the source code and slides for the Gilded Rose Refactoring Kata talk
Kotlin
10
star
18

easy-way-to-create-ij-plugins

Kotlin
8
star
19

lsystem-js

Interactive demo of L-Systems using webgl, see http://dkandalov.github.io/lsystem/
JavaScript
8
star
20

programming-kotlin-with-nothing

Reimplementing lambda calculus in Kotlin for fun and profit.
Kotlin
6
star
21

parser-combinator-koans

Koans to build parser combinator in Kotlin from scratch
Kotlin
6
star
22

katas

🙈🙈🙈
Roff
5
star
23

kotlin-failed-line-inspection

Kotlin
5
star
24

vcs-reader

Minimal Java library for reading VCS commits (git, hg, svn)
Java
5
star
25

limited-wip-for-devs

Kotlin
5
star
26

intellij-wordcloud

JavaScript
4
star
27

project-treemap

Project treemap micro-plugin for IntelliJ (using d3.js for visualisation)
JavaScript
4
star
28

neo-psi

Groovy
4
star
29

promotion-service-kata

Promotion service kata
C
4
star
30

groovy-beans

Groovy
3
star
31

hello-webgl

JavaScript
3
star
32

definilizer

Java ClassLoader which removes finals at runtime
Java
3
star
33

gilded-rose-service

Code kata and source code for the Refactoring Spring to Kotlin talk
Kotlin
2
star
34

statemachine

A Ruby Library, Gem, and Rails Plugin
Ruby
2
star
35

datsok

Minimal test assertions for Kotlin
Kotlin
2
star
36

error-handling-in-kotlin

Kotlin
2
star
37

code-history-mining-cli

Command line interface for mining code history
2
star
38

Beautiful-code-best-practice-enterprise-patterns

2
star
39

htmlexport

Java
2
star
40

ijkl-keymaps

2
star
41

refactorings

Groovy
2
star
42

nonstdlib

Kotlin
2
star
43

connect-four

Kotlin
2
star
44

opengl_redbook

C
2
star
45

graalvm-snake

Kotlin
2
star
46

flare_visualization

JavaScript
1
star
47

scala-native-snake

Scala
1
star
48

spa-http4k

Kotlin
1
star
49

MarkdownParse

Kotlin
1
star
50

game-of-life-3d

JavaScript
1
star
51

tags

Simple tag manage library
1
star
52

Parser_Combinator_Koans

Kotlin
1
star
53

c-99-problems

🤖🤖🤖
C++
1
star
54

history-slider-plugin

Groovy
1
star
55

understanding-computation

Ruby
1
star
56

dkandalov.github.io

JavaScript
1
star
57

colorizer

Groovy
1
star
58

groovy-beans-user

Groovy
1
star
59

d3-components

JavaScript
1
star
60

rust-snake

Minimal ncurses snake game in rust
Rust
1
star
61

MPS-baseLanguage-examples

MPS baseLanguage examples
1
star
62

man-page-viewer

Man page viewer plugin 📓🤓
Kotlin
1
star
63

squasher

Source code for the squasher coroutine blog post
Assembly
1
star
64

go-snake

Go
1
star
65

dependencies-graph

Groovy
1
star