JetBrains Highlights K2 Compiler’s Faster and More Stable Kotlin Code Highlighting and Completion
JetBrains’ upcoming IntelliJ IDEA 2024.1, scheduled for release on April 4, will introduce an optional K2 compiler mode. This new mode aims to provide faster and more robust Kotlin code analysis, offering developers enhanced performance and reliability. The K2 compiler mode will coexist with the standard K1 compiler mode, giving developers the flexibility to choose between the two for their Kotlin projects, JetBrains announced in a March 25 blog post.
In IntelliJ IDEA 2024.1, the IDE will feature two distinct modes: the class mode, which is enabled by default and relies on the K1 Kotlin compiler, and the optional K2 mode, which leverages the newer K2 compiler for code analysis. Although the K2 mode is still in its alpha state, JetBrains is positioning it as a high-performance alternative that will serve as the foundation for future Kotlin language features.
The introduction of the K2 compiler represents a significant overhaul, as JetBrains has rewritten the compiler from the ground up. The new architecture promises better performance and scalability, laying the groundwork for more advanced Kotlin language features in the future. However, it is important to note that switching to the K2 mode only impacts code analysis within the IDE; if developers want to compile their projects using the K2 compiler, they will need to configure this separately in their build settings.
The K2 mode will support essential IDE features such as code highlighting, code completion, navigation, debugging, and refactoring. Developers will also benefit from features like code formatting, type hierarchy, inspections, quick fixes, new project wizards, wizard importing, and the ability to run tests and applications directly from the IDE. These features are expected to improve the overall coding experience, particularly for those working with large and complex Kotlin projects.
However, the initial release of the K2 mode will have some limitations. It will not yet support Kotlin Multiplatform projects, Android projects, or certain refactoring operations like extract function refactoring. Other missing features include inlay hints and Java-to-Kotlin conversion. Additionally, third-party IntelliJ IDEA plugins that depend on the Kotlin plugin will be disabled in K2 mode, although JetBrains plans to introduce support for these plugins in future updates.
JetBrains has acknowledged that while the K2 mode offers promising improvements, there is still work to be done to fully realize its potential. The company is actively working on adding support for the missing features and is developing an API that will allow third-party plugins to integrate with the new K2 compiler. Developers can expect these enhancements to be rolled out in upcoming releases, making the K2 mode a more complete solution for Kotlin development in IntelliJ IDEA.