Skip to content

Library Extensions

Mikhail Mutcianko edited this page Jan 28, 2020 · 2 revisions

Setting up the project

Latest sbt-idea-plugin version: 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

Available extension points

Manifest

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 and until-version stand for versions of IntelliJ IDEA on which given injector should be loaded
  • interface attribute of extension 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 multiple extension sections inside ideaVersion

Referring from the original library (Auto-loading)

There are two ways for IDEA to discover the extensions for your library automatically:

  • Place a json file intellij-compat.json under META-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"
}

Usage

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

Example project

There is a sample project that one can import and play with here