The plugin adds support for the Scala language to IntelliJ IDEA.
It enables multiple features such as:
- Coding assistance (highlighting, completion, formatting, refactorings, code inspection etc.)
- Navigation, search, information about types and implicits
- Integration with build tools: SBT, Maven, Gradle, BSP
- Testing frameworks support (ScalaTest, MUnit, Specs2, uTest)
- Scala debugger, worksheets and Ammonite scripts
- And many more!
(note that HOCON support was moved to a separate plugin)
-
To get information about how to install and use this plugin in IDEA, please use IntelliJ IDEA online help
-
If you have any question about the Scala plugin, we'd be glad to answer it in our discord channel
If you found a bug, please report it on our issue tracker
Please see CONTRIBUTING.md
In order to take part in Scala plugin development, you need:
- IntelliJ IDEA 2022.3 or higher with a compatible version of Scala plugin
- JDK 17 (you can download it via IntelliJ IDEA)
- (optional but recommended)
Enable internal mode in IDEA to get access to helpful internal actions and debug information
- Clone this repository to your computer
$ git clone https://github.com/JetBrains/intellij-scala.git
-
Open IntelliJ IDEA. From the Welcome screen or
File
menu, clickOpen
, and point to the directory where you cloned the Scala plugin sources. It will be automatically imported as a sbt project. -
In the next step, select JDK 17 as project JDK (create it from an installed JDK if necessary).
-
Select the
scalaCommunity
run configuration and select theRun
orDebug
button to build and start a development version of IDEA with the Scala plugin.
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.
To run and distribute a modified version of the plugin in a regular IntelliJ instance, you need to package it.
- on the sbt shell, run
packageArtifactZip
. This will output the generated plugin zip location (typically into<project directory>/target/scala-plugin.zip
). - In IntelliJ, open Preferences, section Plugins, choose "Install plugin from disk..." and navigate to the scala-plugin.zip
- Restart IntelliJ
To run tests properly, the plugin needs to be packaged. On the sbt shell:
packageArtifact
runFastTests
The "fast tests" can take over an hour. To get a quick feedback on project health, run only the type inference tests:
> runTypeInferenceTests
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.
-
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 thebsp
andsbt-impl
modules multiple times. Make sure it's only included once by removing duplicates. This can be done inFile > Project Structure...
. -
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 -
After building the project you see git local changes in
ImportsPanel.java
(or similar files). AllIdeBorderFactory.PlainSmallWithIndent
are replaced withBorderFactory
Solution: enable internal mode.
UI Designer uses different border class in internal mode, seecom.intellij.uiDesigner.make.FormSourceCodeGenerator#borderFactoryClassName
-
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. -
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 inFile > Project Structure...
and make sure that they don't have a name that starts withscala.<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
.
- YourKit
- There is a "Scala plugin profiler" tool window to track invocations of methods with
@Cached*
or@Measure
annotations (fromorg.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
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.