$npx -y skills add Amplicode/spring-skills --skill codefmtReformat source code in this project using its own code-style settings. Use this whenever the user asks to format, reformat, tidy, "prettify", fix indentation, or optimize imports on Java/Kotlin/XML/etc. files — whether it's a single named file, a selected block or line range, a
| 1 | # Formatting files through the IntelliJ IDE/OpenIDE |
| 2 | |
| 3 | This project runs inside a live IntelliJ IDEA instance reachable through the |
| 4 | **MCP Steroid** tools. The IDE's own formatter (`ReformatCodeProcessor`) applies |
| 5 | the project's configured code style — the same result a developer gets from |
| 6 | **Code → Reformat Code**. Driving it through the IDE (rather than an external |
| 7 | CLI formatter) means the style always matches what the team sees, and the IDE's |
| 8 | VFS/PSI/index caches stay consistent after the edit. |
| 9 | |
| 10 | ## Prerequisites |
| 11 | |
| 12 | 1. Load the MCP Steroid tools if they aren't already available — their schemas |
| 13 | are deferred in Claude Code: |
| 14 | `ToolSearch("steroid list projects execute code")` then use |
| 15 | `steroid_list_projects` and `steroid_execute_code`. |
| 16 | 2. Get the routing key: call `steroid_list_projects` and take the |
| 17 | `project_name` (the opaque key, e.g. `spring-petclinic-ipvczgii`), **not** the |
| 18 | human-readable `name`. Every `steroid_execute_code` call needs this key. |
| 19 | 3. Run all formatting code with `modal: "smart_non_modal"` (the default). It |
| 20 | commits documents and refreshes the VFS around your script, which is exactly |
| 21 | what formatting needs. |
| 22 | |
| 23 | ## Choosing the recipe |
| 24 | |
| 25 | | The user wants to format… | Use | |
| 26 | |-----------------------------------------|----------------------------------------------------------------------------| |
| 27 | | One file named by path or class name | [Single file](#1-single-file-by-name) | |
| 28 | | A specific block / line range in a file | [Code block](#2-code-block-line-range) | |
| 29 | | Every uncommitted / changed file | [All uncommitted files](#3-all-uncommitted-files) → run the bundled script | |
| 30 | | Several named files at once | [A group of named files](#4-a-group-of-named-files) | |
| 31 | |
| 32 | Always report back what actually changed — run `git diff --stat <paths>` after |
| 33 | formatting. It's normal and correct for a reformat to produce **no diff** when |
| 34 | the file already conforms to the code style; say so plainly rather than implying |
| 35 | work was done. |
| 36 | |
| 37 | --- |
| 38 | |
| 39 | ## 1. Single file by name |
| 40 | |
| 41 | Script: [`scripts/format-single-file.kts`](scripts/format-single-file.kts). |
| 42 | |
| 43 | **To run it:** read the script, edit the `name` / `pathSuffix` placeholders at |
| 44 | the top to point at the target file, then pass the body as the `code` argument |
| 45 | to `steroid_execute_code`. Drop the `OptimizeImportsProcessor` line for non-JVM |
| 46 | files. |
| 47 | |
| 48 | ## 2. Code block (line range) |
| 49 | |
| 50 | Script: [`scripts/format-code-block.kts`](scripts/format-code-block.kts). |
| 51 | |
| 52 | **To run it:** read the script, edit the `name` / `startLine` / `endLine` |
| 53 | placeholders, then pass the body as the `code` argument to |
| 54 | `steroid_execute_code`. If the user pasted a snippet rather than a line range, |
| 55 | build the `TextRange` from `indexOf(snippet)` instead — see the header comment |
| 56 | in the script. |
| 57 | |
| 58 | ## 3. All uncommitted files |
| 59 | |
| 60 | This is a bundled, validated script: |
| 61 | [`scripts/format-uncommitted.kts`](scripts/format-uncommitted.kts). |
| 62 | |
| 63 | **To run it:** read the script file and pass its body as the `code` argument to |
| 64 | `steroid_execute_code` (`project_name` = the routing key, `modal: |
| 65 | "smart_non_modal"`). It's self-contained — no arguments needed. Afterward, run |
| 66 | `git status --porcelain` / `git diff --stat` to show the user the result. |
| 67 | |
| 68 | Adjust the `FORMATTABLE` extension set at the top of the script if the user |
| 69 | wants a narrower or wider net (e.g. only `java`). |
| 70 | |
| 71 | ## 4. A group of named files |
| 72 | |
| 73 | Script: [`scripts/format-file-group.kts`](scripts/format-file-group.kts). |
| 74 | |
| 75 | **To run it:** read the script, edit the `requested` list to the target files, |
| 76 | then pass the body as the `code` argument to `steroid_execute_code`. |