diff --git a/docs/topics/k2-compiler-migration-guide.md b/docs/topics/k2-compiler-migration-guide.md index d4879bd37bb..cc2e3875324 100644 --- a/docs/topics/k2-compiler-migration-guide.md +++ b/docs/topics/k2-compiler-migration-guide.md @@ -522,8 +522,8 @@ Starting with Kotlin 2.0.0, the Kotlin K2 compiler is enabled by default. To upgrade the Kotlin version, change it to 2.0.0 or a later release in your [Gradle](gradle-configure-project.md#apply-the-plugin) and [Maven](maven.md#configure-and-enable-the-plugin) build scripts. -To have the best experience with IntelliJ IDEA or Android Studio, consider [enabling K2 mode](#support-in-ides) -in your IDE. +To get the best experience with Android Studio, use [K2 mode](#support-in-ides) in your IDE. IntelliJ IDEA uses +K2 mode by default, so you don't have to change anything. ### Use Kotlin build reports with Gradle @@ -557,26 +557,13 @@ For more information on what is possible with build reports, see [Build reports] K2 mode in IntelliJ IDEA and Android Studio uses the K2 compiler to improve code analysis, code completion, and highlighting. -Starting with IntelliJ IDEA 2025.1, K2 mode is [enabled by default](https://blog.jetbrains.com/idea/2025/04/k2-mode-in-intellij-idea-2025-1-current-state-and-faq/). +IntelliJ IDEA 2025.3 and later always uses K2 mode. In Android Studio, you can enable K2 mode starting with 2024.1 by following these steps: 1. Go to **Settings** | **Languages & Frameworks** | **Kotlin**. 2. Select the **Enable K2 mode** option. -### Previous IDE behavior {initial-collapse-state="collapsed" collapsible="true"} - -If you want to go back to the previous IDE behavior, you can disable K2 mode: - -1. Go to **Settings** | **Languages & Frameworks** | **Kotlin**. -2. Deselect the **Enable K2 mode** option. - -> We plan to introduce [Stable](components-stability.md#stability-levels-explained) language features after Kotlin 2.1.0. -> Until then, you can continue to use the previous IDE features for code analysis, and you won't encounter any code highlighting -> issues due to unrecognized language features. -> -{style="note"} - ## Try the Kotlin K2 compiler in the Kotlin Playground The Kotlin Playground supports Kotlin 2.0.0 and later releases. [Check it out!](https://pl.kotl.in/czuoQprce) diff --git a/docs/topics/releases.md b/docs/topics/releases.md index 8e6ddf95d22..33203f22e36 100644 --- a/docs/topics/releases.md +++ b/docs/topics/releases.md @@ -121,7 +121,7 @@ Kotlin has full out-of-the-box support in [IntelliJ IDEA](https://www.jetbrains. K2 mode in IntelliJ IDEA and Android Studio uses the K2 compiler to improve code analysis, code completion, and highlighting. -Starting with IntelliJ IDEA 2025.1, K2 mode is [enabled by default](https://blog.jetbrains.com/idea/2025/04/k2-mode-in-intellij-idea-2025-1-current-state-and-faq/). +IntelliJ IDEA 2025.3 and later always uses K2 mode. In Android Studio, you can enable K2 mode starting with 2024.1 by following these steps: diff --git a/docs/topics/run-code-snippets.md b/docs/topics/run-code-snippets.md index 0a57580ee33..30da70c0dfc 100644 --- a/docs/topics/run-code-snippets.md +++ b/docs/topics/run-code-snippets.md @@ -4,66 +4,53 @@ Kotlin code is typically organized into projects with which you work in an IDE, if you want to quickly see how a function works or find an expression's value, there's no need to create a new project and build it. Check out these three handy ways to run Kotlin code instantly in different environments: -* [Scratch files and worksheets](#ide-scratches-and-worksheets) in the IDE. +* [Scratch files](#ide-scratches-and-worksheets) in the IDE. * [Kotlin Playground](#browser-kotlin-playground) in the browser. * [ki shell](#command-line-ki-shell) in the command line. -## IDE: scratches and worksheets +## IDE: scratches {id="ide-scratches-and-worksheets"} -IntelliJ IDEA and Android Studio support Kotlin [scratch files and worksheets](https://www.jetbrains.com/help/idea/kotlin-repl.html#efb8fb32). +IntelliJ IDEA and Android Studio support Kotlin [scratch files](https://www.jetbrains.com/help/idea/kotlin-repl.html#efb8fb32). -* _Scratch files_ (or just _scratches_) let you create code drafts in the same IDE window as your project and run them on the fly. - Scratches are not tied to projects; you can access and run all your scratches from any IntelliJ IDEA window on your OS. +_Scratch files_ (or just _scratches_) let you create code drafts in the same IDE window as your project and run them on the fly. +Scratches are not tied to projects; you can access and run all your scratches from any IntelliJ IDEA window on your OS. - To create a Kotlin scratch, click **File** | **New** | **Scratch File** and select the **Kotlin** type. - -* _Worksheets_ are project files: they are stored in project directories and tied to the project modules. - Worksheets are useful for writing pieces of code that don't actually make a software unit but should still be stored together - in a project, such as educational or demo materials. - - To create a Kotlin worksheet in a project directory, right-click the directory in the project tree and select - **New** | **Kotlin Class/File** | **Kotlin Worksheet**. - - > Kotlin worksheets aren't supported in [K2 mode](https://blog.jetbrains.com/idea/2024/11/k2-mode-becomes-stable/). We're working on providing an alternative with similar functionality. - > - {style="warning"} +To create a Kotlin scratch, click **File** | **New** | **Scratch File** and select the **Kotlin** type. Syntax highlighting, auto-completion, and other -IntelliJ IDEA code editing features are supported in scratches and worksheets. There's no need to declare the `main()` function +IntelliJ IDEA code editing features are supported in scratches. There's no need to declare the `main()` function – all the code you write is executed as if it were in the body of `main()`. -Once you have finished writing your code in a scratch or a worksheet, click **Run**. +Once you have finished writing your code in a scratch, click **Run**. The execution results will appear in the lines opposite your code. ![Run scratch](scratch-run.png){width=700} ### Interactive mode -The IDE can run code from scratches and worksheets automatically. To get execution results as soon as you stop +The IDE can run code from scratches automatically. To get execution results as soon as you stop typing, switch on **Interactive mode**. ![Scratch interactive mode](scratch-interactive.png){width=700} ### Use modules -You can use classes or functions from a Kotlin project in your scratches and worksheets. - -Worksheets automatically have access to classes and functions from the module where they reside. +You can use classes or functions from a Kotlin project in your scratches. To use classes or functions from a project in a scratch, import them into the scratch file with the `import` statement, as usual. Then write your code and run it with the appropriate module selected in the **Use classpath of module** list. -Both scratches and worksheets use the compiled versions of connected modules. So, if you modify a module's source files, -the changes will propagate to scratches and worksheets when you rebuild the module. -To rebuild the module automatically before each run of a scratch or a worksheet, select **Make module before Run**. +Scratches and use the compiled versions of connected modules. So, if you modify a module's source files, +the changes will propagate to scratches when you rebuild the module. +To rebuild the module automatically before each run of a scratch, select **Make module before Run**. ![Scratch select module](scratch-select-module.png){width=700} ### Run as REPL -To evaluate each particular expression in a scratch or a worksheet, run it with **Use REPL** selected. The code lines +To evaluate each particular expression in a scratch, run it with **Use REPL** selected. The code lines will run sequentially, providing the results of each call. -You can later use the results in the same file by reffering to their auto-generated `res*` names (they are shown in the corresponding lines). +You can later use the results in the same file by referring to their auto-generated `res*` names (they are shown in the corresponding lines). ![Scratch REPL](scratch-repl.png){width=700}