-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Update K2 mode for 2025.3 #5208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sarahhaggarty
wants to merge
1
commit into
master
Choose a base branch
from
2025-3-k2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−44
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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. | ||||||
|
|
||||||
| {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**. | ||||||
|
|
||||||
| {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**. | ||||||
|
|
||||||
| {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 refering to their auto-generated `res*` names (they are shown in the corresponding lines). | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| {width=700} | ||||||
|
|
||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we say right here that IDEA doesn't even have the option to not use it? It feels a little disjointed to do a call to action and then follow a link that says that there is no action.