Logo

dev-resources.site

for different kinds of informations.

JavaScript in IDE scripting console

Published at
9/18/2024
Categories
jetbrains
javascript
idea
Author
Maksim
Categories
3 categories in total
jetbrains
open
javascript
open
idea
open
JavaScript in IDE scripting console

Official script example written in JavaScript

function main() {
  let sum = 0;
  let arr = "35907 77134 453661 175096 23673 29350".split(" ");
  arr.forEach((it) => sum += it.length);

  com.intellij.openapi.ui.Messages.showInfoMessage((sum / arr.length).toString(), "test");
}

main();

IDEA uses GraalJS to run the script. So you can use interop between JavaScript and Java to access Java objects.

JavaScript runtime also has a global variable IDE which reference an instance of com.intellij.ide.script.IDE

IDE.print("Hello World!")

Featured ones: