Skip to content

Commit faa27ea

Browse files
committed
Show how to enable the IntelliJ plugin, format on save and use the native binary
Two screenshots: the open-java-format Settings page with the plugin enabled, and Actions on Save with Reformat code for Java files and the whole file, the scope the GitHub Action checks. A new section explains the native binary in the IDE: it is switched on by openjavaformat.native.formatter in the Gradle build, and the settings page then shows Native image formatter.
1 parent 285ccf3 commit faa27ea

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

89.9 KB
Loading
59.3 KB
Loading

‎docs/get-started/intellij-idea.md‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,49 @@ A version that is not on the Marketplace yet can be installed from a release.
3535

3636
The plugin is off in every project until you turn it on.
3737

38-
1. Open **Settings** and search for **open-java-format Settings**.
38+
1. Open **Settings** and go to **Other Settings → open-java-format Settings**.
3939
2. Tick **Enable open-java-format**.
4040

41+
![The open-java-format Settings page with Enable open-java-format ticked](../assets/images/intellij-enable.webp){ width="1000" height="673" loading="lazy" }
42+
4143
From then on Reformat Code, ++ctrl+alt+l++ or ++option+cmd+l++ on macOS, formats Java files with
4244
open-java-format.
4345

44-
## Which formatter version runs
46+
## Format on save
47+
48+
1. Open **Settings** and go to **Tools → Actions on Save**.
49+
2. Tick **Reformat code**.
50+
3. Next to it, choose **Java** in the file list and **Whole file** instead of **Changed lines**.
4551

46-
The formatter runs in a process of its own, on the IDE's runtime, so the project SDK can be any
47-
version. When a Gradle build runs the formatter as a
48-
[native binary](gradle.md#choose-how-the-formatter-runs), the IDE runs that binary instead.
52+
![Actions on Save with Reformat code ticked for Java files and the whole file](../assets/images/intellij-actions-on-save.webp){ width="1000" height="674" loading="lazy" }
53+
54+
Limiting it to Java keeps other files out: the IDE would reformat those with its own formatters.
55+
**Whole file** formats the entire file, which is what the [GitHub Action](github-actions.md) checks.
56+
**Changed lines** formats only the lines you edited, the way `formatDiff` does.
57+
58+
## Which formatter version runs
4959

5060
A project that applies the [Gradle plugin](gradle.md) takes the formatter version from the build.
51-
Every other project uses the version bundled with the IDE plugin.
61+
Every other project uses the version bundled with the IDE plugin, which the settings page shows as
62+
`(bundled)` under **Implementation version**, as in the screenshot above.
63+
64+
By default the formatter runs in a process of its own, on the IDE's runtime, so the project SDK can
65+
be any version.
66+
67+
## Native binary
68+
69+
In a project with the [Gradle plugin](gradle.md), the IDE can run the formatter as the native binary
70+
that the build uses. It is switched on in the build, not in the IDE:
71+
72+
``` properties title="gradle.properties"
73+
openjavaformat.native.formatter=true
74+
```
75+
76+
After the next Gradle sync in the IDE, the plugin writes the path of the binary into
77+
`.idea/open-java-format.xml`, and **Formatter type** on the settings page changes from
78+
**Java-based formatter** to **Native image formatter**. Each reformat starts the formatter as a new
79+
process, and the native binary starts without a JVM.
80+
81+
The binary runs on the platforms listed on the
82+
[Gradle plugin](gradle.md#choose-how-the-formatter-runs) page. Elsewhere the plugin ignores the
83+
property, and the IDE keeps the Java-based formatter.

0 commit comments

Comments
 (0)