This is IntelliJ plugin for writing IDE plugins at runtime in Groovy. (See also plugin repository page.)
It's difficult to explain better than Martin Fowler does in this blog post but in short:
- to make writing plugins easier. There is no need to set up and configure a separate project.
- faster feedback loop. There is no need to start new IDE instance to run a plugin. If you change plugin code, there is no need to restart IDE.
- great goodness of customized IDE. In a way even Excel can be "customized" at runtime with VB script. This is an attempt to fix this and have easy-to-extend IDE.
import com.intellij.openapi.actionSystem.AnActionEvent
import static liveplugin.PluginUtil.*
// This action inserts new line above current line.
// It's a follow-up for these posts:
// http://martinfowler.com/bliki/InternalReprogrammability.html
// http://nealford.com/memeagora/2013/01/22/why_everyone_eventually_hates_maven.html
// Note that there is "Start New Line Before Current" action (ctrl + alt + enter) which does almost the same thing.
registerAction("InsertNewLineAbove", "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 'InsertNewLineAbove' action<br/>Use 'Alt+Shift+Enter' to run it")
See also Scala plugin example and Clojure plugin example.
Through IntelliJ plugin manager. In "Preferences -> Plugins -> Browse Repositories" search for "liveplugin". Alternatively, download LivePlugin.zip and use "Install plugin from disk".
- open "Plugins" tool window on the right side
- select "helloWorld" plugin and press "alt + C, alt + E" to execute it ("plugin.groovy" are plugin entry points)
- add plugin examples and experiment with them
- it helps to be familiar with IntelliJ API (e.g. look at plugin development wiki page). Some parts of it which seem to be useful for small plugins are in PluginUtil class. Even if you don't use it, it might be a good place to look up bits of IntelliJ API.
- it helps to have JetGroovy plugin installed (available only for IntelliJ IDEA).
- you can get auto-completion in plugins code by adding IDEA and LivePlugin jars to project (in "Settings" drop-down at the top of "Plugins" tool window). This is a bit of a hack, but seems much easier than setting up a new project for every tiny experiment.
- get IntelliJ source code, find out how your favorite feature is implemented, steal the code and adapt it for your needs
- if your plugins are stable enough, you can enable "Settings -> Run All Live Plugins on IDE Startup" option. If some of them are not meant to be executed at startup, add "if (isIdeStartup) return" statement at the top.
- when plugin seems to be big enough, you can create a separate project for it but still use live plugin for loading. Or you can use liveplugin with existing plugins, the only thing is to make it reloadable. See liveplugin as an entry point for standard plugins.
- intellij-emacs - macros for making IntelliJ more friendly to emacs users (see also blog post)
- Simplistic "compile and run haskell" action - obviously this can be done for other languages/environments
- Google quick search popup - prototype of google popup search mini-plugin
- Scripting a macros - example of finding and invoking built-in actions
- Console filter/transform example - example of filtering and changing console output
- VCS update listener example - example of adding callback on VCS update
- Find class dependencies - simple action to find all class dependencies within current project
- Module transitive dependencies - finds all transitive dependencies for modules in IDEA project
- Show text diff - really lame example of opening IntelliJ text diff window (please don't use it!)
- Find all recursive methods in project (for Java) - quick plugin as a follow up for this talk
- Watching projects open/close events - an example of reloadable project listener
- Minimalistic view for java code - collapses most of Java keywords and types leaving only variable names
- Symbolize keywords - collapses Java keywords into shorter symbols
- Change List Size Watchdog - micro-plugin to show warning when change list size exceeds threshold (see also Limited WIP plugin)
- Template completion on "Tab" - simplistic prototype for auto-completion on tab key (in case built-in live templates are not enough)
- Completion contributor example - only gives an idea which part of IntelliJ API to use
- Google auto-completion contributor example - same as above but with google search plugged in
- Add custom search example - only gives an idea which part of IntelliJ API to use
- Get files from last commits example - gets VirtualFiles from several last commits
- Show PSI view dialog - one-liner to show PSI viewer dialog. Normally it's only enabled in plugin projects.
- Simplistic "generify return type" - attempt to pattern-match PSI tree
- No copy-paste - disables copy/paste actions
- Text munging actions - simple actions on text (sort, unique, keep/delete lines)
- Wrap selection - micro-plugin to wrap long lines with separator
- Wrap selected text to column width - copy of this plugin https://github.com/abrookins/WrapToColumn
- Create .jar patch file for current change list - that's what it does
- Remove getters/setters - removes all setters or getters in a class
- ISO DateTime / Epoch timestamp converter - converts Epoch time to/from ISO format
- Make cursor move in circle - definitely not practical but gives an idea about threading
- Word Cloud - shows world cloud for the selected item (file/package/folder)
- Project TreeMap View - shows project structure (packages/classes) as treemap based on size of classes
- Method History - combines built-in method history based on selection and method history based on method name
- Evaluate selection as Groovy - that's exactly what it does
- Code History Mining - (not a tiny project) allows to grab, analyze and visualize project source code history
It just runs your code in JVM, like this:
GroovyScriptEngine scriptEngine = new GroovyScriptEngine(pluginFolderUrl, classLoader);
scriptEngine.run(mainScriptUrl, createGroovyBinding(binding));
- each plugin is evaluated with its own classloader
- it uses Groovy bundled with IntelliJ
- plugins are stored in "$HOME/.$INTELLIJ_VERSION/config/live-plugins" (on Mac "$HOME/Library/Application Support/IntelliJIdea12/live-plugins"). You can also use standard "ctrl + shift + C" shortcut to copy file/folder path.
The idea of running code inside IntelliJ is not original. There are similar plugins (although I wasn't too happy with them):
- IDE Scripting Console (experimental feature, bundled with IntelliJ since 14.1)
- PMIP - Poor Mans IDE Plugin (for Ruby)
- Remote Groovy Console
- Script Monkey
- Groovy Console Plugin
- HotPlugin (probably outdated)
- to try writing a language plugin
- to have nice object tree pattern-matching API for Groovy (can be good for writing inspections/intentions to match/replace syntax tree).
- add more languages, e.g. Ruby, Kotlin or Java.
Please see CONTRIBUTING.md.