Home

Awesome

official JetBrains project Scala Plugin Build & Test Discord

Scala Plugin for IntelliJ IDEA

The plugin adds support for the Scala language to IntelliJ IDEA.
It enables multiple features such as:

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

General information

Reporting issues

If you found a bug, please report it on our issue tracker

Contributing

Please see CONTRIBUTING.md

Setting up the project

Prerequisites

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

  1. IntelliJ IDEA 2022.3 or higher with a compatible version of Scala plugin
  2. JDK 17 (you can download it via IntelliJ IDEA)
  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. From the Welcome screen or File menu, click Open, and point to the directory where you cloned the Scala plugin sources. It will be automatically imported as a sbt project.

  2. In the next step, select JDK 17 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.

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. Under the hood it will launch IntelliJ IDEA with pre-installed Scala Plugin, built from sources.

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

Running the 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

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.

Common problems

  1. Error object BuildInfo is already defined ... during compilation of the project
    BuildInfo is an sbt plugin that exposes some of the sbt build metadata to the main project. We use it to forward some dependencies versions from the build sources to main project sources. Sometimes during import this generated source root is added to the bsp and sbt-impl modules multiple times. Make sure it's only included once by removing duplicates. This can be done in File > Project Structure....

  2. Can't browse 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.
    Solution:
    Invoke "Attach Intellij Sources" action (you need to enable internal mode to access this action

  3. After building the project you see git local changes in ImportsPanel.java (or similar files). All IdeBorderFactory.PlainSmallWithIndent are replaced with BorderFactory
    Solution: enable internal mode.
    UI Designer uses different border class in internal mode, see com.intellij.uiDesigner.make.FormSourceCodeGenerator#borderFactoryClassName

  4. Unexpected local git changes in uiDesigner.xml or other files in .idea directory
    It may happen due to disable internal mode or by enabling it after/during setup.
    The solution to this problem might be to revert these changes, enable internal mode (if it has not already been done) and restart IntelliJ.

  5. The Scala plugin is not loaded when running the scalaCommunity Run Configuration. Unfortunately, there can be multiple reasons for this, like an improperly packaged plugin which cannot be loaded by IDEA at runtime.
    Check the list of project modules in File > Project Structure... and make sure that they don't have a name that starts with scala.<module name> (e.g. scala.structure-view). This is a bug in the sbt import process.
    If there are modules like this, then remove all modules from the project (in the same Project Structure window) and reimport the project <sbt tab> > Reload All sbt Projects.

Other

Investigation performance issues

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.declarationRedundancy.*;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.

Lexers and parsers

See our dedicated lexer/parser README.