17

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?

4
  • Found anything? Commented 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. Commented Feb 20, 2017 at 10:22
  • 1
    @clems4ever "Experimental feature for power users and developers" You made my day Commented May 26, 2017 at 11:48
  • dmitrijs.artjomenko.com/2015/09/… this may be helpful. Commented Nov 13, 2017 at 11:09

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot for your example! How do you execute this run() function after you created this script? Is there some menu in IDE, where you can select it and start? Do you think it is possible to implement a JS script, which will do this: when user right clicks some line in code and selects "Some item" in context menu, JS will open in browser the url composed of filename and line number.
I get this error if I try to execute this by Ctrl+A Ctrl+Enter: NoSuchMethodException: None of the fixed arity signatures [(com.intellij.execution.runners.ExecutionEnvironment, boolean, boolean), (com.intellij.openapi.project.Project, com.intellij.execution.RunnerAndConfigurationSettings, com.intellij.execution.Executor)] of method com.intellij.execution.ProgramRunnerUtil.executeConfiguration match the argument types [com.intellij.openapi.project.impl.ProjectImpl, jdk.nashorn.internal.runtime.Undefined, com.intellij.execution.executors.DefaultDebugExecutor]
-4

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

1 Comment

This isn't how IDE scripting console should be used. jetbrains.com/help/idea/ide-scripting-console.html What you are doing is different, you are running JS code in an external Node process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.