Ammonite, developed by Li Haoyi, is a well-known toolset that lets us use Scala language for scripting purposes. It contains a modernized REPL, a replacement for the Bash system shell, a Filesystem Library, and specific notations for more productive scripting.
Even though many situations in which you would use Ammonite are intended for the command-line mode, quite a few use cases are also relevant for an IDE. After receiving some feedback from our users, we’ve decided to provide advanced support for this technology in our Scala plugin. The set of enhancements includes: support for Ammonite Notations, Run Configuration, a gutter icon for running scripts more easily, and pop-up actions for automatically importing libraries. Read on for more details and screenshots.
To demonstrate our new features, we’ll use an example of Li Haoyi’s project, which forms a blog from a set of text documents and pictures. As Ammonite is an external tool, there are some prerequisites for its usage:
- Ammonite must be installed on your OS.
- IntelliJ IDEA needs to knows where the Ammonite executable is located. You can:
- add a symlink to already accessible places like usr/bin;
- modify the $path variable; or
- specify the path to the Ammonite executable in Default Ammonite Run Configuration, by using the “Amm executable” field.
- Finally, .sc files have to be treated as Ammonite files (by default, IntelliJ IDEA treats them as Worksheets). You can define this in File | Settings | Languages & Frameworks | Scala | Worksheet.
After you’ve completed the above, IntelliJ IDEA suggests adding Ammonite standard dependencies to your project when you open an .sc file for the first time. This is required for code processing in the Editor and for navigation.
IntelliJ IDEA will download the latest version of Ammonite. Besides, if an opened file contains
$ivy. imports, IntelliJ IDEA will suggest adding them to the project as well. Note that declared libraries have to be present in local caches. If they’re missing, just run the code with these imports once and Ammonite will automatically add them to the cache.
After these imports are done, you are all set and can successfully use IDE tools to work with Ammonite code. If you open a new project, IntelliJ IDEA will suggest performing these actions one by one, as new imports appear.
Ammonite Notations, Predefs and Builtins
The editor correctly handles all Ammonite-specific code and provides appropriate highlighting and navigation.
You can run your scripts right from the Editor by using the gutter icon to the left of the code that looks like a ‘play’ button. The Scala plugin will automatically create a Run Configuration and show the output of the script in the Run Tool Window:
We would love to learn more about your experiences with Ammonite and IntelliJ IDEA. Please share with us! Feature requests, pull requests and improvement suggestions are very welcome, too! Your feedback can influence the roadmap for Ammonite support a lot. Just add a comment here or create an issue in YouTrack. Thanks!
Performance tips for IntelliJ Scala Plugin
A full-blown IDE is one of the most complicated applications you can find on an average laptop. This is why we – the Scala plugin team at JetBrains – from time to time receive reports that our product lags in certain situations or works slowly in general. In some of these cases we can help, but in o…
Dataflow Analysis for Scala
One of the things IntelliJ IDEA is most famous for is its huge variety of helpful inspections and warnings. They make the lives of programmers significantly easier, frequently showing them errors in logic or style that they wouldn’t have noticed otherwise. Those inspections come in various shapes…
BSP Support for Bazel
The Build Server Protocol (BSP), a protocol initially developed by the Scala Center and JetBrains, enables the easy integration of IDEs and build tools. To give users even more options in the BSP ecosystem, we decided to add support for Bazel. While there is already a Bazel plugin for Intel…
IntelliJ Scala Plugin 2021.2 EAP: Package Search Integration
Package Search is a service developed by JetBrains that supports searching for libraries from multiple repositories such as Maven Central, Google Maven, and others. Since its introduction at the end of 2019, the Package Search plugin has made searching for and managing dependencies for Maven and …