Javascript in IntelliJ's "IDE scripting console"

Viewed 4785

Recent versions of IntelliJ have an "IDE scripting console" option under the tools menu. I've had a hard time finding blog posts about it. Some of these posts pointed out, and the gui proves this, that it has support for javascript. Could someone please point me to an example or blogpost how to use this feature (api docs) with javascript please?

2 Answers

Here is how to use it: https://www.jetbrains.com/help/idea/ide-scripting-console.html

Here is the API docs: http://www.jetbrains.org/intellij/sdk/docs/welcome.html

Best/largest(?) set of examples I could find: https://gist.github.com/gregsh/b7ef2e4ebbc4c4c11ee9

Unfortunately for JS there is the least amount of examples. That said, I've tried to implement an Action that starts the first Run Configuration. The code actually works pretty well. I've got stuck, however, on how to extend the Java Action abstract class from JS. Below is the working code:

var result = function run() {
    var executor = com.intellij.execution.executors.DefaultDebugExecutor.getDebugExecutorInstance();
    var runConfigsSettings = com.intellij.execution.RunManager.getInstance(IDE.project).allSettings;
    var a = com.intellij.execution.ProgramRunnerUtil.executeConfiguration(IDE.project, runConfigsSettings[0], executor);
    return a;
}()

I found the necessary docs here:

http://www.jetbrains.org/intellij/sdk/docs/basics/run_configurations/run_configuration_execution.html#starting-a-run-configuration-from-code

Hope this could help anyone. Write in the comments if you know how to create an Action in JS.

IDE scripting console for JavaScript requires NodeJS installed on your computer (and make sure it's available on you PATH system variable for Windows OS, whereas for Mac OS you just need to install it with brew).

Main reason why it may not work is NodeJS installation missing/misconfigured, or due to IntelliJ being unable to get an access to NodeJS binaries (the latter is mainly Windows specific problem).

Once you have NodeJS up & running, simply write any JS code as if you did it in regular JS file, and press F10 (or control + enter in some configurations) in order to run the script

Simple IDE scripting console demo

NOTE: I use fully licensed IntelliJ Ultimate 2017.x, all the above is for this particular version, I haven't used the community edition for a while, therefore I doubt I'll be able to help you with that one

Related