laitimes

K2 Kotlin Mode in IntelliJ IDEA (Alpha)

author:Not bald programmer
K2 Kotlin Mode in IntelliJ IDEA (Alpha)

Starting with v.2024.1, IntelliJ IDEA comes with an optional K2 mode. In this mode, the IDE uses the K2 compiler for faster and more robust Kotlin code analysis.

The IDE now has two modes:

  • Classic mode (enabled by default) – The IDE analyzes Kotlin code using the standard (K1) Kotlin compiler.
  • K2 Mode (Alpha) – The IDE uses the new K2 compiler as the code analysis engine.

These patterns only affect code analysis in the IDE. If you want to compile your project using the K2 compiler¹, you will need to specify this in your project's build settings. The K2 IDE pattern does not depend on the version of the Kotlin compiler specified in the project's build settings.

K2 Kotlin Mode in IntelliJ IDEA (Alpha)

What is K2 mode?

We've rewritten the Kotlin compiler from the ground up, improving performance and enhancing the internal architecture to facilitate the further development of the Kotlin language. In addition, because the Kotlin compiler is used as a code analysis engine in the IDE, the K2 compiler is optimized to meet the requirements of the IDE.

The K2 model provides:

  • Compatibility with future Kotlin features: The new model will support future language features that will only be available in the K2 Kotlin compiler.
  • Code Analysis Stability: Code analysis will be more stable and will no longer have the Highlighting is suspended due to internal error message! Thanks to a massive architectural redesign, the quality and reliability of IDE features should improve.
  • Better IDE performance: Kotlin code highlighting and Kotlin code completion are significantly faster.
K2 Kotlin Mode in IntelliJ IDEA (Alpha)

IntelliJ Ultimate 源码库的性能测试

  • Improved APIs: In future releases, we plan to introduce easy-to-use elastic APIs for third-party plugins.
K2 Kotlin Mode in IntelliJ IDEA (Alpha)

What IDE features are supported?

In order to provide support for the K2 compiler in IntelliJ IDEA, we wrote many IDE features from scratch because they are very dependent on the K1 compiler's API. This allowed us to rethink the current design and solve problems that could not be solved in the K1-based IDE configuration.

We're not in a hurry to implement or migrate as many IDE features as possible. Our goal is to improve a small number of features at a time and strive for the best quality. We'll be steadily expanding IDE feature support with each subsequent release, and we'd love to hear from you.

K2 mode support in IntelliJ IDEA 2024.1:

  • Code highlighting
  • Code completion
  • navigation
  • Find usage
  • debugging
  • Rename(重命名)、Introduce Variable(引入变量)、Move(移动)、Inline Variable(内联变量)、Change Signature(更改签名)和 Safe Delete(安全删除)等重构
  • Basic editing features such as code formatting, parameter information, staple area icons, QuickDoc, import optimizer, and Type Hierarchy
  • Hot checks, intents, and quick fixes
  • New Project Wizard, Project Import, and Running Tests and Applications from IntelliJ IDEA

In IntelliJ IDEA 2024.1, K2 mode does not support:

  • Kotlin Multiplatform 项目 (KMP)
  • Android project
  • Extract Function(提取函数)重构
  • Embed prompts
  • Java to Kotlin conversion
  • Methods and Calls Hierarchy
  • Smart Step Into(智能步入)
  • Tools for debugging coroutines
  • .gradle.kts file
  • Other minor features
  • Third-party IntelliJ IDEA plugins that rely on the Kotlin plugin will be disabled. We will provide migration guidance to third-party plugin authors as soon as possible!

Support for missing features will be added in the next release.

K2 Kotlin Mode in IntelliJ IDEA (Alpha)

How do I try out K2 Kotlin compiler mode?

转到 Settings | Languages & Frameworks | Kotlin(设置 | 语言和框架 | Kotlin),点击 Enable the K2-based Kotlin plugin(启用基于 K2 的 Kotlin 插件)复选框启用新模式。

K2 Kotlin Mode in IntelliJ IDEA (Alpha)

How to enable Kotlin K2 mode in IntelliJ IDEA

Once K2 mode is enabled, you will need to restart the IDE.

K2 Kotlin Mode in IntelliJ IDEA (Alpha)

feedback

We welcome your feedback and would love to hear about your experience with IntelliJ IDEA's K2 Kotlin mode, the features you'd like us to add to this pattern, and your thoughts on its performance.

Share your experience with us by commenting below, sending us a message in our public Slack channel² or creating a question in YouTrack³.

We're actively working on improving this feature, and we look forward to your feedback!

Happy developing!

Related Links:

1. Compile the project using the K2 compiler:

https://kotlinlang.org/docs/whatsnew-eap.html

2. Public Slack Channels:

https://kotlinlang.slack.com/archives/C0B8H786P

3. YouTrack:

https://youtrack.jetbrains.com/issues/KTIJ