/intellij-scala

Scala plugin for IntelliJ IDEA

Primary LanguageScalaApache License 2.0Apache-2.0

official JetBrains project Scala Plugin Build & Test Discord Gitter

Scala Plugin for IntelliJ IDEA

The plugin adds support for the Scala language:

  • Coding assistance (highlighting, completion, formatting, refactorings, etc.)
  • Navigation, search, information about types and implicits
  • Integration with sbt and other build tools
  • Testing frameworks support (ScalaTest, Specs2, uTest)
  • Scala debugger, worksheets and Ammonite scripts

(note that HOCON support was moved to a separate plugin)

General information

Setting up the project

Prerequisites

In order to take part in Scala plugin development, you need:

  1. IntelliJ IDEA 2021.3 or higher with a compatible version of Scala plugin
  2. JDK 11
  3. (optional but recommended)
    Enable internal mode in IDEA to get access to helpful internal actions and debug information

Setup

  1. Clone this repository to your computer
$ git clone https://github.com/JetBrains/intellij-scala.git
  1. Open IntelliJ IDEA, select File -> New -> Project from existing sources, point to the directory where the Scala plugin repository is and then import it as sbt project.

  2. In the next step, select JDK 11 as project JDK (create it from an installed JDK if necessary).

  3. Select the scalaCommunity run configuration and select the Run or Debug button to build and start a development version of IDEA with the Scala plugin.

Browsing IntelliJ Platform sources

When loading Scala Plugin project in sbt, the IntelliJ platform is downloaded to <home>/.ScalaPluginIC/sdk/<sdk version>/. IntelliJ platform sources should be automatically attached after project has been imported and indices have been built.

However, sometimes this doesn't happen and the sources are not attached. As a result you see decompiled code when opening a Platform API class. To fix this you can invoke "Attach Intellij Sources" action (you need to enable internal mode to access this action)

Tests

To run tests properly, the plugin needs to be packaged. On the sbt shell:

  1. packageArtifact
  2. runFastTests

The "fast tests" can take over an hour. To get a quick feedback on project health, run only the type inference tests:

> runTypeInferenceTests

Generating test coverage reports

You might want to generate a test coverage report for a given package. It can be done by running for example the following:

sbt "project scala-impl;set coverageEnabled := true;project scalaCommunity;testOnly org.jetbrains.plugins.scala.codeInspection.unusedInspections.*;scala-impl/coverageReport"

Close to the very tail of the output of this command you will find a line that gives you the location of the generated report, for example:

[info] Written HTML coverage report [/Users/alice/intellij-scala/scala/scala-impl/target/scala-2.13/scoverage-report/index.html]

Note that in order to continue working from IntelliJ IDEA again you need to perform Build > Rebuild Project.

GitHub Actions build

The project is configured to build and run the typeInference tests and fast tests with Github Actions. The full test suite isn't run to avoid really long build times.

Running the plugin

Debugging mode

The easiest way to try your changes is typically to launch the scalaCommunity run configuration which is created when you set up the project as described above.

As a standalone plugin

To run and distribute a modified version of the plugin in a regular IntelliJ instance, you need to package it.

  1. on the sbt shell, run packageArtifactZip. This will output the generated plugin zip location (typically into <project directory>/target/scala-plugin.zip).
  2. In IntelliJ, open Preferences, section Plugins, choose "Install plugin from disk..." and navigate to the scala-plugin.zip
  3. Restart IntelliJ

Other

Investigation performance issues

  • YourKit
  • There is a "Scala plugin profiler" tool window to track invocations of methods with @Cached* or @Measure annotations (from org.jetbrains.plugins.scala.macroAnnotations package) in real time. The tool window is available in internal mode or if -Dinternal.profiler.tracing=true is passed to IDEA using custom VM options