-
Notifications
You must be signed in to change notification settings - Fork 397
Library Extensions
Latest sbt-idea-plugin version:
- Insert into
project/plugins.sbt
:
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % LATEST_VERSION)
- Enable the plugin via
enablePlugins(SbtIdeaPlugin)
- define IDEA version you wish to build against and add plugin dependency
intellijBuild in ThisBuild := "183.4284.118" // specify IDEA version you want to build against
intellijExternalPlugins += "org.intellij.scala".toPlugin
-
ScalaMacroTypeable
- provide return types for whitebox macro - example -
ScalaMacroExpandable
- provide expansions for whitebox macro - example -
SyntheticMembersInjector
- inject members into classes\objects\traits - example -
BundledInspectionBase
- custom code inspections - more to come
This file should be named intellij-compat.xml
and placed under META-INF
folder of the extensions JAR.
An example manifest goes like this:
<intellij-compat>
<name>Shapeless support</name>
<description>This provides type inference for shapless macros</description>
<version>3.2.2-1</version>
<vendor>JetBrains</vendor>
<ideaVersion since-build="2018.1.0" until-build="2018.2.0">
<extension interface="org.jetbrains.plugins.scala.lang.macros.evaluator.ScalaMacroTypeable"
implementation="org.jetbrains.shapeless.ShapelessMaterializeGeneric">
<description>Support for Generic macro</description>
</extension>
</ideaVersion>
</intellij-compat>
Where:
-
since-version
anduntil-version
stand for versions of IntelliJ IDEA on which given injector should be loaded -
interface
attribute ofextension
tag basically specifies an extension point in Scala plugin -
implementation
attribute specifies an actual class of your injector which will be loaded by plugin - note that there can be multiple
ideaVersion
sections if you wish to support multiple versions of IDEA as well as multipleextension
sections insideideaVersion
There are two ways for IDEA to discover the extensions for your library automatically:
- Place a json file
intellij-compat.json
underMETA-INF
folder of your original library with a reference to the exensions. You can also provide a direct link to the jar by using "urlOverride" instead of "artifact" key in the JSON
{
"artifact": "org.mycompany % mylib-extensions_2.12 % 1.0.0"
}
- Create a pull request to intellij-scala with your extensions added to the BundledExtensionIndex
After opening a project of modifying libraries, Scala plugin will search for libraries containing intellij-compat.json
and download extensions specified there. A search wil also be performed against the bundled extension index.
If such libraries have been found and have a valid injector manifest, Scala plugin will then notify the user that one can activate code analysis extensions provided by the library and suggest enabling them.
User can also add or remove the extensions manually on the "Extensions" setting tab under File | Settings | Languages & Frameworks | Scala | Extensions
There is a sample project that one can import and play with here