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?
-
Found anything?kornfridge– kornfridge2017-02-17 20:59:44 +00:00Commented Feb 17, 2017 at 20:59
-
There is a topic on Youtrack about this, pointing to this example. It is mentioned that it is an experimental feature for now, for power users and developers.clementescolano– clementescolano2017-02-20 10:22:41 +00:00Commented Feb 20, 2017 at 10:22
-
1@clems4ever "Experimental feature for power users and developers" You made my daym0skit0– m0skit02017-05-26 11:48:06 +00:00Commented May 26, 2017 at 11:48
-
dmitrijs.artjomenko.com/2015/09/… this may be helpful.pmaddi– pmaddi2017-11-13 11:09:16 +00:00Commented Nov 13, 2017 at 11:09
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:
Hope this could help anyone. Write in the comments if you know how to create an Action in JS.
2 Comments
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
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
