IntelliJ API to Build Scala Macros Support
A macro is executed at compile-time and modifies the AST of your code: e.g. it can extend the class or its companion object with new methods or other code represented by the AST returned by the macro. Since IntelliJ IDEA’s coding assistance is based on static code analysis, the IDE is not aware of AST changes, and can’t provide appropriate code completion and inspections for the generated code.
Since macros are heavily used in some projects and libraries, we’ve added a special API to the platform that lets build IntelliJ plugins supporting particular macros. Using this API, we earlier added support for Monocle, and now Simulacrum:
Now, everyone can use this API to make their macros more friendly to their favorite IDE. To do that, you have to implement SyntheticMembersInjector, and register it in the plugin.xml file:
<extensions defaultExtensionNs="org.intellij.scala"> <syntheticMemberInjector implementation="org.jetbrains.example.injector.Injector"/> </extensions>
The Monocle and Simulacrum implementations will help you understand how to use the API. To help you with setting up a project, we’ve prepared a skeleton. You’re welcome to fork it, and add your implementation.
Once you’ve built a working plugin, it can be installed to the IDE via Settings → Plugins → Install plugin from disk…. If you want to share your plugin with other IntelliJ IDEA users, feel free to upload it to our plugin repository.
In case you’d like to have particular macros supported by the Scala plugin, send us pull requests.
Develop with Pleasure!
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 …