This is experimental IntelliJ IDEA plugin for writing plugins in Groovy at runtime
(or running Groovy code inside IntelliJ).
- it should be possible to write a simple plugin without setting up new project
- plugins source code should be easily available and editable
- time between writing code and seeing how it works should be short
import com.intellij.openapi.actionSystem.AnActionEvent
import static intellijeval.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")
Through IntelliJ plugin manager. Search for "eval". (Just in case this is the plugin page.)
- open "Plugins" tool window on the right side
- select "helloWorld" plugin and press "ctrl + C, ctrl + E" to execute it ("plugin.groovy" are plugin entry points)
- add plugin examples and experiment with them
- have auto-completion by adding IDEA and IntelliJEval jars to project (can be done in "Settings" drop-down at the top of "Plugins" tool window).
- install Groovy plugin
- look at PluginUtil class
- get IntelliJ sources to see source code and javadocs
- this is essentially a host plugin for other plugins
- each plugin is evaluated with its own classloader using GroovyScriptEngine
- it uses Groovy bundled with IntelliJ (v1.8.5 at the moment)
- plugins are stored in "$HOME/.$INTELLIJ_VERSION/config/intellij-eval-plugins" (on Mac "$HOME/Library/Application Support/IntelliJIdea12/intellij-eval-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:
- PMIP - Poor Mans IDE Plugin (it's for Ruby)
- Remote Groovy Console
- Script Monkey
- Groovy Console Plugin
- HotPlugin (probably outdated)
- have nice object tree pattern-matching API for Groovy. Or may be there is one and I just don't know about it.
- use another language (e.g. Scala or Ruby).
- go meta! Rewrite IntelliJEval as its own plugin. This is really how it was started (loads of fun with classloaders). The old meta-version was too broken to be released and two years later was replaced with this.