A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/dkandalov/live-plugin below:

dkandalov/live-plugin: IntelliJ plugin for writing IntelliJ plugins at runtime ⚡️

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

Hello world in Groovy:

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

Insert New Line Above action in 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: AnActionEvent ->
    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")

Make sure "hello world" works fine:

Try bundled examples:

Take a look at settings in the Live Plugins tool window:

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 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:

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.

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

Please see CONTRIBUTING.md.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4