How do I make intellij Idea to highlight Scala script correctly.
Attempt 1 change filename to 'test.sc' . Intellij does not like the first line i.e it is not valid scala comment syntax
Attempt 2 change filename to 'test.sh' . Intellij thinks all of the syntax is bash script.
filenName = ./test.sh
#!/usr/bin/env amm
import ammonite.ops._ , ImplicitWd._
println("Stop script")
val x = 1 + 1
Press Ctrl+Alt+S to open Settings/Preferences dialog. From the options on the left, select Build, Execution, Deployment | Compiler | Scala | Scala Compiler Server. In JVM SDK field specify the appropriate SDK.
If you need to preserve .sc
extension here is a little trick
change shebang to #! /usr/bin/env amm
which is still a valid shebang
put a file named #!.scala
next to your script with the content:
class CLZ {
def /(that: CLZ): CLZ = this
def amm: Unit = {}
}
object #! extends CLZ
object usr extends CLZ
object bin extends CLZ
object env extends CLZ
Now, your script is properly highlighted
JetBrains published a blog article about support for Ammonite.
If you have a .scala
extension, IDEA recognizes as a valid Scala script file.
Even a multiline shebang line is supported:
#!/bin/sh
DIR=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
exec scala -classpath $DIR/scalaj-http_2.11-2.3.0.jar -savecompiled "$0" "$@"
!#
/* Scala code*/
Make sure:
It works even if the script is outside of a declared source folder. I can even edit scripts outside of my project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With