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 "alt + C, alt + E" to execute it ("plugin.groovy" are plugin entry points)
- add plugin examples and experiment with them
- to 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 source code
- Wrap selected text to column width - copy of this plugin https://github.com/abrookins/WrapToColumn
- Symbolize keywords - collapses Java keywords into shorter symbols
- 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
- Change List Size Watchdog - micro-plugin to show warning when change list size exceeds threshold
- 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
- Template completion on "Tab" - simplistic prototype for auto-completion on tab key (in case built-in live templates are not enough)
- No copy-paste - disables copy/paste actions
- Wrap selection - micro-plugin to wrap long lines with separator
- 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
- 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)
- to have nice object tree pattern-matching API for Groovy (can be good for writing inspections/intentions to match/replace syntax tree). 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 this plugin 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.